From 58f855136d43c7a2d0230149b4738f9d7acd8b31 Mon Sep 17 00:00:00 2001 From: Sheldon Hearn Date: Sat, 26 Jun 1999 07:16:42 +0000 Subject: Add -d option to vipw(8) to allow selection of an alternative directory for the password files. PR: 2703 Submitted by: jmg --- libutil/pw_util.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'libutil/pw_util.c') diff --git a/libutil/pw_util.c b/libutil/pw_util.c index 2003cd6..cdfcc4d 100644 --- a/libutil/pw_util.c +++ b/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); } -- cgit v1.2.3-56-ge451