From 73ca041dfcdee40aae69e5de3412a1148126ec4e Mon Sep 17 00:00:00 2001 From: Peter Wemm Date: Mon, 12 Aug 1996 14:45:26 +0000 Subject: 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. --- chpass/chpass.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'chpass/chpass.c') diff --git a/chpass/chpass.c b/chpass/chpass.c index 9a7b8a6..2c5e79d 100644 --- a/chpass/chpass.c +++ b/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 @@ -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); } -- cgit v1.2.3-56-ge451