AuthZoneManager: updated GetAuthZoneInfo() to check for null. Added NameExists(), GetAllRecords() and SetRecords().

This commit is contained in:
Shreyas Zare
2022-10-05 19:07:10 +05:30
parent 2848246a86
commit c514cc55ec

View File

@@ -940,7 +940,7 @@ namespace DnsServerCore.Dns.ZoneManagers
public AuthZoneInfo GetAuthZoneInfo(string zoneName, bool loadHistory = false)
{
if (_root.TryGet(zoneName, out AuthZoneNode authZoneNode))
if (_root.TryGet(zoneName, out AuthZoneNode authZoneNode) && (authZoneNode.ApexZone is not null))
return new AuthZoneInfo(authZoneNode.ApexZone, loadHistory);
return null;
@@ -955,6 +955,13 @@ namespace DnsServerCore.Dns.ZoneManagers
return new AuthZoneInfo(apexZone, loadHistory);
}
public bool NameExists(string zoneName, string domain)
{
ValidateZoneNameFor(zoneName, domain);
return _root.TryGet(zoneName, domain, out _);
}
public void ListAllRecords(string zoneName, List<DnsResourceRecord> records)
{
foreach (AuthZone zone in _root.GetZoneWithSubDomainZones(zoneName))
@@ -971,6 +978,16 @@ namespace DnsServerCore.Dns.ZoneManagers
return Array.Empty<DnsResourceRecord>();
}
public IReadOnlyDictionary<DnsResourceRecordType, IReadOnlyList<DnsResourceRecord>> GetAllRecords(string zoneName, string domain)
{
ValidateZoneNameFor(zoneName, domain);
if (_root.TryGet(zoneName, domain, out AuthZone authZone))
return authZone.GetAllRecords();
return new Dictionary<DnsResourceRecordType, IReadOnlyList<DnsResourceRecord>>(1);
}
public IReadOnlyList<DnsResourceRecord> QueryZoneTransferRecords(string zoneName)
{
AuthZoneInfo authZone = GetAuthZoneInfo(zoneName, false);
@@ -1480,6 +1497,28 @@ namespace DnsServerCore.Dns.ZoneManagers
subDomainZone.AutoUpdateState();
}
public void SetRecords(string zoneName, IReadOnlyList<DnsResourceRecord> records)
{
for (int i = 1; i < records.Count; i++)
{
if (!records[i].Name.Equals(records[0].Name, StringComparison.OrdinalIgnoreCase))
throw new InvalidOperationException();
if (records[i].Type != records[0].Type)
throw new InvalidOperationException();
if (records[i].Class != records[0].Class)
throw new InvalidOperationException();
}
AuthZone authZone = GetOrAddSubDomainZone(zoneName, records[0].Name);
authZone.SetRecords(records[0].Type, records);
if (authZone is SubDomainZone subDomainZone)
subDomainZone.AutoUpdateState();
}
public void SetRecord(string zoneName, DnsResourceRecord record)
{
ValidateZoneNameFor(zoneName, record.Name);