mirror of
https://github.com/fergalmoran/DnsServer.git
synced 2026-05-24 03:56:07 +00:00
removed application zone
This commit is contained in:
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using TechnitiumLibrary.Net.Dns;
|
||||
|
||||
namespace DnsServerCore.Dns.Zones
|
||||
{
|
||||
class ApplicationSubDomainZone : SubDomainZone
|
||||
{
|
||||
#region variables
|
||||
|
||||
readonly ApplicationZone _applicationZone;
|
||||
|
||||
#endregion
|
||||
|
||||
#region constructor
|
||||
|
||||
public ApplicationSubDomainZone(ApplicationZone applicationZone, string name)
|
||||
: base(name)
|
||||
{
|
||||
_applicationZone = applicationZone;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public
|
||||
|
||||
public override void SetRecords(DnsResourceRecordType type, IReadOnlyList<DnsResourceRecord> records)
|
||||
{
|
||||
base.SetRecords(type, records);
|
||||
|
||||
_applicationZone.IncrementSoaSerial();
|
||||
}
|
||||
|
||||
public override void AddRecord(DnsResourceRecord record)
|
||||
{
|
||||
base.AddRecord(record);
|
||||
|
||||
_applicationZone.IncrementSoaSerial();
|
||||
}
|
||||
|
||||
public override bool DeleteRecords(DnsResourceRecordType type)
|
||||
{
|
||||
if (base.DeleteRecords(type))
|
||||
{
|
||||
_applicationZone.IncrementSoaSerial();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool DeleteRecord(DnsResourceRecordType type, DnsResourceRecordData record)
|
||||
{
|
||||
if (base.DeleteRecord(type, record))
|
||||
{
|
||||
_applicationZone.IncrementSoaSerial();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,132 +0,0 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
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 primaryNameServer, string appName, string classPath, string data)
|
||||
: base(name)
|
||||
{
|
||||
DnsSOARecord soa = new DnsSOARecord(primaryNameServer, _name.Length == 0 ? "hostadmin" : "hostadmin." + _name, 1, 14400, 3600, 604800, 900);
|
||||
|
||||
_entries[DnsResourceRecordType.SOA] = new DnsResourceRecord[] { new DnsResourceRecord(_name, DnsResourceRecordType.SOA, DnsClass.IN, soa.Refresh, soa) };
|
||||
_entries[DnsResourceRecordType.NS] = new DnsResourceRecord[] { new DnsResourceRecord(_name, DnsResourceRecordType.NS, DnsClass.IN, soa.Refresh, new DnsNSRecord(soa.PrimaryNameServer)) };
|
||||
|
||||
DnsResourceRecord appRecord = new DnsResourceRecord(name, DnsResourceRecordType.APP, DnsClass.IN, 60, new DnsApplicationRecord(appName, classPath, data));
|
||||
|
||||
_entries[DnsResourceRecordType.APP] = new DnsResourceRecord[] { appRecord };
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region public
|
||||
|
||||
public void IncrementSoaSerial()
|
||||
{
|
||||
DnsResourceRecord record = _entries[DnsResourceRecordType.SOA][0];
|
||||
DnsSOARecord soa = record.RDATA as DnsSOARecord;
|
||||
|
||||
uint serial = soa.Serial;
|
||||
if (serial < uint.MaxValue)
|
||||
serial++;
|
||||
else
|
||||
serial = 0;
|
||||
|
||||
DnsResourceRecord newRecord = new DnsResourceRecord(record.Name, record.Type, record.Class, record.TtlValue, new DnsSOARecord(soa.PrimaryNameServer, soa.ResponsiblePerson, serial, soa.Refresh, soa.Retry, soa.Expire, soa.Minimum)) { Tag = record.Tag };
|
||||
_entries[DnsResourceRecordType.SOA] = new DnsResourceRecord[] { newRecord };
|
||||
}
|
||||
|
||||
public override void SetRecords(DnsResourceRecordType type, IReadOnlyList<DnsResourceRecord> records)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case DnsResourceRecordType.CNAME:
|
||||
throw new InvalidOperationException("Cannot set CNAME record to zone root.");
|
||||
|
||||
case DnsResourceRecordType.SOA:
|
||||
if ((records.Count != 1) || !records[0].Name.Equals(_name, StringComparison.OrdinalIgnoreCase))
|
||||
throw new InvalidOperationException("Invalid SOA record.");
|
||||
|
||||
//remove any resource record info
|
||||
records[0].Tag = null;
|
||||
break;
|
||||
}
|
||||
|
||||
base.SetRecords(type, records);
|
||||
|
||||
IncrementSoaSerial();
|
||||
}
|
||||
|
||||
public override void AddRecord(DnsResourceRecord record)
|
||||
{
|
||||
if (record.Type == DnsResourceRecordType.APP)
|
||||
throw new InvalidOperationException("Cannot add record: use SetRecords() for " + record.Type.ToString() + " record");
|
||||
|
||||
base.AddRecord(record);
|
||||
|
||||
IncrementSoaSerial();
|
||||
}
|
||||
|
||||
public override bool DeleteRecords(DnsResourceRecordType type)
|
||||
{
|
||||
if (type == DnsResourceRecordType.SOA)
|
||||
throw new InvalidOperationException("Cannot delete SOA record.");
|
||||
|
||||
if (base.DeleteRecords(type))
|
||||
{
|
||||
IncrementSoaSerial();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool DeleteRecord(DnsResourceRecordType type, DnsResourceRecordData record)
|
||||
{
|
||||
if (type == DnsResourceRecordType.SOA)
|
||||
throw new InvalidOperationException("Cannot delete SOA record.");
|
||||
|
||||
if (base.DeleteRecord(type, record))
|
||||
{
|
||||
IncrementSoaSerial();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -96,7 +96,7 @@ namespace DnsServerCore.Dns.Zones
|
||||
return newRecords;
|
||||
}
|
||||
|
||||
private async Task<IReadOnlyList<NameServerAddress>> GetNameServerAddressesAsync(DnsServer dnsServer, DnsResourceRecord record)
|
||||
private static async Task<IReadOnlyList<NameServerAddress>> GetNameServerAddressesAsync(DnsServer dnsServer, DnsResourceRecord record)
|
||||
{
|
||||
string nsDomain;
|
||||
|
||||
@@ -243,9 +243,9 @@ namespace DnsServerCore.Dns.Zones
|
||||
}
|
||||
|
||||
//set new entries into zone
|
||||
if ((this is ForwarderZone) || (this is ApplicationZone))
|
||||
if (this is ForwarderZone)
|
||||
{
|
||||
//skip NS and SOA records from being added to ForwarderZone or ApplicationZone
|
||||
//skip NS and SOA records from being added to ForwarderZone
|
||||
foreach (KeyValuePair<DnsResourceRecordType, List<DnsResourceRecord>> newEntry in newEntries)
|
||||
{
|
||||
switch (newEntry.Key)
|
||||
|
||||
@@ -32,8 +32,7 @@ namespace DnsServerCore.Dns.Zones
|
||||
Primary = 1,
|
||||
Secondary = 2,
|
||||
Stub = 3,
|
||||
Forwarder = 4,
|
||||
Application = 5
|
||||
Forwarder = 4
|
||||
}
|
||||
|
||||
public sealed class AuthZoneInfo : IComparable<AuthZoneInfo>
|
||||
@@ -98,8 +97,6 @@ namespace DnsServerCore.Dns.Zones
|
||||
_type = AuthZoneType.Stub;
|
||||
else if (_zone is ForwarderZone)
|
||||
_type = AuthZoneType.Forwarder;
|
||||
else if (_zone is ApplicationZone)
|
||||
_type = AuthZoneType.Application;
|
||||
else
|
||||
_type = AuthZoneType.Unknown;
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace DnsServerCore.Dns.Zones
|
||||
if (zone is SubDomainZone)
|
||||
return child; //child has value so return it
|
||||
|
||||
if ((zone is PrimaryZone) || (zone is SecondaryZone) || (zone is StubZone) || (zone is ForwarderZone) || (zone is ApplicationZone))
|
||||
if ((zone is PrimaryZone) || (zone is SecondaryZone) || (zone is StubZone) || (zone is ForwarderZone))
|
||||
{
|
||||
//skip to next child to avoid listing this auth zone's sub domains
|
||||
child = null; //set null to avoid child being set as current after the loop
|
||||
@@ -262,7 +262,7 @@ namespace DnsServerCore.Dns.Zones
|
||||
{
|
||||
if (zoneValue is AuthZone)
|
||||
{
|
||||
if ((zoneValue is PrimaryZone) || (zoneValue is SecondaryZone) || (zoneValue is StubZone) || (zoneValue is ForwarderZone) || (zoneValue is ApplicationZone))
|
||||
if ((zoneValue is PrimaryZone) || (zoneValue is SecondaryZone) || (zoneValue is StubZone) || (zoneValue is ForwarderZone))
|
||||
{
|
||||
if (IsKeySubDomain(value.Key, key))
|
||||
{
|
||||
@@ -435,7 +435,7 @@ namespace DnsServerCore.Dns.Zones
|
||||
{
|
||||
if (TryRemove(domain, out value, out Node closestNode))
|
||||
{
|
||||
if ((value != null) && ((value is PrimaryZone) || (value is SecondaryZone) || (value is StubZone) || (value is ForwarderZone) || (value is ApplicationZone)))
|
||||
if ((value != null) && ((value is PrimaryZone) || (value is SecondaryZone) || (value is StubZone) || (value is ForwarderZone)))
|
||||
{
|
||||
//remove all sub domains under current zone
|
||||
Node current = closestNode;
|
||||
@@ -483,7 +483,7 @@ namespace DnsServerCore.Dns.Zones
|
||||
T zone = nodeValue.Value;
|
||||
if (zone != null)
|
||||
{
|
||||
if ((zone is PrimaryZone) || (zone is SecondaryZone) || (zone is StubZone) || (zone is ForwarderZone) || (zone is ApplicationZone))
|
||||
if ((zone is PrimaryZone) || (zone is SecondaryZone) || (zone is StubZone) || (zone is ForwarderZone))
|
||||
{
|
||||
zones.Add(zone);
|
||||
|
||||
@@ -606,7 +606,7 @@ namespace DnsServerCore.Dns.Zones
|
||||
//zone found
|
||||
if (zoneValue is AuthZone)
|
||||
{
|
||||
if ((zoneValue is PrimaryZone) || (zoneValue is SecondaryZone) || (zoneValue is StubZone) || (zoneValue is ForwarderZone) || (zoneValue is ApplicationZone))
|
||||
if ((zoneValue is PrimaryZone) || (zoneValue is SecondaryZone) || (zoneValue is StubZone) || (zoneValue is ForwarderZone))
|
||||
{
|
||||
delegation = null;
|
||||
authority = zoneValue;
|
||||
|
||||
Reference in New Issue
Block a user