summaryrefslogtreecommitdiffstats
path: root/pw
diff options
context:
space:
mode:
authorDima Dorfman <dd@FreeBSD.org>2001-09-03 14:12:42 +0000
committerDima Dorfman <dd@FreeBSD.org>2001-09-03 14:12:42 +0000
commitd42f11d7dcacdbfb839c22012c4adf7e0a803b3b (patch)
tree78264d0d889c515a0c41bc076547904cb73e53cf /pw
parent9a02d1e0da0818375a208378d76d157c9c69b3a3 (diff)
downloadpw-darwin-d42f11d7dcacdbfb839c22012c4adf7e0a803b3b.tar.gz
pw-darwin-d42f11d7dcacdbfb839c22012c4adf7e0a803b3b.tar.zst
pw-darwin-d42f11d7dcacdbfb839c22012c4adf7e0a803b3b.zip
For new users, create the home directory before sending the welcome
mail, if configured to do so. Some sites have setups where the user's mail is delivered to their home directory, so sending mail before is exists didn't work. PR: 29892
Diffstat (limited to 'pw')
-rw-r--r--pw/pw_user.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/pw/pw_user.c b/pw/pw_user.c
index c1bfd94..125d032 100644
--- a/pw/pw_user.c
+++ b/pw/pw_user.c
@@ -113,6 +113,7 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
struct group *grp;
struct stat st;
char line[_PASSWORD_LEN+1];
+ FILE *fp;
static struct passwd fakeuser =
{
@@ -730,39 +731,16 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
* doesn't hurt anything to create the empty mailfile
*/
if (mode == M_ADD) {
- FILE *fp;
-
if (!PWALTDIR()) {
sprintf(line, "%s/%s", _PATH_MAILDIR, pwd->pw_name);
close(open(line, O_RDWR | O_CREAT, 0600)); /* Preserve contents &
* mtime */
chown(line, pwd->pw_uid, pwd->pw_gid);
-
- /*
- * Send mail to the new user as well, if we are asked to
- */
- if (cnf->newmail && *cnf->newmail && (fp = fopen(cnf->newmail, "r")) != NULL) {
- FILE *pfp = popen(_PATH_SENDMAIL " -t", "w");
-
- if (pfp == 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);
- }
- pclose(pfp);
- pw_log(cnf, mode, W_USER, "%s(%ld) new user mail sent",
- pwd->pw_name, (long) pwd->pw_uid);
- }
- fclose(fp);
- }
}
}
/*
- * Finally, let's create and populate the user's home directory. Note
+ * 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.
*/
@@ -772,6 +750,28 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
pwd->pw_name, (long) pwd->pw_uid, pwd->pw_dir);
}
+
+ /*
+ * Finally, send mail to the new user as well, if we are asked to
+ */
+ if (mode == M_ADD && !PWALTDIR() && cnf->newmail && *cnf->newmail && (fp = fopen(cnf->newmail, "r")) != NULL) {
+ FILE *pfp = popen(_PATH_SENDMAIL " -t", "w");
+
+ if (pfp == 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);
+ }
+ pclose(pfp);
+ pw_log(cnf, mode, W_USER, "%s(%ld) new user mail sent",
+ pwd->pw_name, (long) pwd->pw_uid);
+ }
+ fclose(fp);
+ }
+
return EXIT_SUCCESS;
}