Bug 310: be consistent about stat/lstat and chown/lchown to avoid accidentally
[oweals/busybox.git] / loginutils / adduser.c
index 41dc9f0193202d3ce1e29e61aea5ed31e60007e0..5ff0cd962ec626162ce5e748d663dd8d7359b9ff 100644 (file)
@@ -53,7 +53,6 @@ typedef struct {
 static const char default_passwd[] = "x";
 static const char default_gecos[] = "Linux User,,,";
 static const char default_home_prefix[] = "/home";
-static const char default_shell[] = "/bin/sh";
 
 #ifdef CONFIG_FEATURE_SHADOWPASSWDS
 /* shadow in use? */
@@ -78,7 +77,7 @@ static int passwd_study(const char *filename, struct passwd *p)
        if ((p->pw_uid > max) || (p->pw_uid < min))
                p->pw_uid = min;
 
-       /* stuff to do:  
+       /* stuff to do:
         * make sure login isn't taken;
         * find free uid and gid;
         */
@@ -118,7 +117,7 @@ static void addgroup_wrapper(const char *login, gid_t gid)
 {
        char *cmd;
 
-       bb_xasprintf(&cmd, "addgroup -g %d %s", gid, login);
+       cmd = bb_xasprintf("addgroup -g %d \"%s\"", gid, login);
        system(cmd);
        free(cmd);
 }
@@ -239,15 +238,15 @@ void if_i_am_not_root(void)
        }
 }
 
-#define SETPASS                                1
-#define MAKEHOME                       4
+#define SETPASS                                (1 << 4)
+#define MAKEHOME                       (1 << 6)
 
 /*
  * adduser will take a login_name as its first parameter.
  *
  * home
  * shell
- * gecos 
+ * gecos
  *
  * can be customized via command-line parameters.
  * ________________________________________________________________________ */
@@ -257,7 +256,7 @@ int adduser_main(int argc, char **argv)
        const char *login;
        const char *gecos = default_gecos;
        const char *home = NULL;
-       const char *shell = default_shell;
+       const char *shell = DEFAULT_SHELL;
        const char *usegroup = NULL;
        int flags;
        int setpass = 1;
@@ -306,13 +305,8 @@ int adduser_main(int argc, char **argv)
 
        if (usegroup) {
                /* Add user to a group that already exists */
-               struct group *g;
-
-               g = getgrnam(usegroup);
-               if (g == NULL)
-                       bb_error_msg_and_die("group %s does not exist", usegroup);
-
-               pw.pw_gid = g->gr_gid;
+               pw.pw_gid = bb_xgetgrnam(usegroup);
+               /* exits on error */    
        }
 
        /* grand finale */