diff options
author | Tito Ragusa <farmatito@tiscali.it> | 2014-01-17 09:17:55 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2014-01-17 09:17:55 +0100 |
commit | 891b98c9bcb0872465c1f9192b8cbc9779b8d164 (patch) | |
tree | 859511fb76a5c50793a2833697cf4b232865e283 | |
parent | 2e66daca654d130b820a4f0498de7f0ec355039a (diff) | |
download | busybox-w32-891b98c9bcb0872465c1f9192b8cbc9779b8d164.tar.gz busybox-w32-891b98c9bcb0872465c1f9192b8cbc9779b8d164.tar.bz2 busybox-w32-891b98c9bcb0872465c1f9192b8cbc9779b8d164.zip |
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>
-rw-r--r-- | loginutils/Config.src | 11 | ||||
-rw-r--r-- | loginutils/addgroup.c | 13 | ||||
-rw-r--r-- | loginutils/adduser.c | 24 |
3 files changed, 27 insertions, 21 deletions
diff --git a/loginutils/Config.src b/loginutils/Config.src index 9bf79afee..b78d7c38e 100644 --- a/loginutils/Config.src +++ b/loginutils/Config.src | |||
@@ -118,10 +118,17 @@ config FEATURE_CHECK_NAMES | |||
118 | For compatibility with Samba machine accounts "$" is also supported | 118 | For compatibility with Samba machine accounts "$" is also supported |
119 | at the end of the user or group name. | 119 | at the end of the user or group name. |
120 | 120 | ||
121 | config LAST_ID | ||
122 | int "Last valid uid or gid for adduser and addgroup" | ||
123 | depends on ADDUSER || ADDGROUP | ||
124 | default 60000 | ||
125 | help | ||
126 | Last valid uid or gid for adduser and addgroup | ||
127 | |||
121 | config FIRST_SYSTEM_ID | 128 | config FIRST_SYSTEM_ID |
122 | int "First valid system uid or gid for adduser and addgroup" | 129 | int "First valid system uid or gid for adduser and addgroup" |
123 | depends on ADDUSER || ADDGROUP | 130 | depends on ADDUSER || ADDGROUP |
124 | range 0 64900 | 131 | range 0 LAST_ID |
125 | default 100 | 132 | default 100 |
126 | help | 133 | help |
127 | First valid system uid or gid for adduser and addgroup | 134 | First valid system uid or gid for adduser and addgroup |
@@ -129,7 +136,7 @@ config FIRST_SYSTEM_ID | |||
129 | config LAST_SYSTEM_ID | 136 | config LAST_SYSTEM_ID |
130 | int "Last valid system uid or gid for adduser and addgroup" | 137 | int "Last valid system uid or gid for adduser and addgroup" |
131 | depends on ADDUSER || ADDGROUP | 138 | depends on ADDUSER || ADDGROUP |
132 | range 0 64900 | 139 | range FIRST_SYSTEM_ID LAST_ID |
133 | default 999 | 140 | default 999 |
134 | help | 141 | help |
135 | Last valid system uid or gid for adduser and addgroup | 142 | Last valid system uid or gid for adduser and addgroup |
diff --git a/loginutils/addgroup.c b/loginutils/addgroup.c index b37270ff0..22cd0e661 100644 --- a/loginutils/addgroup.c +++ b/loginutils/addgroup.c | |||
@@ -22,14 +22,16 @@ | |||
22 | #if CONFIG_LAST_SYSTEM_ID < CONFIG_FIRST_SYSTEM_ID | 22 | #if CONFIG_LAST_SYSTEM_ID < CONFIG_FIRST_SYSTEM_ID |
23 | #error Bad LAST_SYSTEM_ID or FIRST_SYSTEM_ID in .config | 23 | #error Bad LAST_SYSTEM_ID or FIRST_SYSTEM_ID in .config |
24 | #endif | 24 | #endif |
25 | #if CONFIG_LAST_ID < CONFIG_LAST_SYSTEM_ID | ||
26 | #error Bad LAST_ID or LAST_SYSTEM_ID in .config | ||
27 | #endif | ||
25 | 28 | ||
26 | #define OPT_GID (1 << 0) | 29 | #define OPT_GID (1 << 0) |
27 | #define OPT_SYSTEM_ACCOUNT (1 << 1) | 30 | #define OPT_SYSTEM_ACCOUNT (1 << 1) |
28 | 31 | ||
29 | /* We assume GID_T_MAX == INT_MAX */ | ||
30 | static void xgroup_study(struct group *g) | 32 | static void xgroup_study(struct group *g) |
31 | { | 33 | { |
32 | unsigned max = INT_MAX; | 34 | unsigned max = CONFIG_LAST_ID; |
33 | 35 | ||
34 | /* Make sure gr_name is unused */ | 36 | /* Make sure gr_name is unused */ |
35 | if (getgrnam(g->gr_name)) { | 37 | if (getgrnam(g->gr_name)) { |
@@ -46,7 +48,6 @@ static void xgroup_study(struct group *g) | |||
46 | max = CONFIG_LAST_SYSTEM_ID; | 48 | max = CONFIG_LAST_SYSTEM_ID; |
47 | } else { | 49 | } else { |
48 | g->gr_gid = CONFIG_LAST_SYSTEM_ID + 1; | 50 | g->gr_gid = CONFIG_LAST_SYSTEM_ID + 1; |
49 | max = 64999; | ||
50 | } | 51 | } |
51 | } | 52 | } |
52 | /* Check if the desired gid is free | 53 | /* Check if the desired gid is free |
@@ -125,7 +126,7 @@ int addgroup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | |||
125 | int addgroup_main(int argc UNUSED_PARAM, char **argv) | 126 | int addgroup_main(int argc UNUSED_PARAM, char **argv) |
126 | { | 127 | { |
127 | unsigned opts; | 128 | unsigned opts; |
128 | unsigned gid = 0; | 129 | const char *gid = "0"; |
129 | 130 | ||
130 | /* need to be root */ | 131 | /* need to be root */ |
131 | if (geteuid()) { | 132 | if (geteuid()) { |
@@ -139,7 +140,7 @@ int addgroup_main(int argc UNUSED_PARAM, char **argv) | |||
139 | * addgroup -g num group | 140 | * addgroup -g num group |
140 | * addgroup user group | 141 | * addgroup user group |
141 | * Check for min, max and missing args */ | 142 | * Check for min, max and missing args */ |
142 | opt_complementary = "-1:?2:g+"; | 143 | opt_complementary = "-1:?2"; |
143 | opts = getopt32(argv, "g:S", &gid); | 144 | opts = getopt32(argv, "g:S", &gid); |
144 | /* move past the commandline options */ | 145 | /* move past the commandline options */ |
145 | argv += optind; | 146 | argv += optind; |
@@ -175,7 +176,7 @@ int addgroup_main(int argc UNUSED_PARAM, char **argv) | |||
175 | #endif /* ENABLE_FEATURE_ADDUSER_TO_GROUP */ | 176 | #endif /* ENABLE_FEATURE_ADDUSER_TO_GROUP */ |
176 | { | 177 | { |
177 | die_if_bad_username(argv[0]); | 178 | die_if_bad_username(argv[0]); |
178 | new_group(argv[0], gid); | 179 | new_group(argv[0], xatou_range(gid, 0, CONFIG_LAST_ID)); |
179 | } | 180 | } |
180 | /* Reached only on success */ | 181 | /* Reached only on success */ |
181 | return EXIT_SUCCESS; | 182 | return EXIT_SUCCESS; |
diff --git a/loginutils/adduser.c b/loginutils/adduser.c index ef390adf8..568a3018e 100644 --- a/loginutils/adduser.c +++ b/loginutils/adduser.c | |||
@@ -26,6 +26,10 @@ | |||
26 | #if CONFIG_LAST_SYSTEM_ID < CONFIG_FIRST_SYSTEM_ID | 26 | #if CONFIG_LAST_SYSTEM_ID < CONFIG_FIRST_SYSTEM_ID |
27 | #error Bad LAST_SYSTEM_ID or FIRST_SYSTEM_ID in .config | 27 | #error Bad LAST_SYSTEM_ID or FIRST_SYSTEM_ID in .config |
28 | #endif | 28 | #endif |
29 | #if CONFIG_LAST_ID < CONFIG_LAST_SYSTEM_ID | ||
30 | #error Bad LAST_ID or LAST_SYSTEM_ID in .config | ||
31 | #endif | ||
32 | |||
29 | 33 | ||
30 | /* #define OPT_HOME (1 << 0) */ /* unused */ | 34 | /* #define OPT_HOME (1 << 0) */ /* unused */ |
31 | /* #define OPT_GECOS (1 << 1) */ /* unused */ | 35 | /* #define OPT_GECOS (1 << 1) */ /* unused */ |
@@ -36,12 +40,11 @@ | |||
36 | #define OPT_DONT_MAKE_HOME (1 << 6) | 40 | #define OPT_DONT_MAKE_HOME (1 << 6) |
37 | #define OPT_UID (1 << 7) | 41 | #define OPT_UID (1 << 7) |
38 | 42 | ||
39 | /* We assume UID_T_MAX == INT_MAX */ | ||
40 | /* remix */ | 43 | /* remix */ |
41 | /* recoded such that the uid may be passed in *p */ | 44 | /* recoded such that the uid may be passed in *p */ |
42 | static void passwd_study(struct passwd *p) | 45 | static void passwd_study(struct passwd *p) |
43 | { | 46 | { |
44 | int max = UINT_MAX; | 47 | int max = CONFIG_LAST_ID; |
45 | 48 | ||
46 | if (getpwnam(p->pw_name)) { | 49 | if (getpwnam(p->pw_name)) { |
47 | bb_error_msg_and_die("%s '%s' in use", "user", p->pw_name); | 50 | bb_error_msg_and_die("%s '%s' in use", "user", p->pw_name); |
@@ -54,7 +57,6 @@ static void passwd_study(struct passwd *p) | |||
54 | max = CONFIG_LAST_SYSTEM_ID; | 57 | max = CONFIG_LAST_SYSTEM_ID; |
55 | } else { | 58 | } else { |
56 | p->pw_uid = CONFIG_LAST_SYSTEM_ID + 1; | 59 | p->pw_uid = CONFIG_LAST_SYSTEM_ID + 1; |
57 | max = 64999; | ||
58 | } | 60 | } |
59 | } | 61 | } |
60 | /* check for a free uid (and maybe gid) */ | 62 | /* check for a free uid (and maybe gid) */ |
@@ -147,6 +149,7 @@ int adduser_main(int argc UNUSED_PARAM, char **argv) | |||
147 | const char *usegroup = NULL; | 149 | const char *usegroup = NULL; |
148 | char *p; | 150 | char *p; |
149 | unsigned opts; | 151 | unsigned opts; |
152 | char *uid; | ||
150 | 153 | ||
151 | #if ENABLE_FEATURE_ADDUSER_LONG_OPTIONS | 154 | #if ENABLE_FEATURE_ADDUSER_LONG_OPTIONS |
152 | applet_long_options = adduser_longopts; | 155 | applet_long_options = adduser_longopts; |
@@ -164,16 +167,11 @@ int adduser_main(int argc UNUSED_PARAM, char **argv) | |||
164 | 167 | ||
165 | /* at least one and at most two non-option args */ | 168 | /* at least one and at most two non-option args */ |
166 | /* disable interactive passwd for system accounts */ | 169 | /* disable interactive passwd for system accounts */ |
167 | opt_complementary = "-1:?2:SD:u+"; | 170 | opt_complementary = "-1:?2:SD"; |
168 | if (sizeof(pw.pw_uid) == sizeof(int)) { | 171 | opts = getopt32(argv, "h:g:s:G:DSHu:", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup, &uid); |
169 | opts = getopt32(argv, "h:g:s:G:DSHu:", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup, &pw.pw_uid); | 172 | if (opts & OPT_UID) |
170 | } else { | 173 | pw.pw_uid = xatou_range(uid, 0, CONFIG_LAST_ID); |
171 | unsigned uid; | 174 | |
172 | opts = getopt32(argv, "h:g:s:G:DSHu:", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup, &uid); | ||
173 | if (opts & OPT_UID) { | ||
174 | pw.pw_uid = uid; | ||
175 | } | ||
176 | } | ||
177 | argv += optind; | 175 | argv += optind; |
178 | pw.pw_name = argv[0]; | 176 | pw.pw_name = argv[0]; |
179 | 177 | ||