Skip to content

Commit

Permalink
Merge pull request #45 from yast/Bug_931019
Browse files Browse the repository at this point in the history
Bug 931019
  • Loading branch information
schubi2 committed Jun 19, 2015
2 parents dd5180b + ee6dc77 commit 3ee5384
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 57 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
2.17.24
2.17.25
22 changes: 22 additions & 0 deletions package/yast2-dns-server.changes
@@ -1,3 +1,25 @@
-------------------------------------------------------------------
Thu Jun 18 10:20:45 CEST 2015 - schubi@suse.de

- Fixed handling of zones (bnc#931019)
Backporting fix from SLES12 written by locilka@suse.com :
- Checking for system zones was moved to separate function
- Extended list of zones marked as system (internal) ones with
(0\.)+ip6.arpa
- Not allowing to edit system zones (belong to bind package)
- Added check for 'bind' package to be installed before writing
the configuration
- Marking all imported zones as 'modified' to be written later
- Marking all imported non-system zones as 'is_new' to create
a zone file for them
- Flushing /etc/named.conf cache 'after' writing zones (instead
of 'before')
- Using "" as the default NETCONFIG_DNS_POLICY (instead of 0)
- Do not write system zones to LDAP (bnc#746401)
- If systems zones are marked as modified, they are written to
named configuration (if LDAP is not in use)
- 2.17.25

-------------------------------------------------------------------
Mon Jun 15 19:50:56 UTC 2015 - mfilka@suse.com

Expand Down
99 changes: 80 additions & 19 deletions src/DnsServer.pm
Expand Up @@ -66,7 +66,7 @@ my %yapi_conf = ();

#my $modify_resolv_conf_dynamically = 0;

my $netconfig_dns_policy = 0;
my $netconfig_dns_policy = "";

my @acl = ();

Expand Down Expand Up @@ -105,6 +105,21 @@ sub contains {
$found;
}

# System zones are not allowed to be edited in YaST DNS Server
#
# @param [String] zone name
# @return [Boolean] whether zone is a system one (included in bind package)
sub is_system_zone {
my $zone_name = shift;

return (
$zone_name eq "localhost" ||
$zone_name eq "0.0.127.in-addr.arpa" ||
$zone_name =~ /^(0\.)+ip6.arpa$/ ||
$zone_name eq "."
);
}

##------------------------------------
# Routines for reading/writing configuration

Expand All @@ -120,9 +135,10 @@ sub ZoneWrite {
return 0;
}

if ($zone_name eq "localhost" || $zone_name eq "0.0.127.in-addr.arpa")
# Do not write system zones to LDAP (bnc#746401)
if ($use_ldap && is_system_zone($zone_name))
{
y2milestone ("Skipping system zone $zone_name");
y2milestone ("Using LDAP, skipping system zone $zone_name");
return 1;
}

Expand Down Expand Up @@ -385,15 +401,20 @@ sub SaveGlobals {
! $self->contains (\@current_zones, $_);
} @old_zones;
@del_zones = grep {
$_ ne "zone \".\" in" && $_ ne "zone \"localhost\" in"
&& $_ ne "zone \"0.0.127.in-addr.arpa\" in"
$_ =~ /^zone[ \t]+\"([^ \t]+)\".*/;
my $zone = $1;
!is_system_zone($zone)
} @del_zones;
y2milestone ("Deleting zones @del_zones");
foreach my $z (@del_zones) {
$z =~ /^zone[ \t]+\"([^ \t]+)\".*/;
$z = $1;
$z = "zone \"$z\" in";
SCR->Write (".dns.named.section.\"\Q$z\E\"", undef);

if (@del_zones > 0) {
y2milestone ("Deleting zones @del_zones");
foreach my $z (@del_zones) {
$z =~ /^zone[ \t]+\"([^ \t]+)\".*/;
$z = $1;
y2milestone("Deleting zone: ".$z);
$z = "zone \"$z\" in";
SCR->Write (".dns.named.section.\"\Q$z\E\"", undef);
}
}

if ($use_ldap)
Expand Down Expand Up @@ -1202,9 +1223,16 @@ sub Read {
}
\%zd;
} @zone_headers;

@zones = grep {
scalar (keys (%{$_})) > 0
} @zones;

# System zones cannot be edited in Yast
@zones = grep {
! is_system_zone($_->{"zone"})
} @zones;

$modified = 0;

Progress->NextStage ();
Expand Down Expand Up @@ -1233,6 +1261,35 @@ sub GetWhichZonesAreConnectedWith {
return \@ret;
}

# Server package should be installed already, but we have to check, e.g.,
# when applying configuration in AutoYast config module
sub check_and_install_package {
my $self = shift;
return 1 if (PackageSystem->Installed("bind"));

my $installed = 0;

# Try to install the required package
if (Mode->autoinst()) {
# Non-interactively, as we can't ask user in this case
$installed = PackageSystem->CheckAndInstallPackages(["bind"]);
} else {
# Package cannot be installed in some modes, changing the mode temporarily
my $previous_mode = Mode->mode();
Mode->SetMode("normal");
$installed = PackageSystem->CheckAndInstallPackagesInteractive(["bind"]);

# Reread the configuration stat if it has changed
$configuration_timestamp = $self->GetConfigurationStat() if $installed;
Mode->SetMode($previous_mode);
}

return 1 if $installed;

y2error("Server package cannot be installed, cannot write configuration");
return 0;
}

BEGIN { $TYPEINFO{Write} = ["function", "boolean"]; }
sub Write {
my $self = shift;
Expand Down Expand Up @@ -1281,6 +1338,8 @@ sub Write {

Progress->NextStage ();

return 0 unless $self->check_and_install_package();

my $ok = 1;

foreach my $z (@zones) {
Expand Down Expand Up @@ -1363,18 +1422,10 @@ sub Write {
#ensure that if there is an include file, named.conf.include gets recreated
$ok = $self->EnsureNamedConfIncludeIsRecreated () && $ok;

#be sure the named.conf file is saved
SCR->Write (".dns.named", undef);

#set daemon starting
SCR->Write (".sysconfig.named.NAMED_RUN_CHROOTED", $chroot ? "yes" : "no");
SCR->Write (".sysconfig.named", undef);

# SCR->Write (".sysconfig.network.config.MODIFY_NAMED_CONF_DYNAMICALLY",
# $modify_named_conf_dynamically ? "yes" : "no");
# SCR->Write (".sysconfig.network.config.MODIFY_RESOLV_CONF_DYNAMICALLY",
# $modify_resolv_conf_dynamically ? "yes" : "no");

# Store the NETCONFIG_DNS_POLICY
# Note: NETCONFIG_DNS_STATIC_SERVERS is stored in SaveGlobals();
SCR->Write (".sysconfig.network.config.NETCONFIG_DNS_POLICY", $netconfig_dns_policy);
Expand All @@ -1392,6 +1443,10 @@ sub Write {
$ok = $self->ZoneWrite ($z) && $ok;
}

# Flush the cache after writing zones, but before re/starting service
# (otherwise new zones aren't written before closing Yast)
SCR->Write (".dns.named", undef);

my $ret = 0;
if (scalar (@zones_update_actions) > 0)
{
Expand Down Expand Up @@ -1546,6 +1601,12 @@ sub Import {
$use_ldap = $settings{"use_ldap"} || 0;
@allowed_interfaces = @{$settings{"allowed_interfaces"} || []};
@zones = @{$settings{"zones"} || []};
for my $zone (@zones) {
$zone->{"modified"} = 1;
# Local zones are already part of the 'bind' package
$zone->{"is_new"} = 1 unless is_system_zone($zone->{"zone"});
y2milestone("Imported zone: ".$zone->{"zone"});
}
@options = @{$settings{"options"} || []};
@logging = @{$settings{"logging"} || []};

Expand Down
18 changes: 9 additions & 9 deletions testsuite/tests/Read.out
Expand Up @@ -6,21 +6,21 @@ Execute .dns.named_conf_convert "/etc/named.conf" 0
Execute .target.bash_output "stat --format='rights: %a, blocks: %b, size: %s, owner: %u:%g changed: %Z, modifyied: %Y' /etc/named.conf" $["exit":1, "stderr":"", "stdout":""]
Read .sysconfig.named.NAMED_RUN_CHROOTED 0
Read .sysconfig.network.config.NETCONFIG_DNS_POLICY "STATIC"
Dir .dns.named.section: ["options", "zone \"localhost\" in"]
Dir .dns.named.section: ["options", "zone \"example.org\" in"]
Dir .dns.named.value.options: ["directory", "notify"]
Read .dns.named.value.options.directory ["\"/var/lib/named\""]
Read .dns.named.value.options.notify ["no"]
Read .sysconfig.network.config.NETCONFIG_DNS_STATIC_SERVERS ""
Dir .dns.named.section: ["options", "zone \"localhost\" in"]
Dir .dns.named.section: ["options", "zone \"example.org\" in"]
Read .dns.named.value.acl []
Read .sysconfig.named.NAMED_CONF_INCLUDE_FILES 0
Read .target.ycp "/var/lib/YaST2/yast2-dns-server_reverse-zones" $[]
Read .dns.named.value."zone \"localhost\" in".type ["master"]
Read .dns.named.value."zone \"localhost\" in".file ["\"localhost.zone\""]
Read .dns.zone "/var/lib/named/localhost.zone" $["TTL":"1W", "records":[$["key":"", "type":"NS", "value":"@"], $["key":"", "type":"A", "value":"127.0.0.1"], $["key":"localhost2", "type":"A", "value":"127.0.0.2"]], "soa":$["expiry":"6W", "mail":"root", "minimum":"1W", "refresh":"2D", "retry":"4H", "serial":42, "server":"@", "zone":"@"]]
Dir .dns.named.value."zone \"localhost\" in": ["file", "type"]
Read .dns.named.value."zone \"localhost\" in"."file" ["\"localhost.zone\""]
Read .dns.named.value."zone \"localhost\" in"."type" ["master"]
Read .dns.named.value."zone \"example.org\" in".type ["master"]
Read .dns.named.value."zone \"example.org\" in".file ["\"master/example.org\""]
Read .dns.zone "/var/lib/named/master/example.org" $["TTL":"1W", "records":[$["key":"", "type":"NS", "value":"@"], $["key":"", "type":"A", "value":"10.0.0.1"], $["key":"server_name", "type":"A", "value":"10.0.0.2"]], "soa":$["expiry":"6W", "mail":"root", "minimum":"1W", "refresh":"2D", "retry":"4H", "serial":42, "server":"@", "zone":"@"]]
Dir .dns.named.value."zone \"example.org\" in": ["file", "type"]
Read .dns.named.value."zone \"example.org\" in"."file" ["\"master/example.org\""]
Read .dns.named.value."zone \"example.org\" in"."type" ["master"]
Return true
Dump =======================
Return $["allowed_interfaces":[], "chroot":"1", "logging":[], "options":[$["key":"directory", "value":"\"/var/lib/named\""], $["key":"notify", "value":"no"], $["key":"forwarders", "value":""]], "start_service":"0", "use_ldap":"0", "zones":[$["file":"localhost.zone", "options":[$["key":"file", "value":"\"localhost.zone\""], $["key":"type", "value":"master"]], "records":[$["key":"localhost.", "type":"NS", "value":"@"], $["key":"localhost.", "type":"A", "value":"127.0.0.1"], $["key":"localhost2", "type":"A", "value":"127.0.0.2"]], "soa":$["expiry":"6W", "mail":"root", "minimum":"1W", "refresh":"2D", "retry":"4H", "serial":"42", "server":"@", "zone":"@"], "this_zone_had_NS_record_at_start":"1", "ttl":"1W", "type":"master", "zone":"localhost"]]]
Return $["allowed_interfaces":[], "chroot":"1", "logging":[], "options":[$["key":"directory", "value":"\"/var/lib/named\""], $["key":"notify", "value":"no"], $["key":"forwarders", "value":""]], "start_service":"0", "use_ldap":"0", "zones":[$["file":"master/example.org", "options":[$["key":"file", "value":"\"master/example.org\""], $["key":"type", "value":"master"]], "records":[$["key":"example.org.", "type":"NS", "value":"@"], $["key":"example.org.", "type":"A", "value":"10.0.0.1"], $["key":"server_name", "type":"A", "value":"10.0.0.2"]], "soa":$["expiry":"6W", "mail":"root", "minimum":"1W", "refresh":"2D", "retry":"4H", "serial":"42", "server":"@", "zone":"@"], "this_zone_had_NS_record_at_start":"1", "ttl":"1W", "type":"master", "zone":"example.org"]]]
12 changes: 6 additions & 6 deletions testsuite/tests/Read.ycp
Expand Up @@ -149,16 +149,16 @@
"named" : $[
"section" : $[
"options" : "",
"zone \"localhost\" in" : "",
"zone \"example.org\" in" : "",
],
"value" : $[
"options" : $[
"directory" : ["\"/var/lib/named\""],
"notify" : ["no"],
],
"zone \"localhost\" in" : $[
"zone \"example.org\" in" : $[
"type" : ["master"],
"file" : ["\"localhost.zone\""],
"file" : ["\"master/example.org\""],
],
"acl" : [],
],
Expand All @@ -173,11 +173,11 @@
], $[
"key":"",
"type":"A",
"value":"127.0.0.1"
"value":"10.0.0.1"
], $[
"key" : "localhost2",
"key" : "server_name",
"type" : "A",
"value" : "127.0.0.2"
"value" : "10.0.0.2"
],
],
"soa":$[
Expand Down
9 changes: 5 additions & 4 deletions testsuite/tests/Write.out
Expand Up @@ -22,19 +22,20 @@ Write .sysconfig.named.NAMED_CONF_INCLUDE_FILES "" true
Read .sysconfig.named.NAMED_INITIALIZE_SCRIPTS 0
Write .sysconfig.named.NAMED_INITIALIZE_SCRIPTS "createNamedConfInclude" true
Write .sysconfig.named nil true
Write .dns.named nil true
Write .sysconfig.named.NAMED_RUN_CHROOTED "yes" true
Write .sysconfig.named nil true
Write .sysconfig.network.config.NETCONFIG_DNS_POLICY "0" true
Write .sysconfig.network.config.NETCONFIG_DNS_POLICY "" true
Read .sysconfig.named.NAMED_INITIALIZE_SCRIPTS 0
Write .sysconfig.named.NAMED_INITIALIZE_SCRIPTS "" true
Write .sysconfig.named nil true
Read .target.size "/var/lib/named/master/example.com" 0
Write .dns.named.value."zone \"example.com\" in".type ["master"] true
Dir .dns.named.value."zone \"example.com\" in": []
Execute .target.bash_output "/bin/hostname --fqdn" $["exit":0, "stdout":"20030806"]
Write .dns.zone ["/var/lib/named/example.com", $["TTL":"1W", "records":[$["key":"localhost", "type":"A", "value":"127.0.0.1"], $["key":"localhost", "type":"NS", "value":"127.0.0.1"], $["key":"localhost2", "type":"A", "value":"127.0.0.2"]], "soa":$["expiry":"6W", "mail":"root", "minimum":"1W", "refresh":"2D", "retry":"4H", "serial":"42", "server":"@", "zone":"@"]]] true
Write .dns.named.value."zone \"example.com\" in".file ["\"example.com\""] true
Write .dns.zone ["/var/lib/named/master/example.com", $["TTL":"1W", "records":[$["key":"localhost", "type":"A", "value":"127.0.0.1"], $["key":"localhost", "type":"NS", "value":"127.0.0.1"], $["key":"localhost2", "type":"A", "value":"127.0.0.2"]], "soa":$["expiry":"6W", "mail":"root", "minimum":"1W", "refresh":"2D", "retry":"4H", "serial":"42", "server":"@", "zone":"@"]]] true
Write .dns.named.value."zone \"example.com\" in".file ["\"master/example.com\""] true
Write .dns.named.value."zone \"example.com\" in".type ["master"] true
Write .dns.named nil true
Write .sysconfig.network.config.NETCONFIG_DNS_FORWARDER "bind" true
Write .sysconfig.network.config nil true
Execute .target.bash_output "/sbin/netconfig update" $["exit":0, "stdout":"20030806"]
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/Write.ycp
Expand Up @@ -215,7 +215,7 @@
"start_service":false,
"zones":[
$[
"file":"example.com",
"file":"master/example.com",
"records":[
$[
"key" : "localhost",
Expand Down
18 changes: 9 additions & 9 deletions testsuite/tests/YaPIReadZones.out
Expand Up @@ -6,20 +6,20 @@ Execute .dns.named_conf_convert "/etc/named.conf" 0
Execute .target.bash_output "stat --format='rights: %a, blocks: %b, size: %s, owner: %u:%g changed: %Z, modifyied: %Y' /etc/named.conf" $["exit":1, "stderr":"", "stdout":""]
Read .sysconfig.named.NAMED_RUN_CHROOTED nil
Read .sysconfig.network.config.NETCONFIG_DNS_POLICY "auto"
Dir .dns.named.section: ["options", "zone \"localhost\" in"]
Dir .dns.named.section: ["options", "zone \"example.org\" in"]
Dir .dns.named.value.options: ["directory", "notify"]
Read .dns.named.value.options.directory ["\"/var/lib/named\""]
Read .dns.named.value.options.notify ["no"]
Read .sysconfig.network.config.NETCONFIG_DNS_STATIC_SERVERS ""
Dir .dns.named.section: ["options", "zone \"localhost\" in"]
Dir .dns.named.section: ["options", "zone \"example.org\" in"]
Read .dns.named.value.acl []
Read .sysconfig.named.NAMED_CONF_INCLUDE_FILES nil
Read .target.ycp "/var/lib/YaST2/yast2-dns-server_reverse-zones" $[]
Read .dns.named.value."zone \"localhost\" in".type ["master"]
Read .dns.named.value."zone \"localhost\" in".file ["\"localhost.zone\""]
Read .dns.zone "/var/lib/named/localhost.zone" $["TTL":"1W", "records":[$["key":"", "type":"NS", "value":"@"], $["key":"", "type":"A", "value":"127.0.0.1"], $["key":"localhost2", "type":"A", "value":"127.0.0.2"]], "soa":$["expiry":"6W", "mail":"root", "minimum":"1W", "refresh":"2D", "retry":"4H", "serial":42, "server":"@", "zone":"@"]]
Dir .dns.named.value."zone \"localhost\" in": ["file", "type"]
Read .dns.named.value."zone \"localhost\" in"."file" ["\"localhost.zone\""]
Read .dns.named.value."zone \"localhost\" in"."type" ["master"]
Return [$["file":"localhost.zone", "options":[$["key":"file", "value":"\"localhost.zone\""], $["key":"type", "value":"master"]], "records":[$["key":"localhost.", "type":"NS", "value":"@"], $["key":"localhost.", "type":"A", "value":"127.0.0.1"], $["key":"localhost2", "type":"A", "value":"127.0.0.2"]], "soa":$["expiry":"6W", "mail":"root", "minimum":"1W", "refresh":"2D", "retry":"4H", "serial":"42", "server":"@", "zone":"@"], "this_zone_had_NS_record_at_start":"1", "ttl":"1W", "type":"master", "zone":"localhost"]]
Read .dns.named.value."zone \"example.org\" in".type ["master"]
Read .dns.named.value."zone \"example.org\" in".file ["\"/master/example.org\""]
Read .dns.zone "/var/lib/named//master/example.org" $["TTL":"1W", "records":[$["key":"", "type":"NS", "value":"@"], $["key":"", "type":"A", "value":"10.0.0.1"], $["key":"server2", "type":"A", "value":"10.0.0.2"]], "soa":$["expiry":"6W", "mail":"root", "minimum":"1W", "refresh":"2D", "retry":"4H", "serial":42, "server":"@", "zone":"@"]]
Dir .dns.named.value."zone \"example.org\" in": ["file", "type"]
Read .dns.named.value."zone \"example.org\" in"."file" ["\"/master/example.org\""]
Read .dns.named.value."zone \"example.org\" in"."type" ["master"]
Return [$["file":"/master/example.org", "options":[$["key":"file", "value":"\"/master/example.org\""], $["key":"type", "value":"master"]], "records":[$["key":"example.org.", "type":"NS", "value":"@"], $["key":"example.org.", "type":"A", "value":"10.0.0.1"], $["key":"server2", "type":"A", "value":"10.0.0.2"]], "soa":$["expiry":"6W", "mail":"root", "minimum":"1W", "refresh":"2D", "retry":"4H", "serial":"42", "server":"@", "zone":"@"], "this_zone_had_NS_record_at_start":"1", "ttl":"1W", "type":"master", "zone":"example.org"]]
Dump ==========================================================
12 changes: 6 additions & 6 deletions testsuite/tests/YaPIReadZones.ycp
Expand Up @@ -133,16 +133,16 @@
"named" : $[
"section" : $[
"options" : "",
"zone \"localhost\" in" : "",
"zone \"example.org\" in" : "",
],
"value" : $[
"options" : $[
"directory" : ["\"/var/lib/named\""],
"notify" : ["no"],
],
"zone \"localhost\" in" : $[
"zone \"example.org\" in" : $[
"type" : ["master"],
"file" : ["\"localhost.zone\""],
"file" : ["\"/master/example.org\""],
],
"acl" : [],
],
Expand All @@ -157,11 +157,11 @@
], $[
"key":"",
"type":"A",
"value":"127.0.0.1"
"value":"10.0.0.1"
], $[
"key" : "localhost2",
"key" : "server2",
"type" : "A",
"value" : "127.0.0.2"
"value" : "10.0.0.2"
],
],
"soa":$[
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/YaPIWriteGlobalOptions.out
Expand Up @@ -41,13 +41,13 @@ Write .sysconfig.named.NAMED_CONF_INCLUDE_FILES "" true
Read .sysconfig.named.NAMED_INITIALIZE_SCRIPTS nil
Write .sysconfig.named.NAMED_INITIALIZE_SCRIPTS "createNamedConfInclude" true
Write .sysconfig.named nil true
Write .dns.named nil true
Write .sysconfig.named.NAMED_RUN_CHROOTED "yes" true
Write .sysconfig.named nil true
Write .sysconfig.network.config.NETCONFIG_DNS_POLICY "auto" true
Read .sysconfig.named.NAMED_INITIALIZE_SCRIPTS nil
Write .sysconfig.named.NAMED_INITIALIZE_SCRIPTS "" true
Write .sysconfig.named nil true
Write .dns.named nil true
Write .sysconfig.network.config.NETCONFIG_DNS_FORWARDER "bind" true
Write .sysconfig.network.config nil true
Execute .target.bash_output "/sbin/netconfig update" $["exit":1, "stderr":"", "stdout":""]
Expand Down

0 comments on commit 3ee5384

Please sign in to comment.