From 23ecbb3ed5f1b2881e28e54cccec16586e8241fb Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sun, 24 Jul 2022 01:08:13 +0200 Subject: [PATCH] [SECLOGON][ADVAPI] CreateProcessWithLogonW: Return process information to the caller --- base/services/seclogon/rpcserver.c | 40 ++++++++++++++++++++++++++-- dll/win32/advapi32/wine/security.c | 21 +++++++++++---- sdk/include/reactos/idl/seclogon.idl | 7 ++++- 3 files changed, 60 insertions(+), 8 deletions(-) diff --git a/base/services/seclogon/rpcserver.c b/base/services/seclogon/rpcserver.c index 9c8f85e7c97..17671e08801 100644 --- a/base/services/seclogon/rpcserver.c +++ b/base/services/seclogon/rpcserver.c @@ -64,6 +64,7 @@ SeclCreateProcessWithLogonW( PROFILEINFOW ProfileInfo; HANDLE hToken = NULL; + HANDLE hTargetProcessHandle = NULL; ULONG dwError = ERROR_SUCCESS; BOOL rc; @@ -80,6 +81,17 @@ SeclCreateProcessWithLogonW( TRACE("CurrentDirectory: '%S'\n", pRequest->CurrentDirectory); TRACE("LogonFlags: 0x%lx\n", pRequest->dwLogonFlags); TRACE("CreationFlags: 0x%lx\n", pRequest->dwCreationFlags); + TRACE("ProcessId: %lu\n", pRequest->dwProcessId); + } + + hTargetProcessHandle = OpenProcess(PROCESS_DUP_HANDLE, + FALSE, + pRequest->dwProcessId); + if (hTargetProcessHandle == NULL) + { + dwError = GetLastError(); + WARN("OpenProcess() failed with Error %lu\n", dwError); + goto done; } ZeroMemory(&ProfileInfo, sizeof(ProfileInfo)); @@ -140,9 +152,33 @@ SeclCreateProcessWithLogonW( goto done; } - /* FIXME: Pass process info to the caller */ + /* Return process info to the caller */ + if (pResponse != NULL) + { + DuplicateHandle(GetCurrentProcess(), + ProcessInfo.hProcess, + hTargetProcessHandle, + (PHANDLE)&pResponse->hProcess, + 0, + FALSE, + DUPLICATE_SAME_ACCESS); + + DuplicateHandle(GetCurrentProcess(), + ProcessInfo.hThread, + hTargetProcessHandle, + (PHANDLE)&pResponse->hThread, + 0, + FALSE, + DUPLICATE_SAME_ACCESS); + + pResponse->dwProcessId = ProcessInfo.dwProcessId; + pResponse->dwThreadId = ProcessInfo.dwThreadId; + } done: + if (hTargetProcessHandle) + CloseHandle(hTargetProcessHandle); + if (ProcessInfo.hThread) CloseHandle(ProcessInfo.hThread); @@ -156,5 +192,5 @@ done: CloseHandle(hToken); if (pResponse != NULL) - pResponse->ulError = dwError; + pResponse->dwError = dwError; } diff --git a/dll/win32/advapi32/wine/security.c b/dll/win32/advapi32/wine/security.c index 4b20be2b14c..ce31d7fb474 100644 --- a/dll/win32/advapi32/wine/security.c +++ b/dll/win32/advapi32/wine/security.c @@ -3538,7 +3538,14 @@ CreateProcessWithLogonW( Request.dwLogonFlags = dwLogonFlags; Request.dwCreationFlags = dwCreationFlags; - Response.ulError = ERROR_SUCCESS; + Request.dwProcessId = GetCurrentProcessId(); + TRACE("Request.dwProcessId %lu\n", Request.dwProcessId); + + Response.hProcess = 0; + Response.hThread = 0; + Response.dwProcessId = 0; + Response.dwThreadId = 0; + Response.dwError = ERROR_SUCCESS; RpcTryExcept { @@ -3561,13 +3568,17 @@ CreateProcessWithLogonW( hBinding = NULL; } - TRACE("Response.ulError %lu\n", Response.ulError); - if (Response.ulError != ERROR_SUCCESS) - SetLastError(Response.ulError); + TRACE("Response.hProcess %p\n", Response.hProcess); + TRACE("Response.hThread %p\n", Response.hThread); + TRACE("Response.dwProcessId %lu\n", Response.dwProcessId); + TRACE("Response.dwThreadId %lu\n", Response.dwThreadId); + TRACE("Response.dwError %lu\n", Response.dwError); + if (Response.dwError != ERROR_SUCCESS) + SetLastError(Response.dwError); TRACE("CreateProcessWithLogonW() done\n"); - return (Response.ulError == ERROR_SUCCESS); + return (Response.dwError == ERROR_SUCCESS); } BOOL WINAPI CreateProcessWithTokenW(HANDLE token, DWORD logon_flags, LPCWSTR application_name, LPWSTR command_line, diff --git a/sdk/include/reactos/idl/seclogon.idl b/sdk/include/reactos/idl/seclogon.idl index c605176e16f..d76689463a7 100644 --- a/sdk/include/reactos/idl/seclogon.idl +++ b/sdk/include/reactos/idl/seclogon.idl @@ -14,11 +14,16 @@ typedef struct _SECL_REQUEST [string] WCHAR *CurrentDirectory; DWORD dwLogonFlags; DWORD dwCreationFlags; + DWORD dwProcessId; } SECL_REQUEST, *PSECL_REQUEST; typedef struct _SECL_RESPONSE { - ULONG ulError; + DWORD_PTR hProcess; + DWORD_PTR hThread; + DWORD dwProcessId; + DWORD dwThreadId; + DWORD dwError; } SECL_RESPONSE, *PSECL_RESPONSE; [