- passwd_wrapper(p->pw_name);
- }
-
- return 0;
-}
-
-
-/* return current uid (root is always uid == 0, right?) */
-#ifndef CONFIG_ADDGROUP
-static inline void if_i_am_not_root(void)
-#else
-void if_i_am_not_root(void)
-#endif
-{
- if (geteuid()) {
- bb_error_msg_and_die( "Only root may add a user or group to the system.");
- }
-}
-
-#define SETPASS 1
-#define MAKEHOME 4
-
-/*
- * adduser will take a login_name as its first parameter.
- *
- * home
- * shell
- * gecos
- *
- * can be customized via command-line parameters.
- * ________________________________________________________________________ */
-int adduser_main(int argc, char **argv)
-{
- struct passwd pw;
- const char *login;
- const char *gecos = default_gecos;
- const char *home = NULL;
- const char *shell = DEFAULT_SHELL;
- const char *usegroup = NULL;
- int flags;
- int setpass = 1;
- int makehome = 1;
-
- /* init */
- if (argc < 2) {
- bb_show_usage();
- }
- /* get args */
- flags = bb_getopt_ulflags(argc, argv, "h:g:s:G:DSH", &home, &gecos, &shell, &usegroup);
-
- if (flags & SETPASS) {
- setpass = 0;
- }
- if (flags & MAKEHOME) {
- makehome = 0;
- }
-
- /* got root? */
- if_i_am_not_root();
-
- /* get login */
- if (optind >= argc) {
- bb_error_msg_and_die( "no user specified");
- }
- login = argv[optind];
-
- /* create string for $HOME if not specified already */
- if (!home) {
- home = concat_path_file(default_home_prefix, login);
- }
-#ifdef CONFIG_FEATURE_SHADOWPASSWDS
- /* is /etc/shadow in use? */
- shadow_enabled = (0 == access(bb_path_shadow_file, F_OK));
-#endif
-
- /* create a passwd struct */
- pw.pw_name = (char *)login;
- pw.pw_passwd = (char *)default_passwd;
- pw.pw_uid = 0;
- pw.pw_gid = 0;
- pw.pw_gecos = (char *)gecos;
- pw.pw_dir = (char *)home;
- pw.pw_shell = (char *)shell;
-
- 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;