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.
This commit is contained in:
Peter Wemm 1996-08-12 14:45:26 +00:00
parent ce70b6caf8
commit 366982a550
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=17544
5 changed files with 38 additions and 13 deletions

View File

@ -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 \

View File

@ -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);
}

View File

@ -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,

View File

@ -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, },

View File

@ -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))