Subject: bin/14412: rdist notify can generate bad To: mail addresses
To: None <gnats-bugs@gnats.netbsd.org>
From: None <ginsbach@cray.com>
List: netbsd-bugs
Date: 10/31/2001 15:35:11
>Number:         14412
>Category:       bin
>Synopsis:       rdist notify can generate bad To: mail addresses
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Oct 31 13:36:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Brian Ginsbach
>Release:        NetBSD 1.5.2 and current
>Organization:
Cray Inc.
>Environment:
n.a.

>Description:
	It is possible for the notify command to generate bad mail
	addresses.  It is possible to get them in the form of
	user@login@host.  Needless to say sendmail doesn't really
	like this form.  It is also apparent when running rdist
	with the -n option.

>How-To-Repeat:
	Create a distfile that uses the user@host form for the host
	to rdist to.  Example:  (distfile)

HOSTS		=	(nbsrc@ncostest ltest)
FILES		=	(/home/bg/netbsd/rdist_files)
TARGET		=	(/proj/netbsd)

${FILES}	->	${HOSTS}
			install -R ${TARGET} ;
			notify (bg nbteam@mailhost) ;

	Run using the above distfile with the -n option.

nbtest> rdist -f distfile -n
updating host nbsrc@ncostest
install /home/bg/netbsd/rdist_files /proj/netbsd
notify @nbsrc@ncostest ( bg nbteam@mailhost )		<<== incorrect!
updating host ltest
install /home/bg/netbsd/rdist_files /proj/netbsd
notify @ltest ( bg nbteam@mailhost )			<<== correct!

	Running the above without the -n option produces a mail
	To: header line like the following:

To: bg@nbsrc@ncostest, nbteam@mailhost		<<== INCORRECT!

	and

To: bg@ltest, nbteam@mailhost			<<== correct

>Fix:
	The workaround is to not use user@host and notify or use
	an address that contains an '@'.  The fix is below.

Index: docmd.c
===================================================================
RCS file: /cvsroot/basesrc/usr.bin/rdist/docmd.c,v
retrieving revision 1.20
diff -u -r1.20 docmd.c
--- docmd.c	2000/06/12 04:43:11	1.20
+++ docmd.c	2001/10/31 20:51:25
@@ -545,13 +545,19 @@
 	int fd, len;
 	struct stat stb;
 	FILE *pf;
+	char *cp, *nrhost = rhost;
 
 	if ((options & VERIFY) || to == NULL)
 		return;
+
+	/* strip any leading user@ prefix from rhost */
+	if (rhost && (cp = strchr(rhost, '@')) != NULL)
+		nrhost = cp + 1;
+
 	if (!qflag) {
 		printf("notify ");
 		if (rhost)
-			printf("@%s ", rhost);
+			printf("@%s ", nrhost);
 		prnames(to);
 	}
 	if (nflag)
@@ -586,13 +592,13 @@
 	fprintf(pf, "From: rdist (Remote distribution program)\n");
 	fprintf(pf, "To:");
 	if (!any('@', to->n_name) && rhost != NULL)
-		fprintf(pf, " %s@%s", to->n_name, rhost);
+		fprintf(pf, " %s@%s", to->n_name, nrhost);
 	else
 		fprintf(pf, " %s", to->n_name);
 	to = to->n_next;
 	while (to != NULL) {
 		if (!any('@', to->n_name) && rhost != NULL)
-			fprintf(pf, ", %s@%s", to->n_name, rhost);
+			fprintf(pf, ", %s@%s", to->n_name, nrhost);
 		else
 			fprintf(pf, ", %s", to->n_name);
 		to = to->n_next;
>Release-Note:
>Audit-Trail:
>Unformatted: