ReactOS  0.4.15-dev-5462-g4d0d22a
rpcserver.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Secondary Logon Service
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: Secondary Logon service RPC server
5  * COPYRIGHT: Eric Kohl 2022 <eric.kohl@reactos.org>
6  */
7 
8 /* INCLUDES *****************************************************************/
9 
10 #include "precomp.h"
11 
12 #include <seclogon_s.h>
13 
15 
16 /* FUNCTIONS *****************************************************************/
17 
18 
20 {
22 }
23 
24 
26 {
28 }
29 
30 
31 DWORD
33 {
35 
36  Status = lpServiceGlobals->StartRpcServer(L"seclogon", ISeclogon_v1_0_s_ifspec);
37  TRACE("StartRpcServer returned 0x%08lx\n", Status);
38 
40 }
41 
42 
43 DWORD
45 {
47 
48  Status = lpServiceGlobals->StopRpcServer(ISeclogon_v1_0_s_ifspec);
49  TRACE("StopRpcServer returned 0x%08lx\n", Status);
50 
52 }
53 
54 
55 VOID
60  _Out_ SECL_RESPONSE *pResponse)
61 {
62  STARTUPINFOW StartupInfo;
63  PROCESS_INFORMATION ProcessInfo;
64 
65  PROFILEINFOW ProfileInfo;
66  HANDLE hToken = NULL;
67  HANDLE hTargetProcessHandle = NULL;
68 
69  ULONG dwError = ERROR_SUCCESS;
70  BOOL rc;
71 
72  TRACE("SeclCreateProcessWithLogonW(%p %p %p)\n", hBinding, pRequest, pResponse);
73 
74  if (pRequest != NULL)
75  {
76  TRACE("Username: '%S'\n", pRequest->Username);
77  TRACE("Domain: '%S'\n", pRequest->Domain);
78  TRACE("Password: '%S'\n", pRequest->Password);
79  TRACE("ApplicationName: '%S'\n", pRequest->ApplicationName);
80  TRACE("CommandLine: '%S'\n", pRequest->CommandLine);
81  TRACE("CurrentDirectory: '%S'\n", pRequest->CurrentDirectory);
82  TRACE("LogonFlags: 0x%lx\n", pRequest->dwLogonFlags);
83  TRACE("CreationFlags: 0x%lx\n", pRequest->dwCreationFlags);
84  TRACE("ProcessId: %lu\n", pRequest->dwProcessId);
85  }
86 
87  hTargetProcessHandle = OpenProcess(PROCESS_DUP_HANDLE,
88  FALSE,
89  pRequest->dwProcessId);
90  if (hTargetProcessHandle == NULL)
91  {
92  dwError = GetLastError();
93  WARN("OpenProcess() failed with Error %lu\n", dwError);
94  goto done;
95  }
96 
97  ZeroMemory(&ProfileInfo, sizeof(ProfileInfo));
98 
99  /* Logon */
100  rc = LogonUser(pRequest->Username,
101  pRequest->Domain,
102  pRequest->Password,
105  &hToken);
106  if (rc == FALSE)
107  {
108  dwError = GetLastError();
109  WARN("LogonUser() failed with Error %lu\n", dwError);
110  goto done;
111  }
112 
113  /* Load the user profile */
114  if (pRequest->dwLogonFlags & LOGON_WITH_PROFILE)
115  {
116  ProfileInfo.dwSize = sizeof(ProfileInfo);
117  ProfileInfo.lpUserName = pRequest->Username;
118 
119  rc = LoadUserProfileW(hToken,
120  &ProfileInfo);
121  if (rc == FALSE)
122  {
123  dwError = GetLastError();
124  WARN("LoadUserProfile() failed with Error %lu\n", dwError);
125  goto done;
126  }
127  }
128 
129  ZeroMemory(&StartupInfo, sizeof(StartupInfo));
130  StartupInfo.cb = sizeof(StartupInfo);
131 
132  /* FIXME: Get startup info from the caller */
133 
134  ZeroMemory(&ProcessInfo, sizeof(ProcessInfo));
135 
136  /* Create Process */
137  rc = CreateProcessAsUserW(hToken,
138  pRequest->ApplicationName,
139  pRequest->CommandLine,
140  NULL, // lpProcessAttributes,
141  NULL, // lpThreadAttributes,
142  FALSE, // bInheritHandles,
143  pRequest->dwCreationFlags,
144  NULL, // lpEnvironment,
145  pRequest->CurrentDirectory,
146  &StartupInfo,
147  &ProcessInfo);
148  if (rc == FALSE)
149  {
150  dwError = GetLastError();
151  WARN("CreateProcessAsUser() failed with Error %lu\n", dwError);
152  goto done;
153  }
154 
155  /* Return process info to the caller */
156  if (pResponse != NULL)
157  {
159  ProcessInfo.hProcess,
160  hTargetProcessHandle,
161  (PHANDLE)&pResponse->hProcess,
162  0,
163  FALSE,
165 
167  ProcessInfo.hThread,
168  hTargetProcessHandle,
169  (PHANDLE)&pResponse->hThread,
170  0,
171  FALSE,
173 
174  pResponse->dwProcessId = ProcessInfo.dwProcessId;
175  pResponse->dwThreadId = ProcessInfo.dwThreadId;
176  }
177 
178 done:
179  if (hTargetProcessHandle)
180  CloseHandle(hTargetProcessHandle);
181 
182  if (ProcessInfo.hThread)
183  CloseHandle(ProcessInfo.hThread);
184 
185  if (ProcessInfo.hProcess)
186  CloseHandle(ProcessInfo.hProcess);
187 
188  if (ProfileInfo.hProfile != NULL)
189  UnloadUserProfile(hToken, ProfileInfo.hProfile);
190 
191  if (hToken != NULL)
192  CloseHandle(hToken);
193 
194  if (pResponse != NULL)
195  pResponse->dwError = dwError;
196 }
WINE_DEFAULT_DEBUG_CHANNEL(browser)
#define CloseHandle
Definition: compat.h:739
HANDLE hProfile
Definition: userenv.h:43
#define ERROR_SUCCESS
Definition: deptool.c:10
handle_t hBinding
Definition: ctx_c.c:54
#define _Out_
Definition: ms_sal.h:345
PSVCHOST_GLOBAL_DATA lpServiceGlobals
Definition: seclogon.c:18
#define WARN(fmt,...)
Definition: debug.h:112
LONG NTSTATUS
Definition: precomp.h:26
FxRequest * pRequest
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define ZeroMemory
Definition: winbase.h:1670
BOOL WINAPI UnloadUserProfile(_In_ HANDLE hToken, _In_ HANDLE hProfile)
Definition: profile.c:2184
LPWSTR lpUserName
Definition: userenv.h:38
#define LogonUser
Definition: winbase.h:3735
#define L(x)
Definition: ntvdm.h:50
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
#define DUPLICATE_SAME_ACCESS
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
void __RPC_USER midl_user_free(void __RPC_FAR *ptr)
Definition: rpcserver.c:55
#define PROCESS_DUP_HANDLE
static PVOID ptr
Definition: dispmode.c:27
DWORD StopRpcServer(VOID)
Definition: rpcserver.c:44
#define _In_
Definition: ms_sal.h:308
#define __RPC_FAR
Definition: rpc.h:56
#define __RPC_USER
Definition: rpc.h:65
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:736
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
DWORD cb
Definition: winbase.h:852
#define LOGON_WITH_PROFILE
Definition: winbase.h:619
unsigned long DWORD
Definition: ntddk_ex.h:95
#define __stdcall
Definition: typedefs.h:25
DWORD dwSize
Definition: userenv.h:36
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:454
GLenum GLsizei len
Definition: glext.h:6722
#define GetCurrentProcess()
Definition: compat.h:759
#define LOGON32_LOGON_INTERACTIVE
Definition: winbase.h:391
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessAsUserW(_In_opt_ HANDLE hToken, _In_opt_ LPCWSTR lpApplicationName, _Inout_opt_ LPWSTR lpCommandLine, _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes, _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes, _In_ BOOL bInheritHandles, _In_ DWORD dwCreationFlags, _In_opt_ LPVOID lpEnvironment, _In_opt_ LPCWSTR lpCurrentDirectory, _In_ LPSTARTUPINFOW lpStartupInfo, _Out_ LPPROCESS_INFORMATION lpProcessInformation)
Definition: logon.c:993
ULONG_PTR SIZE_T
Definition: typedefs.h:80
PSTART_RPC_SERVER StartRpcServer
Definition: svc.h:114
HANDLE WINAPI OpenProcess(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwProcessId)
Definition: proc.c:1227
#define NULL
Definition: types.h:112
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
void __RPC_FAR *__RPC_USER midl_user_allocate(SIZE_T len)
Definition: rpcserver.c:49
BOOL WINAPI LoadUserProfileW(_In_ HANDLE hToken, _Inout_ LPPROFILEINFOW lpProfileInfo)
Definition: profile.c:2005
unsigned int ULONG
Definition: retypes.h:1
DWORD StartRpcServer(VOID)
Definition: rpcserver.c:32
#define LOGON32_PROVIDER_DEFAULT
Definition: winbase.h:387
VOID __stdcall SeclCreateProcessWithLogonW(_In_ handle_t hBinding, _In_ SECL_REQUEST *pRequest, _Out_ SECL_RESPONSE *pResponse)
Definition: rpcserver.c:57
PSTOP_RPC_SERVER StopRpcServer
Definition: svc.h:115
#define HeapFree(x, y, z)
Definition: compat.h:735
BOOL WINAPI DuplicateHandle(IN HANDLE hSourceProcessHandle, IN HANDLE hSourceHandle, IN HANDLE hTargetProcessHandle, OUT LPHANDLE lpTargetHandle, IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwOptions)
Definition: handle.c:149