[DHCPCSVC] DhcpHandlePnPEvent: Set the binary class id

Also add a bit of documentation
This commit is contained in:
Eric Kohl
2026-03-08 23:04:22 +01:00
parent fb22bd74c6
commit 1f8f73d3b2

View File

@@ -88,6 +88,116 @@ PDHCP_SERVER_NAME_unbind(
}
}
static
DWORD
SetBinaryClassId(
_In_ PWSTR pszAdapterName)
{
WCHAR szKeyName[256];
PWSTR pszUnicodeBuffer = NULL;
PSZ pszAnsiBuffer = NULL;
DWORD dwUnicodeSize = 0, dwAnsiSize = 0;
HKEY hKey = NULL;
DWORD dwError = ERROR_SUCCESS;
DPRINT("SetBinaryClassId(%S)\n", pszAdapterName);
_swprintf(szKeyName,
L"System\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\%s",
pszAdapterName);
DPRINT("KeyName %S\n", szKeyName);
dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
szKeyName,
0,
KEY_QUERY_VALUE | KEY_SET_VALUE,
&hKey);
if (dwError != ERROR_SUCCESS)
{
DPRINT1("Error %lu\n", dwError);
return dwError;
}
RegQueryValueExW(hKey,
L"DhcpClassId",
NULL,
NULL,
NULL,
&dwUnicodeSize);
DPRINT("UnicodeSize %lu\n", dwUnicodeSize);
pszUnicodeBuffer = HeapAlloc(GetProcessHeap(), 0, dwUnicodeSize);
if (pszUnicodeBuffer == NULL)
{
dwError = ERROR_NOT_ENOUGH_MEMORY;
DPRINT1("Error %lu\n", dwError);
goto done;
}
dwError = RegQueryValueExW(hKey,
L"DhcpClassId",
NULL,
NULL,
(PBYTE)pszUnicodeBuffer,
&dwUnicodeSize);
if (dwError != ERROR_SUCCESS)
{
DPRINT1("Error %lu\n", dwError);
goto done;
}
dwAnsiSize = WideCharToMultiByte(CP_ACP,
0,
pszUnicodeBuffer,
-1,
NULL,
0,
NULL,
NULL);
DPRINT("AnsiSize %lu\n", dwAnsiSize);
pszAnsiBuffer = HeapAlloc(GetProcessHeap(), 0, dwAnsiSize);
if (pszAnsiBuffer == NULL)
{
dwError = ERROR_NOT_ENOUGH_MEMORY;
DPRINT1("Error %lu\n", dwError);
goto done;
}
WideCharToMultiByte(CP_ACP,
0,
pszUnicodeBuffer,
-1,
pszAnsiBuffer,
dwAnsiSize,
NULL,
NULL);
DPRINT("AnsiBuffer %s\n", pszAnsiBuffer);
dwError = RegSetValueExW(hKey,
L"DhcpClassIdBin",
0,
REG_BINARY,
(PBYTE)pszAnsiBuffer,
strlen(pszAnsiBuffer));
if (dwError != ERROR_SUCCESS)
{
DPRINT1("Error %lu\n", dwError);
}
done:
if (hKey)
RegCloseKey(hKey);
if (pszAnsiBuffer)
HeapFree(GetProcessHeap(), 0, pszAnsiBuffer);
if (pszUnicodeBuffer)
HeapFree(GetProcessHeap(), 0, pszUnicodeBuffer);
return dwError;
}
/*!
* Initializes the DHCP interface
*
@@ -150,6 +260,25 @@ DhcpAcquireParameters(
return ret;
}
/*!
* Enumerates the DHCP user classes for the given adapter
*
* \param[in] Unknown1
* Unknown
*
* \param[in] AdapterName
* Name (GUID) of the Adapter
*
* \param[in] Unknown3
* Unknown
*
* \param[in] Unknown4
* Unknown
*
* \return ERROR_SUCCESS on success
*
* \remarks Undocumented by Microsoft
*/
DWORD
APIENTRY
DhcpEnumClasses(
@@ -163,6 +292,28 @@ DhcpEnumClasses(
return 0;
}
/*!
* Enumerates the DHCP user classes for the given adapter
*
* \param[in] Unknown1
* Unknown
*
* \param[in] Unknown2
* Unknown
*
* \param[in] AdapterName
* Name (GUID) of the Adapter
*
* \param[in] PnpEvent
* Unknown
*
* \param[in] Unknown5
* Unknown
*
* \return ERROR_SUCCESS on success
*
* \remarks Undocumented by Microsoft
*/
DWORD
APIENTRY
DhcpHandlePnPEvent(
@@ -172,13 +323,20 @@ DhcpHandlePnPEvent(
_In_ PDHCP_PNP_EVENT PnpEvent,
_In_ DWORD Unknown5)
{
DWORD dwError = ERROR_SUCCESS;
DPRINT1("DhcpHandlePnPEvent(%lx %lx %S %p %lx)\n",
Unknown1, Unknown2, AdapterName, PnpEvent, Unknown5);
if ((Unknown1 != 0) || (Unknown2 != 1) || (PnpEvent == NULL) || (Unknown5 != 0))
return ERROR_INVALID_PARAMETER;
return 0;
if (PnpEvent->Unknown5)
{
dwError = SetBinaryClassId(AdapterName);
}
return dwError;
}
/*!