[SECLOGON][ADVAPI] CreateProcessWithLogonW: Return process information to the caller

This commit is contained in:
Eric Kohl 2022-07-24 01:08:13 +02:00
parent bfe959e62c
commit 23ecbb3ed5
3 changed files with 60 additions and 8 deletions

View File

@ -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;
}

View File

@ -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,

View File

@ -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;
[