From root@ikar.pl  Mon Aug 20 00:47:35 2001
Return-Path: <root@ikar.pl>
Received: from ikar.pl (spitfire.303.krakow.pl [217.96.99.173])
	by hub.freebsd.org (Postfix) with SMTP id 089C437B40C
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 20 Aug 2001 00:47:27 -0700 (PDT)
	(envelope-from root@ikar.pl)
Received: (qmail 1557 invoked by uid 0); 20 Aug 2001 07:46:41 -0000
Message-Id: <20010820074641.1556.qmail@ikar.pl>
Date: 20 Aug 2001 07:46:41 -0000
From: Jan Srzednicki <winfried@dream.vg>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: pw user add + qmail problem
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         29892
>Category:       bin
>Synopsis:       pw user add + qmail problem
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    dd
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Aug 20 00:50:02 PDT 2001
>Closed-Date:    Fri Nov 23 08:04:54 PST 2001
>Last-Modified:  Fri Nov 23 08:05:04 PST 2001
>Originator:     Jan Srzednicki
>Release:        FreeBSD 4.4-PRERELEASE i386
>Organization:
MPS
>Environment:
System: 
FreeBSD ikar.pl 4.4-PRERELEASE FreeBSD 4.4-PRERELEASE #1: Tue Aug 7 14:41:13 CEST 2001

sources cvsupped recently.

	
>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.
	
>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.
	
>Fix:

Put the homedir creation code before mail sending code in 
/usr/src/usr.sbin/pw/pw_user.c
	
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->dd 
Responsible-Changed-By: dd 
Responsible-Changed-When: Thu Aug 30 03:32:16 PDT 2001 
Responsible-Changed-Why:  
I have a fix for this. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=29892 

From: Dima Dorfman <dima@unixfreak.org>
To: Jan Srzednicki <winfried@dream.vg>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/29892: pw user add + qmail problem 
Date: Thu, 30 Aug 2001 03:32:12 -0700

 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;

From: Jan Srzednicki <winfried@dream.vg>
To: Dima Dorfman <dima@unixfreak.org>
Cc: <FreeBSD-gnats-submit@freebsd.org>
Subject: Re: bin/29892: pw user add + qmail problem 
Date: Mon, 3 Sep 2001 11:38:27 +0200 (CEST)

 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 dostrzeona sprawiedliwo stanowi w istocie objaw
         niesprawiedliwoci wyszego rzdu. '' - Jacek Dukaj
 
State-Changed-From-To: open->analyzed 
State-Changed-By: dd 
State-Changed-When: Mon Sep 3 07:12:59 PDT 2001 
State-Changed-Why:  
Fixed in -current, I'll MFC some time after the release. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=29892 

From: Dima Dorfman <dima@unixfreak.org>
To: Jan Srzednicki <winfried@dream.vg>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/29892: pw user add + qmail problem 
Date: Mon, 03 Sep 2001 07:14:00 -0700

 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.
State-Changed-From-To: analyzed->closed 
State-Changed-By: dd 
State-Changed-When: Fri Nov 23 08:04:54 PST 2001 
State-Changed-Why:  
MFC'd 2001/10/15 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=29892 
>Unformatted:
