[MSGINA] Simplify the auto logon code path

- Get rid of DoAutoLogon() and the AutoLogonState variable.
- Handle the auto logon in the normal logon code path instead.
- Set bAutoAdminLogon to FALSE on a successful login. This will prevent another automatic logon after a logoff.
- The IgnoreShiftOverride feature got lost by this change but I will add it again.
This commit is contained in:
Eric Kohl 2018-05-21 16:29:02 +02:00
parent 3dc07c91f8
commit 0d308f4b6e
3 changed files with 21 additions and 127 deletions

View File

@ -873,6 +873,8 @@ DoLogon(
ZeroMemory(pgContext->Password, sizeof(pgContext->Password));
wcscpy(pgContext->Password, Password);
pgContext->bAutoAdminLogon = FALSE;
result = TRUE;
done:
@ -944,21 +946,29 @@ LoggedOutWindowProc(
pgContext = (PGINA_CONTEXT)lParam;
SetWindowLongPtrW(hwndDlg, GWLP_USERDATA, (LONG_PTR)pgContext);
if (!pgContext->bDontDisplayLastUserName)
if (pgContext->bAutoAdminLogon ||
!pgContext->bDontDisplayLastUserName)
SetDlgItemTextW(hwndDlg, IDC_USERNAME, pgContext->UserName);
if (pgContext->bAutoAdminLogon)
SetDlgItemTextW(hwndDlg, IDC_PASSWORD, pgContext->Password);
SetDomainComboBox(GetDlgItem(hwndDlg, IDC_LOGON_TO), pgContext);
if (pgContext->bDisableCAD)
EnableWindow(GetDlgItem(hwndDlg, IDCANCEL), FALSE);
if (!pgContext->bShutdownWithoutLogon)
EnableWindow(GetDlgItem(hwndDlg, IDC_SHUTDOWN), FALSE);
SetDomainComboBox(GetDlgItem(hwndDlg, IDC_LOGON_TO), pgContext);
SetFocus(GetDlgItem(hwndDlg, pgContext->bDontDisplayLastUserName ? IDC_USERNAME : IDC_PASSWORD));
/* Draw the logo bitmap */
pgContext->hBitmap = LoadImageW(pgContext->hDllInstance, MAKEINTRESOURCEW(IDI_ROSLOGO), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
if (pgContext->bAutoAdminLogon)
PostMessage(GetDlgItem(hwndDlg, IDOK), BM_CLICK, 0, 0);
return TRUE;
}

View File

@ -242,6 +242,14 @@ GetRegistrySettings(PGINA_CONTEXT pgContext)
(LPBYTE)&pgContext->Domain,
&dwSize);
dwSize = sizeof(pgContext->Password);
rc = RegQueryValueExW(hKey,
L"DefaultPassword",
NULL,
NULL,
(LPBYTE)&pgContext->Password,
&dwSize);
if (lpShutdownWithoutLogon != NULL)
HeapFree(GetProcessHeap(), 0, lpShutdownWithoutLogon);
@ -333,9 +341,6 @@ WlxInitialize(
/* Locates the authentication package */
//LsaRegisterLogonProcess(...);
/* Check autologon settings the first time */
pgContext->AutoLogonState = AUTOLOGON_CHECK_REGISTRY;
pgContext->nShutdownAction = WLX_SAS_ACTION_SHUTDOWN_POWER_OFF;
ChooseGinaUI();
@ -868,115 +873,6 @@ cleanup:
}
static BOOL
DoAutoLogon(
IN PGINA_CONTEXT pgContext)
{
HKEY WinLogonKey = NULL;
LPWSTR AutoLogon = NULL;
LPWSTR AutoCount = NULL;
LPWSTR IgnoreShiftOverride = NULL;
LPWSTR UserName = NULL;
LPWSTR Domain = NULL;
LPWSTR Password = NULL;
BOOL result = FALSE;
LONG rc;
NTSTATUS Status;
NTSTATUS SubStatus = STATUS_SUCCESS;
TRACE("DoAutoLogon(): AutoLogonState = %lu\n",
pgContext->AutoLogonState);
if (pgContext->AutoLogonState == AUTOLOGON_DISABLED)
return FALSE;
rc = RegOpenKeyExW(
HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\WinLogon",
0,
KEY_QUERY_VALUE,
&WinLogonKey);
if (rc != ERROR_SUCCESS)
goto cleanup;
if (pgContext->AutoLogonState == AUTOLOGON_CHECK_REGISTRY)
{
/* Set it by default to disabled, we might reenable it again later */
pgContext->AutoLogonState = AUTOLOGON_DISABLED;
rc = ReadRegSzValue(WinLogonKey, L"AutoAdminLogon", &AutoLogon);
if (rc != ERROR_SUCCESS)
goto cleanup;
if (wcscmp(AutoLogon, L"1") != 0)
goto cleanup;
rc = ReadRegSzValue(WinLogonKey, L"AutoLogonCount", &AutoCount);
if (rc == ERROR_SUCCESS && wcscmp(AutoCount, L"0") == 0)
goto cleanup;
else if (rc != ERROR_FILE_NOT_FOUND)
goto cleanup;
rc = ReadRegSzValue(WinLogonKey, L"IgnoreShiftOverride", &UserName);
if (rc == ERROR_SUCCESS)
{
if (wcscmp(AutoLogon, L"1") != 0 && GetKeyState(VK_SHIFT) < 0)
goto cleanup;
}
else if (GetKeyState(VK_SHIFT) < 0)
{
/* User pressed SHIFT */
goto cleanup;
}
pgContext->AutoLogonState = AUTOLOGON_ONCE;
result = TRUE;
}
else /* pgContext->AutoLogonState == AUTOLOGON_ONCE */
{
pgContext->AutoLogonState = AUTOLOGON_DISABLED;
rc = ReadRegSzValue(WinLogonKey, L"DefaultUserName", &UserName);
if (rc != ERROR_SUCCESS)
goto cleanup;
rc = ReadRegSzValue(WinLogonKey, L"DefaultDomain", &Domain);
if (rc != ERROR_SUCCESS && rc != ERROR_FILE_NOT_FOUND)
goto cleanup;
rc = ReadRegSzValue(WinLogonKey, L"DefaultPassword", &Password);
if (rc != ERROR_SUCCESS)
goto cleanup;
Status = DoLoginTasks(pgContext, UserName, Domain, Password, &SubStatus);
if (!NT_SUCCESS(Status))
{
/* FIXME: Handle errors!!! */
result = FALSE;
goto cleanup;
}
result = CreateProfile(pgContext, UserName, Domain, Password);
if (result)
{
ZeroMemory(pgContext->Password, sizeof(pgContext->Password));
wcscpy(pgContext->Password, Password);
NotifyBootConfigStatus(TRUE);
}
}
cleanup:
if (WinLogonKey != NULL)
RegCloseKey(WinLogonKey);
HeapFree(GetProcessHeap(), 0, AutoLogon);
HeapFree(GetProcessHeap(), 0, AutoCount);
HeapFree(GetProcessHeap(), 0, IgnoreShiftOverride);
HeapFree(GetProcessHeap(), 0, UserName);
HeapFree(GetProcessHeap(), 0, Domain);
HeapFree(GetProcessHeap(), 0, Password);
TRACE("DoAutoLogon(): AutoLogonState = %lu, returning %d\n",
pgContext->AutoLogonState, result);
return result;
}
/*
* @implemented
*/
@ -998,12 +894,9 @@ WlxDisplaySASNotice(
if (pgContext->bAutoAdminLogon)
{
/* Don't display the window, we want to do an automatic logon */
pgContext->AutoLogonState = AUTOLOGON_ONCE;
pgContext->pWlxFuncs->WlxSasNotify(pgContext->hWlx, WLX_SAS_TYPE_CTRL_ALT_DEL);
return;
}
else
pgContext->AutoLogonState = AUTOLOGON_DISABLED;
if (pgContext->bDisableCAD)
{
@ -1043,14 +936,6 @@ WlxLoggedOutSAS(
pgContext->pMprNotifyInfo = pMprNotifyInfo;
pgContext->pProfile = pProfile;
if (0 == GetSystemMetrics(SM_REMOTESESSION) &&
DoAutoLogon(pgContext))
{
/* User is local and registry contains information
* to log on him automatically */
*phToken = pgContext->UserToken;
return WLX_SAS_ACTION_LOGON;
}
res = pGinaUI->LoggedOutSAS(pgContext);
*phToken = pgContext->UserToken;

View File

@ -42,7 +42,6 @@ typedef struct
HWND hStatusWindow;
HANDLE LsaHandle;
ULONG AuthenticationPackage;
DWORD AutoLogonState;
BOOL bDisableCAD;
BOOL bAutoAdminLogon;
BOOL bDontDisplayLastUserName;