summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pw
diff options
context:
space:
mode:
authordd <dd@FreeBSD.org>2001-09-03 14:12:42 +0000
committerdd <dd@FreeBSD.org>2001-09-03 14:12:42 +0000
commit3c48707476de97f838adbbe8557b6072a25927ad (patch)
tree62774f3784ed7066002aaa60280d94d184ff365e /usr.sbin/pw
parent6315b454a5296c1dc3150fd21b2f0da648599384 (diff)
downloadFreeBSD-src-3c48707476de97f838adbbe8557b6072a25927ad.zip
FreeBSD-src-3c48707476de97f838adbbe8557b6072a25927ad.tar.gz
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 'usr.sbin/pw')
-rw-r--r--usr.sbin/pw/pw_user.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/usr.sbin/pw/pw_user.c b/usr.sbin/pw/pw_user.c
index c1bfd94..125d032 100644
--- a/usr.sbin/pw/pw_user.c
+++ b/usr.sbin/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;
}
OpenPOWER on IntegriCloud