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