[comp.mail.sendmail] Problem with host sending MX-ed mail to itself

mb@rex.cs.tulane.edu (Mark Benard) (02/15/91)

I am running sendmail 5.61 and just noticed the following problem.

We serve as secondary MX site for several other hosts on campus, so when they
are down, we get their mail.  But after this host receives such mail, it
tries to forward it to the final destination.  Since the final destination is
down, it tries the secondary MX site - itself.  (This results in a 553 error
to prevent looping.)

Shouldn't my sendmail recognize itself as the secondary MX site and just
queue the mail until the destination can receive it?  Is this a problem with
sendmail 5.61 or do I just have a configuration error?

rickert@mp.cs.niu.edu (Neil Rickert) (02/16/91)

In article <6166@rex.cs.tulane.edu> mb@rex.cs.tulane.edu (Mark Benard) writes:
>I am running sendmail 5.61 and just noticed the following problem.
>
>We serve as secondary MX site for several other hosts on campus, so when they
>are down, we get their mail.  But after this host receives such mail, it
>tries to forward it to the final destination.  Since the final destination is
>down, it tries the secondary MX site - itself.  (This results in a 553 error
>to prevent looping.)
>
>Shouldn't my sendmail recognize itself as the secondary MX site and just
>queue the mail until the destination can receive it?  Is this a problem with
>sendmail 5.61 or do I just have a configuration error?

  Absolutely it should.  And the code is there in sendmail to do so.  But you
have to be sure you don't outsmart it.

  'sendmail' compares the hostname on the destination of the MX record with
the value of $w.  You must make sure that $w is the FULLY QUALIFIED DOMAIN
NAME of your host, and that the MX record refers to that name and not to some
alias.  Unfortunately there are many rulesets out there which incorrectly use
$w as the unqualified host name.

-- 
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
  Neil W. Rickert, Computer Science               <rickert@cs.niu.edu>
  Northern Illinois Univ.
  DeKalb, IL 60115                                   +1-815-753-6940

vixie@decwrl.dec.com (Paul A Vixie) (02/16/91)

As Mr. Rickert points out, you need to make sure that $w is the same as
the name listed in the MX.  If you are a multi-homed host, and your
interface addresses have different names attached to them, and if you
are listed in some MX's by one name and in other MX's by some other name,
then you might wish that sendmail would ignore MX's in $=w rather than
those which match $w, and in that case, you need a patch that I made to
KJS last week.  It will appear in the next release, which should also
be based on 5.65 (but don't hold your breath or you may turn blue).  The
patch goes something like this (assuming -DDECWRL in Makefile):

*** /tmp/,RCSt1a25728	Fri Feb 15 23:30:16 1991
--- domain.c	Thu Jan 31 13:41:35 1991
***************
*** 41,48 ****
  
  static char hostbuf[MAXMXHOSTS*PACKETSZ];
  
! getmxrr(host, mxhosts, localhost, rcode)
! 	char *host, **mxhosts, *localhost;
  	int *rcode;
  {
  	extern int h_errno;
--- 41,48 ----
  
  static char hostbuf[MAXMXHOSTS*PACKETSZ];
  
! getmxrr(host, mxhosts, rcode)
! 	char *host, **mxhosts;
  	int *rcode;
  {
  	extern int h_errno;
***************
*** 118,124 ****
  		if ((n = dn_expand((char *)&answer, eom, cp, bp, buflen)) < 0)
  			break;
  		cp += n;
! 		if (!strcasecmp(bp, localhost)) {
  			if (seenlocal == 0 || pref < localpref)
  				localpref = pref;
  			seenlocal = 1;
--- 118,124 ----
  		if ((n = dn_expand((char *)&answer, eom, cp, bp, buflen)) < 0)
  			break;
  		cp += n;
! 		if (host_is_local(bp)) {
  			if (seenlocal == 0 || pref < localpref)
  				localpref = pref;
  			seenlocal = 1;
***************
*** 166,171 ****
--- 166,179 ----
  		}
  	}
  	return(nmx);
+ }
+ 
+ int
+ host_is_local(h)
+ 	char *h;
+ {
+ 	STAB *s = stab(h, ST_CLASS, ST_FIND);
+ 	return (s != NULL && bitnset('w', s->s_class));
  }
  
  /*
*** /tmp/,RCSt1a25728	Fri Feb 15 23:30:17 1991
--- deliver.c	Thu Jan 31 13:35:22 1991
***************
*** 18,24 ****
  
  #ifndef lint
  static char sccsid[] = "@(#)deliver.c	5.26 (Berkeley) 1/1/89";
! static char rcsid[] = "$Header: deliver.c,v 1.8 90/10/23 20:03:33 vixie Locked $";
  #endif /* not lint */
  
  #include <sendmail.h>
--- 18,24 ----
  
  #ifndef lint
  static char sccsid[] = "@(#)deliver.c	5.26 (Berkeley) 1/1/89";
! static char rcsid[] = "$Header: deliver.c,v 1.8 90/10/23 20:03:33 vixie Exp $";
  #endif /* not lint */
  
  #include <sendmail.h>
***************
*** 449,466 ****
  #ifdef SMTP
  	if (clever)
  	{
  		expand("\001w", buf, &buf[sizeof(buf) - 1], e);
  		rcode = EX_OK;
  #ifdef NAMED_BIND
  		if (host[0] != '[' && m->m_mailer[0] != '/')
  		{
- 			Nmx = getmxrr(host, MxHosts, buf, &rcode);
  #ifdef DECWRL
  			if (Nmx == -1)
  			{
  				Nmx = 1;
  				MxHosts[0] = host;
  			}
  #endif DECWRL
  		}
  		else
--- 449,470 ----
  #ifdef SMTP
  	if (clever)
  	{
+ #ifndef DECWRL
  		expand("\001w", buf, &buf[sizeof(buf) - 1], e);
+ #endif DECWRL
  		rcode = EX_OK;
  #ifdef NAMED_BIND
  		if (host[0] != '[' && m->m_mailer[0] != '/')
  		{
  #ifdef DECWRL
+ 			Nmx = getmxrr(host, MxHosts, &rcode);
  			if (Nmx == -1)
  			{
  				Nmx = 1;
  				MxHosts[0] = host;
  			}
+ #else DECWRL
+ 			Nmx = getmxrr(host, MxHosts, buf, &rcode);
  #endif DECWRL
  		}
  		else
--
Paul Vixie
DEC Western Research Lab	<vixie@wrl.dec.com>
Palo Alto, California		...!decwrl!vixie