From c1b4e5ffd1690d966d90bfa3059c850299ca4a15 Mon Sep 17 00:00:00 2001 From: alinmear Date: Sun, 19 Mar 2017 20:25:27 +0100 Subject: [PATCH] Fix #526: fatal: no SASL authentication mechanisms When using the container with SMTP_ONLY = 1, then the container fails on ehlo because there is no valid sasl authentication mechanism available. This happens because sasl has been enabled within postfix/main.cf per default but sasl is not configured. To fix this _setup_postfix_sasl does not depend anymore on ENABLE_SASLAUTHD and will check in it's logic, whether to enable sasl or not within postfix/main.cf. --- target/start-mailserver.sh | 14 ++++++++++++-- test/email-templates/smtp-only.txt | 8 ++++++++ test/tests.bats | 13 +++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 test/email-templates/smtp-only.txt diff --git a/target/start-mailserver.sh b/target/start-mailserver.sh index 6a725874..07883c93 100644 --- a/target/start-mailserver.sh +++ b/target/start-mailserver.sh @@ -90,7 +90,6 @@ function register_functions() { if [ "$ENABLE_SASLAUTHD" = 1 ];then _register_setup_function "_setup_saslauthd" - _register_setup_function "_setup_postfix_sasl" fi if [ "$ENABLE_POSTGREY" = 1 ];then @@ -107,6 +106,7 @@ function register_functions() { _register_setup_function "_setup_postfix_hostname" _register_setup_function "_setup_dovecot_hostname" + _register_setup_function "_setup_postfix_sasl" _register_setup_function "_setup_postfix_override_configuration" _register_setup_function "_setup_postfix_sasl_password" _register_setup_function "_setup_security_stack" @@ -545,11 +545,21 @@ function _setup_postgrey() { function _setup_postfix_sasl() { + if [[ ${ENABLE_SASLAUTHD} == 1 ]];then [ ! -f /etc/postfix/sasl/smtpd.conf ] && cat > /etc/postfix/sasl/smtpd.conf << EOF pwcheck_method: saslauthd mech_list: plain login EOF - return 0 + fi + + # cyrus sasl or dovecot sasl + if [[ ${ENABLE_SASLAUTHD} == 1 ]] || [[ ${SMTP_ONLY} == 0 ]];then + sed -i -e 's|^smtpd_sasl_auth_enable[[:space:]]\+.*|smtpd_sasl_auth_enable = yes|g' /etc/postfix/main.cf + else + sed -i -e 's|^smtpd_sasl_auth_enable[[:space:]]\+.*|smtpd_sasl_auth_enable = no|g' /etc/postfix/main.cf + fi + + return 0 } function _setup_saslauthd() { diff --git a/test/email-templates/smtp-only.txt b/test/email-templates/smtp-only.txt new file mode 100644 index 00000000..220ace15 --- /dev/null +++ b/test/email-templates/smtp-only.txt @@ -0,0 +1,8 @@ +HELO mail.localhost +MAIL FROM: test@localhost +RCPT TO: user2@external.tld +DATA +This is a test mail. + +. +QUIT diff --git a/test/tests.bats b/test/tests.bats index 39fd6efa..857ae476 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -331,6 +331,19 @@ load 'test_helper/bats-assert/load' assert_output 1 } +@test "checking smtp_only: mail send should work" { + run docker exec mail_smtponly /bin/sh -c "postconf -e smtp_host_lookup=no" + assert_success + run docker exec mail_smtponly /bin/sh -c "/etc/init.d/postfix reload" + assert_success + run docker exec mail_smtponly /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/smtp-only.txt" + assert_success + run docker exec mail_smtponly /bin/sh -c 'grep -E "to=.*status\=sent" /var/log/mail/mail.log' + assert_success +} + + + # # accounts #