[fix] reading multiline dkim key + fixing autodiscover zone having NULL name

This commit is contained in:
Benjamin Sonntag 2018-07-17 17:39:14 +02:00
parent 3bc65aed3f
commit e3d2b84418
2 changed files with 23 additions and 3 deletions

View File

@ -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="";

View File

@ -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;
}