From 2b68be8997c447ab20c7c8d891ccd42d205997e6 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sat, 14 Sep 2024 16:41:38 +0530 Subject: [PATCH] DhcpServer: removed client domain case lowering to allow having same case records in DNS. Updated UpdateDnsAuthZone() to use updated AuthZoneManager calls. --- DnsServerCore/Dhcp/DhcpServer.cs | 39 ++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/DnsServerCore/Dhcp/DhcpServer.cs b/DnsServerCore/Dhcp/DhcpServer.cs index 5aae0925..9c149e0c 100644 --- a/DnsServerCore/Dhcp/DhcpServer.cs +++ b/DnsServerCore/Dhcp/DhcpServer.cs @@ -20,6 +20,7 @@ along with this program. If not, see . using DnsServerCore.Auth; using DnsServerCore.Dhcp.Options; using DnsServerCore.Dns; +using DnsServerCore.Dns.ResourceRecords; using DnsServerCore.Dns.Zones; using System; using System.Collections.Concurrent; @@ -496,7 +497,7 @@ namespace DnsServerCore.Dhcp if (!clientDomainName.Equals(leaseOffer.HostName, StringComparison.OrdinalIgnoreCase)) UpdateDnsAuthZone(false, scope, leaseOffer); //hostname changed! delete old hostname entry from DNS - leaseOffer.SetHostName(clientDomainName.ToLower()); + leaseOffer.SetHostName(clientDomainName); UpdateDnsAuthZone(true, scope, leaseOffer); } } @@ -732,7 +733,7 @@ namespace DnsServerCore.Dhcp if (zoneInfo is null) { //zone does not exists; create new primary zone - zoneInfo = _dnsServer.AuthZoneManager.CreatePrimaryZone(scope.DomainName, _dnsServer.ServerDomain, false); + zoneInfo = _dnsServer.AuthZoneManager.CreatePrimaryZone(scope.DomainName); if (zoneInfo is null) { _log?.Write("DHCP Server failed to create DNS primary zone '" + scope.DomainName + "'."); @@ -745,16 +746,15 @@ namespace DnsServerCore.Dhcp _authManager.SetPermission(PermissionSection.Zones, zoneInfo.Name, _authManager.GetGroup(Group.DHCP_ADMINISTRATORS), PermissionFlag.ViewModifyDelete); _authManager.SaveConfigFile(); - _log?.Write("DHCP Server create DNS primary zone '" + zoneInfo.Name + "'."); - _dnsServer.AuthZoneManager.SaveZoneFile(zoneInfo.Name); + _log?.Write("DHCP Server create DNS primary zone '" + zoneInfo.DisplayName + "'."); } else if ((zoneInfo.Type != AuthZoneType.Primary) && (zoneInfo.Type != AuthZoneType.Forwarder)) { if (zoneInfo.Name.Equals(scope.DomainName, StringComparison.OrdinalIgnoreCase)) - throw new DhcpServerException("Cannot update DNS zone '" + zoneInfo.Name + "': not a primary or a forwarder zone."); + throw new DhcpServerException("Cannot update DNS zone '" + zoneInfo.DisplayName + "': not a primary or a forwarder zone."); //create new primary zone - zoneInfo = _dnsServer.AuthZoneManager.CreatePrimaryZone(scope.DomainName, _dnsServer.ServerDomain, false); + zoneInfo = _dnsServer.AuthZoneManager.CreatePrimaryZone(scope.DomainName); if (zoneInfo is null) { _log?.Write("DHCP Server failed to create DNS primary zone '" + scope.DomainName + "'."); @@ -767,8 +767,7 @@ namespace DnsServerCore.Dhcp _authManager.SetPermission(PermissionSection.Zones, zoneInfo.Name, _authManager.GetGroup(Group.DHCP_ADMINISTRATORS), PermissionFlag.ViewModifyDelete); _authManager.SaveConfigFile(); - _log?.Write("DHCP Server create DNS primary zone '" + zoneInfo.Name + "'."); - _dnsServer.AuthZoneManager.SaveZoneFile(zoneInfo.Name); + _log?.Write("DHCP Server create DNS primary zone '" + zoneInfo.DisplayName + "'."); } zoneName = zoneInfo.Name; @@ -793,7 +792,10 @@ namespace DnsServerCore.Dhcp } } - _dnsServer.AuthZoneManager.SetRecords(zoneName, domain, DnsResourceRecordType.A, scope.DnsTtl, new DnsResourceRecordData[] { new DnsARecordData(address) }); + DnsResourceRecord aRecord = new DnsResourceRecord(domain, DnsResourceRecordType.A, DnsClass.IN, scope.DnsTtl, new DnsARecordData(address)); + aRecord.GetAuthGenericRecordInfo().LastModified = DateTime.UtcNow; + + _dnsServer.AuthZoneManager.SetRecord(zoneName, aRecord); _log?.Write("DHCP Server updated DNS A record '" + domain + "' with IP address [" + address.ToString() + "]."); //update reverse zone @@ -803,7 +805,7 @@ namespace DnsServerCore.Dhcp string reverseZone = Zone.GetReverseZone(address, scope.SubnetMask); //reverse zone does not exists; create new reverse primary zone - reverseZoneInfo = _dnsServer.AuthZoneManager.CreatePrimaryZone(reverseZone, _dnsServer.ServerDomain, false); + reverseZoneInfo = _dnsServer.AuthZoneManager.CreatePrimaryZone(reverseZone); if (reverseZoneInfo is null) { _log?.Write("DHCP Server failed to create DNS primary zone '" + reverseZone + "'."); @@ -816,18 +818,17 @@ namespace DnsServerCore.Dhcp _authManager.SetPermission(PermissionSection.Zones, reverseZoneInfo.Name, _authManager.GetGroup(Group.DHCP_ADMINISTRATORS), PermissionFlag.ViewModifyDelete); _authManager.SaveConfigFile(); - _log?.Write("DHCP Server create DNS primary zone '" + reverseZoneInfo.Name + "'."); - _dnsServer.AuthZoneManager.SaveZoneFile(reverseZoneInfo.Name); + _log?.Write("DHCP Server create DNS primary zone '" + reverseZoneInfo.DisplayName + "'."); } else if ((reverseZoneInfo.Type != AuthZoneType.Primary) && (reverseZoneInfo.Type != AuthZoneType.Forwarder)) { string reverseZone = Zone.GetReverseZone(address, scope.SubnetMask); if (reverseZoneInfo.Name.Equals(reverseZone, StringComparison.OrdinalIgnoreCase)) - throw new DhcpServerException("Cannot update reverse DNS zone '" + reverseZoneInfo.Name + "': not a primary or a forwarder zone."); + throw new DhcpServerException("Cannot update reverse DNS zone '" + reverseZoneInfo.DisplayName + "': not a primary or a forwarder zone."); //create new reverse primary zone - reverseZoneInfo = _dnsServer.AuthZoneManager.CreatePrimaryZone(reverseZone, _dnsServer.ServerDomain, false); + reverseZoneInfo = _dnsServer.AuthZoneManager.CreatePrimaryZone(reverseZone); if (reverseZoneInfo is null) { _log?.Write("DHCP Server failed to create DNS primary zone '" + reverseZone + "'."); @@ -840,12 +841,16 @@ namespace DnsServerCore.Dhcp _authManager.SetPermission(PermissionSection.Zones, reverseZoneInfo.Name, _authManager.GetGroup(Group.DHCP_ADMINISTRATORS), PermissionFlag.ViewModifyDelete); _authManager.SaveConfigFile(); - _log?.Write("DHCP Server create DNS primary zone '" + reverseZoneInfo.Name + "'."); - _dnsServer.AuthZoneManager.SaveZoneFile(reverseZoneInfo.Name); + _log?.Write("DHCP Server create DNS primary zone '" + reverseZoneInfo.DisplayName + "'."); } reverseZoneName = reverseZoneInfo.Name; - _dnsServer.AuthZoneManager.SetRecords(reverseZoneName, reverseDomain, DnsResourceRecordType.PTR, scope.DnsTtl, new DnsResourceRecordData[] { new DnsPTRRecordData(domain) }); + + DnsResourceRecord ptrRecord = new DnsResourceRecord(reverseDomain, DnsResourceRecordType.PTR, DnsClass.IN, scope.DnsTtl, new DnsPTRRecordData(domain)); + ptrRecord.GetAuthGenericRecordInfo().LastModified = DateTime.UtcNow; + + _dnsServer.AuthZoneManager.SetRecord(reverseZoneName, ptrRecord); + _log?.Write("DHCP Server updated DNS PTR record '" + reverseDomain + "' with domain name '" + domain + "'."); } else