undo RESPONSE hack -- is it worthwhile?
[unix-history] / usr / src / usr.sbin / pwd_mkdb / pw_scan.c
CommitLineData
d4653600
KB
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8#ifndef lint
9static char sccsid[] = "@(#)pw_scan.c 5.1 (Berkeley) %G%";
10#endif /* not lint */
11
12/*
13 * This module is used to "verify" password entries by chpass(1) and
14 * pwd_mkdb(8).
15 */
16
17#include <sys/param.h>
18#include <fcntl.h>
19#include <pwd.h>
20#include <errno.h>
21#include <stdio.h>
22#include <string.h>
23#include <stdlib.h>
24
25extern char *progname;
26
27pw_scan(bp, pw)
28 char *bp;
29 struct passwd *pw;
30{
31 register long id;
32 register int root;
33 register char *p, *sh;
34 char *getusershell();
35
36 if (!(pw->pw_name = strsep(&bp, ":"))) /* login */
37 goto fmt;
38 root = !strcmp(pw->pw_name, "root");
39
40 if (!(pw->pw_passwd = strsep(&bp, ":"))) /* passwd */
41 goto fmt;
42
43 if (!(p = strsep(&bp, ":"))) /* uid */
44 goto fmt;
45 id = atol(p);
46 if (root && id) {
47 (void)fprintf(stderr, "%s: root uid should be 0", progname);
48 return(0);
49 }
50 if (id > USHRT_MAX) {
51 (void)fprintf(stderr,
52 "%s: %s > max uid value (%d)", progname, p, USHRT_MAX);
53 return(0);
54 }
55 pw->pw_uid = id;
56
57 if (!(p = strsep(&bp, ":"))) /* gid */
58 goto fmt;
59 id = atol(p);
60 if (id > USHRT_MAX) {
61 (void)fprintf(stderr,
62 "%s: %s > max gid value (%d)", progname, p, USHRT_MAX);
63 return(0);
64 }
65 pw->pw_gid = id;
66
67 pw->pw_class = strsep(&bp, ":"); /* class */
68 if (!(p = strsep(&bp, ":"))) /* change */
69 goto fmt;
70 pw->pw_change = atol(p);
71 if (!(p = strsep(&bp, ":"))) /* expire */
72 goto fmt;
73 pw->pw_expire = atol(p);
74 pw->pw_gecos = strsep(&bp, ":"); /* gecos */
75 pw->pw_dir = strsep(&bp, ":"); /* directory */
76 if (!(pw->pw_shell = strsep(&bp, ":"))) /* shell */
77 goto fmt;
78
79 p = pw->pw_shell;
80 if (root && *p) /* empty == /bin/sh */
81 for (setusershell();;) {
82 if (!(sh = getusershell())) {
83 (void)fprintf(stderr,
84 "%s: warning, unknown root shell\n",
85 progname);
86 break;
87 }
88 if (!strcmp(p, sh))
89 break;
90 }
91
92 if (p = strsep(&bp, ":")) { /* too many */
93fmt: (void)fprintf(stderr, "%s: corrupted entry\n", progname);
94 return(0);
95 }
96 return(1);
97}