diff options
author | Andrew Stadler <stadler@android.com> | 2010-02-12 13:46:58 -0800 |
---|---|---|
committer | Andrew Stadler <stadler@android.com> | 2010-02-12 13:46:58 -0800 |
commit | 715c889713a7b3bd2f487dd14482af9675afc5cf (patch) | |
tree | db57dd6a73deb8d25aa7017c6cfb56f71f8dcdff /toolbox | |
parent | 9b0bf529440552ab2fb45a30f52c4e7a6abd3e5e (diff) | |
download | system_core-715c889713a7b3bd2f487dd14482af9675afc5cf.zip system_core-715c889713a7b3bd2f487dd14482af9675afc5cf.tar.gz system_core-715c889713a7b3bd2f487dd14482af9675afc5cf.tar.bz2 |
Allow numeric uid & gid in chown
This makes it more like the POSIX version which accepts number or name.
Diffstat (limited to 'toolbox')
-rw-r--r-- | toolbox/chown.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/toolbox/chown.c b/toolbox/chown.c index 13617db..e9d108b 100644 --- a/toolbox/chown.c +++ b/toolbox/chown.c @@ -35,19 +35,29 @@ int chown_main(int argc, char **argv) gid_t gid = -1; // passing -1 to chown preserves current group pw = getpwnam(user); - if (pw == NULL) { - fprintf(stderr, "No such user '%s'\n", user); - return 10; + if (pw != NULL) { + uid = pw->pw_uid; + } else { + char* endptr; + uid = (int) strtoul(user, &endptr, 0); + if (endptr == user) { // no conversion + fprintf(stderr, "No such user '%s'\n", user); + return 10; + } } - uid = pw->pw_uid; if (group != NULL) { grp = getgrnam(group); - if (grp == NULL) { - fprintf(stderr, "No such group '%s'\n", group); - return 10; + if (grp != NULL) { + gid = grp->gr_gid; + } else { + char* endptr; + gid = (int) strtoul(group, &endptr, 0); + if (endptr == group) { // no conversion + fprintf(stderr, "No such group '%s'\n", group); + return 10; + } } - gid = grp->gr_gid; } for (i = 2; i < argc; i++) { @@ -59,4 +69,3 @@ int chown_main(int argc, char **argv) return 0; } - |