[ PATCH] was Re: How to add an existing user to an existing group
Tito
farmatito at tiscali.it
Tue Sep 18 19:57:18 UTC 2012
Hi,
attached v2 of the patch with a minor cleanup.
Hints and critics are welcome.
Ciao,
Tito
Allow adduser user group v2
Signed off by Tito Ragusa <farmatito at tiscali.it>
--- loginutils/adduser.c.original 2012-07-31 21:23:24.000000000 +0200
+++ loginutils/adduser.c 2012-09-18 21:46:29.000000000 +0200
@@ -9,9 +9,9 @@
*/
//usage:#define adduser_trivial_usage
-//usage: "[OPTIONS] USER"
+//usage: "[OPTIONS] USER or USER GROUP"
//usage:#define adduser_full_usage "\n\n"
-//usage: "Add a user\n"
+//usage: "Add a user or add a existing user to a existing group\n"
//usage: "\n -h DIR Home directory"
//usage: "\n -g GECOS GECOS field"
//usage: "\n -s SHELL Login shell"
@@ -80,7 +80,7 @@
}
}
-static void addgroup_wrapper(struct passwd *p, const char *group_name)
+static int addgroup_wrapper(struct passwd *p, const char *group_name)
{
char *argv[6];
@@ -110,7 +110,7 @@
argv[5] = NULL;
}
- spawn_and_wait(argv);
+ return spawn_and_wait(argv);
}
static void passwd_wrapper(const char *login_name) NORETURN;
@@ -162,9 +162,9 @@
pw.pw_shell = (char *)get_shell_name();
pw.pw_dir = NULL;
- /* exactly one non-option arg */
+ /* at most two non-option args */
/* disable interactive passwd for system accounts */
- opt_complementary = "=1:SD:u+";
+ opt_complementary = "?2:SD:u+";
if (sizeof(pw.pw_uid) == sizeof(int)) {
opts = getopt32(argv, "h:g:s:G:DSHu:", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup, &pw.pw_uid);
} else {
@@ -175,9 +175,15 @@
}
}
argv += optind;
+ pw.pw_name = argv[0];
+
+ if (!opts && argv[1]) {
+ /*If called with two non-option arguments, adduser
+ will add an existing user to an existing group. */
+ return addgroup_wrapper(&pw, argv[1]);
+ }
/* fill in the passwd struct */
- pw.pw_name = argv[0];
die_if_bad_username(pw.pw_name);
if (!pw.pw_dir) {
/* create string for $HOME if not specified already */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: adduser_v2.patch
Type: text/x-patch
Size: 1851 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20120918/34720c9f/attachment.bin>
More information about the busybox
mailing list