Skip to content

Commit 51ee32f

Browse files
committed
[WINLOGON] Close all the user network connections only at logoff (reactos#8324)
Per-user network connections (to shared drives...) are restored at user logon: `HandleLogon() -> RestoreAllConnections()`. These connections should be closed only at user logoff, in `HandleLogoff()`, instead of inside the common logoff/shutdown thread, which is also invoked at... shutdown! - Isolate the network connections closing inside a `CloseAllConnections()` helper (which also performs the necessary user thread impersonation). - Invoke this helper directly inside `HandleLogoff()`, and also re-enable the `IDS_CLOSINGNETWORKCONNECTIONS` message display.
1 parent 4f61d2e commit 51ee32f

File tree

1 file changed

+20
-10
lines changed
  • base/system/winlogon

1 file changed

+20
-10
lines changed

base/system/winlogon/sas.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ PlayEventSound(
429429

430430
static
431431
VOID
432-
RestoreAllConnections(PWLSESSION Session)
432+
RestoreAllConnections(
433+
_In_ PWLSESSION Session)
433434
{
434435
DWORD dRet;
435436
HANDLE hEnum;
@@ -441,9 +442,7 @@ RestoreAllConnections(PWLSESSION Session)
441442

442443
UserProfile = (Session && Session->UserToken);
443444
if (!UserProfile)
444-
{
445445
return;
446-
}
447446

448447
if (!ImpersonateLoggedOnUser(Session->UserToken))
449448
{
@@ -471,7 +470,7 @@ RestoreAllConnections(PWLSESSION Session)
471470
dSize = 0x1000;
472471
dCount = -1;
473472

474-
memset(lpRes, 0, dSize);
473+
ZeroMemory(lpRes, dSize);
475474
dRet = WNetEnumResource(hEnum, &dCount, lpRes, &dSize);
476475
if (dRet == WN_SUCCESS || dRet == WN_MORE_DATA)
477476
{
@@ -491,6 +490,17 @@ RestoreAllConnections(PWLSESSION Session)
491490
RevertToSelf();
492491
}
493492

493+
static
494+
VOID
495+
CloseAllConnections(
496+
_In_ PWLSESSION Session)
497+
{
498+
if (!Session->UserToken || !ImpersonateLoggedOnUser(Session->UserToken))
499+
return;
500+
WNetClearConnections(NULL);
501+
RevertToSelf();
502+
}
503+
494504
/**
495505
* @brief
496506
* Frees the Profile information structure (WLX_PROFILE_V1_0
@@ -757,9 +767,6 @@ LogoffShutdownThread(
757767
ret = FALSE;
758768
}
759769

760-
/* Cancel all the user connections */
761-
WNetClearConnections(NULL);
762-
763770
if (UserToken)
764771
RevertToSelf();
765772

@@ -1036,15 +1043,18 @@ HandleLogoff(
10361043

10371044
PlayLogoffShutdownSound(Session, WLX_SHUTTINGDOWN(wlxAction));
10381045

1046+
/* Close all user network connections */
1047+
DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_CLOSINGNETWORKCONNECTIONS);
1048+
CloseAllConnections(Session);
1049+
// TODO: Do any other user-specific network-related cleaning:
1050+
// user-added NetAPI message aliases; user cached credentials (remote login)...
1051+
10391052
SetWindowStationUser(Session->InteractiveWindowStation,
10401053
&LuidNone, NULL, 0);
10411054

10421055
// DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_LOGGINGOFF);
10431056
CallNotificationDlls(Session, LogoffHandler);
10441057

1045-
// FIXME: Closing network connections!
1046-
// DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_CLOSINGNETWORKCONNECTIONS);
1047-
10481058
/* Kill remaining COM processes that may have been started by logoff scripts */
10491059
hThread = CreateThread(psa, 0, KillComProcesses, (PVOID)Session->UserToken, 0, NULL);
10501060
if (hThread)

0 commit comments

Comments
 (0)