146381Sbostic /*- 261863Sbostic * Copyright (c) 1990, 1993 361863Sbostic * The Regents of the University of California. All rights reserved. 446381Sbostic * 546381Sbostic * %sccs.include.redist.c% 646381Sbostic */ 746381Sbostic 846381Sbostic #ifndef lint 9*66581Spendry static char sccsid[] = "@(#)pw_scan.c 8.2 (Berkeley) 04/01/94"; 1046381Sbostic #endif /* not lint */ 1146381Sbostic 1246381Sbostic /* 1346381Sbostic * This module is used to "verify" password entries by chpass(1) and 1446381Sbostic * pwd_mkdb(8). 1546381Sbostic */ 1646381Sbostic 1746381Sbostic #include <sys/param.h> 18*66581Spendry 19*66581Spendry #include <err.h> 2046381Sbostic #include <fcntl.h> 2146381Sbostic #include <pwd.h> 2246381Sbostic #include <errno.h> 2346381Sbostic #include <stdio.h> 2446381Sbostic #include <string.h> 2546381Sbostic #include <stdlib.h> 26*66581Spendry #include <unistd.h> 2746381Sbostic 28*66581Spendry #include "pw_scan.h" 2946381Sbostic 30*66581Spendry int 3146381Sbostic pw_scan(bp, pw) 3246381Sbostic char *bp; 3346381Sbostic struct passwd *pw; 3446381Sbostic { 35*66581Spendry long id; 36*66581Spendry int root; 37*66581Spendry char *p, *sh; 3846381Sbostic 3946381Sbostic if (!(pw->pw_name = strsep(&bp, ":"))) /* login */ 4046381Sbostic goto fmt; 4146381Sbostic root = !strcmp(pw->pw_name, "root"); 4246381Sbostic 4346381Sbostic if (!(pw->pw_passwd = strsep(&bp, ":"))) /* passwd */ 4446381Sbostic goto fmt; 4546381Sbostic 4646381Sbostic if (!(p = strsep(&bp, ":"))) /* uid */ 4746381Sbostic goto fmt; 4846381Sbostic id = atol(p); 4946381Sbostic if (root && id) { 50*66581Spendry warnx("root uid should be 0"); 51*66581Spendry return (0); 5246381Sbostic } 5346381Sbostic if (id > USHRT_MAX) { 54*66581Spendry warnx("%s > max uid value (%d)", p, USHRT_MAX); 55*66581Spendry return (0); 5646381Sbostic } 5746381Sbostic pw->pw_uid = id; 5846381Sbostic 5946381Sbostic if (!(p = strsep(&bp, ":"))) /* gid */ 6046381Sbostic goto fmt; 6146381Sbostic id = atol(p); 6246381Sbostic if (id > USHRT_MAX) { 63*66581Spendry warnx("%s > max gid value (%d)", p, USHRT_MAX); 64*66581Spendry return (0); 6546381Sbostic } 6646381Sbostic pw->pw_gid = id; 6746381Sbostic 6846381Sbostic pw->pw_class = strsep(&bp, ":"); /* class */ 6946381Sbostic if (!(p = strsep(&bp, ":"))) /* change */ 7046381Sbostic goto fmt; 7146381Sbostic pw->pw_change = atol(p); 7246381Sbostic if (!(p = strsep(&bp, ":"))) /* expire */ 7346381Sbostic goto fmt; 7446381Sbostic pw->pw_expire = atol(p); 7546381Sbostic pw->pw_gecos = strsep(&bp, ":"); /* gecos */ 7646381Sbostic pw->pw_dir = strsep(&bp, ":"); /* directory */ 7746381Sbostic if (!(pw->pw_shell = strsep(&bp, ":"))) /* shell */ 7846381Sbostic goto fmt; 7946381Sbostic 8046381Sbostic p = pw->pw_shell; 8146381Sbostic if (root && *p) /* empty == /bin/sh */ 8246381Sbostic for (setusershell();;) { 8346381Sbostic if (!(sh = getusershell())) { 84*66581Spendry warnx("warning, unknown root shell"); 8546381Sbostic break; 8646381Sbostic } 8746381Sbostic if (!strcmp(p, sh)) 8846381Sbostic break; 8946381Sbostic } 9046381Sbostic 9146381Sbostic if (p = strsep(&bp, ":")) { /* too many */ 92*66581Spendry fmt: warnx("corrupted entry"); 93*66581Spendry return (0); 9446381Sbostic } 95*66581Spendry return (1); 9646381Sbostic } 97