Skip to content

Commit c92a4ee

Browse files
author
Till Brehm
committed
Merge branch 'dns-dnssec-fix-dbmaster' into 'stable-3.1'
Fix: DNSSEC-Info not written back into master DB adds some permissions for slave servers to DB and enables the slave to write back it's dnssec-info into the master db See merge request !312
2 parents b3e3f86 + 7416d2f commit c92a4ee

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

install/lib/installer_base.lib.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,15 @@ public function grant_master_database_rights($verbose = false) {
658658
if(!$this->dbmaster->query($query, $value['db'] . '.mail_backup', $value['user'], $host)) {
659659
$this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage);
660660
}
661+
662+
$query = "GRANT SELECT, UPDATE(`dnssec_initialized`, `dnssec_info`, `dnssec_last_signed`) ON ?? TO ?@?";
663+
if ($verbose){
664+
echo $query ."\n";
665+
}
666+
if(!$this->dbmaster->query($query, $value['db'] . '.dns_soa', $value['user'], $host)) {
667+
$this->warning('Unable to set rights of user in master database: '.$value['db']."\n Query: ".$query."\n Error: ".$this->dbmaster->errorMessage);
668+
}
669+
661670
}
662671

663672
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,13 @@ public function onRunJob() {
6868

6969
//TODO : change this when distribution information has been integrated into server record
7070
$filespre = (file_exists('/etc/gentoo-release')) ? 'pri/' : 'pri.';
71-
72-
$soas = $app->db->queryAllRecords('SELECT * FROM dns_soa WHERE dnssec_wanted=\'Y\' AND dnssec_initialized=\'Y\' AND dnssec_last_signed < '.(time()-(3600*24*5)+900)); //Resign zones every 5 days (expiry is 16 days so we have enough safety, 15 minutes tolerance)
73-
71+
$soas = $app->db->queryAllRecords('SELECT `id`,`serial`,`origin` FROM dns_soa WHERE server_id=? AND active=\'Y\' AND dnssec_wanted=\'Y\' AND dnssec_initialized=\'Y\' AND (dnssec_last_signed < ? OR dnssec_last_signed > ?)', intval($conf['server_id']), time()-(3600*24*5)+900, time()+900); //Resign zones every 5 days (expiry is 16 days so we have enough safety, 15 minutes tolerance)
72+
7473
foreach ($soas as $data) {
7574
$domain = substr($data['origin'], 0, strlen($data['origin'])-1);
76-
if (!file_exists($dns_config['bind_zonefiles_dir'].'/'.$filespre.$domain)) return false;
75+
if (!file_exists($dns_config['bind_zonefiles_dir'].'/'.$filespre.$domain)) continue;
7776

78-
$app->log('DNSSEC Auto-Resign: Touching zone '.$domain, LOGLEVEL_INFO);
77+
$app->log('DNSSEC Auto-Resign: Touching zone '.$domain, LOGLEVEL_DEBUG);
7978
$app->db->datalogUpdate('dns_soa', array("serial" => $this->increase_serial($data['serial'])), 'id', $data['id']);
8079
}
8180

server/plugins-available/bind_plugin.inc.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ function soa_dnssec_create(&$data) {
9595
//* Check Entropy
9696
if (file_get_contents('/proc/sys/kernel/random/entropy_avail') < 400) {
9797
$app->log('DNSSEC ERROR: We are low on entropy. Not generating new Keys for '.$domain.'. Please consider installing package haveged.', LOGLEVEL_WARN);
98+
echo "DNSSEC ERROR: We are low on entropy. Not generating new Keys for $domain. Please consider installing package haveged.\n";
9899
return false;
99100
}
100101

@@ -157,7 +158,8 @@ function soa_dnssec_sign(&$data) {
157158
$dnssecdata .= file_get_contents($keyfile)."\n\n";
158159
}
159160

160-
$app->db->query('UPDATE dns_soa SET dnssec_info=\''.$dnssecdata.'\', dnssec_initialized=\'Y\', dnssec_last_signed=\''.time().'\' WHERE id='.$data['new']['id']);
161+
if ($app->dbmaster !== $app->db) $app->dbmaster->query('UPDATE dns_soa SET dnssec_info=?, dnssec_initialized=\'Y\', dnssec_last_signed=? WHERE id=?', $dnssecdata, intval(time()), intval($data['new']['id']));
162+
$app->db->query('UPDATE dns_soa SET dnssec_info=?, dnssec_initialized=\'Y\', dnssec_last_signed=? WHERE id=?', $dnssecdata, intval(time()), intval($data['new']['id']));
161163
}
162164

163165
function soa_dnssec_update(&$data, $new=false) {
@@ -178,12 +180,13 @@ function soa_dnssec_update(&$data, $new=false) {
178180
//* Check for available entropy
179181
if (file_get_contents('/proc/sys/kernel/random/entropy_avail') < 200) {
180182
$app->log('DNSSEC ERROR: We are low on entropy. This could cause server script to fail. Please consider installing package haveged.', LOGLEVEL_ERR);
183+
echo "DNSSEC ERROR: We are low on entropy. This could cause server script to fail. Please consider installing package haveged.\n";
181184
return false;
182185
}
183186

184187
if (!$new && !file_exists($dns_config['bind_zonefiles_dir'].'/dsset-'.$domain.'.')) $this->soa_dnssec_create($data);
185188

186-
$dbdata = $app->db->queryOneRecord('SELECT id,serial FROM dns_soa WHERE id='.$data['new']['id']);
189+
$dbdata = $app->db->queryOneRecord('SELECT id,serial FROM dns_soa WHERE id=?', intval($data['new']['id']));
187190
exec('cd '.escapeshellcmd($dns_config['bind_zonefiles_dir']).';'.
188191
'named-checkzone '.escapeshellcmd($domain).' '.escapeshellcmd($dns_config['bind_zonefiles_dir']).'/'.$filespre.escapeshellcmd($domain).' | egrep -ho \'[0-9]{10}\'', $serial, $retState);
189192
if ($retState != 0) {
@@ -212,7 +215,8 @@ function soa_dnssec_delete(&$data) {
212215
unlink($dns_config['bind_zonefiles_dir'].'/'.$filespre.$domain.'.signed');
213216
unlink($dns_config['bind_zonefiles_dir'].'/dsset-'.$domain.'.');
214217

215-
$app->db->query('UPDATE dns_soa SET dnssec_info=\'\', dnssec_initialized=\'N\' WHERE id='.$data['new']['id']);
218+
if ($app->dbmaster !== $app->db) $app->dbmaster->query('UPDATE dns_soa SET dnssec_info=\'\', dnssec_initialized=\'N\' WHERE id=?', intval($data['new']['id']));
219+
$app->db->query('UPDATE dns_soa SET dnssec_info=\'\', dnssec_initialized=\'N\' WHERE id=?', intval($data['new']['id']));
216220
}
217221

218222
function soa_insert($event_name, $data) {

0 commit comments

Comments
 (0)