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
This commit is contained in:
parent
093a61588e
commit
2be196f14c
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user