DWORD WINAPI InstallReactOS(HINSTANCE hInstance) { TCHAR szBuffer[MAX_PATH]; HANDLE token; TOKEN_PRIVILEGES privs; HKEY hKey; HINF hShortcutsInf; InitializeSetupActionLog(FALSE); LogItem(SYSSETUP_SEVERITY_INFORMATION, L"Installing ReactOS"); if (!InitializeProfiles()) { FatalError("InitializeProfiles() failed"); return 0; } CreateTempDir(L"TEMP"); CreateTempDir(L"TMP"); if (GetWindowsDirectory(szBuffer, sizeof(szBuffer) / sizeof(TCHAR))) { if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_WRITE, &hKey) == ERROR_SUCCESS) { RegSetValueExW(hKey, L"PathName", 0, REG_SZ, (LPBYTE)szBuffer, (wcslen(szBuffer) + 1) * sizeof(WCHAR)); RegSetValueExW(hKey, L"SystemRoot", 0, REG_SZ, (LPBYTE)szBuffer, (wcslen(szBuffer) + 1) * sizeof(WCHAR)); RegCloseKey(hKey); } PathAddBackslash(szBuffer); _tcscat(szBuffer, _T("system")); CreateDirectory(szBuffer, NULL); } if (!CommonInstall()) return 0; InstallWizard(); InstallSecurity(); SetAutoAdminLogon(); hShortcutsInf = SetupOpenInfFileW(L"shortcuts.inf", NULL, INF_STYLE_WIN4, NULL); if (hShortcutsInf == INVALID_HANDLE_VALUE) { FatalError("Failed to open shortcuts.inf"); return 0; } if (!CreateShortcuts(hShortcutsInf, L"ShortcutFolders")) { FatalError("CreateShortcuts() failed"); return 0; } SetupCloseInfFile(hShortcutsInf); /* ROS HACK, as long as NtUnloadKey is not implemented */ { NTSTATUS Status = NtUnloadKey(NULL); if (Status == STATUS_NOT_IMPLEMENTED) { /* Create the Administrator profile */ PROFILEINFOW ProfileInfo; HANDLE hToken; BOOL ret; ret = LogonUserW(AdminInfo.Name, AdminInfo.Domain, AdminInfo.Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &hToken); if (!ret) { FatalError("LogonUserW() failed!"); return 0; } ZeroMemory(&ProfileInfo, sizeof(PROFILEINFOW)); ProfileInfo.dwSize = sizeof(PROFILEINFOW); ProfileInfo.lpUserName = L"Administrator"; ProfileInfo.dwFlags = PI_NOUI; LoadUserProfileW(hToken, &ProfileInfo); CloseHandle(hToken); } else { DPRINT1("ROS HACK not needed anymore. Please remove it\n"); } } /* END OF ROS HACK */ SetupCloseInfFile(hSysSetupInf); SetSetupType(0); LogItem(SYSSETUP_SEVERITY_INFORMATION, L"Installing ReactOS done"); TerminateSetupActionLog(); if (AdminInfo.Name != NULL) RtlFreeHeap(RtlGetProcessHeap(), 0, AdminInfo.Name); if (AdminInfo.Domain != NULL) RtlFreeHeap(RtlGetProcessHeap(), 0, AdminInfo.Domain); if (AdminInfo.Password != NULL) RtlFreeHeap(RtlGetProcessHeap(), 0, AdminInfo.Password); /* Get shutdown privilege */ if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token)) { FatalError("OpenProcessToken() failed!"); return 0; } if (!LookupPrivilegeValue( NULL, SE_SHUTDOWN_NAME, &privs.Privileges[0].Luid)) { FatalError("LookupPrivilegeValue() failed!"); return 0; } privs.PrivilegeCount = 1; privs.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; if (AdjustTokenPrivileges( token, FALSE, &privs, 0, (PTOKEN_PRIVILEGES)NULL, NULL) == 0) { FatalError("AdjustTokenPrivileges() failed!"); return 0; } ExitWindowsEx(EWX_REBOOT, 0); return 0; }
static BOOL HandleLogon( IN OUT PWLSESSION Session) { PROFILEINFOW ProfileInfo; BOOL ret = FALSE; /* Loading personal settings */ DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_LOADINGYOURPERSONALSETTINGS); ProfileInfo.hProfile = INVALID_HANDLE_VALUE; if (0 == (Session->Options & WLX_LOGON_OPT_NO_PROFILE)) { if (Session->Profile == NULL || (Session->Profile->dwType != WLX_PROFILE_TYPE_V1_0 && Session->Profile->dwType != WLX_PROFILE_TYPE_V2_0)) { ERR("WL: Wrong profile\n"); goto cleanup; } /* Load the user profile */ ZeroMemory(&ProfileInfo, sizeof(PROFILEINFOW)); ProfileInfo.dwSize = sizeof(PROFILEINFOW); ProfileInfo.dwFlags = 0; ProfileInfo.lpUserName = Session->MprNotifyInfo.pszUserName; ProfileInfo.lpProfilePath = Session->Profile->pszProfile; if (Session->Profile->dwType >= WLX_PROFILE_TYPE_V2_0) { ProfileInfo.lpDefaultPath = Session->Profile->pszNetworkDefaultUserProfile; ProfileInfo.lpServerName = Session->Profile->pszServerName; ProfileInfo.lpPolicyPath = Session->Profile->pszPolicy; } if (!LoadUserProfileW(Session->UserToken, &ProfileInfo)) { ERR("WL: LoadUserProfileW() failed\n"); goto cleanup; } } /* Create environment block for the user */ if (!CreateUserEnvironment(Session)) { WARN("WL: SetUserEnvironment() failed\n"); goto cleanup; } CallNotificationDlls(Session, LogonHandler); DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_APPLYINGYOURPERSONALSETTINGS); UpdatePerUserSystemParameters(0, TRUE); /* Set default user language */ if (!SetDefaultLanguage(Session)) { WARN("WL: SetDefaultLanguage() failed\n"); goto cleanup; } AllowWinstaAccess(Session); /* Connect remote resources */ RestoreAllConnections(Session); if (!StartUserShell(Session)) { //WCHAR StatusMsg[256]; WARN("WL: WlxActivateUserShell() failed\n"); //LoadStringW(hAppInstance, IDS_FAILEDACTIVATEUSERSHELL, StatusMsg, sizeof(StatusMsg) / sizeof(StatusMsg[0])); //MessageBoxW(0, StatusMsg, NULL, MB_ICONERROR); goto cleanup; } CallNotificationDlls(Session, StartShellHandler); if (!InitializeScreenSaver(Session)) WARN("WL: Failed to initialize screen saver\n"); Session->hProfileInfo = ProfileInfo.hProfile; /* Logon has succeeded. Play sound. */ PlayLogonSound(Session); ret = TRUE; cleanup: if (Session->Profile) { HeapFree(GetProcessHeap(), 0, Session->Profile->pszProfile); HeapFree(GetProcessHeap(), 0, Session->Profile); } Session->Profile = NULL; if (!ret && ProfileInfo.hProfile != INVALID_HANDLE_VALUE) { UnloadUserProfile(Session->UserToken, ProfileInfo.hProfile); } RemoveStatusMessage(Session); if (!ret) { SetWindowStationUser(Session->InteractiveWindowStation, &LuidNone, NULL, 0); CloseHandle(Session->UserToken); Session->UserToken = NULL; } if (ret) { SwitchDesktop(Session->ApplicationDesktop); Session->LogonState = STATE_LOGGED_ON; } return ret; }
BOOL WINAPI LoadUserProfileA(IN HANDLE hToken, IN OUT LPPROFILEINFOA lpProfileInfo) { BOOL bResult = FALSE; PROFILEINFOW ProfileInfoW = {0}; int len; DPRINT("LoadUserProfileA() called\n"); /* Check profile info */ if (!lpProfileInfo || (lpProfileInfo->dwSize != sizeof(PROFILEINFOA)) || (lpProfileInfo->lpUserName == NULL) || (lpProfileInfo->lpUserName[0] == 0)) { SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } /* Convert the structure to UNICODE... */ ProfileInfoW.dwSize = sizeof(PROFILEINFOW); ProfileInfoW.dwFlags = lpProfileInfo->dwFlags; if (lpProfileInfo->lpUserName) { len = MultiByteToWideChar(CP_ACP, 0, lpProfileInfo->lpUserName, -1, NULL, 0); ProfileInfoW.lpUserName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); if (!ProfileInfoW.lpUserName) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); goto cleanup; } MultiByteToWideChar(CP_ACP, 0, lpProfileInfo->lpUserName, -1, ProfileInfoW.lpUserName, len); } if (lpProfileInfo->lpProfilePath) { len = MultiByteToWideChar(CP_ACP, 0, lpProfileInfo->lpProfilePath, -1, NULL, 0); ProfileInfoW.lpProfilePath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); if (!ProfileInfoW.lpProfilePath) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); goto cleanup; } MultiByteToWideChar(CP_ACP, 0, lpProfileInfo->lpProfilePath, -1, ProfileInfoW.lpProfilePath, len); } if (lpProfileInfo->lpDefaultPath) { len = MultiByteToWideChar(CP_ACP, 0, lpProfileInfo->lpDefaultPath, -1, NULL, 0); ProfileInfoW.lpDefaultPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); if (!ProfileInfoW.lpDefaultPath) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); goto cleanup; } MultiByteToWideChar(CP_ACP, 0, lpProfileInfo->lpDefaultPath, -1, ProfileInfoW.lpDefaultPath, len); } if (lpProfileInfo->lpServerName) { len = MultiByteToWideChar(CP_ACP, 0, lpProfileInfo->lpServerName, -1, NULL, 0); ProfileInfoW.lpServerName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); if (!ProfileInfoW.lpServerName) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); goto cleanup; } MultiByteToWideChar(CP_ACP, 0, lpProfileInfo->lpServerName, -1, ProfileInfoW.lpServerName, len); } if ((ProfileInfoW.dwFlags & PI_APPLYPOLICY) != 0 && lpProfileInfo->lpPolicyPath) { len = MultiByteToWideChar(CP_ACP, 0, lpProfileInfo->lpPolicyPath, -1, NULL, 0); ProfileInfoW.lpPolicyPath = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); if (!ProfileInfoW.lpPolicyPath) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); goto cleanup; } MultiByteToWideChar(CP_ACP, 0, lpProfileInfo->lpPolicyPath, -1, ProfileInfoW.lpPolicyPath, len); } /* ... and call the UNICODE function */ bResult = LoadUserProfileW(hToken, &ProfileInfoW); /* Save the returned value */ lpProfileInfo->hProfile = ProfileInfoW.hProfile; cleanup: /* Memory cleanup */ if (ProfileInfoW.lpUserName) HeapFree(GetProcessHeap(), 0, ProfileInfoW.lpUserName); if (ProfileInfoW.lpProfilePath) HeapFree(GetProcessHeap(), 0, ProfileInfoW.lpProfilePath); if (ProfileInfoW.lpDefaultPath) HeapFree(GetProcessHeap(), 0, ProfileInfoW.lpDefaultPath); if (ProfileInfoW.lpServerName) HeapFree(GetProcessHeap(), 0, ProfileInfoW.lpServerName); if ((ProfileInfoW.dwFlags & PI_APPLYPOLICY) != 0 && ProfileInfoW.lpPolicyPath) HeapFree(GetProcessHeap(), 0, ProfileInfoW.lpPolicyPath); return bResult; }