Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/SLE-12-GA' into fix_import_ope…
Browse files Browse the repository at this point in the history
…nSUSE-13_2
  • Loading branch information
kobliha committed Dec 10, 2014
2 parents 9c43e74 + 6661d67 commit b3c7c38
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 59 deletions.
21 changes: 21 additions & 0 deletions package/yast2-dns-server.changes
@@ -1,3 +1,24 @@
-------------------------------------------------------------------
Tue Dec 9 16:35:24 CET 2014 - locilka@suse.com

- Fixed handling of zones (bnc#898659)
- 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)
- 3.1.7.2

-------------------------------------------------------------------
Fri Dec 5 16:44:27 CET 2014 - locilka@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-dns-server.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-dns-server
Version: 3.1.7.1
Version: 3.1.7.2
Release: 0
Url: https://github.com/yast/yast-dns-server

Expand Down
105 changes: 82 additions & 23 deletions src/modules/DnsServer.pm
Expand Up @@ -72,7 +72,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 @@ -111,6 +111,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 @@ -126,9 +141,10 @@ sub ZoneWrite {
return 0;
}

if ($zone_name eq "localhost" || $zone_name eq "0.0.127.in-addr.arpa" || $zone_name =~ /^(0\.)+ip6.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 @@ -390,16 +406,23 @@ sub SaveGlobals {
my @del_zones = grep {
! $self->contains (\@current_zones, $_);
} @old_zones;

# Do not remove system 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 @@ -1190,9 +1213,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 @@ -1266,6 +1296,35 @@ sub update_forwarding {
$self->write_local_forwarder();
}

# 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 @@ -1312,6 +1371,8 @@ sub Write {

Progress->NextStage ();

return 0 unless $self->check_and_install_package();

my $ok = 1;

foreach my $z (@zones) {
Expand Down Expand Up @@ -1397,18 +1458,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 @@ -1426,6 +1479,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 = 1;
if (scalar (@zones_update_actions) > 0)
{
Expand Down Expand Up @@ -1478,7 +1535,7 @@ sub Write {
if (! $success)
{
# Cannot start service 'named', because of error that follows Error:. Do not translate named.
Report->Error (__("Error occurred while starting service named.\n\n".Service->FullInfo("named")));
Report->Error (__("Error occurred while starting service named.\n\n"));
$ok = 0;
# There's no 'named' running -> prevent from blocking DNS queries
$self->SetLocalForwarder("resolver") if GetLocalForwarder() eq "bind";
Expand Down Expand Up @@ -1564,9 +1621,11 @@ sub Import {
@allowed_interfaces = @{$settings{"allowed_interfaces"} || []};

@zones = @{$settings{"zones"} || []};
for my $i (0..@zones-1) {
$zones[$i]{"modified"} = 1;
y2milestone("Imported zone: ".$zones[$i]{"zone"});
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"} || []};
Expand Down
18 changes: 9 additions & 9 deletions testsuite/tests/Read.out
Expand Up @@ -4,21 +4,21 @@ Execute .target.bash_output "stat --format='rights: %a, blocks: %b, size: %s, ow
Read .sysconfig.named.NAMED_RUN_CHROOTED 0
Read .sysconfig.network.config.NETCONFIG_DNS_POLICY "STATIC"
Read .sysconfig.network.config.NETCONFIG_DNS_FORWARDER 0
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"]]]
10 changes: 5 additions & 5 deletions testsuite/tests/Read.rb
Expand Up @@ -178,15 +178,15 @@ def main
},
"dns" => {
"named" => {
"section" => { "options" => "", "zone \"localhost\" in" => "" },
"section" => { "options" => "", "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 @@ -195,8 +195,8 @@ def main
"TTL" => "1W",
"records" => [
{ "key" => "", "type" => "NS", "value" => "@" },
{ "key" => "", "type" => "A", "value" => "127.0.0.1" },
{ "key" => "localhost2", "type" => "A", "value" => "127.0.0.2" }
{ "key" => "", "type" => "A", "value" => "10.0.0.1" },
{ "key" => "server_name", "type" => "A", "value" => "10.0.0.2" }
],
"soa" => {
"expiry" => "6W",
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, "stderr":"", "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 -m dns" $["exit":0, "stderr":"", "stdout":"20030806"]
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/Write.rb
Expand Up @@ -278,7 +278,7 @@ def main
"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 @@ -4,20 +4,20 @@ Execute .target.bash_output "stat --format='rights: %a, blocks: %b, size: %s, ow
Read .sysconfig.named.NAMED_RUN_CHROOTED nil
Read .sysconfig.network.config.NETCONFIG_DNS_POLICY "auto"
Read .sysconfig.network.config.NETCONFIG_DNS_FORWARDER "resolver"
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 ==========================================================
10 changes: 5 additions & 5 deletions testsuite/tests/YaPIReadZones.rb
Expand Up @@ -166,15 +166,15 @@ def main
},
"dns" => {
"named" => {
"section" => { "options" => "", "zone \"localhost\" in" => "" },
"section" => { "options" => "", "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 @@ -183,8 +183,8 @@ def main
"TTL" => "1W",
"records" => [
{ "key" => "", "type" => "NS", "value" => "@" },
{ "key" => "", "type" => "A", "value" => "127.0.0.1" },
{ "key" => "localhost2", "type" => "A", "value" => "127.0.0.2" }
{ "key" => "", "type" => "A", "value" => "10.0.0.1" },
{ "key" => "server2", "type" => "A", "value" => "10.0.0.2" }
],
"soa" => {
"expiry" => "6W",
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/YaPIWriteGlobalOptions.out
Expand Up @@ -40,13 +40,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 -m dns" $["exit":1, "stderr":"", "stdout":""]
Expand Down

0 comments on commit b3c7c38

Please sign in to comment.