From 894d6234e9ee6e636679bf4229cc527eb84cc307 Mon Sep 17 00:00:00 2001 From: Michael Kuron Date: Sat, 22 Apr 2017 14:28:37 +0200 Subject: [PATCH] Improvements to forwarding hosts in Postfix - No more premature EOF and no more leaking of bash processes - Log result - Correctly treat non-CIDR entries - Adapt to schema change from df71e97 - Correctly report SQL failure --- data/conf/postfix/whitelist_forwardinghosts.sh | 7 ++++--- data/conf/rspamd/dynmaps/forwardinghosts.php | 9 ++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/data/conf/postfix/whitelist_forwardinghosts.sh b/data/conf/postfix/whitelist_forwardinghosts.sh index aa9df608..f18139b5 100755 --- a/data/conf/postfix/whitelist_forwardinghosts.sh +++ b/data/conf/postfix/whitelist_forwardinghosts.sh @@ -1,11 +1,12 @@ #!/bin/bash -while true; do - read QUERY +while read QUERY; do QUERY=($QUERY) if [ "${QUERY[0]}" != "get" ]; then echo "500 dunno" continue fi - echo $(curl -s http://172.22.1.251:8081/forwardinghosts.php?host=${QUERY[1]}) + result=$(curl -s http://172.22.1.251:8081/forwardinghosts.php?host=${QUERY[1]}) + logger -t whitelist_forwardinghosts -p mail.info "Look up ${QUERY[1]} on whitelist, result $result" + echo $result done diff --git a/data/conf/rspamd/dynmaps/forwardinghosts.php b/data/conf/rspamd/dynmaps/forwardinghosts.php index 95773e45..377c5e7e 100644 --- a/data/conf/rspamd/dynmaps/forwardinghosts.php +++ b/data/conf/rspamd/dynmaps/forwardinghosts.php @@ -7,13 +7,16 @@ ini_set('error_reporting', 0); function in_net($addr, $net) { $net = explode('/', $net); - $mask = $net[1]; + if (count($net) > 1) + $mask = $net[1]; $net = inet_pton($net[0]); $addr = inet_pton($addr); $length = strlen($net); // 4 for IPv4, 16 for IPv6 if (strlen($net) != strlen($addr)) return FALSE; + if (!isset($mask)) + $mask = $length * 8; $addr_bin = ''; $net_bin = ''; @@ -34,7 +37,7 @@ $opt = [ ]; try { $pdo = new PDO($dsn, $database_user, $database_pass, $opt); - $stmt = $pdo->query("SELECT * FROM `forwarding_hosts`"); + $stmt = $pdo->query("SELECT host FROM `forwarding_hosts`"); $networks = $stmt->fetchAll(PDO::FETCH_COLUMN); foreach ($networks as $network) { @@ -47,7 +50,7 @@ try { echo '200 dunno'; } catch (PDOException $e) { - echo 'settings { }'; + echo '200 dunno'; exit; } ?>