From 580413f044f429df1c06a4e941b5ff952ee9c57f Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sun, 27 Jan 2019 19:15:50 +0530 Subject: [PATCH] added validation checks for api calls. --- DnsServerCore/DnsWebService.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/DnsServerCore/DnsWebService.cs b/DnsServerCore/DnsWebService.cs index 95be0ad1..22dafb41 100644 --- a/DnsServerCore/DnsWebService.cs +++ b/DnsServerCore/DnsWebService.cs @@ -1807,7 +1807,8 @@ namespace DnsServerCore if (string.IsNullOrEmpty(domain)) throw new DnsWebServiceException("Parameter 'domain' missing."); - _dnsServer.AuthoritativeZoneRoot.DeleteZone(domain, false); + if (!_dnsServer.AuthoritativeZoneRoot.DeleteZone(domain, false)) + throw new DnsWebServiceException("Zone '" + domain + "' was not found."); _log.Write(GetRequestRemoteEndPoint(request), true, "[" + GetSession(request).Username + "] Authoritative zone was deleted: " + domain); @@ -1820,6 +1821,9 @@ namespace DnsServerCore if (string.IsNullOrEmpty(domain)) throw new DnsWebServiceException("Parameter 'domain' missing."); + if (!_dnsServer.AuthoritativeZoneRoot.DeleteZone(domain, false)) + throw new DnsWebServiceException("Zone '" + domain + "' was not found."); + _dnsServer.AuthoritativeZoneRoot.EnableZone(domain); _log.Write(GetRequestRemoteEndPoint(request), true, "[" + GetSession(request).Username + "] Authoritative zone was enabled: " + domain); @@ -1833,6 +1837,9 @@ namespace DnsServerCore if (string.IsNullOrEmpty(domain)) throw new DnsWebServiceException("Parameter 'domain' missing."); + if (!_dnsServer.AuthoritativeZoneRoot.DeleteZone(domain, false)) + throw new DnsWebServiceException("Zone '" + domain + "' was not found."); + _dnsServer.AuthoritativeZoneRoot.DisableZone(domain); _log.Write(GetRequestRemoteEndPoint(request), true, "[" + GetSession(request).Username + "] Authoritative zone was disabled: " + domain); @@ -1933,6 +1940,8 @@ namespace DnsServerCore throw new DnsWebServiceException("Parameter 'domain' missing."); DnsResourceRecord[] records = _dnsServer.AuthoritativeZoneRoot.GetAllRecords(domain); + if (records.Length == 0) + throw new DnsWebServiceException("Zone '" + domain + "' was not found."); WriteRecordsAsJson(records, jsonWriter, true); } @@ -2151,6 +2160,9 @@ namespace DnsServerCore if (string.IsNullOrEmpty(value)) throw new DnsWebServiceException("Parameter 'value' missing."); + if (!_dnsServer.AuthoritativeZoneRoot.ZoneExists(domain)) + throw new DnsWebServiceException("Zone '" + domain + "' was not found."); + switch (type) { case DnsResourceRecordType.A: @@ -2654,6 +2666,8 @@ namespace DnsServerCore { domain = domain.ToLower(); DnsResourceRecord[] records = _dnsServer.AuthoritativeZoneRoot.GetAllRecords(domain, DnsResourceRecordType.ANY, true, true); + if (records.Length == 0) + throw new DnsWebServiceException("Zone '" + domain + "' was not found."); string authZone = records[0].Name.ToLower();