2005-01-06 13:58:04 +00:00
|
|
|
/* $Id$
|
2005-05-08 04:07:56 +00:00
|
|
|
*
|
1999-06-08 22:50:59 +00:00
|
|
|
* reactos/subsys/csrss/init.c
|
|
|
|
*
|
|
|
|
* Initialize the CSRSS subsystem server process.
|
|
|
|
*
|
|
|
|
* ReactOS Operating System
|
|
|
|
*
|
|
|
|
*/
|
1999-12-22 14:48:30 +00:00
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
2005-07-26 08:55:25 +00:00
|
|
|
#include <csrss.h>
|
1999-06-08 22:50:59 +00:00
|
|
|
|
2005-02-19 23:07:22 +00:00
|
|
|
#define NDEBUG
|
2003-08-11 18:50:12 +00:00
|
|
|
#include <debug.h>
|
|
|
|
|
1999-12-22 14:48:30 +00:00
|
|
|
/* GLOBALS ******************************************************************/
|
1999-06-08 22:50:59 +00:00
|
|
|
|
2005-03-20 22:55:05 +00:00
|
|
|
HANDLE CsrHeap = (HANDLE) 0;
|
2000-02-27 02:12:07 +00:00
|
|
|
|
2005-03-20 22:55:05 +00:00
|
|
|
HANDLE CsrObjectDirectory = (HANDLE) 0;
|
2000-02-27 02:12:07 +00:00
|
|
|
|
|
|
|
UNICODE_STRING CsrDirectoryName;
|
|
|
|
|
2000-04-23 17:44:53 +00:00
|
|
|
extern HANDLE CsrssApiHeap;
|
2000-02-27 02:12:07 +00:00
|
|
|
|
2004-05-28 21:33:41 +00:00
|
|
|
static unsigned InitCompleteProcCount;
|
|
|
|
static CSRPLUGIN_INIT_COMPLETE_PROC *InitCompleteProcs = NULL;
|
|
|
|
|
2006-10-30 14:20:45 +00:00
|
|
|
static unsigned HardErrorProcCount;
|
|
|
|
static CSRPLUGIN_HARDERROR_PROC *HardErrorProcs = NULL;
|
|
|
|
|
2005-03-20 22:55:05 +00:00
|
|
|
HANDLE hSbApiPort = (HANDLE) 0;
|
|
|
|
|
|
|
|
HANDLE hBootstrapOk = (HANDLE) 0;
|
|
|
|
|
|
|
|
HANDLE hSmApiPort = (HANDLE) 0;
|
|
|
|
|
|
|
|
HANDLE hApiPort = (HANDLE) 0;
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* CsrpAddInitCompleteProc/1
|
|
|
|
*/
|
2004-05-28 21:33:41 +00:00
|
|
|
static NTSTATUS FASTCALL
|
2005-03-20 22:55:05 +00:00
|
|
|
CsrpAddInitCompleteProc(CSRPLUGIN_INIT_COMPLETE_PROC Proc)
|
2004-05-28 21:33:41 +00:00
|
|
|
{
|
|
|
|
CSRPLUGIN_INIT_COMPLETE_PROC *NewProcs;
|
|
|
|
|
2005-03-20 22:55:05 +00:00
|
|
|
DPRINT("CSR: %s called\n", __FUNCTION__);
|
|
|
|
|
2004-05-28 21:33:41 +00:00
|
|
|
NewProcs = RtlAllocateHeap(CsrssApiHeap, 0,
|
|
|
|
(InitCompleteProcCount + 1)
|
|
|
|
* sizeof(CSRPLUGIN_INIT_COMPLETE_PROC));
|
|
|
|
if (NULL == NewProcs)
|
|
|
|
{
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
if (0 != InitCompleteProcCount)
|
|
|
|
{
|
|
|
|
RtlCopyMemory(NewProcs, InitCompleteProcs,
|
|
|
|
InitCompleteProcCount * sizeof(CSRPLUGIN_INIT_COMPLETE_PROC));
|
|
|
|
RtlFreeHeap(CsrssApiHeap, 0, InitCompleteProcs);
|
|
|
|
}
|
|
|
|
NewProcs[InitCompleteProcCount] = Proc;
|
|
|
|
InitCompleteProcs = NewProcs;
|
|
|
|
InitCompleteProcCount++;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-10-30 14:20:45 +00:00
|
|
|
static NTSTATUS FASTCALL
|
|
|
|
CsrpAddHardErrorProc(CSRPLUGIN_HARDERROR_PROC Proc)
|
|
|
|
{
|
|
|
|
CSRPLUGIN_HARDERROR_PROC *NewProcs;
|
|
|
|
|
|
|
|
DPRINT("CSR: %s called\n", __FUNCTION__);
|
|
|
|
|
|
|
|
NewProcs = RtlAllocateHeap(CsrssApiHeap, 0,
|
|
|
|
(HardErrorProcCount + 1)
|
|
|
|
* sizeof(CSRPLUGIN_HARDERROR_PROC));
|
|
|
|
if (NULL == NewProcs)
|
|
|
|
{
|
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
|
|
|
if (0 != HardErrorProcCount)
|
|
|
|
{
|
|
|
|
RtlCopyMemory(NewProcs, HardErrorProcs,
|
|
|
|
HardErrorProcCount * sizeof(CSRPLUGIN_HARDERROR_PROC));
|
|
|
|
RtlFreeHeap(CsrssApiHeap, 0, HardErrorProcs);
|
|
|
|
}
|
|
|
|
|
|
|
|
NewProcs[HardErrorProcCount] = Proc;
|
|
|
|
HardErrorProcs = NewProcs;
|
|
|
|
HardErrorProcCount++;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-03-20 22:55:05 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* CallInitComplete/0
|
|
|
|
*/
|
2004-05-28 21:33:41 +00:00
|
|
|
static BOOL FASTCALL
|
|
|
|
CallInitComplete(void)
|
|
|
|
{
|
|
|
|
BOOL Ok;
|
|
|
|
unsigned i;
|
|
|
|
|
2005-03-20 22:55:05 +00:00
|
|
|
DPRINT("CSR: %s called\n", __FUNCTION__);
|
|
|
|
|
2004-05-28 21:33:41 +00:00
|
|
|
Ok = TRUE;
|
|
|
|
if (0 != InitCompleteProcCount)
|
|
|
|
{
|
|
|
|
for (i = 0; i < InitCompleteProcCount && Ok; i++)
|
|
|
|
{
|
|
|
|
Ok = (*(InitCompleteProcs[i]))();
|
|
|
|
}
|
|
|
|
RtlFreeHeap(CsrssApiHeap, 0, InitCompleteProcs);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2006-10-30 14:20:45 +00:00
|
|
|
BOOL
|
|
|
|
FASTCALL
|
|
|
|
CallHardError(void)
|
|
|
|
{
|
|
|
|
BOOL Ok;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
DPRINT("CSR: %s called\n", __FUNCTION__);
|
|
|
|
|
|
|
|
Ok = TRUE;
|
|
|
|
if (0 != HardErrorProcCount)
|
|
|
|
{
|
|
|
|
for (i = 0; i < HardErrorProcCount && Ok; i++)
|
|
|
|
{
|
|
|
|
Ok = (*(HardErrorProcs[i]))();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2001-03-25 03:34:30 +00:00
|
|
|
ULONG
|
|
|
|
InitializeVideoAddressSpace(VOID);
|
|
|
|
|
2005-03-20 22:55:05 +00:00
|
|
|
/**********************************************************************
|
2005-10-08 22:41:49 +00:00
|
|
|
* CsrpCreateObjectDirectory/3
|
2005-03-20 22:55:05 +00:00
|
|
|
*/
|
2000-02-27 02:12:07 +00:00
|
|
|
static NTSTATUS
|
2005-10-08 22:41:49 +00:00
|
|
|
CsrpCreateObjectDirectory (int argc, char ** argv, char ** envp)
|
2000-02-27 02:12:07 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
OBJECT_ATTRIBUTES Attributes;
|
|
|
|
|
2005-03-20 22:55:05 +00:00
|
|
|
DPRINT("CSR: %s called\n", __FUNCTION__);
|
|
|
|
|
2000-02-27 02:12:07 +00:00
|
|
|
|
|
|
|
/* create object directory ('\Windows') */
|
|
|
|
RtlCreateUnicodeString (&CsrDirectoryName,
|
|
|
|
L"\\Windows");
|
|
|
|
|
|
|
|
InitializeObjectAttributes (&Attributes,
|
|
|
|
&CsrDirectoryName,
|
2005-04-11 22:37:46 +00:00
|
|
|
OBJ_OPENIF,
|
2000-02-27 02:12:07 +00:00
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
2005-04-08 20:29:30 +00:00
|
|
|
Status = NtOpenDirectoryObject(&CsrObjectDirectory,
|
2007-01-20 13:29:04 +00:00
|
|
|
DIRECTORY_ALL_ACCESS,
|
2005-04-08 20:29:30 +00:00
|
|
|
&Attributes);
|
2000-02-27 02:12:07 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2005-03-20 22:55:05 +00:00
|
|
|
/**********************************************************************
|
2005-10-08 22:41:49 +00:00
|
|
|
* CsrpInitVideo/3
|
2005-03-20 22:55:05 +00:00
|
|
|
*
|
|
|
|
* TODO: we need a virtual device for sessions other than
|
|
|
|
* TODO: the console one
|
|
|
|
*/
|
|
|
|
static NTSTATUS
|
2005-10-08 22:41:49 +00:00
|
|
|
CsrpInitVideo (int argc, char ** argv, char ** envp)
|
2002-06-14 14:23:14 +00:00
|
|
|
{
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
Large change to modify NTDLL'S CSR Functions to be compatible with NT. They are external and we should at least try to match the number of arguments (one vs eight? come on!). Because this is also the direction that Emanuele wants to be taking, the whole external calling interface was modified to be more compatible with NT (although internally it still isn't, and does not have a reason to be). API Names are now generated by a macro from the Server ID, like Emanuele and I noticed from traces, and I've entirely removed the concept of a reply structure. CSRSS uses full-duplex one-way structures, not dual-strutures (this would've been incompatible with the external interface anyways). I don't seem to have introduced any new bugs (console-ROS works great for me, as does the GUI), but there is still a chance some obscure bug might happen, so please bear with me, I had to hand-edit over 250 calls. Also, this now allows full removal of ntdll headers and the next commits will clean this up
svn path=/trunk/; revision=16213
2005-06-22 04:02:32 +00:00
|
|
|
UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\??\\DISPLAY1");
|
2002-06-14 14:23:14 +00:00
|
|
|
IO_STATUS_BLOCK Iosb;
|
2005-03-20 22:55:05 +00:00
|
|
|
HANDLE VideoHandle = (HANDLE) 0;
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
DPRINT("CSR: %s called\n", __FUNCTION__);
|
2002-06-14 14:23:14 +00:00
|
|
|
|
2003-06-17 13:55:16 +00:00
|
|
|
InitializeVideoAddressSpace();
|
|
|
|
|
2002-06-14 14:23:14 +00:00
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&DeviceName,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
Status = NtOpenFile(&VideoHandle,
|
|
|
|
FILE_ALL_ACCESS,
|
|
|
|
&ObjectAttributes,
|
|
|
|
&Iosb,
|
|
|
|
0,
|
|
|
|
0);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
NtClose(VideoHandle);
|
|
|
|
}
|
2005-03-20 22:55:05 +00:00
|
|
|
return Status;
|
2002-06-14 14:23:14 +00:00
|
|
|
}
|
|
|
|
|
2005-03-20 22:55:05 +00:00
|
|
|
/**********************************************************************
|
2005-10-08 22:41:49 +00:00
|
|
|
* CsrpInitWin32Csr/3
|
2005-03-20 22:55:05 +00:00
|
|
|
*
|
|
|
|
* TODO: this function should be turned more general to load an
|
|
|
|
* TODO: hosted server DLL as received from the command line;
|
|
|
|
* TODO: for instance: ServerDll=winsrv:ConServerDllInitialization,2
|
|
|
|
* TODO: ^method ^dll ^api ^sid
|
|
|
|
* TODO:
|
|
|
|
* TODO: CsrpHostServerDll (LPWSTR DllName,
|
|
|
|
* TODO: LPWSTR ApiName,
|
|
|
|
* TODO: DWORD ServerId)
|
|
|
|
*/
|
|
|
|
static NTSTATUS
|
2005-10-08 22:41:49 +00:00
|
|
|
CsrpInitWin32Csr (int argc, char ** argv, char ** envp)
|
2003-12-02 11:38:47 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
UNICODE_STRING DllName;
|
|
|
|
HINSTANCE hInst;
|
|
|
|
ANSI_STRING ProcName;
|
|
|
|
CSRPLUGIN_INITIALIZE_PROC InitProc;
|
|
|
|
CSRSS_EXPORTED_FUNCS Exports;
|
|
|
|
PCSRSS_API_DEFINITION ApiDefinitions;
|
|
|
|
PCSRSS_OBJECT_DEFINITION ObjectDefinitions;
|
2004-05-28 21:33:41 +00:00
|
|
|
CSRPLUGIN_INIT_COMPLETE_PROC InitCompleteProc;
|
2006-10-30 14:20:45 +00:00
|
|
|
CSRPLUGIN_HARDERROR_PROC HardErrorProc;
|
2003-12-02 11:38:47 +00:00
|
|
|
|
2005-03-20 22:55:05 +00:00
|
|
|
DPRINT("CSR: %s called\n", __FUNCTION__);
|
|
|
|
|
2003-12-02 11:38:47 +00:00
|
|
|
RtlInitUnicodeString(&DllName, L"win32csr.dll");
|
|
|
|
Status = LdrLoadDll(NULL, 0, &DllName, (PVOID *) &hInst);
|
|
|
|
if (! NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
RtlInitAnsiString(&ProcName, "Win32CsrInitialization");
|
|
|
|
Status = LdrGetProcedureAddress(hInst, &ProcName, 0, (PVOID *) &InitProc);
|
|
|
|
if (! NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
Exports.CsrInsertObjectProc = CsrInsertObject;
|
|
|
|
Exports.CsrGetObjectProc = CsrGetObject;
|
|
|
|
Exports.CsrReleaseObjectProc = CsrReleaseObject;
|
2005-12-01 22:38:03 +00:00
|
|
|
Exports.CsrEnumProcessesProc = CsrEnumProcesses;
|
2004-05-28 21:33:41 +00:00
|
|
|
if (! (*InitProc)(&ApiDefinitions, &ObjectDefinitions, &InitCompleteProc,
|
2006-10-30 14:20:45 +00:00
|
|
|
&HardErrorProc, &Exports, CsrssApiHeap))
|
2003-12-02 11:38:47 +00:00
|
|
|
{
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = CsrApiRegisterDefinitions(ApiDefinitions);
|
|
|
|
if (! NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
Status = CsrRegisterObjectDefinitions(ObjectDefinitions);
|
2004-05-28 21:33:41 +00:00
|
|
|
if (! NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
if (NULL != InitCompleteProc)
|
|
|
|
{
|
2005-03-20 22:55:05 +00:00
|
|
|
Status = CsrpAddInitCompleteProc(InitCompleteProc);
|
2004-05-28 21:33:41 +00:00
|
|
|
}
|
2006-10-30 14:20:45 +00:00
|
|
|
if (HardErrorProc) Status = CsrpAddHardErrorProc(HardErrorProc);
|
2003-12-02 11:38:47 +00:00
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSRSS_API_DEFINITION NativeDefinitions[] =
|
|
|
|
{
|
Large change to modify NTDLL'S CSR Functions to be compatible with NT. They are external and we should at least try to match the number of arguments (one vs eight? come on!). Because this is also the direction that Emanuele wants to be taking, the whole external calling interface was modified to be more compatible with NT (although internally it still isn't, and does not have a reason to be). API Names are now generated by a macro from the Server ID, like Emanuele and I noticed from traces, and I've entirely removed the concept of a reply structure. CSRSS uses full-duplex one-way structures, not dual-strutures (this would've been incompatible with the external interface anyways). I don't seem to have introduced any new bugs (console-ROS works great for me, as does the GUI), but there is still a chance some obscure bug might happen, so please bear with me, I had to hand-edit over 250 calls. Also, this now allows full removal of ntdll headers and the next commits will clean this up
svn path=/trunk/; revision=16213
2005-06-22 04:02:32 +00:00
|
|
|
CSRSS_DEFINE_API(CREATE_PROCESS, CsrCreateProcess),
|
|
|
|
CSRSS_DEFINE_API(TERMINATE_PROCESS, CsrTerminateProcess),
|
|
|
|
CSRSS_DEFINE_API(CONNECT_PROCESS, CsrConnectProcess),
|
|
|
|
CSRSS_DEFINE_API(REGISTER_SERVICES_PROCESS, CsrRegisterServicesProcess),
|
|
|
|
CSRSS_DEFINE_API(GET_SHUTDOWN_PARAMETERS, CsrGetShutdownParameters),
|
|
|
|
CSRSS_DEFINE_API(SET_SHUTDOWN_PARAMETERS, CsrSetShutdownParameters),
|
|
|
|
CSRSS_DEFINE_API(GET_INPUT_HANDLE, CsrGetInputHandle),
|
|
|
|
CSRSS_DEFINE_API(GET_OUTPUT_HANDLE, CsrGetOutputHandle),
|
|
|
|
CSRSS_DEFINE_API(CLOSE_HANDLE, CsrCloseHandle),
|
|
|
|
CSRSS_DEFINE_API(VERIFY_HANDLE, CsrVerifyHandle),
|
|
|
|
CSRSS_DEFINE_API(DUPLICATE_HANDLE, CsrDuplicateHandle),
|
|
|
|
CSRSS_DEFINE_API(GET_INPUT_WAIT_HANDLE, CsrGetInputWaitHandle),
|
|
|
|
{ 0, 0, NULL }
|
2003-12-02 11:38:47 +00:00
|
|
|
};
|
|
|
|
|
2005-03-20 22:55:05 +00:00
|
|
|
static NTSTATUS STDCALL
|
|
|
|
CsrpCreateListenPort (IN LPWSTR Name,
|
|
|
|
IN OUT PHANDLE Port,
|
|
|
|
IN PTHREAD_START_ROUTINE ListenThread)
|
|
|
|
{
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
OBJECT_ATTRIBUTES PortAttributes;
|
|
|
|
UNICODE_STRING PortName;
|
|
|
|
|
|
|
|
DPRINT("CSR: %s called\n", __FUNCTION__);
|
|
|
|
|
|
|
|
RtlInitUnicodeString (& PortName, Name);
|
|
|
|
InitializeObjectAttributes (& PortAttributes,
|
|
|
|
& PortName,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
Status = NtCreatePort ( Port,
|
|
|
|
& PortAttributes,
|
2005-11-27 13:51:28 +00:00
|
|
|
LPC_MAX_DATA_LENGTH, /* TODO: make caller set it*/
|
|
|
|
LPC_MAX_MESSAGE_LENGTH, /* TODO: make caller set it*/
|
2005-03-20 22:55:05 +00:00
|
|
|
0); /* TODO: make caller set it*/
|
|
|
|
if(!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("CSR: %s: NtCreatePort failed (Status=%08lx)\n",
|
|
|
|
__FUNCTION__, Status);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
Status = RtlCreateUserThread(NtCurrentProcess(),
|
|
|
|
NULL,
|
|
|
|
FALSE,
|
|
|
|
0,
|
2005-07-12 01:56:14 +00:00
|
|
|
0,
|
|
|
|
0,
|
2005-03-20 22:55:05 +00:00
|
|
|
(PTHREAD_START_ROUTINE) ListenThread,
|
2006-10-30 18:45:22 +00:00
|
|
|
*Port,
|
2005-03-20 22:55:05 +00:00
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* === INIT ROUTINES === */
|
|
|
|
|
2005-02-19 22:56:59 +00:00
|
|
|
/**********************************************************************
|
2005-10-08 22:41:49 +00:00
|
|
|
* CsrpCreateHeap/3
|
2005-02-19 22:56:59 +00:00
|
|
|
*/
|
2005-03-20 22:55:05 +00:00
|
|
|
static NTSTATUS
|
2005-10-08 22:41:49 +00:00
|
|
|
CsrpCreateHeap (int argc, char ** argv, char ** envp)
|
2005-02-19 22:56:59 +00:00
|
|
|
{
|
2005-03-20 22:55:05 +00:00
|
|
|
DPRINT("CSR: %s called\n", __FUNCTION__);
|
|
|
|
|
|
|
|
CsrssApiHeap = RtlCreateHeap(HEAP_GROWABLE,
|
|
|
|
NULL,
|
|
|
|
65536,
|
|
|
|
65536,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
if (CsrssApiHeap == NULL)
|
|
|
|
{
|
|
|
|
return STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2005-02-19 22:56:59 +00:00
|
|
|
|
2005-03-20 22:55:05 +00:00
|
|
|
/**********************************************************************
|
2005-10-08 22:41:49 +00:00
|
|
|
* CsrpCreateCallbackPort/3
|
2005-03-20 22:55:05 +00:00
|
|
|
*/
|
|
|
|
static NTSTATUS
|
2005-10-08 22:41:49 +00:00
|
|
|
CsrpCreateCallbackPort (int argc, char ** argv, char ** envp)
|
2005-03-20 22:55:05 +00:00
|
|
|
{
|
|
|
|
DPRINT("CSR: %s called\n", __FUNCTION__);
|
|
|
|
|
|
|
|
return CsrpCreateListenPort (L"\\Windows\\SbApiPort",
|
|
|
|
& hSbApiPort,
|
|
|
|
ServerSbApiPortThread);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
2005-10-08 22:41:49 +00:00
|
|
|
* CsrpRegisterSubsystem/3
|
2005-03-20 22:55:05 +00:00
|
|
|
*/
|
|
|
|
static NTSTATUS
|
2005-10-08 22:41:49 +00:00
|
|
|
CsrpRegisterSubsystem (int argc, char ** argv, char ** envp)
|
2005-03-20 22:55:05 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
OBJECT_ATTRIBUTES BootstrapOkAttributes;
|
|
|
|
UNICODE_STRING Name;
|
|
|
|
|
|
|
|
DPRINT("CSR: %s called\n", __FUNCTION__);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the event object the callback port
|
|
|
|
* thread will signal *if* the SM will
|
|
|
|
* authorize us to bootstrap.
|
|
|
|
*/
|
|
|
|
RtlInitUnicodeString (& Name, L"\\CsrssBooting");
|
|
|
|
InitializeObjectAttributes(& BootstrapOkAttributes,
|
|
|
|
& Name,
|
|
|
|
0, NULL, NULL);
|
|
|
|
Status = NtCreateEvent (& hBootstrapOk,
|
|
|
|
EVENT_ALL_ACCESS,
|
|
|
|
& BootstrapOkAttributes,
|
|
|
|
SynchronizationEvent,
|
|
|
|
FALSE);
|
|
|
|
if(!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT("CSR: %s: NtCreateEvent failed (Status=0x%08lx)\n",
|
|
|
|
__FUNCTION__, Status);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Let's tell the SM a new environment
|
|
|
|
* subsystem server is in the system.
|
|
|
|
*/
|
|
|
|
RtlInitUnicodeString (& Name, L"\\Windows\\SbApiPort");
|
|
|
|
DPRINT("CSR: %s: registering with SM for\n IMAGE_SUBSYSTEM_WINDOWS_CUI == 3\n", __FUNCTION__);
|
|
|
|
Status = SmConnectApiPort (& Name,
|
|
|
|
hSbApiPort,
|
2005-02-19 22:56:59 +00:00
|
|
|
IMAGE_SUBSYSTEM_WINDOWS_CUI,
|
2005-03-20 22:55:05 +00:00
|
|
|
& hSmApiPort);
|
2005-02-19 22:56:59 +00:00
|
|
|
if(!NT_SUCCESS(Status))
|
|
|
|
{
|
2005-03-20 22:55:05 +00:00
|
|
|
DPRINT("CSR: %s unable to connect to the SM (Status=0x%08lx)\n",
|
|
|
|
__FUNCTION__, Status);
|
|
|
|
NtClose (hBootstrapOk);
|
2005-02-19 22:56:59 +00:00
|
|
|
return Status;
|
|
|
|
}
|
2005-03-20 22:55:05 +00:00
|
|
|
/*
|
|
|
|
* Wait for SM to reply OK... If the SM
|
|
|
|
* won't answer, we hang here forever!
|
|
|
|
*/
|
|
|
|
DPRINT("CSR: %s: waiting for SM to OK boot...\n", __FUNCTION__);
|
|
|
|
Status = NtWaitForSingleObject (hBootstrapOk,
|
|
|
|
FALSE,
|
|
|
|
NULL);
|
|
|
|
NtClose (hBootstrapOk);
|
2005-05-08 04:07:56 +00:00
|
|
|
return Status;
|
2005-02-19 22:56:59 +00:00
|
|
|
}
|
|
|
|
|
2005-03-20 22:55:05 +00:00
|
|
|
/**********************************************************************
|
2005-10-08 22:41:49 +00:00
|
|
|
* EnvpToUnicodeString/2
|
|
|
|
*/
|
|
|
|
static ULONG FASTCALL
|
|
|
|
EnvpToUnicodeString (char ** envp, PUNICODE_STRING UnicodeEnv)
|
|
|
|
{
|
|
|
|
ULONG CharCount = 0;
|
|
|
|
ULONG Index = 0;
|
|
|
|
ANSI_STRING AnsiEnv;
|
|
|
|
|
|
|
|
UnicodeEnv->Buffer = NULL;
|
|
|
|
|
|
|
|
for (Index=0; NULL != envp[Index]; Index++)
|
|
|
|
{
|
|
|
|
CharCount += strlen (envp[Index]);
|
|
|
|
++ CharCount;
|
|
|
|
}
|
|
|
|
++ CharCount;
|
|
|
|
|
|
|
|
AnsiEnv.Buffer = RtlAllocateHeap (RtlGetProcessHeap(), 0, CharCount);
|
|
|
|
if (NULL != AnsiEnv.Buffer)
|
|
|
|
{
|
2005-10-16 01:27:32 +00:00
|
|
|
|
2005-10-08 22:41:49 +00:00
|
|
|
PCHAR WritePos = AnsiEnv.Buffer;
|
|
|
|
|
|
|
|
for (Index=0; NULL != envp[Index]; Index++)
|
|
|
|
{
|
2005-10-16 01:27:32 +00:00
|
|
|
strcpy (WritePos, envp[Index]);
|
2005-10-08 22:41:49 +00:00
|
|
|
WritePos += strlen (envp[Index]) + 1;
|
|
|
|
}
|
2005-10-16 01:27:32 +00:00
|
|
|
|
|
|
|
/* FIXME: the last (double) nullterm should perhaps not be included in Length
|
|
|
|
* but only in MaximumLength. -Gunnar */
|
|
|
|
AnsiEnv.Buffer [CharCount-1] = '\0';
|
2005-10-08 22:41:49 +00:00
|
|
|
AnsiEnv.Length = CharCount;
|
|
|
|
AnsiEnv.MaximumLength = CharCount;
|
2005-10-16 01:27:32 +00:00
|
|
|
|
2005-10-08 22:41:49 +00:00
|
|
|
RtlAnsiStringToUnicodeString (UnicodeEnv, & AnsiEnv, TRUE);
|
|
|
|
RtlFreeHeap (RtlGetProcessHeap(), 0, AnsiEnv.Buffer);
|
|
|
|
}
|
|
|
|
return CharCount;
|
|
|
|
}
|
|
|
|
/**********************************************************************
|
|
|
|
* CsrpLoadKernelModeDriver/3
|
2005-06-02 13:17:37 +00:00
|
|
|
*/
|
|
|
|
static NTSTATUS
|
2005-10-08 22:41:49 +00:00
|
|
|
CsrpLoadKernelModeDriver (int argc, char ** argv, char ** envp)
|
2005-06-02 13:17:37 +00:00
|
|
|
{
|
2005-10-08 22:41:49 +00:00
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
WCHAR Data [MAX_PATH + 1];
|
|
|
|
ULONG DataLength = sizeof Data;
|
|
|
|
ULONG DataType = 0;
|
|
|
|
UNICODE_STRING Environment;
|
2005-06-02 13:17:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
DPRINT("SM: %s called\n", __FUNCTION__);
|
|
|
|
|
2005-10-08 22:41:49 +00:00
|
|
|
|
|
|
|
EnvpToUnicodeString (envp, & Environment);
|
2005-06-02 13:17:37 +00:00
|
|
|
Status = SmLookupSubsystem (L"Kmode",
|
|
|
|
Data,
|
|
|
|
& DataLength,
|
|
|
|
& DataType,
|
2005-10-08 22:41:49 +00:00
|
|
|
Environment.Buffer);
|
|
|
|
RtlFreeUnicodeString (& Environment);
|
2005-06-02 13:17:37 +00:00
|
|
|
if((STATUS_SUCCESS == Status) && (DataLength > sizeof Data[0]))
|
|
|
|
{
|
|
|
|
WCHAR ImagePath [MAX_PATH + 1] = {0};
|
2005-06-20 11:56:10 +00:00
|
|
|
UNICODE_STRING ModuleName;
|
2005-06-02 13:17:37 +00:00
|
|
|
|
|
|
|
wcscpy (ImagePath, L"\\??\\");
|
|
|
|
wcscat (ImagePath, Data);
|
2005-06-20 11:56:10 +00:00
|
|
|
RtlInitUnicodeString (& ModuleName, ImagePath);
|
|
|
|
Status = NtSetSystemInformation(/* FIXME: SystemLoadAndCallImage */
|
|
|
|
SystemExtendServiceTableInformation,
|
|
|
|
& ModuleName,
|
|
|
|
sizeof ModuleName);
|
2005-06-02 13:17:37 +00:00
|
|
|
if(!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT("WIN: %s: loading Kmode failed (Status=0x%08lx)\n",
|
|
|
|
__FUNCTION__, Status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* CsrpCreateApiPort/2
|
2005-03-20 22:55:05 +00:00
|
|
|
*/
|
|
|
|
static NTSTATUS
|
2005-10-08 22:41:49 +00:00
|
|
|
CsrpCreateApiPort (int argc, char ** argv, char ** envp)
|
2005-03-20 22:55:05 +00:00
|
|
|
{
|
|
|
|
DPRINT("CSR: %s called\n", __FUNCTION__);
|
|
|
|
|
2007-06-14 16:47:24 +00:00
|
|
|
CsrInitProcessData();
|
|
|
|
|
2007-06-14 19:09:32 +00:00
|
|
|
return CsrpCreateListenPort(L"\\Windows\\ApiPort", &hApiPort,
|
|
|
|
(PTHREAD_START_ROUTINE)ClientConnectionThread);
|
2005-03-20 22:55:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* CsrpApiRegisterDef/0
|
|
|
|
*/
|
|
|
|
static NTSTATUS
|
2005-10-08 22:41:49 +00:00
|
|
|
CsrpApiRegisterDef (int argc, char ** argv, char ** envp)
|
2005-03-20 22:55:05 +00:00
|
|
|
{
|
|
|
|
return CsrApiRegisterDefinitions(NativeDefinitions);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* CsrpCCTS/2
|
|
|
|
*/
|
|
|
|
static NTSTATUS
|
2005-10-08 22:41:49 +00:00
|
|
|
CsrpCCTS (int argc, char ** argv, char ** envp)
|
2005-03-20 22:55:05 +00:00
|
|
|
{
|
2005-09-07 19:37:28 +00:00
|
|
|
ULONG Dummy;
|
|
|
|
ULONG DummyLength = sizeof(Dummy);
|
|
|
|
return CsrClientConnectToServer(L"\\Windows",
|
|
|
|
0, &Dummy, &DummyLength, NULL);
|
2005-03-20 22:55:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* CsrpRunWinlogon/0
|
|
|
|
*
|
|
|
|
* Start the logon process (winlogon.exe).
|
|
|
|
*
|
|
|
|
* TODO: this should be moved in CsrpCreateSession/x (one per session)
|
|
|
|
* TODO: in its own desktop (one logon desktop per winstation).
|
|
|
|
*/
|
|
|
|
static NTSTATUS
|
2005-10-08 22:41:49 +00:00
|
|
|
CsrpRunWinlogon (int argc, char ** argv, char ** envp)
|
2005-03-20 22:55:05 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
UNICODE_STRING ImagePath;
|
|
|
|
UNICODE_STRING CommandLine;
|
|
|
|
PRTL_USER_PROCESS_PARAMETERS ProcessParameters = NULL;
|
2005-07-12 01:56:14 +00:00
|
|
|
RTL_USER_PROCESS_INFORMATION ProcessInfo;
|
2005-03-20 22:55:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
DPRINT("CSR: %s called\n", __FUNCTION__);
|
|
|
|
|
|
|
|
/* initialize the process parameters */
|
|
|
|
RtlInitUnicodeString (& ImagePath, L"\\SystemRoot\\system32\\winlogon.exe");
|
|
|
|
RtlInitUnicodeString (& CommandLine, L"");
|
|
|
|
RtlCreateProcessParameters(& ProcessParameters,
|
|
|
|
& ImagePath,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
& CommandLine,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
/* Create the winlogon process */
|
|
|
|
Status = RtlCreateUserProcess (& ImagePath,
|
|
|
|
OBJ_CASE_INSENSITIVE,
|
|
|
|
ProcessParameters,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
FALSE,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
& ProcessInfo);
|
|
|
|
/* Cleanup */
|
|
|
|
RtlDestroyProcessParameters (ProcessParameters);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2005-04-02 00:18:46 +00:00
|
|
|
DPRINT1("SM: %s: loading winlogon.exe failed (Status=%08lx)\n",
|
2005-03-20 22:55:05 +00:00
|
|
|
__FUNCTION__, Status);
|
|
|
|
}
|
2005-04-02 00:18:46 +00:00
|
|
|
ZwResumeThread(ProcessInfo.ThreadHandle, NULL);
|
2005-03-20 22:55:05 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2006-10-26 04:55:34 +00:00
|
|
|
static NTSTATUS
|
|
|
|
CsrpCreateHardErrorPort (int argc, char ** argv, char ** envp)
|
|
|
|
{
|
|
|
|
return NtSetDefaultHardErrorPort(hApiPort);
|
|
|
|
}
|
2005-03-20 22:55:05 +00:00
|
|
|
|
2005-10-08 22:41:49 +00:00
|
|
|
typedef NTSTATUS (* CSR_INIT_ROUTINE)(int,char**,char**);
|
2005-03-20 22:55:05 +00:00
|
|
|
|
|
|
|
struct {
|
|
|
|
BOOL Required;
|
|
|
|
CSR_INIT_ROUTINE EntryPoint;
|
|
|
|
PCHAR ErrorMessage;
|
|
|
|
} InitRoutine [] = {
|
2005-06-02 13:17:37 +00:00
|
|
|
{TRUE, CsrpCreateCallbackPort, "create the callback port \\Windows\\SbApiPort"},
|
|
|
|
{TRUE, CsrpRegisterSubsystem, "register with SM"},
|
|
|
|
{TRUE, CsrpCreateHeap, "create the CSR heap"},
|
|
|
|
{TRUE, CsrpCreateApiPort, "create the api port \\Windows\\ApiPort"},
|
2006-10-26 04:55:34 +00:00
|
|
|
{TRUE, CsrpCreateHardErrorPort, "create the hard error port"},
|
2005-10-08 22:41:49 +00:00
|
|
|
{TRUE, CsrpCreateObjectDirectory,"create the object directory \\Windows"},
|
2005-06-02 13:17:37 +00:00
|
|
|
{TRUE, CsrpLoadKernelModeDriver, "load Kmode driver"},
|
|
|
|
{TRUE, CsrpInitVideo, "initialize video"},
|
|
|
|
{TRUE, CsrpApiRegisterDef, "initialize api definitions"},
|
|
|
|
{TRUE, CsrpCCTS, "connect client to server"},
|
|
|
|
{TRUE, CsrpInitWin32Csr, "load usermode dll"},
|
|
|
|
{TRUE, CsrpRunWinlogon, "run WinLogon"},
|
2005-03-20 22:55:05 +00:00
|
|
|
};
|
2002-06-14 14:23:14 +00:00
|
|
|
|
1999-07-17 23:10:31 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* NAME
|
2000-02-27 02:12:07 +00:00
|
|
|
* CsrServerInitialization
|
1999-07-17 23:10:31 +00:00
|
|
|
*
|
|
|
|
* DESCRIPTION
|
2005-03-20 22:55:05 +00:00
|
|
|
* Initialize the Win32 environment subsystem server.
|
1999-07-17 23:10:31 +00:00
|
|
|
*
|
|
|
|
* RETURN VALUE
|
|
|
|
* TRUE: Initialization OK; otherwise FALSE.
|
|
|
|
*/
|
2005-03-20 22:55:05 +00:00
|
|
|
BOOL STDCALL
|
2000-02-27 02:12:07 +00:00
|
|
|
CsrServerInitialization (
|
2005-10-08 22:41:49 +00:00
|
|
|
int argc,
|
|
|
|
char ** argv,
|
|
|
|
char ** envp
|
2000-02-27 02:12:07 +00:00
|
|
|
)
|
1999-06-08 22:50:59 +00:00
|
|
|
{
|
2005-07-05 22:35:29 +00:00
|
|
|
UINT i = 0;
|
2005-03-20 22:55:05 +00:00
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
2003-12-02 11:38:47 +00:00
|
|
|
|
2005-03-20 22:55:05 +00:00
|
|
|
DPRINT("CSR: %s called\n", __FUNCTION__);
|
2003-12-02 11:38:47 +00:00
|
|
|
|
2005-03-20 22:55:05 +00:00
|
|
|
for (i=0; i < (sizeof InitRoutine / sizeof InitRoutine[0]); i++)
|
|
|
|
{
|
2005-10-08 22:41:49 +00:00
|
|
|
Status = InitRoutine[i].EntryPoint(argc,argv,envp);
|
2005-03-20 22:55:05 +00:00
|
|
|
if(!NT_SUCCESS(Status))
|
|
|
|
{
|
2005-05-08 04:07:56 +00:00
|
|
|
DPRINT1("CSR: %s: failed to %s (Status=%08lx)\n",
|
2005-03-20 22:55:05 +00:00
|
|
|
__FUNCTION__,
|
|
|
|
InitRoutine[i].ErrorMessage,
|
|
|
|
Status);
|
|
|
|
if (InitRoutine[i].Required)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (CallInitComplete())
|
|
|
|
{
|
|
|
|
Status = SmCompleteSession (hSmApiPort,hSbApiPort,hApiPort);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
1999-06-08 22:50:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|