summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2011-02-27 04:03:27 +0100
committerDenys Vlasenko2011-02-27 04:03:27 +0100
commit143c5baf6c2471c7f695e5e20da865f9e799ffbd (patch)
tree5e6fa973a950a8a16009c947b2ae4100f7889a8f
parente3b1a1fd28558f7a1b3c0ec33313bedb675be8a1 (diff)
downloadbusybox-143c5baf6c2471c7f695e5e20da865f9e799ffbd.zip
busybox-143c5baf6c2471c7f695e5e20da865f9e799ffbd.tar.gz
adduser: use better argv passing to addgroup
function old new delta adduser_main 855 882 +27 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--loginutils/adduser.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/loginutils/adduser.c b/loginutils/adduser.c
index d938b80..9d3d9cb 100644
--- a/loginutils/adduser.c
+++ b/loginutils/adduser.c
@@ -67,15 +67,24 @@ static void passwd_study(struct passwd *p)
static void addgroup_wrapper(struct passwd *p, const char *group_name)
{
- char *cmd;
-
- if (group_name) /* Add user to existing group */
- cmd = xasprintf("addgroup '%s' '%s'", p->pw_name, group_name);
- else /* Add user to his own group with the first free gid found in passwd_study */
- cmd = xasprintf("addgroup -g %u '%s'", (unsigned)p->pw_gid, p->pw_name);
- /* Warning: to be compatible with external addgroup programs we should use --gid instead */
- system(cmd);
- free(cmd);
+ char *argv[5];
+
+ argv[0] = (char*)"addgroup";
+ if (group_name) {
+ /* Add user to existing group */
+ argv[1] = p->pw_name;
+ argv[2] = (char*)group_name;
+ argv[3] = NULL;
+ } else {
+ /* Add user to his own group with the first free gid found in passwd_study */
+//TODO: to be compatible with external addgroup programs we should use --gid instead...
+ argv[1] = (char*)"-g";
+ argv[2] = utoa(p->pw_gid);
+ argv[3] = p->pw_name;
+ argv[4] = NULL;
+ }
+
+ spawn_and_wait(argv);
}
static void passwd_wrapper(const char *login_name) NORETURN;