diff options
| author | Tito Ragusa <farmatito@tiscali.it> | 2012-10-08 11:18:08 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2012-10-08 11:18:08 +0200 |
| commit | 8dc6d1a813e2be33ecfcf3fa97a1b5aae05a8631 (patch) | |
| tree | 5972e8c0ab86d25c313580cb29646164b3e83ff0 | |
| parent | fd77ea505ed1eb15161585a6e3b6ea7ae95ed6b3 (diff) | |
| download | busybox-w32-8dc6d1a813e2be33ecfcf3fa97a1b5aae05a8631.tar.gz busybox-w32-8dc6d1a813e2be33ecfcf3fa97a1b5aae05a8631.tar.bz2 busybox-w32-8dc6d1a813e2be33ecfcf3fa97a1b5aae05a8631.zip | |
adduser: make it accept "adduser USER GROUP" form
Signed-off-by: Tito Ragusa <farmatito@tiscali.it>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | loginutils/adduser.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/loginutils/adduser.c b/loginutils/adduser.c index 1d082c876..dc0244476 100644 --- a/loginutils/adduser.c +++ b/loginutils/adduser.c | |||
| @@ -9,9 +9,9 @@ | |||
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | //usage:#define adduser_trivial_usage | 11 | //usage:#define adduser_trivial_usage |
| 12 | //usage: "[OPTIONS] USER" | 12 | //usage: "[OPTIONS] USER [GROUP]" |
| 13 | //usage:#define adduser_full_usage "\n\n" | 13 | //usage:#define adduser_full_usage "\n\n" |
| 14 | //usage: "Add a user\n" | 14 | //usage: "Create new user, or add USER to GROUP\n" |
| 15 | //usage: "\n -h DIR Home directory" | 15 | //usage: "\n -h DIR Home directory" |
| 16 | //usage: "\n -g GECOS GECOS field" | 16 | //usage: "\n -g GECOS GECOS field" |
| 17 | //usage: "\n -s SHELL Login shell" | 17 | //usage: "\n -s SHELL Login shell" |
| @@ -80,7 +80,7 @@ static void passwd_study(struct passwd *p) | |||
| 80 | } | 80 | } |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | static void addgroup_wrapper(struct passwd *p, const char *group_name) | 83 | static int addgroup_wrapper(struct passwd *p, const char *group_name) |
| 84 | { | 84 | { |
| 85 | char *argv[6]; | 85 | char *argv[6]; |
| 86 | 86 | ||
| @@ -110,7 +110,7 @@ static void addgroup_wrapper(struct passwd *p, const char *group_name) | |||
| 110 | argv[5] = NULL; | 110 | argv[5] = NULL; |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | spawn_and_wait(argv); | 113 | return spawn_and_wait(argv); |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | static void passwd_wrapper(const char *login_name) NORETURN; | 116 | static void passwd_wrapper(const char *login_name) NORETURN; |
| @@ -162,9 +162,9 @@ int adduser_main(int argc UNUSED_PARAM, char **argv) | |||
| 162 | pw.pw_shell = (char *)get_shell_name(); | 162 | pw.pw_shell = (char *)get_shell_name(); |
| 163 | pw.pw_dir = NULL; | 163 | pw.pw_dir = NULL; |
| 164 | 164 | ||
| 165 | /* exactly one non-option arg */ | 165 | /* at most two non-option args */ |
| 166 | /* disable interactive passwd for system accounts */ | 166 | /* disable interactive passwd for system accounts */ |
| 167 | opt_complementary = "=1:SD:u+"; | 167 | opt_complementary = "?2:SD:u+"; |
| 168 | if (sizeof(pw.pw_uid) == sizeof(int)) { | 168 | if (sizeof(pw.pw_uid) == sizeof(int)) { |
| 169 | opts = getopt32(argv, "h:g:s:G:DSHu:", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup, &pw.pw_uid); | 169 | opts = getopt32(argv, "h:g:s:G:DSHu:", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup, &pw.pw_uid); |
| 170 | } else { | 170 | } else { |
| @@ -175,9 +175,16 @@ int adduser_main(int argc UNUSED_PARAM, char **argv) | |||
| 175 | } | 175 | } |
| 176 | } | 176 | } |
| 177 | argv += optind; | 177 | argv += optind; |
| 178 | pw.pw_name = argv[0]; | ||
| 179 | |||
| 180 | if (!opts && argv[1]) { | ||
| 181 | /* if called with two non-option arguments, adduser | ||
| 182 | * will add an existing user to an existing group. | ||
| 183 | */ | ||
| 184 | return addgroup_wrapper(&pw, argv[1]); | ||
| 185 | } | ||
| 178 | 186 | ||
| 179 | /* fill in the passwd struct */ | 187 | /* fill in the passwd struct */ |
| 180 | pw.pw_name = argv[0]; | ||
| 181 | die_if_bad_username(pw.pw_name); | 188 | die_if_bad_username(pw.pw_name); |
| 182 | if (!pw.pw_dir) { | 189 | if (!pw.pw_dir) { |
| 183 | /* create string for $HOME if not specified already */ | 190 | /* create string for $HOME if not specified already */ |
| @@ -205,7 +212,6 @@ int adduser_main(int argc UNUSED_PARAM, char **argv) | |||
| 205 | } | 212 | } |
| 206 | if (ENABLE_FEATURE_CLEAN_UP) | 213 | if (ENABLE_FEATURE_CLEAN_UP) |
| 207 | free(p); | 214 | free(p); |
| 208 | |||
| 209 | #if ENABLE_FEATURE_SHADOWPASSWDS | 215 | #if ENABLE_FEATURE_SHADOWPASSWDS |
| 210 | /* /etc/shadow fields: | 216 | /* /etc/shadow fields: |
| 211 | * 1. username | 217 | * 1. username |
