Using Sendmail's generics and masquerading


In sendmail, to change the domain that a message appears to come from--that is, all the stuff on the right side of the @ --use the masquerading rules, usually the DM setting, although you may also need to modify section S94 which converts the envelope to masqueraded from. The DM setting affects just the header, I think.

To change the person that the message appears to come from--that is, all the stuff on the left side of the @ --use the generics rules. Specifically, on ednhp7, I had to uncomment the Kgenerics setting in the section labeled 'Generics table (mapping outgoing addresses)'. I chose the hash version instead ot the dbm version, like so:

# Generics table (mapping outgoing addresses) #Kgenerics dbm -o /etc/mail/genericstable Kgenerics hash -o /etc/mail/genericstable

I also had to go to section S93 and uncomment all the rules for handling the generics database:

S93 # handle generics database R$+ < @ $=G . > $: < $1@$2 > $1 < @ $2 . > @ mark R$+ < @ *LOCAL* > $: < $1@$j > $1 < @ *LOCAL* > @ mark R< $+ > $+ < $* > @ $: < $(generics $1 $: $) > $2 < $3 > R< > $+ < @ $+ > $: < $(generics $1 $: $) > $1 < @ $2 > R< $* @ $* > $* < $* > $@ $>3 $1 @ $2 found qualified R< $+ > $* < $* > $: $>3 $1 @ *LOCAL* found unqualified R< > $* $: $1 not found

Then, go to the /etc/mail directory, or wherever you find the aliases and sendmail.cf files, and create a text file containing the IDs and the addresses you want to map them to. The local ID to be mapped goes on the left and the to-be-mapped-to address goes on the right, like so:

applmgr applmgr.ednhp7@nextelpartners.com pscheie buzz.lightyear@nextelpartners.com

Next, convert the genericstable file into a db file that sendmail can use:

makemap hash genericstable < genericstable

This will create a file called genericstable.db that sendmail will now look to. You could just leave off the '< genericstable' part and enter the mappings right there by hand; makemap defaults to getting input from STDIN. I just think that creating a text file and using that for the input makes it more akin to the aliases process and makes it easier to see what generics have previously been created. In the example above, I created a hash file. The man page on makemap lists two other formats, dbm and btree. Looking around the internet, using dbm seems popular and may be preferred. Using dbm produces two files, a .pag and a .dir. I didn't see any mention of using the btree format. The syntax for dbm is the same except you use the flag 'dbm' instead of 'hash' (and make sure 'dbm' is the specified database type on the Kgenerics line in sendmail.cf).

Because of the changes made to the sendmail.cf file, you have to restart sendmail. Later, if you just make changes to the genericstable text file and regen the db file, it is not necessary to restart sendmail. Note that depending on what you put in the generics table, you may not need to modify the DM masquerade setting in sendmail.cf. For example, the applmgr setting in the example above will automatically change the domain from ednhp7.nextelpartners.com fo nextelpartners.com for applmgr's outbound messages. If this is the only ID that needs such a change, then masquerading can be ignored.

10/27/2004