From: roberts@nimrod.wpd.sgi.com (roberts)
Subject: Re:  how do I make sendmail use the name server rather than /etc/hosts
Organization: Silicon Graphics, Inc.  Mountain View, CA
Date: Fri, 31 Jul 1992 00:21:11 GMT


Jeffrey W. Tannehill writes:
> 
> 	# Canonicalize the host name.  Detect any failures.
> 	R$*<@$+>$*              $:$1<@$[$2$:$2.$Y$]>$3
>  
> 	# If we successfully canonicalize a hostname, but the result contains
> 	# no dots, make it relative to our domain.
> 	R$*<@$->$*              $1<@$2.$D>$3
> 
> Apparently, the first rule takes "bob@physics.phy.duke.edu" and changes it to 
> something like "bob@physics" and the second line then rewrites this as 
> "bob@physics.cs.duke.edu".

The first rule canonicalizes the "physics.phy.duke.edu" part of the address
($2) by feeding it to gethostbyname(3N).  If gethostbyname returns with no
error, the $[$2$:$2.$Y$] on the RHS of the rewrite rule will resolve to
the contents of the h_name field of the hostent returned by gethostbyname
(the canonical host name).  If gethostbyname returns an error, the
$[$2$:$2.$Y$] on the RHS of the rewrite will resolve to the initial host
name ($2) appended with a dot and the $Y macro (.FAIL).  (The .FAIL suffix
is used by later rewrite rules to determine whether or not the canonicalization
step was successful.)

The second rule matches any address with a single token hostname.  (Since any
failed canonicalization step would have added .FAIL to the hostname, a
single-token hostname at this point must be a canonical single token hostname.)
This rule appends the local domain name to any such hostname (the local domain
name may be null and must be if the network does not use domain naming).
This handles cases where folks within a domain prefer to have canonical
hostnames within that domain that do not contain the domain qualifier.  Note
that it assumes that all single token canonical hostnames exist within the
local domain.  Your situation violates that assumption, so the "wrong" domain
gets appended.

What the second rule is doing is restoring information lost during the
canonicalization step.  Since the host really does exist in a specific domain,
the trick of hiding the domain name by canonicalizing to a single token
host name throws away vital information needed by later rewrite rules.  For
example, later rewrite rules decide whether or not to send a message via
the forwarder host based on whether or not the destination host is contained
within the top level domain (T macro).  If the real domain information for
the destination host were lost, these later rules would do the wrong things.

It is best to always canonicalize to the Fully Qualified Domain Name and
avoid these hassles.  I'm supporting the non-FQDN canonical name case for
historical reasons.

>			If the name services is consulted instead of the
> /etc/hosts file (i.e. I remove physics from the hosts file) then the mail
> is sent properly.

The name server returns a FQDN.

>                    I tried using the "-oI" option with sendmail, which the 
> man page says will
> 
>      	  Insist that the domain name server be running to resolve host names
>           and MX records.  Treat ECONNREFUSED errors from the resolver as
>           temporary failures.
> 
> but this had no effect when the entry for physics was in the /etc/hosts file.

Yes, because you got the entry from /etc/hosts and never got an ECONNREFUSED
error.  That option means that if the domain name server is your only source
of canonical names, and if it returns ECONNREFUSED, queue the message and
wait for the domain name server to come back on line.

> Since I prefer to use the name services anyway (it is more likely to be
> correct than the local /etc/hosts file), then is there anyway that I can
> make sendmail consult the name services first?  

Check the stuff about hostresorder in the resolver(4) man page.

	- Robert Stephens
	  Silicon Graphics Inc.


Newsgroups: comp.sys.sgi