Sun Mar 15 20:03:49 2009 UTC ()
Pull up following revision(s) (requested by mlelstv in ticket #562):
	usr.sbin/user/user.c: revision 1.121
bin/40994: Michael van Elst: usermod -l change password so user is unable to
login. User getpwnam_r to avoid trashing result of previous call to getpwnam().


(snj)
diff -r1.120 -r1.120.4.1 src/usr.sbin/user/user.c

cvs diff -r1.120 -r1.120.4.1 src/usr.sbin/user/user.c (expand / switch to unified diff)

--- src/usr.sbin/user/user.c 2008/07/21 13:37:00 1.120
+++ src/usr.sbin/user/user.c 2009/03/15 20:03:49 1.120.4.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: user.c,v 1.120 2008/07/21 13:37:00 lukem Exp $ */ 1/* $NetBSD: user.c,v 1.120.4.1 2009/03/15 20:03:49 snj Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1999 Alistair G. Crooks. All rights reserved. 4 * Copyright (c) 1999 Alistair G. Crooks. All rights reserved.
5 * Copyright (c) 2005 Liam J. Foy. All rights reserved. 5 * Copyright (c) 2005 Liam J. Foy. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -23,27 +23,27 @@ @@ -23,27 +23,27 @@
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31#include <sys/cdefs.h> 31#include <sys/cdefs.h>
32 32
33#ifndef lint 33#ifndef lint
34__COPYRIGHT("@(#) Copyright (c) 1999\ 34__COPYRIGHT("@(#) Copyright (c) 1999\
35 The NetBSD Foundation, Inc. All rights reserved."); 35 The NetBSD Foundation, Inc. All rights reserved.");
36__RCSID("$NetBSD: user.c,v 1.120 2008/07/21 13:37:00 lukem Exp $"); 36__RCSID("$NetBSD: user.c,v 1.120.4.1 2009/03/15 20:03:49 snj Exp $");
37#endif 37#endif
38 38
39#include <sys/types.h> 39#include <sys/types.h>
40#include <sys/param.h> 40#include <sys/param.h>
41#include <sys/stat.h> 41#include <sys/stat.h>
42 42
43#include <ctype.h> 43#include <ctype.h>
44#include <dirent.h> 44#include <dirent.h>
45#include <err.h> 45#include <err.h>
46#include <fcntl.h> 46#include <fcntl.h>
47#include <grp.h> 47#include <grp.h>
48#ifdef EXTENSIONS 48#ifdef EXTENSIONS
49#include <login_cap.h> 49#include <login_cap.h>
@@ -1375,46 +1375,48 @@ is_local(char *name, const char *file) @@ -1375,46 +1375,48 @@ is_local(char *name, const char *file)
1375 if (strncmp(buf, name, len) == 0 && buf[len] == ':') { 1375 if (strncmp(buf, name, len) == 0 && buf[len] == ':') {
1376 ret = 1; 1376 ret = 1;
1377 break; 1377 break;
1378 } 1378 }
1379 } 1379 }
1380 (void)fclose(fp); 1380 (void)fclose(fp);
1381 return ret; 1381 return ret;
1382} 1382}
1383 1383
1384/* modify a user */ 1384/* modify a user */
1385static int 1385static int
1386moduser(char *login_name, char *newlogin, user_t *up, int allow_samba) 1386moduser(char *login_name, char *newlogin, user_t *up, int allow_samba)
1387{ 1387{
1388 struct passwd *pwp; 1388 struct passwd *pwp, pw;
1389 struct group *grp; 1389 struct group *grp;
1390 const char *homedir; 1390 const char *homedir;
1391 char *locked_pwd; 1391 char *locked_pwd;
1392 size_t colonc; 1392 size_t colonc;
1393 size_t loginc; 1393 size_t loginc;
1394 size_t len; 1394 size_t len;
1395 FILE *master; 1395 FILE *master;
1396 char newdir[MaxFileNameLen]; 1396 char newdir[MaxFileNameLen];
1397 char buf[MaxEntryLen]; 1397 char buf[MaxEntryLen];
 1398 char pwbuf[MaxEntryLen];
1398 char *colon; 1399 char *colon;
1399 int masterfd; 1400 int masterfd;
1400 int ptmpfd; 1401 int ptmpfd;
1401 int error; 1402 int error;
1402 1403
1403 if (!valid_login(newlogin, allow_samba)) { 1404 if (!valid_login(newlogin, allow_samba)) {
1404 errx(EXIT_FAILURE, "Can't modify user `%s': invalid login name", 1405 errx(EXIT_FAILURE, "Can't modify user `%s': invalid login name",
1405 login_name); 1406 login_name);
1406 } 1407 }
1407 if ((pwp = getpwnam(login_name)) == NULL) { 1408 if (getpwnam_r(login_name, &pw, pwbuf, sizeof(pwbuf), &pwp) != 0
 1409 || pwp == NULL) {
1408 errx(EXIT_FAILURE, "Can't modify user `%s': no such user", 1410 errx(EXIT_FAILURE, "Can't modify user `%s': no such user",
1409 login_name); 1411 login_name);
1410 } 1412 }
1411 if (!is_local(login_name, _PATH_MASTERPASSWD)) { 1413 if (!is_local(login_name, _PATH_MASTERPASSWD)) {
1412 errx(EXIT_FAILURE, "Can't modify user `%s': must be a local user", 1414 errx(EXIT_FAILURE, "Can't modify user `%s': must be a local user",
1413 login_name); 1415 login_name);
1414 } 1416 }
1415 /* keep dir name in case we need it for '-m' */ 1417 /* keep dir name in case we need it for '-m' */
1416 homedir = pwp->pw_dir; 1418 homedir = pwp->pw_dir;
1417 1419
1418 if ((masterfd = open(_PATH_MASTERPASSWD, O_RDONLY)) < 0) { 1420 if ((masterfd = open(_PATH_MASTERPASSWD, O_RDONLY)) < 0) {
1419 err(EXIT_FAILURE, "Can't modify user `%s': can't open `%s'", 1421 err(EXIT_FAILURE, "Can't modify user `%s': can't open `%s'",
1420 login_name, _PATH_MASTERPASSWD); 1422 login_name, _PATH_MASTERPASSWD);