1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174 |
- /*
- Technitium DNS Server
- Copyright (C) 2024 Shreyas Zare (shreyas@technitium.com)
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- using DnsServerCore.Dns.Dnssec;
- using DnsServerCore.Dns.ResourceRecords;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Net;
- using System.Net.Sockets;
- using System.Threading.Tasks;
- using TechnitiumLibrary.IO;
- using TechnitiumLibrary.Net;
- using TechnitiumLibrary.Net.Dns;
- using TechnitiumLibrary.Net.Dns.ResourceRecords;
- namespace DnsServerCore.Dns.Zones
- {
- public enum AuthZoneType : byte
- {
- Unknown = 0,
- Primary = 1,
- Secondary = 2,
- Stub = 3,
- Forwarder = 4
- }
- public sealed class AuthZoneInfo : IComparable<AuthZoneInfo>
- {
- #region variables
- readonly ApexZone _apexZone;
- readonly string _name;
- readonly AuthZoneType _type;
- readonly bool _disabled;
- readonly AuthZoneTransfer _zoneTransfer;
- readonly IReadOnlyCollection<NetworkAddress> _zoneTransferNameServers;
- readonly AuthZoneNotify _notify;
- readonly IReadOnlyCollection<IPAddress> _notifyNameServers;
- readonly AuthZoneUpdate _update;
- readonly IReadOnlyCollection<NetworkAddress> _updateIpAddresses;
- readonly DateTime _lastModified;
- readonly DateTime _expiry;
- readonly IReadOnlyList<DnsResourceRecord> _zoneHistory; //for IXFR support
- readonly IReadOnlyDictionary<string, object> _zoneTransferTsigKeyNames;
- readonly IReadOnlyDictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>> _updateSecurityPolicies;
- readonly IReadOnlyCollection<DnssecPrivateKey> _dnssecPrivateKeys;
- #endregion
- #region constructor
- public AuthZoneInfo(string name, AuthZoneType type, bool disabled)
- {
- _name = name;
- _type = type;
- _disabled = disabled;
- switch (_type)
- {
- case AuthZoneType.Primary:
- _zoneTransfer = AuthZoneTransfer.AllowOnlyZoneNameServers;
- _notify = AuthZoneNotify.ZoneNameServers;
- _update = AuthZoneUpdate.Deny;
- break;
- default:
- _zoneTransfer = AuthZoneTransfer.Deny;
- _notify = AuthZoneNotify.None;
- _update = AuthZoneUpdate.Deny;
- break;
- }
- }
- public AuthZoneInfo(BinaryReader bR, DateTime lastModified)
- {
- byte version = bR.ReadByte();
- switch (version)
- {
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- case 8:
- case 9:
- case 10:
- case 11:
- _name = bR.ReadShortString();
- _type = (AuthZoneType)bR.ReadByte();
- _disabled = bR.ReadBoolean();
- if (version >= 2)
- {
- {
- _zoneTransfer = (AuthZoneTransfer)bR.ReadByte();
- int count = bR.ReadByte();
- if (count > 0)
- {
- NetworkAddress[] networks = new NetworkAddress[count];
- if (version >= 9)
- {
- for (int i = 0; i < count; i++)
- networks[i] = NetworkAddress.ReadFrom(bR);
- }
- else
- {
- for (int i = 0; i < count; i++)
- {
- IPAddress address = IPAddressExtensions.ReadFrom(bR);
- switch (address.AddressFamily)
- {
- case AddressFamily.InterNetwork:
- networks[i] = new NetworkAddress(address, 32);
- break;
- case AddressFamily.InterNetworkV6:
- networks[i] = new NetworkAddress(address, 128);
- break;
- default:
- throw new InvalidOperationException();
- }
- }
- }
- _zoneTransferNameServers = networks;
- }
- }
- {
- _notify = (AuthZoneNotify)bR.ReadByte();
- int count = bR.ReadByte();
- if (count > 0)
- {
- IPAddress[] nameServers = new IPAddress[count];
- for (int i = 0; i < count; i++)
- nameServers[i] = IPAddressExtensions.ReadFrom(bR);
- _notifyNameServers = nameServers;
- }
- }
- if (version >= 6)
- {
- _update = (AuthZoneUpdate)bR.ReadByte();
- int count = bR.ReadByte();
- if (count > 0)
- {
- NetworkAddress[] networks = new NetworkAddress[count];
- if (version >= 9)
- {
- for (int i = 0; i < count; i++)
- networks[i] = NetworkAddress.ReadFrom(bR);
- }
- else
- {
- for (int i = 0; i < count; i++)
- {
- IPAddress address = IPAddressExtensions.ReadFrom(bR);
- switch (address.AddressFamily)
- {
- case AddressFamily.InterNetwork:
- networks[i] = new NetworkAddress(address, 32);
- break;
- case AddressFamily.InterNetworkV6:
- networks[i] = new NetworkAddress(address, 128);
- break;
- default:
- throw new InvalidOperationException();
- }
- }
- }
- _updateIpAddresses = networks;
- }
- }
- }
- else
- {
- switch (_type)
- {
- case AuthZoneType.Primary:
- _zoneTransfer = AuthZoneTransfer.AllowOnlyZoneNameServers;
- _notify = AuthZoneNotify.ZoneNameServers;
- _update = AuthZoneUpdate.Deny;
- break;
- default:
- _zoneTransfer = AuthZoneTransfer.Deny;
- _notify = AuthZoneNotify.None;
- _update = AuthZoneUpdate.Deny;
- break;
- }
- }
- if (version >= 8)
- _lastModified = bR.ReadDateTime();
- else
- _lastModified = lastModified;
- switch (_type)
- {
- case AuthZoneType.Primary:
- if (version >= 3)
- {
- int count = bR.ReadInt32();
- DnsResourceRecord[] zoneHistory = new DnsResourceRecord[count];
- if (version >= 11)
- {
- for (int i = 0; i < count; i++)
- {
- zoneHistory[i] = new DnsResourceRecord(bR.BaseStream);
- if (bR.ReadBoolean())
- zoneHistory[i].Tag = new HistoryRecordInfo(bR);
- }
- }
- else
- {
- for (int i = 0; i < count; i++)
- {
- zoneHistory[i] = new DnsResourceRecord(bR.BaseStream);
- zoneHistory[i].Tag = new HistoryRecordInfo(bR);
- }
- }
- _zoneHistory = zoneHistory;
- }
- if (version >= 4)
- {
- int count = bR.ReadByte();
- Dictionary<string, object> tsigKeyNames = new Dictionary<string, object>(count);
- for (int i = 0; i < count; i++)
- tsigKeyNames.Add(bR.ReadShortString(), null);
- _zoneTransferTsigKeyNames = tsigKeyNames;
- }
- if (version >= 7)
- {
- int count = bR.ReadByte();
- Dictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>> updateSecurityPolicies = new Dictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>>(count);
- for (int i = 0; i < count; i++)
- {
- string tsigKeyName = bR.ReadShortString().ToLower();
- if (!updateSecurityPolicies.TryGetValue(tsigKeyName, out IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>> policyMap))
- {
- policyMap = new Dictionary<string, IReadOnlyList<DnsResourceRecordType>>();
- updateSecurityPolicies.Add(tsigKeyName, policyMap);
- }
- int policyCount = bR.ReadByte();
- for (int j = 0; j < policyCount; j++)
- {
- string domain = bR.ReadShortString().ToLower();
- if (!policyMap.TryGetValue(domain, out IReadOnlyList<DnsResourceRecordType> types))
- {
- types = new List<DnsResourceRecordType>();
- (policyMap as Dictionary<string, IReadOnlyList<DnsResourceRecordType>>).Add(domain, types);
- }
- int typeCount = bR.ReadByte();
- for (int k = 0; k < typeCount; k++)
- (types as List<DnsResourceRecordType>).Add((DnsResourceRecordType)bR.ReadUInt16());
- }
- }
- _updateSecurityPolicies = updateSecurityPolicies;
- }
- else if (version >= 6)
- {
- int count = bR.ReadByte();
- Dictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>> updateSecurityPolicies = new Dictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>>(count);
- Dictionary<string, IReadOnlyList<DnsResourceRecordType>> defaultAllowPolicy = new Dictionary<string, IReadOnlyList<DnsResourceRecordType>>(1);
- defaultAllowPolicy.Add(_name, new List<DnsResourceRecordType>() { DnsResourceRecordType.ANY });
- defaultAllowPolicy.Add("*." + _name, new List<DnsResourceRecordType>() { DnsResourceRecordType.ANY });
- for (int i = 0; i < count; i++)
- updateSecurityPolicies.Add(bR.ReadShortString().ToLower(), defaultAllowPolicy);
- _updateSecurityPolicies = updateSecurityPolicies;
- }
- if (version >= 5)
- {
- int count = bR.ReadByte();
- if (count > 0)
- {
- List<DnssecPrivateKey> dnssecPrivateKeys = new List<DnssecPrivateKey>(count);
- for (int i = 0; i < count; i++)
- dnssecPrivateKeys.Add(DnssecPrivateKey.ReadFrom(bR));
- _dnssecPrivateKeys = dnssecPrivateKeys;
- }
- }
- break;
- case AuthZoneType.Secondary:
- _expiry = bR.ReadDateTime();
- if (version >= 4)
- {
- int count = bR.ReadInt32();
- DnsResourceRecord[] zoneHistory = new DnsResourceRecord[count];
- if (version >= 11)
- {
- for (int i = 0; i < count; i++)
- {
- zoneHistory[i] = new DnsResourceRecord(bR.BaseStream);
- if (bR.ReadBoolean())
- zoneHistory[i].Tag = new HistoryRecordInfo(bR);
- }
- }
- else
- {
- for (int i = 0; i < count; i++)
- {
- zoneHistory[i] = new DnsResourceRecord(bR.BaseStream);
- zoneHistory[i].Tag = new HistoryRecordInfo(bR);
- }
- }
- _zoneHistory = zoneHistory;
- }
- if (version >= 4)
- {
- int count = bR.ReadByte();
- Dictionary<string, object> tsigKeyNames = new Dictionary<string, object>(count);
- for (int i = 0; i < count; i++)
- tsigKeyNames.Add(bR.ReadShortString(), null);
- _zoneTransferTsigKeyNames = tsigKeyNames;
- }
- if (version == 6)
- {
- //MUST skip old version data
- int count = bR.ReadByte();
- Dictionary<string, object> tsigKeyNames = new Dictionary<string, object>(count);
- for (int i = 0; i < count; i++)
- tsigKeyNames.Add(bR.ReadShortString(), null);
- }
- break;
- case AuthZoneType.Stub:
- _expiry = bR.ReadDateTime();
- break;
- case AuthZoneType.Forwarder:
- if (version >= 10)
- {
- int count = bR.ReadByte();
- Dictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>> updateSecurityPolicies = new Dictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>>(count);
- for (int i = 0; i < count; i++)
- {
- string tsigKeyName = bR.ReadShortString().ToLower();
- if (!updateSecurityPolicies.TryGetValue(tsigKeyName, out IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>> policyMap))
- {
- policyMap = new Dictionary<string, IReadOnlyList<DnsResourceRecordType>>();
- updateSecurityPolicies.Add(tsigKeyName, policyMap);
- }
- int policyCount = bR.ReadByte();
- for (int j = 0; j < policyCount; j++)
- {
- string domain = bR.ReadShortString().ToLower();
- if (!policyMap.TryGetValue(domain, out IReadOnlyList<DnsResourceRecordType> types))
- {
- types = new List<DnsResourceRecordType>();
- (policyMap as Dictionary<string, IReadOnlyList<DnsResourceRecordType>>).Add(domain, types);
- }
- int typeCount = bR.ReadByte();
- for (int k = 0; k < typeCount; k++)
- (types as List<DnsResourceRecordType>).Add((DnsResourceRecordType)bR.ReadUInt16());
- }
- }
- _updateSecurityPolicies = updateSecurityPolicies;
- }
- break;
- }
- break;
- default:
- throw new InvalidDataException("AuthZoneInfo format version not supported.");
- }
- }
- internal AuthZoneInfo(ApexZone apexZone, bool loadHistory = false)
- {
- _apexZone = apexZone;
- _name = _apexZone.Name;
- if (_apexZone is PrimaryZone primaryZone)
- {
- _type = AuthZoneType.Primary;
- if (loadHistory)
- _zoneHistory = primaryZone.GetZoneHistory();
- _zoneTransferTsigKeyNames = primaryZone.ZoneTransferTsigKeyNames;
- _updateSecurityPolicies = primaryZone.UpdateSecurityPolicies;
- _dnssecPrivateKeys = primaryZone.DnssecPrivateKeys;
- }
- else if (_apexZone is SecondaryZone secondaryZone)
- {
- _type = AuthZoneType.Secondary;
- if (loadHistory)
- _zoneHistory = secondaryZone.GetZoneHistory();
- _expiry = secondaryZone.Expiry;
- _zoneTransferTsigKeyNames = secondaryZone.ZoneTransferTsigKeyNames;
- }
- else if (_apexZone is StubZone stubZone)
- {
- _type = AuthZoneType.Stub;
- _expiry = stubZone.Expiry;
- }
- else if (_apexZone is ForwarderZone forwarderZone)
- {
- _type = AuthZoneType.Forwarder;
- _updateSecurityPolicies = forwarderZone.UpdateSecurityPolicies;
- }
- else
- {
- _type = AuthZoneType.Unknown;
- }
- _disabled = _apexZone.Disabled;
- _zoneTransfer = _apexZone.ZoneTransfer;
- _zoneTransferNameServers = _apexZone.ZoneTransferNameServers;
- _notify = _apexZone.Notify;
- _notifyNameServers = _apexZone.NotifyNameServers;
- _update = _apexZone.Update;
- _updateIpAddresses = _apexZone.UpdateIpAddresses;
- _lastModified = _apexZone.LastModified;
- }
- #endregion
- #region public
- public IReadOnlyList<DnsResourceRecord> GetApexRecords(DnsResourceRecordType type)
- {
- if (_apexZone is null)
- throw new InvalidOperationException();
- return _apexZone.GetRecords(type);
- }
- public void TriggerNotify()
- {
- if (_apexZone is null)
- throw new InvalidOperationException();
- switch (_type)
- {
- case AuthZoneType.Primary:
- (_apexZone as PrimaryZone).TriggerNotify();
- break;
- case AuthZoneType.Secondary:
- (_apexZone as SecondaryZone).TriggerNotify();
- break;
- default:
- throw new InvalidOperationException();
- }
- }
- public void TriggerRefresh()
- {
- if (_apexZone is null)
- throw new InvalidOperationException();
- switch (_type)
- {
- case AuthZoneType.Secondary:
- (_apexZone as SecondaryZone).TriggerRefresh();
- break;
- case AuthZoneType.Stub:
- (_apexZone as StubZone).TriggerRefresh();
- break;
- default:
- throw new InvalidOperationException();
- }
- }
- public void TriggerResync()
- {
- if (_apexZone is null)
- throw new InvalidOperationException();
- switch (_type)
- {
- case AuthZoneType.Secondary:
- (_apexZone as SecondaryZone).TriggerResync();
- break;
- case AuthZoneType.Stub:
- (_apexZone as StubZone).TriggerResync();
- break;
- default:
- throw new InvalidOperationException();
- }
- }
- public Task<IReadOnlyList<NameServerAddress>> GetPrimaryNameServerAddressesAsync(DnsServer dnsServer)
- {
- if (_apexZone is null)
- throw new InvalidOperationException();
- return _apexZone.GetPrimaryNameServerAddressesAsync(dnsServer);
- }
- public Task<IReadOnlyList<NameServerAddress>> GetSecondaryNameServerAddressesAsync(DnsServer dnsServer)
- {
- if (_apexZone is null)
- throw new InvalidOperationException();
- return _apexZone.GetSecondaryNameServerAddressesAsync(dnsServer);
- }
- public void WriteTo(BinaryWriter bW)
- {
- if (_apexZone is null)
- throw new InvalidOperationException();
- bW.Write((byte)11); //version
- bW.WriteShortString(_name);
- bW.Write((byte)_type);
- bW.Write(_disabled);
- bW.Write((byte)_zoneTransfer);
- if (_zoneTransferNameServers is null)
- {
- bW.Write((byte)0);
- }
- else
- {
- bW.Write(Convert.ToByte(_zoneTransferNameServers.Count));
- foreach (NetworkAddress networkAddress in _zoneTransferNameServers)
- networkAddress.WriteTo(bW);
- }
- bW.Write((byte)_notify);
- if (_notifyNameServers is null)
- {
- bW.Write((byte)0);
- }
- else
- {
- bW.Write(Convert.ToByte(_notifyNameServers.Count));
- foreach (IPAddress nameServer in _notifyNameServers)
- nameServer.WriteTo(bW);
- }
- bW.Write((byte)_update);
- if (_updateIpAddresses is null)
- {
- bW.Write((byte)0);
- }
- else
- {
- bW.Write(Convert.ToByte(_updateIpAddresses.Count));
- foreach (NetworkAddress networkAddress in _updateIpAddresses)
- networkAddress.WriteTo(bW);
- }
- bW.Write(_lastModified);
- switch (_type)
- {
- case AuthZoneType.Primary:
- if (_zoneHistory is null)
- {
- bW.Write(0);
- }
- else
- {
- bW.Write(_zoneHistory.Count);
- foreach (DnsResourceRecord record in _zoneHistory)
- {
- record.WriteTo(bW.BaseStream);
- if (record.Tag is HistoryRecordInfo rrInfo)
- {
- bW.Write(true);
- rrInfo.WriteTo(bW);
- }
- else
- {
- bW.Write(false);
- }
- }
- }
- if (_zoneTransferTsigKeyNames is null)
- {
- bW.Write((byte)0);
- }
- else
- {
- bW.Write(Convert.ToByte(_zoneTransferTsigKeyNames.Count));
- foreach (KeyValuePair<string, object> tsigKeyName in _zoneTransferTsigKeyNames)
- bW.WriteShortString(tsigKeyName.Key);
- }
- if (_updateSecurityPolicies is null)
- {
- bW.Write((byte)0);
- }
- else
- {
- bW.Write(Convert.ToByte(_updateSecurityPolicies.Count));
- foreach (KeyValuePair<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>> updateSecurityPolicy in _updateSecurityPolicies)
- {
- bW.WriteShortString(updateSecurityPolicy.Key);
- bW.Write(Convert.ToByte(updateSecurityPolicy.Value.Count));
- foreach (KeyValuePair<string, IReadOnlyList<DnsResourceRecordType>> policyMap in updateSecurityPolicy.Value)
- {
- bW.WriteShortString(policyMap.Key);
- bW.Write(Convert.ToByte(policyMap.Value.Count));
- foreach (DnsResourceRecordType type in policyMap.Value)
- bW.Write((ushort)type);
- }
- }
- }
- if (_dnssecPrivateKeys is null)
- {
- bW.Write((byte)0);
- }
- else
- {
- bW.Write(Convert.ToByte(_dnssecPrivateKeys.Count));
- foreach (DnssecPrivateKey dnssecPrivateKey in _dnssecPrivateKeys)
- dnssecPrivateKey.WriteTo(bW);
- }
- break;
- case AuthZoneType.Secondary:
- bW.Write(_expiry);
- if (_zoneHistory is null)
- {
- bW.Write(0);
- }
- else
- {
- bW.Write(_zoneHistory.Count);
- foreach (DnsResourceRecord record in _zoneHistory)
- {
- record.WriteTo(bW.BaseStream);
- if (record.Tag is HistoryRecordInfo rrInfo)
- {
- bW.Write(true);
- rrInfo.WriteTo(bW);
- }
- else
- {
- bW.Write(false);
- }
- }
- }
- if (_zoneTransferTsigKeyNames is null)
- {
- bW.Write((byte)0);
- }
- else
- {
- bW.Write(Convert.ToByte(_zoneTransferTsigKeyNames.Count));
- foreach (KeyValuePair<string, object> tsigKeyName in _zoneTransferTsigKeyNames)
- bW.WriteShortString(tsigKeyName.Key);
- }
- break;
- case AuthZoneType.Stub:
- bW.Write(_expiry);
- break;
- case AuthZoneType.Forwarder:
- if (_updateSecurityPolicies is null)
- {
- bW.Write((byte)0);
- }
- else
- {
- bW.Write(Convert.ToByte(_updateSecurityPolicies.Count));
- foreach (KeyValuePair<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>> updateSecurityPolicy in _updateSecurityPolicies)
- {
- bW.WriteShortString(updateSecurityPolicy.Key);
- bW.Write(Convert.ToByte(updateSecurityPolicy.Value.Count));
- foreach (KeyValuePair<string, IReadOnlyList<DnsResourceRecordType>> policyMap in updateSecurityPolicy.Value)
- {
- bW.WriteShortString(policyMap.Key);
- bW.Write(Convert.ToByte(policyMap.Value.Count));
- foreach (DnsResourceRecordType type in policyMap.Value)
- bW.Write((ushort)type);
- }
- }
- }
- break;
- }
- }
- public int CompareTo(AuthZoneInfo other)
- {
- return _name.CompareTo(other._name);
- }
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(this, obj))
- return true;
- if (obj is not AuthZoneInfo other)
- return false;
- return _name.Equals(other._name, StringComparison.OrdinalIgnoreCase);
- }
- public override int GetHashCode()
- {
- return HashCode.Combine(_name);
- }
- public override string ToString()
- {
- return _name;
- }
- #endregion
- #region properties
- internal ApexZone ApexZone
- { get { return _apexZone; } }
- public string Name
- { get { return _name; } }
- public AuthZoneType Type
- { get { return _type; } }
- public bool Disabled
- {
- get
- {
- if (_apexZone is null)
- return _disabled;
- return _apexZone.Disabled;
- }
- set
- {
- if (_apexZone is null)
- throw new InvalidOperationException();
- _apexZone.Disabled = value;
- }
- }
- public AuthZoneTransfer ZoneTransfer
- {
- get
- {
- if (_apexZone is null)
- return _zoneTransfer;
- return _apexZone.ZoneTransfer;
- }
- set
- {
- if (_apexZone is null)
- throw new InvalidOperationException();
- _apexZone.ZoneTransfer = value;
- }
- }
- public IReadOnlyCollection<NetworkAddress> ZoneTransferNameServers
- {
- get
- {
- if (_apexZone is null)
- return _zoneTransferNameServers;
- return _apexZone.ZoneTransferNameServers;
- }
- set
- {
- if (_apexZone is null)
- throw new InvalidOperationException();
- _apexZone.ZoneTransferNameServers = value;
- }
- }
- public AuthZoneNotify Notify
- {
- get
- {
- if (_apexZone is null)
- return _notify;
- return _apexZone.Notify;
- }
- set
- {
- if (_apexZone is null)
- throw new InvalidOperationException();
- _apexZone.Notify = value;
- }
- }
- public IReadOnlyCollection<IPAddress> NotifyNameServers
- {
- get
- {
- if (_apexZone is null)
- return _notifyNameServers;
- return _apexZone.NotifyNameServers;
- }
- set
- {
- if (_apexZone is null)
- throw new InvalidOperationException();
- _apexZone.NotifyNameServers = value;
- }
- }
- public AuthZoneUpdate Update
- {
- get
- {
- if (_apexZone is null)
- return _update;
- return _apexZone.Update;
- }
- set
- {
- if (_apexZone is null)
- throw new InvalidOperationException();
- _apexZone.Update = value;
- }
- }
- public IReadOnlyCollection<NetworkAddress> UpdateIpAddresses
- {
- get
- {
- if (_apexZone is null)
- return _updateIpAddresses;
- return _apexZone.UpdateIpAddresses;
- }
- set
- {
- if (_apexZone is null)
- throw new InvalidOperationException();
- _apexZone.UpdateIpAddresses = value;
- }
- }
- public DateTime LastModified
- {
- get
- {
- if (_apexZone is null)
- return _lastModified;
- return _apexZone.LastModified;
- }
- }
- public DateTime Expiry
- {
- get
- {
- if (_apexZone is null)
- return _expiry;
- switch (_type)
- {
- case AuthZoneType.Secondary:
- return (_apexZone as SecondaryZone).Expiry;
- case AuthZoneType.Stub:
- return (_apexZone as StubZone).Expiry;
- default:
- throw new InvalidOperationException();
- }
- }
- }
- public IReadOnlyList<DnsResourceRecord> ZoneHistory
- {
- get
- {
- if (_apexZone is null)
- return _zoneHistory;
- return _apexZone.GetZoneHistory();
- }
- }
- public IReadOnlyDictionary<string, object> ZoneTransferTsigKeyNames
- {
- get
- {
- if (_apexZone is null)
- return _zoneTransferTsigKeyNames;
- return _apexZone.ZoneTransferTsigKeyNames;
- }
- set
- {
- if (_apexZone is null)
- throw new InvalidOperationException();
- switch (_type)
- {
- case AuthZoneType.Primary:
- case AuthZoneType.Secondary:
- _apexZone.ZoneTransferTsigKeyNames = value;
- break;
- default:
- throw new InvalidOperationException();
- }
- }
- }
- public IReadOnlyDictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>> UpdateSecurityPolicies
- {
- get
- {
- if (_apexZone is null)
- return _updateSecurityPolicies;
- return _apexZone.UpdateSecurityPolicies;
- }
- set
- {
- if (_apexZone is null)
- throw new InvalidOperationException();
- switch (_type)
- {
- case AuthZoneType.Primary:
- case AuthZoneType.Forwarder:
- _apexZone.UpdateSecurityPolicies = value;
- break;
- default:
- throw new InvalidOperationException();
- }
- }
- }
- public IReadOnlyCollection<DnssecPrivateKey> DnssecPrivateKeys
- {
- get
- {
- if (_apexZone is null)
- return _dnssecPrivateKeys;
- switch (_type)
- {
- case AuthZoneType.Primary:
- return (_apexZone as PrimaryZone).DnssecPrivateKeys;
- default:
- throw new InvalidOperationException();
- }
- }
- }
- public AuthZoneDnssecStatus DnssecStatus
- {
- get
- {
- if (_apexZone is null)
- throw new InvalidOperationException();
- return _apexZone.DnssecStatus;
- }
- }
- public uint DnsKeyTtl
- {
- get
- {
- if (_apexZone is null)
- throw new InvalidOperationException();
- switch (_type)
- {
- case AuthZoneType.Primary:
- return (_apexZone as PrimaryZone).GetDnsKeyTtl();
- default:
- throw new InvalidOperationException();
- }
- }
- }
- public bool Internal
- {
- get
- {
- if (_apexZone is null)
- throw new InvalidOperationException();
- switch (_type)
- {
- case AuthZoneType.Primary:
- return (_apexZone as PrimaryZone).Internal;
- default:
- return false;
- }
- }
- }
- public bool IsExpired
- {
- get
- {
- if (_apexZone is null)
- throw new InvalidOperationException();
- switch (_type)
- {
- case AuthZoneType.Secondary:
- return (_apexZone as SecondaryZone).IsExpired;
- case AuthZoneType.Stub:
- return (_apexZone as StubZone).IsExpired;
- default:
- return false;
- }
- }
- }
- public string[] NotifyFailed
- {
- get
- {
- if (_apexZone is null)
- throw new InvalidOperationException();
- switch (_type)
- {
- case AuthZoneType.Primary:
- return (_apexZone as PrimaryZone).NotifyFailed;
- case AuthZoneType.Secondary:
- return (_apexZone as SecondaryZone).NotifyFailed;
- default:
- throw new InvalidOperationException();
- }
- }
- }
- public bool SyncFailed
- {
- get
- {
- if (_apexZone is null)
- throw new InvalidOperationException();
- switch (_type)
- {
- case AuthZoneType.Secondary:
- return (_apexZone as SecondaryZone).SyncFailed;
- case AuthZoneType.Stub:
- return (_apexZone as StubZone).SyncFailed;
- default:
- throw new InvalidOperationException();
- }
- }
- }
- #endregion
- }
- }
|