various fixes
authorIan Kelling <ian@iankelling.org>
Sat, 7 Nov 2020 11:51:44 +0000 (06:51 -0500)
committerIan Kelling <ian@iankelling.org>
Sat, 7 Nov 2020 11:51:44 +0000 (06:51 -0500)
distro-begin
distro-end
mail-setup
vpn-mail-forward

index 154664734ed7d90ef817984e611a6fca2fabd1a3..df11e9383e69ea6597a7286e640aa6e9c372dbb3 100755 (executable)
@@ -292,6 +292,13 @@ if [[ ! -L /etc/nsswitch.conf ]]; then
   sudo mv /etc/nsswitch.conf /etc/nsswitch
   sudo ln -sf /etc/nsswitch/nsswitch.conf /etc
 fi
+
+f=/etc/apparmor.d/abstractions/nameservice
+if ! grep -q /etc/nsswitch/nsswitch.conf $f; then
+  sudo sed -i '/\/etc\/nsswitch.conf/a /etc/nsswitch/nsswitch.conf r,' $f
+  m ser reload apparmor
+fi
+
 pi libnss-resolve
 # default is
 # files mdns4_minimal [NOTFOUND=return] dns myhostname
index 00531718d0d588b5c9481d8c12385a9e49893ead..d917b585b03f432f4654f0efaa0ef9732d442fc1 100755 (executable)
@@ -519,7 +519,7 @@ ifconfig-push 10.8.0.5 255.255.255.0
 ifconfig-ipv6-push 2600:3c00:e000:280::3/64
 EOF
 
-    sudo dd of=/etc/systemd/system/vpnmail.service <<'EOF'
+    sudo dd of=/etc/systemd/system/vpn-mail-forward.service <<'EOF'
 [Unit]
 Description=Turns on iptables mail nat
 BindsTo=openvpn-server@mail.service
@@ -533,7 +533,7 @@ ExecStop=/a/bin/distro-setup/vpn-mail-forward stop
 RequiredBy=openvpn-server@mail.service
 EOF
     ser daemon-reload
-    sgo vpnmail.service
+    sgo vpn-mail-forward.service
     # needed for li's local mail delivery.
     tu /etc/hosts <<<"10.8.0.4 mail.iankelling.org"
     sgo openvpn-server@mail
index ea9e82d969f9eea4cf100e2a33b7d606cc651d05..b8377ed3f27258591b43fcb472944a241c29d13b 100755 (executable)
@@ -339,6 +339,7 @@ pi exim4 exim4-daemon-heavy spamassassin spf-tools-perl openvpn p0f postgrey pyz
 # note: pyzor debian readme says you need to run some initialization command
 # but its outdated.
 
+m usermod -a -G Debian-exim clamav
 soff openvpn
 
 
@@ -814,12 +815,15 @@ warn
 
 
 deny
-# defer_ok = accept messages even if there is a problem with clamav.
-# clamav regularly has fails, we havent had a reported problem with mail
-# not getting through, but this seems better.
   malware = */defer_ok
+  !condition = ${if match {$malware_name}{\N^Heuristic\N}}
   message = This message was detected as possible malware ($malware_name).
 
+warn
+  condition = ${if def:malware_name}
+  remove_header = Subject:
+  add_header = Subject: [Clamav warning: $malware_name] $h_subject
+  log_message = heuristic malware warning: $malware_name
 
 #accept
 #  spf = pass:fail:softfail:none:neutral:permerror:temperror
@@ -2120,6 +2124,9 @@ esac
 
 # * mail monitoring / testing
 
+# note, to test clamav, send an email with body that only contains
+# https://en.wikipedia.org/wiki/EICAR_test_file
+# which set malware_name to Eicar-Signature
 case $HOSTNAME in
   $MAIL_HOST|bk|je)
     # note: cronjob "ian" also does some important monitoring
index 7965263cebae29eb071eca2ba417faff935c9c31..54e01396822126d7d16bd05c5011ec350c0a437b 100755 (executable)
@@ -3,27 +3,39 @@
 set -eE -o pipefail
 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
 m() { printf "%s\n" "$*";  "$@"; }
-gw=$(/usr/sbin/ip route | sed -rn 's/^default via .* dev (\S+).*/\1/p')
+found=false
+# wait up to 10 seconds for the gateway to appear
+for i in in {1..10}; do
+  gw=$(/usr/sbin/ip route | sed -rn 's/^default via .* dev (\S+).*/\1/p')
+  if [[ $gw ]]; then
+    found=true
+  fi
+  sleep 1
+done
+if ! $found; then
+  echo $0: error: couldnt find gateway interface in 10 seconds >&2
+  exit 1
+fi
 do-forward() {
-    cmd=$1; shift
-    for port; do
-        m /sbin/iptables -t nat $cmd PREROUTING -i $gw -p tcp -m tcp --dport $port -j DNAT --to-destination 10.8.0.4:$port
-        # we could leave these on all the time but its convenient to do it here
-    done
-    m /sbin/iptables $cmd FORWARD -i tun+ -o $gw -j ACCEPT
-    m /sbin/iptables $cmd FORWARD -i $gw -o tun+ -j ACCEPT
+  cmd=$1; shift
+  for port; do
+    m /sbin/iptables -t nat $cmd PREROUTING -i $gw -p tcp -m tcp --dport $port -j DNAT --to-destination 10.8.0.4:$port
+  done
+  # we could leave these on all the time but its convenient to do it here
+  m /sbin/iptables $cmd FORWARD -i tun+ -o $gw -j ACCEPT
+  m /sbin/iptables $cmd FORWARD -i $gw -o tun+ -j ACCEPT
 }
 
 ports=(25 143 587)
 case $1 in
-    start)
-        do-forward -A ${ports[@]}
-        ;;
-    stop)
-        do-forward -D ${ports[@]}
-        ;;
-    *)
-        echo "$0: error: expected 1 argument of start or stop"
-        exit 1
-        ;;
+  start)
+    do-forward -A ${ports[@]}
+    ;;
+  stop)
+    do-forward -D ${ports[@]}
+    ;;
+  *)
+    echo "$0: error: expected 1 argument of start or stop"
+    exit 1
+    ;;
 esac