diff options
author | Tito Ragusa | 2014-01-17 09:17:55 +0100 |
---|---|---|
committer | Denys Vlasenko | 2014-01-17 09:17:55 +0100 |
commit | 891b98c9bcb0872465c1f9192b8cbc9779b8d164 (patch) | |
tree | 859511fb76a5c50793a2833697cf4b232865e283 /loginutils/addgroup.c | |
parent | 2e66daca654d130b820a4f0498de7f0ec355039a (diff) | |
download | busybox-891b98c9bcb0872465c1f9192b8cbc9779b8d164.zip busybox-891b98c9bcb0872465c1f9192b8cbc9779b8d164.tar.gz |
adduser,addgroup: introduce and use CONFIG_LAST_ID
Changes adduser.c, addgroup.c and Config.src to set and use CONFIG_LAST_ID.
function old new delta
adduser_main 841 865 +24
addgroup_main 407 425 +18
Signed-off-by: Tito Ragusa <farmatito@tiscali.it>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'loginutils/addgroup.c')
-rw-r--r-- | loginutils/addgroup.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/loginutils/addgroup.c b/loginutils/addgroup.c index b37270f..22cd0e6 100644 --- a/loginutils/addgroup.c +++ b/loginutils/addgroup.c @@ -22,14 +22,16 @@ #if CONFIG_LAST_SYSTEM_ID < CONFIG_FIRST_SYSTEM_ID #error Bad LAST_SYSTEM_ID or FIRST_SYSTEM_ID in .config #endif +#if CONFIG_LAST_ID < CONFIG_LAST_SYSTEM_ID +#error Bad LAST_ID or LAST_SYSTEM_ID in .config +#endif #define OPT_GID (1 << 0) #define OPT_SYSTEM_ACCOUNT (1 << 1) -/* We assume GID_T_MAX == INT_MAX */ static void xgroup_study(struct group *g) { - unsigned max = INT_MAX; + unsigned max = CONFIG_LAST_ID; /* Make sure gr_name is unused */ if (getgrnam(g->gr_name)) { @@ -46,7 +48,6 @@ static void xgroup_study(struct group *g) max = CONFIG_LAST_SYSTEM_ID; } else { g->gr_gid = CONFIG_LAST_SYSTEM_ID + 1; - max = 64999; } } /* Check if the desired gid is free @@ -125,7 +126,7 @@ int addgroup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int addgroup_main(int argc UNUSED_PARAM, char **argv) { unsigned opts; - unsigned gid = 0; + const char *gid = "0"; /* need to be root */ if (geteuid()) { @@ -139,7 +140,7 @@ int addgroup_main(int argc UNUSED_PARAM, char **argv) * addgroup -g num group * addgroup user group * Check for min, max and missing args */ - opt_complementary = "-1:?2:g+"; + opt_complementary = "-1:?2"; opts = getopt32(argv, "g:S", &gid); /* move past the commandline options */ argv += optind; @@ -175,7 +176,7 @@ int addgroup_main(int argc UNUSED_PARAM, char **argv) #endif /* ENABLE_FEATURE_ADDUSER_TO_GROUP */ { die_if_bad_username(argv[0]); - new_group(argv[0], gid); + new_group(argv[0], xatou_range(gid, 0, CONFIG_LAST_ID)); } /* Reached only on success */ return EXIT_SUCCESS; |