This commit is contained in:
chris committed 2026-11-09 15:14:08 +01:00
commit 4b1af1419e
6 files changed
+167 -79

No files matched your search

+80 -33
View File
@@ -23,9 +23,17 @@ postfix_spool_dir="/var/spool/postfix"
opendmarc_socket_dir="${postfix_spool_dir}/opendmarc"
opendmarc_socket_file="${opendmarc_socket_dir}/opendmarc.sock"
# - HistoryFile is intentionally NOT set: it is only useful if the records are
# - imported regularly with opendmarc-importstats(8) to generate DMARC aggregate
# - reports. We do not generate such reports, so the file would only grow and,
# - located in /run, be lost at every reboot. An active setting is commented out
# - further below.
# -
config_file_name_value_parameters="
AuthservID|HOSTNAME
TrustedAuthservIDs|HOSTNAME
PublicSuffixList|/usr/share/publicsuffix/public_suffix_list.dat
UserID|opendmarc
PidFile|/run/opendmarc/opendmarc.pid"
if which sympa ; then
config_file_name_value_parameters="$config_file_name_value_parameters
@@ -44,8 +52,7 @@ config_file_name_value_parameters="$config_file_name_value_parameters
UMask|002
FailureReports|false
AutoRestart|true
HistoryFile|/run/opendmarc/opendmarc.dat
SPFIgnoreResults|false
SPFIgnoreResults|true
SPFSelfValidate|true
Socket|${opendmarc_socket_file}
"
@@ -468,27 +475,17 @@ else
fi
# - Add 'HistoryFile' with default value to the original opendmarc.conf file
# - Do not use 'HistoryFile': see the note at the parameter list on top of this
# - script. Comment out an active setting, e.g. left over from a previous version
# - of this script.
#
_param="HistoryFile"
echononl " Add '${_param}' with default value to the opendmarc.conf file.."
if ! $(grep -q -E "^${_param}\s+" ${opendmarc_conf_file} 2> /dev/null) ; then
cat << EOF >> ${opendmarc_conf_file}
## HistoryFile (string)
##
## If set, specifies the location of a text file to which records are written
## that can be used to generate DMARC aggregate reports. Records are batches of
## rows containing information about a single received message, and include all
## relevant information needed to generate a DMARC aggregate report. It is
## expected that this will not be used in its raw form, but rather periodically
## imported into a relational database from which the aggregate reports can be
## extracted using opendmarc-importstats(8).
#
#HistoryFile /run/opendmarc/opendmarc.dat
EOF
echononl " Deactivate '${_param}' in the opendmarc.conf file.."
if grep -q -E "^\s*${_param}\s+" ${opendmarc_conf_file} 2> /dev/null ; then
perl -i -p -e 's/^(\s*HistoryFile\s)/#$1/' ${opendmarc_conf_file} > "$log_file" 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
opendmarc_needs_restart=true
else
echo_failed
error "$(cat $log_file)"
@@ -509,7 +506,7 @@ if ! $(grep -q -E "^${_param}\s+" ${opendmarc_conf_file} 2> /dev/null) ; then
## is useful if you want the filter to perform SPF checks itself, or because you
## don't trust the arriving header. The default is "false".
#
SPFIgnoreResults false
SPFIgnoreResults true
EOF
if [[ $? -eq 0 ]] ; then
echo_ok
@@ -547,6 +544,60 @@ else
fi
# - Add 'PublicSuffixList' with default value to the original opendmarc.conf file
#
_param="PublicSuffixList"
echononl " Add '${_param}' with default value to the opendmarc.conf file.."
if ! $(grep -q -E "^${_param}\s+" ${opendmarc_conf_file} 2> /dev/null) ; then
cat << EOF >> ${opendmarc_conf_file}
## PublicSuffixList (string)
##
## Specifies the path to a file that contains top-level domains (TLDs) that
## will be used to compute the Organizational Domain for a given domain name,
## as described in the DMARC specification. If not provided, the filter will
## not be able to determine the Organizational Domain and only the presented
## domain will be evaluated.
#
PublicSuffixList /usr/share/publicsuffix/public_suffix_list.dat
EOF
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
# - Add 'UserID' with default value to the original opendmarc.conf file
#
_param="UserID"
echononl " Add '${_param}' with default value to the opendmarc.conf file.."
if ! $(grep -q -E "^${_param}\s+" ${opendmarc_conf_file} 2> /dev/null) ; then
cat << EOF >> ${opendmarc_conf_file}
## UserID (string)
##
## Attempts to become the specified userid before starting operations.
## The process will be assigned all of the groups and primary group ID of
## the named userid unless an alternate group is specified.
#
UserID opendmarc
EOF
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
else
echo_skipped
fi
# - Save configuration file from distribution
# -
echononl " Save configuration file from distribution"
@@ -746,22 +797,18 @@ else
cat <<EOF > ${opendmarc_base_dir}/ignore.hosts 2> $log_file
# /etc/opendmarc/ignore.hosts
#
# Aktuell hat OpenDMARC seinen Milter nur am Dienst
# 'localhost:10025' hängen. Dort ist der Client
# immer 127.0.0.1, nicht die externe Gegenstelle.
# OpenDMARC haengt als Milter an den SMTP-Diensten von Postfix
# (smtpd_milters in main.cf), also vor Amavis. Er sieht dort die
# echte Client-IP. An 'localhost:10025' laeuft kein Milter.
#
# Deshalb macht es in diesem Setup keinen Sinn,
# hier IP-Adressen von externen Diensten (CRSend etc.)
# einzutragen – sie würden nie matchen.
# Eingetragene Hostnamen, IP-Adressen oder CIDR-Netze werden von
# OpenDMARC nicht geprueft. Ein Eintrag wirkt also tatsaechlich:
# fuer solche Clients werden DMARC-Richtlinien nicht durchgesetzt.
#
# WICHTIG:
# - KEIN 127.0.0.1
# - KEIN localhost
# - KEIN ::1
# Eigene Listen- und Relay-Server gehoeren nicht hierher: sie werden
# mit /etc/postfix/smtpd_milter_map von allen Miltern ausgenommen.
#
# Eintrag dieser Adressen würde DMARC komplett deaktivieren.
#
# ==> Datei bleibt absichtlich leer.
# ==> Datei bleibt absichtlich leer, solange keine Ausnahme noetig ist.
EOF
opendmarc_needs_restart=true
if [[ $? -eq 0 ]] ; then
+26 -10
View File
@@ -1213,19 +1213,30 @@ set_postfwd_default() {
_tmp_file="$(mktemp)"
awk -v var="$_var" -v val="$_val" '
function unq(s) {
gsub(/^[ \t]+|[ \t]+$/, "", s)
gsub(/^[ \t\r]+|[ \t\r]+$/, "", s)
if (s ~ /^".*"$/ || s ~ /^\047.*\047$/) s = substr(s, 2, length(s) - 2)
return s
}
$0 ~ "^[ \t]*" var "=" {
cur = $0 ; sub("^[ \t]*" var "=", "", cur)
if (! done && unq(cur) == unq(val)) { print ; done = 1 ; next }
print "#" $0
if (! done) { print var "=" val ; done = 1 }
next
function is_set(s) { return s ~ ("^[ \t]*" var "=") }
function is_wanted(s) {
sub("^[ \t]*" var "=", "", s)
return unq(s) == unq(val)
}
# - Read the whole file first: a line with the wanted value must stay
# - untouched, no matter which other settings of VAR precede it.
{
line[NR] = $0
if (is_set($0) && is_wanted($0)) found = 1
}
END {
for (i = 1; i <= NR; i++) {
if (! is_set(line[i])) { print line[i] ; continue }
if (is_wanted(line[i])) { print line[i] ; continue }
print "#" line[i]
if (! found) { print var "=" val ; found = 1 }
}
if (! found) print var "=" val
}
{ print }
END { if (! done) print var "=" val }
' "$postfwd_default_file" > "$_tmp_file" 2> "$log_file"
if [[ $? -ne 0 ]] ; then
@@ -2537,7 +2548,12 @@ smtpd_client_restrictions =
reject_rhsbl_helo dbl.spamhaus.org=127.0.1.[2..99],
reject_rhsbl_reverse_client dbl.spamhaus.org=127.0.1.[2..99],
reject_rhsbl_sender dbl.spamhaus.org=127.0.1.[2..99],
reject_rbl_client zen.spamhaus.org=127.0.1.[2..99],
# Only reject on real listings. ZEN answers with 127.0.0.2 - 127.0.0.11,
# DBL with 127.0.1.2 - 127.0.1.99. Do NOT use these lists without a range:
# If Spamhaus blocks our queries, it answers every query with an error code
# like 127.255.255.254. Without a range, all mail would then be rejected.
#
reject_rbl_client zen.spamhaus.org=127.0.0.[2..11],
# Greylisting check
#
+20 -9
View File
@@ -120,19 +120,30 @@ set_postfwd_default() {
_tmp_file="$(mktemp)"
awk -v var="$_var" -v val="$_val" '
function unq(s) {
gsub(/^[ \t]+|[ \t]+$/, "", s)
gsub(/^[ \t\r]+|[ \t\r]+$/, "", s)
if (s ~ /^".*"$/ || s ~ /^\047.*\047$/) s = substr(s, 2, length(s) - 2)
return s
}
$0 ~ "^[ \t]*" var "=" {
cur = $0 ; sub("^[ \t]*" var "=", "", cur)
if (! done && unq(cur) == unq(val)) { print ; done = 1 ; next }
print "#" $0
if (! done) { print var "=" val ; done = 1 }
next
function is_set(s) { return s ~ ("^[ \t]*" var "=") }
function is_wanted(s) {
sub("^[ \t]*" var "=", "", s)
return unq(s) == unq(val)
}
# - Read the whole file first: a line with the wanted value must stay
# - untouched, no matter which other settings of VAR precede it.
{
line[NR] = $0
if (is_set($0) && is_wanted($0)) found = 1
}
END {
for (i = 1; i <= NR; i++) {
if (! is_set(line[i])) { print line[i] ; continue }
if (is_wanted(line[i])) { print line[i] ; continue }
print "#" line[i]
if (! found) { print var "=" val ; found = 1 }
}
if (! found) print var "=" val
}
{ print }
END { if (! done) print var "=" val }
' "$postfwd_default_file" > "$_tmp_file" 2> "$log_file"
if [[ $? -ne 0 ]] ; then
+2 -2
View File
@@ -2200,7 +2200,7 @@ fi
## - log_path = syslog
## - syslog_facility = local1
## - auth_verbose = yes
## - auth_verbose_passwords = plain
## - auth_verbose_passwords = no
## -
## - in conjunction with the the following entries in /etc/rsyslog.conf
## -
@@ -2219,7 +2219,7 @@ perl -i -n -p -e "s#^([ ]*)\#?\ ?(syslog_facility\ ?=.*)#\1\#\# \2\n\1syslog_fac
/usr/local/dovecot-${_version}/etc/dovecot/conf.d/10-logging.conf || _failed=true
perl -i -n -p -e "s#^([ ]*)\#?\ ?(auth_verbose\ ?=.*)#\1\#\# \2\n\1auth_verbose = yes#g" \
/usr/local/dovecot-${_version}/etc/dovecot/conf.d/10-logging.conf || _failed=true
perl -i -n -p -e "s#^([ ]*)\#?\ ?(auth_verbose_passwords\ ?=.*)#\1\#\# \2\n\1auth_verbose_passwords = plain#g" \
perl -i -n -p -e "s#^([ ]*)\#?\ ?(auth_verbose_passwords\ ?=.*)#\1\#\# \2\n\1auth_verbose_passwords = no#g" \
/usr/local/dovecot-${_version}/etc/dovecot/conf.d/10-logging.conf || _failed=true
if ! $_failed ; then
+10 -5
View File
@@ -6874,7 +6874,7 @@ if [[ $dovecot_major_version -gt 2 ]] \
# log_path =syslog
# syslog_facility = local1
# auth_verbose = yes
# auth_verbose_passwords = plain
# auth_verbose_passwords = no
#
#
# in conjunction with the the following entries in /etc/rsyslog.conf
@@ -6949,7 +6949,9 @@ EOF
if grep -qE "^\s*auth_verbose_passwords\s*=" "${_conf_file}"; then
replace_variable "auth_verbose_passwords" "yes" "${_conf_file}" || _failed=true
# - Never log attempted passwords: 'yes' and 'plain' write them in cleartext to
# - the log, including the real passwords of users who only made a typo.
replace_variable "auth_verbose_passwords" "no" "${_conf_file}" || _failed=true
else
@@ -6962,7 +6964,10 @@ EOF
#
# plain, yes: Output cleartext password (NOT RECOMMENDED)
# sha1: Output SHA1 hashed password
auth_verbose_passwords = plain
#
# Never log attempted passwords: they also contain real passwords of users
# who only made a typo.
auth_verbose_passwords = no
EOF
fi
@@ -7000,7 +7005,7 @@ else
## - log_path = syslog
## - syslog_facility = local1
## - auth_verbose = yes
## - auth_verbose_passwords = plain
## - auth_verbose_passwords = no
## -
## - in conjunction with the the following entries in /etc/rsyslog.conf
## -
@@ -7018,7 +7023,7 @@ else
${_conf_file} || _failed=true
perl -i -n -p -e "s#^([ ]*)\#?\ ?(auth_verbose\ ?=.*)#\1\#\# \2\n\1auth_verbose = yes#g" \
${_conf_file} || _failed=true
perl -i -n -p -e "s#^([ ]*)\#?\ ?(auth_verbose_passwords\ ?=.*)#\1\#\# \2\n\1auth_verbose_passwords = plain#g" \
perl -i -n -p -e "s#^([ ]*)\#?\ ?(auth_verbose_passwords\ ?=.*)#\1\#\# \2\n\1auth_verbose_passwords = no#g" \
${_conf_file} || _failed=true
if ! $_failed ; then
+29 -20
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
#
# Update /etc/default/postfwd (idempotent) and reload postfwd.
# Update /etc/default/postfwd (idempotent) and restart postfwd if needed.
#
# For every variable below:
# - already set to the wanted value -> nothing to do
@@ -14,8 +14,7 @@
# - file changed -> 'systemctl restart postfwd'
# (ARGS, INET and PORT are start parameters of the
# daemon - a reload does NOT apply them)
# - file unchanged -> 'systemctl reload postfwd'
# (rereads postfwd.cf and the file: lists)
# - file unchanged -> postfwd is left alone (no restart, no reload)
#
postfwd_default_file="/etc/default/postfwd"
@@ -80,19 +79,30 @@ set_postfwd_default() {
_tmp_file="$(mktemp)"
awk -v var="$_var" -v val="$_val" '
function unq(s) {
gsub(/^[ \t]+|[ \t]+$/, "", s)
gsub(/^[ \t\r]+|[ \t\r]+$/, "", s)
if (s ~ /^".*"$/ || s ~ /^\047.*\047$/) s = substr(s, 2, length(s) - 2)
return s
}
$0 ~ "^[ \t]*" var "=" {
cur = $0 ; sub("^[ \t]*" var "=", "", cur)
if (! done && unq(cur) == unq(val)) { print ; done = 1 ; next }
print "#" $0
if (! done) { print var "=" val ; done = 1 }
next
function is_set(s) { return s ~ ("^[ \t]*" var "=") }
function is_wanted(s) {
sub("^[ \t]*" var "=", "", s)
return unq(s) == unq(val)
}
# - Read the whole file first: a line with the wanted value must stay
# - untouched, no matter which other settings of VAR precede it.
{
line[NR] = $0
if (is_set($0) && is_wanted($0)) found = 1
}
END {
for (i = 1; i <= NR; i++) {
if (! is_set(line[i])) { print line[i] ; continue }
if (is_wanted(line[i])) { print line[i] ; continue }
print "#" line[i]
if (! found) { print var "=" val ; found = 1 }
}
if (! found) print var "=" val
}
{ print }
END { if (! done) print var "=" val }
' "$postfwd_default_file" > "$_tmp_file" 2> "$log_file"
if [[ $? -ne 0 ]] ; then
@@ -149,18 +159,17 @@ done
echo ""
if $errors ; then
fatal "Errors while updating '${postfwd_default_file}' - postfwd NOT reloaded."
fatal "Errors while updating '${postfwd_default_file}' - postfwd NOT restarted."
fi
if $file_changed ; then
echononl " Restart postfwd (start parameters changed)"
_action="restart"
else
echononl " Reload postfwd"
_action="reload"
if ! $file_changed ; then
echo " Nothing changed - postfwd is left alone."
echo ""
clean_up 0
fi
if systemctl $_action postfwd > "$log_file" 2>&1 ; then
echononl " Restart postfwd (start parameters changed)"
if systemctl restart postfwd > "$log_file" 2>&1 ; then
echo_ok
else
echo_failed