Subject: Re: bin/11695: chown no longer reports "invalid user name" when appropriate
To: None <mike@pelley.com>
From: Simon Burge <simonb@wasabisystems.com>
List: netbsd-bugs
Date: 12/12/2000 09:55:55
mike@pelley.com wrote:

> >Number:         11695
> >Category:       bin
> >Synopsis:       chown no longer reports "invalid user name" when appropriate

If I read your patch correctly, there is now two calls to getpwnam()
for the same userid.  Either a_uid() could be changed to take an extra
parameter as to abort or not (see my patch below with seems to DTRT for
a couple of tests) or change from getpwnam() to uid_from_user() so that
at least multiple passwd lookups are cached.

Simon.
--
Simon Burge                            <simonb@wasabisystems.com>
NetBSD Sales, Support and Service:  http://www.wasabisystems.com/


Index: chown.c
===================================================================
RCS file: /cvsroot/basesrc/usr.sbin/chown/chown.c,v
retrieving revision 1.24
diff -d -p -u -r1.24 chown.c
--- chown.c	2000/08/25 06:25:59	1.24
+++ chown.c	2000/12/11 22:53:10
@@ -64,7 +64,7 @@ __RCSID("$NetBSD: chown.c,v 1.24 2000/08
 #include <unistd.h>
 
 static void	a_gid __P((const char *));
-static int	a_uid __P((const char *));
+static int	a_uid __P((const char *, int));
 static id_t	id __P((const char *, const char *));
 	int	main __P((int, char **));
 static void	usage __P((void));
@@ -153,13 +153,13 @@ main(argc, argv)
 		}
 #ifdef SUPPORT_DOT
 		else if ((cp = strrchr(*argv, '.')) != NULL) {
-			if (a_uid(*argv) == -1) {
+			if (a_uid(*argv, 0) == -1) {
 				*cp++ = '\0';
 				a_gid(cp);
 			}
 		}
 #endif
-		(void) a_uid(*argv);
+		(void) a_uid(*argv, 1);
 	} else
 		a_gid(*argv);
 
@@ -232,8 +232,9 @@ a_gid(s)
 }
 
 static int
-a_uid(s)
+a_uid(s, abort)
 	const char *s;
+	int abort;
 {
 	struct passwd *pw;
 
@@ -244,7 +245,7 @@ a_uid(s)
 		uid = pw->pw_uid;
 		return 0;
 	}
-	if (isalpha(*s))
+	if (isalpha(*s) && !abort)
 		return -1;
 	uid = id(s, "user");
 	return 0;