From 0cef5021f5bc1ca6b67acf369bed9b61760a7360 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Fri, 17 Nov 2017 18:54:11 +0530 Subject: [PATCH] DnsWebService: Save zone file code updated to allow storing all records for a given authoritative zone in a single file instead of different file for each sub domain. Implemented delete zone file feature accordingly. --- DnsServerCore/DnsWebService.cs | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/DnsServerCore/DnsWebService.cs b/DnsServerCore/DnsWebService.cs index 5a85d28b..52ea5b74 100644 --- a/DnsServerCore/DnsWebService.cs +++ b/DnsServerCore/DnsWebService.cs @@ -691,10 +691,8 @@ namespace DnsServerCore if (string.IsNullOrEmpty(domain)) throw new DnsWebServiceException("Parameter 'domain' missing."); - string[] deletedZones = _dnsServer.AuthoritativeZoneRoot.DeleteZone(domain); - - foreach (string deletedZone in deletedZones) - DeleteZoneFile(deletedZone); + _dnsServer.AuthoritativeZoneRoot.DeleteZone(domain); + DeleteZoneFile(domain); } private void EnableZone(HttpListenerRequest request) @@ -1311,26 +1309,22 @@ namespace DnsServerCore private void SaveZoneFile(string domain) { domain = domain.ToLower(); - DnsResourceRecord[] records = _dnsServer.AuthoritativeZoneRoot.GetAllRecords(domain, false); + DnsResourceRecord[] records = _dnsServer.AuthoritativeZoneRoot.GetAllRecords(domain, true, true); - if ((records == null) || (records.Length == 0)) - { - DeleteZoneFile(domain); - } - else - { - using (FileStream fS = new FileStream(Path.Combine(_configFolder, domain + ".zone"), FileMode.Create, FileAccess.Write)) - { - BincodingEncoder encoder = new BincodingEncoder(fS, "DZ", 1); + string authZone = records[0].Name.ToLower(); - encoder.Encode(records); - } + using (FileStream fS = new FileStream(Path.Combine(_configFolder, authZone + ".zone"), FileMode.Create, FileAccess.Write)) + { + BincodingEncoder encoder = new BincodingEncoder(fS, "DZ", 1); + + encoder.Encode(records); } } private void DeleteZoneFile(string domain) { domain = domain.ToLower(); + File.Delete(Path.Combine(_configFolder, domain + ".zone")); }