Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/vipw Add a new "-d" option which allows to specifiy...
details: https://anonhg.NetBSD.org/src/rev/1d144ca54567
branches: trunk
changeset: 500138:1d144ca54567
user: tron <tron%NetBSD.org@localhost>
date: Wed Dec 06 14:04:25 2000 +0000
description:
Add a new "-d" option which allows to specifiy the root directory of the
password database.
diffstat:
usr.sbin/vipw/vipw.8 | 14 +++++++++++++-
usr.sbin/vipw/vipw.c | 49 ++++++++++++++++++++++++++++++-------------------
2 files changed, 43 insertions(+), 20 deletions(-)
diffs (157 lines):
diff -r 38ad80ff0854 -r 1d144ca54567 usr.sbin/vipw/vipw.8
--- a/usr.sbin/vipw/vipw.8 Wed Dec 06 13:54:08 2000 +0000
+++ b/usr.sbin/vipw/vipw.8 Wed Dec 06 14:04:25 2000 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: vipw.8,v 1.8 2000/08/04 14:58:52 ad Exp $
+.\" $NetBSD: vipw.8,v 1.9 2000/12/06 14:04:25 tron Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -41,6 +41,9 @@
.Nd edit the password file
.Sh SYNOPSIS
.Nm
+.Bk -words
+.Op Fl d Ar directory
+.Ek
.Sh DESCRIPTION
.Nm
edits the password file after setting the appropriate locks,
@@ -73,6 +76,15 @@
is completed, the password file is unavailable for other updates
and the new information is not available to programs.
.Pp
+The options are as follows:
+.Bl -tag -width flag
+.It Fl d Ar directory
+Change the root directory of the generated files from
+.Dq Pa
+to
+.Ar directory .
+.El
+.Pp
If a
.Nm
session is killed it may leave
diff -r 38ad80ff0854 -r 1d144ca54567 usr.sbin/vipw/vipw.c
--- a/usr.sbin/vipw/vipw.c Wed Dec 06 13:54:08 2000 +0000
+++ b/usr.sbin/vipw/vipw.c Wed Dec 06 14:04:25 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vipw.c,v 1.6 1998/12/09 12:40:15 christos Exp $ */
+/* $NetBSD: vipw.c,v 1.7 2000/12/06 14:04:25 tron Exp $ */
/*
* Copyright (c) 1987, 1993, 1994
@@ -43,11 +43,12 @@
#if 0
static char sccsid[] = "@(#)vipw.c 8.3 (Berkeley) 4/2/94";
#else
-__RCSID("$NetBSD: vipw.c,v 1.6 1998/12/09 12:40:15 christos Exp $");
+__RCSID("$NetBSD: vipw.c,v 1.7 2000/12/06 14:04:25 tron Exp $");
#endif
#endif /* not lint */
#include <sys/types.h>
+#include <sys/param.h>
#include <sys/stat.h>
#include <err.h>
@@ -64,17 +65,24 @@
static void copyfile __P((int, int));
static void usage __P((void));
+char mpwd[MAXPATHLEN], mpwdl[MAXPATHLEN];
+
int
-main(argc, argv)
- int argc;
- char *argv[];
+main(int argc, char *argv[])
{
+ char *prefix;
int pfd, tfd;
struct stat begin, end;
int ch;
- while ((ch = getopt(argc, argv, "")) != -1) {
+ prefix = "";
+ while ((ch = getopt(argc, argv, "d:")) != -1) {
switch (ch) {
+ case 'd':
+ prefix = optarg;
+ if (pw_setprefix(prefix) < 0)
+ err(1, "%s", prefix);
+ break;
case '?':
default:
usage();
@@ -86,27 +94,31 @@
if (argc != 0)
usage();
+ (void)snprintf(mpwd, sizeof(mpwd), "%s%s", prefix, _PATH_MASTERPASSWD);
+ (void)snprintf(mpwdl, sizeof(mpwdl), "%s%s", prefix,
+ _PATH_MASTERPASSWD_LOCK);
+
pw_init();
tfd = pw_lock(0);
if (tfd < 0) {
if (errno == EEXIST)
errx(1, "the passwd file is busy.");
else
- err(1, "%s", _PATH_MASTERPASSWD_LOCK);
+ err(1, "%s", mpwdl);
}
- pfd = open(_PATH_MASTERPASSWD, O_RDONLY, 0);
+ pfd = open(mpwd, O_RDONLY, 0);
if (pfd < 0)
- pw_error(_PATH_MASTERPASSWD, 1, 1);
+ pw_error(mpwd, 1, 1);
copyfile(pfd, tfd);
(void)close(tfd);
for (;;) {
- if (stat(_PATH_MASTERPASSWD_LOCK, &begin))
- pw_error(_PATH_MASTERPASSWD_LOCK, 1, 1);
+ if (stat(mpwdl, &begin))
+ pw_error(mpwdl, 1, 1);
pw_edit(0, NULL);
- if (stat(_PATH_MASTERPASSWD_LOCK, &end))
- pw_error(_PATH_MASTERPASSWD_LOCK, 1, 1);
+ if (stat(mpwdl, &end))
+ pw_error(mpwdl, 1, 1);
if (begin.st_mtime == end.st_mtime) {
warnx("no changes made");
pw_error((char *)NULL, 0, 0);
@@ -119,8 +131,7 @@
}
static void
-copyfile(from, to)
- int from, to;
+copyfile(int from, int to)
{
int nr, nw, off;
char buf[8*1024];
@@ -128,16 +139,16 @@
while ((nr = read(from, buf, sizeof(buf))) > 0)
for (off = 0; off < nr; nr -= nw, off += nw)
if ((nw = write(to, buf + off, nr)) < 0)
- pw_error(_PATH_MASTERPASSWD_LOCK, 1, 1);
+ pw_error(mpwdl, 1, 1);
if (nr < 0)
- pw_error(_PATH_MASTERPASSWD, 1, 1);
+ pw_error(mpwd, 1, 1);
}
static void
-usage()
+usage(void)
{
extern char *__progname;
- (void)fprintf(stderr, "Usage: %s\n", __progname);
+ (void)fprintf(stderr, "Usage: %s [-d directory]\n", __progname);
exit(1);
}
Home |
Main Index |
Thread Index |
Old Index