AuthZoneInfo.cs 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054
  1. /*
  2. Technitium DNS Server
  3. Copyright (C) 2024 Shreyas Zare (shreyas@technitium.com)
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. using DnsServerCore.Dns.Dnssec;
  16. using DnsServerCore.Dns.ResourceRecords;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.IO;
  20. using System.Net;
  21. using System.Net.Sockets;
  22. using TechnitiumLibrary.IO;
  23. using TechnitiumLibrary.Net;
  24. using TechnitiumLibrary.Net.Dns;
  25. using TechnitiumLibrary.Net.Dns.ResourceRecords;
  26. namespace DnsServerCore.Dns.Zones
  27. {
  28. public enum AuthZoneType : byte
  29. {
  30. Unknown = 0,
  31. Primary = 1,
  32. Secondary = 2,
  33. Stub = 3,
  34. Forwarder = 4,
  35. SecondaryForwarder = 5,
  36. Catalog = 6,
  37. SecondaryCatalog = 7
  38. }
  39. public sealed class AuthZoneInfo : IComparable<AuthZoneInfo>
  40. {
  41. #region variables
  42. readonly ApexZone _apexZone;
  43. readonly string _name;
  44. readonly AuthZoneType _type;
  45. readonly DateTime _lastModified;
  46. readonly bool _disabled;
  47. readonly string _catalogZoneName;
  48. readonly bool _overrideCatalogQueryAccess;
  49. readonly bool _overrideCatalogZoneTransfer;
  50. readonly bool _overrideCatalogNotify;
  51. readonly bool _overrideCatalogPrimaryNameServers; //only for secondary zones
  52. readonly AuthZoneQueryAccess _queryAccess;
  53. readonly IReadOnlyCollection<NetworkAccessControl> _queryAccessNetworkACL;
  54. readonly AuthZoneTransfer _zoneTransfer;
  55. readonly IReadOnlyCollection<NetworkAccessControl> _zoneTransferNetworkACL;
  56. readonly IReadOnlyDictionary<string, object> _zoneTransferTsigKeyNames;
  57. readonly IReadOnlyList<DnsResourceRecord> _zoneHistory; //for IXFR support
  58. readonly AuthZoneNotify _notify;
  59. readonly IReadOnlyCollection<IPAddress> _notifyNameServers;
  60. readonly IReadOnlyCollection<IPAddress> _notifySecondaryCatalogNameServers;
  61. readonly AuthZoneUpdate _update;
  62. readonly IReadOnlyCollection<NetworkAccessControl> _updateNetworkACL;
  63. readonly IReadOnlyDictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>> _updateSecurityPolicies;
  64. readonly IReadOnlyCollection<DnssecPrivateKey> _dnssecPrivateKeys; //only for primary zones
  65. readonly IReadOnlyList<NameServerAddress> _primaryNameServerAddresses; //only for secondary and stub zones
  66. readonly DnsTransportProtocol _primaryZoneTransferProtocol; //only for secondary zones
  67. readonly string _primaryZoneTransferTsigKeyName; //only for secondary zones
  68. readonly DateTime _expiry; //only for secondary and stub zones
  69. readonly bool _validateZone; //only for secondary zones
  70. readonly bool _validationFailed; //only for secondary zones
  71. #endregion
  72. #region constructor
  73. public AuthZoneInfo(string name, AuthZoneType type, bool disabled)
  74. {
  75. _name = name;
  76. _type = type;
  77. _lastModified = DateTime.UtcNow;
  78. _disabled = disabled;
  79. _queryAccess = AuthZoneQueryAccess.Allow;
  80. switch (_type)
  81. {
  82. case AuthZoneType.Primary:
  83. _zoneTransfer = AuthZoneTransfer.AllowOnlyZoneNameServers;
  84. _notify = AuthZoneNotify.ZoneNameServers;
  85. _update = AuthZoneUpdate.Deny;
  86. break;
  87. default:
  88. _zoneTransfer = AuthZoneTransfer.Deny;
  89. _notify = AuthZoneNotify.None;
  90. _update = AuthZoneUpdate.Deny;
  91. break;
  92. }
  93. }
  94. public AuthZoneInfo(BinaryReader bR, DateTime lastModified)
  95. {
  96. byte version = bR.ReadByte();
  97. switch (version)
  98. {
  99. case 1:
  100. case 2:
  101. case 3:
  102. case 4:
  103. case 5:
  104. case 6:
  105. case 7:
  106. case 8:
  107. case 9:
  108. case 10:
  109. case 11:
  110. {
  111. _name = bR.ReadShortString();
  112. _type = (AuthZoneType)bR.ReadByte();
  113. _disabled = bR.ReadBoolean();
  114. _queryAccess = AuthZoneQueryAccess.Allow;
  115. if (version >= 2)
  116. {
  117. {
  118. _zoneTransfer = (AuthZoneTransfer)bR.ReadByte();
  119. int count = bR.ReadByte();
  120. if (count > 0)
  121. {
  122. NetworkAddress[] networks = new NetworkAddress[count];
  123. if (version >= 9)
  124. {
  125. for (int i = 0; i < count; i++)
  126. networks[i] = NetworkAddress.ReadFrom(bR);
  127. }
  128. else
  129. {
  130. for (int i = 0; i < count; i++)
  131. {
  132. IPAddress address = IPAddressExtensions.ReadFrom(bR);
  133. switch (address.AddressFamily)
  134. {
  135. case AddressFamily.InterNetwork:
  136. networks[i] = new NetworkAddress(address, 32);
  137. break;
  138. case AddressFamily.InterNetworkV6:
  139. networks[i] = new NetworkAddress(address, 128);
  140. break;
  141. default:
  142. throw new InvalidOperationException();
  143. }
  144. }
  145. }
  146. _zoneTransferNetworkACL = ConvertDenyAllowToACL(null, networks);
  147. }
  148. }
  149. {
  150. _notify = (AuthZoneNotify)bR.ReadByte();
  151. int count = bR.ReadByte();
  152. if (count > 0)
  153. {
  154. IPAddress[] nameServers = new IPAddress[count];
  155. for (int i = 0; i < count; i++)
  156. nameServers[i] = IPAddressExtensions.ReadFrom(bR);
  157. _notifyNameServers = nameServers;
  158. }
  159. }
  160. if (version >= 6)
  161. {
  162. _update = (AuthZoneUpdate)bR.ReadByte();
  163. int count = bR.ReadByte();
  164. if (count > 0)
  165. {
  166. NetworkAddress[] networks = new NetworkAddress[count];
  167. if (version >= 9)
  168. {
  169. for (int i = 0; i < count; i++)
  170. networks[i] = NetworkAddress.ReadFrom(bR);
  171. }
  172. else
  173. {
  174. for (int i = 0; i < count; i++)
  175. {
  176. IPAddress address = IPAddressExtensions.ReadFrom(bR);
  177. switch (address.AddressFamily)
  178. {
  179. case AddressFamily.InterNetwork:
  180. networks[i] = new NetworkAddress(address, 32);
  181. break;
  182. case AddressFamily.InterNetworkV6:
  183. networks[i] = new NetworkAddress(address, 128);
  184. break;
  185. default:
  186. throw new InvalidOperationException();
  187. }
  188. }
  189. }
  190. _updateNetworkACL = ConvertDenyAllowToACL(null, networks);
  191. }
  192. }
  193. }
  194. else
  195. {
  196. switch (_type)
  197. {
  198. case AuthZoneType.Primary:
  199. _zoneTransfer = AuthZoneTransfer.AllowOnlyZoneNameServers;
  200. _notify = AuthZoneNotify.ZoneNameServers;
  201. _update = AuthZoneUpdate.Deny;
  202. break;
  203. default:
  204. _zoneTransfer = AuthZoneTransfer.Deny;
  205. _notify = AuthZoneNotify.None;
  206. _update = AuthZoneUpdate.Deny;
  207. break;
  208. }
  209. }
  210. if (version >= 8)
  211. _lastModified = bR.ReadDateTime();
  212. else
  213. _lastModified = lastModified;
  214. switch (_type)
  215. {
  216. case AuthZoneType.Primary:
  217. {
  218. if (version >= 3)
  219. {
  220. int count = bR.ReadInt32();
  221. DnsResourceRecord[] zoneHistory = new DnsResourceRecord[count];
  222. if (version >= 11)
  223. {
  224. for (int i = 0; i < count; i++)
  225. {
  226. zoneHistory[i] = new DnsResourceRecord(bR.BaseStream);
  227. if (bR.ReadBoolean())
  228. zoneHistory[i].Tag = new HistoryRecordInfo(bR);
  229. }
  230. }
  231. else
  232. {
  233. for (int i = 0; i < count; i++)
  234. {
  235. zoneHistory[i] = new DnsResourceRecord(bR.BaseStream);
  236. zoneHistory[i].Tag = new HistoryRecordInfo(bR);
  237. }
  238. }
  239. _zoneHistory = zoneHistory;
  240. }
  241. if (version >= 4)
  242. {
  243. int count = bR.ReadByte();
  244. Dictionary<string, object> tsigKeyNames = new Dictionary<string, object>(count);
  245. for (int i = 0; i < count; i++)
  246. tsigKeyNames.Add(bR.ReadShortString(), null);
  247. _zoneTransferTsigKeyNames = tsigKeyNames;
  248. }
  249. if (version >= 7)
  250. {
  251. int count = bR.ReadByte();
  252. Dictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>> updateSecurityPolicies = new Dictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>>(count);
  253. for (int i = 0; i < count; i++)
  254. {
  255. string tsigKeyName = bR.ReadShortString().ToLowerInvariant();
  256. if (!updateSecurityPolicies.TryGetValue(tsigKeyName, out IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>> policyMap))
  257. {
  258. policyMap = new Dictionary<string, IReadOnlyList<DnsResourceRecordType>>();
  259. updateSecurityPolicies.Add(tsigKeyName, policyMap);
  260. }
  261. int policyCount = bR.ReadByte();
  262. for (int j = 0; j < policyCount; j++)
  263. {
  264. string domain = bR.ReadShortString().ToLowerInvariant();
  265. if (!policyMap.TryGetValue(domain, out IReadOnlyList<DnsResourceRecordType> types))
  266. {
  267. types = new List<DnsResourceRecordType>();
  268. (policyMap as Dictionary<string, IReadOnlyList<DnsResourceRecordType>>).Add(domain, types);
  269. }
  270. int typeCount = bR.ReadByte();
  271. for (int k = 0; k < typeCount; k++)
  272. (types as List<DnsResourceRecordType>).Add((DnsResourceRecordType)bR.ReadUInt16());
  273. }
  274. }
  275. _updateSecurityPolicies = updateSecurityPolicies;
  276. }
  277. else if (version >= 6)
  278. {
  279. int count = bR.ReadByte();
  280. Dictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>> updateSecurityPolicies = new Dictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>>(count);
  281. Dictionary<string, IReadOnlyList<DnsResourceRecordType>> defaultAllowPolicy = new Dictionary<string, IReadOnlyList<DnsResourceRecordType>>(1);
  282. defaultAllowPolicy.Add(_name, new List<DnsResourceRecordType>() { DnsResourceRecordType.ANY });
  283. defaultAllowPolicy.Add("*." + _name, new List<DnsResourceRecordType>() { DnsResourceRecordType.ANY });
  284. for (int i = 0; i < count; i++)
  285. updateSecurityPolicies.Add(bR.ReadShortString().ToLowerInvariant(), defaultAllowPolicy);
  286. _updateSecurityPolicies = updateSecurityPolicies;
  287. }
  288. if (version >= 5)
  289. {
  290. int count = bR.ReadByte();
  291. if (count > 0)
  292. {
  293. List<DnssecPrivateKey> dnssecPrivateKeys = new List<DnssecPrivateKey>(count);
  294. for (int i = 0; i < count; i++)
  295. dnssecPrivateKeys.Add(DnssecPrivateKey.ReadFrom(bR));
  296. _dnssecPrivateKeys = dnssecPrivateKeys;
  297. }
  298. }
  299. }
  300. break;
  301. case AuthZoneType.Secondary:
  302. {
  303. _expiry = bR.ReadDateTime();
  304. if (version >= 4)
  305. {
  306. int count = bR.ReadInt32();
  307. DnsResourceRecord[] zoneHistory = new DnsResourceRecord[count];
  308. if (version >= 11)
  309. {
  310. for (int i = 0; i < count; i++)
  311. {
  312. zoneHistory[i] = new DnsResourceRecord(bR.BaseStream);
  313. if (bR.ReadBoolean())
  314. zoneHistory[i].Tag = new HistoryRecordInfo(bR);
  315. }
  316. }
  317. else
  318. {
  319. for (int i = 0; i < count; i++)
  320. {
  321. zoneHistory[i] = new DnsResourceRecord(bR.BaseStream);
  322. zoneHistory[i].Tag = new HistoryRecordInfo(bR);
  323. }
  324. }
  325. _zoneHistory = zoneHistory;
  326. }
  327. if (version >= 4)
  328. {
  329. int count = bR.ReadByte();
  330. Dictionary<string, object> tsigKeyNames = new Dictionary<string, object>(count);
  331. for (int i = 0; i < count; i++)
  332. tsigKeyNames.Add(bR.ReadShortString(), null);
  333. _zoneTransferTsigKeyNames = tsigKeyNames;
  334. }
  335. if (version == 6)
  336. {
  337. //MUST skip old version data
  338. int count = bR.ReadByte();
  339. Dictionary<string, object> tsigKeyNames = new Dictionary<string, object>(count);
  340. for (int i = 0; i < count; i++)
  341. tsigKeyNames.Add(bR.ReadShortString(), null);
  342. }
  343. }
  344. break;
  345. case AuthZoneType.Stub:
  346. {
  347. _expiry = bR.ReadDateTime();
  348. }
  349. break;
  350. case AuthZoneType.Forwarder:
  351. {
  352. if (version >= 10)
  353. {
  354. int count = bR.ReadByte();
  355. Dictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>> updateSecurityPolicies = new Dictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>>(count);
  356. for (int i = 0; i < count; i++)
  357. {
  358. string tsigKeyName = bR.ReadShortString().ToLowerInvariant();
  359. if (!updateSecurityPolicies.TryGetValue(tsigKeyName, out IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>> policyMap))
  360. {
  361. policyMap = new Dictionary<string, IReadOnlyList<DnsResourceRecordType>>();
  362. updateSecurityPolicies.Add(tsigKeyName, policyMap);
  363. }
  364. int policyCount = bR.ReadByte();
  365. for (int j = 0; j < policyCount; j++)
  366. {
  367. string domain = bR.ReadShortString().ToLowerInvariant();
  368. if (!policyMap.TryGetValue(domain, out IReadOnlyList<DnsResourceRecordType> types))
  369. {
  370. types = new List<DnsResourceRecordType>();
  371. (policyMap as Dictionary<string, IReadOnlyList<DnsResourceRecordType>>).Add(domain, types);
  372. }
  373. int typeCount = bR.ReadByte();
  374. for (int k = 0; k < typeCount; k++)
  375. (types as List<DnsResourceRecordType>).Add((DnsResourceRecordType)bR.ReadUInt16());
  376. }
  377. }
  378. _updateSecurityPolicies = updateSecurityPolicies;
  379. }
  380. }
  381. break;
  382. }
  383. }
  384. break;
  385. case 12:
  386. case 13:
  387. {
  388. _name = bR.ReadShortString();
  389. _type = (AuthZoneType)bR.ReadByte();
  390. _lastModified = bR.ReadDateTime();
  391. _disabled = bR.ReadBoolean();
  392. switch (_type)
  393. {
  394. case AuthZoneType.Primary:
  395. _catalogZoneName = bR.ReadShortString();
  396. if (_catalogZoneName.Length == 0)
  397. _catalogZoneName = null;
  398. _overrideCatalogQueryAccess = bR.ReadBoolean();
  399. _overrideCatalogZoneTransfer = bR.ReadBoolean();
  400. _overrideCatalogNotify = bR.ReadBoolean();
  401. _queryAccess = (AuthZoneQueryAccess)bR.ReadByte();
  402. _queryAccessNetworkACL = ReadNetworkACLFrom(bR);
  403. _zoneTransfer = (AuthZoneTransfer)bR.ReadByte();
  404. _zoneTransferNetworkACL = ReadNetworkACLFrom(bR);
  405. _zoneTransferTsigKeyNames = ReadZoneTransferTsigKeyNamesFrom(bR);
  406. _zoneHistory = ReadZoneHistoryFrom(bR);
  407. _notify = (AuthZoneNotify)bR.ReadByte();
  408. _notifyNameServers = ReadIPAddressesFrom(bR);
  409. _update = (AuthZoneUpdate)bR.ReadByte();
  410. _updateNetworkACL = ReadNetworkACLFrom(bR);
  411. _updateSecurityPolicies = ReadUpdateSecurityPoliciesFrom(bR);
  412. _dnssecPrivateKeys = ReadDnssecPrivateKeysFrom(bR);
  413. break;
  414. case AuthZoneType.Secondary:
  415. _catalogZoneName = bR.ReadShortString();
  416. if (_catalogZoneName.Length == 0)
  417. _catalogZoneName = null;
  418. _overrideCatalogQueryAccess = bR.ReadBoolean();
  419. _overrideCatalogZoneTransfer = bR.ReadBoolean();
  420. _overrideCatalogPrimaryNameServers = bR.ReadBoolean();
  421. _queryAccess = (AuthZoneQueryAccess)bR.ReadByte();
  422. _queryAccessNetworkACL = ReadNetworkACLFrom(bR);
  423. _zoneTransfer = (AuthZoneTransfer)bR.ReadByte();
  424. _zoneTransferNetworkACL = ReadNetworkACLFrom(bR);
  425. _zoneTransferTsigKeyNames = ReadZoneTransferTsigKeyNamesFrom(bR);
  426. _zoneHistory = ReadZoneHistoryFrom(bR);
  427. _notify = (AuthZoneNotify)bR.ReadByte();
  428. _notifyNameServers = ReadIPAddressesFrom(bR);
  429. _update = (AuthZoneUpdate)bR.ReadByte();
  430. _updateNetworkACL = ReadNetworkACLFrom(bR);
  431. _primaryNameServerAddresses = ReadNameServerAddressesFrom(bR);
  432. _primaryZoneTransferProtocol = (DnsTransportProtocol)bR.ReadByte();
  433. _primaryZoneTransferTsigKeyName = bR.ReadShortString();
  434. if (_primaryZoneTransferTsigKeyName.Length == 0)
  435. _primaryZoneTransferTsigKeyName = null;
  436. _expiry = bR.ReadDateTime();
  437. _validateZone = bR.ReadBoolean();
  438. _validationFailed = bR.ReadBoolean();
  439. break;
  440. case AuthZoneType.Stub:
  441. _catalogZoneName = bR.ReadShortString();
  442. if (_catalogZoneName.Length == 0)
  443. _catalogZoneName = null;
  444. _overrideCatalogQueryAccess = bR.ReadBoolean();
  445. _queryAccess = (AuthZoneQueryAccess)bR.ReadByte();
  446. _queryAccessNetworkACL = ReadNetworkACLFrom(bR);
  447. _primaryNameServerAddresses = ReadNameServerAddressesFrom(bR);
  448. _expiry = bR.ReadDateTime();
  449. break;
  450. case AuthZoneType.Forwarder:
  451. _catalogZoneName = bR.ReadShortString();
  452. if (_catalogZoneName.Length == 0)
  453. _catalogZoneName = null;
  454. _overrideCatalogQueryAccess = bR.ReadBoolean();
  455. _overrideCatalogZoneTransfer = bR.ReadBoolean();
  456. _overrideCatalogNotify = bR.ReadBoolean();
  457. _queryAccess = (AuthZoneQueryAccess)bR.ReadByte();
  458. _queryAccessNetworkACL = ReadNetworkACLFrom(bR);
  459. _zoneTransfer = (AuthZoneTransfer)bR.ReadByte();
  460. _zoneTransferNetworkACL = ReadNetworkACLFrom(bR);
  461. _zoneTransferTsigKeyNames = ReadZoneTransferTsigKeyNamesFrom(bR);
  462. _zoneHistory = ReadZoneHistoryFrom(bR);
  463. _notify = (AuthZoneNotify)bR.ReadByte();
  464. _notifyNameServers = ReadIPAddressesFrom(bR);
  465. _update = (AuthZoneUpdate)bR.ReadByte();
  466. _updateNetworkACL = ReadNetworkACLFrom(bR);
  467. _updateSecurityPolicies = ReadUpdateSecurityPoliciesFrom(bR);
  468. break;
  469. case AuthZoneType.SecondaryForwarder:
  470. _catalogZoneName = bR.ReadShortString();
  471. if (_catalogZoneName.Length == 0)
  472. _catalogZoneName = null;
  473. _overrideCatalogQueryAccess = bR.ReadBoolean();
  474. _queryAccess = (AuthZoneQueryAccess)bR.ReadByte();
  475. _queryAccessNetworkACL = ReadNetworkACLFrom(bR);
  476. _update = (AuthZoneUpdate)bR.ReadByte();
  477. _updateNetworkACL = ReadNetworkACLFrom(bR);
  478. _primaryNameServerAddresses = ReadNameServerAddressesFrom(bR);
  479. _primaryZoneTransferProtocol = (DnsTransportProtocol)bR.ReadByte();
  480. _primaryZoneTransferTsigKeyName = bR.ReadShortString();
  481. if (_primaryZoneTransferTsigKeyName.Length == 0)
  482. _primaryZoneTransferTsigKeyName = null;
  483. _expiry = bR.ReadDateTime();
  484. break;
  485. case AuthZoneType.Catalog:
  486. _queryAccess = (AuthZoneQueryAccess)bR.ReadByte();
  487. _queryAccessNetworkACL = ReadNetworkACLFrom(bR);
  488. _zoneTransfer = (AuthZoneTransfer)bR.ReadByte();
  489. _zoneTransferNetworkACL = ReadNetworkACLFrom(bR);
  490. _zoneTransferTsigKeyNames = ReadZoneTransferTsigKeyNamesFrom(bR);
  491. _zoneHistory = ReadZoneHistoryFrom(bR);
  492. _notify = (AuthZoneNotify)bR.ReadByte();
  493. _notifyNameServers = ReadIPAddressesFrom(bR);
  494. if (version >= 13)
  495. _notifySecondaryCatalogNameServers = ReadIPAddressesFrom(bR);
  496. break;
  497. case AuthZoneType.SecondaryCatalog:
  498. _queryAccess = (AuthZoneQueryAccess)bR.ReadByte();
  499. _queryAccessNetworkACL = ReadNetworkACLFrom(bR);
  500. _zoneTransfer = (AuthZoneTransfer)bR.ReadByte();
  501. _zoneTransferNetworkACL = ReadNetworkACLFrom(bR);
  502. _zoneTransferTsigKeyNames = ReadZoneTransferTsigKeyNamesFrom(bR);
  503. _primaryNameServerAddresses = ReadNameServerAddressesFrom(bR);
  504. _primaryZoneTransferProtocol = (DnsTransportProtocol)bR.ReadByte();
  505. _primaryZoneTransferTsigKeyName = bR.ReadShortString();
  506. if (_primaryZoneTransferTsigKeyName.Length == 0)
  507. _primaryZoneTransferTsigKeyName = null;
  508. _expiry = bR.ReadDateTime();
  509. break;
  510. }
  511. }
  512. break;
  513. default:
  514. throw new InvalidDataException("AuthZoneInfo format version not supported.");
  515. }
  516. }
  517. internal AuthZoneInfo(ApexZone apexZone, bool loadHistory = false)
  518. {
  519. _apexZone = apexZone;
  520. _name = _apexZone.Name;
  521. _lastModified = _apexZone.LastModified;
  522. _disabled = _apexZone.Disabled;
  523. if (_apexZone is PrimaryZone primaryZone)
  524. {
  525. _type = AuthZoneType.Primary;
  526. _catalogZoneName = _apexZone.CatalogZoneName;
  527. _overrideCatalogQueryAccess = _apexZone.OverrideCatalogQueryAccess;
  528. _overrideCatalogZoneTransfer = _apexZone.OverrideCatalogZoneTransfer;
  529. _overrideCatalogNotify = _apexZone.OverrideCatalogNotify;
  530. _queryAccess = _apexZone.QueryAccess;
  531. _queryAccessNetworkACL = _apexZone.QueryAccessNetworkACL;
  532. _zoneTransfer = _apexZone.ZoneTransfer;
  533. _zoneTransferNetworkACL = _apexZone.ZoneTransferNetworkACL;
  534. _zoneTransferTsigKeyNames = _apexZone.ZoneTransferTsigKeyNames;
  535. if (loadHistory)
  536. _zoneHistory = _apexZone.GetZoneHistory();
  537. _notify = _apexZone.Notify;
  538. _notifyNameServers = _apexZone.NotifyNameServers;
  539. _update = _apexZone.Update;
  540. _updateNetworkACL = _apexZone.UpdateNetworkACL;
  541. _updateSecurityPolicies = _apexZone.UpdateSecurityPolicies;
  542. _dnssecPrivateKeys = primaryZone.DnssecPrivateKeys;
  543. }
  544. else if (_apexZone is SecondaryCatalogZone secondaryCatalogZone)
  545. {
  546. _type = AuthZoneType.SecondaryCatalog;
  547. _queryAccess = _apexZone.QueryAccess;
  548. _queryAccessNetworkACL = _apexZone.QueryAccessNetworkACL;
  549. _zoneTransfer = _apexZone.ZoneTransfer;
  550. _zoneTransferNetworkACL = _apexZone.ZoneTransferNetworkACL;
  551. _zoneTransferTsigKeyNames = _apexZone.ZoneTransferTsigKeyNames;
  552. _primaryNameServerAddresses = secondaryCatalogZone.PrimaryNameServerAddresses;
  553. _primaryZoneTransferProtocol = secondaryCatalogZone.PrimaryZoneTransferProtocol;
  554. _primaryZoneTransferTsigKeyName = secondaryCatalogZone.PrimaryZoneTransferTsigKeyName;
  555. _expiry = secondaryCatalogZone.Expiry;
  556. }
  557. else if (_apexZone is SecondaryForwarderZone secondaryForwarderZone)
  558. {
  559. _type = AuthZoneType.SecondaryForwarder;
  560. _catalogZoneName = _apexZone.CatalogZoneName;
  561. _overrideCatalogQueryAccess = _apexZone.OverrideCatalogQueryAccess;
  562. _queryAccess = _apexZone.QueryAccess;
  563. _queryAccessNetworkACL = _apexZone.QueryAccessNetworkACL;
  564. _update = _apexZone.Update;
  565. _updateNetworkACL = _apexZone.UpdateNetworkACL;
  566. _primaryNameServerAddresses = secondaryForwarderZone.PrimaryNameServerAddresses;
  567. _primaryZoneTransferProtocol = secondaryForwarderZone.PrimaryZoneTransferProtocol;
  568. _primaryZoneTransferTsigKeyName = secondaryForwarderZone.PrimaryZoneTransferTsigKeyName;
  569. _expiry = secondaryForwarderZone.Expiry;
  570. }
  571. else if (_apexZone is SecondaryZone secondaryZone)
  572. {
  573. _type = AuthZoneType.Secondary;
  574. _catalogZoneName = _apexZone.CatalogZoneName;
  575. _overrideCatalogQueryAccess = _apexZone.OverrideCatalogQueryAccess;
  576. _overrideCatalogZoneTransfer = _apexZone.OverrideCatalogZoneTransfer;
  577. _overrideCatalogPrimaryNameServers = secondaryZone.OverrideCatalogPrimaryNameServers;
  578. _queryAccess = _apexZone.QueryAccess;
  579. _queryAccessNetworkACL = _apexZone.QueryAccessNetworkACL;
  580. _zoneTransfer = _apexZone.ZoneTransfer;
  581. _zoneTransferNetworkACL = _apexZone.ZoneTransferNetworkACL;
  582. _zoneTransferTsigKeyNames = _apexZone.ZoneTransferTsigKeyNames;
  583. if (loadHistory)
  584. _zoneHistory = _apexZone.GetZoneHistory();
  585. _notify = _apexZone.Notify;
  586. _notifyNameServers = _apexZone.NotifyNameServers;
  587. _update = _apexZone.Update;
  588. _updateNetworkACL = _apexZone.UpdateNetworkACL;
  589. _primaryNameServerAddresses = secondaryZone.PrimaryNameServerAddresses;
  590. _primaryZoneTransferProtocol = secondaryZone.PrimaryZoneTransferProtocol;
  591. _primaryZoneTransferTsigKeyName = secondaryZone.PrimaryZoneTransferTsigKeyName;
  592. _expiry = secondaryZone.Expiry;
  593. _validateZone = secondaryZone.ValidateZone;
  594. _validationFailed = secondaryZone.ValidationFailed;
  595. }
  596. else if (_apexZone is StubZone stubZone)
  597. {
  598. _type = AuthZoneType.Stub;
  599. _catalogZoneName = _apexZone.CatalogZoneName;
  600. _overrideCatalogQueryAccess = _apexZone.OverrideCatalogQueryAccess;
  601. _queryAccess = _apexZone.QueryAccess;
  602. _queryAccessNetworkACL = _apexZone.QueryAccessNetworkACL;
  603. _primaryNameServerAddresses = stubZone.PrimaryNameServerAddresses;
  604. _expiry = stubZone.Expiry;
  605. }
  606. else if (_apexZone is CatalogZone)
  607. {
  608. _type = AuthZoneType.Catalog;
  609. _queryAccess = _apexZone.QueryAccess;
  610. _queryAccessNetworkACL = _apexZone.QueryAccessNetworkACL;
  611. _zoneTransfer = _apexZone.ZoneTransfer;
  612. _zoneTransferNetworkACL = _apexZone.ZoneTransferNetworkACL;
  613. _zoneTransferTsigKeyNames = _apexZone.ZoneTransferTsigKeyNames;
  614. if (loadHistory)
  615. _zoneHistory = _apexZone.GetZoneHistory();
  616. _notify = _apexZone.Notify;
  617. _notifyNameServers = _apexZone.NotifyNameServers;
  618. _notifySecondaryCatalogNameServers = _apexZone.NotifySecondaryCatalogNameServers;
  619. }
  620. else if (_apexZone is ForwarderZone)
  621. {
  622. _type = AuthZoneType.Forwarder;
  623. _catalogZoneName = _apexZone.CatalogZoneName;
  624. _overrideCatalogQueryAccess = _apexZone.OverrideCatalogQueryAccess;
  625. _overrideCatalogZoneTransfer = _apexZone.OverrideCatalogZoneTransfer;
  626. _overrideCatalogNotify = _apexZone.OverrideCatalogNotify;
  627. _queryAccess = _apexZone.QueryAccess;
  628. _queryAccessNetworkACL = _apexZone.QueryAccessNetworkACL;
  629. _zoneTransfer = _apexZone.ZoneTransfer;
  630. _zoneTransferNetworkACL = _apexZone.ZoneTransferNetworkACL;
  631. _zoneTransferTsigKeyNames = _apexZone.ZoneTransferTsigKeyNames;
  632. if (loadHistory)
  633. _zoneHistory = _apexZone.GetZoneHistory();
  634. _notify = _apexZone.Notify;
  635. _notifyNameServers = _apexZone.NotifyNameServers;
  636. _update = _apexZone.Update;
  637. _updateNetworkACL = _apexZone.UpdateNetworkACL;
  638. _updateSecurityPolicies = _apexZone.UpdateSecurityPolicies;
  639. }
  640. else
  641. {
  642. _type = AuthZoneType.Unknown;
  643. }
  644. }
  645. #endregion
  646. #region static
  647. public static string GetZoneTypeName(AuthZoneType type)
  648. {
  649. switch (type)
  650. {
  651. case AuthZoneType.SecondaryForwarder:
  652. return "Secondary Forwarder";
  653. case AuthZoneType.SecondaryCatalog:
  654. return "Secondary Catalog";
  655. default:
  656. return type.ToString();
  657. }
  658. }
  659. internal static NameServerAddress[] ReadNameServerAddressesFrom(BinaryReader bR)
  660. {
  661. int count = bR.ReadByte();
  662. if (count < 1)
  663. return null;
  664. NameServerAddress[] nameServerAddresses = new NameServerAddress[count];
  665. for (int i = 0; i < count; i++)
  666. nameServerAddresses[i] = new NameServerAddress(bR);
  667. return nameServerAddresses;
  668. }
  669. internal static void WriteNameServerAddressesTo(IReadOnlyCollection<NameServerAddress> nameServerAddresses, BinaryWriter bW)
  670. {
  671. if (nameServerAddresses is null)
  672. {
  673. bW.Write((byte)0);
  674. }
  675. else
  676. {
  677. bW.Write(Convert.ToByte(nameServerAddresses.Count));
  678. foreach (NameServerAddress network in nameServerAddresses)
  679. network.WriteTo(bW);
  680. }
  681. }
  682. internal static NetworkAccessControl[] ReadNetworkACLFrom(BinaryReader bR)
  683. {
  684. int count = bR.ReadByte();
  685. if (count < 1)
  686. return null;
  687. NetworkAccessControl[] acl = new NetworkAccessControl[count];
  688. for (int i = 0; i < count; i++)
  689. acl[i] = NetworkAccessControl.ReadFrom(bR);
  690. return acl;
  691. }
  692. internal static void WriteNetworkACLTo(IReadOnlyCollection<NetworkAccessControl> acl, BinaryWriter bW)
  693. {
  694. if (acl is null)
  695. {
  696. bW.Write((byte)0);
  697. }
  698. else
  699. {
  700. bW.Write(Convert.ToByte(acl.Count));
  701. foreach (NetworkAccessControl nac in acl)
  702. nac.WriteTo(bW);
  703. }
  704. }
  705. internal static NetworkAddress[] ReadNetworkAddressesFrom(BinaryReader bR)
  706. {
  707. int count = bR.ReadByte();
  708. if (count < 1)
  709. return null;
  710. NetworkAddress[] networks = new NetworkAddress[count];
  711. for (int i = 0; i < count; i++)
  712. networks[i] = NetworkAddress.ReadFrom(bR);
  713. return networks;
  714. }
  715. internal static void WriteNetworkAddressesTo(IReadOnlyCollection<NetworkAddress> networkAddresses, BinaryWriter bW)
  716. {
  717. if (networkAddresses is null)
  718. {
  719. bW.Write((byte)0);
  720. }
  721. else
  722. {
  723. bW.Write(Convert.ToByte(networkAddresses.Count));
  724. foreach (NetworkAddress network in networkAddresses)
  725. network.WriteTo(bW);
  726. }
  727. }
  728. internal static IPAddress[] ReadIPAddressesFrom(BinaryReader bR)
  729. {
  730. int count = bR.ReadByte();
  731. if (count < 1)
  732. return null;
  733. IPAddress[] ipAddresses = new IPAddress[count];
  734. for (int i = 0; i < count; i++)
  735. ipAddresses[i] = IPAddressExtensions.ReadFrom(bR);
  736. return ipAddresses;
  737. }
  738. internal static void WriteIPAddressesTo(IReadOnlyCollection<IPAddress> ipAddresses, BinaryWriter bW)
  739. {
  740. if (ipAddresses is null)
  741. {
  742. bW.Write((byte)0);
  743. }
  744. else
  745. {
  746. bW.Write(Convert.ToByte(ipAddresses.Count));
  747. foreach (IPAddress ipAddress in ipAddresses)
  748. ipAddress.WriteTo(bW);
  749. }
  750. }
  751. internal static List<NetworkAccessControl> ConvertDenyAllowToACL(NetworkAddress[] deniedNetworks, NetworkAddress[] allowedNetworks)
  752. {
  753. List<NetworkAccessControl> acl = new List<NetworkAccessControl>();
  754. if (deniedNetworks is not null)
  755. {
  756. foreach (NetworkAddress network in deniedNetworks)
  757. acl.Add(new NetworkAccessControl(network, true));
  758. }
  759. if (allowedNetworks is not null)
  760. {
  761. foreach (NetworkAddress network in allowedNetworks)
  762. acl.Add(new NetworkAccessControl(network));
  763. }
  764. if (acl.Count > 0)
  765. return acl;
  766. return null;
  767. }
  768. #endregion
  769. #region private
  770. private static Dictionary<string, object> ReadZoneTransferTsigKeyNamesFrom(BinaryReader bR)
  771. {
  772. int count = bR.ReadByte();
  773. Dictionary<string, object> zoneTransferTsigKeyNames = new Dictionary<string, object>(count);
  774. for (int i = 0; i < count; i++)
  775. zoneTransferTsigKeyNames.Add(bR.ReadShortString(), null);
  776. return zoneTransferTsigKeyNames;
  777. }
  778. private void WriteZoneTransferTsigKeyNamesTo(BinaryWriter bW)
  779. {
  780. if (_zoneTransferTsigKeyNames is null)
  781. {
  782. bW.Write((byte)0);
  783. }
  784. else
  785. {
  786. bW.Write(Convert.ToByte(_zoneTransferTsigKeyNames.Count));
  787. foreach (KeyValuePair<string, object> tsigKeyName in _zoneTransferTsigKeyNames)
  788. bW.WriteShortString(tsigKeyName.Key);
  789. }
  790. }
  791. private static DnsResourceRecord[] ReadZoneHistoryFrom(BinaryReader bR)
  792. {
  793. int count = bR.ReadInt32();
  794. DnsResourceRecord[] zoneHistory = new DnsResourceRecord[count];
  795. for (int i = 0; i < count; i++)
  796. {
  797. zoneHistory[i] = new DnsResourceRecord(bR.BaseStream);
  798. if (bR.ReadBoolean())
  799. zoneHistory[i].Tag = new HistoryRecordInfo(bR);
  800. }
  801. return zoneHistory;
  802. }
  803. private void WriteZoneHistoryTo(BinaryWriter bW)
  804. {
  805. if (_zoneHistory is null)
  806. {
  807. bW.Write(0);
  808. }
  809. else
  810. {
  811. bW.Write(_zoneHistory.Count);
  812. foreach (DnsResourceRecord record in _zoneHistory)
  813. {
  814. record.WriteTo(bW.BaseStream);
  815. if (record.Tag is HistoryRecordInfo rrInfo)
  816. {
  817. bW.Write(true);
  818. rrInfo.WriteTo(bW);
  819. }
  820. else
  821. {
  822. bW.Write(false);
  823. }
  824. }
  825. }
  826. }
  827. private static Dictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>> ReadUpdateSecurityPoliciesFrom(BinaryReader bR)
  828. {
  829. int count = bR.ReadInt32();
  830. Dictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>> updateSecurityPolicies = new Dictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>>(count);
  831. for (int i = 0; i < count; i++)
  832. {
  833. string tsigKeyName = bR.ReadShortString().ToLowerInvariant();
  834. if (!updateSecurityPolicies.TryGetValue(tsigKeyName, out IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>> policyMap))
  835. {
  836. policyMap = new Dictionary<string, IReadOnlyList<DnsResourceRecordType>>();
  837. updateSecurityPolicies.Add(tsigKeyName, policyMap);
  838. }
  839. int policyCount = bR.ReadByte();
  840. for (int j = 0; j < policyCount; j++)
  841. {
  842. string domain = bR.ReadShortString().ToLowerInvariant();
  843. if (!policyMap.TryGetValue(domain, out IReadOnlyList<DnsResourceRecordType> types))
  844. {
  845. types = new List<DnsResourceRecordType>();
  846. (policyMap as Dictionary<string, IReadOnlyList<DnsResourceRecordType>>).Add(domain, types);
  847. }
  848. int typeCount = bR.ReadByte();
  849. for (int k = 0; k < typeCount; k++)
  850. (types as List<DnsResourceRecordType>).Add((DnsResourceRecordType)bR.ReadUInt16());
  851. }
  852. }
  853. return updateSecurityPolicies;
  854. }
  855. private void WriteUpdateSecurityPoliciesTo(BinaryWriter bW)
  856. {
  857. if (_updateSecurityPolicies is null)
  858. {
  859. bW.Write(0);
  860. }
  861. else
  862. {
  863. bW.Write(_updateSecurityPolicies.Count);
  864. foreach (KeyValuePair<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>> updateSecurityPolicy in _updateSecurityPolicies)
  865. {
  866. bW.WriteShortString(updateSecurityPolicy.Key);
  867. bW.Write(Convert.ToByte(updateSecurityPolicy.Value.Count));
  868. foreach (KeyValuePair<string, IReadOnlyList<DnsResourceRecordType>> policyMap in updateSecurityPolicy.Value)
  869. {
  870. bW.WriteShortString(policyMap.Key);
  871. bW.Write(Convert.ToByte(policyMap.Value.Count));
  872. foreach (DnsResourceRecordType type in policyMap.Value)
  873. bW.Write((ushort)type);
  874. }
  875. }
  876. }
  877. }
  878. private static DnssecPrivateKey[] ReadDnssecPrivateKeysFrom(BinaryReader bR)
  879. {
  880. int count = bR.ReadByte();
  881. if (count < 1)
  882. return null;
  883. DnssecPrivateKey[] dnssecPrivateKeys = new DnssecPrivateKey[count];
  884. for (int i = 0; i < count; i++)
  885. dnssecPrivateKeys[i] = DnssecPrivateKey.ReadFrom(bR);
  886. return dnssecPrivateKeys;
  887. }
  888. private void WriteDnssecPrivateKeysTo(BinaryWriter bW)
  889. {
  890. if (_dnssecPrivateKeys is null)
  891. {
  892. bW.Write((byte)0);
  893. }
  894. else
  895. {
  896. bW.Write(Convert.ToByte(_dnssecPrivateKeys.Count));
  897. foreach (DnssecPrivateKey dnssecPrivateKey in _dnssecPrivateKeys)
  898. dnssecPrivateKey.WriteTo(bW);
  899. }
  900. }
  901. #endregion
  902. #region public
  903. public void TriggerRefresh()
  904. {
  905. if (_apexZone is null)
  906. throw new InvalidOperationException();
  907. switch (_type)
  908. {
  909. case AuthZoneType.Secondary:
  910. case AuthZoneType.SecondaryForwarder:
  911. case AuthZoneType.SecondaryCatalog:
  912. (_apexZone as SecondaryZone).TriggerRefresh();
  913. break;
  914. case AuthZoneType.Stub:
  915. (_apexZone as StubZone).TriggerRefresh();
  916. break;
  917. default:
  918. throw new InvalidOperationException();
  919. }
  920. }
  921. public void TriggerResync()
  922. {
  923. if (_apexZone is null)
  924. throw new InvalidOperationException();
  925. switch (_type)
  926. {
  927. case AuthZoneType.Secondary:
  928. case AuthZoneType.SecondaryForwarder:
  929. case AuthZoneType.SecondaryCatalog:
  930. (_apexZone as SecondaryZone).TriggerResync();
  931. break;
  932. case AuthZoneType.Stub:
  933. (_apexZone as StubZone).TriggerResync();
  934. break;
  935. default:
  936. throw new InvalidOperationException();
  937. }
  938. }
  939. public void WriteTo(BinaryWriter bW)
  940. {
  941. if (_apexZone is null)
  942. throw new InvalidOperationException();
  943. bW.Write((byte)13); //version
  944. bW.WriteShortString(_name);
  945. bW.Write((byte)_type);
  946. bW.Write(_lastModified);
  947. bW.Write(_disabled);
  948. switch (_type)
  949. {
  950. case AuthZoneType.Primary:
  951. bW.Write(_catalogZoneName ?? "");
  952. bW.Write(_overrideCatalogQueryAccess);
  953. bW.Write(_overrideCatalogZoneTransfer);
  954. bW.Write(_overrideCatalogNotify);
  955. bW.Write((byte)_queryAccess);
  956. WriteNetworkACLTo(_queryAccessNetworkACL, bW);
  957. bW.Write((byte)_zoneTransfer);
  958. WriteNetworkACLTo(_zoneTransferNetworkACL, bW);
  959. WriteZoneTransferTsigKeyNamesTo(bW);
  960. WriteZoneHistoryTo(bW);
  961. bW.Write((byte)_notify);
  962. WriteIPAddressesTo(_notifyNameServers, bW);
  963. bW.Write((byte)_update);
  964. WriteNetworkACLTo(_updateNetworkACL, bW);
  965. WriteUpdateSecurityPoliciesTo(bW);
  966. WriteDnssecPrivateKeysTo(bW);
  967. break;
  968. case AuthZoneType.Secondary:
  969. bW.Write(_catalogZoneName ?? "");
  970. bW.Write(_overrideCatalogQueryAccess);
  971. bW.Write(_overrideCatalogZoneTransfer);
  972. bW.Write(_overrideCatalogPrimaryNameServers);
  973. bW.Write((byte)_queryAccess);
  974. WriteNetworkACLTo(_queryAccessNetworkACL, bW);
  975. bW.Write((byte)_zoneTransfer);
  976. WriteNetworkACLTo(_zoneTransferNetworkACL, bW);
  977. WriteZoneTransferTsigKeyNamesTo(bW);
  978. WriteZoneHistoryTo(bW);
  979. bW.Write((byte)_notify);
  980. WriteIPAddressesTo(_notifyNameServers, bW);
  981. bW.Write((byte)_update);
  982. WriteNetworkACLTo(_updateNetworkACL, bW);
  983. WriteNameServerAddressesTo(_primaryNameServerAddresses, bW);
  984. bW.Write((byte)_primaryZoneTransferProtocol);
  985. bW.Write(_primaryZoneTransferTsigKeyName ?? "");
  986. bW.Write(_expiry);
  987. bW.Write(_validateZone);
  988. bW.Write(_validationFailed);
  989. break;
  990. case AuthZoneType.Stub:
  991. bW.Write(_catalogZoneName ?? "");
  992. bW.Write(_overrideCatalogQueryAccess);
  993. bW.Write((byte)_queryAccess);
  994. WriteNetworkACLTo(_queryAccessNetworkACL, bW);
  995. WriteNameServerAddressesTo(_primaryNameServerAddresses, bW);
  996. bW.Write(_expiry);
  997. break;
  998. case AuthZoneType.Forwarder:
  999. bW.Write(_catalogZoneName ?? "");
  1000. bW.Write(_overrideCatalogQueryAccess);
  1001. bW.Write(_overrideCatalogZoneTransfer);
  1002. bW.Write(_overrideCatalogNotify);
  1003. bW.Write((byte)_queryAccess);
  1004. WriteNetworkACLTo(_queryAccessNetworkACL, bW);
  1005. bW.Write((byte)_zoneTransfer);
  1006. WriteNetworkACLTo(_zoneTransferNetworkACL, bW);
  1007. WriteZoneTransferTsigKeyNamesTo(bW);
  1008. WriteZoneHistoryTo(bW);
  1009. bW.Write((byte)_notify);
  1010. WriteIPAddressesTo(_notifyNameServers, bW);
  1011. bW.Write((byte)_update);
  1012. WriteNetworkACLTo(_updateNetworkACL, bW);
  1013. WriteUpdateSecurityPoliciesTo(bW);
  1014. break;
  1015. case AuthZoneType.SecondaryForwarder:
  1016. bW.Write(_catalogZoneName ?? "");
  1017. bW.Write(_overrideCatalogQueryAccess);
  1018. bW.Write((byte)_queryAccess);
  1019. WriteNetworkACLTo(_queryAccessNetworkACL, bW);
  1020. bW.Write((byte)_update);
  1021. WriteNetworkACLTo(_updateNetworkACL, bW);
  1022. WriteNameServerAddressesTo(_primaryNameServerAddresses, bW);
  1023. bW.Write((byte)_primaryZoneTransferProtocol);
  1024. bW.Write(_primaryZoneTransferTsigKeyName ?? "");
  1025. bW.Write(_expiry);
  1026. break;
  1027. case AuthZoneType.Catalog:
  1028. bW.Write((byte)_queryAccess);
  1029. WriteNetworkACLTo(_queryAccessNetworkACL, bW);
  1030. bW.Write((byte)_zoneTransfer);
  1031. WriteNetworkACLTo(_zoneTransferNetworkACL, bW);
  1032. WriteZoneTransferTsigKeyNamesTo(bW);
  1033. WriteZoneHistoryTo(bW);
  1034. bW.Write((byte)_notify);
  1035. WriteIPAddressesTo(_notifyNameServers, bW);
  1036. WriteIPAddressesTo(_notifySecondaryCatalogNameServers, bW);
  1037. break;
  1038. case AuthZoneType.SecondaryCatalog:
  1039. bW.Write((byte)_queryAccess);
  1040. WriteNetworkACLTo(_queryAccessNetworkACL, bW);
  1041. bW.Write((byte)_zoneTransfer);
  1042. WriteNetworkACLTo(_zoneTransferNetworkACL, bW);
  1043. WriteZoneTransferTsigKeyNamesTo(bW);
  1044. WriteNameServerAddressesTo(_primaryNameServerAddresses, bW);
  1045. bW.Write((byte)_primaryZoneTransferProtocol);
  1046. bW.Write(_primaryZoneTransferTsigKeyName ?? "");
  1047. bW.Write(_expiry);
  1048. break;
  1049. }
  1050. }
  1051. public int CompareTo(AuthZoneInfo other)
  1052. {
  1053. return _name.CompareTo(other._name);
  1054. }
  1055. public override bool Equals(object obj)
  1056. {
  1057. if (ReferenceEquals(this, obj))
  1058. return true;
  1059. if (obj is not AuthZoneInfo other)
  1060. return false;
  1061. return _name.Equals(other._name, StringComparison.OrdinalIgnoreCase);
  1062. }
  1063. public override int GetHashCode()
  1064. {
  1065. return HashCode.Combine(_name);
  1066. }
  1067. public override string ToString()
  1068. {
  1069. return _name.Length == 0 ? "<root>" : _name; ;
  1070. }
  1071. #endregion
  1072. #region properties
  1073. internal ApexZone ApexZone
  1074. { get { return _apexZone; } }
  1075. public string Name
  1076. { get { return _name; } }
  1077. public string DisplayName
  1078. { get { return _name.Length == 0 ? "<root>" : _name; } }
  1079. public AuthZoneType Type
  1080. { get { return _type; } }
  1081. public string TypeName
  1082. { get { return GetZoneTypeName(_type); } }
  1083. public DateTime LastModified
  1084. {
  1085. get
  1086. {
  1087. if (_apexZone is null)
  1088. return _lastModified;
  1089. return _apexZone.LastModified;
  1090. }
  1091. }
  1092. public bool Disabled
  1093. {
  1094. get
  1095. {
  1096. if (_apexZone is null)
  1097. return _disabled;
  1098. return _apexZone.Disabled;
  1099. }
  1100. set
  1101. {
  1102. if (_apexZone is null)
  1103. throw new InvalidOperationException();
  1104. _apexZone.Disabled = value;
  1105. }
  1106. }
  1107. public string CatalogZoneName
  1108. {
  1109. get
  1110. {
  1111. if (_apexZone is null)
  1112. return _catalogZoneName;
  1113. return _apexZone.CatalogZoneName;
  1114. }
  1115. }
  1116. public bool OverrideCatalogQueryAccess
  1117. {
  1118. get
  1119. {
  1120. if (_apexZone is null)
  1121. return _overrideCatalogQueryAccess;
  1122. return _apexZone.OverrideCatalogQueryAccess;
  1123. }
  1124. set
  1125. {
  1126. if (_apexZone is null)
  1127. throw new InvalidOperationException();
  1128. _apexZone.OverrideCatalogQueryAccess = value;
  1129. }
  1130. }
  1131. public bool OverrideCatalogZoneTransfer
  1132. {
  1133. get
  1134. {
  1135. if (_apexZone is null)
  1136. return _overrideCatalogZoneTransfer;
  1137. return _apexZone.OverrideCatalogZoneTransfer;
  1138. }
  1139. set
  1140. {
  1141. if (_apexZone is null)
  1142. throw new InvalidOperationException();
  1143. _apexZone.OverrideCatalogZoneTransfer = value;
  1144. }
  1145. }
  1146. public bool OverrideCatalogNotify
  1147. {
  1148. get
  1149. {
  1150. if (_apexZone is null)
  1151. return _overrideCatalogNotify;
  1152. return _apexZone.OverrideCatalogNotify;
  1153. }
  1154. set
  1155. {
  1156. if (_apexZone is null)
  1157. throw new InvalidOperationException();
  1158. _apexZone.OverrideCatalogNotify = value;
  1159. }
  1160. }
  1161. public bool OverrideCatalogPrimaryNameServers
  1162. {
  1163. get
  1164. {
  1165. if (_apexZone is null)
  1166. return _overrideCatalogPrimaryNameServers;
  1167. switch (_type)
  1168. {
  1169. case AuthZoneType.Secondary:
  1170. return (_apexZone as SecondaryZone).OverrideCatalogPrimaryNameServers;
  1171. case AuthZoneType.SecondaryForwarder:
  1172. case AuthZoneType.SecondaryCatalog:
  1173. return false;
  1174. default:
  1175. throw new InvalidOperationException();
  1176. }
  1177. }
  1178. set
  1179. {
  1180. if (_apexZone is null)
  1181. throw new InvalidOperationException();
  1182. switch (_type)
  1183. {
  1184. case AuthZoneType.Secondary:
  1185. (_apexZone as SecondaryZone).OverrideCatalogPrimaryNameServers = value;
  1186. break;
  1187. default:
  1188. throw new InvalidOperationException();
  1189. }
  1190. }
  1191. }
  1192. public AuthZoneQueryAccess QueryAccess
  1193. {
  1194. get
  1195. {
  1196. if (_apexZone is null)
  1197. return _queryAccess;
  1198. return _apexZone.QueryAccess;
  1199. }
  1200. set
  1201. {
  1202. if (_apexZone is null)
  1203. throw new InvalidOperationException();
  1204. _apexZone.QueryAccess = value;
  1205. }
  1206. }
  1207. public IReadOnlyCollection<NetworkAccessControl> QueryAccessNetworkACL
  1208. {
  1209. get
  1210. {
  1211. if (_apexZone is null)
  1212. return _queryAccessNetworkACL;
  1213. return _apexZone.QueryAccessNetworkACL;
  1214. }
  1215. set
  1216. {
  1217. if (_apexZone is null)
  1218. throw new InvalidOperationException();
  1219. _apexZone.QueryAccessNetworkACL = value;
  1220. }
  1221. }
  1222. public AuthZoneTransfer ZoneTransfer
  1223. {
  1224. get
  1225. {
  1226. if (_apexZone is null)
  1227. return _zoneTransfer;
  1228. return _apexZone.ZoneTransfer;
  1229. }
  1230. set
  1231. {
  1232. if (_apexZone is null)
  1233. throw new InvalidOperationException();
  1234. _apexZone.ZoneTransfer = value;
  1235. }
  1236. }
  1237. public IReadOnlyCollection<NetworkAccessControl> ZoneTransferNetworkACL
  1238. {
  1239. get
  1240. {
  1241. if (_apexZone is null)
  1242. return _zoneTransferNetworkACL;
  1243. return _apexZone.ZoneTransferNetworkACL;
  1244. }
  1245. set
  1246. {
  1247. if (_apexZone is null)
  1248. throw new InvalidOperationException();
  1249. _apexZone.ZoneTransferNetworkACL = value;
  1250. }
  1251. }
  1252. public IReadOnlyDictionary<string, object> ZoneTransferTsigKeyNames
  1253. {
  1254. get
  1255. {
  1256. if (_apexZone is null)
  1257. return _zoneTransferTsigKeyNames;
  1258. return _apexZone.ZoneTransferTsigKeyNames;
  1259. }
  1260. set
  1261. {
  1262. if (_apexZone is null)
  1263. throw new InvalidOperationException();
  1264. switch (_type)
  1265. {
  1266. case AuthZoneType.Primary:
  1267. case AuthZoneType.Secondary:
  1268. case AuthZoneType.Forwarder:
  1269. case AuthZoneType.Catalog:
  1270. _apexZone.ZoneTransferTsigKeyNames = value;
  1271. break;
  1272. default:
  1273. throw new InvalidOperationException();
  1274. }
  1275. }
  1276. }
  1277. public IReadOnlyList<DnsResourceRecord> ZoneHistory
  1278. {
  1279. get
  1280. {
  1281. if (_apexZone is null)
  1282. return _zoneHistory;
  1283. return _apexZone.GetZoneHistory();
  1284. }
  1285. }
  1286. public AuthZoneNotify Notify
  1287. {
  1288. get
  1289. {
  1290. if (_apexZone is null)
  1291. return _notify;
  1292. return _apexZone.Notify;
  1293. }
  1294. set
  1295. {
  1296. if (_apexZone is null)
  1297. throw new InvalidOperationException();
  1298. _apexZone.Notify = value;
  1299. }
  1300. }
  1301. public IReadOnlyCollection<IPAddress> NotifyNameServers
  1302. {
  1303. get
  1304. {
  1305. if (_apexZone is null)
  1306. return _notifyNameServers;
  1307. return _apexZone.NotifyNameServers;
  1308. }
  1309. set
  1310. {
  1311. if (_apexZone is null)
  1312. throw new InvalidOperationException();
  1313. _apexZone.NotifyNameServers = value;
  1314. }
  1315. }
  1316. public IReadOnlyCollection<IPAddress> NotifySecondaryCatalogNameServers
  1317. {
  1318. get
  1319. {
  1320. if (_apexZone is null)
  1321. return _notifySecondaryCatalogNameServers;
  1322. return _apexZone.NotifySecondaryCatalogNameServers;
  1323. }
  1324. set
  1325. {
  1326. if (_apexZone is null)
  1327. throw new InvalidOperationException();
  1328. _apexZone.NotifySecondaryCatalogNameServers = value;
  1329. }
  1330. }
  1331. public AuthZoneUpdate Update
  1332. {
  1333. get
  1334. {
  1335. if (_apexZone is null)
  1336. return _update;
  1337. return _apexZone.Update;
  1338. }
  1339. set
  1340. {
  1341. if (_apexZone is null)
  1342. throw new InvalidOperationException();
  1343. _apexZone.Update = value;
  1344. }
  1345. }
  1346. public IReadOnlyCollection<NetworkAccessControl> UpdateNetworkACL
  1347. {
  1348. get
  1349. {
  1350. if (_apexZone is null)
  1351. return _updateNetworkACL;
  1352. return _apexZone.UpdateNetworkACL;
  1353. }
  1354. set
  1355. {
  1356. if (_apexZone is null)
  1357. throw new InvalidOperationException();
  1358. _apexZone.UpdateNetworkACL = value;
  1359. }
  1360. }
  1361. public IReadOnlyDictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>> UpdateSecurityPolicies
  1362. {
  1363. get
  1364. {
  1365. if (_apexZone is null)
  1366. return _updateSecurityPolicies;
  1367. return _apexZone.UpdateSecurityPolicies;
  1368. }
  1369. set
  1370. {
  1371. if (_apexZone is null)
  1372. throw new InvalidOperationException();
  1373. switch (_type)
  1374. {
  1375. case AuthZoneType.Primary:
  1376. case AuthZoneType.Forwarder:
  1377. _apexZone.UpdateSecurityPolicies = value;
  1378. break;
  1379. default:
  1380. throw new InvalidOperationException();
  1381. }
  1382. }
  1383. }
  1384. public IReadOnlyCollection<DnssecPrivateKey> DnssecPrivateKeys
  1385. {
  1386. get
  1387. {
  1388. if (_apexZone is null)
  1389. return _dnssecPrivateKeys;
  1390. switch (_type)
  1391. {
  1392. case AuthZoneType.Primary:
  1393. return (_apexZone as PrimaryZone).DnssecPrivateKeys;
  1394. default:
  1395. throw new InvalidOperationException();
  1396. }
  1397. }
  1398. }
  1399. public IReadOnlyList<NameServerAddress> PrimaryNameServerAddresses
  1400. {
  1401. get
  1402. {
  1403. if (_apexZone is null)
  1404. return _primaryNameServerAddresses;
  1405. switch (_type)
  1406. {
  1407. case AuthZoneType.Secondary:
  1408. case AuthZoneType.SecondaryForwarder:
  1409. case AuthZoneType.SecondaryCatalog:
  1410. return (_apexZone as SecondaryZone).PrimaryNameServerAddresses;
  1411. case AuthZoneType.Stub:
  1412. return (_apexZone as StubZone).PrimaryNameServerAddresses;
  1413. default:
  1414. throw new InvalidOperationException();
  1415. }
  1416. }
  1417. set
  1418. {
  1419. if (_apexZone is null)
  1420. throw new InvalidOperationException();
  1421. switch (_type)
  1422. {
  1423. case AuthZoneType.Secondary:
  1424. case AuthZoneType.SecondaryForwarder:
  1425. case AuthZoneType.SecondaryCatalog:
  1426. (_apexZone as SecondaryZone).PrimaryNameServerAddresses = value;
  1427. break;
  1428. case AuthZoneType.Stub:
  1429. (_apexZone as StubZone).PrimaryNameServerAddresses = value;
  1430. break;
  1431. default:
  1432. throw new InvalidOperationException();
  1433. }
  1434. }
  1435. }
  1436. public DnsTransportProtocol PrimaryZoneTransferProtocol
  1437. {
  1438. get
  1439. {
  1440. if (_apexZone is null)
  1441. return _primaryZoneTransferProtocol;
  1442. switch (_type)
  1443. {
  1444. case AuthZoneType.Secondary:
  1445. case AuthZoneType.SecondaryForwarder:
  1446. case AuthZoneType.SecondaryCatalog:
  1447. return (_apexZone as SecondaryZone).PrimaryZoneTransferProtocol;
  1448. default:
  1449. throw new InvalidOperationException();
  1450. }
  1451. }
  1452. set
  1453. {
  1454. if (_apexZone is null)
  1455. throw new InvalidOperationException();
  1456. switch (_type)
  1457. {
  1458. case AuthZoneType.Secondary:
  1459. case AuthZoneType.SecondaryForwarder:
  1460. case AuthZoneType.SecondaryCatalog:
  1461. (_apexZone as SecondaryZone).PrimaryZoneTransferProtocol = value;
  1462. break;
  1463. default:
  1464. throw new InvalidOperationException();
  1465. }
  1466. }
  1467. }
  1468. public string PrimaryZoneTransferTsigKeyName
  1469. {
  1470. get
  1471. {
  1472. if (_apexZone is null)
  1473. return _primaryZoneTransferTsigKeyName;
  1474. switch (_type)
  1475. {
  1476. case AuthZoneType.Secondary:
  1477. case AuthZoneType.SecondaryForwarder:
  1478. case AuthZoneType.SecondaryCatalog:
  1479. return (_apexZone as SecondaryZone).PrimaryZoneTransferTsigKeyName;
  1480. default:
  1481. throw new InvalidOperationException();
  1482. }
  1483. }
  1484. set
  1485. {
  1486. if (_apexZone is null)
  1487. throw new InvalidOperationException();
  1488. switch (_type)
  1489. {
  1490. case AuthZoneType.Secondary:
  1491. case AuthZoneType.SecondaryForwarder:
  1492. case AuthZoneType.SecondaryCatalog:
  1493. (_apexZone as SecondaryZone).PrimaryZoneTransferTsigKeyName = value;
  1494. break;
  1495. default:
  1496. throw new InvalidOperationException();
  1497. }
  1498. }
  1499. }
  1500. public DateTime Expiry
  1501. {
  1502. get
  1503. {
  1504. if (_apexZone is null)
  1505. return _expiry;
  1506. switch (_type)
  1507. {
  1508. case AuthZoneType.Secondary:
  1509. case AuthZoneType.SecondaryForwarder:
  1510. case AuthZoneType.SecondaryCatalog:
  1511. return (_apexZone as SecondaryZone).Expiry;
  1512. case AuthZoneType.Stub:
  1513. return (_apexZone as StubZone).Expiry;
  1514. default:
  1515. throw new InvalidOperationException();
  1516. }
  1517. }
  1518. }
  1519. public bool ValidateZone
  1520. {
  1521. get
  1522. {
  1523. if (_apexZone is null)
  1524. return _validateZone;
  1525. switch (_type)
  1526. {
  1527. case AuthZoneType.Secondary:
  1528. return (_apexZone as SecondaryZone).ValidateZone;
  1529. default:
  1530. throw new InvalidOperationException();
  1531. }
  1532. }
  1533. set
  1534. {
  1535. if (_apexZone is null)
  1536. throw new InvalidOperationException();
  1537. switch (_type)
  1538. {
  1539. case AuthZoneType.Secondary:
  1540. (_apexZone as SecondaryZone).ValidateZone = value;
  1541. break;
  1542. default:
  1543. throw new InvalidOperationException();
  1544. }
  1545. }
  1546. }
  1547. public bool ValidationFailed
  1548. {
  1549. get
  1550. {
  1551. if (_apexZone is null)
  1552. return _validationFailed;
  1553. switch (_type)
  1554. {
  1555. case AuthZoneType.Secondary:
  1556. return (_apexZone as SecondaryZone).ValidationFailed;
  1557. default:
  1558. throw new InvalidOperationException();
  1559. }
  1560. }
  1561. }
  1562. public uint DnsKeyTtl
  1563. {
  1564. get
  1565. {
  1566. if (_apexZone is null)
  1567. throw new InvalidOperationException();
  1568. switch (_type)
  1569. {
  1570. case AuthZoneType.Primary:
  1571. return (_apexZone as PrimaryZone).GetDnsKeyTtl();
  1572. default:
  1573. throw new InvalidOperationException();
  1574. }
  1575. }
  1576. }
  1577. public bool Internal
  1578. {
  1579. get
  1580. {
  1581. if (_apexZone is null)
  1582. throw new InvalidOperationException();
  1583. switch (_type)
  1584. {
  1585. case AuthZoneType.Primary:
  1586. return (_apexZone as PrimaryZone).Internal;
  1587. default:
  1588. return false;
  1589. }
  1590. }
  1591. }
  1592. public bool IsExpired
  1593. {
  1594. get
  1595. {
  1596. if (_apexZone is null)
  1597. throw new InvalidOperationException();
  1598. switch (_type)
  1599. {
  1600. case AuthZoneType.Secondary:
  1601. case AuthZoneType.SecondaryForwarder:
  1602. case AuthZoneType.SecondaryCatalog:
  1603. return (_apexZone as SecondaryZone).IsExpired;
  1604. case AuthZoneType.Stub:
  1605. return (_apexZone as StubZone).IsExpired;
  1606. default:
  1607. return false;
  1608. }
  1609. }
  1610. }
  1611. public string[] NotifyFailed
  1612. {
  1613. get
  1614. {
  1615. if (_apexZone is null)
  1616. throw new InvalidOperationException();
  1617. switch (_type)
  1618. {
  1619. case AuthZoneType.Primary:
  1620. case AuthZoneType.Secondary:
  1621. case AuthZoneType.Forwarder:
  1622. case AuthZoneType.Catalog:
  1623. return _apexZone.NotifyFailed;
  1624. default:
  1625. throw new InvalidOperationException();
  1626. }
  1627. }
  1628. }
  1629. public bool SyncFailed
  1630. {
  1631. get
  1632. {
  1633. if (_apexZone is null)
  1634. throw new InvalidOperationException();
  1635. switch (_type)
  1636. {
  1637. case AuthZoneType.Secondary:
  1638. case AuthZoneType.SecondaryForwarder:
  1639. case AuthZoneType.SecondaryCatalog:
  1640. case AuthZoneType.Stub:
  1641. return _apexZone.SyncFailed;
  1642. default:
  1643. throw new InvalidOperationException();
  1644. }
  1645. }
  1646. }
  1647. #endregion
  1648. }
  1649. }