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