diff options
author | peter <peter@FreeBSD.org> | 1996-08-12 14:45:26 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1996-08-12 14:45:26 +0000 |
commit | 6b18c72cfcfbbcb9ef4ef47dba3d309c3ad51740 (patch) | |
tree | 1527176a279bb4dc9a6e348a851ec74ee4f7e79b /usr.bin/chpass | |
parent | 665b6e261ba076b16c6c02125a104c2297ae5a96 (diff) | |
download | FreeBSD-src-6b18c72cfcfbbcb9ef4ef47dba3d309c3ad51740.zip FreeBSD-src-6b18c72cfcfbbcb9ef4ef47dba3d309c3ad51740.tar.gz |
Add new option to chpass: -e "expire" ; change the account expire time
from a script as if it was done in the interactive editor.
When reassembling the gecos string, trim any excess trailing commas, they
look ugly in the passwd file. :-)
Have a simple Makefile tweak to prevent mortal users from changing their
fullname. As ISP's we have seem some real bizzare stuff here..
When decoding the change/expire string, allow the month number as a
synonym for the name of the month.. (ie: 1 as well as Jan or January)
Note that using numbers means there's a chance that you can get bitten
if you're not used to the American DD-MM-YY order.
Diffstat (limited to 'usr.bin/chpass')
-rw-r--r-- | usr.bin/chpass/Makefile | 3 | ||||
-rw-r--r-- | usr.bin/chpass/chpass.c | 25 | ||||
-rw-r--r-- | usr.bin/chpass/edit.c | 3 | ||||
-rw-r--r-- | usr.bin/chpass/table.c | 4 | ||||
-rw-r--r-- | usr.bin/chpass/util.c | 16 |
5 files changed, 38 insertions, 13 deletions
diff --git a/usr.bin/chpass/Makefile b/usr.bin/chpass/Makefile index 0f582b9..45d2767 100644 --- a/usr.bin/chpass/Makefile +++ b/usr.bin/chpass/Makefile @@ -17,6 +17,9 @@ MLINKS= chpass.1 chfn.1 chpass.1 chsh.1 COPTS+= -DYP -I. -I${.CURDIR}/../../libexec/ypxfr \ -I${.CURDIR}/../../usr.sbin/rpc.yppasswdd -Dyp_error=warnx +#Some people need this, uncomment to activate +#COPTS+= -DRESTRICT_FULLNAME_CHANGE + SRCS+= yppasswd_private_xdr.c yppasswd_comm.c yp_clnt.c \ yppasswd_clnt.c pw_yp.c ypxfr_misc.c CLEANFILES= yp_clnt.c yp.h yppasswd_clnt.c yppasswd.h \ diff --git a/usr.bin/chpass/chpass.c b/usr.bin/chpass/chpass.c index 9a7b8a6..2c5e79d 100644 --- a/usr.bin/chpass/chpass.c +++ b/usr.bin/chpass/chpass.c @@ -40,7 +40,7 @@ static char copyright[] = #ifndef lint static char sccsid[] = "From: @(#)chpass.c 8.4 (Berkeley) 4/2/94"; static char rcsid[] = - "$Id: chpass.c,v 1.9 1996/07/01 19:38:07 guido Exp $"; + "$Id: chpass.c,v 1.10 1996/07/14 16:42:33 guido Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -82,7 +82,7 @@ main(argc, argv) int argc; char **argv; { - enum { NEWSH, LOADENTRY, EDITENTRY, NEWPW } op; + enum { NEWSH, LOADENTRY, EDITENTRY, NEWPW, NEWEXP } op; struct passwd *pw, lpw; char *username = NULL; int ch, pfd, tfd; @@ -94,9 +94,9 @@ main(argc, argv) op = EDITENTRY; #ifdef YP - while ((ch = getopt(argc, argv, "a:p:s:d:h:oly")) != EOF) + while ((ch = getopt(argc, argv, "a:p:s:e:d:h:oly")) != EOF) #else - while ((ch = getopt(argc, argv, "a:p:s:")) != EOF) + while ((ch = getopt(argc, argv, "a:p:s:e:")) != EOF) #endif switch(ch) { case 'a': @@ -111,6 +111,10 @@ main(argc, argv) op = NEWPW; arg = optarg; break; + case 'e': + op = NEWEXP; + arg = optarg; + break; #ifdef YP case 'h': #ifdef PARANOID @@ -156,7 +160,7 @@ main(argc, argv) uid = getuid(); - if (op == EDITENTRY || op == NEWSH || op == NEWPW) + if (op == EDITENTRY || op == NEWSH || op == NEWPW || op == NEWEXP) switch(argc) { #ifdef YP case 0: @@ -189,6 +193,13 @@ main(argc, argv) pw_error((char *)NULL, 0, 1); } + if (op == NEWEXP) { + if (uid) /* only root can change expire */ + baduser(); + if (p_expire(arg, pw, (ENTRY *)NULL)) + pw_error((char *)NULL, 0, 1); + } + if (op == LOADENTRY) { if (uid) baduser(); @@ -272,9 +283,9 @@ usage() (void)fprintf(stderr, #ifdef YP - "usage: chpass [-l] [-y] [-d domain [-h host]] [-a list] [-p encpass] [-s shell] [user]\n"); + "usage: chpass [-l] [-y] [-d domain [-h host]] [-a list] [-p encpass] [-s shell] [-e mmm dd yy] [user]\n"); #else - "usage: chpass [-a list] [-p encpass] [-s shell] [user]\n"); + "usage: chpass [-a list] [-p encpass] [-s shell] [-e mmm dd yy] [user]\n"); #endif exit(1); } diff --git a/usr.bin/chpass/edit.c b/usr.bin/chpass/edit.c index bca6ace..cf87fdf 100644 --- a/usr.bin/chpass/edit.c +++ b/usr.bin/chpass/edit.c @@ -233,6 +233,9 @@ bad: (void)fclose(fp); (void)sprintf(pw->pw_gecos = p, "%s,%s,%s,%s", list[E_NAME].save, list[E_LOCATE].save, list[E_BPHONE].save, list[E_HPHONE].save); + while ((len = strlen(pw->pw_gecos)) && pw->pw_gecos[len - 1] == ',') + pw->pw_gecos[len - 1] = '\0'; + if (snprintf(buf, sizeof(buf), "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s", pw->pw_name, pw->pw_passwd, pw->pw_uid, pw->pw_gid, pw->pw_class, diff --git a/usr.bin/chpass/table.c b/usr.bin/chpass/table.c index 46a12d1..3363e1d 100644 --- a/usr.bin/chpass/table.c +++ b/usr.bin/chpass/table.c @@ -50,7 +50,11 @@ ENTRY list[] = { { "class", p_class, 1, 5, e1, }, { "change", p_change, 1, 6, NULL, }, { "expire", p_expire, 1, 6, NULL, }, +#ifdef RESTRICT_FULLNAME_CHANGE /* do not allow fullname changes */ + { "full name", p_gecos, 1, 9, e2, }, +#else { "full name", p_gecos, 0, 9, e2, }, +#endif { "office phone", p_gecos, 0, 12, e2, }, { "home phone", p_gecos, 0, 10, e2, }, { "location", p_gecos, 0, 8, e2, }, diff --git a/usr.bin/chpass/util.c b/usr.bin/chpass/util.c index fe89d79..605a484 100644 --- a/usr.bin/chpass/util.c +++ b/usr.bin/chpass/util.c @@ -91,12 +91,16 @@ atot(p, store) } if (!(t = strtok(p, " \t"))) goto bad; - for (mp = months;; ++mp) { - if (!*mp) - goto bad; - if (!strncasecmp(*mp, t, 3)) { - month = mp - months + 1; - break; + if (isdigit(*t)) { + month = atoi(t); + } else { + for (mp = months;; ++mp) { + if (!*mp) + goto bad; + if (!strncasecmp(*mp, t, 3)) { + month = mp - months + 1; + break; + } } } if (!(t = strtok((char *)NULL, " \t,")) || !isdigit(*t)) |