[net.mail] changing hostname aliases to real official names

lee@rochester.UUCP (Lee Moore) (08/07/85)

I hope this questions isn't too lame but what is the easiest
way to make sendmail re-write aliases for hosts to be the official
names?  Can this be done without actually touching the C code?

thanks!


-- 
TCP/IP:		lee@rochester.arpa
UUCP:		{decvax, allegra, seismo, cmcl2}!rochester!lee
XNS:		Lee Moore:CS:Univ Rochester
Phone:		+1 (716) 275-7747, -5671
Physical:	43 01' 40'' N, 77 37' 49'' W

hedrick@topaz.RUTGERS.EDU (Chuck Hedrick) (08/08/85)

In article <10904@rochester.UUCP>, lee@rochester.UUCP (Lee Moore) writes:
> I hope this questions isn't too lame but what is the easiest
> way to make sendmail re-write aliases for hosts to be the official
> names?  Can this be done without actually touching the C code?

We have not figured out any way to do this without modifying the C
code.  For those who don't understand the request, this is part of the
Arpanet domain conversion.  Our full domain names are thing like
TOPAZ.RUTGERS.EDU.  Local users do not want to type these.  So we will
provide aliases such as TOPAZ.  However according to the RFC's, if a
message leaves Rutgers, any host names mentioned in headers should
have the full domain qualification.  The simplest way to enforce this
is to turn the aliases into the official host name automatically.

The following code does two things: (1) it prevents sendmail from
appending .ARPA to all host names. (2) it adds an operator to be used
in SENDMAIL.CF that maps a host name into its official form.  This
operator works only on the RHS side of a production.  $%2 works just
like $2.  I.e. it causes the second thing matched by the LHS to be
replaced.  However the thing being replaced it first checked against
/etc/hosts and if it is a nickname is turned into the primary host
name.  If the thing is not a nickname it is copied with change.

There is a warning about the implementation: The item on the RHS is
put in a fixed place in memory.  This means that there can be only one
such mapped host name active at any given time.  A second one would be
put in the same place as the first.  This does not seem to be a
problem the way we use it, since sendmail analyses one address at a
time.  However you should be careful if you play with things like
foo%bar@baz.  If you tried to dealias both bar and baz, you would get
in trouble.


*** daemon.c.ORIG	Fri Feb 10 06:59:21 1984
--- daemon.c	Sat Aug  3 07:49:46 1985
***************
*** 183,189
  			/* determine host name */
  			hp = gethostbyaddr(&otherend.sin_addr, sizeof otherend.sin_addr, AF_INET);
  			if (hp != NULL)
! 				(void) sprintf(buf, "%s.ARPA", hp->h_name);
  			else
  				/* this should produce a dotted quad */
  				(void) sprintf(buf, "%lx", otherend.sin_addr.s_addr);

--- 185,191 -----
  			/* determine host name */
  			hp = gethostbyaddr(&otherend.sin_addr, sizeof otherend.sin_addr, AF_INET);
  			if (hp != NULL)
! 				(void) sprintf(buf, "%s", hp->h_name);
  			else
  				/* this should produce a dotted quad */
  				(void) sprintf(buf, "%lx", otherend.sin_addr.s_addr);
*** main.c.ORIG	Fri Feb 10 11:17:52 1984
--- main.c	Sat Aug  3 05:08:28 1985
***************
*** 702,707
  	/* and finally the conditional operations */
  	'?', CONDIF,	'|', CONDELSE,	'.', CONDFI,
  
  	'\0'
  };
  

--- 702,710 -----
  	/* and finally the conditional operations */
  	'?', CONDIF,	'|', CONDELSE,	'.', CONDFI,
  
+ 	/* now the normalization operator */
+ 	'%', NORMREPL,
+ 
  	'\0'
  };
  
*** parseaddr.c.ORIG	Fri Feb 10 06:59:12 1984
--- parseaddr.c	Sat Aug  3 06:08:42 1985
***************
*** 446,451
  
  # define MAXMATCH	9	/* max params per rewrite */
  
  
  rewrite(pvp, ruleset)
  	char **pvp;

--- 446,452 -----
  
  # define MAXMATCH	9	/* max params per rewrite */
  
+ char hostbuf[512];
  
  
  rewrite(pvp, ruleset)
***************
*** 447,452
  # define MAXMATCH	9	/* max params per rewrite */
  
  
  rewrite(pvp, ruleset)
  	char **pvp;
  	int ruleset;

--- 448,454 -----
  
  char hostbuf[512];
  
+ 
  rewrite(pvp, ruleset)
  	char **pvp;
  	int ruleset;
***************
*** 626,631
  		/* substitute */
  		for (avp = npvp; *rvp != NULL; rvp++)
  		{
  			register struct match *m;
  			register char **pp;
  

--- 628,634 -----
  		/* substitute */
  		for (avp = npvp; *rvp != NULL; rvp++)
  		{
+ #include <netdb.h>
  			register struct match *m;
  			register char **pp;
  			char **oldavp,**tavp;
***************
*** 628,633
  		{
  			register struct match *m;
  			register char **pp;
  
  			rp = *rvp;
  			if (*rp != MATCHREPL)

--- 631,638 -----
  #include <netdb.h>
  			register struct match *m;
  			register char **pp;
+ 			char **oldavp,**tavp;
+ 			struct hostent *hostpt;
  
  			rp = *rvp;
  			if ((*rp != MATCHREPL) && (*rp != NORMREPL))
***************
*** 630,636
  			register char **pp;
  
  			rp = *rvp;
! 			if (*rp != MATCHREPL)
  			{
  				if (avp >= &npvp[MAXATOM])
  				{

--- 635,641 -----
  			struct hostent *hostpt;
  
  			rp = *rvp;
! 			if ((*rp != MATCHREPL) && (*rp != NORMREPL))
  			{
  				if (avp >= &npvp[MAXATOM])
  				{
***************
*** 642,647
  			}
  
  			/* substitute from LHS */
  			m = &mlist[rp[1] - '1'];
  # ifdef DEBUG
  			if (tTd(21, 15))

--- 647,653 -----
  			}
  
  			/* substitute from LHS */
+ 
  			m = &mlist[rp[1] - '1'];
  # ifdef DEBUG
  			if (tTd(21, 15))
***************
*** 658,663
  			}
  # endif DEBUG
  			pp = m->first;
  			while (pp <= m->last)
  			{
  				if (avp >= &npvp[MAXATOM])

--- 664,670 -----
  			}
  # endif DEBUG
  			pp = m->first;
+ 			oldavp = avp;
  			while (pp <= m->last)
  			{
  				if (avp >= &npvp[MAXATOM])
***************
*** 666,671
  					return;
  				}
  				*avp++ = *pp++;
  			}
  		}
  		*avp++ = NULL;

--- 673,688 -----
  					return;
  				}
  				*avp++ = *pp++;
+ 			}
+ 			if (*rp == NORMREPL) {
+ 			  hostbuf[0] = '\0';
+ 			  for (tavp = oldavp; tavp < avp; tavp++)
+ 			    strcat(hostbuf,*tavp);
+ 			  hostpt = gethostbyname(hostbuf);
+ 			  if (hostpt) {
+ 			    *oldavp = hostpt -> h_name;
+ 			    avp = oldavp + 1;
+ 			  }
  			}
  		}
  		*avp++ = NULL;
*** sendmail.h.ORIG	Fri Feb 10 06:59:10 1984
--- sendmail.h	Sat Aug  3 05:06:53 1985
***************
*** 290,295
  # define CONDIF		'\031'	/* conditional if-then */
  # define CONDELSE	'\032'	/* conditional else */
  # define CONDFI		'\033'	/* conditional fi */
  /*
  **  Symbol table definitions
  */

--- 290,299 -----
  # define CONDIF		'\031'	/* conditional if-then */
  # define CONDELSE	'\032'	/* conditional else */
  # define CONDFI		'\033'	/* conditional fi */
+ 
+ /* normalize Internet address operator */
+ # define NORMREPL       '\034'  /* normalized host replacement */
+ 
  /*
  **  Symbol table definitions
  */