]>
Commit | Line | Data |
---|---|---|
1815bff5 A |
1 | /* |
2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
2fc1e207 A |
6 | * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights |
7 | * Reserved. This file contains Original Code and/or Modifications of | |
8 | * Original Code as defined in and that are subject to the Apple Public | |
9 | * Source License Version 1.0 (the 'License'). You may not use this file | |
10 | * except in compliance with the License. Please obtain a copy of the | |
11 | * License at http://www.apple.com/publicsource and read it before using | |
12 | * this file. | |
1815bff5 A |
13 | * |
14 | * The Original Code and all software distributed under the License are | |
15 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2fc1e207 A |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
19 | * License for the specific language governing rights and limitations | |
20 | * under the License." | |
1815bff5 A |
21 | * |
22 | * @APPLE_LICENSE_HEADER_END@ | |
23 | */ | |
24 | /* | |
25 | * Copyright (c) 1988, 1993, 1994 | |
26 | * The Regents of the University of California. All rights reserved. | |
27 | * | |
28 | * Redistribution and use in source and binary forms, with or without | |
29 | * modification, are permitted provided that the following conditions | |
30 | * are met: | |
31 | * 1. Redistributions of source code must retain the above copyright | |
32 | * notice, this list of conditions and the following disclaimer. | |
33 | * 2. Redistributions in binary form must reproduce the above copyright | |
34 | * notice, this list of conditions and the following disclaimer in the | |
35 | * documentation and/or other materials provided with the distribution. | |
36 | * 3. All advertising materials mentioning features or use of this software | |
37 | * must display the following acknowledgement: | |
38 | * This product includes software developed by the University of | |
39 | * California, Berkeley and its contributors. | |
40 | * 4. Neither the name of the University nor the names of its contributors | |
41 | * may be used to endorse or promote products derived from this software | |
42 | * without specific prior written permission. | |
43 | * | |
44 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
45 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
46 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
47 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
48 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
49 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
50 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
51 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
52 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
53 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
54 | * SUCH DAMAGE. | |
55 | */ | |
56 | ||
57 | #include <sys/param.h> | |
58 | ||
59 | #include <ctype.h> | |
60 | #include <err.h> | |
61 | #include <errno.h> | |
62 | #include <grp.h> | |
63 | #include <pwd.h> | |
64 | #include <stdio.h> | |
65 | #include <stdlib.h> | |
66 | #include <string.h> | |
67 | #include <unistd.h> | |
68 | ||
69 | #include "chpass.h" | |
70 | #include "pathnames.h" | |
71 | ||
72 | /* ARGSUSED */ | |
73 | int | |
74 | p_login(p, pw, ep) | |
75 | char *p; | |
76 | struct passwd *pw; | |
77 | ENTRY *ep; | |
78 | { | |
79 | if (!*p) { | |
80 | warnx("empty login field"); | |
81 | return (1); | |
82 | } | |
83 | if (*p == '-') { | |
84 | warnx("login names may not begin with a hyphen"); | |
85 | return (1); | |
86 | } | |
87 | if (!(pw->pw_name = strdup(p))) { | |
88 | warnx("can't save entry"); | |
89 | return (1); | |
90 | } | |
91 | if (strchr(p, '.')) | |
92 | warnx("\'.\' is dangerous in a login name"); | |
93 | for (; *p; ++p) | |
94 | if (isupper(*p)) { | |
95 | warnx("upper-case letters are dangerous in a login name"); | |
96 | break; | |
97 | } | |
98 | return (0); | |
99 | } | |
100 | ||
101 | /* ARGSUSED */ | |
102 | int | |
103 | p_passwd(p, pw, ep) | |
104 | char *p; | |
105 | struct passwd *pw; | |
106 | ENTRY *ep; | |
107 | { | |
108 | if (!*p) | |
109 | pw->pw_passwd = ""; /* "NOLOGIN"; */ | |
110 | else if (!(pw->pw_passwd = strdup(p))) { | |
111 | warnx("can't save password entry"); | |
112 | return (1); | |
113 | } | |
114 | ||
115 | return (0); | |
116 | } | |
117 | ||
118 | /* ARGSUSED */ | |
119 | int | |
120 | p_uid(p, pw, ep) | |
121 | char *p; | |
122 | struct passwd *pw; | |
123 | ENTRY *ep; | |
124 | { | |
125 | uid_t id; | |
126 | char *np; | |
127 | ||
128 | if (!*p) { | |
129 | warnx("empty uid field"); | |
130 | return (1); | |
131 | } | |
132 | if (!isdigit(*p)) { | |
133 | warnx("illegal uid"); | |
134 | return (1); | |
135 | } | |
136 | errno = 0; | |
137 | id = strtoul(p, &np, 10); | |
138 | if (*np || (id == ULONG_MAX && errno == ERANGE)) { | |
139 | warnx("illegal uid"); | |
140 | return (1); | |
141 | } | |
142 | pw->pw_uid = id; | |
143 | return (0); | |
144 | } | |
145 | ||
146 | /* ARGSUSED */ | |
147 | int | |
148 | p_gid(p, pw, ep) | |
149 | char *p; | |
150 | struct passwd *pw; | |
151 | ENTRY *ep; | |
152 | { | |
153 | struct group *gr; | |
154 | gid_t id; | |
155 | char *np; | |
156 | ||
157 | if (!*p) { | |
158 | warnx("empty gid field"); | |
159 | return (1); | |
160 | } | |
161 | if (!isdigit(*p)) { | |
162 | if (!(gr = getgrnam(p))) { | |
163 | warnx("unknown group %s", p); | |
164 | return (1); | |
165 | } | |
166 | pw->pw_gid = gr->gr_gid; | |
167 | return (0); | |
168 | } | |
169 | errno = 0; | |
170 | id = strtoul(p, &np, 10); | |
171 | if (*np || (id == ULONG_MAX && errno == ERANGE)) { | |
172 | warnx("illegal gid"); | |
173 | return (1); | |
174 | } | |
175 | pw->pw_gid = id; | |
176 | return (0); | |
177 | } | |
178 | ||
179 | /* ARGSUSED */ | |
180 | int | |
181 | p_class(p, pw, ep) | |
182 | char *p; | |
183 | struct passwd *pw; | |
184 | ENTRY *ep; | |
185 | { | |
186 | if (!*p) | |
187 | pw->pw_class = ""; | |
188 | else if (!(pw->pw_class = strdup(p))) { | |
189 | warnx("can't save entry"); | |
190 | return (1); | |
191 | } | |
192 | ||
193 | return (0); | |
194 | } | |
195 | ||
196 | /* ARGSUSED */ | |
197 | int | |
198 | p_change(p, pw, ep) | |
199 | char *p; | |
200 | struct passwd *pw; | |
201 | ENTRY *ep; | |
202 | { | |
203 | if (!atot(p, &pw->pw_change)) | |
204 | return (0); | |
205 | warnx("illegal date for change field"); | |
206 | return (1); | |
207 | } | |
208 | ||
209 | /* ARGSUSED */ | |
210 | int | |
211 | p_expire(p, pw, ep) | |
212 | char *p; | |
213 | struct passwd *pw; | |
214 | ENTRY *ep; | |
215 | { | |
216 | if (!atot(p, &pw->pw_expire)) | |
217 | return (0); | |
218 | warnx("illegal date for expire field"); | |
219 | return (1); | |
220 | } | |
221 | ||
222 | /* ARGSUSED */ | |
223 | int | |
224 | p_gecos(p, pw, ep) | |
225 | char *p; | |
226 | struct passwd *pw; | |
227 | ENTRY *ep; | |
228 | { | |
229 | if (!*p) | |
230 | ep->save = ""; | |
231 | else if (!(ep->save = strdup(p))) { | |
232 | warnx("can't save entry"); | |
233 | return (1); | |
234 | } | |
235 | return (0); | |
236 | } | |
237 | ||
238 | /* ARGSUSED */ | |
239 | int | |
240 | p_hdir(p, pw, ep) | |
241 | char *p; | |
242 | struct passwd *pw; | |
243 | ENTRY *ep; | |
244 | { | |
245 | if (!*p) { | |
246 | warnx("empty home directory field"); | |
247 | return (1); | |
248 | } | |
249 | if (!(pw->pw_dir = strdup(p))) { | |
250 | warnx("can't save entry"); | |
251 | return (1); | |
252 | } | |
253 | return (0); | |
254 | } | |
255 | ||
256 | /* ARGSUSED */ | |
257 | int | |
258 | p_shell(p, pw, ep) | |
259 | char *p; | |
260 | struct passwd *pw; | |
261 | ENTRY *ep; | |
262 | { | |
263 | char *t, *ok_shell(); | |
264 | ||
265 | if (!*p) { | |
266 | pw->pw_shell = _PATH_BSHELL; | |
267 | return (0); | |
268 | } | |
269 | /* only admin can change from or to "restricted" shells */ | |
270 | if (uid && pw->pw_shell && !ok_shell(pw->pw_shell)) { | |
271 | warnx("%s: current shell non-standard", pw->pw_shell); | |
272 | return (1); | |
273 | } | |
274 | if (!(t = ok_shell(p))) { | |
275 | if (uid) { | |
276 | warnx("%s: non-standard shell", p); | |
277 | return (1); | |
278 | } | |
279 | } | |
280 | else | |
281 | p = t; | |
282 | if (!(pw->pw_shell = strdup(p))) { | |
283 | warnx("can't save entry"); | |
284 | return (1); | |
285 | } | |
286 | return (0); | |
287 | } | |
c3a08f59 A |
288 | |
289 | #ifdef DIRECTORY_SERVICE | |
290 | void | |
291 | d_change(struct display *d, FILE *fp) | |
292 | { | |
293 | fprintf(fp, "Change [month day year]: %s\n", ttoa(d->pw->pw_change)); | |
294 | } | |
295 | ||
296 | void | |
297 | d_class(struct display *d, FILE *fp) | |
298 | { | |
299 | fprintf(fp, "Class: %s\n", d->pw->pw_class); | |
300 | } | |
301 | ||
302 | void | |
303 | d_expire(struct display *d, FILE *fp) | |
304 | { | |
305 | fprintf(fp, "Expire [month day year]: %s\n", ttoa(d->pw->pw_expire)); | |
306 | } | |
307 | ||
308 | void | |
309 | d_fullname(struct display *d, FILE *fp) | |
310 | { | |
311 | fprintf(fp, "Full Name: %s\n", d->fullname); | |
312 | } | |
313 | ||
314 | void | |
315 | d_gid(struct display *d, FILE *fp) | |
316 | { | |
317 | fprintf(fp, "Gid [# or name]: %d\n", d->pw->pw_gid); | |
318 | } | |
319 | ||
320 | void | |
321 | d_hdir(struct display *d, FILE *fp) | |
322 | { | |
323 | fprintf(fp, "Home directory: %s\n", d->pw->pw_dir); | |
324 | } | |
325 | ||
326 | void | |
327 | d_homephone(struct display *d, FILE *fp) | |
328 | { | |
329 | fprintf(fp, "Home Phone: %s\n", d->homephone); | |
330 | } | |
331 | ||
332 | void | |
333 | d_login(struct display *d, FILE *fp) | |
334 | { | |
335 | fprintf(fp, "Login: %s\n", d->pw->pw_name); | |
336 | } | |
337 | ||
338 | void | |
339 | d_location(struct display *d, FILE *fp) | |
340 | { | |
341 | fprintf(fp, "Location: %s\n", d->location); | |
342 | } | |
343 | ||
344 | void | |
345 | d_officephone(struct display *d, FILE *fp) | |
346 | { | |
347 | fprintf(fp, "Office Phone: %s\n", d->officephone); | |
348 | } | |
349 | ||
350 | void | |
351 | d_passwd(struct display *d, FILE *fp) | |
352 | { | |
353 | fprintf(fp, "Password: %s\n", d->pw->pw_passwd); | |
354 | } | |
355 | ||
356 | void | |
357 | d_shell(struct display *d, FILE *fp) | |
358 | { | |
359 | fprintf(fp, "Shell: %s\n", *d->pw->pw_shell ? d->pw->pw_shell | |
360 | : _PATH_BSHELL); | |
361 | } | |
362 | ||
363 | void | |
364 | d_uid(struct display *d, FILE *fp) | |
365 | { | |
366 | fprintf(fp, "Uid [#]: %d\n", d->pw->pw_uid); | |
367 | } | |
368 | #endif /* DIRECTORY_SERVICE */ |