summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko2007-01-03 20:07:06 +0000
committerDenis Vlasenko2007-01-03 20:07:06 +0000
commit6eebed561a4d7a022f9b44e2ddc1347a43eaa866 (patch)
treec4bf193888dbe808acecc063e577fe5f3b491ab6
parentc9d34da375d6a3934eefdf7247d29546360eaccc (diff)
downloadbusybox-6eebed561a4d7a022f9b44e2ddc1347a43eaa866.zip
busybox-6eebed561a4d7a022f9b44e2ddc1347a43eaa866.tar.gz
chown: fix handling of "user.group" notation
-rw-r--r--coreutils/chown.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/coreutils/chown.c b/coreutils/chown.c
index a45348a..2f48610 100644
--- a/coreutils/chown.c
+++ b/coreutils/chown.c
@@ -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 @@ static int fileAction(const char *fileName, struct stat *statbuf,
// 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 @@ int chown_main(int argc, char **argv)
/* 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 */