Skip to content

Commit 78ce856

Browse files
committed
[WINLOGON] Duplicate the logged-in user/domain names and give them to the notifications (reactos#8322)
Test results: - Test 1a: `Asynchronous: FALSE, Impersonation: FALSE` BEFORE the fix: OK, the thread isn't impersonated: ``` Thread Token : 0x00000000 - User: '(null)\(null)' ``` BUT these two WLX notify info fields aren't set when the user is logged in: ``` Info.UserName : '(null)' Info.Domain : '(null)' ``` Results: ``` WLEventStartup: 30 tests executed (0 marked as todo, 1 failure), 0 skipped. WLEventLogon: 30 tests executed (0 marked as todo, 3 failures), 2 skipped. WLEventStartShell: 30 tests executed (0 marked as todo, 3 failures), 2 skipped. (NOTE: WLEventPostShell isn't yet implemented in ReactOS) WLEventLock: 30 tests executed (0 marked as todo, 4 failures), 2 skipped. WLEventUnlock: 30 tests executed (0 marked as todo, 3 failures), 2 skipped. WLEventStartScreenSaver: 30 tests executed (0 marked as todo, 9 failures), 2 skipped. WLEventStopScreenSaver: 30 tests executed (0 marked as todo, 7 failures), 2 skipped. WLEventLogoff: 30 tests executed (0 marked as todo, 4 failures), 2 skipped. WLEventShutdown: 31 tests executed (0 marked as todo, 3 failures), 0 skipped. ``` - Test 1b: `Asynchronous: FALSE, Impersonation: FALSE` AFTER the fix: OK, the thread isn't impersonated: ``` Thread Token : 0x00000000 - User: '(null)\(null)' ``` OK, these two WLX notify info fields are now set when the user is logged in: ``` Info.UserName : 'Administrator' Info.Domain : 'MYCOMPUTERNAME' ``` Results: ``` WLEventStartup: 30 tests executed (0 marked as todo, 1 failure), 0 skipped. WLEventLogon: 32 tests executed (0 marked as todo, 1 failure), 0 skipped. WLEventStartShell: 32 tests executed (0 marked as todo, 1 failure), 0 skipped. (NOTE: WLEventPostShell isn't yet implemented in ReactOS) WLEventLock: 32 tests executed (0 marked as todo, 2 failures), 0 skipped. WLEventUnlock: 32 tests executed (0 marked as todo, 1 failure), 0 skipped. WLEventStartScreenSaver: 32 tests executed (0 marked as todo, 7 failures), 0 skipped. WLEventStopScreenSaver: 32 tests executed (0 marked as todo, 5 failures), 0 skipped. WLEventLogoff: 32 tests executed (0 marked as todo, 2 failures), 0 skipped. WLEventShutdown: 31 tests executed (0 marked as todo, 3 failures), 0 skipped. ``` Less failed tests and none skipped anymore. - Test 2a: `Asynchronous: FALSE, Impersonation: TRUE` BEFORE the fix: OK, the thread impersonates the user when (s)he is logged in: ``` Thread Token : 0x00000360 - User: 'MYCOMPUTERNAME\Administrator' ``` BUT these two WLX notify info fields aren't set when the user is logged in: ``` Info.UserName : '(null)' Info.Domain : '(null)' ``` Results: ``` WLEventStartup: 30 tests executed (0 marked as todo, 1 failure), 0 skipped. WLEventLogon: 31 tests executed (0 marked as todo, 5 failures), 2 skipped. WLEventStartShell: 31 tests executed (0 marked as todo, 5 failures), 2 skipped. (NOTE: WLEventPostShell isn't yet implemented in ReactOS) WLEventLock: 31 tests executed (0 marked as todo, 6 failures), 2 skipped. WLEventUnlock: 31 tests executed (0 marked as todo, 5 failures), 2 skipped. WLEventStartScreenSaver: 32 tests executed (0 marked as todo, 6 failures), 2 skipped. WLEventStopScreenSaver: 32 tests executed (0 marked as todo, 4 failures), 2 skipped. WLEventLogoff: 32 tests executed (0 marked as todo, 4 failures), 2 skipped. WLEventShutdown: 31 tests executed (0 marked as todo, 3 failures), 0 skipped. ``` - Test 2b: `Asynchronous: FALSE, Impersonation: TRUE` AFTER the fix: OK, the thread impersonates the user when (s)he is logged in: ``` Thread Token : 0x00000360 - User: 'MYCOMPUTERNAME\Administrator' ``` OK, these two WLX notify info fields are now set when the user is logged in: ``` Info.UserName : 'Administrator' Info.Domain : 'MYCOMPUTERNAME' ``` Results: ``` WLEventStartup: 30 tests executed (0 marked as todo, 1 failure), 0 skipped. WLEventLogon: 33 tests executed (0 marked as todo, 3 failures), 0 skipped. WLEventStartShell: 33 tests executed (0 marked as todo, 3 failures), 0 skipped. (NOTE: WLEventPostShell isn't yet implemented in ReactOS) WLEventLock: 33 tests executed (0 marked as todo, 4 failures), 0 skipped. WLEventUnlock: 33 tests executed (0 marked as todo, 3 failures), 0 skipped. WLEventStartScreenSaver: 34 tests executed (0 marked as todo, 4 failures), 0 skipped. WLEventStopScreenSaver: 34 tests executed (0 marked as todo, 2 failures), 0 skipped. WLEventLogoff: 34 tests executed (0 marked as todo, 2 failures), 0 skipped. WLEventShutdown: 31 tests executed (0 marked as todo, 3 failures), 0 skipped. ``` As well, less failed tests and none skipped anymore.
1 parent b1322d4 commit 78ce856

File tree

4 files changed

+44
-11
lines changed

4 files changed

+44
-11
lines changed

base/system/winlogon/notify.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,13 @@ AddSfcNotification(VOID)
190190
if (!NotificationDll)
191191
return; // If needed: dwError = ERROR_OUTOFMEMORY;
192192

193-
NotificationDll->pszDllName = RtlAllocateHeap(RtlGetProcessHeap(), 0,
194-
(wcslen(szSfcPath) + 1) * sizeof(WCHAR));
193+
NotificationDll->pszDllName = WlStrDup(szSfcPath);
195194
if (NotificationDll->pszDllName == NULL)
196195
{
197196
dwError = ERROR_OUTOFMEMORY;
198197
goto done;
199198
}
200199

201-
wcscpy(NotificationDll->pszDllName, szSfcPath);
202-
203200
NotificationDll->bEnabled = TRUE;
204201
NotificationDll->dwMaxWait = 30; /* FIXME: ??? */
205202
NotificationDll->bSfcNotification = TRUE;
@@ -290,16 +287,13 @@ AddNotificationDll(
290287
goto done;
291288
}
292289

293-
NotificationDll->pszKeyName = RtlAllocateHeap(RtlGetProcessHeap(), 0,
294-
(wcslen(pszKeyName) + 1) * sizeof(WCHAR));
290+
NotificationDll->pszKeyName = WlStrDup(pszKeyName);
295291
if (NotificationDll->pszKeyName == NULL)
296292
{
297293
lError = ERROR_OUTOFMEMORY;
298294
goto done;
299295
}
300296

301-
wcscpy(NotificationDll->pszKeyName, pszKeyName);
302-
303297
dwSize = 0;
304298
lError = RegQueryValueExW(hDllKey,
305299
L"DllName",
@@ -560,8 +554,8 @@ CallNotificationDlls(
560554
break;
561555
}
562556

563-
Info.UserName = NULL; //UserName;
564-
Info.Domain = NULL; //Domain;
557+
Info.UserName = pSession->UserName;
558+
Info.Domain = pSession->Domain;
565559
Info.WindowStation = pSession->InteractiveWindowStationName;
566560
Info.hToken = pSession->UserToken;
567561

base/system/winlogon/sas.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,10 @@ HandleLogon(
621621
Session->hProfileInfo = ProfileInfo.hProfile;
622622
}
623623

624+
/* Cache the username and domain */
625+
Session->UserName = WlStrDup(Session->MprNotifyInfo.pszUserName);
626+
Session->Domain = WlStrDup(Session->MprNotifyInfo.pszDomain);
627+
624628
/* Create environment block for the user */
625629
if (!CreateUserEnvironment(Session))
626630
{
@@ -687,6 +691,10 @@ HandleLogon(
687691

688692
if (!ret)
689693
{
694+
RtlFreeHeap(RtlGetProcessHeap(), 0, Session->UserName);
695+
RtlFreeHeap(RtlGetProcessHeap(), 0, Session->Domain);
696+
Session->UserName = Session->Domain = NULL;
697+
690698
if (Session->hProfileInfo)
691699
UnloadUserProfile(Session->UserToken, Session->hProfileInfo);
692700
Session->hProfileInfo = NULL;
@@ -1050,6 +1058,10 @@ HandleLogoff(
10501058

10511059
DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_SAVEYOURSETTINGS);
10521060

1061+
RtlFreeHeap(RtlGetProcessHeap(), 0, Session->UserName);
1062+
RtlFreeHeap(RtlGetProcessHeap(), 0, Session->Domain);
1063+
Session->UserName = Session->Domain = NULL;
1064+
10531065
if (Session->hProfileInfo)
10541066
UnloadUserProfile(Session->UserToken, Session->hProfileInfo);
10551067
Session->hProfileInfo = NULL;

base/system/winlogon/winlogon.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,27 @@ PWLSESSION WLSession = NULL;
2121

2222
/* FUNCTIONS *****************************************************************/
2323

24+
/**
25+
* @brief
26+
* Duplicates the given string, allocating a buffer on the heap.
27+
**/
28+
PWSTR
29+
WlStrDup(
30+
_In_opt_ PCWSTR String)
31+
{
32+
PWSTR ptr;
33+
34+
if (!String)
35+
return NULL;
36+
37+
ptr = RtlAllocateHeap(RtlGetProcessHeap(), 0,
38+
(wcslen(String) + 1) * sizeof(WCHAR));
39+
if (ptr)
40+
wcscpy(ptr, String);
41+
return ptr;
42+
}
43+
44+
2445
static
2546
BOOL
2647
StartServicesManager(VOID)

base/system/winlogon/winlogon.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ typedef struct _WLSESSION
227227
BOOL UtilManHotkey;
228228
HWND SASWindow;
229229
HWINSTA InteractiveWindowStation;
230-
LPWSTR InteractiveWindowStationName;
230+
PWSTR InteractiveWindowStationName;
231+
PWSTR UserName;
232+
PWSTR Domain;
231233
HDESK ApplicationDesktop;
232234
HDESK WinlogonDesktop;
233235
HDESK ScreenSaverDesktop;
@@ -403,6 +405,10 @@ StartSystemShutdown(
403405
IN ULONG dwReason);
404406

405407
/* winlogon.c */
408+
PWSTR
409+
WlStrDup(
410+
_In_opt_ PCWSTR String);
411+
406412
BOOL
407413
PlaySoundRoutine(IN LPCWSTR FileName,
408414
IN UINT Logon,

0 commit comments

Comments
 (0)