From dce60e2a29deac6625154756c61922dc5b8f2cad Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sat, 30 Apr 2022 13:04:36 +0530 Subject: [PATCH] WebServiceDhcpApi: Updated RemoveDhcpLease() to directly find scope and use its methods. Updated ConvertToReservedLease() and ConvertToDynamicLease() methods to support using both hardware address and client identifier. --- DnsServerCore/WebServiceDhcpApi.cs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/DnsServerCore/WebServiceDhcpApi.cs b/DnsServerCore/WebServiceDhcpApi.cs index cb621d0d..eeaac0c9 100644 --- a/DnsServerCore/WebServiceDhcpApi.cs +++ b/DnsServerCore/WebServiceDhcpApi.cs @@ -697,13 +697,17 @@ namespace DnsServerCore if (string.IsNullOrEmpty(scopeName)) throw new DnsWebServiceException("Parameter 'name' missing."); + Scope scope = _dnsWebService.DhcpServer.GetScope(scopeName); + if (scope is null) + throw new DnsWebServiceException("DHCP scope does not exists: " + scopeName); + string strClientIdentifier = request.QueryString["clientIdentifier"]; string strHardwareAddress = request.QueryString["hardwareAddress"]; if (!string.IsNullOrEmpty(strClientIdentifier)) - _dnsWebService.DhcpServer.RemoveLeaseByClientIdentifier(scopeName, strClientIdentifier); + scope.RemoveLease(ClientIdentifierOption.Parse(strClientIdentifier)); else if (!string.IsNullOrEmpty(strHardwareAddress)) - _dnsWebService.DhcpServer.RemoveLeaseByHardwareAddress(scopeName, strHardwareAddress); + scope.RemoveLease(strHardwareAddress); else throw new DnsWebServiceException("Parameter 'hardwareAddress' or 'clientIdentifier' missing. At least one of them must be specified."); @@ -722,11 +726,15 @@ namespace DnsServerCore if (scope == null) throw new DnsWebServiceException("DHCP scope does not exists: " + scopeName); + string strClientIdentifier = request.QueryString["clientIdentifier"]; string strHardwareAddress = request.QueryString["hardwareAddress"]; - if (string.IsNullOrEmpty(strHardwareAddress)) - throw new DnsWebServiceException("Parameter 'hardwareAddress' missing."); - scope.ConvertToReservedLease(strHardwareAddress); + if (!string.IsNullOrEmpty(strClientIdentifier)) + scope.ConvertToReservedLease(ClientIdentifierOption.Parse(strClientIdentifier)); + else if (!string.IsNullOrEmpty(strHardwareAddress)) + scope.ConvertToReservedLease(strHardwareAddress); + else + throw new DnsWebServiceException("Parameter 'hardwareAddress' or 'clientIdentifier' missing. At least one of them must be specified."); _dnsWebService.DhcpServer.SaveScope(scopeName); @@ -743,11 +751,15 @@ namespace DnsServerCore if (scope == null) throw new DnsWebServiceException("DHCP scope does not exists: " + scopeName); + string strClientIdentifier = request.QueryString["clientIdentifier"]; string strHardwareAddress = request.QueryString["hardwareAddress"]; - if (string.IsNullOrEmpty(strHardwareAddress)) - throw new DnsWebServiceException("Parameter 'hardwareAddress' missing."); - scope.ConvertToDynamicLease(strHardwareAddress); + if (!string.IsNullOrEmpty(strClientIdentifier)) + scope.ConvertToDynamicLease(ClientIdentifierOption.Parse(strClientIdentifier)); + else if (!string.IsNullOrEmpty(strHardwareAddress)) + scope.ConvertToDynamicLease(strHardwareAddress); + else + throw new DnsWebServiceException("Parameter 'hardwareAddress' or 'clientIdentifier' missing. At least one of them must be specified."); _dnsWebService.DhcpServer.SaveScope(scopeName);