+ char tmp[1014];
+ FILE *fp;
+ int fd;
+ size_t len;
+ off_t atofs = 0;
+
+ if ((fd = openat(conf.rootfd, "etc/opiekeys", O_RDWR)) == -1)
+ return;
+
+ fp = fdopen(fd, "r+");
+ len = strlen(name);
+
+ while (fgets(tmp, sizeof(tmp), fp) != NULL) {
+ if (strncmp(name, tmp, len) == 0 && tmp[len]==' ') {
+ /* Comment username out */
+ if (fseek(fp, atofs, SEEK_SET) == 0)
+ fwrite("#", 1, 1, fp);
+ break;
+ }
+ atofs = ftell(fp);
+ }
+ /*
+ * If we got an error of any sort, don't update!
+ */
+ fclose(fp);
+}
+
+int
+pw_user_next(int argc, char **argv, char *name __unused)
+{
+ struct userconf *cnf = NULL;
+ const char *cfg = NULL;
+ int ch;
+ bool quiet = false;
+ uid_t next;
+
+ while ((ch = getopt(argc, argv, "C:q")) != -1) {
+ switch (ch) {
+ case 'C':
+ cfg = optarg;
+ break;
+ case 'q':
+ quiet = true;
+ break;
+ }
+ }
+
+ if (quiet)
+ freopen(_PATH_DEVNULL, "w", stderr);
+
+ cnf = get_userconfig(cfg);
+
+ next = pw_uidpolicy(cnf, -1);
+
+ printf("%ju:", (uintmax_t)next);
+ pw_groupnext(cnf, quiet);
+
+ return (EXIT_SUCCESS);
+}
+
+int
+pw_user_show(int argc, char **argv, char *arg1)
+{
+ struct passwd *pwd = NULL;
+ char *name = NULL;
+ intmax_t id = -1;
+ int ch;
+ bool all = false;
+ bool pretty = false;
+ bool force = false;
+ bool v7 = false;
+ bool quiet = false;
+
+ if (arg1 != NULL) {
+ if (arg1[strspn(arg1, "0123456789")] == '\0')
+ id = pw_checkid(arg1, UID_MAX);
+ else
+ name = arg1;
+ }
+
+ while ((ch = getopt(argc, argv, "C:qn:u:FPa7")) != -1) {
+ switch (ch) {
+ case 'C':
+ /* ignore compatibility */
+ break;
+ case 'q':
+ quiet = true;
+ break;
+ case 'n':
+ name = optarg;
+ break;
+ case 'u':
+ id = pw_checkid(optarg, UID_MAX);
+ break;
+ case 'F':
+ force = true;
+ break;
+ case 'P':
+ pretty = true;
+ break;
+ case 'a':
+ all = true;
+ break;
+ case '7':
+ v7 = true;
+ break;
+ }
+ }
+
+ if (quiet)
+ freopen(_PATH_DEVNULL, "w", stderr);
+
+ if (all) {
+ SETPWENT();
+ while ((pwd = GETPWENT()) != NULL)
+ print_user(pwd, pretty, v7);
+ ENDPWENT();
+ return (EXIT_SUCCESS);
+ }
+
+ if (id < 0 && name == NULL)
+ errx(EX_DATAERR, "username or id required");
+
+ pwd = (name != NULL) ? GETPWNAM(pw_checkname(name, 0)) : GETPWUID(id);
+ if (pwd == NULL) {
+ if (force) {
+ pwd = &fakeuser;
+ } else {
+ if (name == NULL)
+ errx(EX_NOUSER, "no such uid `%ju'",
+ (uintmax_t) id);
+ errx(EX_NOUSER, "no such user `%s'", name);
+ }
+ }
+
+ return (print_user(pwd, pretty, v7));
+}
+
+int
+pw_user_del(int argc, char **argv, char *arg1)
+{
+ struct userconf *cnf = NULL;
+ struct passwd *pwd = NULL;
+ struct group *gr, *grp;
+ char *name = NULL;
+ char grname[MAXLOGNAME];
+ char *nispasswd = NULL;
+ char file[MAXPATHLEN];
+ char home[MAXPATHLEN];
+ const char *cfg = NULL;
+ struct stat st;
+ intmax_t id = -1;
+ int ch, rc;
+ bool nis = false;
+ bool deletehome = false;
+ bool quiet = false;
+
+ if (arg1 != NULL) {
+ if (arg1[strspn(arg1, "0123456789")] == '\0')
+ id = pw_checkid(arg1, UID_MAX);
+ else
+ name = arg1;
+ }
+
+ while ((ch = getopt(argc, argv, "C:qn:u:rYy:")) != -1) {
+ switch (ch) {
+ case 'C':
+ cfg = optarg;
+ break;
+ case 'q':
+ quiet = true;
+ break;
+ case 'n':
+ name = optarg;
+ break;
+ case 'u':
+ id = pw_checkid(optarg, UID_MAX);
+ break;
+ case 'r':
+ deletehome = true;
+ break;
+ case 'y':
+ nispasswd = optarg;
+ break;
+ case 'Y':
+ nis = true;
+ break;
+ }
+ }
+
+ if (quiet)
+ freopen(_PATH_DEVNULL, "w", stderr);
+
+ if (id < 0 && name == NULL)
+ errx(EX_DATAERR, "username or id required");
+
+ cnf = get_userconfig(cfg);
+
+ if (nispasswd == NULL)
+ nispasswd = cnf->nispasswd;
+
+ pwd = (name != NULL) ? GETPWNAM(pw_checkname(name, 0)) : GETPWUID(id);
+ if (pwd == NULL) {
+ if (name == NULL)
+ errx(EX_NOUSER, "no such uid `%ju'", (uintmax_t) id);
+ errx(EX_NOUSER, "no such user `%s'", name);
+ }
+
+ if (PWF._altdir == PWF_REGULAR &&
+ ((pwd->pw_fields & _PWF_SOURCE) != _PWF_FILES)) {
+ if ((pwd->pw_fields & _PWF_SOURCE) == _PWF_NIS) {
+ if (!nis && nispasswd && *nispasswd != '/')
+ errx(EX_NOUSER, "Cannot remove NIS user `%s'",
+ name);
+ } else {
+ errx(EX_NOUSER, "Cannot remove non local user `%s'",
+ name);
+ }
+ }
+
+ id = pwd->pw_uid;
+ if (name == NULL)
+ name = pwd->pw_name;
+
+ if (strcmp(pwd->pw_name, "root") == 0)
+ errx(EX_DATAERR, "cannot remove user 'root'");
+
+ /* Remove opie record from /etc/opiekeys */
+ if (PWALTDIR() != PWF_ALT)
+ rmopie(pwd->pw_name);
+
+ if (!PWALTDIR()) {
+ /* Remove crontabs */
+ snprintf(file, sizeof(file), "/var/cron/tabs/%s", pwd->pw_name);
+ if (access(file, F_OK) == 0) {
+ snprintf(file, sizeof(file), "crontab -u %s -r",
+ pwd->pw_name);
+ system(file);
+ }
+ }
+
+ /*
+ * Save these for later, since contents of pwd may be
+ * invalidated by deletion
+ */
+ snprintf(file, sizeof(file), "%s/%s", _PATH_MAILDIR, pwd->pw_name);
+ strlcpy(home, pwd->pw_dir, sizeof(home));
+ gr = GETGRGID(pwd->pw_gid);
+ if (gr != NULL)
+ strlcpy(grname, gr->gr_name, LOGNAMESIZE);
+ else
+ grname[0] = '\0';
+
+ rc = delpwent(pwd);
+ if (rc == -1)
+ err(EX_IOERR, "user '%s' does not exist", pwd->pw_name);
+ else if (rc != 0)
+ err(EX_IOERR, "passwd update");
+
+ if (nis && nispasswd && *nispasswd=='/') {
+ rc = delnispwent(nispasswd, name);
+ if (rc == -1)
+ warnx("WARNING: user '%s' does not exist in NIS passwd",
+ pwd->pw_name);
+ else if (rc != 0)
+ warn("WARNING: NIS passwd update");
+ }
+
+ grp = GETGRNAM(name);
+ if (grp != NULL &&
+ (grp->gr_mem == NULL || *grp->gr_mem == NULL) &&
+ strcmp(name, grname) == 0)
+ delgrent(GETGRNAM(name));
+ SETGRENT();
+ while ((grp = GETGRENT()) != NULL) {
+ int i, j;
+ char group[MAXLOGNAME];
+ if (grp->gr_mem == NULL)
+ continue;
+
+ for (i = 0; grp->gr_mem[i] != NULL; i++) {
+ if (strcmp(grp->gr_mem[i], name) != 0)
+ continue;
+
+ for (j = i; grp->gr_mem[j] != NULL; j++)
+ grp->gr_mem[j] = grp->gr_mem[j+1];
+ strlcpy(group, grp->gr_name, MAXLOGNAME);
+ chggrent(group, grp);
+ }
+ }
+ ENDGRENT();
+
+ pw_log(cnf, M_DELETE, W_USER, "%s(%ju) account removed", name,
+ (uintmax_t)id);
+
+ /* Remove mail file */
+ if (PWALTDIR() != PWF_ALT)
+ unlinkat(conf.rootfd, file + 1, 0);
+
+ /* Remove at jobs */
+ if (!PWALTDIR() && getpwuid(id) == NULL)
+ rmat(id);
+
+ /* Remove home directory and contents */
+ if (PWALTDIR() != PWF_ALT && deletehome && *home == '/' &&
+ GETPWUID(id) == NULL &&
+ fstatat(conf.rootfd, home + 1, &st, 0) != -1) {
+ rm_r(conf.rootfd, home, id);
+ pw_log(cnf, M_DELETE, W_USER, "%s(%ju) home '%s' %s"
+ "removed", name, (uintmax_t)id, home,
+ fstatat(conf.rootfd, home + 1, &st, 0) == -1 ? "" : "not "
+ "completely ");
+ }
+
+ return (EXIT_SUCCESS);
+}
+
+int
+pw_user_lock(int argc, char **argv, char *arg1)
+{
+ int ch;
+
+ while ((ch = getopt(argc, argv, "Cq")) != -1) {
+ switch (ch) {
+ case 'C':
+ case 'q':
+ /* compatibility */
+ break;
+ }
+ }
+
+ return (pw_userlock(arg1, M_LOCK));
+}
+
+int
+pw_user_unlock(int argc, char **argv, char *arg1)
+{
+ int ch;
+
+ while ((ch = getopt(argc, argv, "Cq")) != -1) {
+ switch (ch) {
+ case 'C':
+ case 'q':
+ /* compatibility */
+ break;
+ }
+ }
+
+ return (pw_userlock(arg1, M_UNLOCK));
+}
+
+static struct group *
+group_from_name_or_id(char *name)
+{
+ const char *errstr = NULL;
+ struct group *grp;
+ uintmax_t id;
+
+ if ((grp = GETGRNAM(name)) == NULL) {
+ id = strtounum(name, 0, GID_MAX, &errstr);
+ if (errstr)
+ errx(EX_NOUSER, "group `%s' does not exist", name);
+ grp = GETGRGID(id);
+ if (grp == NULL)
+ errx(EX_NOUSER, "group `%s' does not exist", name);
+ }
+
+ return (grp);
+}
+
+static void
+split_groups(StringList **groups, char *groupsstr)
+{
+ struct group *grp;
+ char *p;
+ char tok[] = ", \t";
+
+ for (p = strtok(groupsstr, tok); p != NULL; p = strtok(NULL, tok)) {
+ grp = group_from_name_or_id(p);
+ if (*groups == NULL)
+ *groups = sl_init();
+ sl_add(*groups, newstr(grp->gr_name));
+ }
+}
+
+static void
+validate_grname(struct userconf *cnf, char *group)
+{
+ struct group *grp;
+
+ if (group == NULL || *group == '\0') {
+ cnf->default_group = "";
+ return;
+ }
+ grp = group_from_name_or_id(group);
+ cnf->default_group = newstr(grp->gr_name);
+}
+
+static mode_t
+validate_mode(char *mode)
+{
+ mode_t m;
+ void *set;
+
+ if ((set = setmode(mode)) == NULL)
+ errx(EX_DATAERR, "invalid directory creation mode '%s'", mode);
+
+ m = getmode(set, _DEF_DIRMODE);
+ free(set);
+ return (m);
+}
+
+static void
+mix_config(struct userconf *cmdcnf, struct userconf *cfg)
+{
+
+ if (cmdcnf->default_password == 0)
+ cmdcnf->default_password = cfg->default_password;
+ if (cmdcnf->reuse_uids == 0)
+ cmdcnf->reuse_uids = cfg->reuse_uids;
+ if (cmdcnf->reuse_gids == 0)
+ cmdcnf->reuse_gids = cfg->reuse_gids;
+ if (cmdcnf->nispasswd == NULL)
+ cmdcnf->nispasswd = cfg->nispasswd;
+ if (cmdcnf->dotdir == NULL)
+ cmdcnf->dotdir = cfg->dotdir;
+ if (cmdcnf->newmail == NULL)
+ cmdcnf->newmail = cfg->newmail;
+ if (cmdcnf->logfile == NULL)
+ cmdcnf->logfile = cfg->logfile;
+ if (cmdcnf->home == NULL)
+ cmdcnf->home = cfg->home;
+ if (cmdcnf->homemode == 0)
+ cmdcnf->homemode = cfg->homemode;
+ if (cmdcnf->shelldir == NULL)
+ cmdcnf->shelldir = cfg->shelldir;
+ if (cmdcnf->shells == NULL)
+ cmdcnf->shells = cfg->shells;
+ if (cmdcnf->shell_default == NULL)
+ cmdcnf->shell_default = cfg->shell_default;
+ if (cmdcnf->default_group == NULL)
+ cmdcnf->default_group = cfg->default_group;
+ if (cmdcnf->groups == NULL)
+ cmdcnf->groups = cfg->groups;
+ if (cmdcnf->default_class == NULL)
+ cmdcnf->default_class = cfg->default_class;
+ if (cmdcnf->min_uid == 0)
+ cmdcnf->min_uid = cfg->min_uid;
+ if (cmdcnf->max_uid == 0)
+ cmdcnf->max_uid = cfg->max_uid;
+ if (cmdcnf->min_gid == 0)
+ cmdcnf->min_gid = cfg->min_gid;
+ if (cmdcnf->max_gid == 0)
+ cmdcnf->max_gid = cfg->max_gid;
+ if (cmdcnf->expire_days == 0)
+ cmdcnf->expire_days = cfg->expire_days;
+ if (cmdcnf->password_days == 0)
+ cmdcnf->password_days = cfg->password_days;
+}
+
+int
+pw_user_add(int argc, char **argv, char *arg1)
+{
+ struct userconf *cnf, *cmdcnf;
+ struct passwd *pwd;
+ struct group *grp;
+ struct stat st;
+ char args[] = "C:qn:u:c:d:e:p:g:G:mM:k:s:oL:i:w:h:H:Db:NPy:Y";
+ char line[_PASSWORD_LEN+1], path[MAXPATHLEN];
+ char *gecos, *homedir, *skel, *walk, *userid, *groupid, *grname;
+ char *default_passwd, *name, *p;
+ const char *cfg;
+ login_cap_t *lc;
+ FILE *pfp, *fp;
+ intmax_t id = -1;
+ time_t now;
+ int rc, ch, fd = -1;
+ size_t i;
+ bool dryrun, nis, pretty, quiet, createhome, precrypted, genconf;
+
+ dryrun = nis = pretty = quiet = createhome = precrypted = false;
+ genconf = false;
+ gecos = homedir = skel = userid = groupid = default_passwd = NULL;
+ grname = name = NULL;
+
+ if ((cmdcnf = calloc(1, sizeof(struct userconf))) == NULL)
+ err(EXIT_FAILURE, "calloc()");
+
+ if (arg1 != NULL) {
+ if (arg1[strspn(arg1, "0123456789")] == '\0')
+ id = pw_checkid(arg1, UID_MAX);
+ else
+ name = arg1;
+ }
+
+ while ((ch = getopt(argc, argv, args)) != -1) {
+ switch (ch) {
+ case 'C':
+ cfg = optarg;
+ break;
+ case 'q':
+ quiet = true;
+ break;
+ case 'n':
+ name = optarg;
+ break;
+ case 'u':
+ userid = optarg;
+ break;
+ case 'c':
+ gecos = pw_checkname(optarg, 1);
+ break;
+ case 'd':
+ homedir = optarg;
+ break;
+ case 'e':
+ now = time(NULL);
+ cmdcnf->expire_days = parse_date(now, optarg);
+ break;
+ case 'p':
+ now = time(NULL);
+ cmdcnf->password_days = parse_date(now, optarg);
+ break;
+ case 'g':
+ validate_grname(cmdcnf, optarg);
+ grname = optarg;
+ break;
+ case 'G':
+ split_groups(&cmdcnf->groups, optarg);
+ break;
+ case 'm':
+ createhome = true;
+ break;
+ case 'M':
+ cmdcnf->homemode = validate_mode(optarg);
+ break;
+ case 'k':
+ walk = skel = optarg;
+ if (*walk == '/')
+ walk++;
+ if (fstatat(conf.rootfd, walk, &st, 0) == -1)
+ errx(EX_OSFILE, "skeleton `%s' does not "
+ "exists", skel);
+ if (!S_ISDIR(st.st_mode))
+ errx(EX_OSFILE, "skeleton `%s' is not a "
+ "directory", skel);
+ cmdcnf->dotdir = skel;
+ break;
+ case 's':
+ cmdcnf->shell_default = optarg;
+ break;
+ case 'o':
+ conf.checkduplicate = false;
+ break;
+ case 'L':
+ cmdcnf->default_class = pw_checkname(optarg, 0);
+ break;
+ case 'i':
+ groupid = optarg;
+ break;
+ case 'w':
+ default_passwd = optarg;
+ break;
+ case 'H':
+ if (fd != -1)
+ errx(EX_USAGE, "'-h' and '-H' are mutually "
+ "exclusive options");
+ fd = pw_checkfd(optarg);
+ precrypted = true;
+ if (fd == '-')
+ errx(EX_USAGE, "-H expects a file descriptor");
+ break;
+ case 'h':
+ if (fd != -1)
+ errx(EX_USAGE, "'-h' and '-H' are mutually "
+ "exclusive options");
+ fd = pw_checkfd(optarg);
+ break;
+ case 'D':
+ genconf = true;
+ break;
+ case 'b':
+ cmdcnf->home = optarg;
+ break;
+ case 'N':
+ dryrun = true;
+ break;
+ case 'P':
+ pretty = true;
+ break;
+ case 'y':
+ cmdcnf->nispasswd = optarg;
+ break;
+ case 'Y':
+ nis = true;
+ break;
+ }
+ }
+
+ if (geteuid() != 0 && ! dryrun)
+ errx(EX_NOPERM, "you must be root");
+
+ if (quiet)
+ freopen(_PATH_DEVNULL, "w", stderr);
+
+ cnf = get_userconfig(cfg);
+
+ mix_config(cmdcnf, cnf);
+ if (default_passwd)
+ cmdcnf->default_password = passwd_val(default_passwd,
+ cnf->default_password);
+ if (genconf) {
+ if (name != NULL)
+ errx(EX_DATAERR, "can't combine `-D' with `-n name'");
+ if (userid != NULL) {
+ if ((p = strtok(userid, ", \t")) != NULL)
+ cmdcnf->min_uid = pw_checkid(p, UID_MAX);
+ if (cmdcnf->min_uid == 0)
+ cmdcnf->min_uid = 1000;
+ if ((p = strtok(NULL, " ,\t")) != NULL)
+ cmdcnf->max_uid = pw_checkid(p, UID_MAX);
+ if (cmdcnf->max_uid == 0)
+ cmdcnf->max_uid = 32000;
+ }
+ if (groupid != NULL) {
+ if ((p = strtok(groupid, ", \t")) != NULL)
+ cmdcnf->min_gid = pw_checkid(p, GID_MAX);
+ if (cmdcnf->min_gid == 0)
+ cmdcnf->min_gid = 1000;
+ if ((p = strtok(NULL, " ,\t")) != NULL)
+ cmdcnf->max_gid = pw_checkid(p, GID_MAX);
+ if (cmdcnf->max_gid == 0)
+ cmdcnf->max_gid = 32000;
+ }
+ if (write_userconfig(cmdcnf, cfg))
+ return (EXIT_SUCCESS);
+ err(EX_IOERR, "config update");
+ }
+
+ if (userid)
+ id = pw_checkid(userid, UID_MAX);
+ if (id < 0 && name == NULL)
+ errx(EX_DATAERR, "user name or id required");
+
+ if (name == NULL)
+ errx(EX_DATAERR, "login name required");
+
+ if (GETPWNAM(name) != NULL)
+ errx(EX_DATAERR, "login name `%s' already exists", name);
+
+ pwd = &fakeuser;
+ pwd->pw_name = name;
+ pwd->pw_class = cmdcnf->default_class ? cmdcnf->default_class : "";
+ pwd->pw_uid = pw_uidpolicy(cmdcnf, id);
+ pwd->pw_gid = pw_gidpolicy(cnf, grname, pwd->pw_name,
+ (gid_t) pwd->pw_uid, dryrun);
+ pwd->pw_change = cmdcnf->password_days;
+ pwd->pw_expire = cmdcnf->expire_days;
+ pwd->pw_dir = pw_homepolicy(cmdcnf, homedir, pwd->pw_name);
+ pwd->pw_shell = pw_shellpolicy(cmdcnf);
+ lc = login_getpwclass(pwd);
+ if (lc == NULL || login_setcryptfmt(lc, "sha512", NULL) == NULL)
+ warn("setting crypt(3) format");
+ login_close(lc);
+ pwd->pw_passwd = pw_password(cmdcnf, pwd->pw_name, dryrun);
+ if (pwd->pw_uid == 0 && strcmp(pwd->pw_name, "root") != 0)
+ warnx("WARNING: new account `%s' has a uid of 0 "
+ "(superuser access!)", pwd->pw_name);
+ if (gecos)
+ pwd->pw_gecos = gecos;
+
+ if (fd != -1)
+ pw_set_passwd(pwd, fd, precrypted, false);
+
+ if (dryrun)
+ return (print_user(pwd, pretty, false));
+
+ if ((rc = addpwent(pwd)) != 0) {
+ if (rc == -1)
+ errx(EX_IOERR, "user '%s' already exists",
+ pwd->pw_name);
+ else if (rc != 0)
+ err(EX_IOERR, "passwd file update");
+ }
+ if (nis && cmdcnf->nispasswd && *cmdcnf->nispasswd == '/') {
+ printf("%s\n", cmdcnf->nispasswd);
+ rc = addnispwent(cmdcnf->nispasswd, pwd);
+ if (rc == -1)
+ warnx("User '%s' already exists in NIS passwd",
+ pwd->pw_name);
+ else if (rc != 0)
+ warn("NIS passwd update");
+ /* NOTE: we treat NIS-only update errors as non-fatal */
+ }
+
+ if (cmdcnf->groups != NULL) {
+ for (i = 0; i < cmdcnf->groups->sl_cur; i++) {
+ grp = GETGRNAM(cmdcnf->groups->sl_str[i]);
+ grp = gr_add(grp, pwd->pw_name);
+ /*
+ * grp can only be NULL in 2 cases:
+ * - the new member is already a member
+ * - a problem with memory occurs
+ * in both cases we want to skip now.
+ */
+ if (grp == NULL)
+ continue;
+ chggrent(grp->gr_name, grp);
+ free(grp);
+ }
+ }
+
+ pwd = GETPWNAM(name);
+ if (pwd == NULL)
+ errx(EX_NOUSER, "user '%s' disappeared during update", name);
+
+ grp = GETGRGID(pwd->pw_gid);
+ pw_log(cnf, M_ADD, W_USER, "%s(%ju):%s(%ju):%s:%s:%s",
+ pwd->pw_name, (uintmax_t)pwd->pw_uid,
+ grp ? grp->gr_name : "unknown",
+ (uintmax_t)(grp ? grp->gr_gid : (uid_t)-1),
+ pwd->pw_gecos, pwd->pw_dir, pwd->pw_shell);
+
+ /*
+ * let's touch and chown the user's mail file. This is not
+ * strictly necessary under BSD with a 0755 maildir but it also
+ * doesn't hurt anything to create the empty mailfile
+ */
+ if (PWALTDIR() != PWF_ALT) {
+ snprintf(path, sizeof(path), "%s/%s", _PATH_MAILDIR,
+ pwd->pw_name);
+ /* Preserve contents & mtime */
+ close(openat(conf.rootfd, path +1, O_RDWR | O_CREAT, 0600));
+ fchownat(conf.rootfd, path + 1, pwd->pw_uid, pwd->pw_gid,
+ AT_SYMLINK_NOFOLLOW);
+ }
+
+ /*
+ * Let's create and populate the user's home directory. Note
+ * that this also `works' for editing users if -m is used, but
+ * existing files will *not* be overwritten.
+ */
+ if (PWALTDIR() != PWF_ALT && createhome && pwd->pw_dir &&
+ *pwd->pw_dir == '/' && pwd->pw_dir[1])
+ create_and_populate_homedir(cmdcnf, pwd, cmdcnf->dotdir,
+ cmdcnf->homemode, false);
+
+ if (!PWALTDIR() && cmdcnf->newmail && *cmdcnf->newmail &&
+ (fp = fopen(cnf->newmail, "r")) != NULL) {
+ if ((pfp = popen(_PATH_SENDMAIL " -t", "w")) == NULL)
+ warn("sendmail");
+ else {
+ fprintf(pfp, "From: root\n" "To: %s\n"
+ "Subject: Welcome!\n\n", pwd->pw_name);
+ while (fgets(line, sizeof(line), fp) != NULL) {
+ /* Do substitutions? */
+ fputs(line, pfp);