106f25ae9SGregory Neil Shapirodivert(-1)changequote(<<, >>)<< 206f25ae9SGregory Neil Shapiro----------------------------------------------------------------------------- 306f25ae9SGregory Neil Shapiro 406f25ae9SGregory Neil Shapiro FEATURE(domainmap) Macro 506f25ae9SGregory Neil Shapiro 606f25ae9SGregory Neil Shapiro The existing virtusertable feature distributed with sendmail is a good 706f25ae9SGregory Neil Shapiro basic approach to virtual hosting, but it is missing a few key 806f25ae9SGregory Neil Shapiro features: 906f25ae9SGregory Neil Shapiro 1006f25ae9SGregory Neil Shapiro 1. Ability to have a different map for each domain. 1106f25ae9SGregory Neil Shapiro 2. Ability to perform virtual hosting for domains which are not in $=w. 1206f25ae9SGregory Neil Shapiro 3. Ability to use a centralized network-accessible database (such as 1306f25ae9SGregory Neil Shapiro PH) which is keyed on username alone (as opposed to the 1406f25ae9SGregory Neil Shapiro fully-qualified email address). 1506f25ae9SGregory Neil Shapiro 1606f25ae9SGregory Neil Shapiro The FEATURE(domainmap) macro neatly solves these problems. 1706f25ae9SGregory Neil Shapiro 1806f25ae9SGregory Neil Shapiro The basic syntax of the macro is: 1906f25ae9SGregory Neil Shapiro FEATURE(domainmap, `domain.com', `map definition ...')dnl 2006f25ae9SGregory Neil Shapiro 2106f25ae9SGregory Neil Shapiro To illustrate how it works, here is an example: 2206f25ae9SGregory Neil Shapiro FEATURE(domainmap, `foo.com', `dbm -o /etc/mail/foo-users')dnl 2306f25ae9SGregory Neil Shapiro 2406f25ae9SGregory Neil Shapiro In this example, mail sent to user@foo.com will be rewritten by the 2506f25ae9SGregory Neil Shapiro domainmap. The username will be looked up in the DBM map 2606f25ae9SGregory Neil Shapiro /etc/mail/foo-users, which looks like this: 2706f25ae9SGregory Neil Shapiro jsmith johnsmith@mailbox.foo.com 2806f25ae9SGregory Neil Shapiro jdoe janedoe@sandbox.bar.com 2906f25ae9SGregory Neil Shapiro 3006f25ae9SGregory Neil Shapiro So mail sent to jsmith@foo.com will be relayed to 3106f25ae9SGregory Neil Shapiro johnsmith@mailbox.foo.com, and mail sent to jdoe@foo.com will be 3206f25ae9SGregory Neil Shapiro relayed to janedoe@sandbox.bar.com. 3306f25ae9SGregory Neil Shapiro 3406f25ae9SGregory Neil Shapiro The FEATURE(domainmap) Macro supports the user+detail syntax by 3506f25ae9SGregory Neil Shapiro stripping off the +detail portion before the domainmap lookup and 3606f25ae9SGregory Neil Shapiro tacking it back on to the result. Using the example above, mail sent 3706f25ae9SGregory Neil Shapiro to jsmith+sometext@foo.com will be rewritten as 3806f25ae9SGregory Neil Shapiro johnsmith+sometext@mailbox.foo.com. 3906f25ae9SGregory Neil Shapiro 4006f25ae9SGregory Neil Shapiro If one of the elements in the $=w class (i.e., "local" delivery hosts) 4106f25ae9SGregory Neil Shapiro is a domain specified in a FEATURE(domainmap) entry, you need to use 4206f25ae9SGregory Neil Shapiro the LOCAL_USER(username) macro to specify the list of users for whom 4306f25ae9SGregory Neil Shapiro domainmap lookups should not be done. 4406f25ae9SGregory Neil Shapiro 4506f25ae9SGregory Neil Shapiro To use this macro, simply copy this file into the cf/feature directory 4606f25ae9SGregory Neil Shapiro in the sendmail source tree. For more information, please see the 4706f25ae9SGregory Neil Shapiro following URL: 4806f25ae9SGregory Neil Shapiro 49a7ec597cSGregory Neil Shapiro http://www-dev.cites.uiuc.edu/sendmail/domainmap/ 5006f25ae9SGregory Neil Shapiro 5106f25ae9SGregory Neil Shapiro Feedback is welcome. 5206f25ae9SGregory Neil Shapiro 5306f25ae9SGregory Neil Shapiro Mark D. Roth <roth@uiuc.edu> 5406f25ae9SGregory Neil Shapiro 5506f25ae9SGregory Neil Shapiro----------------------------------------------------------------------------- 5606f25ae9SGregory Neil Shapiro>>changequote(`, ')undivert(-1)divert 5706f25ae9SGregory Neil Shapiro 5806f25ae9SGregory Neil Shapiroifdef(`_DOMAIN_MAP_',`',`dnl 5906f25ae9SGregory Neil ShapiroLOCAL_RULE_0 6006f25ae9SGregory Neil Shapiro# do mapping for domains where applicable 6142e5d165SGregory Neil ShapiroR$* $=O $* <@ $={MappedDomain} .> $@ $>Recurse $1 $2 $3 Strip extraneous routing 6206f25ae9SGregory Neil ShapiroR$+ <@ $={MappedDomain} .> $>DomainMapLookup $1 <@ $2 .> domain mapping 6306f25ae9SGregory Neil Shapiro 6406f25ae9SGregory Neil ShapiroLOCAL_RULESETS 6506f25ae9SGregory Neil Shapiro########################################################################### 6606f25ae9SGregory Neil Shapiro### Ruleset DomainMapLookup -- special rewriting for mapped domains ### 6706f25ae9SGregory Neil Shapiro########################################################################### 6806f25ae9SGregory Neil Shapiro 6906f25ae9SGregory Neil ShapiroSDomainMapLookup 7006f25ae9SGregory Neil ShapiroR $=L <@ $=w .> $@ $1 <@ $2 .> weed out local users, in case 7106f25ae9SGregory Neil Shapiro# Cw contains a mapped domain 7240266059SGregory Neil ShapiroR $+ <@ $+> $: $1 <@ $2 > <$&{addr_type}> check if sender 7340266059SGregory Neil ShapiroR $+ <@ $+> <e s> $#smtp $@ $2 $: $1 @ $2 do not process sender 74193538b7SGregory Neil Shapiroifdef(`DOMAINMAP_NO_REGEX',`dnl 7540266059SGregory Neil ShapiroR $+ <@ $+> <$*> $: $1 <@ $2> <$2> find domain 7642e5d165SGregory Neil ShapiroR $+ <$+> <$+ . $+> $1 <$2> < $(dequote $3 "_" $4 $) > 7706f25ae9SGregory Neil Shapiro# change "." to "_" 7842e5d165SGregory Neil ShapiroR $+ <$+> <$+ .> $: $1 <$2> < $(dequote "domain_" $3 $) > 7906f25ae9SGregory Neil Shapiro# prepend "domain_" 80193538b7SGregory Neil Shapirodnl',`dnl 8140266059SGregory Neil ShapiroR $+ <@ $+> <$*> $: $1 <@ $2> <$2 :NOTDONE:> find domain 82193538b7SGregory Neil ShapiroR $+ <$+> <$+ . :NOTDONE:> $1 <$2> < $(domainmap_regex $3 $: $3 $) > 83193538b7SGregory Neil Shapiro# change "." and "-" to "_" 84193538b7SGregory Neil ShapiroR $+ <$+> <$+> $: $1 <$2> < $(dequote "domain_" $3 $) > 85193538b7SGregory Neil Shapiro# prepend "domain_" 86193538b7SGregory Neil Shapirodnl') 8742e5d165SGregory Neil ShapiroR $+ <$+> <$+> $: $1 <$2> <$3> $1 find user name 8842e5d165SGregory Neil ShapiroR $+ <$+> <$+> $+ + $* $: $1 <$2> <$3> $4 handle user+detail syntax 8942e5d165SGregory Neil ShapiroR $+ <$+> <$+> $+ $: $1 <$2> $( $3 $4 $: <ERROR> $) 9006f25ae9SGregory Neil Shapiro# do actual domain map lookup 9142e5d165SGregory Neil ShapiroR $+ <$+> <ERROR> $#error $@ 5.1.1 $: "550 email address lookup in domain map failed" 9242e5d165SGregory Neil ShapiroR $+ <@ $+> $* <TEMP> $* $#dsmtp $@ localhost $: $1 @ $2 9342e5d165SGregory Neil Shapiro# queue it up for later delivery 9442e5d165SGregory Neil ShapiroR $+ + $* <$+> $+ @ $+ $: $1 + $2 <$3> $4 + $2 @ $5 9542e5d165SGregory Neil Shapiro# reset original user+detail 9642e5d165SGregory Neil ShapiroR $+ <$+> $+ $@ $>Recurse $3 recanonify 97193538b7SGregory Neil Shapiro 98193538b7SGregory Neil Shapiroifdef(`DOMAINMAP_NO_REGEX',`',`dnl 99193538b7SGregory Neil ShapiroLOCAL_CONFIG 100193538b7SGregory Neil ShapiroK domainmap_regex regex -a.:NOTDONE: -s1,2 -d_ (.*)[-\.]([^-\.]*)$ 101193538b7SGregory Neil Shapiro')define(`_DOMAIN_MAP_',`1')') 10206f25ae9SGregory Neil Shapiro 10306f25ae9SGregory Neil ShapiroLOCAL_CONFIG 10406f25ae9SGregory Neil ShapiroC{MappedDomain} _ARG_ 105193538b7SGregory Neil ShapiroK `domain_'translit(_ARG_, `.-', `__') _ARG2_ -T<TEMP> 106