From 4a876557b7f02230f70d95e6d53b22cd64b0fae2 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sat, 27 Feb 2021 19:22:30 +0530 Subject: [PATCH] added ApplicationZone --- DnsServerCore/Dns/Zones/ApplicationZone.cs | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 DnsServerCore/Dns/Zones/ApplicationZone.cs diff --git a/DnsServerCore/Dns/Zones/ApplicationZone.cs b/DnsServerCore/Dns/Zones/ApplicationZone.cs new file mode 100644 index 00000000..83ce1efa --- /dev/null +++ b/DnsServerCore/Dns/Zones/ApplicationZone.cs @@ -0,0 +1,86 @@ +/* +Technitium DNS Server +Copyright (C) 2021 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 . + +*/ + +using System; +using System.Collections.Generic; +using TechnitiumLibrary.Net.Dns; +using TechnitiumLibrary.Net.Dns.ResourceRecords; + +namespace DnsServerCore.Dns.Zones +{ + class ApplicationZone : AuthZone + { + #region constructor + + public ApplicationZone(AuthZoneInfo zoneInfo) + : base(zoneInfo.Name) + { + _disabled = zoneInfo.Disabled; + } + + public ApplicationZone(string name, string package, string classPath, string data) + : base(name) + { + DnsResourceRecord appRecord = new DnsResourceRecord(name, DnsResourceRecordType.APP, DnsClass.IN, 60, new DnsApplicationRecord(package, classPath, data)); + + _entries[DnsResourceRecordType.APP] = new DnsResourceRecord[] { appRecord }; + } + + #endregion + + #region public + + public override void SetRecords(DnsResourceRecordType type, IReadOnlyList records) + { + switch (type) + { + case DnsResourceRecordType.CNAME: + throw new InvalidOperationException("Cannot set CNAME record to zone root."); + + case DnsResourceRecordType.NS: + throw new InvalidOperationException("Cannot set NS record to application zone root."); + + case DnsResourceRecordType.SOA: + throw new InvalidOperationException("Cannot set SOA record to application zone root."); + + default: + base.SetRecords(type, records); + break; + } + } + + public override void AddRecord(DnsResourceRecord record) + { + switch (record.Type) + { + case DnsResourceRecordType.APP: + throw new InvalidOperationException("Cannot add record: use SetRecords() for " + record.Type.ToString() + " record"); + + case DnsResourceRecordType.NS: + throw new InvalidOperationException("Cannot add NS record at application zone root."); + + default: + base.AddRecord(record); + break; + } + } + + #endregion + } +}