diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2004-04-20 23:21:24 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2004-04-20 23:21:24 +0000 |
commit | 8db2b678974619797ec0d47670dc966ac139aad7 (patch) | |
tree | 79d137f6b429a414544d16fd2766f9ded60886ed /usr.bin | |
parent | a4ccbe5bc7e8df106f798254306616fb80e6922f (diff) |
Adapt to new pw_copy() API, closes PR 3698.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/chpass/chpass.c | 17 | ||||
-rw-r--r-- | usr.bin/passwd/local_passwd.c | 13 |
2 files changed, 21 insertions, 9 deletions
diff --git a/usr.bin/chpass/chpass.c b/usr.bin/chpass/chpass.c index 56f13c4de5e..905579ebad6 100644 --- a/usr.bin/chpass/chpass.c +++ b/usr.bin/chpass/chpass.c @@ -1,4 +1,4 @@ -/* $OpenBSD: chpass.c,v 1.29 2003/11/26 00:33:58 espie Exp $ */ +/* $OpenBSD: chpass.c,v 1.30 2004/04/20 23:21:23 millert Exp $ */ /* $NetBSD: chpass.c,v 1.8 1996/05/15 21:50:43 jtc Exp $ */ /*- @@ -40,7 +40,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)chpass.c 8.4 (Berkeley) 4/2/94"; #else -static char rcsid[] = "$OpenBSD: chpass.c,v 1.29 2003/11/26 00:33:58 espie Exp $"; +static char rcsid[] = "$OpenBSD: chpass.c,v 1.30 2004/04/20 23:21:23 millert Exp $"; #endif #endif /* not lint */ @@ -80,7 +80,7 @@ void usage(void); int main(int argc, char *argv[]) { - struct passwd *pw = NULL, lpw; + struct passwd *pw = NULL, *opw, lpw; int i, ch, pfd, tfd, dfd; char *arg = NULL; sigset_t fullset; @@ -170,12 +170,16 @@ main(int argc, char *argv[]) if (!pw_scan(arg, pw, NULL)) exit(1); } + if ((opw = pw_dup(pw)) == NULL) + err(1, NULL); /* Edit the user passwd information if requested. */ if (op == EDITENTRY) { char tempname[] = _PATH_VARTMP "pw.XXXXXXXXXX"; int edit_status; + if ((pw = pw_dup(pw)) == NULL) + pw_error(NULL, 1, 1); dfd = mkstemp(tempname); if (dfd == -1 || fcntl(dfd, F_SETFD, 1) == -1) pw_error(tempname, 1, 1); @@ -233,10 +237,13 @@ main(int argc, char *argv[]) #endif /* YP */ { /* Copy the passwd file to the lock file, updating pw. */ - pw_copy(pfd, tfd, pw); + pw_copy(pfd, tfd, pw, opw); + + /* If username changed we need to rebuild the entire db. */ + arg = !strcmp(opw->pw_name, pw->pw_name) ? pw->pw_name : NULL; /* Now finish the passwd file update. */ - if (pw_mkdb(pw->pw_name, 0) == -1) + if (pw_mkdb(arg, 0) == -1) pw_error(NULL, 0, 1); } diff --git a/usr.bin/passwd/local_passwd.c b/usr.bin/passwd/local_passwd.c index e0b9436f82d..5193e7f5e5e 100644 --- a/usr.bin/passwd/local_passwd.c +++ b/usr.bin/passwd/local_passwd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: local_passwd.c,v 1.31 2004/03/10 21:23:17 millert Exp $ */ +/* $OpenBSD: local_passwd.c,v 1.32 2004/04/20 23:21:23 millert Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -31,7 +31,7 @@ #ifndef lint /*static const char sccsid[] = "from: @(#)local_passwd.c 5.5 (Berkeley) 5/6/91";*/ -static const char rcsid[] = "$OpenBSD: local_passwd.c,v 1.31 2004/03/10 21:23:17 millert Exp $"; +static const char rcsid[] = "$OpenBSD: local_passwd.c,v 1.32 2004/04/20 23:21:23 millert Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -63,7 +63,7 @@ void kbintr(int); int local_passwd(char *uname, int authenticated) { - struct passwd *pw; + struct passwd *pw, *opw; login_cap_t *lc; sigset_t fullset; time_t period; @@ -78,6 +78,10 @@ local_passwd(char *uname, int authenticated) warnx("unknown user %s.", uname); return(1); } + if ((opw = pw_dup(pw)) == NULL) { + warn(NULL); + return(1); + } if ((lc = login_getclass(pw->pw_class)) == NULL) { warnx("unable to get login class for user %s.", uname); return(1); @@ -133,7 +137,8 @@ local_passwd(char *uname, int authenticated) pw_error(_PATH_MASTERPASSWD, 1, 1); /* Update master.passwd file and rebuild spwd.db. */ - pw_copy(pfd, tfd, pw); + pw_copy(pfd, tfd, pw, opw); + free(opw); if (pw_mkdb(uname, pwflags) < 0) pw_error(NULL, 0, 1); |