Problem
I would like to get the functionality of the baduser option in mmdf
using sendmail. This option forwards any mail sent to a non-local
user (not present in /etc/passwd) to a different host machine. The
only mail I want affected is mail sent in the following format:userMail sent with a fully qualified domain name will be sent through the usual SMTP channels.
Solution
This solution will only work on sendmail version 8.7.x or greater. The latest version of sendmail is available as SCO Support Level Supplement (SLS) OSS443, the Sendmail Security Supplement.
As root, copy the file /usr/lib/sendmail.cf to
/usr/lib/sendmail.old. Using your favorite text editor, edit
the file /usr/lib/sendmail.cf.1. Search for the entry "Smart". Make the following entry just
below the "DS" macro.# place to which unknown users should be forwarded
Kuser user -m -a<>
DLThe result should look similar to the following:
# "Smart" relay host (may be null)
DS# place to which unknown users should be forwarded
Kuser user -m -a<>
DLAfter the DL macro, enter the fully qualified domain name for the
machine you want non-local user's mail forwarded to. The result
will look similar to the following (for the host "machine1"):# "Smart" relay host (may be null)
DS# place to which unknown users should be forwarded
Kuser user -m -a<>
DLmachine1.domain.com2. Search for the entry "S5". Comment out the lines that are
already listed under that ruleset and add the following rules:# deal with plussed users so aliases work nicely
R$+ + * $#local $@ $&h $: $1
R$+ + $* $#local $@ $2 $: $1 + *# prepend an empty "forward host" on the front
R$+ $: <> $1# send unrecognized local users to a relay host
R< > $+ + $* $: < $L . > $( user $1 $) + $2
R< > $+ $: < $L . > $( user $1 $) look up user
R< $* > $+ <> $* $: < > $2 $3 found; strip $L
R< $* . > $+ $: < $1 > $2 strip extra dot# handle plussed local names
R< > $+ + $* $#local $@ $2 $: $1# see if we have a relay or a hub
R< > $+ $: < $H > $1 try hub
R< > $+ $: < $R > $1 try relay
R< > $+ $@ $1 nope, give up
R< local : $* > $* $: $>95 < local : $1 > $2
R< error : $* > $* $: $>95 < error : $1 > $2
R< $- : $+ > $+ $: $>95 < $1 : $2 > $3 < @ $2 >
R< $+ > $+ $@ $>95 < $1 > $2 < @ $1 >The resulting ruleset will look similar to the following:
S5# deal with plussed users so aliases work nicely
R$+ + * $#local $@ $&h $: $1
R$+ + $* $#local $@ $2 $: $1 + *# prepend an empty "forward host" on the front
R$+ $: <> $1# send unrecognized local users to a relay host
R< > $+ + $* $: < $L . > $( user $1 $) + $2
R< > $+ $: < $L . > $( user $1 $) look up user
R< $* > $+ <> $* $: < > $2 $3 found; strip $L
R< $* . > $+ $: < $1 > $2 strip extra dot# handle plussed local names
R< > $+ + $* $#local $@ $2 $: $1# see if we have a relay or a hub
R< > $+ $: < $H > $1 try hub
R< > $+ $: < $R > $1 try relay
R< > $+ $@ $1 nope, give up
R< local : $* > $* $: $>95 < local : $1 > $2
R< error : $* > $* $: $>95 < error : $1 > $2
R< $- : $+ > $+ $: $>95 < $1 : $2 > $3 < @ $2 >
R< $+ > $+ $@ $>95 < $1 > $2 < @ $1 ># see if we have a relay or a hub
#R$+ $: < $R > $1 try relay
#R< > $+ $: < $H > $1 try hub
#R< > $+ $@ $1 nope, give up
#R< $- : $+ > $+ $: $>95 < $1 : $2 > $3 < @ $2 >
#R< $+ > $+ $@ $>95 < $1 > $2 < @ $1 >Make sure that the spaces between the left-hand-side and
right-hand-side in the above entries are tabs. Save your
file and test this configuration. See also
sendmail(ADMN), mail(C)