summaryrefslogtreecommitdiff
path: root/coreutils/chown.c
diff options
context:
space:
mode:
authorDenis Vlasenko2006-12-28 05:44:47 +0000
committerDenis Vlasenko2006-12-28 05:44:47 +0000
commit9a44c4f91ce7e517d5325fd3743e6ad9d54ef3f0 (patch)
tree34292ef12cab59b118e91a6c58844ae25f1bee94 /coreutils/chown.c
parentba092336f00644c1233735bae4b81382309955d8 (diff)
downloadbusybox-9a44c4f91ce7e517d5325fd3743e6ad9d54ef3f0.zip
busybox-9a44c4f91ce7e517d5325fd3743e6ad9d54ef3f0.tar.gz
bb_xget[pw/gr]nam were horribly misnamed - fixed.
uidgid_get -> get_uidgid, add additional param (numeric_ok). Make chown use it. chown: fix "chown user: ...." install: fix incorrect use of bb_xget[pw/gr]nam
Diffstat (limited to 'coreutils/chown.c')
-rw-r--r--coreutils/chown.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/coreutils/chown.c b/coreutils/chown.c
index fddce7c..a45348a 100644
--- a/coreutils/chown.c
+++ b/coreutils/chown.c
@@ -54,32 +54,38 @@ static int fileAction(const char *fileName, struct stat *statbuf,
int chown_main(int argc, char **argv)
{
- int retval = EXIT_SUCCESS;
char *groupName;
+ int retval = EXIT_SUCCESS;
opt_complementary = "-2";
getopt32(argc, argv, OPT_STR);
+ argv += optind;
if (OPT_NODEREF) chown_func = lchown;
- argv += optind;
-
/* First, check if there is a group name here */
- groupName = strchr(*argv, '.');
+ groupName = strchr(*argv, '.'); /* deprecated? */
if (!groupName) {
groupName = strchr(*argv, ':');
}
- /* Check for the username and groupname */
- if (groupName) {
- *groupName++ = '\0';
- gid = get_ug_id(groupName, bb_xgetgrnam);
+ /* First, try parsing "user[:[group]]" */
+ if (!groupName) { /* "user" */
+ uid = get_ug_id(*argv, xuname2uid);
+ } else if (groupName == *argv) { /* ":group" */
+ 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;
}
- if (--groupName != *argv)
- uid = get_ug_id(*argv, bb_xgetpwnam);
- ++argv;
/* Ok, ready to do the deed now */
+ argv++;
do {
if (!recursive_action(*argv,
OPT_RECURSE, // recurse