1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
|
//+---------------------------------------------------------------------------
//
// Microsoft Windows
// Copyright (C) Microsoft Corporation, 1992 - 1993.
//
// File: wlxutil.c
//
// Contents: WLX helper functions
//
// Classes:
//
// Functions:
//
// History: 8-24-94 RichardW Created
//
//----------------------------------------------------------------------------
#include "precomp.h"
#pragma hdrstop
#if DBG
char * StateNames[] = {"Preload", "Initialize", "NoOne", "NoOne_Display",
"NoOne_SAS", "LoggedOnUser_StartShell", "LoggedOnUser",
"LoggedOn_SAS", "Locked", "Locked_Display", "Locked_SAS",
"WaitForLogoff", "WaitForShutdown", "Shutdown" };
#endif
WLX_DISPATCH_VERSION_1_1 WlxDispatchTable = {
WlxUseCtrlAltDel,
WlxSetContextPointer,
WlxSasNotify,
WlxSetTimeout,
WlxAssignShellProtection,
WlxMessageBox,
WlxDialogBox,
WlxDialogBoxParam,
WlxDialogBoxIndirect,
WlxDialogBoxIndirectParam,
WlxSwitchDesktopToUser,
WlxSwitchDesktopToWinlogon,
WlxChangePasswordNotify,
WlxGetSourceDesktop,
WlxSetReturnDesktop,
WlxCreateUserDesktop,
WlxChangePasswordNotifyEx };
typedef struct _WindowMapper {
DWORD fMapper;
HWND hWnd;
DLGPROC DlgProc;
struct _WindowMapper * pPrev;
LPARAM InitialParameter;
} WindowMapper, * PWindowMapper;
#define MAPPERFLAG_ACTIVE 1
#define MAPPERFLAG_DIALOG 2
#define MAPPERFLAG_SAS 4
#define MAPPERFLAG_WINLOGON 8
#define MAX_WINDOW_MAPPERS 32
WindowMapper Mappers[MAX_WINDOW_MAPPERS];
DWORD cActiveWindow;
DWORD PendingSasEvents[MAX_WINDOW_MAPPERS];
DWORD PendingSasHead;
DWORD PendingSasTail;
void
InitWindowMappers()
{
ZeroMemory(Mappers, sizeof(WindowMapper) * MAX_WINDOW_MAPPERS);
cActiveWindow = 0;
PendingSasHead = 0;
PendingSasTail = 0;
}
PWindowMapper
LocateTopMappedWindow(void)
{
int i;
for (i = 0; i < MAX_WINDOW_MAPPERS ; i++ )
{
if (Mappers[i].fMapper & MAPPERFLAG_SAS)
{
return(&Mappers[i]);
}
}
return(NULL);
}
PWindowMapper
AllocWindowMapper(void)
{
int i;
PWindowMapper pMap;
for (i = 0 ; i < MAX_WINDOW_MAPPERS ; i++ )
{
if ((Mappers[i].fMapper & MAPPERFLAG_ACTIVE) == 0)
{
cActiveWindow ++;
pMap = LocateTopMappedWindow();
if (pMap)
{
FLAG_OFF(pMap->fMapper, MAPPERFLAG_SAS);
}
Mappers[i].hWnd = NULL;
FLAG_ON(Mappers[i].fMapper, MAPPERFLAG_ACTIVE | MAPPERFLAG_SAS);
Mappers[i].pPrev = pMap;
return(&Mappers[i]);
}
}
return(NULL);
}
PWindowMapper
LocateWindowMapper(HWND hWnd)
{
int i;
for (i = 0; i < MAX_WINDOW_MAPPERS ; i++ )
{
if (Mappers[i].hWnd == hWnd)
{
return(&Mappers[i]);
}
}
return(NULL);
}
void
FreeWindowMapper(PWindowMapper pMap)
{
pMap->hWnd = NULL;
pMap->DlgProc = NULL;
if (pMap->fMapper & MAPPERFLAG_SAS)
{
if (pMap->pPrev)
{
FLAG_ON(pMap->pPrev->fMapper, MAPPERFLAG_SAS);
}
}
pMap->fMapper = 0;
pMap->pPrev = NULL;
cActiveWindow--;
}
HWND
LocateTopWindow(VOID)
{
PWindowMapper pMap;
pMap = LocateTopMappedWindow();
if (pMap)
{
return(pMap->hWnd);
}
return(NULL);
}
BOOL
SetMapperFlag(
HWND hWnd,
DWORD Flag
)
{
PWindowMapper pMap;
pMap = LocateWindowMapper(hWnd);
if (!pMap)
{
return(FALSE);
}
pMap->fMapper |= Flag;
return(TRUE);
}
BOOL
QueueSasEvent(
DWORD dwSasType)
{
if (((PendingSasTail + 1) % MAX_WINDOW_MAPPERS) == PendingSasHead)
{
return(FALSE);
}
PendingSasEvents[PendingSasTail] = dwSasType;
PendingSasTail ++;
PendingSasTail %= MAX_WINDOW_MAPPERS;
return(TRUE);
}
BOOL
FetchPendingSas(
PDWORD pSasType)
{
if (PendingSasHead == PendingSasTail)
{
return(FALSE);
}
*pSasType = PendingSasEvents[PendingSasHead++];
PendingSasHead %= MAX_WINDOW_MAPPERS;
return(TRUE);
}
BOOL
TestPendingSas(VOID)
{
return (PendingSasHead == PendingSasTail);
}
VOID
EnableSasMessages(HWND hWnd)
{
DWORD SasType;
SasMessages = TRUE;
while (FetchPendingSas(&SasType))
{
if (hWnd)
{
#if DBG
DebugLog((DEB_TRACE, "Posting queued Sas %d to window %x\n",
SasType, hWnd ));
#endif
PostMessage(hWnd, WLX_WM_SAS, (WPARAM) SasType, 0);
}
}
}
//+---------------------------------------------------------------------------
//
// Function: RootWndProc
//
// Synopsis: This is the base window proc for all testgina windows.
//
// Arguments: [hWnd] --
// [Message] --
// [wParam] --
// [lParam] --
//
// History: 7-18-94 RichardW Created
//
// Notes:
//
//----------------------------------------------------------------------------
BOOL
CALLBACK
RootDlgProc(
HWND hWnd,
UINT Message,
WPARAM wParam,
LPARAM lParam)
{
PWindowMapper pMap;
int res;
BOOLEAN bRet;
//
// If this is a WM_INITDIALOG message, then the parameter is the mapping,
// which needs to have a hwnd associated with it. Otherwise, do the normal
// preprocessing.
//
if (Message == WM_INITDIALOG)
{
pMap = (PWindowMapper) lParam;
pMap->hWnd = hWnd;
SetTopTimeout(hWnd);
lParam = pMap->InitialParameter;
//
// Now that everything is done, enable sas messages again. This
// protects us from people pounding on the c-a-d keys, when our response
// time is slow, e.g. due to stress. We also drain the queue of pending
// SAS events.
//
EnableSasMessages(hWnd);
}
else
{
pMap = LocateWindowMapper(hWnd);
if (!pMap)
{
return(FALSE);
}
}
if (Message == WLX_WM_SAS &&
((pMap->fMapper & MAPPERFLAG_WINLOGON) == 0))
{
if ((wParam == WLX_SAS_TYPE_TIMEOUT) ||
(wParam == WLX_SAS_TYPE_SCRNSVR_TIMEOUT) )
{
DebugLog((DEB_TRACE, "Sending timeout to top window.\n"));
}
}
bRet = pMap->DlgProc(hWnd, Message, wParam, lParam);
if (!bRet)
{
if (Message == WM_INITDIALOG)
{
return(bRet);
}
if (Message == WLX_WM_SAS)
{
if ((pMap->fMapper & MAPPERFLAG_WINLOGON) == 0)
{
//
// Re-enable the messages
EnableSasMessages(pMap->hWnd);
}
switch (wParam)
{
case WLX_SAS_TYPE_CTRL_ALT_DEL:
default:
res = WLX_DLG_SAS;
break;
case WLX_SAS_TYPE_TIMEOUT:
res = WLX_DLG_INPUT_TIMEOUT;
break;
case WLX_SAS_TYPE_SCRNSVR_TIMEOUT:
res = WLX_DLG_SCREEN_SAVER_TIMEOUT;
break;
case WLX_SAS_TYPE_USER_LOGOFF:
res = WLX_DLG_USER_LOGOFF;
break;
}
if (res)
{
EndDialog(hWnd, res);
bRet = TRUE;
}
}
}
else
{
if (Message == WLX_WM_SAS &&
((pMap->fMapper & MAPPERFLAG_WINLOGON) == 0))
{
//
// Re-enable the messages
//
EnableSasMessages(pMap->hWnd);
switch (wParam)
{
case WLX_SAS_TYPE_TIMEOUT:
res = WLX_DLG_INPUT_TIMEOUT;
break;
case WLX_SAS_TYPE_SCRNSVR_TIMEOUT:
res = WLX_DLG_SCREEN_SAVER_TIMEOUT;
break;
case WLX_SAS_TYPE_USER_LOGOFF:
res = WLX_DLG_USER_LOGOFF;
break;
default:
res = 0;
break;
}
if (res)
{
DebugLog((DEB_TRACE, "Gina ate the SAS (%d) message, but ending it anyway.\n", wParam));
EndDialog(hWnd, res);
}
}
}
return(bRet);
}
VOID
ChangeStateForSAS(PGLOBALS pGlobals)
{
#if DBG
WinstaState State = pGlobals->WinlogonState;
#endif
if ((pGlobals->SasType == WLX_SAS_TYPE_SCRNSVR_TIMEOUT) &&
(pGlobals->SasType == WLX_SAS_TYPE_TIMEOUT) )
{
DebugLog((DEB_TRACE, "SAS was a timeout, no state change\n"));
return;
}
switch (pGlobals->WinlogonState)
{
case Winsta_NoOne:
case Winsta_NoOne_Display:
pGlobals->WinlogonState = Winsta_NoOne_SAS;
break;
case Winsta_Locked:
case Winsta_Locked_Display:
pGlobals->WinlogonState = Winsta_Locked_SAS;
break;
case Winsta_LoggedOnUser:
case Winsta_LoggedOnUser_StartShell:
pGlobals->WinlogonState = Winsta_LoggedOn_SAS;
break;
case Winsta_WaitForLogoff:
case Winsta_WaitForShutdown:
case Winsta_InShutdownDlg:
break;
default:
DebugLog((DEB_ERROR, "Don't know how to get to next state from %d, %s\n",
pGlobals->WinlogonState, GetState(pGlobals->WinlogonState)));
}
#if DBG
DebugLog((DEB_TRACE, "ChangeStateForSAS: Went from %d (%s) to %d (%s)\n",
State, GetState(State), pGlobals->WinlogonState,
GetState(pGlobals->WinlogonState) ));
#endif
}
BOOL
SendSasToTopWindow(
PGLOBALS pGlobals,
DWORD SasType)
{
PWindowMapper pMap;
#if DBG
WCHAR WindowName[32];
#endif
if (cActiveWindow)
{
if ((pGlobals->WinlogonState == Winsta_InShutdownDlg) &&
(SasType == WLX_SAS_TYPE_SCRNSVR_TIMEOUT))
{
return(TRUE);
}
pMap = LocateTopMappedWindow();
if (!pMap)
{
return(FALSE);
}
if ( ( SasType > WLX_SAS_TYPE_MAX_MSFT_VALUE) ||
( SasType == WLX_SAS_TYPE_SCRNSVR_TIMEOUT) ||
( SasType == WLX_SAS_TYPE_TIMEOUT) )
{
//
// Either a timeout (which we have to forward), or a private
// which we have to forward. Kill any message boxes
//
if (KillMessageBox( SasType ))
{
DebugLog((DEB_TRACE, "Killed a pending message box\n"));
}
}
#if DBG
GetWindowText( pMap->hWnd, WindowName, 32 );
DebugLog((DEB_TRACE, "Sending SAS code %d to window %x (%ws) \n", SasType, pMap->hWnd, WindowName ));
#endif
PostMessage(pMap->hWnd, WLX_WM_SAS, (WPARAM) SasType, 0);
//
// This will cause them to be queued, and then handled later.
//
DisableSasMessages();
return(TRUE);
}
return(FALSE);
}
VOID
DestroyMprInfo(
PWLX_MPR_NOTIFY_INFO pMprInfo)
{
if (pMprInfo->pszUserName)
{
LocalFree(pMprInfo->pszUserName);
}
if (pMprInfo->pszDomain)
{
LocalFree(pMprInfo->pszDomain);
}
if (pMprInfo->pszPassword)
{
ZeroMemory(pMprInfo->pszPassword, wcslen(pMprInfo->pszPassword) * 2);
LocalFree(pMprInfo->pszPassword);
}
if (pMprInfo->pszOldPassword)
{
ZeroMemory(pMprInfo->pszOldPassword, wcslen(pMprInfo->pszOldPassword) * 2);
LocalFree(pMprInfo->pszOldPassword);
}
}
VOID
WINAPI
WlxUseCtrlAltDel(
HANDLE hWlx)
{
PGLOBALS pGlobals;
if (pGlobals = VerifyHandle(hWlx))
{
pGlobals->ForwardCAD = TRUE;
}
}
VOID
WINAPI
WlxSetContextPointer(
HANDLE hWlx,
PVOID pWlxContext
)
{
PGLOBALS pGlobals;
if (pGlobals = VerifyHandle(hWlx))
{
pGlobals->pGina->pGinaContext = pWlxContext;
}
}
VOID
WINAPI
WlxSasNotify(
HANDLE hWlx,
DWORD SasType
)
{
PGLOBALS pGlobals;
if (pGlobals = VerifyHandle(hWlx))
{
switch (SasType)
{
case WLX_SAS_TYPE_USER_LOGOFF:
case WLX_SAS_TYPE_TIMEOUT:
case WLX_SAS_TYPE_SCRNSVR_TIMEOUT:
DebugLog((DEB_ERROR, "Illegal SAS Type (%d) passed to WlxSasNotify\n", SasType ));
return;
default:
SASRouter(pGlobals, SasType);
}
}
}
BOOL
WINAPI
WlxSetTimeout(
HANDLE hWlx,
DWORD Timeout
)
{
PGLOBALS pGlobals;
if (pGlobals = VerifyHandle(hWlx))
{
if ((pGlobals->WinlogonState == Winsta_NoOne_Display) ||
(pGlobals->WinlogonState == Winsta_Locked_Display) )
{
if (Timeout)
{
SetLastErrorEx(ERROR_INVALID_PARAMETER, SLE_ERROR);
return(FALSE);
}
}
pGlobals->pGina->cTimeout = Timeout;
TimeoutUpdateTopTimeout( Timeout );
return(TRUE);
}
SetLastErrorEx(ERROR_INVALID_HANDLE, SLE_ERROR);
return(FALSE);
}
int
WINAPI
WlxAssignShellProtection(
HANDLE hWlx,
HANDLE hToken,
HANDLE hProcess,
HANDLE hThread
)
{
PGLOBALS pGlobals;
PTOKEN_DEFAULT_DACL pDefDacl;
DWORD cDefDacl = 0;
NTSTATUS Status;
PSECURITY_DESCRIPTOR psd;
unsigned char buf[SECURITY_DESCRIPTOR_MIN_LENGTH];
BOOL Success;
if (!(pGlobals = VerifyHandle(hWlx)))
{
DebugLog((DEB_ERROR, "Invalid hWlx handle\n"));
return(ERROR_INVALID_HANDLE);
}
Status = NtQueryInformationToken(hToken, TokenDefaultDacl, NULL, 0, &cDefDacl);
if (!NT_SUCCESS(Status) && ( Status != STATUS_BUFFER_TOO_SMALL ))
{
return(RtlNtStatusToDosError(Status));
}
pDefDacl = LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, cDefDacl);
if (!pDefDacl)
{
return(ERROR_OUTOFMEMORY);
}
Status = NtQueryInformationToken(hToken, TokenDefaultDacl,
pDefDacl, cDefDacl, &cDefDacl);
if (!NT_SUCCESS(Status))
{
LocalFree(pDefDacl);
return(RtlNtStatusToDosError(Status));
}
psd = (PSECURITY_DESCRIPTOR) buf;
InitializeSecurityDescriptor(psd, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(psd, TRUE, pDefDacl->DefaultDacl, FALSE);
Success = SetKernelObjectSecurity(hProcess, DACL_SECURITY_INFORMATION, psd);
LocalFree(pDefDacl);
if (Success)
{
if (SetProcessToken(pGlobals, hProcess, hThread, hToken))
return(0);
}
return(GetLastError());
}
int WINAPI
WlxMessageBox(
HANDLE hWlx,
HWND hWnd,
LPWSTR lpsz1,
LPWSTR lpsz2,
UINT fmb)
{
PGLOBALS pGlobals;
if (!(pGlobals = VerifyHandle(hWlx)))
{
DebugLog((DEB_ERROR, "Invalid hWlx handle\n"));
SetLastErrorEx(ERROR_INVALID_HANDLE, SLE_ERROR);
return(-1);
}
return(TimeoutMessageBoxlpstr(pGlobals, hWnd, lpsz1, lpsz2, fmb,
pGlobals->pGina->cTimeout | TIMEOUT_SS_NOTIFY ) );
}
int WINAPI
WlxDialogBox(
HANDLE hWlx,
HANDLE hInstance,
LPWSTR lpsz1,
HWND hWnd,
DLGPROC dlgproc)
{
return(WlxDialogBoxParam(hWlx, hInstance, lpsz1, hWnd, dlgproc, 0));
}
int WINAPI
WlxDialogBoxIndirect(
HANDLE hWlx,
HANDLE hInstance,
LPCDLGTEMPLATE lpTemplate,
HWND hWnd,
DLGPROC dlgproc)
{
return(WlxDialogBoxIndirectParam(hWlx, hInstance, lpTemplate, hWnd, dlgproc, 0));
}
int WINAPI
WlxDialogBoxParam(
HANDLE hWlx,
HANDLE hInstance,
LPWSTR lpsz1,
HWND hWnd,
DLGPROC dlgproc,
LPARAM lParam)
{
PWindowMapper pMap;
PGLOBALS pGlobals;
int res;
pMap = AllocWindowMapper();
if (!pMap)
{
ASSERTMSG("Too many nested windows? send mail to richardw", pMap);
DebugLog((DEB_ERROR, "Too many nested windows?!?\n"));
SetLastError(ERROR_OUTOFMEMORY);
return(-1);
}
pMap->InitialParameter = lParam;
pMap->DlgProc = dlgproc;
pMap->fMapper |= MAPPERFLAG_DIALOG;
if (!(pGlobals = VerifyHandle(hWlx)))
{
DebugLog((DEB_ERROR, "Invalid hWlx handle\n"));
SetLastErrorEx(ERROR_INVALID_HANDLE, SLE_ERROR);
return(-1);
}
//res = DialogBoxParam(hInstance, lpsz1, hWnd, RootDlgProc, (LPARAM) pMap);
res = TimeoutDialogBoxParam(pGlobals, hInstance, lpsz1, hWnd,
RootDlgProc, (LPARAM) pMap,
pGlobals->pGina->cTimeout | TIMEOUT_SS_NOTIFY);
FreeWindowMapper(pMap);
return(res);
}
int WINAPI
WlxDialogBoxIndirectParam(
HANDLE hWlx,
HANDLE hInstance,
LPCDLGTEMPLATE lpTemplate,
HWND hWnd,
DLGPROC dlgproc,
LPARAM lParam)
{
PWindowMapper pMap;
int res;
pMap = AllocWindowMapper();
if (!pMap)
{
ASSERTMSG("Too many nested windows? send mail to richardw", pMap);
DebugLog((DEB_ERROR, "Too many nested windows?!?\n"));
SetLastError(ERROR_OUTOFMEMORY);
return(-1);
}
pMap->InitialParameter = lParam;
pMap->DlgProc = dlgproc;
pMap->fMapper |= MAPPERFLAG_DIALOG;
res = DialogBoxIndirectParam(hInstance, lpTemplate, hWnd, RootDlgProc, (LPARAM) pMap);
FreeWindowMapper(pMap);
return(res);
}
int WINAPI
WlxSwitchDesktopToUser(
HANDLE hWlx)
{
PGLOBALS pGlobals;
if (!(pGlobals = VerifyHandle(hWlx)))
{
DebugLog((DEB_ERROR, "Invalid hWlx handle\n"));
return(ERROR_INVALID_HANDLE);
}
SetActiveDesktop(&pGlobals->WindowStation, Desktop_Application);
SetThreadDesktop(pGlobals->WindowStation.hdeskApplication);
return(0);
}
int WINAPI
WlxSwitchDesktopToWinlogon(
HANDLE hWlx)
{
PGLOBALS pGlobals;
if (!(pGlobals = VerifyHandle(hWlx)))
{
DebugLog((DEB_ERROR, "Invalid hWlx handle\n"));
return(ERROR_INVALID_HANDLE);
}
SetActiveDesktop(&pGlobals->WindowStation, Desktop_Winlogon);
SetThreadDesktop(pGlobals->WindowStation.hdeskWinlogon);
return(0);
}
int WINAPI
WlxChangePasswordNotify(
HANDLE hWlx,
PWLX_MPR_NOTIFY_INFO pMprInfo,
DWORD dwChangeInfo)
{
PGLOBALS pGlobals;
int Result;
return WlxChangePasswordNotifyEx( hWlx, pMprInfo, dwChangeInfo, NULL, NULL );
}
int WINAPI
WlxChangePasswordNotifyEx(
HANDLE hWlx,
PWLX_MPR_NOTIFY_INFO pMprInfo,
DWORD dwChangeInfo,
PWSTR pszProvider,
PVOID pvReserved)
{
PGLOBALS pGlobals;
int Result;
if (!(pGlobals = VerifyHandle(hWlx)))
{
DebugLog((DEB_ERROR, "Invalid hWlx handle\n"));
return(ERROR_INVALID_HANDLE);
}
Result = MprChangePasswordNotify(
pGlobals,
LocateTopWindow(),
pszProvider,
pMprInfo->pszUserName,
pMprInfo->pszDomain,
pMprInfo->pszPassword,
pMprInfo->pszOldPassword,
dwChangeInfo,
FALSE);
DestroyMprInfo(pMprInfo);
if (Result == DLG_SUCCESS)
{
return(0);
}
else
return(ERROR_INVALID_PARAMETER);
}
BOOL
WINAPI
WlxGetSourceDesktop(
HANDLE hWlx,
PWLX_DESKTOP * ppDesktop)
{
PGLOBALS pGlobals;
DWORD len;
PWLX_DESKTOP pDesktop;
if (!(pGlobals = VerifyHandle(hWlx)))
{
DebugLog((DEB_ERROR, "Invalid hWlx handle\n"));
SetLastError(ERROR_INVALID_HANDLE);
return( FALSE );
}
if (pGlobals->WindowStation.pszDesktop)
{
len = (wcslen(pGlobals->WindowStation.pszDesktop) + 1) * sizeof(WCHAR);
}
else
{
len = 0;
}
pDesktop = LocalAlloc( LMEM_FIXED, sizeof(WLX_DESKTOP) + len );
if (!pDesktop)
{
return( FALSE );
}
pDesktop->Size = sizeof(WLX_DESKTOP);
pDesktop->Flags = WLX_DESKTOP_NAME;
pDesktop->hDesktop = NULL;
pDesktop->pszDesktopName = (PWSTR) (pDesktop + 1);
if (len)
{
wcscpy( pDesktop->pszDesktopName, pGlobals->WindowStation.pszDesktop );
}
*ppDesktop = pDesktop;
return( TRUE );
}
BOOL
WINAPI
WlxSetReturnDesktop(
HANDLE hWlx,
PWLX_DESKTOP pDesktop)
{
PGLOBALS pGlobals;
if (!(pGlobals = VerifyHandle(hWlx)))
{
DebugLog((DEB_ERROR, "Invalid hWlx handle\n"));
SetLastError(ERROR_INVALID_HANDLE);
return( FALSE );
}
if ((pDesktop->Size != sizeof(WLX_DESKTOP)) ||
((pDesktop->Flags & (WLX_DESKTOP_HANDLE | WLX_DESKTOP_NAME)) == 0) )
{
DebugLog((DEB_ERROR, "Invalid desktop\n"));
SetLastError( ERROR_INVALID_PARAMETER );
return( FALSE );
}
return( SetReturnDesktop( &pGlobals->WindowStation, pDesktop ) );
}
BOOL
WINAPI
WlxCreateUserDesktop(
HANDLE hWlx,
HANDLE hToken,
DWORD Flags,
PWSTR pszDesktopName,
PWLX_DESKTOP * ppDesktop)
{
PGLOBALS pGlobals;
PTOKEN_GROUPS pGroups;
PTOKEN_USER pUser;
DWORD Needed;
NTSTATUS Status;
DWORD i;
PSID pSid;
PWLX_DESKTOP pDesktop;
if (!(pGlobals = VerifyHandle(hWlx)))
{
DebugLog((DEB_ERROR, "Invalid hWlx handle\n"));
SetLastError(ERROR_INVALID_HANDLE);
return( FALSE );
}
if (((Flags & (WLX_CREATE_INSTANCE_ONLY | WLX_CREATE_USER)) == 0 ) ||
((Flags & (WLX_CREATE_INSTANCE_ONLY | WLX_CREATE_USER)) ==
(WLX_CREATE_INSTANCE_ONLY | WLX_CREATE_USER) ) )
{
DebugLog((DEB_ERROR, "Invalid flags\n"));
SetLastError( ERROR_INVALID_PARAMETER );
return( FALSE );
}
pGroups = NULL;
pUser = NULL;
pSid = NULL;
if ( Flags & WLX_CREATE_INSTANCE_ONLY )
{
Status = NtQueryInformationToken( hToken,
TokenGroups,
NULL,
0,
&Needed );
if ( Status != STATUS_BUFFER_TOO_SMALL )
{
SetLastError( RtlNtStatusToDosError( Status ) );
return( FALSE );
}
pGroups = (PTOKEN_GROUPS) LocalAlloc( LMEM_FIXED, Needed );
if ( !pGroups )
{
return( FALSE );
}
Status = NtQueryInformationToken( hToken,
TokenGroups,
pGroups,
Needed,
&Needed );
if ( !NT_SUCCESS( Status ) )
{
LocalFree( pGroups );
SetLastError( RtlNtStatusToDosError( Status ) );
return( FALSE );
}
for (i = 0 ; i < pGroups->GroupCount ; i++ )
{
if ( pGroups->Groups[i].Attributes & SE_GROUP_LOGON_ID )
{
pSid = pGroups->Groups[i].Sid;
break;
}
}
}
else
{
Status = NtQueryInformationToken( hToken,
TokenUser,
NULL,
0,
&Needed );
if ( Status != STATUS_BUFFER_TOO_SMALL )
{
SetLastError( RtlNtStatusToDosError( Status ) );
return( FALSE );
}
pUser = (PTOKEN_USER) LocalAlloc( LMEM_FIXED, Needed );
if ( !pUser )
{
return( FALSE );
}
Status = NtQueryInformationToken( hToken,
TokenUser,
pUser,
Needed,
&Needed );
if ( !NT_SUCCESS( Status ) )
{
LocalFree( pUser );
SetLastError( RtlNtStatusToDosError( Status ) );
return( FALSE );
}
pSid = pUser->User.Sid;
}
if ( !pSid )
{
SetLastError( ERROR_INVALID_PARAMETER );
goto CleanUp;
}
//
// Okay, we have the right SID now, so create the desktop.
//
Needed = sizeof( WLX_DESKTOP ) + (wcslen( pszDesktopName ) + 1 ) * sizeof(WCHAR);
pDesktop = (PWLX_DESKTOP) LocalAlloc( LMEM_FIXED, Needed );
if ( !pDesktop )
{
goto CleanUp;
}
pDesktop->Size = sizeof( WLX_DESKTOP );
pDesktop->Flags = WLX_DESKTOP_NAME;
pDesktop->hDesktop = NULL;
pDesktop->pszDesktopName = (PWSTR) (pDesktop + 1);
wcscpy( pDesktop->pszDesktopName, pszDesktopName );
pDesktop->hDesktop = CreateDesktop( pszDesktopName,
NULL, NULL, 0, MAXIMUM_ALLOWED, NULL);
if ( !pDesktop->hDesktop )
{
goto CleanUp;
}
if (!SetUserDesktopSecurity(pDesktop->hDesktop,
pSid, pWinlogonSid ) )
{
goto CleanUp;
}
if (!AddUserToWinsta( &pGlobals->WindowStation,
pSid,
hToken ) )
{
goto CleanUp;
}
*ppDesktop = pDesktop;
pDesktop->Flags |= WLX_DESKTOP_HANDLE;
if ( pGroups )
{
LocalFree( pGroups );
}
if ( pUser )
{
LocalFree( pUser );
}
return( TRUE );
CleanUp:
if ( pDesktop )
{
if ( pDesktop->hDesktop )
{
CloseDesktop( pDesktop->hDesktop );
}
LocalFree( pDesktop );
}
if ( pGroups )
{
LocalFree( pGroups );
}
if ( pUser )
{
LocalFree( pUser );
}
return( FALSE );
}
BOOL
WINAPI
WlxCloseUserDesktop(
HANDLE hWlx,
PWLX_DESKTOP pDesktop,
HANDLE hToken )
{
PGLOBALS pGlobals;
if (!(pGlobals = VerifyHandle(hWlx)))
{
DebugLog((DEB_ERROR, "Invalid hWlx handle\n"));
SetLastError(ERROR_INVALID_HANDLE);
return( FALSE );
}
if ( RemoveUserFromWinsta( &pGlobals->WindowStation, hToken ) )
{
return( CloseDesktop( pDesktop->hDesktop ) );
}
return( FALSE );
}
|