I know this thread is stone-age old, but I had the same problem and came up with a solution. It might be helpful for others, who come accross this post via Google like me. So mods, please don't crucify me.
As of 2012, sendmail still does not support white-listing (sigh). Access db is not suitable for this, because it is a black-list and trying to implement white-listing with a black-list is like trying to make a fence water-proof. If you cannot use the (in countless ways) superior postfix and are stuck with sendmail for whatever reason, then here is what you can do:
If you want to white-list based on sender addresses, put this at the end of your sendmail.mc:
Code:
LOCAL_CONFIG
Kwhitelist hash -T<TMPF> -aOK /etc/mail/whitelist
LOCAL_RULESETS
SLocal_check_mail
R$* $: $(whitelist From:$1 $: ? $)
R? $: $(whitelist Connect:$&{client_addr} $)
ROK $@ OK
R$* $#error $: 550 Access denied
If, on the other hand, you want to white-list based on recipient addresses, put this at the end of your sendmail.mc (it's practicaly the same code, the main difference being that the recipient instead of the sender is checked):
Code:
LOCAL_CONFIG
Kwhitelist hash -T<TMPF> -aOK /etc/mail/whitelist
LOCAL_RULESETS
SLocal_check_rcpt
R$* $: $(whitelist To:$1 $: ? $)
R? $: $(whitelist Connect:$&{client_addr} $)
ROK $@ OK
R$* $#error $: 550 Access denied
You can use both methods in conjuction, which would look like this:
Code:
LOCAL_CONFIG
Kwhitelist hash -T<TMPF> -aOK /etc/mail/whitelist
LOCAL_RULESETS
SLocal_check_mail
R$* $: $(whitelist From:$1 $: ? $)
R? $: $(whitelist Connect:$&{client_addr} $)
ROK $@ OK
R$* $#error $: 550 Access denied
SLocal_check_rcpt
R$* $: $(whitelist To:$1 $: ? $)
R? $: $(whitelist Connect:$&{client_addr} $)
ROK $@ OK
R$* $#error $: 550 Access denied
But please beware that then sender AND recipient addresses of a mail must have a match in the white-list. For example, if you white-listed sender@example.com and recipient@example.com, then the only accepted mails are those that have exactly this sender AND recipient. It does NOT mean that any mail from sender@example.com OR to recipient@example.com is accepted.
No matter, which method you choose, create a file /etc/mail/whitelist with the following content:
Code:
# This file contains a whitelist of e-mail and IP addresses.
# E-mail addresses listed here may send/receive mails to/from any host.
# Client IP addresses listed here are not affected by whitelisting, i.e.,
# they may send mail to/from any address.
# Any other requests will be REJECTed.
#
# Entries may have one of the following formats (the availability of
# "From" and "To" depends on whether sender or recipient checking is enabled):
# From:<e-mail address of sender>
# To:<e-mail address of recipient>
# Connect:<IP address of client>
#
# It is NOT possible to specify wild-cards or to use full domains
# (e.g., "To:@example.com" in order to accept everything sent to an
# address ending on "@example.com").
# Make sure not to insert any whitespace.
#
# If you make any changes to this file, regenerate the database via
# makemap -e hash /etc/mail/whitelist.db < /etc/mail/whitelist
#
#
#
# white-listed senders
#
From:sender@example.com
#
# white-listed recipients
#
To:recipient@example.com
#
# do not restrict local connections
#
Connect:127.0.0.1
Connect:IPv6:::1
Connect:
Finally, build the white-list db and reload sendmail.
Code:
makemap -e hash /etc/mail/whitelist.db < /etc/mail/whitelist
/etc/init.d/sendmail reload