-/* $Id: services.c,v 1.9 2002/10/20 14:54:34 ekohl Exp $
+/* $Id: services.c,v 1.10 2002/12/27 13:54:28 robd Exp $
*
* service control manager
*
PrintString(char* fmt,...)
{
#ifdef DBG
- char buffer[512];
- va_list ap;
+ char buffer[512];
+ va_list ap;
- va_start(ap, fmt);
- vsprintf(buffer, fmt, ap);
- va_end(ap);
+ va_start(ap, fmt);
+ vsprintf(buffer, fmt, ap);
+ va_end(ap);
- OutputDebugStringA(buffer);
+ OutputDebugStringA(buffer);
#endif
}
BOOL
ScmCreateStartEvent(PHANDLE StartEvent)
{
- HANDLE hEvent;
-
- hEvent = CreateEvent(NULL,
- TRUE,
- FALSE,
- _T("SvcctrlStartEvent_A3725DX"));
- if (hEvent == NULL)
- {
- if (GetLastError() == ERROR_ALREADY_EXISTS)
- {
- hEvent = OpenEvent(EVENT_ALL_ACCESS,
- FALSE,
- _T("SvcctrlStartEvent_A3725DX"));
- if (hEvent == NULL)
- {
- return(FALSE);
- }
- }
- else
- {
- return(FALSE);
- }
+ HANDLE hEvent;
+
+ hEvent = CreateEvent(NULL,
+ TRUE,
+ FALSE,
+ _T("SvcctrlStartEvent_A3725DX"));
+ if (hEvent == NULL) {
+ if (GetLastError() == ERROR_ALREADY_EXISTS) {
+ hEvent = OpenEvent(EVENT_ALL_ACCESS,
+ FALSE,
+ _T("SvcctrlStartEvent_A3725DX"));
+ if (hEvent == NULL) {
+ return FALSE;
+ }
+ } else {
+ return FALSE;
+ }
}
-
- *StartEvent = hEvent;
-
- return(TRUE);
+ *StartEvent = hEvent;
+ return TRUE;
}
BOOL
ScmNamedPipeHandleRequest(
- PVOID Request,
- DWORD RequestSize,
- PVOID Reply,
- LPDWORD ReplySize)
+ PVOID Request,
+ DWORD RequestSize,
+ PVOID Reply,
+ LPDWORD ReplySize)
{
- DbgPrint("SCM READ: %s\n", Request);
-
- *ReplySize = 0;
+ DbgPrint("SCM READ: %s\n", Request);
- return FALSE;
+ *ReplySize = 0;
+ return FALSE;
}
DWORD
WINAPI
-ScmNamedPipeThread(
- LPVOID Context)
+ScmNamedPipeThread(LPVOID Context)
{
- CHAR chRequest[PIPE_BUFSIZE];
- CHAR chReply[PIPE_BUFSIZE];
- DWORD cbReplyBytes;
- DWORD cbBytesRead;
- DWORD cbWritten;
- BOOL fSuccess;
- HANDLE hPipe;
-
- DPRINT("Accepting SCM commands through named pipe\n");
-
- hPipe = (HANDLE)Context;
-
- for (;;)
- {
- fSuccess = ReadFile(
- hPipe,
- &chRequest,
- PIPE_BUFSIZE,
- &cbBytesRead,
- NULL);
- if (!fSuccess || cbBytesRead == 0)
- {
- break;
+ CHAR chRequest[PIPE_BUFSIZE];
+ CHAR chReply[PIPE_BUFSIZE];
+ DWORD cbReplyBytes;
+ DWORD cbBytesRead;
+ DWORD cbWritten;
+ BOOL fSuccess;
+ HANDLE hPipe;
+
+ hPipe = (HANDLE)Context;
+
+ DPRINT("ScmNamedPipeThread(%x) - Accepting SCM commands through named pipe\n", hPipe);
+
+ for (;;) {
+ fSuccess = ReadFile(hPipe,
+ &chRequest,
+ PIPE_BUFSIZE,
+ &cbBytesRead,
+ NULL);
+ if (!fSuccess || cbBytesRead == 0) {
+ break;
+ }
+ if (ScmNamedPipeHandleRequest(&chRequest, cbBytesRead, &chReply, &cbReplyBytes)) {
+ fSuccess = WriteFile(hPipe,
+ &chReply,
+ cbReplyBytes,
+ &cbWritten,
+ NULL);
+ if (!fSuccess || cbReplyBytes != cbWritten) {
+ break;
+ }
+ }
}
-
- if (ScmNamedPipeHandleRequest(&chRequest, cbBytesRead, &chReply, &cbReplyBytes))
- {
- fSuccess = WriteFile(
- hPipe,
- &chReply,
- cbReplyBytes,
- &cbWritten,
- NULL);
- if (!fSuccess || cbReplyBytes != cbWritten)
- {
- break;
- }
- }
- }
-
- FlushFileBuffers(hPipe);
- DisconnectNamedPipe(hPipe);
- CloseHandle(hPipe);
-
- return ERROR_SUCCESS;
+ DPRINT("ScmNamedPipeThread(%x) - Disconnecting named pipe connection\n", hPipe);
+ FlushFileBuffers(hPipe);
+ DisconnectNamedPipe(hPipe);
+ CloseHandle(hPipe);
+ DPRINT("ScmNamedPipeThread(%x) - Done.\n", hPipe);
+ return ERROR_SUCCESS;
}
-
BOOL ScmCreateNamedPipe(VOID)
{
- DWORD dwThreadId;
- BOOL fConnected;
- HANDLE hThread;
- HANDLE hPipe;
-
- hPipe = CreateNamedPipe("\\\\.\\pipe\\Ntsvcs",
- PIPE_ACCESS_DUPLEX,
- PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
- PIPE_UNLIMITED_INSTANCES,
- PIPE_BUFSIZE,
- PIPE_BUFSIZE,
- PIPE_TIMEOUT,
- NULL);
- if (hPipe == INVALID_HANDLE_VALUE)
- {
- DPRINT("CreateNamedPipe() failed (%d)\n", GetLastError());
- return(FALSE);
+ DWORD dwThreadId;
+ BOOL fConnected;
+ HANDLE hThread;
+ HANDLE hPipe;
+
+ DPRINT("ScmCreateNamedPipe() - CreateNamedPipe(\"\\\\.\\pipe\\Ntsvcs\")\n");
+
+ hPipe = CreateNamedPipe("\\\\.\\pipe\\Ntsvcs",
+ PIPE_ACCESS_DUPLEX,
+ PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
+ PIPE_UNLIMITED_INSTANCES,
+ PIPE_BUFSIZE,
+ PIPE_BUFSIZE,
+ PIPE_TIMEOUT,
+ NULL);
+ if (hPipe == INVALID_HANDLE_VALUE) {
+ DPRINT("CreateNamedPipe() failed (%d)\n", GetLastError());
+ return FALSE;
}
- fConnected = ConnectNamedPipe(hPipe,
- NULL) ? TRUE : (GetLastError() == ERROR_PIPE_CONNECTED);
- if (fConnected)
- {
- DPRINT("Pipe connected\n");
-
- hThread = CreateThread(NULL,
- 0,
- ScmNamedPipeThread,
- (LPVOID)hPipe,
- 0,
- &dwThreadId);
- if (!hThread)
- {
- DPRINT("Could not create thread (%d)\n", GetLastError());
-
- DisconnectNamedPipe(hPipe);
- CloseHandle(hPipe);
- return(FALSE);
- }
+ DPRINT("CreateNamedPipe() - calling ConnectNamedPipe(%x)\n", hPipe);
+ fConnected = ConnectNamedPipe(hPipe,
+ NULL) ? TRUE : (GetLastError() == ERROR_PIPE_CONNECTED);
+ DPRINT("CreateNamedPipe() - ConnectNamedPipe() returned %d\n", fConnected);
+
+ if (fConnected) {
+ DPRINT("Pipe connected\n");
+ hThread = CreateThread(NULL,
+ 0,
+ ScmNamedPipeThread,
+ (LPVOID)hPipe,
+ 0,
+ &dwThreadId);
+ if (!hThread) {
+ DPRINT("Could not create thread (%d)\n", GetLastError());
+ DisconnectNamedPipe(hPipe);
+ CloseHandle(hPipe);
+ DPRINT("CreateNamedPipe() - returning FALSE\n");
+ return FALSE;
+ }
+ } else {
+ DPRINT("Pipe not connected\n");
+ CloseHandle(hPipe);
+ DPRINT("CreateNamedPipe() - returning FALSE\n");
+ return FALSE;
}
- else
- {
- DPRINT("Pipe not connected\n");
+ DPRINT("CreateNamedPipe() - returning TRUE\n");
+ return TRUE;
+}
- CloseHandle(hPipe);
- return FALSE;
+DWORD
+WINAPI
+ScmNamedPipeListenerThread(LPVOID Context)
+{
+// HANDLE hPipe;
+ DPRINT("ScmNamedPipeListenerThread(%x) - aka SCM.\n", Context);
+
+// hPipe = (HANDLE)Context;
+ for (;;) {
+ PrintString("SCM: Waiting for connection on named pipe...\n");
+ /* Create named pipe */
+ if (!ScmCreateNamedPipe()) {
+ PrintString("\nSCM: Failed to create named pipe\n");
+ break;
+ //ExitThread(0);
+ }
+ PrintString("\nSCM: named pipe session created.\n");
+ Sleep(10);
}
-
- return TRUE;
+ DPRINT("\n\nWARNING: ScmNamedPipeListenerThread(%x) - Aborted.\n\n", Context);
+ return ERROR_SUCCESS;
}
+BOOL StartScmNamedPipeThreadListener(void)
+{
+ DWORD dwThreadId;
+ HANDLE hThread;
+
+ hThread = CreateThread(NULL,
+ 0,
+ ScmNamedPipeListenerThread,
+ NULL, /*(LPVOID)hPipe,*/
+ 0,
+ &dwThreadId);
+
+ if (!hThread) {
+ PrintString("SERVICES: Could not create thread (Status %lx)\n", GetLastError());
+ return FALSE;
+ }
+ return TRUE;
+}
int STDCALL
WinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int nShowCmd)
+ HINSTANCE hPrevInstance,
+ LPSTR lpCmdLine,
+ int nShowCmd)
{
HANDLE hScmStartEvent;
HANDLE hEvent;
NTSTATUS Status;
- PrintString("Service Control Manager\n");
+ PrintString("SERVICES: Service Control Manager\n");
/* Create start event */
if (!ScmCreateStartEvent(&hScmStartEvent))
ExitThread(0);
}
+ PrintString("SERVICES: created start event with handle %x.\n", hScmStartEvent);
/* FIXME: more initialization */
Status = ScmCreateServiceDataBase();
if (!NT_SUCCESS(Status))
{
- PrintString("ScmCreateServiceDataBase() failed (Status %lx)\n", Status);
+ PrintString("SERVICES: failed to create SCM database (Status %lx)\n", Status);
ExitThread(0);
}
ScmGetBootAndSystemDriverState();
#if 0
- /* Create named pipe */
- if (!ScmCreateNamedPipe())
- {
- PrintString("SERVICES: Failed to create named pipe\n");
- ExitThread(0);
- }
+ PrintString("SERVICES: Attempting to create named pipe...\n");
+ /* Create named pipe */
+ if (!ScmCreateNamedPipe()) {
+ PrintString("SERVICES: Failed to create named pipe\n");
+ ExitThread(0);
+ }
+ PrintString("SERVICES: named pipe created successfully.\n");
+#else
+ PrintString("SERVICES: Attempting to create named pipe listener...\n");
+ if (!StartScmNamedPipeThreadListener()) {
+ PrintString("SERVICES: Failed to create named pipe listener thread.\n");
+ ExitThread(0);
+ }
+ PrintString("SERVICES: named pipe listener thread created.\n");
#endif
/* FIXME: create listener thread for pipe */
PrintString("SERVICES: Running.\n");
+#if 1
hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
WaitForSingleObject(hEvent, INFINITE);
-#if 0
+#else
for (;;)
{
- NtYieldExecution();
+ NtYieldExecution();
}
#endif
-/* $Id: winlogon.c,v 1.12 2002/09/08 10:23:48 chorns Exp $
+/* $Id: winlogon.c,v 1.13 2002/12/27 13:54:28 robd Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
#include <wchar.h>
-#define NDEBUG
+#define DBG
#include <debug.h>
/* GLOBALS ******************************************************************/
StartupInfo.cbReserved2 = 0;
StartupInfo.lpReserved2 = 0;
+ PrintString("WL: Creating new process - \"services.exe\".\n");
+
Result = CreateProcess(CommandLine,
- NULL,
- NULL,
- NULL,
- FALSE,
- DETACHED_PROCESS,
- NULL,
- NULL,
- &StartupInfo,
- &ProcessInformation);
+ NULL,
+ NULL,
+ NULL,
+ FALSE,
+ DETACHED_PROCESS,
+ NULL,
+ NULL,
+ &StartupInfo,
+ &ProcessInformation);
if (!Result)
{
- PrintString("WL: Failed to execute services\n");
- return FALSE;
+ PrintString("WL: Failed to execute services\n");
+ return FALSE;
}
/* wait for event creation (by SCM) for max. 20 seconds */
for (Count = 0; Count < 20; Count++)
{
- Sleep(1000);
+ Sleep(1000);
- ServicesInitEvent = OpenEvent(EVENT_ALL_ACCESS, //SYNCHRONIZE,
- FALSE,
- "SvcctrlStartEvent_A3725DX");
- if (ServicesInitEvent != NULL)
- {
- break;
- }
+ //DbgPrint("WL: Attempting to open event \"SvcctrlStartEvent_A3725DX\"\n");
+ ServicesInitEvent = OpenEvent(EVENT_ALL_ACCESS, //SYNCHRONIZE,
+ FALSE,
+ "SvcctrlStartEvent_A3725DX");
+ if (ServicesInitEvent != NULL)
+ {
+ break;
+ }
}
+ if (ServicesInitEvent == NULL)
+ {
+ DbgPrint("WL: Failed to open event \"SvcctrlStartEvent_A3725DX\"\n");
+ return FALSE;
+ }
+
/* wait for event signalization */
+ //DbgPrint("WL: Waiting forever on event handle: %x\n", ServicesInitEvent);
WaitForSingleObject(ServicesInitEvent, INFINITE);
+ //DbgPrint("WL: Closing event object \"SvcctrlStartEvent_A3725DX\"\n");
CloseHandle(ServicesInitEvent);
+ DbgPrint("WL: StartServices() Done.\n");
return TRUE;
}
CHAR CommandLine[MAX_PATH];
LsassInitEvent = CreateEvent(NULL,
- TRUE,
- FALSE,
- "\\LsassInitDone");
+ TRUE,
+ FALSE,
+ "\\LsassInitDone");
if (LsassInitEvent == NULL)
{
- DbgPrint("Failed to create lsass notification event\n");
- return(FALSE);
+ DbgPrint("WL: Failed to create lsass notification event\n");
+ return(FALSE);
}
/* Start the local security authority subsystem (lsass.exe) */
StartupInfo.lpReserved2 = 0;
Result = CreateProcess(CommandLine,
- NULL,
- NULL,
- NULL,
- FALSE,
- DETACHED_PROCESS,
- NULL,
- NULL,
- &StartupInfo,
- &ProcessInformation);
+ NULL,
+ NULL,
+ NULL,
+ FALSE,
+ DETACHED_PROCESS,
+ NULL,
+ NULL,
+ &StartupInfo,
+ &ProcessInformation);
if (!Result)
{
- DbgPrint("WL: Failed to execute lsass\n");
- return(FALSE);
+ DbgPrint("WL: Failed to execute lsass\n");
+ return(FALSE);
}
DPRINT("WL: Waiting for lsass\n");
StartupInfo.lpReserved2 = 0;
Result = CreateProcess(CommandLine,
- NULL,
- NULL,
- NULL,
- FALSE,
- DETACHED_PROCESS,
- NULL,
- CurrentDirectory,
- &StartupInfo,
- &ProcessInformation);
+ NULL,
+ NULL,
+ NULL,
+ FALSE,
+ DETACHED_PROCESS,
+ NULL,
+ CurrentDirectory,
+ &StartupInfo,
+ &ProcessInformation);
if (!Result)
{
- DbgPrint("WL: Failed to execute user shell\n");
- return;
+ DbgPrint("WL: Failed to execute user shell\n");
+ return;
}
WaitForSingleObject(ProcessInformation.hProcess, INFINITE);
CloseHandle( ProcessInformation.hProcess );
int STDCALL
WinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int nShowCmd)
+ HINSTANCE hPrevInstance,
+ LPSTR lpCmdLine,
+ int nShowCmd)
{
#if 0
LSA_STRING ProcessName;
CreateWindowStationW(L"WinSta0", 0, GENERIC_ALL, NULL);
if (InteractiveWindowStation == NULL)
{
- DbgPrint("Failed to create window station (0x%X)\n", GetLastError());
+ DbgPrint("WL: Failed to create window station (0x%X)\n", GetLastError());
NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED, 0, 0, 0, 0, 0);
ExitProcess(1);
}
*/
ApplicationDesktop =
CreateDesktopW(L"Default",
- NULL,
- NULL,
- 0, /* FIXME: Set some flags */
- GENERIC_ALL,
- NULL);
+ NULL,
+ NULL,
+ 0, /* FIXME: Set some flags */
+ GENERIC_ALL,
+ NULL);
/*
* Create the winlogon desktop
*/
WinlogonDesktop = CreateDesktopW(L"Winlogon",
- NULL,
- NULL,
- 0, /* FIXME: Set some flags */
- GENERIC_ALL,
- NULL);
+ NULL,
+ NULL,
+ 0, /* FIXME: Set some flags */
+ GENERIC_ALL,
+ NULL);
/*
* Create the screen saver desktop
*/
ScreenSaverDesktop = CreateDesktopW(L"Screen-Saver",
- NULL,
- NULL,
- 0, /* FIXME: Set some flags */
- GENERIC_ALL,
- NULL);
+ NULL,
+ NULL,
+ 0, /* FIXME: Set some flags */
+ GENERIC_ALL,
+ NULL);
/*
* Switch to winlogon desktop
*/
/* FIXME: Do start up in the application desktop for now. */
Status = NtSetInformationProcess(NtCurrentProcess(),
- ProcessDesktop,
- &ApplicationDesktop,
- sizeof(ApplicationDesktop));
+ ProcessDesktop,
+ &ApplicationDesktop,
+ sizeof(ApplicationDesktop));
if (!NT_SUCCESS(Status))
{
DbgPrint("WL: Cannot set default desktop for winlogon.\n");
Success = SwitchDesktop(ApplicationDesktop);
if (!Success)
{
- DbgPrint("Cannot switch to Winlogon desktop (0x%X)\n", GetLastError());
+ DbgPrint("WL: Cannot switch to Winlogon desktop (0x%X)\n", GetLastError());
}
AllocConsole();
SetConsoleTitle( "Winlogon" );
/* start system processes (services.exe & lsass.exe) */
- StartServices();
+ Success = StartServices();
+ if (!Success)
+ {
+ DbgPrint("WL: Failed to Start Services (0x%X)\n", GetLastError());
+ }
#if 0
- StartLsass();
+ Success = StartLsass();
+ if (!Success)
+ {
+ DbgPrint("WL: Failed to Start Security System (0x%X)\n", GetLastError());
+ }
#endif
/* FIXME: What name does the real WinLogon use? */
Status = LsaRegisterLogonProcess(&ProcessName, &LsaHandle, &Mode);
if (!NT_SUCCESS(Status))
{
- DbgPrint("WL: Failed to connect to lsass\n");
- return(1);
+ DbgPrint("WL: Failed to connect to lsass\n");
+ return(1);
}
#endif
#if 0
/* Display login prompt */
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),
- LoginPrompt,
- strlen(LoginPrompt), // wcslen(LoginPrompt),
- &Result,
- NULL);
+ LoginPrompt,
+ strlen(LoginPrompt), // wcslen(LoginPrompt),
+ &Result,
+ NULL);
i = 0;
do
- {
- ReadConsole(GetStdHandle(STD_INPUT_HANDLE),
- &LoginName[i],
- 1,
- &Result,
- NULL);
- i++;
- } while (LoginName[i - 1] != '\n');
+ {
+ ReadConsole(GetStdHandle(STD_INPUT_HANDLE),
+ &LoginName[i],
+ 1,
+ &Result,
+ NULL);
+ i++;
+ } while (LoginName[i - 1] != '\n');
LoginName[i - 1] = 0;
- /* Display password prompt */
+ /* Display password prompt */
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),
- PasswordPrompt,
- strlen(PasswordPrompt), // wcslen(PasswordPrompt),
- &Result,
- NULL);
+ PasswordPrompt,
+ strlen(PasswordPrompt), // wcslen(PasswordPrompt),
+ &Result,
+ NULL);
i = 0;
do
- {
- ReadConsole(GetStdHandle(STD_INPUT_HANDLE),
- &Password[i],
- 1,
- &Result,
- NULL);
- i++;
- } while (Password[i - 1] != '\n');
+ {
+ ReadConsole(GetStdHandle(STD_INPUT_HANDLE),
+ &Password[i],
+ 1,
+ &Result,
+ NULL);
+ i++;
+ } while (Password[i - 1] != '\n');
Password[i - 1] =0;
#endif
DoLoginUser(LoginName, Password);