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