]>
git.saurik.com Git - apple/system_cmds.git/blob - system_cmds-597.1.1/chpass.tproj/field.c
2 * Copyright (c) 1999-2006 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 * Copyright (c) 1988, 1993, 1994
25 * The Regents of the University of California. All rights reserved.
26 * Copyright (c) 2002 Networks Associates Technology, Inc.
27 * All rights reserved.
29 * Portions of this software were developed for the FreeBSD Project by
30 * ThinkSec AS and NAI Labs, the Security Research Division of Network
31 * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035
32 * ("CBOSS"), as part of the DARPA CHATS research program.
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. All advertising materials mentioning features or use of this software
43 * must display the following acknowledgement:
44 * This product includes software developed by the University of
45 * California, Berkeley and its contributors.
46 * 4. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 static char sccsid
[] = "@(#)field.c 8.4 (Berkeley) 4/2/94";
70 #include <sys/cdefs.h>
71 __FBSDID("$FreeBSD: src/usr.bin/chpass/field.c,v 1.9 2004/01/18 21:46:39 charnier Exp $");
74 #include <sys/param.h>
90 p_login(char *p
, struct passwd
*pw
, ENTRY
*ep __unused
)
93 warnx("empty login field");
97 warnx("login names may not begin with a hyphen");
100 #ifndef OPEN_DIRECTORY
101 if (!(pw
->pw_name
= strdup(p
))) {
102 warnx("can't save entry");
107 warnx("\'.\' is dangerous in a login name");
110 warnx("upper-case letters are dangerous in a login name");
118 p_passwd(char *p
, struct passwd
*pw
, ENTRY
*ep __unused
)
120 #ifndef OPEN_DIRECTORY
121 if (!(pw
->pw_passwd
= strdup(p
))) {
122 warnx("can't save password entry");
132 p_uid(char *p
, struct passwd
*pw
, ENTRY
*ep __unused
)
138 warnx("empty uid field");
142 warnx("illegal uid");
146 id
= strtoul(p
, &np
, 10);
147 if (*np
|| (id
== (uid_t
)ULONG_MAX
&& errno
== ERANGE
)) {
148 warnx("illegal uid");
151 #ifndef OPEN_DIRECTORY
159 p_gid(char *p
, struct passwd
*pw
, ENTRY
*ep __unused
)
166 warnx("empty gid field");
170 if (!(gr
= getgrnam(p
))) {
171 warnx("unknown group %s", p
);
174 #ifndef OPEN_DIRECTORY
175 pw
->pw_gid
= gr
->gr_gid
;
180 id
= strtoul(p
, &np
, 10);
181 if (*np
|| (id
== (uid_t
)ULONG_MAX
&& errno
== ERANGE
)) {
182 warnx("illegal gid");
185 #ifndef OPEN_DIRECTORY
193 p_class(char *p
, struct passwd
*pw
, ENTRY
*ep __unused
)
195 #ifndef OPEN_DIRECTORY
196 if (!(pw
->pw_class
= strdup(p
))) {
197 warnx("can't save entry");
207 p_change(char *p
, struct passwd
*pw
, ENTRY
*ep __unused
)
209 #ifndef OPEN_DIRECTORY
210 if (!atot(p
, &pw
->pw_change
))
212 warnx("illegal date for change field");
219 p_expire(char *p
, struct passwd
*pw
, ENTRY
*ep __unused
)
221 #ifndef OPEN_DIRECTORY
222 if (!atot(p
, &pw
->pw_expire
))
224 warnx("illegal date for expire field");
231 p_gecos(char *p
, struct passwd
*pw __unused
, ENTRY
*ep
)
233 #ifndef OPEN_DIRECTORY
234 if (!(ep
->save
= strdup(p
))) {
235 warnx("can't save entry");
244 p_hdir(char *p
, struct passwd
*pw
, ENTRY
*ep __unused
)
247 warnx("empty home directory field");
250 #ifndef OPEN_DIRECTORY
251 if (!(pw
->pw_dir
= strdup(p
))) {
252 warnx("can't save entry");
262 p_shell(char *p
, struct passwd
*pw
, ENTRY
*ep __unused
)
265 #ifdef OPEN_DIRECTORY
268 memset(pw
, 0, sizeof(lpw
));
272 #ifndef OPEN_DIRECTORY
274 pw
->pw_shell
= strdup(_PATH_BSHELL
);
277 /* only admin can change from or to "restricted" shells */
278 if (!master_mode
&& pw
->pw_shell
&& !ok_shell(pw
->pw_shell
)) {
279 warnx("%s: current shell non-standard", pw
->pw_shell
);
282 #endif /* !OPEN_DIRECTORY */
285 warnx("%s: non-standard shell", p
);
288 #ifndef OPEN_DIRECTORY
289 pw
->pw_shell
= strdup(p
);
292 #ifndef OPEN_DIRECTORY
294 pw
->pw_shell
= dup_shell(p
);
296 warnx("can't save entry");
300 if (stat(pw
->pw_shell
, &sbuf
) < 0) {
302 warnx("WARNING: shell '%s' does not exist",
305 warn("WARNING: can't stat shell '%s'", pw
->pw_shell
);
308 if (!S_ISREG(sbuf
.st_mode
)) {
309 warnx("WARNING: shell '%s' is not a regular file",
313 if ((sbuf
.st_mode
& (S_IXOTH
| S_IXGRP
| S_IXUSR
)) == 0) {
314 warnx("WARNING: shell '%s' is not executable", pw
->pw_shell
);
321 #ifdef OPEN_DIRECTORY
322 #include <uuid/uuid.h>
325 p_uuid(char *p
, struct passwd
*pw __unused
, ENTRY
*ep
)
328 if (uuid_parse(p
, uu
) != 0) {
329 warnx("invalid UUID");
336 display_string(CFDictionaryRef attrs
, CFStringRef attrName
, const char* prompt
, FILE *fp
)
338 CFTypeRef value
= CFSTR("");
339 CFArrayRef values
= CFDictionaryGetValue(attrs
, attrName
);
341 value
= CFArrayGetCount(values
) > 0 ? CFArrayGetValueAtIndex(values
, 0) : NULL
;
342 if (value
&& CFGetTypeID(value
) != CFStringGetTypeID()) value
= NULL
;
344 cfprintf(fp
, "%s: %@\n", prompt
, value
);
346 #endif /* OPEN_DIRECTORY */