[SECLOGON][ADVAPI] CreateProcessWithLogonW: Return process information to the caller
authorEric Kohl <eric.kohl@reactos.org>
Sat, 23 Jul 2022 23:08:13 +0000 (01:08 +0200)
committerEric Kohl <eric.kohl@reactos.org>
Sat, 23 Jul 2022 23:08:13 +0000 (01:08 +0200)
base/services/seclogon/rpcserver.c
dll/win32/advapi32/wine/security.c
sdk/include/reactos/idl/seclogon.idl

index 9c8f85e..17671e0 100644 (file)
@@ -64,6 +64,7 @@ SeclCreateProcessWithLogonW(
 
     PROFILEINFOW ProfileInfo;
     HANDLE hToken = NULL;
 
     PROFILEINFOW ProfileInfo;
     HANDLE hToken = NULL;
+    HANDLE hTargetProcessHandle = NULL;
 
     ULONG dwError = ERROR_SUCCESS;
     BOOL rc;
 
     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("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));
     }
 
     ZeroMemory(&ProfileInfo, sizeof(ProfileInfo));
@@ -140,9 +152,33 @@ SeclCreateProcessWithLogonW(
         goto done;
     }
 
         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:
 
 done:
+    if (hTargetProcessHandle)
+        CloseHandle(hTargetProcessHandle);
+
     if (ProcessInfo.hThread)
         CloseHandle(ProcessInfo.hThread);
 
     if (ProcessInfo.hThread)
         CloseHandle(ProcessInfo.hThread);
 
@@ -156,5 +192,5 @@ done:
         CloseHandle(hToken);
 
     if (pResponse != NULL)
         CloseHandle(hToken);
 
     if (pResponse != NULL)
-        pResponse->ulError = dwError;
+        pResponse->dwError = dwError;
 }
 }
index 4b20be2..ce31d7f 100644 (file)
@@ -3538,7 +3538,14 @@ CreateProcessWithLogonW(
     Request.dwLogonFlags = dwLogonFlags;
     Request.dwCreationFlags = dwCreationFlags;
 
     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
     {
 
     RpcTryExcept
     {
@@ -3561,13 +3568,17 @@ CreateProcessWithLogonW(
         hBinding = NULL;
     }
 
         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");
 
 
     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,
 }
 
 BOOL WINAPI CreateProcessWithTokenW(HANDLE token, DWORD logon_flags, LPCWSTR application_name, LPWSTR command_line,
index c605176..d766894 100644 (file)
@@ -14,11 +14,16 @@ typedef struct _SECL_REQUEST
     [string] WCHAR *CurrentDirectory;
     DWORD dwLogonFlags;
     DWORD dwCreationFlags;
     [string] WCHAR *CurrentDirectory;
     DWORD dwLogonFlags;
     DWORD dwCreationFlags;
+    DWORD dwProcessId;
 } SECL_REQUEST, *PSECL_REQUEST;
 
 typedef struct _SECL_RESPONSE
 {
 } 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;
 
 [
 } SECL_RESPONSE, *PSECL_RESPONSE;
 
 [