From 0bd6b3dd5812886de497b395cb1c7bcfdde4aa9e Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Wed, 13 Aug 2025 14:57:59 +0200 Subject: [PATCH] [DHCPCSVC][PSDK] Clean up, add some documentation and missing declarations --- base/services/dhcpcsvc/dhcpcsvc.c | 173 +++++++++++++++++++----------- sdk/include/psdk/dhcpcapi.h | 31 +++--- sdk/include/psdk/dhcpcsdk.h | 4 + 3 files changed, 133 insertions(+), 75 deletions(-) diff --git a/base/services/dhcpcsvc/dhcpcsvc.c b/base/services/dhcpcsvc/dhcpcsvc.c index b2b0a16430f..948110b2944 100644 --- a/base/services/dhcpcsvc/dhcpcsvc.c +++ b/base/services/dhcpcsvc/dhcpcsvc.c @@ -87,22 +87,46 @@ PDHCP_SERVER_NAME_unbind( } } - +/*! + * Initializes the DHCP interface + * + * \param[out] Version + * Returns the DHCP Interface Version + * + * \return ERROR_SUCCESS on success + * + * \remarks DhcpCApiInitialized must be called before any other DHCP Function. + */ DWORD APIENTRY DhcpCApiInitialize( _Out_ LPDWORD Version) { *Version = 2; - return NO_ERROR; + return ERROR_SUCCESS; } +/*! + * Cleans up the DHCP interface + * + * \remarks Other DHCP Functions must not be called after DhcpCApiCleanup. + */ VOID APIENTRY DhcpCApiCleanup(VOID) { } +/*! + * Renews a DHCP Lease + * + * \param[in] AdapterName + * Name (GUID) of the Adapter + * + * \return ERROR_SUCCESS on success + * + * \remarks Undocumented by Microsoft + */ DWORD APIENTRY DhcpAcquireParameters( @@ -125,28 +149,6 @@ DhcpAcquireParameters( return ret; } -DWORD -APIENTRY -DhcpReleaseParameters( - _In_ PWSTR AdapterName) -{ - DWORD ret; - - DPRINT("DhcpReleaseParameters(%S)\n", AdapterName); - - RpcTryExcept - { - ret = Client_ReleaseParameters(NULL, AdapterName); - } - RpcExcept(EXCEPTION_EXECUTE_HANDLER) - { - ret = I_RpcMapWin32Status(RpcExceptionCode()); - } - RpcEndExcept; - - return ret; -} - DWORD APIENTRY DhcpEnumClasses( @@ -174,6 +176,58 @@ DhcpHandlePnPEvent( return 0; } +/*! + * Set new TCP/IP parameters and notify DHCP client service of this + * + * \param[in] ServerName + * NULL for local machine + * + * \param[in] AdapterName + * IPHLPAPI name of adapter to change + * + * \param[in] NewIpAddress + * TRUE if IP address changes + + * \param[in] IpIndex + * ... + * + * \param[in] IpAddress + * New IP address (network byte order) + * + * \param[in] SubnetMask + * New subnet mask (network byte order) + * + * \param[in] DhcpAction + * 0 - don't modify + * 1 - enable DHCP + * 2 - disable DHCP + * + * \return ERROR_SUCCESS on success + * + * \remarks Undocumented by Microsoft + */ +DWORD +APIENTRY +DhcpNotifyConfigChange( + _In_ LPWSTR ServerName, + _In_ LPWSTR AdapterName, + _In_ BOOL NewIpAddress, + _In_ DWORD IpIndex, + _In_ DWORD IpAddress, + _In_ DWORD SubnetMask, + _In_ INT DhcpAction) +{ + DPRINT1("DHCPCSVC: DhcpNotifyConfigChange not implemented yet\n"); + DPRINT1("DhcpNotifyConfigChange(%S %S %lu %lu %lu %lu %d)\n", + ServerName, AdapterName, NewIpAddress, IpIndex, IpAddress, SubnetMask, DhcpAction); + + if (AdapterName == NULL) + return ERROR_INVALID_PARAMETER; + + UNIMPLEMENTED; + return ERROR_SUCCESS; +} + DWORD APIENTRY DhcpQueryHWInfo(DWORD AdapterIndex, PDWORD MediaType, @@ -197,6 +251,38 @@ DhcpQueryHWInfo(DWORD AdapterIndex, return (ret == ERROR_SUCCESS) ? 1 : 0; } +/*! + * Releases a DHCP Lease + * + * \param[in] AdapterName + * Name (GUID) of the Adapter + * + * \return ERROR_SUCCESS on success + * + * \remarks Undocumented by Microsoft + */ +DWORD +APIENTRY +DhcpReleaseParameters( + _In_ PWSTR AdapterName) +{ + DWORD ret; + + DPRINT("DhcpReleaseParameters(%S)\n", AdapterName); + + RpcTryExcept + { + ret = Client_ReleaseParameters(NULL, AdapterName); + } + RpcExcept(EXCEPTION_EXECUTE_HANDLER) + { + ret = I_RpcMapWin32Status(RpcExceptionCode()); + } + RpcEndExcept; + + return ret; +} + DWORD APIENTRY DhcpStaticRefreshParams(DWORD AdapterIndex, @@ -220,45 +306,6 @@ DhcpStaticRefreshParams(DWORD AdapterIndex, return (ret == ERROR_SUCCESS) ? 1 : 0; } -/*! - * Set new TCP/IP parameters and notify DHCP client service of this - * - * \param[in] ServerName - * NULL for local machine - * - * \param[in] AdapterName - * IPHLPAPI name of adapter to change - * - * \param[in] NewIpAddress - * TRUE if IP address changes - * - * \param[in] IpAddress - * New IP address (network byte order) - * - * \param[in] SubnetMask - * New subnet mask (network byte order) - * - * \param[in] DhcpAction - * 0 - don't modify - * 1 - enable DHCP - * 2 - disable DHCP - * - * \return non-zero on success - * - * \remarks Undocumented by Microsoft - */ -DWORD APIENTRY -DhcpNotifyConfigChange(LPWSTR ServerName, - LPWSTR AdapterName, - BOOL NewIpAddress, - DWORD IpIndex, - DWORD IpAddress, - DWORD SubnetMask, - INT DhcpAction) -{ - DPRINT1("DHCPCSVC: DhcpNotifyConfigChange not implemented yet\n"); - return 0; -} DWORD APIENTRY DhcpRequestParams(DWORD Flags, diff --git a/sdk/include/psdk/dhcpcapi.h b/sdk/include/psdk/dhcpcapi.h index 960860eeb6f..6a90f6267de 100644 --- a/sdk/include/psdk/dhcpcapi.h +++ b/sdk/include/psdk/dhcpcapi.h @@ -27,26 +27,33 @@ DhcpHandlePnPEvent( _In_ DWORD Unknown4, _In_ DWORD Unknown5); +DWORD +APIENTRY +DhcpNotifyConfigChange( + _In_ LPWSTR ServerName, + _In_ LPWSTR AdapterName, + _In_ BOOL NewIpAddress, + _In_ DWORD IpIndex, + _In_ DWORD IpAddress, + _In_ DWORD SubnetMask, + _In_ INT DhcpAction); + +DWORD +APIENTRY +DhcpQueryHWInfo( + _In_ DWORD AdapterIndex, + _Out_ PDWORD MediaType, + _Out_ PDWORD Mtu, + _Out_ PDWORD Speed); + DWORD APIENTRY DhcpReleaseParameters( _In_ PWSTR AdapterName); -DWORD APIENTRY DhcpQueryHWInfo( DWORD AdapterIndex, - PDWORD MediaType, - PDWORD Mtu, - PDWORD Speed ); DWORD APIENTRY DhcpStaticRefreshParams( DWORD AdapterIndex, DWORD Address, DWORD Netmask ); -DWORD APIENTRY -DhcpNotifyConfigChange(LPWSTR ServerName, - LPWSTR AdapterName, - BOOL NewIpAddress, - DWORD IpIndex, - DWORD IpAddress, - DWORD SubnetMask, - int DhcpAction); #ifdef __cplusplus } diff --git a/sdk/include/psdk/dhcpcsdk.h b/sdk/include/psdk/dhcpcsdk.h index 8f96a8212d4..6a4b64faea8 100644 --- a/sdk/include/psdk/dhcpcsdk.h +++ b/sdk/include/psdk/dhcpcsdk.h @@ -119,7 +119,11 @@ typedef struct _DHCPCAPI_CLASSID void WINAPI DhcpCApiCleanup(void); DWORD WINAPI DhcpCApiInitialize(DWORD *); +DWORD WINAPI DhcpDeRegisterParamChange(DWORD, void *, void *); +DWORD WINAPI DhcpRegisterParamChange(DWORD, LPVOID, LPWSTR, LPDHCPCAPI_CLASSID, DHCPCAPI_PARAMS_ARRAY, LPVOID); +DWORD WINAPI DhcpRemoveDNSRegistrations(VOID); DWORD WINAPI DhcpRequestParams(DWORD, void *, WCHAR *, DHCPCAPI_CLASSID *, DHCPCAPI_PARAMS_ARRAY, DHCPCAPI_PARAMS_ARRAY, BYTE *, DWORD *, WCHAR *); +DWORD WINAPI DhcpUndoRequestParams(DWORD, LPVOID, LPWSTR, LPWSTR); #endif