From 859a4b935972f243ffa7a7dfc477b363bd95c0d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ebbinghaus?= Date: Thu, 1 Oct 2026 12:59:07 +0200 Subject: [PATCH 1/2] Add red test for unintended removal of config keys --- unit-tests/000_test-multi-comment.bats | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/unit-tests/000_test-multi-comment.bats b/unit-tests/000_test-multi-comment.bats index 5510737..8d43b13 100644 --- a/unit-tests/000_test-multi-comment.bats +++ b/unit-tests/000_test-multi-comment.bats @@ -70,4 +70,18 @@ fi result=$(grep -E "^demo" /etc/postfix/sasl_passwd | wc -l) [ "$result" == "1" ] -} \ No newline at end of file +} + +@test "deleting a key that is also commented out removes only that key" { + do_postconf -e "smtpd_client_restrictions=permit" + do_postconf -# smtpd_client_restrictions + printf 'smtpd_client_restrictions = permit_mynetworks,\n reject_unlisted_sender\n' >> /etc/postfix/main.cf + do_postconf -e "mynetworks=127.0.0.0/8" + do_postconf -e "myorigin=example.org" + expected="$(postconf -n | grep -v '^smtpd_client_restrictions =')" + + do_postconf -# smtpd_client_restrictions + + postfix check + [ "$(postconf -n)" == "${expected}" ] +} From 5aad9eca8ed7cd2928ab5dbf8a2db96e4802a8bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ebbinghaus?= Date: Thu, 1 Oct 2026 13:00:06 +0200 Subject: [PATCH 2/2] Add fix for #168 Resolves: #168 --- image_root/scripts/common.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/image_root/scripts/common.sh b/image_root/scripts/common.sh index 8c12295..fb7371c 100755 --- a/image_root/scripts/common.sh +++ b/image_root/scripts/common.sh @@ -155,8 +155,8 @@ do_postconf() { fi if [[ "${has_key}" == "1" ]] && [[ "${has_commented_key}" == "1" ]]; then # The key appears in the comment as well as outside the comment. - # Delete the key which is outside of the comment - sed -i -e "/^${key}\s*=/ { :a; N; /^\s/ba; N; d }" /etc/postfix/main.cf + # Delete the key which is outside of the comment (with its continuation lines) + postconf -X "${key}" elif [[ "${has_key}" == "1" ]]; then # Comment out the key with postconf postconf -# "${key}" > /dev/null