From bade5517cc35b7dc95175c1ef3aae896e6878370 Mon Sep 17 00:00:00 2001 From: deraadt Date: Tue, 23 Apr 1996 21:54:36 +0000 Subject: [PATCH] add "-d basedir" flag to pwd_mkdb. the use of "chroot" is incompatible with our cross compilation/installation goals... --- etc/Makefile | 2 +- usr.sbin/pwd_mkdb/pwd_mkdb.c | 56 +++++++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/etc/Makefile b/etc/Makefile index 020bd1d1ec9..f4a58a6d632 100644 --- a/etc/Makefile +++ b/etc/Makefile @@ -41,7 +41,7 @@ distribution: distrib-dirs install -c -o ${BINOWN} -g ${BINGRP} -m 664 ${BIN2} ${DESTDIR}/etc install -c -o root -g wheel -m 600 crontab ${DESTDIR}/var/cron/tabs/root install -c -o root -g wheel -m 600 master.passwd ${DESTDIR}/etc - chroot ${DESTDIR}/ pwd_mkdb -p /etc/master.passwd + pwd_mkdb -p -d ${DESTDIR} /etc/master.passwd install -c -o ${BINOWN} -g ${BINGRP} -m 555 \ MAKEDEV.local etc.${MACHINE}/MAKEDEV ${DESTDIR}/dev (cd root; \ diff --git a/usr.sbin/pwd_mkdb/pwd_mkdb.c b/usr.sbin/pwd_mkdb/pwd_mkdb.c index 86cbcf7d565..8ea7cab2f4c 100644 --- a/usr.sbin/pwd_mkdb/pwd_mkdb.c +++ b/usr.sbin/pwd_mkdb/pwd_mkdb.c @@ -40,7 +40,7 @@ static char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)pwd_mkdb.c 8.5 (Berkeley) 4/20/94";*/ -static char *rcsid = "$Id: pwd_mkdb.c,v 1.1.1.1 1995/10/18 08:48:01 deraadt Exp $"; +static char *rcsid = "$Id: pwd_mkdb.c,v 1.2 1996/04/23 21:55:49 deraadt Exp $"; #endif /* not lint */ #include @@ -80,12 +80,14 @@ HASHINFO openinfo = { static enum state { FILE_INSECURE, FILE_SECURE, FILE_ORIG } clean; static struct passwd pwd; /* password structure */ static char *pname; /* password file name */ +static char *basedir; void cleanup __P((void)); void error __P((char *)); void mv __P((char *, char *)); int scan __P((FILE *, struct passwd *, int *)); void usage __P((void)); +char *changedir __P((char *path, char *dir)); int main(argc, argv) @@ -103,13 +105,16 @@ main(argc, argv) DBT ypdata, ypkey; makeold = 0; - while ((ch = getopt(argc, argv, "pv")) != EOF) + while ((ch = getopt(argc, argv, "pvd:")) != EOF) switch(ch) { case 'p': /* create V7 "file.orig" */ makeold = 1; break; case 'v': /* backward compatible */ break; + case 'd': + basedir = optarg; + break; case '?': default: usage(); @@ -141,7 +146,8 @@ main(argc, argv) error(pname); /* Open the temporary insecure password database. */ - (void)snprintf(buf, sizeof(buf), "%s.tmp", _PATH_MP_DB); + (void)snprintf(buf, sizeof(buf), "%s.tmp", + changedir(_PATH_MP_DB, basedir)); dp = dbopen(buf, O_RDWR|O_CREAT|O_EXCL, PERM_INSECURE, DB_HASH, &openinfo); if (dp == NULL) @@ -256,7 +262,8 @@ main(argc, argv) } /* Open the temporary encrypted password database. */ - (void)snprintf(buf, sizeof(buf), "%s.tmp", _PATH_SMP_DB); + (void)snprintf(buf, sizeof(buf), "%s.tmp", + changedir(_PATH_SMP_DB, basedir)); edp = dbopen(buf, O_RDWR|O_CREAT|O_EXCL, PERM_SECURE, DB_HASH, &openinfo); if (!edp) @@ -327,13 +334,15 @@ main(argc, argv) (void)fclose(fp); /* Install as the real password files. */ - (void)snprintf(buf, sizeof(buf), "%s.tmp", _PATH_MP_DB); - mv(buf, _PATH_MP_DB); - (void)snprintf(buf, sizeof(buf), "%s.tmp", _PATH_SMP_DB); - mv(buf, _PATH_SMP_DB); + (void)snprintf(buf, sizeof(buf), "%s.tmp", + changedir(_PATH_MP_DB, basedir)); + mv(buf, changedir(_PATH_MP_DB, basedir)); + (void)snprintf(buf, sizeof(buf), "%s.tmp", + changedir(_PATH_SMP_DB, basedir)); + mv(buf, changedir(_PATH_SMP_DB, basedir)); if (makeold) { (void)snprintf(buf, sizeof(buf), "%s.orig", pname); - mv(buf, _PATH_PASSWD); + mv(buf, changedir(_PATH_PASSWD, basedir)); } /* * Move the master password LAST -- chpass(1), passwd(1) and vipw(8) @@ -341,7 +350,7 @@ main(argc, argv) * The rename means that everything is unlocked, as the original file * can no longer be accessed. */ - mv(pname, _PATH_MASTERPASSWD); + mv(pname, changedir(_PATH_MASTERPASSWD, basedir)); exit(0); } @@ -413,11 +422,13 @@ cleanup() (void)unlink(buf); /* FALLTHROUGH */ case FILE_SECURE: - (void)snprintf(buf, sizeof(buf), "%s.tmp", _PATH_SMP_DB); + (void)snprintf(buf, sizeof(buf), "%s.tmp", + changedir(_PATH_SMP_DB, basedir)); (void)unlink(buf); /* FALLTHROUGH */ case FILE_INSECURE: - (void)snprintf(buf, sizeof(buf), "%s.tmp", _PATH_MP_DB); + (void)snprintf(buf, sizeof(buf), "%s.tmp", + changedir(_PATH_MP_DB, basedir)); (void)unlink(buf); } } @@ -426,6 +437,25 @@ void usage() { - (void)fprintf(stderr, "usage: pwd_mkdb [-p] file\n"); + (void)fprintf(stderr, "usage: pwd_mkdb [-p] [-d basedir] file\n"); exit(1); } + +char * +changedir(path, dir) + char *path, *dir; +{ + static char fixed[MAXPATHLEN]; + char *p; + + if (!dir) + return (path); + + p = strrchr(path, '/'); + strcpy(fixed, dir); + if (p) { + strcat(fixed, "/"); + strcat(fixed, p + 1); + } + return (fixed); +} -- 2.20.1