svn commit: trunk/busybox/coreutils

vda at busybox.net vda at busybox.net
Wed Jan 3 20:07:07 UTC 2007


Author: vda
Date: 2007-01-03 12:07:06 -0800 (Wed, 03 Jan 2007)
New Revision: 17145

Log:
chown: fix handling of "user.group" notation


Modified:
   trunk/busybox/coreutils/chown.c


Changeset:
Modified: trunk/busybox/coreutils/chown.c
===================================================================
--- trunk/busybox/coreutils/chown.c	2007-01-03 14:11:16 UTC (rev 17144)
+++ trunk/busybox/coreutils/chown.c	2007-01-03 20:07:06 UTC (rev 17145)
@@ -13,8 +13,7 @@
 
 #include "busybox.h"
 
-static uid_t uid = -1;
-static gid_t gid = -1;
+static struct bb_uidgid_t ugid = { -1, -1 };
 
 static int (*chown_func)(const char *, uid_t, gid_t) = chown;
 
@@ -38,12 +37,14 @@
 	// if (depth ... && S_ISLNK(statbuf->st_mode)) ....
 
 	if (!chown_func(fileName,
-				(uid == (uid_t)-1) ? statbuf->st_uid : uid,
-				(gid == (gid_t)-1) ? statbuf->st_gid : gid)) {
+			(ugid.uid == (uid_t)-1) ? statbuf->st_uid : ugid.uid,
+			(ugid.gid == (gid_t)-1) ? statbuf->st_gid : ugid.gid)
+	) {
 		if (OPT_VERBOSE
-		 || (OPT_CHANGED && (statbuf->st_uid != uid || statbuf->st_gid != gid))
+		 || (OPT_CHANGED && (statbuf->st_uid != ugid.uid || statbuf->st_gid != ugid.gid))
 		) {
-			printf("changed ownership of '%s' to %u:%u\n", fileName, uid, gid);
+			printf("changed ownership of '%s' to %u:%u\n",
+					fileName, ugid.uid, ugid.gid);
 		}
 		return TRUE;
 	}
@@ -65,23 +66,21 @@
 
 	/* First, check if there is a group name here */
 	groupName = strchr(*argv, '.'); /* deprecated? */
-	if (!groupName) {
+	if (!groupName)
 		groupName = strchr(*argv, ':');
-	}
+	else
+		*groupName = ':'; /* replace '.' with ':' */
 
 	/* First, try parsing "user[:[group]]" */
         if (!groupName) { /* "user" */
-		uid = get_ug_id(*argv, xuname2uid);
+		ugid.uid = get_ug_id(*argv, xuname2uid);
 	} else if (groupName == *argv) { /* ":group" */
-		gid = get_ug_id(groupName + 1, xgroup2gid);
+		ugid.gid = get_ug_id(groupName + 1, xgroup2gid);
 	} else {
-    		struct bb_uidgid_t ugid;
 		if (!groupName[1]) /* "user:" */
 			*groupName = '\0';
 		if (!get_uidgid(&ugid, *argv, 1))
 			bb_error_msg_and_die("unknown user/group %s", *argv);
-		uid = ugid.uid;
-		gid = ugid.gid;
 	}
 
 	/* Ok, ready to do the deed now */




More information about the busybox-cvs mailing list