From b39c55e5d22fa7f8192987d84dc5ded096287086 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sun, 8 Mar 2020 10:36:02 +0100 Subject: [PATCH] [UMPNPMGR] Implement PNP_DisableDevInst() --- base/services/umpnpmgr/rpcserver.c | 65 +++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/base/services/umpnpmgr/rpcserver.c b/base/services/umpnpmgr/rpcserver.c index 3ffd2e1988b..3dca54effe5 100644 --- a/base/services/umpnpmgr/rpcserver.c +++ b/base/services/umpnpmgr/rpcserver.c @@ -286,6 +286,52 @@ SetDeviceStatus( } +static +CONFIGRET +DisableDeviceInstance( + _In_ LPWSTR pszDeviceInstance, + _Inout_opt_ PPNP_VETO_TYPE pVetoType, + _Inout_opt_ LPWSTR pszVetoName, + _In_ DWORD ulNameLength) +{ + PLUGPLAY_CONTROL_QUERY_REMOVE_DATA QueryRemoveData; + CONFIGRET ret = CR_SUCCESS; + NTSTATUS Status; + + DPRINT1("DisableDeviceInstance(%S %p %p %lu)\n", + pszDeviceInstance, pVetoType, pszVetoName, ulNameLength); + + RtlInitUnicodeString(&QueryRemoveData.DeviceInstance, + pszDeviceInstance); + + QueryRemoveData.Flags = 0; + QueryRemoveData.VetoType = 0; + QueryRemoveData.VetoName = pszVetoName; + QueryRemoveData.NameLength = ulNameLength; + + Status = NtPlugPlayControl(PlugPlayControlQueryAndRemoveDevice, + &QueryRemoveData, + sizeof(PLUGPLAY_CONTROL_QUERY_REMOVE_DATA)); + if (Status == STATUS_NO_SUCH_DEVICE) + { + ret = CR_INVALID_DEVNODE; + } + else if (Status == STATUS_PLUGPLAY_QUERY_VETOED) + { + if (pVetoType != NULL) + *pVetoType = QueryRemoveData.VetoType; + + ret = CR_REMOVE_VETOED; + } + else if (!NT_SUCCESS(Status)) + { + ret = NtStatusToCrError(Status); + } + + return ret; +} + + static BOOL IsValidDeviceInstanceID( @@ -3038,10 +3084,25 @@ PNP_DisableDevInst( DWORD ulNameLength, DWORD ulFlags) { - UNIMPLEMENTED; - return CR_CALL_NOT_IMPLEMENTED; + UNREFERENCED_PARAMETER(hBinding); + + DPRINT1("PNP_DisableDevInst(%p %S %p %p %lu 0x%08lx)\n", + hBinding, pDeviceID, pVetoType, pszVetoName, ulNameLength, ulFlags); + + if (ulFlags & ~CM_DISABLE_BITS) + return CR_INVALID_FLAG; + + if (!IsValidDeviceInstanceID(pDeviceID) || + IsRootDeviceInstanceID(pDeviceID)) + return CR_INVALID_DEVINST; + + return DisableDeviceInstance(pDeviceID, + pVetoType, + pszVetoName, + ulNameLength); } + /* Function 33 */ DWORD WINAPI