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
|
/*++
Copyright (c) 1992 Microsoft Corporation
Module Name:
setuplgn.c
Abstract:
Routines for the special version of winlogon for Setup.
Author:
Ted Miller (tedm) 4-May-1992
Revision History:
--*/
#include "precomp.h"
#pragma hdrstop
#if DEVL
BOOL bDebugSetup;
#endif
//
// Handle to the event used by lsa to stall security initialization.
//
HANDLE LsaStallEvent = NULL;
//
// Thread Id of the main thread of setuplgn.
//
DWORD MainThreadId;
DWORD
WaiterThread(
PVOID hProcess
);
VOID
CreateLsaStallEvent(
VOID
)
/*++
Routine Description:
Create the event used by lsa to stall security initialization.
Arguments:
None.
Return Value:
None.
--*/
{
OBJECT_ATTRIBUTES EventAttributes;
NTSTATUS Status;
UNICODE_STRING EventName;
HANDLE EventHandle;
RtlInitUnicodeString(&EventName,TEXT("\\INSTALLATION_SECURITY_HOLD"));
InitializeObjectAttributes(&EventAttributes,&EventName,0,0,NULL);
Status = NtCreateEvent( &EventHandle,
0,
&EventAttributes,
NotificationEvent,
FALSE
);
if(NT_SUCCESS(Status)) {
LsaStallEvent = EventHandle;
} else {
DebugLog((DEB_ERROR, "Couldn't create lsa stall event (status = %lx)",Status));
}
}
DWORD
CheckSetupType (
VOID
)
/*++
Routine Description:
See if the value "SetupType" exists under the Winlogon key in WIN.INI;
return its value. Return SETUPTYPE_NONE if not found.
Arguments:
None.
Return Value:
SETUPTYPE_xxxx (see SETUPLGN.H).
--*/
{
DWORD SetupType = SETUPTYPE_NONE ;
HANDLE KeyHandle = OpenNtRegKey(KEYNAME_SETUP) ;
if (KeyHandle) {
if ( ! ReadRegistry( KeyHandle,
VARNAME_SETUPTYPE,
REG_DWORD,
(TCHAR*) & SetupType,
& SetupType ) )
SetupType = SETUPTYPE_NONE ;
NtClose(KeyHandle);
}
return SetupType ;
}
BOOL
SetSetupType (
DWORD type
)
/*++
Routine Description:
Set the "SetupType" value in the Registry.
Arguments:
DWORD type (see SETUPLGN.H)
Return Value:
TRUE if operation successful.
--*/
{
char buffer[20];
BOOL Result = FALSE ;
HANDLE KeyHandle = OpenNtRegKey(KEYNAME_SETUP) ;
if (KeyHandle) {
sprintf(buffer,"%ld", type);
Result = WriteRegistry( KeyHandle,
VARNAME_SETUPTYPE_A,
REG_DWORD, buffer,
sizeof type );
NtClose(KeyHandle);
}
return Result ;
}
BOOL
AppendToSetupCommandLine(
LPSTR pszCommandArguments
)
/*++
Routine Description:
Append to the setup command line in the Registry.
Arguments:
LPSTR pszCommandArguments (e.g. " /t STF_COMPUTERNAME = MACHINENAME")
Return Value:
TRUE if operation successful.
--*/
{
TCHAR CmdLineBuffer[512];
DWORD DataSize;
BOOL Result = FALSE ;
HANDLE KeyHandle = OpenNtRegKey(KEYNAME_SETUP) ;
if (KeyHandle) {
DataSize = sizeof(CmdLineBuffer);
Result = ReadRegistry( KeyHandle,
VARNAME_SETUPCMD,
REG_SZ,
CmdLineBuffer,
&DataSize
);
if (Result) {
UNICODE_STRING UniString;
STRING String;
char szBuf[1024];
String.Buffer = szBuf;
String.MaximumLength = sizeof(szBuf);
RtlInitUnicodeString(&UniString, CmdLineBuffer);
RtlUnicodeStringToAnsiString(&String, &UniString, FALSE);
RtlAppendAsciizToString(&String, pszCommandArguments);
String.Buffer[ String.Length ] = '\0';
Result = WriteRegistry( KeyHandle,
VARNAME_SETUPCMD_A,
REG_SZ,
szBuf,
String.Length
);
}
NtClose(KeyHandle);
}
return Result ;
}
VOID
ExecuteSetup(
PGLOBALS pGlobals
)
/*++
Routine Description:
Execute setup.exe. The command line to be passed to setup is obtained
from HKEY_LOCAL_MACHINE\system\setup:cmdline. Wait for setup to complete
before returning.
Arguments:
pGlobals - global data structure
Return Value:
None.
--*/
{
TCHAR CmdLineBuffer[1024];
TCHAR DebugCmdLineBuffer[1024];
PWCHAR CmdLine;
USER_PROCESS_DATA UserProcessData;
PROCESS_INFORMATION ProcessInformation;
HANDLE hProcess;
HANDLE hThread;
ULONG ThreadId;
HKEY hKey;
ULONG Result;
ULONG DataSize;
ULONG ExitCode;
MSG Msg;
USEROBJECTFLAGS uof;
//
// See if this is normal SETUP or special Net IDW setup
// during 2nd phase of triple boot; if Net IDW, alter
// WIN.INI the same way the WINLOGON.CMD script would.
//
if ( pGlobals->SetupType == SETUPTYPE_NETIDW ) {
//
// Establish the proper shell for the first real user boot
//
// Until the new shell is fully integrated, read which shell is
// desired from the "DefaultShell" value, and copy it over.
GetProfileString( APPNAME_WINLOGON,
TEXT("DefaultShell"),
TEXT("progman.exe"),
CmdLineBuffer,
sizeof(CmdLineBuffer)/sizeof(WCHAR) );
WriteProfileString( APPNAME_WINLOGON,
TEXT("DefaultShell"),
NULL );
WriteProfileString( APPNAME_WINLOGON,
VARNAME_SHELL,
CmdLineBuffer );
}
//
// Get the Setup command line from the registry
//
if((Result = RegOpenKey( HKEY_LOCAL_MACHINE,
REGNAME_SETUP,
&hKey)) == NO_ERROR) {
DataSize = sizeof(CmdLineBuffer);
Result = RegQueryValueEx( hKey,
VARNAME_SETUPCMD,
NULL,
NULL,
(LPBYTE)CmdLineBuffer,
&DataSize
);
if(Result == NO_ERROR) {
// DebugLog((DEB_ERROR, "Setup cmd line is '%s'",CmdLineBuffer));
} else {
DebugLog((DEB_ERROR, "error %u querying CmdLine value from \\system\\setup",Result));
}
RegCloseKey(hKey);
} else {
DebugLog((DEB_ERROR, "error %u opening \\system\\setup key for CmdLine (2)",Result));
}
// Alter "SetupType" to indicate setup is no long in progress.
SetSetupType( SETUPTYPE_NONE ) ;
#ifdef INIT_REGISTRY
//
// Dont do this if we want to boot an extra time as Administrator
// so we can run winlogon.cmd command script.
if ( pGlobals->SetupType == SETUPTYPE_NETSRW ) {
WriteProfileString( APPNAME_WINLOGON, VARNAME_AUTOLOGON, TEXT("1") );
} else {
#endif
// Delete "AutoAdminLogon" from WIN.INI if present
// except in the retail upgrade case.
if(pGlobals->SetupType != SETUPTYPE_UPGRADE) {
WriteProfileString( APPNAME_WINLOGON, VARNAME_AUTOLOGON, NULL );
}
#ifdef INIT_REGISTRY
}
#endif
RtlZeroMemory(&UserProcessData,sizeof(UserProcessData));
//
// Make windowstation and desktop handles inheritable.
//
GetUserObjectInformation(pGlobals->WindowStation.hwinsta, UOI_FLAGS, &uof, sizeof(uof), NULL);
uof.fInherit = TRUE;
SetUserObjectInformation(pGlobals->WindowStation.hwinsta, UOI_FLAGS, &uof, sizeof(uof));
GetUserObjectInformation(pGlobals->WindowStation.hdeskApplication, UOI_FLAGS, &uof, sizeof(uof), NULL);
uof.fInherit = TRUE;
SetUserObjectInformation(pGlobals->WindowStation.hdeskApplication, UOI_FLAGS, &uof, sizeof(uof));
SetActiveDesktop(&pGlobals->WindowStation, Desktop_Application);
CmdLine = CmdLineBuffer;
#if DEVL
if ( bDebugSetup ) {
wsprintf( DebugCmdLineBuffer, TEXT("ntsd -d %s%s"),
bDebugSetup == 2 ? TEXT("-g -G ") : TEXT(""),
CmdLine
);
CmdLine = DebugCmdLineBuffer;
}
#endif
if(StartSystemProcess( CmdLine,
TEXT("winsta0\\Default"),
0,
0, // Normal startup feedback
NULL,
FALSE,
&hProcess,
NULL) )
{
if (hProcess)
{
//
// Create a second thread to wait on the setup process.
// When setup terminates, the second thread will send us
// a special message. When we receive the special message,
// exit the dispatch loop.
//
// Do this to allow us to respond to messages sent by the
// system, thus preventing the system from hanging.
//
MainThreadId = GetCurrentThreadId();
hThread = CreateThread( NULL,
0,
WaiterThread,
(LPVOID)hProcess,
0,
&ThreadId
);
if(hThread) {
while(GetMessage(&Msg,NULL,0,0)) {
DispatchMessage(&Msg);
}
CloseHandle(hThread);
GetExitCodeProcess(hProcess,&ExitCode);
// BUGBUG look at exit code; may have to restart machine.
} else {
DebugLog((DEB_ERROR, "couldn't start waiter thread"));
}
CloseHandle(hProcess);
} else {
DebugLog((DEB_ERROR, "couldn't get handle to setup process, error = %u",GetLastError()));
}
} else {
DebugLog((DEB_ERROR, "couldn't exec '%ws'",CmdLine));
}
SetActiveDesktop(&pGlobals->WindowStation, Desktop_Winlogon);
}
DWORD
WaiterThread(
PVOID hProcess
)
{
WaitForSingleObject(hProcess,(DWORD)(-1));
PostThreadMessage(MainThreadId,WM_QUIT,0,0);
ExitThread(0);
return(0); // prevent compiler warning
}
VOID
CheckForIncompleteSetup (
PGLOBALS pGlobals
)
/*++
Routine Description:
Checks to see if setup started but never completed.
Do this by checking to see if the SetupInProgress value has been
reset to 0. This value is set to 1 in the default hives that run setup.
Setup.exe resets it to 0 on successful completion.
Arguments:
None.
Return Value:
None
--*/
{
DWORD SetupInProgress = 0 ;
HANDLE KeyHandle = OpenNtRegKey(KEYNAME_SETUP) ;
if (KeyHandle) {
if ( ! ReadRegistry( KeyHandle,
VARNAME_SETUPINPROGRESS,
REG_DWORD,
(TCHAR*) & SetupInProgress,
& SetupInProgress ) ) {
SetupInProgress = 0;
}
NtClose(KeyHandle);
}
//
// If setup did not complete then make them reboot
//
if (SetupInProgress) {
TimeoutMessageBox(pGlobals,
NULL,
IDS_SETUP_INCOMPLETE,
IDS_WINDOWS_MESSAGE,
MB_ICONSTOP | MB_OK
);
#if DBG
//
// On debug builds let them continue if they hold down Ctrl
//
if ((GetKeyState(VK_LCONTROL) < 0) ||
(GetKeyState(VK_RCONTROL) < 0)) {
return;
}
#endif
//
// Reboot time
//
RebootMachine(pGlobals);
}
}
//
// This function checks if the "Repair" value is set. If so, then
// it loads syssetup.dll and calls RepairStartMenuItems
//
VOID
CheckForRepairRequest (void)
{
HKEY hkeyWinlogon;
LONG lResult;
DWORD dwSize, dwType;
BOOL bRunRepair = FALSE;
HINSTANCE hSysSetup;
REPAIRSTARTMENUITEMS RepairStartMenuItems;
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, WINLOGON_KEY,
0, KEY_READ | KEY_WRITE, &hkeyWinlogon) == ERROR_SUCCESS) {
dwSize = sizeof(bRunRepair);
if (RegQueryValueEx (hkeyWinlogon, L"Repair",
NULL, &dwType, (LPBYTE) &bRunRepair,
&dwSize) == ERROR_SUCCESS) {
RegDeleteValue (hkeyWinlogon, L"Repair");
}
RegCloseKey (hkeyWinlogon);
}
if (bRunRepair) {
hSysSetup = LoadLibrary (L"syssetup.dll");
if (hSysSetup) {
RepairStartMenuItems = (REPAIRSTARTMENUITEMS)GetProcAddress(hSysSetup,
"RepairStartMenuItems");
if (RepairStartMenuItems) {
RepairStartMenuItems();
}
FreeLibrary (hSysSetup);
}
}
}
|