int _cdecl _main(int argc, char *argv[], char *envp[], int DebugFlag) { KPRIORITY BasePriority = (8 + 1) + 4; NTSTATUS Status; //ULONG Response; // see the #if 0 UNREFERENCED_PARAMETER(envp); UNREFERENCED_PARAMETER(DebugFlag); /* Set the Priority */ NtSetInformationProcess(NtCurrentProcess(), ProcessBasePriority, &BasePriority, sizeof(KPRIORITY)); /* Give us IOPL so that we can access the VGA registers */ Status = NtSetInformationProcess(NtCurrentProcess(), ProcessUserModeIOPL, NULL, 0); if (!NT_SUCCESS(Status)) { /* Raise a hard error */ DPRINT1("CSRSS: Could not raise IOPL, Status: 0x%08lx\n", Status); #if 0 Status = NtRaiseHardError(STATUS_IO_PRIVILEGE_FAILED, 0, 0, NULL, OptionOk, &Response); #endif } /* Initialize CSR through CSRSRV */ Status = CsrServerInitialization(argc, argv); if (!NT_SUCCESS(Status)) { /* Kill us */ DPRINT1("CSRSS: Unable to initialize server, Status: 0x%08lx\n", Status); NtTerminateProcess(NtCurrentProcess(), Status); } /* Disable errors */ CsrpSetDefaultProcessHardErrorMode(); /* If this is Session 0, make sure killing us bugchecks the system */ if (NtCurrentPeb()->SessionId == 0) RtlSetProcessIsCritical(TRUE, NULL, FALSE); /* Kill this thread. CSRSRV keeps us going */ NtTerminateThread(NtCurrentThread(), Status); return 0; }
BOOLEAN WINAPI CallPerInstanceInitFunctions ( _In_ PSVCHOST_OPTIONS pOptions ) { PIMAGE_NT_HEADERS pNtHeaders; BOOLEAN bResult; /* Is COM required for this host? */ if (pOptions->CoInitializeSecurityParam != 0) { /* Yes, initialize COM security and parameters */ bResult = InitializeSecurity(pOptions->CoInitializeSecurityParam, pOptions->AuthenticationLevel, pOptions->ImpersonationLevel, pOptions->AuthenticationCapabilities); if (bResult != TRUE) return FALSE; } /* Do we have a custom RPC stack size? */ if (pOptions->DefaultRpcStackSize != 0) { /* Yes, go set it */ RpcMgmtSetServerStackSize(pOptions->DefaultRpcStackSize << 10); } else { /* Nope, get the NT headers from the image */ pNtHeaders = RtlImageNtHeader(NtCurrentPeb()->ImageBaseAddress); if (pNtHeaders) { /* And just use whatever the default thread stack is */ RpcMgmtSetServerStackSize(pNtHeaders->OptionalHeader.SizeOfStackCommit); } } /* Is this host holding critical services? */ if (pOptions->SystemCritical != FALSE) { /* Mark the process as critical if so */ RtlSetProcessIsCritical(TRUE, NULL, TRUE); } /* All done */ return TRUE; }
NTSTATUS _main(IN INT argc, IN PCHAR argv[], IN PCHAR envp[], IN ULONG DebugFlag) { NTSTATUS Status; KPRIORITY SetBasePriority; ULONG_PTR Parameters[4]; HANDLE Handles[2]; PVOID State; ULONG Flags; PROCESS_BASIC_INFORMATION ProcessInfo; UNICODE_STRING DbgString, InitialCommand; /* Make us critical */ RtlSetProcessIsCritical(TRUE, NULL, FALSE); RtlSetThreadIsCritical(TRUE, NULL, FALSE); /* Raise our priority */ SetBasePriority = 11; Status = NtSetInformationProcess(NtCurrentProcess(), ProcessBasePriority, (PVOID)&SetBasePriority, sizeof(SetBasePriority)); ASSERT(NT_SUCCESS(Status)); /* Save the debug flag if it was passed */ if (DebugFlag) SmpDebug = DebugFlag != 0; /* Build the hard error parameters */ Parameters[0] = (ULONG_PTR)&DbgString; Parameters[1] = Parameters[2] = Parameters[3] = 0; /* Enter SEH so we can terminate correctly if anything goes wrong */ _SEH2_TRY { /* Initialize SMSS */ Status = SmpInit(&InitialCommand, Handles); if (!NT_SUCCESS(Status)) { DPRINT1("SMSS: SmpInit return failure - Status == %x\n", Status); RtlInitUnicodeString(&DbgString, L"Session Manager Initialization"); Parameters[1] = Status; _SEH2_LEAVE; } /* Get the global flags */ Status = NtQuerySystemInformation(SystemFlagsInformation, &Flags, sizeof(Flags), NULL); ASSERT(NT_SUCCESS(Status)); /* Before executing the initial command check if the debug flag is on */ if (Flags & (FLG_DEBUG_INITIAL_COMMAND | FLG_DEBUG_INITIAL_COMMAND_EX)) { /* SMSS should launch ntsd with a few parameters at this point */ DPRINT1("Global Flags Set to SMSS Debugging: Not yet supported\n"); } /* Execute the initial command (Winlogon.exe) */ Status = SmpExecuteInitialCommand(0, &InitialCommand, &Handles[1], NULL); if (!NT_SUCCESS(Status)) { /* Fail and raise a hard error */ DPRINT1("SMSS: Execute Initial Command failed\n"); RtlInitUnicodeString(&DbgString, L"Session Manager ExecuteInitialCommand"); Parameters[1] = Status; _SEH2_LEAVE; } /* Check if we're already attached to a session */ Status = SmpAcquirePrivilege(SE_LOAD_DRIVER_PRIVILEGE, &State); if (AttachedSessionId != -1) { /* Detach from it, we should be in no session right now */ Status = NtSetSystemInformation(SystemSessionDetach, &AttachedSessionId, sizeof(AttachedSessionId)); ASSERT(NT_SUCCESS(Status)); AttachedSessionId = -1; } SmpReleasePrivilege(State); /* Wait on either CSRSS or Winlogon to die */ Status = NtWaitForMultipleObjects(RTL_NUMBER_OF(Handles), Handles, WaitAny, FALSE, NULL); if (Status == STATUS_WAIT_0) { /* CSRSS is dead, get exit code and prepare for the hard error */ RtlInitUnicodeString(&DbgString, L"Windows SubSystem"); Status = NtQueryInformationProcess(Handles[0], ProcessBasicInformation, &ProcessInfo, sizeof(ProcessInfo), NULL); DPRINT1("SMSS: Windows subsystem terminated when it wasn't supposed to.\n"); } else { /* The initial command is dead or we have another failure */ RtlInitUnicodeString(&DbgString, L"Windows Logon Process"); if (Status == STATUS_WAIT_1) { /* Winlogon.exe got terminated, get its exit code */ Status = NtQueryInformationProcess(Handles[1], ProcessBasicInformation, &ProcessInfo, sizeof(ProcessInfo), NULL); } else { /* Something else satisfied our wait, so set the wait status */ ProcessInfo.ExitStatus = Status; Status = STATUS_SUCCESS; } DPRINT1("SMSS: Initial command '%wZ' terminated when it wasn't supposed to.\n", &InitialCommand); } /* Check if NtQueryInformationProcess was successful */ if (NT_SUCCESS(Status)) { /* Then we must have a valid exit status in the structure, use it */ Parameters[1] = ProcessInfo.ExitStatus; } else { /* We really don't know what happened, so set a generic error */ Parameters[1] = STATUS_UNSUCCESSFUL; } } _SEH2_EXCEPT(SmpUnhandledExceptionFilter(_SEH2_GetExceptionInformation())) { /* The filter should never return here */ ASSERT(FALSE); } _SEH2_END; /* Something in the init loop failed, terminate SMSS */ return SmpTerminate(Parameters, 1, RTL_NUMBER_OF(Parameters)); }
int WINAPI WinMain( IN HINSTANCE hInstance, IN HINSTANCE hPrevInstance, IN LPSTR lpCmdLine, IN int nShowCmd) { #if 0 LSA_STRING ProcessName, PackageName; HANDLE LsaHandle; LSA_OPERATIONAL_MODE Mode; BOOLEAN Old; ULONG AuthenticationPackage; NTSTATUS Status; #endif ULONG HardErrorResponse; MSG Msg; UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); UNREFERENCED_PARAMETER(nShowCmd); hAppInstance = hInstance; /* Make us critical */ RtlSetProcessIsCritical(TRUE, NULL, FALSE); RtlSetThreadIsCritical(TRUE, NULL, FALSE); if (!RegisterLogonProcess(GetCurrentProcessId(), TRUE)) { ERR("WL: Could not register logon process\n"); NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED, 0, 0, NULL, OptionOk, &HardErrorResponse); ExitProcess(1); } WLSession = (PWLSESSION)HeapAlloc(GetProcessHeap(), 0, sizeof(WLSESSION)); if (!WLSession) { ERR("WL: Could not allocate memory for winlogon instance\n"); NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED, 0, 0, NULL, OptionOk, &HardErrorResponse); ExitProcess(1); } ZeroMemory(WLSession, sizeof(WLSESSION)); WLSession->DialogTimeout = 120; /* 2 minutes */ /* Initialize the dialog tracking list */ InitDialogListHead(); if (!CreateWindowStationAndDesktops(WLSession)) { ERR("WL: Could not create window station and desktops\n"); NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED, 0, 0, NULL, OptionOk, &HardErrorResponse); ExitProcess(1); } LockWorkstation(WLSession); /* Load default keyboard layouts */ if (!InitKeyboardLayouts()) { ERR("WL: Could not preload keyboard layouts\n"); NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED, 0, 0, NULL, OptionOk, &HardErrorResponse); ExitProcess(1); } if (!StartRpcServer()) { ERR("WL: Could not start the RPC server\n"); NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED, 0, 0, NULL, OptionOk, &HardErrorResponse); ExitProcess(1); } if (!StartServicesManager()) { ERR("WL: Could not start services.exe\n"); NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED, 0, 0, NULL, OptionOk, &HardErrorResponse); ExitProcess(1); } if (!StartLsass()) { ERR("WL: Failed to start lsass.exe service (error %lu)\n", GetLastError()); NtRaiseHardError(STATUS_SYSTEM_PROCESS_TERMINATED, 0, 0, NULL, OptionOk, &HardErrorResponse); ExitProcess(1); } /* Wait for the LSA server */ WaitForLsass(); /* Init Notifications */ InitNotifications(); /* Load and initialize gina */ if (!GinaInit(WLSession)) { ERR("WL: Failed to initialize Gina\n"); // FIXME: Retrieve the real name of the GINA DLL we were trying to load. // It is known only inside the GinaInit function... DialogBoxParam(hAppInstance, MAKEINTRESOURCE(IDD_GINALOADFAILED), GetDesktopWindow(), GinaLoadFailedWindowProc, (LPARAM)L"msgina.dll"); HandleShutdown(WLSession, WLX_SAS_ACTION_SHUTDOWN_REBOOT); ExitProcess(1); } DisplayStatusMessage(WLSession, WLSession->WinlogonDesktop, IDS_REACTOSISSTARTINGUP); #if 0 /* Connect to NetLogon service (lsass.exe) */ /* Real winlogon uses "Winlogon" */ RtlInitUnicodeString((PUNICODE_STRING)&ProcessName, L"Winlogon"); Status = LsaRegisterLogonProcess(&ProcessName, &LsaHandle, &Mode); if (Status == STATUS_PORT_CONNECTION_REFUSED) { /* Add the 'SeTcbPrivilege' privilege and try again */ Status = RtlAdjustPrivilege(SE_TCB_PRIVILEGE, TRUE, TRUE, &Old); if (!NT_SUCCESS(Status)) { ERR("RtlAdjustPrivilege() failed with error %lu\n", LsaNtStatusToWinError(Status)); return 1; } Status = LsaRegisterLogonProcess(&ProcessName, &LsaHandle, &Mode); } if (!NT_SUCCESS(Status)) { ERR("LsaRegisterLogonProcess() failed with error %lu\n", LsaNtStatusToWinError(Status)); return 1; } RtlInitUnicodeString((PUNICODE_STRING)&PackageName, MICROSOFT_KERBEROS_NAME_W); Status = LsaLookupAuthenticationPackage(LsaHandle, &PackageName, &AuthenticationPackage); if (!NT_SUCCESS(Status)) { ERR("LsaLookupAuthenticationPackage() failed with error %lu\n", LsaNtStatusToWinError(Status)); LsaDeregisterLogonProcess(LsaHandle); return 1; } #endif CallNotificationDlls(WLSession, StartupHandler); /* Create a hidden window to get SAS notifications */ if (!InitializeSAS(WLSession)) { ERR("WL: Failed to initialize SAS\n"); ExitProcess(2); } // DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_PREPARENETWORKCONNECTIONS); // DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_APPLYINGCOMPUTERSETTINGS); /* Display logged out screen */ WLSession->LogonState = STATE_INIT; RemoveStatusMessage(WLSession); /* Check for pending setup */ if (GetSetupType() != 0) { /* Run setup and reboot when done */ TRACE("WL: Setup mode detected\n"); RunSetup(); } else { PostMessageW(WLSession->SASWindow, WLX_WM_SAS, WLX_SAS_TYPE_CTRL_ALT_DEL, 0); } (void)LoadLibraryW(L"sfc_os.dll"); /* Tell kernel that CurrentControlSet is good (needed * to support Last good known configuration boot) */ NtInitializeRegistry(CM_BOOT_FLAG_ACCEPTED | 1); /* Message loop for the SAS window */ while (GetMessageW(&Msg, WLSession->SASWindow, 0, 0)) { TranslateMessage(&Msg); DispatchMessageW(&Msg); } CleanupNotifications(); /* We never go there */ return 0; }