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