[PATCH] chown user: w/o group

Luciano Miguel Ferreira Rocha strange at nsk.no-ip.org
Sat Sep 23 14:19:14 UTC 2006


On Fri, Sep 22, 2006 at 09:10:52PM +0100, Luciano Miguel Ferreira Rocha wrote:
> Anyway, I don't mind where it ends. I'll make a version w/o that
> function and send it.

Actually, the new version ended up being cleaner and shorter. The only
think i'm unhappy is with the second parse of passwd if the first get of
the new file's uid was with getpwnam. I now use the result of get_ug_id
for a getpwuid.

But I now prefer this version over my first one.

Regards,
Luciano Rocha

-- 
lfr
0/0
-------------- next part --------------
diff -ur busybox-1.2.1.orig/coreutils/chown.c busybox-1.2.1/coreutils/chown.c
--- busybox-1.2.1.orig/coreutils/chown.c	2006-06-30 23:42:07.000000000 +0100
+++ busybox-1.2.1/coreutils/chown.c	2006-09-23 14:45:59.000000000 +0100
@@ -54,16 +54,28 @@
 	argv += optind;
 
 	/* First, check if there is a group name here */
-	if ((groupName = strchr(*argv, '.')) == NULL) {
-		groupName = strchr(*argv, ':');
+	if ((groupName = strchr(*argv, ':')) == NULL) {
+		groupName = strchr(*argv, '.');
 	}
 
-	/* Check for the username and groupname */
+	/* Check for groupname */
 	if (groupName) {
 		*groupName++ = '\0';
-		gid = get_ug_id(groupName, bb_xgetgrnam);
+		if (*groupName)
+			gid = get_ug_id(groupName, bb_xgetgrnam);
+	}
+	/* Check for username */
+	if (**argv) {
+		uid = get_ug_id(*argv, bb_xgetpwnam);
+		if (groupName && !*groupName) {
+			/* groupname defined but empty, use username's default gid */
+			struct passwd *pwe;
+			
+			if (!(pwe = getpwuid(uid)))
+				bb_error_msg_and_die("unknown user name/uid: %s", *argv);
+			gid = pwe->pw_gid;
+		}
 	}
-	if (--groupName != *argv) uid = get_ug_id(*argv, bb_xgetpwnam);
 	++argv;
 
 	/* Ok, ready to do the deed now */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20060923/38ba608c/attachment-0002.pgp 


More information about the busybox mailing list