summaryrefslogtreecommitdiff
path: root/usr.bin/chpass
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/chpass')
-rw-r--r--usr.bin/chpass/Makefile12
-rw-r--r--usr.bin/chpass/chpass.18
-rw-r--r--usr.bin/chpass/chpass.c66
-rw-r--r--usr.bin/chpass/chpass.h8
-rw-r--r--usr.bin/chpass/edit.c24
-rw-r--r--usr.bin/chpass/pw_copy.c113
-rw-r--r--usr.bin/chpass/pw_copy.h38
7 files changed, 50 insertions, 219 deletions
diff --git a/usr.bin/chpass/Makefile b/usr.bin/chpass/Makefile
index 752792ba265..f6f19c838f6 100644
--- a/usr.bin/chpass/Makefile
+++ b/usr.bin/chpass/Makefile
@@ -1,18 +1,16 @@
-# $NetBSD: Makefile,v 1.5 1995/03/26 04:55:22 glass Exp $
+# $NetBSD: Makefile,v 1.6 1996/05/15 21:50:39 jtc Exp $
# @(#)Makefile 8.2 (Berkeley) 4/2/94
PROG= chpass
-SRCS= chpass.c edit.c field.c pw_copy.c pw_scan.c pw_util.c pw_yp.c table.c util.c getpwent.c
+SRCS= chpass.c edit.c field.c pw_yp.c table.c util.c getpwent.c
BINOWN= root
BINMODE=4555
-.PATH: ${.CURDIR}/../../usr.sbin/pwd_mkdb ${.CURDIR}/../../usr.sbin/vipw \
- ${.CURDIR}/../../lib/libc/gen
-CFLAGS+=-I${.CURDIR}/../../usr.sbin/pwd_mkdb -I${.CURDIR}/../../usr.sbin/vipw
+.PATH: ${.CURDIR}/../../lib/libc/gen
LINKS= ${BINDIR}/chpass ${BINDIR}/chfn ${BINDIR}/chpass ${BINDIR}/chsh
MLINKS= chpass.1 chfn.1 chpass.1 chsh.1
CFLAGS+=-DYP
-DPADD+= ${LIBRPCSVC}
-LDADD+= -lrpcsvc
+DPADD+= ${LIBRPCSVC} ${LIBUTIL}
+LDADD+= -lrpcsvc -lutil
.include <bsd.prog.mk>
diff --git a/usr.bin/chpass/chpass.1 b/usr.bin/chpass/chpass.1
index f077510addb..1a66a07f49b 100644
--- a/usr.bin/chpass/chpass.1
+++ b/usr.bin/chpass/chpass.1
@@ -1,4 +1,4 @@
-.\" $NetBSD: chpass.1,v 1.6 1995/09/14 06:10:53 jtc Exp $
+.\" $NetBSD: chpass.1,v 1.7 1996/05/15 21:50:40 jtc Exp $
.\"
.\" Copyright (c) 1988, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -205,8 +205,10 @@ with the user.
The user database
.It Pa /etc/passwd
A Version 7 format password file
-.It Pa /etc/chpass.XXXXXX
-Temporary copy of the password file
+.It Pa /etc/ptmp
+Lock file for the passwd database
+.It Pa /etc/pw.XXXXXX
+Temporary copy of the user passwd information
.It Pa /etc/shells
The list of approved shells
.El
diff --git a/usr.bin/chpass/chpass.c b/usr.bin/chpass/chpass.c
index ba5a7efdade..a959b2fda5d 100644
--- a/usr.bin/chpass/chpass.c
+++ b/usr.bin/chpass/chpass.c
@@ -1,4 +1,4 @@
-/* $NetBSD: chpass.c,v 1.7 1995/07/28 07:01:32 phil Exp $ */
+/* $NetBSD: chpass.c,v 1.8 1996/05/15 21:50:43 jtc Exp $ */
/*-
* Copyright (c) 1988, 1993, 1994
@@ -43,7 +43,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)chpass.c 8.4 (Berkeley) 4/2/94";
#else
-static char rcsid[] = "$NetBSD: chpass.c,v 1.7 1995/07/28 07:01:32 phil Exp $";
+static char rcsid[] = "$NetBSD: chpass.c,v 1.8 1996/05/15 21:50:43 jtc Exp $";
#endif
#endif /* not lint */
@@ -61,10 +61,7 @@ static char rcsid[] = "$NetBSD: chpass.c,v 1.7 1995/07/28 07:01:32 phil Exp $";
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-
-#include <pw_scan.h>
-#include <pw_util.h>
-#include "pw_copy.h"
+#include <util.h>
#include "chpass.h"
#include "pathnames.h"
@@ -89,8 +86,8 @@ main(argc, argv)
{
enum { NEWSH, LOADENTRY, EDITENTRY } op;
struct passwd *pw, lpw;
- int ch, pfd, tfd;
- char *arg;
+ int ch, pfd, tfd, dfd;
+ char *arg, tempname[] = "/etc/pw.XXXXXX";
#ifdef YP
use_yp = _yp_check(NULL);
@@ -178,45 +175,27 @@ main(argc, argv)
exit(1);
}
- /*
- * The temporary file/file descriptor usage is a little tricky here.
- * 1: We start off with two fd's, one for the master password
- * file (used to lock everything), and one for a temporary file.
- * 2: Display() gets an fp for the temporary file, and copies the
- * user's information into it. It then gives the temporary file
- * to the user and closes the fp, closing the underlying fd.
- * 3: The user edits the temporary file some number of times.
- * 4: Verify() gets an fp for the temporary file, and verifies the
- * contents. It can't use an fp derived from the step #2 fd,
- * because the user's editor may have created a new instance of
- * the file. Once the file is verified, its contents are stored
- * in a password structure. The verify routine closes the fp,
- * closing the underlying fd.
- * 5: Delete the temporary file.
- * 6: Get a new temporary file/fd. Pw_copy() gets an fp for it
- * file and copies the master password file into it, replacing
- * the user record with a new one. We can't use the first
- * temporary file for this because it was owned by the user.
- * Pw_copy() closes its fp, flushing the data and closing the
- * underlying file descriptor. We can't close the master
- * password fp, or we'd lose the lock.
- * 7: Call pw_mkdb() (which renames the temporary file) and exit.
- * The exit closes the master passwd fp/fd.
- */
+ /* Get the passwd lock file and open the passwd file for reading. */
pw_init();
- pfd = pw_lock();
- tfd = pw_tmp();
-
+ tfd = pw_lock(0);
+ if (tfd < 0)
+ errx(1, "the passwd file is busy.");
+ pfd = open(_PATH_MASTERPASSWD, O_RDONLY, 0);
+ if (pfd < 0)
+ pw_error(_PATH_MASTERPASSWD, 1, 1);
+
+ /* Edit the user passwd information if requested. */
if (op == EDITENTRY) {
- display(tfd, pw);
- edit(pw);
+ dfd = mkstemp(tempname);
+ if (dfd < 0)
+ pw_error(tempname, 1, 1);
+ display(tempname, dfd, pw);
+ edit(tempname, pw);
(void)unlink(tempname);
- tfd = pw_tmp();
}
-
+
#ifdef YP
if (use_yp) {
- (void)unlink(tempname);
if (pw_yp(pw, uid))
pw_error((char *)NULL, 0, 1);
else
@@ -224,9 +203,12 @@ main(argc, argv)
}
else
#endif /* YP */
+
+ /* Copy the passwd file to the lock file, updating pw. */
pw_copy(pfd, tfd, pw);
- if (!pw_mkdb())
+ /* Now finish the passwd file update. */
+ if (pw_mkdb() < 0)
pw_error((char *)NULL, 0, 1);
exit(0);
diff --git a/usr.bin/chpass/chpass.h b/usr.bin/chpass/chpass.h
index 52997da455c..087556f4131 100644
--- a/usr.bin/chpass/chpass.h
+++ b/usr.bin/chpass/chpass.h
@@ -1,4 +1,4 @@
-/* $NetBSD: chpass.h,v 1.3 1995/03/26 04:55:26 glass Exp $ */
+/* $NetBSD: chpass.h,v 1.4 1996/05/15 21:50:44 jtc Exp $ */
/*
* Copyright (c) 1988, 1993, 1994
@@ -54,8 +54,8 @@ extern ENTRY list[];
extern uid_t uid;
int atot __P((char *, time_t *));
-void display __P((int, struct passwd *));
-void edit __P((struct passwd *));
+void display __P((char *, int, struct passwd *));
+void edit __P((char *, struct passwd *));
char *ok_shell __P((char *));
int p_change __P((char *, struct passwd *, ENTRY *));
int p_class __P((char *, struct passwd *, ENTRY *));
@@ -69,4 +69,4 @@ int p_passwd __P((char *, struct passwd *, ENTRY *));
int p_shell __P((char *, struct passwd *, ENTRY *));
int p_uid __P((char *, struct passwd *, ENTRY *));
char *ttoa __P((time_t));
-int verify __P((struct passwd *));
+int verify __P((char *, struct passwd *));
diff --git a/usr.bin/chpass/edit.c b/usr.bin/chpass/edit.c
index 10c82bb5722..afd0d7f862e 100644
--- a/usr.bin/chpass/edit.c
+++ b/usr.bin/chpass/edit.c
@@ -1,4 +1,4 @@
-/* $NetBSD: edit.c,v 1.5 1995/07/28 07:03:41 phil Exp $ */
+/* $NetBSD: edit.c,v 1.6 1996/05/15 21:50:45 jtc Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)edit.c 8.3 (Berkeley) 4/2/94";
#else
-static char rcsid[] = "$NetBSD: edit.c,v 1.5 1995/07/28 07:03:41 phil Exp $";
+static char rcsid[] = "$NetBSD: edit.c,v 1.6 1996/05/15 21:50:45 jtc Exp $";
#endif
#endif /* not lint */
@@ -53,16 +53,13 @@ static char rcsid[] = "$NetBSD: edit.c,v 1.5 1995/07/28 07:03:41 phil Exp $";
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-
-#include <pw_scan.h>
-#include <pw_util.h>
+#include <util.h>
#include "chpass.h"
-extern char *tempname;
-
void
-edit(pw)
+edit(tempname, pw)
+ char *tempname;
struct passwd *pw;
{
struct stat begin, end;
@@ -70,14 +67,15 @@ edit(pw)
for (;;) {
if (stat(tempname, &begin))
pw_error(tempname, 1, 1);
- pw_edit(1);
+ pw_edit(1, tempname);
if (stat(tempname, &end))
pw_error(tempname, 1, 1);
if (begin.st_mtime == end.st_mtime) {
warnx("no changes made");
+ unlink(tempname);
pw_error(NULL, 0, 0);
}
- if (verify(pw))
+ if (verify(tempname, pw))
break;
pw_prompt();
}
@@ -89,7 +87,8 @@ edit(pw)
* set conditional flag if the user gets to edit the shell.
*/
void
-display(fd, pw)
+display(tempname, fd, pw)
+ char *tempname;
int fd;
struct passwd *pw;
{
@@ -140,7 +139,8 @@ display(fd, pw)
}
int
-verify(pw)
+verify(tempname, pw)
+ char *tempname;
struct passwd *pw;
{
ENTRY *ep;
diff --git a/usr.bin/chpass/pw_copy.c b/usr.bin/chpass/pw_copy.c
index fc1dc24083e..e69de29bb2d 100644
--- a/usr.bin/chpass/pw_copy.c
+++ b/usr.bin/chpass/pw_copy.c
@@ -1,113 +0,0 @@
-/* $NetBSD: pw_copy.c,v 1.3 1995/03/26 04:55:30 glass Exp $ */
-
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)pw_copy.c 8.4 (Berkeley) 4/2/94";
-#else
-static char rcsid[] = "$NetBSD: pw_copy.c,v 1.3 1995/03/26 04:55:30 glass Exp $";
-#endif
-#endif /* not lint */
-
-/*
- * This module is used to copy the master password file, replacing a single
- * record, by chpass(1) and passwd(1).
- */
-
-#include <err.h>
-#include <pwd.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <pw_util.h>
-#include "pw_copy.h"
-
-extern char *tempname;
-
-void
-pw_copy(ffd, tfd, pw)
- int ffd, tfd;
- struct passwd *pw;
-{
- FILE *from, *to;
- int done;
- char *p, buf[8192];
-
- if (!(from = fdopen(ffd, "r")))
- pw_error(_PATH_MASTERPASSWD, 1, 1);
- if (!(to = fdopen(tfd, "w")))
- pw_error(tempname, 1, 1);
-
- for (done = 0; fgets(buf, sizeof(buf), from);) {
- if (!strchr(buf, '\n')) {
- warnx("%s: line too long", _PATH_MASTERPASSWD);
- pw_error(NULL, 0, 1);
- }
- if (done) {
- (void)fprintf(to, "%s", buf);
- if (ferror(to))
- goto err;
- continue;
- }
- if (!(p = strchr(buf, ':'))) {
- warnx("%s: corrupted entry", _PATH_MASTERPASSWD);
- pw_error(NULL, 0, 1);
- }
- *p = '\0';
- if (strcmp(buf, pw->pw_name)) {
- *p = ':';
- (void)fprintf(to, "%s", buf);
- if (ferror(to))
- goto err;
- continue;
- }
- (void)fprintf(to, "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s\n",
- pw->pw_name, pw->pw_passwd, pw->pw_uid, pw->pw_gid,
- pw->pw_class, pw->pw_change, pw->pw_expire, pw->pw_gecos,
- pw->pw_dir, pw->pw_shell);
- done = 1;
- if (ferror(to))
- goto err;
- }
- if (!done)
- (void)fprintf(to, "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s\n",
- pw->pw_name, pw->pw_passwd, pw->pw_uid, pw->pw_gid,
- pw->pw_class, pw->pw_change, pw->pw_expire, pw->pw_gecos,
- pw->pw_dir, pw->pw_shell);
-
- if (ferror(to))
-err: pw_error(NULL, 1, 1);
- (void)fclose(to);
-}
diff --git a/usr.bin/chpass/pw_copy.h b/usr.bin/chpass/pw_copy.h
index ae41c5ad79b..e69de29bb2d 100644
--- a/usr.bin/chpass/pw_copy.h
+++ b/usr.bin/chpass/pw_copy.h
@@ -1,38 +0,0 @@
-/* $NetBSD: pw_copy.h,v 1.2 1995/03/26 04:55:32 glass Exp $ */
-
-/*
- * Copyright (c) 1994
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)pw_copy.h 8.1 (Berkeley) 4/2/94
- */
-
-void pw_copy __P((int, int, struct passwd *));