]>
git.cameronkatri.com Git - pw-darwin.git/blob - libc/gen/pw_scan.c
64293a5527775ee5c447a9614cf851a53066fa82
2 * Copyright (c) 1990, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #if defined(LIBC_SCCS) && !defined(lint)
31 static char sccsid
[] = "@(#)pw_scan.c 8.3 (Berkeley) 4/2/94";
32 #endif /* LIBC_SCCS and not lint */
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
37 * This module is used to "verify" password entries by chpass(1) and
41 #include <sys/param.h>
55 * Some software assumes that IDs are short. We should emit warnings
56 * for id's which cannot be stored in a short, but we are more liberal
57 * by default, warning for IDs greater than USHRT_MAX.
59 * If pw_big_ids_warning is -1 on entry to pw_scan(), it will be set based
60 * on the existence of PW_SCAN_BIG_IDS in the environment.
62 * It is believed all baseline system software that can not handle the
63 * normal ID sizes is now gone so pw_big_ids_warning is disabled for now.
64 * But the code has been left in place in case end-users want to re-enable
65 * it and/or for the next time the ID sizes get bigger but pieces of the
68 static int pw_big_ids_warning
= 0;
71 __pw_scan(char *bp
, struct passwd
*pw
, int flags
)
78 if (pw_big_ids_warning
== -1)
79 pw_big_ids_warning
= getenv("PW_SCAN_BIG_IDS") == NULL
? 1 : 0;
82 if (!(pw
->pw_name
= strsep(&bp
, ":"))) /* login */
84 root
= !strcmp(pw
->pw_name
, "root");
85 if (pw
->pw_name
[0] && (pw
->pw_name
[0] != '+' || pw
->pw_name
[1] == '\0'))
86 pw
->pw_fields
|= _PWF_NAME
;
88 if (!(pw
->pw_passwd
= strsep(&bp
, ":"))) /* passwd */
91 pw
->pw_fields
|= _PWF_PASSWD
;
93 if (!(p
= strsep(&bp
, ":"))) /* uid */
96 pw
->pw_fields
|= _PWF_UID
;
98 if (pw
->pw_name
[0] != '+' && pw
->pw_name
[0] != '-') {
99 if (flags
& _PWSCAN_WARN
)
100 warnx("no uid for user %s", pw
->pw_name
);
105 temp
= strtoul(p
, &ep
, 10);
106 if ((temp
== ULONG_MAX
&& errno
== ERANGE
) || temp
> UID_MAX
) {
107 if (flags
& _PWSCAN_WARN
)
108 warnx("%s > max uid value (%u)", p
, UID_MAX
);
113 if (flags
& _PWSCAN_WARN
)
114 warnx("%s uid is incorrect", p
);
118 if (flags
& _PWSCAN_WARN
)
119 warnx("root uid should be 0");
122 if (flags
& _PWSCAN_WARN
&& pw_big_ids_warning
&& id
> USHRT_MAX
) {
123 warnx("%s > recommended max uid value (%u)", p
, USHRT_MAX
);
124 /*return (0);*/ /* THIS SHOULD NOT BE FATAL! */
128 if (!(p
= strsep(&bp
, ":"))) /* gid */
131 pw
->pw_fields
|= _PWF_GID
;
133 if (pw
->pw_name
[0] != '+' && pw
->pw_name
[0] != '-') {
134 if (flags
& _PWSCAN_WARN
)
135 warnx("no gid for user %s", pw
->pw_name
);
140 temp
= strtoul(p
, &ep
, 10);
141 if ((temp
== ULONG_MAX
&& errno
== ERANGE
) || temp
> GID_MAX
) {
142 if (flags
& _PWSCAN_WARN
)
143 warnx("%s > max gid value (%u)", p
, GID_MAX
);
148 if (flags
& _PWSCAN_WARN
)
149 warnx("%s gid is incorrect", p
);
152 if (flags
& _PWSCAN_WARN
&& pw_big_ids_warning
&& id
> USHRT_MAX
) {
153 warnx("%s > recommended max gid value (%u)", p
, USHRT_MAX
);
154 /* return (0); This should not be fatal! */
158 if (flags
& _PWSCAN_MASTER
) {
159 if (!(pw
->pw_class
= strsep(&bp
, ":"))) /* class */
162 pw
->pw_fields
|= _PWF_CLASS
;
164 if (!(p
= strsep(&bp
, ":"))) /* change */
167 pw
->pw_fields
|= _PWF_CHANGE
;
168 pw
->pw_change
= atol(p
);
170 if (!(p
= strsep(&bp
, ":"))) /* expire */
173 pw
->pw_fields
|= _PWF_EXPIRE
;
174 pw
->pw_expire
= atol(p
);
176 if (!(pw
->pw_gecos
= strsep(&bp
, ":"))) /* gecos */
179 pw
->pw_fields
|= _PWF_GECOS
;
181 if (!(pw
->pw_dir
= strsep(&bp
, ":"))) /* directory */
184 pw
->pw_fields
|= _PWF_DIR
;
186 if (!(pw
->pw_shell
= strsep(&bp
, ":"))) /* shell */
190 if (root
&& *p
) { /* empty == /bin/sh */
191 for (setusershell();;) {
192 if (!(sh
= getusershell())) {
193 if (flags
& _PWSCAN_WARN
)
194 warnx("warning, unknown root shell");
203 pw
->pw_fields
|= _PWF_SHELL
;
205 if ((p
= strsep(&bp
, ":"))) { /* too many */
207 if (flags
& _PWSCAN_WARN
)
208 warnx("corrupted entry");