summaryrefslogtreecommitdiff
path: root/postfix/anti-uce.sh
blob: fc7ecf9e42a9312f41a558b56f85d9cfd905c359 (plain)
  1. #!/bin/bash
  2. set -e
  3. paramdir="/etc/local-COMMON/postfix"
  4. confdir="/etc/postfix"
  5. sp='[[:space:]]'
  6. function getlinesfromfile() {
  7. param="$1"
  8. echo -n "$param = "
  9. cat $paramdir/$param | grep -v '^#' | sed 's/#.*//' | tr "\n" "," | sed -e 's/^[, ]*//' -e 's/[, ]\+/,/g' -e 's/,$//'
  10. }
  11. postconf -e "smtpd_helo_required = yes"
  12. postconf -e "`getlinesfromfile permit_mx_backup_networks`"
  13. postconf -e "`getlinesfromfile maps_rbl_domains`"
  14. postconf -e "`getlinesfromfile smtpd_recipient_restrictions`"
  15. # These options can be fatal if no SASL plugins are available!
  16. if dpkg -L libsasl-modules-plain &> /dev/null; then
  17. mkdir -p $confdir/sasl
  18. echo "pwcheck_method: pam" >$confdir/sasl/smtpd.conf
  19. echo "auto_transition: false" >>$confdir/sasl/smtpd.conf
  20. groups postfix | grep shadow &>/dev/null || adduser postfix shadow
  21. cp -a $confdir/master.cf $confdir/master.cf.old
  22. cat $confdir/master.cf.old | sed \
  23. "s/^\(smtp$sp\+inet\($sp\+[n-]\)\{2\}$sp\+\)[n-]\(\($sp\+-\)\{2\}$sp\+smtpd\).*/\1n\3 -o smtpd_sasl_auth_enable=yes/" \
  24. "s/^#?\(\(smtps|587\)$sp\+inet\($sp\+[n-]\)\{2\}$sp\+\)[n-]/\1n/" \
  25. > $confdir/master.cf
  26. postconf -e "smtpd_use_tls = yes"
  27. postconf -e "smtpd_tls_auth_only = yes"
  28. postconf -e "smtpd_sasl_auth_enable = no"
  29. postconf -e "broken_sasl_auth_clients = yes"
  30. postconf -e "smtpd_sasl_security_options = noanonymous"
  31. postconf -e "smtpd_sasl_local_domain = \$myhostname"
  32. postconf -e "smtpd_tls_cert_file = /etc/ssl/certs/postfix.crt"
  33. postconf -e "smtpd_tls_key_file = /etc/ssl/certs/postfix.key"
  34. postconf -e "tls_random_source = dev:/dev/urandom"
  35. postconf -e "tls_daemon_random_source = dev:/dev/urandom"
  36. fi
  37. /etc/init.d/postfix reload
  38. # Based on this: http://jimsun.linxnet.com/misc/postfix-anti-UCE.txt
  39. # Support for trusted MX backup networks added
  40. # PCRE stuff avoided, as PCRE is only optional on newest Debian packages
  41. # RBLs replaced with those recommended by http://www.antispews.org/
  42. # Here's a convenient overview of different blackholes:
  43. # http://rbls.org/
  44. # smtpd_tls_CAfile