aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coreutils/chown.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/coreutils/chown.c b/coreutils/chown.c
index a45348a24..2f48610a8 100644
--- a/coreutils/chown.c
+++ b/coreutils/chown.c
@@ -13,8 +13,7 @@
13 13
14#include "busybox.h" 14#include "busybox.h"
15 15
16static uid_t uid = -1; 16static struct bb_uidgid_t ugid = { -1, -1 };
17static gid_t gid = -1;
18 17
19static int (*chown_func)(const char *, uid_t, gid_t) = chown; 18static int (*chown_func)(const char *, uid_t, gid_t) = chown;
20 19
@@ -38,12 +37,14 @@ static int fileAction(const char *fileName, struct stat *statbuf,
38 // if (depth ... && S_ISLNK(statbuf->st_mode)) .... 37 // if (depth ... && S_ISLNK(statbuf->st_mode)) ....
39 38
40 if (!chown_func(fileName, 39 if (!chown_func(fileName,
41 (uid == (uid_t)-1) ? statbuf->st_uid : uid, 40 (ugid.uid == (uid_t)-1) ? statbuf->st_uid : ugid.uid,
42 (gid == (gid_t)-1) ? statbuf->st_gid : gid)) { 41 (ugid.gid == (gid_t)-1) ? statbuf->st_gid : ugid.gid)
42 ) {
43 if (OPT_VERBOSE 43 if (OPT_VERBOSE
44 || (OPT_CHANGED && (statbuf->st_uid != uid || statbuf->st_gid != gid)) 44 || (OPT_CHANGED && (statbuf->st_uid != ugid.uid || statbuf->st_gid != ugid.gid))
45 ) { 45 ) {
46 printf("changed ownership of '%s' to %u:%u\n", fileName, uid, gid); 46 printf("changed ownership of '%s' to %u:%u\n",
47 fileName, ugid.uid, ugid.gid);
47 } 48 }
48 return TRUE; 49 return TRUE;
49 } 50 }
@@ -65,23 +66,21 @@ int chown_main(int argc, char **argv)
65 66
66 /* First, check if there is a group name here */ 67 /* First, check if there is a group name here */
67 groupName = strchr(*argv, '.'); /* deprecated? */ 68 groupName = strchr(*argv, '.'); /* deprecated? */
68 if (!groupName) { 69 if (!groupName)
69 groupName = strchr(*argv, ':'); 70 groupName = strchr(*argv, ':');
70 } 71 else
72 *groupName = ':'; /* replace '.' with ':' */
71 73
72 /* First, try parsing "user[:[group]]" */ 74 /* First, try parsing "user[:[group]]" */
73 if (!groupName) { /* "user" */ 75 if (!groupName) { /* "user" */
74 uid = get_ug_id(*argv, xuname2uid); 76 ugid.uid = get_ug_id(*argv, xuname2uid);
75 } else if (groupName == *argv) { /* ":group" */ 77 } else if (groupName == *argv) { /* ":group" */
76 gid = get_ug_id(groupName + 1, xgroup2gid); 78 ugid.gid = get_ug_id(groupName + 1, xgroup2gid);
77 } else { 79 } else {
78 struct bb_uidgid_t ugid;
79 if (!groupName[1]) /* "user:" */ 80 if (!groupName[1]) /* "user:" */
80 *groupName = '\0'; 81 *groupName = '\0';
81 if (!get_uidgid(&ugid, *argv, 1)) 82 if (!get_uidgid(&ugid, *argv, 1))
82 bb_error_msg_and_die("unknown user/group %s", *argv); 83 bb_error_msg_and_die("unknown user/group %s", *argv);
83 uid = ugid.uid;
84 gid = ugid.gid;
85 } 84 }
86 85
87 /* Ok, ready to do the deed now */ 86 /* Ok, ready to do the deed now */