From: per@erix.ericsson.se (Per Hedeland)
Subject: Re: Using sendmail to print Full name as mail address
Organization: Ellemtel Telecom Systems Labs, Stockholm, Sweden
Date: Sat, 22 Aug 1992 10:48:08 GMT

In article <BtCJp8.yn@nntp-sc.Intel.COM> jst@inews.intel.com (Jason
Thomasser) writes a very nice description of the workings of the
"reverse aliasing" function (such as it is:-) of SunOS sendmail/.cf -
one might think that that such a description should be provided by Sun,
but at least to my knowledge, it isn't... Anyway, since I've just
recently been dealing with this myself, I'd like to add a few comments.

> You need to add the -s -n options to mkalias (by default
>in /var/yp/Makefile) like this:
>
>MKALIAS=$(YPDIR)/mkalias -s -n

What do these options do? The mkalias command is also totally
undocumented (yes I have grep'ed all of /usr/man/man*/* for it).

> Be warned that you have
>to specify a mailserver (other wise you have an alias loop) and that
>it makes life mush easier if the master mail machine is dedicated to that 
>function (not acting as a direct mailserver to any users due to subtle
>sendmail rewrites you have to contend with).

I have done what is perhaps those "subtle rewrites", i.e. extended the
simple lookup in the distributed .cf to work also in the case where the
reverse aliasing is done on the mailserver, in the form of a separate
ruleset:

S27
# We assume that the key is an unqualified user@host
# and that the inverse alias is something else
R$-<@$*LOCAL>		$1<@$2LOCAL>?$2$m?$1@$2$m	change local info
R$-<@$*>		$1<@$2>?$2?$1@$2		already OK
R$-			$1?$w?$1@$w			tack on our hostname
R$*?$*$=m?$-@$-.$*	$1?$2$3?$4@$5			unqualify our domain
R$*?$*?$-@$-.$*		$@$1				not our domain
R$*?$*?$*		$1?${Z$3$}			lookup
R$*?$-@$-		$@$1				not found
R$*?$*			$@$>3$2				found

I realize that this is a bit complex (you get that way after too much
browsing of the IDA sendmail config:-) - this is due to the fact that it
will handle all of 'user' (in which case the current host's name as
found in $w is used, which may result in either of the three following
forms), 'user@host', user@host.domain', and 'user@domain' as canditates
for reverse aliasing, and to the lack of failure indication in Sun's NIS
lookups.

This can then be called as

R$+			$:$>27$1			invert aliases

wherever desired in the sendmail.cf (e.g. replacing the direct lookup in
the 'ddn' mailer ruleset).

In the case of the mailserver doing the reverse aliasing, you would of
course not have the

uid: full.name

alias for local users. It might also be added that you should take care
not to have any aliases of the form

alias: user@host

that you *don't* want to be candidates for reverse mapping.

An additional point is that the mkalias program runs off the
mail.aliases database, where all aliases have been converted to
lowercase - i.e. your reverse alias will be on the form
full.name@domain, rather than Full.Name@domain - if this bothers you,
you can replace the mkalias call in /var/yp/Makefile with a string of
commands believed to do the same thing, but directly from the aliases
source file (diff from the SunOS 4.1.1 version):

*** /var/yp/Makefile.ORIG	Sat Feb  2 12:14:33 1991
--- /var/yp/Makefile	Fri Oct 11 09:59:33 1991
***************
*** 154,160 ****
  aliases.time: $(ALIASES)
  	@cp $(ALIASES) $(YPDBDIR)/$(DOM)/mail.aliases; 
  	@/usr/lib/sendmail -bi -oA$(YPDBDIR)/$(DOM)/mail.aliases; 
! 	$(MKALIAS) $(YPDBDIR)/$(DOM)/mail.aliases $(YPDBDIR)/$(DOM)/mail.byaddr; 
  	rm $(YPDBDIR)/$(DOM)/mail.aliases; 
  	@touch aliases.time; 
  	@echo "updated aliases"; 
--- 154,164 ----
  aliases.time: $(ALIASES)
  	@cp $(ALIASES) $(YPDBDIR)/$(DOM)/mail.aliases; 
  	@/usr/lib/sendmail -bi -oA$(YPDBDIR)/$(DOM)/mail.aliases; 
! 	(sed -e '/^#/d' -e s/#.*$$// -e 's/[ 	]//g' \
! 	    $(YPDBDIR)/$(DOM)/mail.aliases $(CHKPIPE))\
! 	|( awk -F: 'BEGIN { OFS="\t"; } \
! 	    NF == 2 && $$2 !~ /,/ && $$2 ~ /@/ { print $$2, $$1 }' $(CHKPIPE))\
! 	| $(MAKEDBM) -l - $(YPDBDIR)/$(DOM)/mail.byaddr; 
  	rm $(YPDBDIR)/$(DOM)/mail.aliases; 
  	@touch aliases.time; 
  	@echo "updated aliases"; 

>As for IDA don't know. Any one else?

I'll let someone else give the details, but I know that there is very
good support for this kind of thing in the standard config that comes
with IDA, and in particular the 'xalparse' program provides great
flexibility in how to set up both forward and reverse aliasing.

--Per Hedeland
per@erix.ericsson.se  or
per%erix.ericsson.se@sunic.sunet.se  or
...uunet!erix.ericsson.se!per
Xref: sparky comp.mail.sendmail:2106 comp.sys.sun.misc:3795