diff options
-rw-r--r-- | lib/libutil/pw_util.c | 22 | ||||
-rw-r--r-- | usr.sbin/vipw/pw_util.c | 22 | ||||
-rw-r--r-- | usr.sbin/vipw/vipw.8 | 11 | ||||
-rw-r--r-- | usr.sbin/vipw/vipw.c | 21 |
4 files changed, 57 insertions, 19 deletions
diff --git a/lib/libutil/pw_util.c b/lib/libutil/pw_util.c index 2003cd6..cdfcc4d 100644 --- a/lib/libutil/pw_util.c +++ b/lib/libutil/pw_util.c @@ -36,7 +36,7 @@ static const char sccsid[] = "@(#)pw_util.c 8.3 (Berkeley) 4/2/94"; #endif static const char rcsid[] = - "$Id: pw_util.c,v 1.12 1998/12/13 01:36:45 dillon Exp $"; + "$Id: pw_util.c,v 1.13 1998/12/13 01:39:32 dillon Exp $"; #endif /* not lint */ /* @@ -66,6 +66,8 @@ static const char rcsid[] = extern char *tempname; static pid_t editpid = -1; static int lockfd; +char *mppath = _PATH_PWD; +char *masterpasswd = _PATH_MASTERPASSWD; void pw_cont(sig) @@ -118,9 +120,9 @@ pw_lock() for (;;) { struct stat st; - lockfd = open(_PATH_MASTERPASSWD, O_RDONLY, 0); + lockfd = open(masterpasswd, O_RDONLY, 0); if (lockfd < 0 || fcntl(lockfd, F_SETFD, 1) == -1) - err(1, "%s", _PATH_MASTERPASSWD); + err(1, "%s", masterpasswd); if (flock(lockfd, LOCK_EX|LOCK_NB)) errx(1, "the password db file is busy"); @@ -142,10 +144,13 @@ pw_lock() int pw_tmp() { - static char path[MAXPATHLEN] = _PATH_MASTERPASSWD; + static char path[MAXPATHLEN]; int fd; char *p; + strncpy(path, masterpasswd, MAXPATHLEN - 1); + path[MAXPATHLEN] = '\0'; + if ((p = strrchr(path, '/'))) ++p; else @@ -168,11 +173,12 @@ char *username; if (!(pid = fork())) { if(!username) { warnx("rebuilding the database..."); - execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p", tempname, NULL); + execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p", "-d", mppath, + tempname, NULL); } else { warnx("updating the database..."); - execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p", "-u", - username, tempname, NULL); + execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p", "-d", mppath, + "-u", username, tempname, NULL); } pw_error(_PATH_PWD_MKDB, 1, 1); } @@ -250,7 +256,7 @@ pw_error(name, err, eval) warnx("NIS information unchanged"); else #endif /* YP */ - warnx("%s: unchanged", _PATH_MASTERPASSWD); + warnx("%s: unchanged", masterpasswd); (void)unlink(tempname); exit(eval); } diff --git a/usr.sbin/vipw/pw_util.c b/usr.sbin/vipw/pw_util.c index 2003cd6..cdfcc4d 100644 --- a/usr.sbin/vipw/pw_util.c +++ b/usr.sbin/vipw/pw_util.c @@ -36,7 +36,7 @@ static const char sccsid[] = "@(#)pw_util.c 8.3 (Berkeley) 4/2/94"; #endif static const char rcsid[] = - "$Id: pw_util.c,v 1.12 1998/12/13 01:36:45 dillon Exp $"; + "$Id: pw_util.c,v 1.13 1998/12/13 01:39:32 dillon Exp $"; #endif /* not lint */ /* @@ -66,6 +66,8 @@ static const char rcsid[] = extern char *tempname; static pid_t editpid = -1; static int lockfd; +char *mppath = _PATH_PWD; +char *masterpasswd = _PATH_MASTERPASSWD; void pw_cont(sig) @@ -118,9 +120,9 @@ pw_lock() for (;;) { struct stat st; - lockfd = open(_PATH_MASTERPASSWD, O_RDONLY, 0); + lockfd = open(masterpasswd, O_RDONLY, 0); if (lockfd < 0 || fcntl(lockfd, F_SETFD, 1) == -1) - err(1, "%s", _PATH_MASTERPASSWD); + err(1, "%s", masterpasswd); if (flock(lockfd, LOCK_EX|LOCK_NB)) errx(1, "the password db file is busy"); @@ -142,10 +144,13 @@ pw_lock() int pw_tmp() { - static char path[MAXPATHLEN] = _PATH_MASTERPASSWD; + static char path[MAXPATHLEN]; int fd; char *p; + strncpy(path, masterpasswd, MAXPATHLEN - 1); + path[MAXPATHLEN] = '\0'; + if ((p = strrchr(path, '/'))) ++p; else @@ -168,11 +173,12 @@ char *username; if (!(pid = fork())) { if(!username) { warnx("rebuilding the database..."); - execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p", tempname, NULL); + execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p", "-d", mppath, + tempname, NULL); } else { warnx("updating the database..."); - execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p", "-u", - username, tempname, NULL); + execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p", "-d", mppath, + "-u", username, tempname, NULL); } pw_error(_PATH_PWD_MKDB, 1, 1); } @@ -250,7 +256,7 @@ pw_error(name, err, eval) warnx("NIS information unchanged"); else #endif /* YP */ - warnx("%s: unchanged", _PATH_MASTERPASSWD); + warnx("%s: unchanged", masterpasswd); (void)unlink(tempname); exit(eval); } diff --git a/usr.sbin/vipw/vipw.8 b/usr.sbin/vipw/vipw.8 index ca70b5e..fdb56d4 100644 --- a/usr.sbin/vipw/vipw.8 +++ b/usr.sbin/vipw/vipw.8 @@ -39,6 +39,7 @@ .Nd edit the password file .Sh SYNOPSIS .Nm vipw +.Op Fl d Ar directory .Sh DESCRIPTION .Nm Vipw edits the password file after setting the appropriate locks, @@ -51,6 +52,16 @@ to try again later. The default editor for is .Xr vi 1 . .Pp +When run without options, +.Nm vipw +will work with the password files in +.Pa /etc . +The +.Fl d +option may be used to specify an alternative +.Ar directory +to work with. +.Pp .Nm Vipw performs a number of consistency checks on the password entries, and will not allow a password file with a diff --git a/usr.sbin/vipw/vipw.c b/usr.sbin/vipw/vipw.c index 30b789e..c555690 100644 --- a/usr.sbin/vipw/vipw.c +++ b/usr.sbin/vipw/vipw.c @@ -42,7 +42,7 @@ static const char copyright[] = static char sccsid[] = "@(#)vipw.c 8.3 (Berkeley) 4/2/94"; #endif static const char rcsid[] = - "$Id$"; + "$Id: vipw.c,v 1.5 1997/10/27 07:53:22 charnier Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -57,6 +57,8 @@ static const char rcsid[] = #include "pw_util.h" +extern char *mppath; +extern char *masterpasswd; char *tempname; void copyfile __P((int, int)); @@ -71,8 +73,21 @@ main(argc, argv) struct stat begin, end; int ch; - while ((ch = getopt(argc, argv, "")) != -1) + while ((ch = getopt(argc, argv, "d:")) != -1) switch (ch) { + case 'd': + if ((masterpasswd = malloc(strlen(optarg) + + strlen(_MASTERPASSWD) + 2)) == NULL) + err(1, NULL); + strcpy(masterpasswd, optarg); + if (masterpasswd[strlen(masterpasswd) - 1] != '/') + masterpasswd[strlen(masterpasswd)] = '/'; + strcat(masterpasswd, _MASTERPASSWD); + if ((mppath = strdup(optarg)) == NULL) + err(1, NULL); + if (mppath[strlen(mppath) - 1] == '/') + mppath[strlen(mppath) - 1] = '\0'; + break; case '?': default: usage(); @@ -126,6 +141,6 @@ static void usage() { - (void)fprintf(stderr, "usage: vipw\n"); + (void)fprintf(stderr, "usage: vipw [ -d directory ]\n"); exit(1); } |