Bug 29892

Summary: pw user add + qmail problem
Product: Base System Reporter: Jan Srzednicki <winfried>
Component: binAssignee: dd <dd>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.4-PRERELEASE   
Hardware: Any   
OS: Any   

Description Jan Srzednicki 2001-08-20 08:50:02 UTC
When delivering locally, qmail checks whether recipients home dir exists and 
is owned by the user. If not it returns a non-existing account error. 
When pw is set to send welcome greetz email to the new user and to create his 
homedir, it first sends the email (which is bounced by qmail, becouse the
homedir doesn't exist yet) and then creates the homedir.

Fix: 

Put the homedir creation code before mail sending code in 
/usr/src/usr.sbin/pw/pw_user.c
How-To-Repeat: 
Configure pw to send welcome greetings email and create user's directory 
by "pw user add" command.
qmail will then return a permanent error and bounce the mail back to root.
Comment 1 dima 2001-08-30 11:32:12 UTC
Jan Srzednicki <winfried@dream.vg> wrote:
> >Description:
> 
> When delivering locally, qmail checks whether recipients home dir exists and 
> is owned by the user. If not it returns a non-existing account error. 
> When pw is set to send welcome greetz email to the new user and to create his
>  
> homedir, it first sends the email (which is bounced by qmail, becouse the
> homedir doesn't exist yet) and then creates the homedir.

Please try the attached patch.  It should apply cleanly to src/usr.sbin/pw.

Index: pw_user.c
===================================================================
RCS file: /ref/cvsf/src/usr.sbin/pw/pw_user.c,v
retrieving revision 1.48
diff -u -r1.48 pw_user.c
--- pw_user.c	21 Aug 2001 13:33:20 -0000	1.48
+++ pw_user.c	30 Aug 2001 10:31:16 -0000
@@ -113,6 +113,7 @@
 	struct group   *grp;
 	struct stat     st;
 	char            line[_PASSWORD_LEN+1];
+	FILE	       *fp;
 
 	static struct passwd fakeuser =
 	{
@@ -730,39 +731,16 @@
 	 * 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.
 	 */
@@ -770,6 +748,28 @@
 		copymkdir(pwd->pw_dir, cnf->dotdir, 0755, pwd->pw_uid, pwd->pw_gid);
 		pw_log(cnf, mode, W_USER, "%s(%ld) home %s made",
 		       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;
Comment 2 dd freebsd_committer freebsd_triage 2001-08-30 11:32:16 UTC
Responsible Changed
From-To: freebsd-bugs->dd

I have a fix for this.
Comment 3 Jan Srzednicki 2001-09-03 10:38:27 UTC
On Thu, 30 Aug 2001, Dima Dorfman wrote:

> Please try the attached patch.  It should apply cleanly to src/usr.sbin/pw.

Seems to work fine. Didn't do heavy testing though, but I don't thing pw
needs that.

--
Winfried
mail: winfried@dream.vg  http://www.violent.dream.vg  ICQ# 104354396
  ,, 1. ¦wiat jest niesprawiedliwy.
     2. ¦wiat jest niesprawiedliwy, nawet gdy wydaje ci siê inaczej.
     3. Wszelka dostrze¿ona sprawiedliwo¶æ stanowi w istocie objaw
        niesprawiedliwo¶ci wy¿szego rzêdu. '' - Jacek Dukaj
Comment 4 dd freebsd_committer freebsd_triage 2001-09-03 15:12:59 UTC
State Changed
From-To: open->analyzed

Fixed in -current, I'll MFC some time after the release.
Comment 5 dima 2001-09-03 15:14:00 UTC
Jan Srzednicki <winfried@dream.vg> wrote:
> On Thu, 30 Aug 2001, Dima Dorfman wrote:
> 
> > Please try the attached patch.  It should apply cleanly to src/usr.sbin/pw.
> 
> Seems to work fine. Didn't do heavy testing though, but I don't thing pw
> needs that.

It's not that it doesn't need it, just that there's no new code.  All
I did was move one block after another.  The reason the diff is so
large is because one of the blocks was in an if() statement.

I've applied the patch to -current, and will MFC it some time after
4.4-RELEASE.
Comment 6 dd freebsd_committer freebsd_triage 2001-11-23 16:04:54 UTC
State Changed
From-To: analyzed->closed

MFC'd 2001/10/15