1 /* $NetBSD: field.c,v 1.12 2009/04/11 12:10:02 lukem Exp $ */
4 * Copyright (c) 1988, 1993, 1994
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 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)field.c 8.4 (Berkeley) 4/2/94";
37 __RCSID("$NetBSD: field.c,v 1.12 2009/04/11 12:10:02 lukem Exp $");
41 #include <sys/param.h>
54 #include "pathnames.h"
58 p_login(const char *p
, struct passwd
*pw
, ENTRY
*ep
)
62 warnx("empty login field");
66 warnx("login names may not begin with a hyphen");
69 if (!(pw
->pw_name
= strdup(p
))) {
70 warnx("can't save entry");
74 warnx("\'.\' is dangerous in a login name");
76 if (isupper((unsigned char)*p
)) {
77 warnx("upper-case letters are dangerous in a login name");
85 p_passwd(const char *p
, struct passwd
*pw
, ENTRY
*ep
)
88 if (!(pw
->pw_passwd
= strdup(p
))) {
89 warnx("can't save password entry");
98 p_uid(const char *p
, struct passwd
*pw
, ENTRY
*ep
)
104 warnx("empty uid field");
107 if (!isdigit((unsigned char)*p
)) {
108 warnx("illegal uid");
112 id
= strtoul(p
, &np
, 10);
114 * We don't need to check the return value of strtoul()
115 * since ULONG_MAX is greater than UID_MAX.
117 if (*np
|| id
> UID_MAX
) {
118 warnx("illegal uid");
121 pw
->pw_uid
= (uid_t
)id
;
127 p_gid(const char *p
, struct passwd
*pw
, ENTRY
*ep
)
134 warnx("empty gid field");
137 if (!isdigit((unsigned char)*p
)) {
138 if (!(gr
= getgrnam(p
))) {
139 warnx("unknown group %s", p
);
142 pw
->pw_gid
= gr
->gr_gid
;
146 id
= strtoul(p
, &np
, 10);
148 * We don't need to check the return value of strtoul()
149 * since ULONG_MAX is greater than GID_MAX.
151 if (*np
|| id
> GID_MAX
) {
152 warnx("illegal gid");
155 pw
->pw_gid
= (gid_t
)id
;
161 p_class(const char *p
, struct passwd
*pw
, ENTRY
*ep
)
164 if (!(pw
->pw_class
= strdup(p
))) {
165 warnx("can't save entry");
174 p_change(const char *p
, struct passwd
*pw
, ENTRY
*ep
)
177 if (!atot(p
, &pw
->pw_change
))
179 warnx("illegal date for change field");
185 p_expire(const char *p
, struct passwd
*pw
, ENTRY
*ep
)
188 if (!atot(p
, &pw
->pw_expire
))
190 warnx("illegal date for expire field");
196 p_gecos(const char *p
, struct passwd
*pw
, ENTRY
*ep
)
199 if (!(ep
->save
= strdup(p
))) {
200 warnx("can't save entry");
208 p_hdir(const char *p
, struct passwd
*pw
, ENTRY
*ep
)
212 warnx("empty home directory field");
215 if (!(pw
->pw_dir
= strdup(p
))) {
216 warnx("can't save entry");
224 p_shell(const char *p
, struct passwd
*pw
, ENTRY
*ep
)
229 if (!(pw
->pw_shell
= strdup(_PATH_BSHELL
))) {
230 warnx("can't save entry");
235 /* only admin can change from or to "restricted" shells */
236 if (uid
&& pw
->pw_shell
&& !ok_shell(pw
->pw_shell
)) {
237 warnx("%s: current shell non-standard", pw
->pw_shell
);
240 if (!(t
= ok_shell(p
))) {
242 warnx("%s: non-standard shell", p
);
248 if (!(pw
->pw_shell
= strdup(p
))) {
249 warnx("can't save entry");