/* * addgroup will take a login_name as its first parameter. * * gid * * can be customized via command-line parameters. * ________________________________________________________________________ */ int addgroup_main(int argc, char **argv) { char *group; char *user; gid_t gid = 0; /* get remaining args */ if(bb_getopt_ulflags(argc, argv, "g:", &group)) { gid = strtol(group, NULL, 10); } if (optind < argc) { group = argv[optind]; optind++; } else { bb_show_usage(); } if (optind < argc) { user = argv[optind]; optind++; } else { user = ""; } if_i_am_not_root(); /* werk */ return addgroup(bb_path_group_file, group, gid, user); }
/* * 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 */ pw.pw_gid = bb_xgetgrnam(usegroup); /* exits on error */ } /* grand finale */ return adduser(bb_path_passwd_file, &pw, makehome, setpass); }