Skip to content

Commit f038c0a

Browse files
committed
Implemented: FS#2024 - Sanity check zones with named-checkzone
1 parent 648d438 commit f038c0a

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

server/plugins-available/bind_plugin.inc.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,19 @@ function soa_update($event_name,$data) {
113113
$filename = escapeshellcmd($dns_config['bind_zonefiles_dir'].'/pri.'.str_replace("/", "_", substr($zone['origin'],0,-1)));
114114
}
115115

116-
$app->log("Writing BIND domain file: ".$filename,LOGLEVEL_DEBUG);
117116
file_put_contents($filename,$tpl->grab());
118117
chown($filename, escapeshellcmd($dns_config['bind_user']));
119118
chgrp($filename, escapeshellcmd($dns_config['bind_group']));
119+
120+
//* Check the zonefile
121+
if(is_file($filename.'.err')) unlink($filename.'.err');
122+
exec('named-checkzone '.escapeshellarg($zone['origin']).' '.escapeshellarg($filename),$out,$return_status);
123+
if($return_status === 0) {
124+
$app->log("Writing BIND domain file: ".$filename,LOGLEVEL_DEBUG);
125+
} else {
126+
$app->log("Writing BIND domain file failed: ".$filename." ".implode(' ',$out),LOGLEVEL_WARN);
127+
rename($filename,$filename.'.err');
128+
}
120129
unset($tpl);
121130
unset($records);
122131
unset($records_out);
@@ -138,7 +147,8 @@ function soa_update($event_name,$data) {
138147
$filename = $dns_config['bind_zonefiles_dir'].'/pri.'.str_replace("/", "_", substr($zone['origin'],0,-1));
139148
}
140149

141-
if(is_file($filename)) unset($filename);
150+
if(is_file($filename)) unlink($filename);
151+
if(is_file($filename.'.err')) unlink($filename.'.err');
142152
}
143153

144154
//* Reload bind nameserver
@@ -166,6 +176,7 @@ function soa_delete($event_name,$data) {
166176
}
167177

168178
if(is_file($zone_file_name)) unlink($zone_file_name);
179+
if(is_file($zone_file_name.'.err')) unlink($zone_file_name.'.err');
169180
$app->log("Deleting BIND domain file: ".$zone_file_name,LOGLEVEL_DEBUG);
170181

171182
//* Reload bind nameserver
@@ -298,12 +309,14 @@ function write_named_conf($data, $dns_config) {
298309
$zones = array();
299310

300311
//* Check if the current zone that triggered this function has at least one NS record
312+
/* Has been replaced by a better zone check
301313
$rec_num = $app->db->queryOneRecord("SELECT count(id) as ns FROM dns_rr WHERE type = 'NS' AND zone = ".intval($data['new']['id'])." AND active = 'Y'");
302314
if($rec_num['ns'] == 0) {
303315
$exclude_zone = $data['new']['origin'];
304316
} else {
305317
$exclude_zone = '';
306318
}
319+
*/
307320

308321
//TODO : change this when distribution information has been integrated into server record
309322
if (file_exists('/etc/gentoo-release')) {
@@ -319,6 +332,8 @@ function write_named_conf($data, $dns_config) {
319332
//* Loop trough zones
320333
foreach($tmps as $tmp) {
321334

335+
$zone_file = $pri_zonefiles_path.str_replace("/", "_",substr($tmp['origin'],0,-1));
336+
322337
$options = '';
323338
if(trim($tmp['xfer']) != '') {
324339
$options .= " allow-transfer {".str_replace(',',';',$tmp['xfer']).";};\n";
@@ -327,9 +342,9 @@ function write_named_conf($data, $dns_config) {
327342
}
328343
if(trim($tmp['also_notify']) != '') $options .= ' also-notify {'.str_replace(',',';',$tmp['also_notify']).";};\n";
329344

330-
if($tmp['origin'] != $exclude_zone) {
345+
if(file_exists($zone_file)) {
331346
$zones[] = array( 'zone' => substr($tmp['origin'],0,-1),
332-
'zonefile_path' => $pri_zonefiles_path.str_replace("/", "_",substr($tmp['origin'],0,-1)),
347+
'zonefile_path' => $zone_file,
333348
'options' => $options
334349
);
335350
}

0 commit comments

Comments
 (0)