summaryrefslogtreecommitdiff
path: root/postfix/anti-uce.sh
blob: 71a52295fe095c67c226fecf1af64c1b95c5d18c (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. # Some badly configured setup use hostname instead of FQDN
  12. if postconf myhostname | grep '.' &> /dev/null; then
  13. postconf -e 'smtpd_helo_required = yes'
  14. fi
  15. postconf -e "`getlinesfromfile permit_mx_backup_networks`"
  16. postconf -e "`getlinesfromfile maps_rbl_domains`"
  17. postconf -e "`getlinesfromfile smtpd_recipient_restrictions`"
  18. # TLS breaks postfix if no SASL modules available (and doesn't make sense either)
  19. # (change the test if using some other modules and avoid the plain ones)
  20. if dpkg -L libsasl-modules-plain &> /dev/null && [ -f /etc/ssl/certs/postfix.pem ]; then
  21. mkdir -p $confdir/sasl
  22. echo 'pwcheck_method: pam' >$confdir/sasl/smtpd.conf
  23. echo 'auto_transition: false' >>$confdir/sasl/smtpd.conf
  24. groups postfix | grep shadow &>/dev/null || adduser postfix shadow
  25. # Release TLS-related daemons from chroot jail (bringing SASL into the jail is just too messy)
  26. cp -a $confdir/master.cf $confdir/master.cf.old
  27. cat $confdir/master.cf.old | sed \
  28. -e "s/^\(smtp$sp\+inet\($sp\+[n-]\)\{2\}$sp\+\)[n-]\(\($sp\+-\)\{2\}$sp\+smtpd\).*/\1n\3 -o smtpd_sasl_auth_enable=yes/" \
  29. -e "s/^#?\(\(smtps\|587\)$sp\+inet\($sp\+[n-]\)\{2\}$sp\+\)[n-]/\1n/" \
  30. > $confdir/master.cf
  31. postconf -e 'smtpd_tls_cert_file = /etc/ssl/certs/postfix.pem'
  32. if [ -f /etc/ssl/private/postfix.pem ]; then
  33. postconf -e 'smtpd_tls_key_file = /etc/ssl/private/postfix.pem'
  34. fi
  35. postconf -e 'smtpd_tls_loglevel = 1'
  36. postconf -e 'smtpd_use_tls = yes'
  37. # postconf -e 'smtpd_tls_session_cache_database = sdbm:/etc/postfix/smtpd_scache'
  38. postconf -e 'smtpd_tls_auth_only = yes'
  39. postconf -e 'smtpd_sasl_auth_enable = no'
  40. postconf -e 'smtpd_sasl_security_options = noanonymous'
  41. postconf -e 'smtpd_sasl_local_domain = $myhostname'
  42. postconf -e 'broken_sasl_auth_clients = yes'
  43. postconf -e 'tls_random_source = dev:/dev/urandom'
  44. postconf -e 'tls_daemon_random_source = dev:/dev/urandom'
  45. # Check if using a proper key exists (not just a self-signed one)
  46. # (it is assumed that a CA certificate is made public if used!)
  47. if [ -f /etc/ssl/certs/cacert.pem ]; then
  48. postconf -e 'smtpd_tls_CAfile = /etc/ssl/certs/cacert.pem'
  49. postconf -e 'smtp_tls_CAfile = $smtpd_tls_CAfile'
  50. postconf -e 'smtp_tls_cert_file = /etc/ssl/certs/postfix.pem'
  51. # Client side TLS only makes sense if a publicly available certificate is available
  52. # (and DON'T publish a self-signed certificate!)
  53. if [ -f /etc/ssl/private/postfix.pem ]; then
  54. postconf -e 'smtp_tls_key_file = $smtpd_tls_key_file'
  55. fi
  56. postconf -e 'smtp_tls_loglevel = 1'
  57. postconf -e 'smtp_use_tls = yes'
  58. postconf -e 'smtp_tls_CApath = /etc/ssl/certs'
  59. postconf -e 'smtp_tls_note_starttls_offer = yes' # Useful when collecting info for smtp_tls_per_site option
  60. # postconf -e 'smtp_tls_session_cache_database = sdbm:/etc/postfix/smtp_scache'
  61. # This makes Netscape ask for a certificate, so make sure it IS public!
  62. postconf -e 'smtpd_tls_ask_ccert = yes'
  63. fi
  64. else
  65. echo 'TLS not activated - check the script for requirements...'
  66. fi
  67. /etc/init.d/postfix reload
  68. # Based on this: http://jimsun.linxnet.com/misc/postfix-anti-UCE.txt
  69. # Support for trusted MX backup networks added
  70. # PCRE stuff avoided, as PCRE is only optional on newest Debian packages
  71. # RBLs replaced with those recommended by http://www.antispews.org/
  72. # Here's a convenient overview of different blackholes:
  73. # http://rbls.org/
  74. # smtpd_tls_CAfile