From e3d2b844189b95da695a5d759d4827d1b7de2879 Mon Sep 17 00:00:00 2001 From: Benjamin Sonntag Date: Tue, 17 Jul 2018 17:39:14 +0200 Subject: [PATCH] [fix] reading multiline dkim key + fixing autodiscover zone having NULL name --- bureau/class/m_bind.php | 2 +- bureau/class/m_mail.php | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/bureau/class/m_bind.php b/bureau/class/m_bind.php index b8b88d9a..7cb493b8 100644 --- a/bureau/class/m_bind.php +++ b/bureau/class/m_bind.php @@ -223,7 +223,7 @@ class m_bind { sub_domaines sd, domaines_type dt WHERE - sd.type=dt.name + sd.type=dt.name AND sd.enable IN ('ENABLE', 'ENABLED') ORDER BY ENTRY ;"); $t=""; diff --git a/bureau/class/m_mail.php b/bureau/class/m_mail.php index 06b158db..e8496866 100644 --- a/bureau/class/m_mail.php +++ b/bureau/class/m_mail.php @@ -1007,12 +1007,12 @@ ORDER BY $db->query("SELECT domaine,sub,type,valeur FROM sub_domaines WHERE domaine=? AND sub='autodiscover' AND type='autodiscover';",array($domain)); if (!$db->next_record()) { - $db->query("INSERT INTO sub_domaines SET domaine=?, compte=?, sub='autodiscover', type='autodiscover';",array($domain,$uid)); + $db->query("INSERT INTO sub_domaines SET domaine=?, compte=?, sub='autodiscover', type='autodiscover', valeur='';",array($domain,$uid)); $changed=true; } $db->query("SELECT domaine,sub,type,valeur FROM sub_domaines WHERE domaine=? AND sub='autoconfig' AND type='autodiscover';",array($domain)); if (!$db->next_record()) { - $db->query("INSERT INTO sub_domaines SET domaine=?, compte=?, sub='autoconfig', type='autodiscover';",array($domain,$uid)); + $db->query("INSERT INTO sub_domaines SET domaine=?, compte=?, sub='autoconfig', type='autodiscover', valeur='';",array($domain,$uid)); $changed=true; } if ($changed) { @@ -1184,10 +1184,30 @@ ORDER BY * or false if an error occurred **/ function dkim_get_entry($domain) { + global $msg; $key=file_get_contents("/etc/opendkim/keys/".$domain."/alternc.txt"); + // easy: monoline key if (preg_match('#alternc._domainkey IN TXT "(.*)"#',$key,$mat)) { return $mat[1]; + } else { + // Need to parse a multiligne key: + $inkey=false; $result=""; + $lines=explode("\n",$key); + foreach($lines as $line) { + if (preg_match('#alternc._domainkey IN TXT \( "(.*)"#',$key,$mat)) { + $result.=$mat[1]; $inkey=true; continue; + } + if ($inkey && preg_match('# "(.*)" \)#',$key,$mat)) { + $result.=$mat[1]; $inkey=false; break; + } + if ($inkey && preg_match('# "(.*)" #',$key,$mat)) { + $result.=$mat[1]; $inkey=true; continue; + } + } + if ($result) + return $result; } + $msg->debug("mail","dkim_get_entry($domain) failed"); return false; }