>From bc@mtiweb.com Tue Sep  5 10:31:45 1995
From: bc@mtiweb.com (Barry Caplin)
To: inet-access@earth.com, linuxisp@lightning.com
Subject: virtual domain email (finally)

Hi All,

   OK.  I've been promising this for a while and I finally
got it together.  This is a compilation of what I did to get
virtual domains within sendmail, i.e. you are localisp.net and
your customer wants to be them@theirbusiness.com.  This has all
been posted to this and other lists in bits and pieces over the
last few months.  A few people have set up web pages with this
info, most notably Chris Candreva (http:/www.westnet.com/providers)
and http://www.vicnet.net.au/vicnet/help/isp.htm (sorry, I forgot
whose page this is :-(.  I will be setting up a similar page as
soon as I'm online.
   This info is for Linux.  I am running v1.2.1.
[NOTE: as of 11/13/95 I upgraded my kernel to 1.2.13.  Everything still
works fine and I didn't have to do anything to change these procedures.]
   First, sendmail.  This method uses the dbm database package
to create btree files using makemap.  Sendmail 8.6.9 does not
support this so I had to upgrade to sendmail 8.6.12.  Next,
I had to get dbm.  I think I got the dbm stuff from berkeley (maybe
ftp.berkeley.edu?).
[NOTE1: on 3/7/96 I upgraded to sendmail 8.6.13.  It has a security
fix.  You can get the patch on my isp page www.mtiweb.net/isp or
on my anon ftp server.  ]
[NOTE2: on 12/30/96 I upgraded to sendmail 8.8.4.  Everyone should do
this.  I used the stock sendmail 8.8.4 from ftp.sendmail.org.  I did
nothing and just compiled it on both a.out and elf 1.2.13 systems.
I used the 8.8.3 sendmail.cf on my isp web page donated by Paul Wouters.
I needed to make a couple of mods in the pathnames that Paul used but that's
about it.]
[NOTE3: this is from the README file of dbm:
Newer versions of this software will periodically be made available by
anonymous ftp from ftp.cs.berkeley.edu.  An archive in compressed format
is in ucb/4bsd/db.tar.Z, or in gzip format in ucb/4bsd/db.tar.gz.  If
you'd like to receive announcements of future releases of this software,
send email to the contact address below.
Email questions may be addressed to Keith Bostic
  at bostic@cs.berkeley.edu. ]
[NOTE4: 6/97 I have gone to sendmail 8.8.6.  The 8.8.x cf files are still
valid.  I have added the check_rcpt and check_relay, and anti-spam rules.
The cf for hub machines is at 
8.8.6.hub.cf, and the cf for forwarding machines is at 
8.8.6.forward.cf.]


   Here are the sendmail.cf mods.  Fw defines the virtual domain
names, K defines the db files.  Incoming mail is handled by
ruleset S98 and outgoing mail is handled by ruleset S40.  The
S40 stuff is optional (this is the masq stuff).
##################
#   local info   #
##################

Cwmtiweb.com
Fw /etc/virtdomains
#bc support for db functions
Kmaildomains btree /etc/maildomains.db
Kmasqdomains btree /etc/masqdomains.db

# who I masquerade as (null for no masquerading)
DMmtiweb.com

###################################################################
###  Ruleset 98 -- local part of ruleset zero (can be null)	###
###################################################################

S98
#bc  rules to remap fake local domains
#bc  the map file is in /etc/maildomains
#bc  new users/domains can be added to /etc/maildomains and then
#bc  added to the db using: makemap btree maildomains < maildomains (in /etc)
R$+ < @ $+  . >		$: $1 < @ $2 > .
R$+ < @ $+ > $*		$: $(maildomains $1 $: $1 < @ $2 > $3 $)
R$+ < @ $+ > $*		$: $(maildomains $1@$2 $: $1 < @ $2 > $3 $)
R$+ < @ $+ > $*		$: $(maildomains $2 $: $1 < @ $2 > $3 $)
RERROR $*               $#error $: $1
R$+ < @ $* > .		$: $1 < @ $2 . >


##################################################
###   Local and Program Mailer specification   ###
##################################################

S40
R$* < @ $* > $*		$@ $1 < @ $2 > $3	already fully qualified
#bc instead of automatically using $M, lookup masquerade in masqdomains
R$*			$: $(masqdomains $1 $: $1 @ $M $)
#bcR$*			$: $1 @ $M		add local qualification
R$-			$: $1 @ $M		add local qualification
R$* @			$: $1 @ $j		if $M not defined

[added 6/23/96 - correction for masq'ing outbound email             ]
[   Ruleset S40 only handles headers for local delivery.  I needed  ]
[   to add the same lookup to Ruleset S61 which handles headers for ]
[   smtp sending.                                                   ]

#####################################
###   SMTP Mailer specification   ###
#####################################

S61

R$* < @ $* > $*         $@ $1 < @ $2 > $3               already qualified
R$=E                    $@ $1 < @ $j>                   show exposed names
#bc instead of automatically using $M, lookup masquerade in masqdomains
#bc  added to the db using: makemap btree masqdomains < masqdomains (in /etc)
R$*                     $: $(masqdomains $1 $: $1 $)
#bc
#bcR$+                  $: $1 < @ $M >                  user w/o host
R$-                     $: $1 < @ $M >                  user w/o host
R$+ <@>                 $: $1 < @ $j >                  in case $M undefined


maildomains looks like:
fakename  localname
i.e.:
sales@theirco.com	joe@localisp.net
theirco.com             ERROR "Unknown User"    <- bounces email to theirco.com
                                                         that is not for sales
webmaster               webmaster@localisp.net  <- sends webmaster@anything to
                                                         the local webmaster
joe@virt.com            jj
virt.com                bob@localisp.net        <- sends all virt.com's mail
                                                         to bob (except for joe's)

you need to make maildomains.db using:
makemap btree maildomains.db < maildomains

masqdomains looks like:
localname  maskname
i.e.:
joe	pres@theirco.com
thus, when joe answers his email, the From: portion of the mail
he sends will say pres@theirco.com instead of joe@localisp.net.

you need to make masqdomains.db just like maildomains.db above.

finally, virtdomains looks like (just a list of your virtual
domains):
virtco1.com
virtco2.com

[Please note the the outgoing address rewrite only seems to work for
shell mail clients.  For pop clients, the return address needs to be
set in the config of the popmail client software.]

   This is all you need on the sendmail end.  The only thing left
is to register the virtual domain names which of course involves
mapping them to an IP address.  Now, if all you're doing is the
email, then I suppose you could just map the virtual names to
your IP address.  If you're doing virtual web also, then each
virtual domain name will need an IP address.
   I'll cover the bind and www stuff in another message.

   I hope you find this useful.  Email or post any questions.

   Barry

   Barry Caplin      MicroWEB Technology, Inc.
   bc@mtiweb.com     http://www.mtiweb.com

[added 2/17/96]
   Alot of people have been asking me where to get the db source
code.  This is from the README:
Newer versions of this software will periodically be made available by
anonymous ftp from ftp.cs.berkeley.edu.  An archive in compressed format
is in ucb/4bsd/db.tar.Z, or in gzip format in ucb/4bsd/db.tar.gz.

[added 11/96]
   There seems to be some problems with the masqdomains stuff and it
doesn't always work.  In general, it seems like the easiest short term
solution is just to have your Eudora/popmail clients set their own
return address in their setup.  Pine can do the same.  When I get
it all worked out I will post this.