diff options
author | Garrett Wollman <wollman@FreeBSD.org> | 1995-01-14 23:14:25 +0000 |
---|---|---|
committer | Garrett Wollman <wollman@FreeBSD.org> | 1995-01-14 23:14:25 +0000 |
commit | 11947d5ba71b18faf8967bc5de38bc0138e5fe8a (patch) | |
tree | a4fba994f93336b2d0b7ee66edfddec51be139f2 /chpass/chpass.c | |
parent | 07dd4bf0f472c2c70379719ac2ead591982a1bf5 (diff) | |
download | pw-darwin-11947d5ba71b18faf8967bc5de38bc0138e5fe8a.tar.gz pw-darwin-11947d5ba71b18faf8967bc5de38bc0138e5fe8a.tar.zst pw-darwin-11947d5ba71b18faf8967bc5de38bc0138e5fe8a.zip |
Add a `-p' option, allowing the super-user to directly set a user's
encrypted password. Kerberized `login' might use this, if I get around
to implementing the complete Allspice System behavior.
Diffstat (limited to 'chpass/chpass.c')
-rw-r--r-- | chpass/chpass.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/chpass/chpass.c b/chpass/chpass.c index 0852c53..f101101 100644 --- a/chpass/chpass.c +++ b/chpass/chpass.c @@ -38,7 +38,9 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)chpass.c 8.4 (Berkeley) 4/2/94"; +static char sccsid[] = "From: @(#)chpass.c 8.4 (Berkeley) 4/2/94"; +static char rcsid[] = + "$Id$"; #endif /* not lint */ #include <sys/param.h> @@ -76,13 +78,13 @@ main(argc, argv) int argc; char **argv; { - enum { NEWSH, LOADENTRY, EDITENTRY } op; + enum { NEWSH, LOADENTRY, EDITENTRY, NEWPW } op; struct passwd *pw, lpw; int ch, pfd, tfd; char *arg; op = EDITENTRY; - while ((ch = getopt(argc, argv, "a:s:")) != EOF) + while ((ch = getopt(argc, argv, "a:p:s:")) != EOF) switch(ch) { case 'a': op = LOADENTRY; @@ -92,6 +94,10 @@ main(argc, argv) op = NEWSH; arg = optarg; break; + case 'p': + op = NEWPW; + arg = optarg; + break; case '?': default: usage(); @@ -101,7 +107,7 @@ main(argc, argv) uid = getuid(); - if (op == EDITENTRY || op == NEWSH) + if (op == EDITENTRY || op == NEWSH || op == NEWPW) switch(argc) { case 0: if (!(pw = getpwuid(uid))) @@ -133,6 +139,16 @@ main(argc, argv) exit(1); } + if (op == NEWPW) { + if (uid) + baduser(); + + if(strchr(arg, ':')) { + errx(1, "invalid format for password"); + } + pw->pw_passwd = arg; + } + /* * The temporary file/file descriptor usage is a little tricky here. * 1: We start off with two fd's, one for the master password @@ -179,7 +195,6 @@ main(argc, argv) void baduser() { - errx(1, "%s", strerror(EACCES)); } @@ -187,6 +202,7 @@ void usage() { - (void)fprintf(stderr, "usage: chpass [-a list] [-s shell] [user]\n"); + (void)fprintf(stderr, + "usage: chpass [-a list] [-p encpass] [-s shell] [user]\n"); exit(1); } |