Snow Leopard Server shipped with a postfix policy for greylisting email. It was easy enough to disable if you didn’t like it, and Server Admin was typically kind enough to not overwrite your settings. Unfortunately, Lion Server isn’t as nice about it.
In addition to occasionally removing the greylisting policy on some servers, I always like to alter the default smtpd_recipient_restrictions directive to include some additional parameters, as well as reorder them to work more efficiently. My directive is typically something like this:
smtpd_recipient_restrictions =
reject_non_fqdn_recipient, check_recipient_access hash:/etc/postfix/access,
permit_mynetworks, reject_unauth_destination,
reject_non_fqdn_sender, check_sender_access hash:/etc/postfix/sender_access,
reject_non_fqdn_hostname, reject_invalid_helo_hostname, check_helo_access hash:/etc/postfix/helo_access,
reject_rbl_client zen.spamhaus.org, reject_rbl_client bl.spamcop.net,
permit
Naturally, this entire directive gets overwritten whenever Lion Server overwrites Postfix main.cf.
So, I’ve written a script that checks to see if the smtpd_recipient_restrictions directive has been altered, and if so, returns it to the preferred state:
#!/bin/bash
restrictions_preferred="reject_non_fqdn_recipient, permit_mynetworks, reject_unauth_destination, reject_non_fqdn_sender, reject_non_fqdn_hostname, reject_invalid_helo_hostname, check_helo_access hash:/etc/postfix/helo_access, reject_rbl_client zen.spamhaus.org, reject_rbl_client bl.spamcop.net, permit";
restrictions_current_full="`postconf smtpd_recipient_restrictions`";
restrictions_current=${restrictions_current_full:31};
if test "$restrictions_preferred" = "$restrictions_current"
then
echo "Postfix smtpd restrictions are set correctly."
exit 0;
else
echo "Postfix smtpd restrictions are NOT set correctly."
serveradmin settings mail:postfix:smtpd_recipient_restrictions = "$restrictions_preferred";
exit 0;
fi
So, update the first variable, restrictions_preferred, to have the parameters you want to populate smtpd_recipient_restrictions with. If all you’re looking to do is disable greylisting, just remove check_policy_service unix:private/policy from the original directive in /etc/postfix/main.cf.
I’ve personally saved this script at /usr/local/bin/disable_greylisting.bash and set its permissions to 755. You can name it and put it anywhere you’d like, but note its full path as you’ll need it for the launchd job plist to trigger it. That plist is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.practiceofcode.disable_greylisting</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/disable_greylisting.bash</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>120</integer>
</dict>
</plist>
Similarly, I’ve placed that at /Library/LaunchDaemons/com.practiceofcode.disable_greylisting.plist. This file needs to be owned by root:wheel and be 644. Again, you can name it as you’d like, but the value for Label in the file’s contents should match the file name (leaving off the .plist).
When the script detects that the directive needs to be repaired, it does so using the serveradmin command. The benefit of using that command is serveradmin automatically restarts Postfix after making the change. Since the script will not restart Postfix if the directive has not been changed, feel free to keep the StartInterval at 120 seconds, or of similar high frequency, as there is little to no tax for just testing your configuration.