Skip to content

Commit 6a85386

Browse files
author
Till Brehm
committed
Merge branch 'dnssec-fix-cron' into 'stable-3.1'
DNSSEC-Fix: Possible transfer issue This fixes the current fact that auto-resigned zones do not change their serial which might cause slave dns servers not to replicate the zone with new RRSIGs. This is kind of a critical fix. See merge request !308
2 parents 1e33ee2 + 7f0edcf commit 6a85386

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

server/lib/classes/cron.d/550-bind_dnssec.inc.php

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,27 @@ class cronjob_bind_dnssec extends cronjob {
3535

3636
// job schedule
3737
protected $_schedule = '30 3 * * *'; //daily at 3:30 a.m.
38+
39+
private function increase_serial($serial){
40+
global $app, $conf;
41+
42+
// increase serial
43+
$serial_date = $app->functions->intval(substr($serial, 0, 8));
44+
$count = $app->functions->intval(substr($serial, 8, 2));
45+
$current_date = date("Ymd");
46+
if($serial_date >= $current_date){
47+
$count += 1;
48+
if ($count > 99) {
49+
$serial_date += 1;
50+
$count = 0;
51+
}
52+
$count = str_pad($count, 2, "0", STR_PAD_LEFT);
53+
$new_serial = $serial_date.$count;
54+
} else {
55+
$new_serial = $current_date.'01';
56+
}
57+
return $new_serial;
58+
}
3859

3960
public function onRunJob() {
4061
global $app, $conf;
@@ -54,36 +75,13 @@ public function onRunJob() {
5475
$domain = substr($data['origin'], 0, strlen($data['origin'])-1);
5576
if (!file_exists($dns_config['bind_zonefiles_dir'].'/'.$filespre.$domain)) return false;
5677

57-
$app->log('DNSSEC Auto-Resign: Resigning zone '.$domain, LOGLEVEL_INFO);
58-
59-
$zonefile = file_get_contents($dns_config['bind_zonefiles_dir'].'/'.$filespre.$domain);
60-
$keycount=0;
61-
foreach (glob($dns_config['bind_zonefiles_dir'].'/K'.$domain.'*.key') as $keyfile) {
62-
$includeline = '$INCLUDE '.basename($keyfile);
63-
if (!preg_match('@'.preg_quote($includeline).'@', $zonefile)) $zonefile .= "\n".$includeline."\n";
64-
$keycount++;
65-
}
66-
if ($keycount != 2) $app->log('DNSSEC Warning: There are more or less than 2 keyfiles for zone '.$domain, LOGLEVEL_WARN);
67-
file_put_contents($dns_config['bind_zonefiles_dir'].'/'.$filespre.$domain, $zonefile);
68-
69-
//Sign the zone and set it valid for max. 16 days
70-
exec('cd '.escapeshellcmd($dns_config['bind_zonefiles_dir']).';'.
71-
'/usr/sbin/dnssec-signzone -A -e +1382400 -3 $(head -c 1000 /dev/random | sha1sum | cut -b 1-16) -N increment -o '.escapeshellcmd($domain).' -t '.$filespre.escapeshellcmd($domain));
72-
73-
//Write Data back into DB
74-
$dnssecdata = "DS-Records:\n".file_get_contents($dns_config['bind_zonefiles_dir'].'/dsset-'.$domain.'.');
75-
$dnssecdata .= "\n------------------------------------\n\nDNSKEY-Records:\n";
76-
foreach (glob($dns_config['bind_zonefiles_dir'].'/K'.$domain.'*.key') as $keyfile) {
77-
$dnssecdata .= file_get_contents($keyfile)."\n\n";
78-
}
79-
80-
$app->db->query('UPDATE dns_soa SET dnssec_info=\''.$dnssecdata.'\', dnssec_initialized=\'Y\', dnssec_last_signed=\''.time().'\' WHERE id='.$data['id']);
81-
$data = next($soas);
78+
$app->log('DNSSEC Auto-Resign: Touching zone '.$domain, LOGLEVEL_INFO);
79+
$app->db->datalogUpdate('dns_soa', array("serial" => $this->increase_serial($data['serial'])), 'id', $data['id']);
8280
}
8381

8482
parent::onRunJob();
8583
}
8684

8785
}
8886

89-
?>
87+
?>

0 commit comments

Comments
 (0)