AuthZoneInfo.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998
  1. /*
  2. Technitium DNS Server
  3. Copyright (C) 2023 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.Threading.Tasks;
  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. }
  36. public sealed class AuthZoneInfo : IComparable<AuthZoneInfo>
  37. {
  38. #region variables
  39. readonly ApexZone _apexZone;
  40. readonly string _name;
  41. readonly AuthZoneType _type;
  42. readonly bool _disabled;
  43. readonly AuthZoneTransfer _zoneTransfer;
  44. readonly IReadOnlyCollection<IPAddress> _zoneTransferNameServers;
  45. readonly AuthZoneNotify _notify;
  46. readonly IReadOnlyCollection<IPAddress> _notifyNameServers;
  47. readonly AuthZoneUpdate _update;
  48. readonly IReadOnlyCollection<IPAddress> _updateIpAddresses;
  49. readonly DateTime _expiry;
  50. readonly IReadOnlyList<DnsResourceRecord> _zoneHistory; //for IXFR support
  51. readonly IReadOnlyDictionary<string, object> _zoneTransferTsigKeyNames;
  52. readonly IReadOnlyDictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>> _updateSecurityPolicies;
  53. readonly IReadOnlyCollection<DnssecPrivateKey> _dnssecPrivateKeys;
  54. #endregion
  55. #region constructor
  56. public AuthZoneInfo(string name, AuthZoneType type, bool disabled)
  57. {
  58. _name = name;
  59. _type = type;
  60. _disabled = disabled;
  61. switch (_type)
  62. {
  63. case AuthZoneType.Primary:
  64. _zoneTransfer = AuthZoneTransfer.AllowOnlyZoneNameServers;
  65. _notify = AuthZoneNotify.ZoneNameServers;
  66. _update = AuthZoneUpdate.Deny;
  67. break;
  68. default:
  69. _zoneTransfer = AuthZoneTransfer.Deny;
  70. _notify = AuthZoneNotify.None;
  71. _update = AuthZoneUpdate.Deny;
  72. break;
  73. }
  74. }
  75. public AuthZoneInfo(BinaryReader bR)
  76. {
  77. byte version = bR.ReadByte();
  78. switch (version)
  79. {
  80. case 1:
  81. case 2:
  82. case 3:
  83. case 4:
  84. case 5:
  85. case 6:
  86. case 7:
  87. _name = bR.ReadShortString();
  88. _type = (AuthZoneType)bR.ReadByte();
  89. _disabled = bR.ReadBoolean();
  90. if (version >= 2)
  91. {
  92. {
  93. _zoneTransfer = (AuthZoneTransfer)bR.ReadByte();
  94. int count = bR.ReadByte();
  95. if (count > 0)
  96. {
  97. IPAddress[] nameServers = new IPAddress[count];
  98. for (int i = 0; i < count; i++)
  99. nameServers[i] = IPAddressExtensions.ReadFrom(bR);
  100. _zoneTransferNameServers = nameServers;
  101. }
  102. }
  103. {
  104. _notify = (AuthZoneNotify)bR.ReadByte();
  105. int count = bR.ReadByte();
  106. if (count > 0)
  107. {
  108. IPAddress[] nameServers = new IPAddress[count];
  109. for (int i = 0; i < count; i++)
  110. nameServers[i] = IPAddressExtensions.ReadFrom(bR);
  111. _notifyNameServers = nameServers;
  112. }
  113. }
  114. if (version >= 6)
  115. {
  116. _update = (AuthZoneUpdate)bR.ReadByte();
  117. int count = bR.ReadByte();
  118. if (count > 0)
  119. {
  120. IPAddress[] ipAddresses = new IPAddress[count];
  121. for (int i = 0; i < count; i++)
  122. ipAddresses[i] = IPAddressExtensions.ReadFrom(bR);
  123. _updateIpAddresses = ipAddresses;
  124. }
  125. }
  126. }
  127. else
  128. {
  129. switch (_type)
  130. {
  131. case AuthZoneType.Primary:
  132. _zoneTransfer = AuthZoneTransfer.AllowOnlyZoneNameServers;
  133. _notify = AuthZoneNotify.ZoneNameServers;
  134. _update = AuthZoneUpdate.Deny;
  135. break;
  136. default:
  137. _zoneTransfer = AuthZoneTransfer.Deny;
  138. _notify = AuthZoneNotify.None;
  139. _update = AuthZoneUpdate.Deny;
  140. break;
  141. }
  142. }
  143. switch (_type)
  144. {
  145. case AuthZoneType.Primary:
  146. if (version >= 3)
  147. {
  148. int count = bR.ReadInt32();
  149. DnsResourceRecord[] zoneHistory = new DnsResourceRecord[count];
  150. for (int i = 0; i < count; i++)
  151. {
  152. zoneHistory[i] = new DnsResourceRecord(bR.BaseStream);
  153. zoneHistory[i].Tag = new AuthRecordInfo(bR, zoneHistory[i].Type == DnsResourceRecordType.SOA);
  154. }
  155. _zoneHistory = zoneHistory;
  156. }
  157. if (version >= 4)
  158. {
  159. int count = bR.ReadByte();
  160. Dictionary<string, object> tsigKeyNames = new Dictionary<string, object>(count);
  161. for (int i = 0; i < count; i++)
  162. tsigKeyNames.Add(bR.ReadShortString(), null);
  163. _zoneTransferTsigKeyNames = tsigKeyNames;
  164. }
  165. if (version >= 7)
  166. {
  167. int count = bR.ReadByte();
  168. Dictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>> updateSecurityPolicies = new Dictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>>(count);
  169. for (int i = 0; i < count; i++)
  170. {
  171. string tsigKeyName = bR.ReadShortString().ToLower();
  172. if (!updateSecurityPolicies.TryGetValue(tsigKeyName, out IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>> policyMap))
  173. {
  174. policyMap = new Dictionary<string, IReadOnlyList<DnsResourceRecordType>>();
  175. updateSecurityPolicies.Add(tsigKeyName, policyMap);
  176. }
  177. int policyCount = bR.ReadByte();
  178. for (int j = 0; j < policyCount; j++)
  179. {
  180. string domain = bR.ReadShortString().ToLower();
  181. if (!policyMap.TryGetValue(domain, out IReadOnlyList<DnsResourceRecordType> types))
  182. {
  183. types = new List<DnsResourceRecordType>();
  184. (policyMap as Dictionary<string, IReadOnlyList<DnsResourceRecordType>>).Add(domain, types);
  185. }
  186. int typeCount = bR.ReadByte();
  187. for (int k = 0; k < typeCount; k++)
  188. (types as List<DnsResourceRecordType>).Add((DnsResourceRecordType)bR.ReadUInt16());
  189. }
  190. }
  191. _updateSecurityPolicies = updateSecurityPolicies;
  192. }
  193. else if (version >= 6)
  194. {
  195. int count = bR.ReadByte();
  196. Dictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>> updateSecurityPolicies = new Dictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>>(count);
  197. Dictionary<string, IReadOnlyList<DnsResourceRecordType>> defaultAllowPolicy = new Dictionary<string, IReadOnlyList<DnsResourceRecordType>>(1);
  198. defaultAllowPolicy.Add(_name, new List<DnsResourceRecordType>() { DnsResourceRecordType.ANY });
  199. defaultAllowPolicy.Add("*." + _name, new List<DnsResourceRecordType>() { DnsResourceRecordType.ANY });
  200. for (int i = 0; i < count; i++)
  201. updateSecurityPolicies.Add(bR.ReadShortString().ToLower(), defaultAllowPolicy);
  202. _updateSecurityPolicies = updateSecurityPolicies;
  203. }
  204. if (version >= 5)
  205. {
  206. int count = bR.ReadByte();
  207. if (count > 0)
  208. {
  209. List<DnssecPrivateKey> dnssecPrivateKeys = new List<DnssecPrivateKey>(count);
  210. for (int i = 0; i < count; i++)
  211. dnssecPrivateKeys.Add(DnssecPrivateKey.ReadFrom(bR));
  212. _dnssecPrivateKeys = dnssecPrivateKeys;
  213. }
  214. }
  215. break;
  216. case AuthZoneType.Secondary:
  217. _expiry = bR.ReadDateTime();
  218. if (version >= 4)
  219. {
  220. int count = bR.ReadInt32();
  221. DnsResourceRecord[] zoneHistory = new DnsResourceRecord[count];
  222. for (int i = 0; i < count; i++)
  223. {
  224. zoneHistory[i] = new DnsResourceRecord(bR.BaseStream);
  225. zoneHistory[i].Tag = new AuthRecordInfo(bR, zoneHistory[i].Type == DnsResourceRecordType.SOA);
  226. }
  227. _zoneHistory = zoneHistory;
  228. }
  229. if (version >= 4)
  230. {
  231. int count = bR.ReadByte();
  232. Dictionary<string, object> tsigKeyNames = new Dictionary<string, object>(count);
  233. for (int i = 0; i < count; i++)
  234. tsigKeyNames.Add(bR.ReadShortString(), null);
  235. _zoneTransferTsigKeyNames = tsigKeyNames;
  236. }
  237. if (version == 6)
  238. {
  239. //MUST skip old version data
  240. int count = bR.ReadByte();
  241. Dictionary<string, object> tsigKeyNames = new Dictionary<string, object>(count);
  242. for (int i = 0; i < count; i++)
  243. tsigKeyNames.Add(bR.ReadShortString(), null);
  244. }
  245. break;
  246. case AuthZoneType.Stub:
  247. _expiry = bR.ReadDateTime();
  248. break;
  249. }
  250. break;
  251. default:
  252. throw new InvalidDataException("AuthZoneInfo format version not supported.");
  253. }
  254. }
  255. internal AuthZoneInfo(ApexZone apexZone, bool loadHistory = false)
  256. {
  257. _apexZone = apexZone;
  258. _name = _apexZone.Name;
  259. if (_apexZone is PrimaryZone primaryZone)
  260. {
  261. _type = AuthZoneType.Primary;
  262. if (loadHistory)
  263. _zoneHistory = primaryZone.GetZoneHistory();
  264. _zoneTransferTsigKeyNames = primaryZone.ZoneTransferTsigKeyNames;
  265. _updateSecurityPolicies = primaryZone.UpdateSecurityPolicies;
  266. _dnssecPrivateKeys = primaryZone.DnssecPrivateKeys;
  267. }
  268. else if (_apexZone is SecondaryZone secondaryZone)
  269. {
  270. _type = AuthZoneType.Secondary;
  271. if (loadHistory)
  272. _zoneHistory = secondaryZone.GetZoneHistory();
  273. _expiry = secondaryZone.Expiry;
  274. _zoneTransferTsigKeyNames = secondaryZone.ZoneTransferTsigKeyNames;
  275. }
  276. else if (_apexZone is StubZone stubZone)
  277. {
  278. _type = AuthZoneType.Stub;
  279. _expiry = stubZone.Expiry;
  280. }
  281. else if (_apexZone is ForwarderZone)
  282. {
  283. _type = AuthZoneType.Forwarder;
  284. }
  285. else
  286. {
  287. _type = AuthZoneType.Unknown;
  288. }
  289. _disabled = _apexZone.Disabled;
  290. _zoneTransfer = _apexZone.ZoneTransfer;
  291. _zoneTransferNameServers = _apexZone.ZoneTransferNameServers;
  292. _notify = _apexZone.Notify;
  293. _notifyNameServers = _apexZone.NotifyNameServers;
  294. _update = _apexZone.Update;
  295. _updateIpAddresses = _apexZone.UpdateIpAddresses;
  296. }
  297. #endregion
  298. #region public
  299. public IReadOnlyList<DnsResourceRecord> GetApexRecords(DnsResourceRecordType type)
  300. {
  301. if (_apexZone is null)
  302. throw new InvalidOperationException();
  303. return _apexZone.GetRecords(type);
  304. }
  305. public void TriggerNotify()
  306. {
  307. if (_apexZone is null)
  308. throw new InvalidOperationException();
  309. switch (_type)
  310. {
  311. case AuthZoneType.Primary:
  312. (_apexZone as PrimaryZone).TriggerNotify();
  313. break;
  314. case AuthZoneType.Secondary:
  315. (_apexZone as SecondaryZone).TriggerNotify();
  316. break;
  317. default:
  318. throw new InvalidOperationException();
  319. }
  320. }
  321. public void TriggerRefresh()
  322. {
  323. if (_apexZone is null)
  324. throw new InvalidOperationException();
  325. switch (_type)
  326. {
  327. case AuthZoneType.Secondary:
  328. (_apexZone as SecondaryZone).TriggerRefresh();
  329. break;
  330. case AuthZoneType.Stub:
  331. (_apexZone as StubZone).TriggerRefresh();
  332. break;
  333. default:
  334. throw new InvalidOperationException();
  335. }
  336. }
  337. public void TriggerResync()
  338. {
  339. if (_apexZone is null)
  340. throw new InvalidOperationException();
  341. switch (_type)
  342. {
  343. case AuthZoneType.Secondary:
  344. (_apexZone as SecondaryZone).TriggerResync();
  345. break;
  346. case AuthZoneType.Stub:
  347. (_apexZone as StubZone).TriggerResync();
  348. break;
  349. default:
  350. throw new InvalidOperationException();
  351. }
  352. }
  353. public Task<IReadOnlyList<NameServerAddress>> GetPrimaryNameServerAddressesAsync(DnsServer dnsServer)
  354. {
  355. if (_apexZone is null)
  356. throw new InvalidOperationException();
  357. return _apexZone.GetPrimaryNameServerAddressesAsync(dnsServer);
  358. }
  359. public Task<IReadOnlyList<NameServerAddress>> GetSecondaryNameServerAddressesAsync(DnsServer dnsServer)
  360. {
  361. if (_apexZone is null)
  362. throw new InvalidOperationException();
  363. return _apexZone.GetSecondaryNameServerAddressesAsync(dnsServer);
  364. }
  365. public void WriteTo(BinaryWriter bW)
  366. {
  367. if (_apexZone is null)
  368. throw new InvalidOperationException();
  369. bW.Write((byte)7); //version
  370. bW.WriteShortString(_name);
  371. bW.Write((byte)_type);
  372. bW.Write(_disabled);
  373. bW.Write((byte)_zoneTransfer);
  374. if (_zoneTransferNameServers is null)
  375. {
  376. bW.Write((byte)0);
  377. }
  378. else
  379. {
  380. bW.Write(Convert.ToByte(_zoneTransferNameServers.Count));
  381. foreach (IPAddress nameServer in _zoneTransferNameServers)
  382. nameServer.WriteTo(bW);
  383. }
  384. bW.Write((byte)_notify);
  385. if (_notifyNameServers is null)
  386. {
  387. bW.Write((byte)0);
  388. }
  389. else
  390. {
  391. bW.Write(Convert.ToByte(_notifyNameServers.Count));
  392. foreach (IPAddress nameServer in _notifyNameServers)
  393. nameServer.WriteTo(bW);
  394. }
  395. bW.Write((byte)_update);
  396. if (_updateIpAddresses is null)
  397. {
  398. bW.Write((byte)0);
  399. }
  400. else
  401. {
  402. bW.Write(Convert.ToByte(_updateIpAddresses.Count));
  403. foreach (IPAddress ipAddress in _updateIpAddresses)
  404. ipAddress.WriteTo(bW);
  405. }
  406. switch (_type)
  407. {
  408. case AuthZoneType.Primary:
  409. if (_zoneHistory is null)
  410. {
  411. bW.Write(0);
  412. }
  413. else
  414. {
  415. bW.Write(_zoneHistory.Count);
  416. foreach (DnsResourceRecord record in _zoneHistory)
  417. {
  418. record.WriteTo(bW.BaseStream);
  419. if (record.Tag is not AuthRecordInfo rrInfo)
  420. rrInfo = AuthRecordInfo.Default; //default info
  421. rrInfo.WriteTo(bW);
  422. }
  423. }
  424. if (_zoneTransferTsigKeyNames is null)
  425. {
  426. bW.Write((byte)0);
  427. }
  428. else
  429. {
  430. bW.Write(Convert.ToByte(_zoneTransferTsigKeyNames.Count));
  431. foreach (KeyValuePair<string, object> tsigKeyName in _zoneTransferTsigKeyNames)
  432. bW.WriteShortString(tsigKeyName.Key);
  433. }
  434. if (_updateSecurityPolicies is null)
  435. {
  436. bW.Write((byte)0);
  437. }
  438. else
  439. {
  440. bW.Write(Convert.ToByte(_updateSecurityPolicies.Count));
  441. foreach (KeyValuePair<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>> updateSecurityPolicy in _updateSecurityPolicies)
  442. {
  443. bW.WriteShortString(updateSecurityPolicy.Key);
  444. bW.Write(Convert.ToByte(updateSecurityPolicy.Value.Count));
  445. foreach (KeyValuePair<string, IReadOnlyList<DnsResourceRecordType>> policyMap in updateSecurityPolicy.Value)
  446. {
  447. bW.WriteShortString(policyMap.Key);
  448. bW.Write(Convert.ToByte(policyMap.Value.Count));
  449. foreach (DnsResourceRecordType type in policyMap.Value)
  450. bW.Write((ushort)type);
  451. }
  452. }
  453. }
  454. if (_dnssecPrivateKeys is null)
  455. {
  456. bW.Write((byte)0);
  457. }
  458. else
  459. {
  460. bW.Write(Convert.ToByte(_dnssecPrivateKeys.Count));
  461. foreach (DnssecPrivateKey dnssecPrivateKey in _dnssecPrivateKeys)
  462. dnssecPrivateKey.WriteTo(bW);
  463. }
  464. break;
  465. case AuthZoneType.Secondary:
  466. bW.Write(_expiry);
  467. if (_zoneHistory is null)
  468. {
  469. bW.Write(0);
  470. }
  471. else
  472. {
  473. bW.Write(_zoneHistory.Count);
  474. foreach (DnsResourceRecord record in _zoneHistory)
  475. {
  476. record.WriteTo(bW.BaseStream);
  477. if (record.Tag is not AuthRecordInfo rrInfo)
  478. rrInfo = AuthRecordInfo.Default; //default info
  479. rrInfo.WriteTo(bW);
  480. }
  481. }
  482. if (_zoneTransferTsigKeyNames is null)
  483. {
  484. bW.Write((byte)0);
  485. }
  486. else
  487. {
  488. bW.Write(Convert.ToByte(_zoneTransferTsigKeyNames.Count));
  489. foreach (KeyValuePair<string, object> tsigKeyName in _zoneTransferTsigKeyNames)
  490. bW.WriteShortString(tsigKeyName.Key);
  491. }
  492. break;
  493. case AuthZoneType.Stub:
  494. bW.Write(_expiry);
  495. break;
  496. }
  497. }
  498. public int CompareTo(AuthZoneInfo other)
  499. {
  500. return _name.CompareTo(other._name);
  501. }
  502. public override bool Equals(object obj)
  503. {
  504. if (ReferenceEquals(this, obj))
  505. return true;
  506. if (obj is not AuthZoneInfo other)
  507. return false;
  508. return _name.Equals(other._name, StringComparison.OrdinalIgnoreCase);
  509. }
  510. public override int GetHashCode()
  511. {
  512. return _name.GetHashCode();
  513. }
  514. public override string ToString()
  515. {
  516. return _name;
  517. }
  518. #endregion
  519. #region properties
  520. internal ApexZone ApexZone
  521. { get { return _apexZone; } }
  522. public string Name
  523. { get { return _name; } }
  524. public AuthZoneType Type
  525. { get { return _type; } }
  526. public bool Disabled
  527. {
  528. get
  529. {
  530. if (_apexZone is null)
  531. return _disabled;
  532. return _apexZone.Disabled;
  533. }
  534. set
  535. {
  536. if (_apexZone is null)
  537. throw new InvalidOperationException();
  538. _apexZone.Disabled = value;
  539. }
  540. }
  541. public AuthZoneTransfer ZoneTransfer
  542. {
  543. get
  544. {
  545. if (_apexZone is null)
  546. return _zoneTransfer;
  547. return _apexZone.ZoneTransfer;
  548. }
  549. set
  550. {
  551. if (_apexZone is null)
  552. throw new InvalidOperationException();
  553. _apexZone.ZoneTransfer = value;
  554. }
  555. }
  556. public IReadOnlyCollection<IPAddress> ZoneTransferNameServers
  557. {
  558. get
  559. {
  560. if (_apexZone is null)
  561. return _zoneTransferNameServers;
  562. return _apexZone.ZoneTransferNameServers;
  563. }
  564. set
  565. {
  566. if (_apexZone is null)
  567. throw new InvalidOperationException();
  568. _apexZone.ZoneTransferNameServers = value;
  569. }
  570. }
  571. public AuthZoneNotify Notify
  572. {
  573. get
  574. {
  575. if (_apexZone is null)
  576. return _notify;
  577. return _apexZone.Notify;
  578. }
  579. set
  580. {
  581. if (_apexZone is null)
  582. throw new InvalidOperationException();
  583. _apexZone.Notify = value;
  584. }
  585. }
  586. public IReadOnlyCollection<IPAddress> NotifyNameServers
  587. {
  588. get
  589. {
  590. if (_apexZone is null)
  591. return _notifyNameServers;
  592. return _apexZone.NotifyNameServers;
  593. }
  594. set
  595. {
  596. if (_apexZone is null)
  597. throw new InvalidOperationException();
  598. _apexZone.NotifyNameServers = value;
  599. }
  600. }
  601. public AuthZoneUpdate Update
  602. {
  603. get
  604. {
  605. if (_apexZone is null)
  606. return _update;
  607. return _apexZone.Update;
  608. }
  609. set
  610. {
  611. if (_apexZone is null)
  612. throw new InvalidOperationException();
  613. _apexZone.Update = value;
  614. }
  615. }
  616. public IReadOnlyCollection<IPAddress> UpdateIpAddresses
  617. {
  618. get
  619. {
  620. if (_apexZone is null)
  621. return _updateIpAddresses;
  622. return _apexZone.UpdateIpAddresses;
  623. }
  624. set
  625. {
  626. if (_apexZone is null)
  627. throw new InvalidOperationException();
  628. _apexZone.UpdateIpAddresses = value;
  629. }
  630. }
  631. public DateTime Expiry
  632. {
  633. get
  634. {
  635. if (_apexZone is null)
  636. return _expiry;
  637. switch (_type)
  638. {
  639. case AuthZoneType.Secondary:
  640. return (_apexZone as SecondaryZone).Expiry;
  641. case AuthZoneType.Stub:
  642. return (_apexZone as StubZone).Expiry;
  643. default:
  644. throw new InvalidOperationException();
  645. }
  646. }
  647. }
  648. public IReadOnlyList<DnsResourceRecord> ZoneHistory
  649. {
  650. get
  651. {
  652. if (_apexZone is null)
  653. return _zoneHistory;
  654. return _apexZone.GetZoneHistory();
  655. }
  656. }
  657. public IReadOnlyDictionary<string, object> ZoneTransferTsigKeyNames
  658. {
  659. get
  660. {
  661. if (_apexZone is null)
  662. return _zoneTransferTsigKeyNames;
  663. return _apexZone.ZoneTransferTsigKeyNames;
  664. }
  665. set
  666. {
  667. if (_apexZone is null)
  668. throw new InvalidOperationException();
  669. switch (_type)
  670. {
  671. case AuthZoneType.Primary:
  672. case AuthZoneType.Secondary:
  673. _apexZone.ZoneTransferTsigKeyNames = value;
  674. break;
  675. default:
  676. throw new InvalidOperationException();
  677. }
  678. }
  679. }
  680. public IReadOnlyDictionary<string, IReadOnlyDictionary<string, IReadOnlyList<DnsResourceRecordType>>> UpdateSecurityPolicies
  681. {
  682. get
  683. {
  684. if (_apexZone is null)
  685. return _updateSecurityPolicies;
  686. return _apexZone.UpdateSecurityPolicies;
  687. }
  688. set
  689. {
  690. if (_apexZone is null)
  691. throw new InvalidOperationException();
  692. switch (_type)
  693. {
  694. case AuthZoneType.Primary:
  695. _apexZone.UpdateSecurityPolicies = value;
  696. break;
  697. default:
  698. throw new InvalidOperationException();
  699. }
  700. }
  701. }
  702. public IReadOnlyCollection<DnssecPrivateKey> DnssecPrivateKeys
  703. {
  704. get
  705. {
  706. if (_apexZone is null)
  707. return _dnssecPrivateKeys;
  708. switch (_type)
  709. {
  710. case AuthZoneType.Primary:
  711. return (_apexZone as PrimaryZone).DnssecPrivateKeys;
  712. default:
  713. throw new InvalidOperationException();
  714. }
  715. }
  716. }
  717. public AuthZoneDnssecStatus DnssecStatus
  718. {
  719. get
  720. {
  721. if (_apexZone is null)
  722. throw new InvalidOperationException();
  723. return _apexZone.DnssecStatus;
  724. }
  725. }
  726. public uint DnsKeyTtl
  727. {
  728. get
  729. {
  730. if (_apexZone is null)
  731. throw new InvalidOperationException();
  732. switch (_type)
  733. {
  734. case AuthZoneType.Primary:
  735. return (_apexZone as PrimaryZone).GetDnsKeyTtl();
  736. default:
  737. throw new InvalidOperationException();
  738. }
  739. }
  740. }
  741. public bool Internal
  742. {
  743. get
  744. {
  745. if (_apexZone is null)
  746. throw new InvalidOperationException();
  747. switch (_type)
  748. {
  749. case AuthZoneType.Primary:
  750. return (_apexZone as PrimaryZone).Internal;
  751. default:
  752. return false;
  753. }
  754. }
  755. }
  756. public bool IsExpired
  757. {
  758. get
  759. {
  760. if (_apexZone is null)
  761. throw new InvalidOperationException();
  762. switch (_type)
  763. {
  764. case AuthZoneType.Secondary:
  765. return (_apexZone as SecondaryZone).IsExpired;
  766. case AuthZoneType.Stub:
  767. return (_apexZone as StubZone).IsExpired;
  768. default:
  769. return false;
  770. }
  771. }
  772. }
  773. public bool NotifyFailed
  774. {
  775. get
  776. {
  777. if (_apexZone is null)
  778. throw new InvalidOperationException();
  779. switch (_type)
  780. {
  781. case AuthZoneType.Primary:
  782. return (_apexZone as PrimaryZone).NotifyFailed;
  783. case AuthZoneType.Secondary:
  784. return (_apexZone as SecondaryZone).NotifyFailed;
  785. default:
  786. throw new InvalidOperationException();
  787. }
  788. }
  789. }
  790. public bool SyncFailed
  791. {
  792. get
  793. {
  794. if (_apexZone is null)
  795. throw new InvalidOperationException();
  796. switch (_type)
  797. {
  798. case AuthZoneType.Secondary:
  799. return (_apexZone as SecondaryZone).SyncFailed;
  800. case AuthZoneType.Stub:
  801. return (_apexZone as StubZone).SyncFailed;
  802. default:
  803. throw new InvalidOperationException();
  804. }
  805. }
  806. }
  807. #endregion
  808. }
  809. }