Skip to content

Commit 3f73319

Browse files
committed
[WINLOGON] Cleanup user login information when logon fails and at logoff (reactos#8182)
1 parent c507b70 commit 3f73319

File tree

1 file changed

+32
-16
lines changed
  • base/system/winlogon

1 file changed

+32
-16
lines changed

base/system/winlogon/sas.c

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -561,18 +561,18 @@ BOOL
561561
HandleLogon(
562562
IN OUT PWLSESSION Session)
563563
{
564-
PROFILEINFOW ProfileInfo;
565564
BOOL ret = FALSE;
566565

567566
/* Loading personal settings */
568567
DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_LOADINGYOURPERSONALSETTINGS);
569568

570-
ProfileInfo.hProfile = INVALID_HANDLE_VALUE;
569+
Session->hProfileInfo = NULL;
571570
if (!(Session->Options & WLX_LOGON_OPT_NO_PROFILE))
572571
{
573572
HKEY hKey;
574573
LONG lError;
575574
BOOL bNoPopups = FALSE;
575+
PROFILEINFOW ProfileInfo;
576576

577577
if (Session->Profile == NULL
578578
|| (Session->Profile->dwType != WLX_PROFILE_TYPE_V1_0
@@ -618,17 +618,19 @@ HandleLogon(
618618
ERR("WL: LoadUserProfileW() failed\n");
619619
goto cleanup;
620620
}
621+
Session->hProfileInfo = ProfileInfo.hProfile;
621622
}
622623

623624
/* Create environment block for the user */
624625
if (!CreateUserEnvironment(Session))
625626
{
626-
WARN("WL: SetUserEnvironment() failed\n");
627+
WARN("WL: CreateUserEnvironment() failed\n");
627628
goto cleanup;
628629
}
629630

630631
CallNotificationDlls(Session, LogonHandler);
631632

633+
/* Enable per-user settings */
632634
DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_APPLYINGYOURPERSONALSETTINGS);
633635
UpdatePerUserSystemParameters(0, TRUE);
634636

@@ -663,8 +665,6 @@ HandleLogon(
663665
if (!InitializeScreenSaver(Session))
664666
WARN("WL: Failed to initialize screen saver\n");
665667

666-
Session->hProfileInfo = ProfileInfo.hProfile;
667-
668668
/* Logon has succeeded. Play sound. */
669669
PlayLogonSound(Session);
670670

@@ -683,25 +683,32 @@ HandleLogon(
683683
FreeWlxMprInfo(&Session->MprNotifyInfo);
684684
ZeroMemory(&Session->MprNotifyInfo, sizeof(Session->MprNotifyInfo));
685685

686-
if (!ret && ProfileInfo.hProfile != INVALID_HANDLE_VALUE)
687-
{
688-
UnloadUserProfile(Session->UserToken, ProfileInfo.hProfile);
689-
}
690686
RemoveStatusMessage(Session);
687+
691688
if (!ret)
692689
{
690+
if (Session->hProfileInfo)
691+
UnloadUserProfile(Session->UserToken, Session->hProfileInfo);
692+
Session->hProfileInfo = NULL;
693+
694+
/* Restore default system parameters */
695+
UpdatePerUserSystemParameters(0, FALSE);
696+
697+
// TODO: Remove session access to window station
698+
// (revert what security.c!AllowAccessOnSession() does).
693699
SetWindowStationUser(Session->InteractiveWindowStation,
694700
&LuidNone, NULL, 0);
701+
702+
/* Switch back to default SYSTEM user */
695703
CloseHandle(Session->UserToken);
696704
Session->UserToken = NULL;
705+
Session->LogonId = LuidNone;
697706
}
698-
699-
if (ret)
707+
else // if (ret)
700708
{
701709
SwitchDesktop(Session->ApplicationDesktop);
702710
Session->LogonState = STATE_LOGGED_ON;
703711
}
704-
705712
return ret;
706713
}
707714

@@ -979,6 +986,7 @@ HandleLogoff(
979986
&LuidNone, NULL, 0);
980987

981988
// DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_LOGGINGOFF);
989+
CallNotificationDlls(Session, LogoffHandler);
982990

983991
// FIXME: Closing network connections!
984992
// DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_CLOSINGNETWORKCONNECTIONS);
@@ -999,14 +1007,22 @@ HandleLogoff(
9991007

10001008
DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_SAVEYOURSETTINGS);
10011009

1002-
UnloadUserProfile(Session->UserToken, Session->hProfileInfo);
1010+
if (Session->hProfileInfo)
1011+
UnloadUserProfile(Session->UserToken, Session->hProfileInfo);
1012+
Session->hProfileInfo = NULL;
10031013

1004-
CallNotificationDlls(Session, LogoffHandler);
1014+
/* Restore default system parameters */
1015+
UpdatePerUserSystemParameters(0, FALSE);
1016+
1017+
// TODO: Remove session access to window station
1018+
// (revert what security.c!AllowAccessOnSession() does).
10051019

1020+
/* Switch back to default SYSTEM user */
10061021
CloseHandle(Session->UserToken);
1007-
UpdatePerUserSystemParameters(0, FALSE);
1008-
Session->LogonState = STATE_LOGGED_OFF;
10091022
Session->UserToken = NULL;
1023+
Session->LogonId = LuidNone;
1024+
1025+
Session->LogonState = STATE_LOGGED_OFF;
10101026

10111027
return STATUS_SUCCESS;
10121028
}

0 commit comments

Comments
 (0)