+ p = xasprintf("x:%u:%u:%s:%s:%s",
+ (unsigned) pw.pw_uid, (unsigned) pw.pw_gid,
+ pw.pw_gecos, pw.pw_dir, pw.pw_shell);
+ if (update_passwd(bb_path_passwd_file, pw.pw_name, p, NULL) < 0) {
+ return EXIT_FAILURE;
+ }
+ if (ENABLE_FEATURE_CLEAN_UP)
+ free(p);
+#if ENABLE_FEATURE_SHADOWPASSWDS
+ /* /etc/shadow fields:
+ * 1. username
+ * 2. encrypted password
+ * 3. last password change (unix date (unix time/24*60*60))
+ * 4. minimum days required between password changes
+ * 5. maximum days password is valid
+ * 6. days before password is to expire that user is warned
+ * 7. days after password expires that account is disabled
+ * 8. unix date when login expires (i.e. when it may no longer be used)
+ */
+ /* fields: 2 3 4 5 6 78 */
+ p = xasprintf("!:%u:0:99999:7:::", (unsigned)(time(NULL)) / (24*60*60));
+ /* ignore errors: if file is missing we suppose admin doesn't want it */
+ update_passwd(bb_path_shadow_file, pw.pw_name, p, NULL);
+ if (ENABLE_FEATURE_CLEAN_UP)
+ free(p);
+#endif
+
+ /* add to group */
+ addgroup_wrapper(&pw, usegroup);
+
+ /* clear the umask for this process so it doesn't
+ * screw up the permissions on the mkdir and chown. */
+ umask(0);
+ if (!(opts & OPT_DONT_MAKE_HOME)) {
+ /* set the owner and group so it is owned by the new user,
+ * then fix up the permissions to 2755. Can't do it before
+ * since chown will clear the setgid bit */
+ int mkdir_err = mkdir(pw.pw_dir, 0755);
+ if (mkdir_err == 0) {
+ /* New home. Copy /etc/skel to it */
+ const char *args[] = {
+ "chown",
+ "-R",
+ xasprintf("%u:%u", (int)pw.pw_uid, (int)pw.pw_gid),
+ pw.pw_dir,
+ NULL
+ };
+ /* Be silent on any errors (like: no /etc/skel) */
+ if (!(opts & OPT_SKEL))
+ logmode = LOGMODE_NONE;
+ copy_file(skel, pw.pw_dir, FILEUTILS_RECUR);
+ logmode = LOGMODE_STDIO;
+ chown_main(4, (char**)args);
+ }
+ if ((mkdir_err != 0 && errno != EEXIST)
+ || chown(pw.pw_dir, pw.pw_uid, pw.pw_gid) != 0
+ || chmod(pw.pw_dir, 02755) != 0 /* set setgid bit on homedir */
+ ) {
+ bb_simple_perror_msg(pw.pw_dir);
+ }
+ }
+
+ if (!(opts & OPT_DONT_SET_PASS)) {
+ /* interactively set passwd */
+ passwd_wrapper(pw.pw_name);
+ }