]>
git.saurik.com Git - apple/system_cmds.git/blob - system_cmds-597.1.1/pwd_mkdb.tproj/pw_scan.c
1 /* $OpenBSD: passwd.c,v 1.42 2003/06/26 16:34:42 deraadt Exp $ */
4 * Copyright (c) 1987, 1993, 1994, 1995
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #if defined(LIBC_SCCS) && !defined(lint)
33 static const char rcsid
[] = "$OpenBSD: passwd.c,v 1.42 2003/06/26 16:34:42 deraadt Exp $";
34 #endif /* LIBC_SCCS and not lint */
36 #include <sys/types.h>
39 #include <sys/resource.h>
58 pw_scan(char *bp
, struct passwd
*pw
, int *flags
)
64 if (flags
!= (int *)NULL
)
74 if (!(p
= strsep(&bp
, ":")) || *p
== '\0') /* login */
77 root
= !strcmp(pw
->pw_name
, "root");
79 if (!(pw
->pw_passwd
= strsep(&bp
, ":"))) /* passwd */
82 if (!(p
= strsep(&bp
, ":"))) /* uid */
84 id
= strtoul(p
, &p2
, 10);
86 warnx("root uid should be 0");
90 warnx("illegal uid field");
94 /* Apple's UID_MAX is too small (sizeof signed) 3091256 */
96 /* errno is set to ERANGE by strtoul(3) */
97 warnx("uid greater than %u", UID_MAX
-1);
101 pw
->pw_uid
= (uid_t
)id
;
102 if ((*p
== '\0') && (flags
!= (int *)NULL
))
103 *flags
|= _PASSWORD_NOUID
;
105 if (!(p
= strsep(&bp
, ":"))) /* gid */
107 id
= strtoul(p
, &p2
, 10);
109 warnx("illegal gid field");
113 /* Apple's UID_MAX is too small (sizeof signed) 3091256 */
115 /* errno is set to ERANGE by strtoul(3) */
116 warnx("gid greater than %u", UID_MAX
-1);
120 pw
->pw_gid
= (gid_t
)id
;
121 if ((*p
== '\0') && (flags
!= (int *)NULL
))
122 *flags
|= _PASSWORD_NOGID
;
124 pw
->pw_class
= strsep(&bp
, ":"); /* class */
125 if (!(p
= strsep(&bp
, ":"))) /* change */
127 pw
->pw_change
= atol(p
);
128 if ((*p
== '\0') && (flags
!= (int *)NULL
))
129 *flags
|= _PASSWORD_NOCHG
;
130 if (!(p
= strsep(&bp
, ":"))) /* expire */
132 pw
->pw_expire
= atol(p
);
133 if ((*p
== '\0') && (flags
!= (int *)NULL
))
134 *flags
|= _PASSWORD_NOEXP
;
135 pw
->pw_gecos
= strsep(&bp
, ":"); /* gecos */
136 pw
->pw_dir
= strsep(&bp
, ":"); /* directory */
137 if (!(pw
->pw_shell
= strsep(&bp
, ":"))) /* shell */
141 if (root
&& *p
) { /* empty == /bin/sh */
142 for (setusershell();;) {
143 if (!(sh
= getusershell())) {
144 warnx("warning, unknown root shell");
153 if ((p
= strsep(&bp
, ":"))) { /* too many */
154 fmt
: warnx("corrupted entry");