fix: Sanitize `postfix-master.cf` via helper

This feature should have been using the helper to avoid user error from their config updates accidentally introducing subtle breakage implicitly (due to CRLF or missing final newline).
This commit is contained in:
polarathene 2024-01-24 19:14:30 +13:00
parent 2c23f765f9
commit ef5a5097fb
1 changed files with 10 additions and 8 deletions

View File

@ -109,8 +109,9 @@ function _setup_postfix_late() {
function __postfix__setup_override_configuration() { function __postfix__setup_override_configuration() {
__postfix__log 'debug' 'Overriding / adjusting configuration with user-supplied values' __postfix__log 'debug' 'Overriding / adjusting configuration with user-supplied values'
if [[ -f /tmp/docker-mailserver/postfix-main.cf ]]; then local OVERRIDE_CONFIG_POSTFIX_MAIN='/tmp/docker-mailserver/postfix-main.cf'
cat /tmp/docker-mailserver/postfix-main.cf >>/etc/postfix/main.cf if [[ -f ${OVERRIDE_CONFIG_POSTFIX_MAIN} ]]; then
cat "${OVERRIDE_CONFIG_POSTFIX_MAIN}" >>/etc/postfix/main.cf
_adjust_mtime_for_postfix_maincf _adjust_mtime_for_postfix_maincf
# do not directly output to 'main.cf' as this causes a read-write-conflict # do not directly output to 'main.cf' as this causes a read-write-conflict
@ -118,20 +119,21 @@ function __postfix__setup_override_configuration() {
mv /tmp/postfix-main-new.cf /etc/postfix/main.cf mv /tmp/postfix-main-new.cf /etc/postfix/main.cf
_adjust_mtime_for_postfix_maincf _adjust_mtime_for_postfix_maincf
__postfix__log 'trace' "Adjusted '/etc/postfix/main.cf' according to '/tmp/docker-mailserver/postfix-main.cf'" __postfix__log 'trace' "Adjusted '/etc/postfix/main.cf' according to '${OVERRIDE_CONFIG_POSTFIX_MAIN}'"
else else
__postfix__log 'trace' "No extra Postfix settings loaded because optional '/tmp/docker-mailserver/postfix-main.cf' was not provided" __postfix__log 'trace' "No extra Postfix settings loaded because optional '${OVERRIDE_CONFIG_POSTFIX_MAIN}' was not provided"
fi fi
if [[ -f /tmp/docker-mailserver/postfix-master.cf ]]; then local OVERRIDE_CONFIG_POSTFIX_MASTER='/tmp/docker-mailserver/postfix-master.cf'
if [[ -f ${OVERRIDE_CONFIG_POSTFIX_MASTER} ]]; then
while read -r LINE; do while read -r LINE; do
if [[ ${LINE} =~ ^[0-9a-z] ]]; then if [[ ${LINE} =~ ^[0-9a-z] ]]; then
postconf -P "${LINE}" postconf -P "${LINE}"
fi fi
done < /tmp/docker-mailserver/postfix-master.cf done < <(_get_valid_lines_from_file "${OVERRIDE_CONFIG_POSTFIX_MASTER}")
__postfix__log 'trace' "Adjusted '/etc/postfix/master.cf' according to '/tmp/docker-mailserver/postfix-master.cf'" __postfix__log 'trace' "Adjusted '/etc/postfix/master.cf' according to '${OVERRIDE_CONFIG_POSTFIX_MASTER}'"
else else
__postfix__log 'trace' "No extra Postfix settings loaded because optional '/tmp/docker-mailserver/postfix-master.cf' was not provided" __postfix__log 'trace' "No extra Postfix settings loaded because optional '${OVERRIDE_CONFIG_POSTFIX_MASTER}' was not provided"
fi fi
} }