Subject: bin/11695: chown no longer reports "invalid user name" when appropriate
To: None <gnats-bugs@gnats.netbsd.org>
From: None <mike@pelley.com>
List: netbsd-bugs
Date: 12/11/2000 12:08:15
>Number:         11695
>Category:       bin
>Synopsis:       chown no longer reports "invalid user name" when appropriate
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Dec 11 12:08:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator:     Mike Pelley
>Release:        current, 1.5 and 1.4.3
>Organization:
Foundation

>Environment:
System: NetBSD trantor.worldmap.net 1.5L NetBSD 1.5L (TRANTOR) #1: Fri Dec 8 00:00:04 EST 2000 mike@trantor.worldmap.net:/usr/src/sys/arch/i386/compile/TRANTOR i386

Architecture: i386
Machine: i386
>Description:

chown does not report the "invalid user name" error anymore.  This error appears to exist in 1.4.3 and 1.5 as well.

>How-To-Repeat:

Attempt to chown a file to an unknown user.  Notice that no error is reported.

>Fix:

Apply the following patch.  Note: this patch leaves the if in a_uid expanded and expands the if in a_gid to match.  If this is inappropriate both can be compressed (there appears to be no mention of this in /usr/share/misc/style).


Index: chown.c
===================================================================
RCS file: /usr/cvsroot/basesrc/usr.sbin/chown/chown.c,v
retrieving revision 1.24
diff -u -r1.24 chown.c
--- chown.c	2000/08/25 06:25:59	1.24
+++ chown.c	2000/12/11 20:06:18
@@ -64,7 +64,7 @@
 #include <unistd.h>
 
 static void	a_gid __P((const char *));
-static int	a_uid __P((const char *));
+static void	a_uid __P((const char *));
 static id_t	id __P((const char *, const char *));
 	int	main __P((int, char **));
 static void	usage __P((void));
@@ -153,13 +153,13 @@
 		}
 #ifdef SUPPORT_DOT
 		else if ((cp = strrchr(*argv, '.')) != NULL) {
-			if (a_uid(*argv) == -1) {
+			if (getpwnam(*argv) == NULL) {
 				*cp++ = '\0';
 				a_gid(cp);
 			}
 		}
 #endif
-		(void) a_uid(*argv);
+		a_uid(*argv);
 	} else
 		a_gid(*argv);
 
@@ -228,26 +228,28 @@
 
 	if (*s == '\0')			/* Argument was "uid[:.]". */
 		return;
-	gid = ((gr = getgrnam(s)) == NULL) ? id(s, "group") : gr->gr_gid;
+	gr = getgrnam(s);
+	if (gr == NULL)
+		gid = id(s, "group");
+	else
+		gid = gr->gr_gid;
+	return;
 }
 
-static int
+static void
 a_uid(s)
 	const char *s;
 {
 	struct passwd *pw;
 
 	if (*s == '\0')			/* Argument was "[:.]gid". */
-		return 0;
+		return;
 	pw = getpwnam(s);
-	if (pw != NULL) {
+	if (pw == NULL)
+		uid = id(s, "user");
+	else
 		uid = pw->pw_uid;
-		return 0;
-	}
-	if (isalpha(*s))
-		return -1;
-	uid = id(s, "user");
-	return 0;
+	return;
 }
 
 static id_t
>Release-Note:
>Audit-Trail:
>Unformatted: