#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	uucpdomain
# This archive created: Thu Mar 19 16:14:24 1987
export PATH; PATH=/bin:/usr/bin:$PATH
if test ! -d 'uucpdomain'
then
	echo shar: "creating directory 'uucpdomain'"
	mkdir 'uucpdomain'
fi
echo shar: "entering directory 'uucpdomain'"
cd 'uucpdomain'
echo shar: "extracting 'README'" '(2162 characters)'
if test -f 'README'
then
	echo shar: "will not over-write existing file 'README'"
else
cat << \SHAR_EOF > 'README'
this shell archive includes diffs to version 5.54 of sendmail
(available in pub/4.3/sendmail.MX.tar on ucbarpa.berkeley.edu) to
support pathalias lookup directly in sendmail.  these modifications add
to sendmail another set of right hand side metasymbols similar to `$['
and `$]'.  a host name enclosed between `${' and `$}' is looked up in
the pathalias database and the shortest known path to that host is
returned.

start out by patching a copy of a 5.54 based sendmail using the
enclosed diffs and recompiling sendmail.  assuming this completes
without error, a number of small changes need to be made to the
sendmail configuration file currently being used.  first of all, add
the following line to the section defining options (often right after
defining the load average where connections are refused)

	# location of pathalias file
	Op/usr/local/lib/palias

this is the pathname where the dbm version of the pathalias data is
stored.

next, the following rules need to be added in ruleset zero usually
before any mailers are `called' with the `$#' metasymbol.

	R$*<@$+.$+>$*		$:$1<@${$2.$3$}>$4
	R$*<@%s>$*		$1
	R$*<@$-!%s>$*		$1<@$2.UUCP>$3
	R$*<@$-!$+!%s>$*	$3!$1<@$2.UUCP>$4

it should be noted that sites on the internet should filter the output
of pathalias before creating the corresponding dbm database, because
many organizations registered with the nic also show up in the maps and
if the appropriate entries are not removed, mail will be sent via uucp
rather than over the internet using smtp.  for example, the domain
`css.gov' is registered with the nic and it is also registered in the
maps, so if a pathalias entry like

	.css.gov	ism780c!seismo!%s

is left in the database, mail will be sent through `ism780c' rather
than where the name server says to send it.  enclosed is a sample
script, mkpalias.sh, that creates the dbm version of the pathalias
database and filters out all domain based names from the output of
pathalias with the exception of those listed in the file `domains'.
the `domains' file used on seismo is enclosed, although most internet
sites only need to list those domains (if any) that they forward mail
to via uucp.
SHAR_EOF
if test 2162 -ne "`wc -c < 'README'`"
then
	echo shar: "error transmitting 'README'" '(should have been 2162 characters)'
fi
chmod 444 'README'
fi
echo shar: "extracting 'domains'" '(673 characters)'
if test -f 'domains'
then
	echo shar: "will not over-write existing file 'domains'"
else
cat << \SHAR_EOF > 'domains'
ait.com
alliant.com
alphacdc.com
amdahl.com
app.edu
att.com
au
bdm.com
bell-atl.com
brs.com
bsw.com
buck.com
ccur.com
cidnet.com
decision.com
fi
ge.com
grebyn.com
hac.com
harris.com
hawaii.edu
howtek.com
icom.com
inmet.com
isc.com
itcorp.com
jp
jpn
junet
kesmai.com
marque.edu
navsea.mil
nbi.com
ndmce.com
nec.com
nl
# shouldn't really be here, but since relay.cs.net doesn't recognize them yet
nz
olivetti.com
oz
peregrine.com
# shouldn't really be here, but rick prefers the direct path
plus5.com
rdl.com
rel.com
retix.com
se
tandy.com
tmc.com
tti.com
unm.edu
usi.com
# these two are gone from the maps, but the nic still has their mx records
usma.edu
vortex.com
vse.com
SHAR_EOF
if test 673 -ne "`wc -c < 'domains'`"
then
	echo shar: "error transmitting 'domains'" '(should have been 673 characters)'
fi
chmod 444 'domains'
fi
echo shar: "extracting 'diffs.sendmail'" '(6543 characters)'
if test -f 'diffs.sendmail'
then
	echo shar: "will not over-write existing file 'diffs.sendmail'"
else
cat << \SHAR_EOF > 'diffs.sendmail'
*** sendmail/src/sendmail.h.orig	Wed Jul 23 18:27:00 1986
--- sendmail/src/sendmail.h	Thu Feb 26 18:46:07 1987
***************
*** 321,326 ****
--- 325,336 ----
  # define HOSTBEGIN	'\035'	/* hostname lookup begin */
  # define HOSTEND	'\036'	/* hostname lookup end */
  
+ #if defined(DBM) && defined(UUCPDOMAIN)
+ /* brace characters for uucp name lookup */
+ # define UUCPBEGIN	'\016'	/* uucpname lookup begin */
+ # define UUCPEND	'\017'	/* uucpname lookup end */
+ #endif
+ 
  /* \001 is also reserved as the macro expansion character */
  /*
  **  Information about hosts that we have looked up recently.
***************
*** 531,536 ****
--- 543,549 ----
  EXTERN char	*mxhosts[MAXMXHOSTS+1];	/* for MX RRs */
  EXTERN char	*TrustedUsers[MAXTRUST+1];	/* list of trusted users */
  EXTERN char	*UserEnviron[MAXUSERENVIRON+1];	/* saved user environment */
+ EXTERN char	*PaliasFile;	/* location of pathalias file */
  /*
  **  Trace information
  */
*** sendmail/src/daemon.c.orig	Wed Jul 23 18:27:01 1986
--- sendmail/src/daemon.c	Wed Mar 18 13:18:36 1987
***************
*** 604,606 ****
--- 607,712 ----
  }
  
  #endif DAEMON
+ 
+ #if defined(DBM) && defined(UUCPDOMAIN)
+ /* XXX */
+ #ifdef sun
+ #undef NULL
+ #endif
+ #include <dbm.h>
+ /* XXX */
+ #ifdef sun
+ #undef NULL
+ #define	NULL	0
+ #endif
+ 
+ /*
+ **  PATHALIAS -- return the shortest path to this host.
+ **
+ **	Parameters:
+ **		hbuf -- a buffer containing a hostname.
+ **
+ **	Returns:
+ **		The shortest known path to this host.
+ **
+ **	Side Effects:
+ **		none.
+ */
+ datum
+ pathalias(hbuf)
+ register char *hbuf;
+ {
+ 	register char *bptr;
+ 	register datum hdatum;
+ 
+ 	hdatum.dptr = hbuf;
+ 	hdatum.dsize = strlen(hbuf) + 1;
+ 	hdatum = fetch(hdatum);
+ 	if (hdatum.dptr != NULL)
+ 		if ((bptr = rindex(hdatum.dptr, '%')) == NULL ||
+ 		    *(bptr + 1) != 's')
+ 			hdatum.dptr = NULL;
+ 		else if (*(bptr + 2) == '@')
+ 			/* path!%s@host -> path!host!%s */
+ 			(void) sprintf(bptr, "%s!%%s", bptr + 3);
+ 	return hdatum;
+ }
+ 
+ 
+ /*
+ **  MAPUUCPHOSTNAME -- turn a hostname into the shortest uucp path
+ **
+ **	Parameters:
+ **		hbuf -- a buffer containing a hostname.
+ **		hbsize -- the size of hbuf.
+ **
+ **	Returns:
+ **		none.
+ **
+ **	Side Effects:
+ **		Looks up the host specified in hbuf.  Replace it
+ **		with the shortest uucp path to that host.
+ */
+ mapuucpname(hbuf, hbsize)
+ 	register char *hbuf;
+ 	register int hbsize;
+ {
+ 	register char *bptr;
+ 	register datum hdatum;
+ 	register bool mapped = FALSE;
+ 
+ 	makelower(hbuf);
+ 	hdatum = pathalias(hbuf);
+ 	if (hdatum.dptr != NULL && hdatum.dsize <= hbsize) {
+ 		(void) strcpy(hbuf, hdatum.dptr);
+ 		return;
+ 	}
+ 	if ((bptr = rindex(hbuf, '.')) == NULL)
+ 		return;
+ 	if (strncmp(bptr, ".uucp", sizeof ".uucp") == 0) {
+ 		/* try host with .uucp removed */
+ 		*bptr = '\0';
+ 		hdatum = pathalias(hbuf);
+ 		*bptr = '.';
+ 		if (hdatum.dptr != NULL && hdatum.dsize <= hbsize)
+ 			(void) strcpy(hbuf, hdatum.dptr);
+ 	}
+ 	else
+ 	{
+ 		/* keep removing left-most subdomain until a match is found */
+ 		for (bptr = hbuf;
+ 		     !mapped && (bptr = index(++bptr, '.')) != NULL;
+ 		     mapped = hdatum.dptr != NULL &&
+ 			      hdatum.dsize + strlen(hbuf) + 1 <= hbsize)
+ 			hdatum = pathalias(bptr);
+ 		if (!mapped || (bptr = rindex(hdatum.dptr, '!')) == NULL)
+ 			return;
+ 		*bptr = '\0';
+ 		if ((bptr = malloc(strlen(hbuf) + 1)) != NULL) {
+ 			(void) strcpy(bptr, hbuf);
+ 			(void) sprintf(hbuf, "%s!%s!%%s", hdatum.dptr, bptr);
+ 			(void) free(bptr);
+ 		}
+ 	}
+ }
+ #endif
*** sendmail/src/main.c.orig	Thu Jan 30 14:03:53 1986
--- sendmail/src/main.c	Mon Jan 26 14:33:20 1987
***************
*** 808,813 ****
--- 812,822 ----
  	/* and finally the hostname lookup characters */
  	'[', HOSTBEGIN,	']', HOSTEND,
  
+ #if defined(DBM) && defined(UUCPDOMAIN)
+ 	/* and the uucpname lookup characters */
+ 	'{', UUCPBEGIN,	'}', UUCPEND,
+ 
+ #endif
  	'\0'
  };
  
*** sendmail/src/parseaddr.c.orig	Wed Apr  2 19:04:03 1986
--- sendmail/src/parseaddr.c	Wed Mar 18 12:10:50 1987
***************
*** 741,747 ****
--- 741,751 ----
  			char pvpbuf[PSBUFSIZE];
  			extern char *DelimChar;
  
+ #if defined(DBM) && defined(UUCPDOMAIN)
+ 			if (**rvp != HOSTBEGIN && **rvp != UUCPBEGIN)
+ #else
  			if (**rvp != HOSTBEGIN)
+ #endif
  				continue;
  
  			/*
***************
*** 753,759 ****
--- 757,769 ----
  			hbrvp = rvp;
  
  			/* extract the match part */
+ #if defined(DBM) && defined(UUCPDOMAIN)
+ 			while (*++rvp != NULL &&
+ 			       (**rvp != HOSTEND && **hbrvp == HOSTBEGIN ||
+ 				**rvp != UUCPEND && **hbrvp == UUCPBEGIN))
+ #else
  			while (*++rvp != NULL && **rvp != HOSTEND)
+ #endif
  				continue;
  			if (*rvp != NULL)
  				*rvp++ = NULL;
***************
*** 764,770 ****
--- 774,801 ----
  
  			/* look it up */
  			cataddr(++hbrvp, buf, sizeof buf);
+ #if defined(DBM) && defined(UUCPDOMAIN)
+ 			if (**(hbrvp - 1) == HOSTBEGIN)
+ 				maphostname(buf, sizeof buf);
+ 			else
+ 			{
+ #ifdef sun
+ 				(void) dbmclose();
+ #endif
+ 				if (dbminit(PaliasFile) == 0)
+ #ifdef sun
+ 				{
+ #endif
+ 					mapuucpname(buf, sizeof buf);
+ #ifdef sun
+ 					(void) dbmclose();
+ 				}
+ #endif
+ 				(void) dbminit(AliasFile);
+ 			}
+ #else
  			maphostname(buf, sizeof buf);
+ #endif
  
  			/* scan the new host name */
  			olddelimchar = DelimChar;
*** sendmail/src/alias.c.orig	Thu Apr 17 23:18:56 1986
--- sendmail/src/alias.c	Mon Jan 26 14:26:42 1987
***************
*** 92,97 ****
--- 92,100 ----
  		p = aliaslookup(a->q_user);
  	if (p == NULL)
  		return;
+ #if defined(DBM) && defined(UUCPDOMAIN)
+ 	p = newstr(p);
+ #endif
  
  	/*
  	**  Match on Alias.
*** sendmail/src/Makefile.orig	Wed Jul 23 18:29:21 1986
--- sendmail/src/Makefile	Sat Feb 14 13:23:50 1987
***************
*** 36,42 ****
  CHMOD=	chmod
  O=	-O
  COPTS=
! CCONFIG=-I../include -DVMUNIX -DMXDOMAIN -DOLDJEEVES
  CFLAGS=	$O $(COPTS) $(CCONFIG)
  ASMSED=	../include/asm.sed
  AR=	-ar
--- 36,42 ----
  CHMOD=	chmod
  O=	-O
  COPTS=
! CCONFIG=-I../include -DVMUNIX -DMXDOMAIN -DOLDJEEVES -DUUCPDOMAIN
  CFLAGS=	$O $(COPTS) $(CCONFIG)
  ASMSED=	../include/asm.sed
  AR=	-ar
*** sendmail/src/readcf.c.orig	Sat Jan 11 03:18:47 1986
--- sendmail/src/readcf.c	Thu Feb 26 18:41:55 1987
***************
*** 913,918 ****
--- 913,925 ----
  		WkTimeFact = atoi(val);
  		break;
  
+ 	  case 'p':		/* pathalias file */
+ 		if (val[0] == '\0')
+ 			PaliasFile = "palias";
+ 		else
+ 			PaliasFile = newstr(val);
+ 		break;
+ 
  	  default:
  		break;
  	}
SHAR_EOF
if test 6543 -ne "`wc -c < 'diffs.sendmail'`"
then
	echo shar: "error transmitting 'diffs.sendmail'" '(should have been 6543 characters)'
fi
chmod 444 'diffs.sendmail'
fi
echo shar: "extracting 'mkpalias.sh'" '(676 characters)'
if test -f 'mkpalias.sh'
then
	echo shar: "will not over-write existing file 'mkpalias.sh'"
else
cat << \SHAR_EOF > 'mkpalias.sh'
#! /bin/sh

DOMAINS=/usr/local/lib/domains
NPALIAS=/usr/local/lib/npalias
OPALIAS=/usr/local/lib/opalias
PALIAS=/usr/local/lib/palias
PATH=/bin:/usr/bin:/usr/new
SEDTMP=/tmp/mkpalias$$

echo #! /bin/sh > $SEDTMP
echo sed -n \\ >> $SEDTMP
echo "-e '/\\..*	/!p' \\" >> $SEDTMP
for domain in `egrep -v \^# $DOMAINS`
do
	domain=`echo $domain | sed 's/\./\\./g'`
	echo "-e '/^$domain	/p' \\" >> $SEDTMP
	echo "-e '/\\.$domain	/p' \\" >> $SEDTMP
done
chmod +x $SEDTMP

pathalias -i Path.* uumap/[du].* | $SEDTMP | tee $NPALIAS | makedb -o $NPALIAS
rm -f $SEDTMP
mv $NPALIAS.dir $PALIAS.dir
mv $NPALIAS.pag $PALIAS.pag
mv $PALIAS $OPALIAS
mv $NPALIAS $PALIAS
sort -o $PALIAS $PALIAS
SHAR_EOF
if test 676 -ne "`wc -c < 'mkpalias.sh'`"
then
	echo shar: "error transmitting 'mkpalias.sh'" '(should have been 676 characters)'
fi
chmod 444 'mkpalias.sh'
fi
chmod 755 .
echo shar: "done with directory 'uucpdomain'"
cd ..
exit 0
#	End of shell archive
