Skip to content

Commit 73db6c4

Browse files
committed
postsetup: Fix login dialog on 98Lite Micro image still appearing
1 parent 283a963 commit 73db6c4

File tree

3 files changed

+222
-21
lines changed

3 files changed

+222
-21
lines changed

sysprep/postsetup/build.bat

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@echo off
2+
del *.obj 2>nul
3+
del *.exe 2>nul
4+
wcl386 main.c -bt=nt -l=nt_win -4 -q -fe=qisetup
5+
del *.obj 2>nul

sysprep/postsetup/main.c

100644100755
Lines changed: 217 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,66 @@ HANDLE __logFile = NULL;
3737
#define LOGGING_FILE "C:\\QI_LOG.TXT"
3838
//#define LOGGING_FILE "QI_LOG.TXT"
3939

40+
unsigned char __BLANK_PWL[] = {
41+
0xe3, 0x82, 0x85, 0x96, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
42+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
43+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
45+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
46+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
47+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
48+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
49+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
50+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
51+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
52+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
53+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
54+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
55+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
56+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
57+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
60+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
62+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
63+
0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
64+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
65+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
66+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
67+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
68+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
69+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
70+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
71+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
72+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
73+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
74+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
75+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
76+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
77+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
78+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
79+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
80+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
81+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
82+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
83+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
84+
0xff, 0xff, 0xff, 0xff, 0x52, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
85+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
86+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
87+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
89+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
90+
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x93, 0x17, 0x10, 0xcb, 0xf4, 0x52,
91+
0x95, 0x6d, 0x45, 0x42, 0xa9, 0x1a, 0xeb, 0x90, 0x65, 0x0c, 0xca, 0xc5,
92+
0xca, 0xb0, 0x61, 0xa9, 0xf2, 0x23, 0x14, 0xba, 0x7f, 0x97, 0xa1, 0x55,
93+
0xb1, 0xab, 0x7f, 0x57, 0x63, 0x8d, 0xf2, 0x7b, 0x0c, 0xe0, 0x6d, 0xed,
94+
0x4c, 0x2a, 0x64, 0x53, 0x2f, 0x6c, 0x18, 0x4f, 0x01, 0xa4, 0x0d, 0xfc,
95+
0x62, 0x4f, 0x6d, 0xe5, 0xed, 0xe4, 0xec, 0xff, 0x7f, 0xd4, 0xe0, 0xe3,
96+
0x5d, 0xee, 0x05, 0xc8, 0x69, 0xd4, 0xfe, 0xd5, 0x6e, 0x64, 0x54, 0x35,
97+
0x6c, 0x3c, 0x5f, 0x21, 0xff, 0xd6, 0x1a, 0x42, 0xba, 0x6c, 0xb8, 0x30,
98+
0xc3, 0x9c, 0x99, 0x56
99+
};
40100

41101
const char *winError(DWORD err)
42102
{
@@ -97,12 +157,12 @@ void log(const char *fmt, ...) {
97157

98158
typedef bool (*KeyEnumerateFunc)(HKEY base, const char *key);
99159

100-
static bool regDoForEachSubkey(HKEY base, const char *key, bool returnAfterTrue,KeyEnumerateFunc func) {
160+
static bool regDoForEachSubkey(HKEY base, const char *key, bool returnAfterTrue, KeyEnumerateFunc func) {
101161
DWORD ret;
102162
DWORD index = 0;
103163
HKEY hKey;
104164

105-
logEnter();
165+
logEnter2("%s - returnAfterTrue: %s", key, returnAfterTrue ? "yes" : "no");
106166

107167
ret = RegOpenKeyExA(base, key, 0, KEY_ENUMERATE_SUB_KEYS, &hKey);
108168
closeKeyLogAndReturnIf(ret != ERROR_SUCCESS, false, hKey, "Can't open key (%s)", winError(ret));
@@ -139,6 +199,14 @@ static const char *regSubKey(const char *key, const char *subKey) {
139199
return skBuf;
140200
}
141201

202+
static bool regKeyExists(HKEY base, const char *key) {
203+
HKEY hKey;
204+
DWORD ret = RegOpenKeyExA(base, key, 0, KEY_READ, &hKey);
205+
logEnter1("%s", key);
206+
closeKeyLogAndReturnIf(ret != ERROR_SUCCESS, false, hKey, "-> no", 0);
207+
logReturn(true, "-> yes", 0);
208+
}
209+
142210
static bool createRegKey(HKEY base, const char *key) {
143211
HKEY hKey;
144212
DWORD ret;
@@ -229,7 +297,7 @@ static bool delRegValue(HKEY base, const char *key, const char *valueName) {
229297
logReturn(true, "OK", 0);
230298
}
231299

232-
void setComputerName() {
300+
static void setComputerName() {
233301
const char nameKey1[] = "System\\CurrentControlSet\\Control\\ComputerName\\ComputerName";
234302
const char nameKey2[] = "System\\CurrentControlSet\\Services\\VxD\\VNETSUP";
235303
const char nameValueName[] = "ComputerName";
@@ -276,7 +344,7 @@ static bool fileExists(const char *root, const char *filename) {
276344
logReturn(ret, "%s", ret ? "exists" : "missing");
277345
}
278346

279-
bool is98Lite() {
347+
static bool is98Lite() {
280348
char sysDir[MAX_PATH];
281349
bool ret;
282350
logEnter();
@@ -286,7 +354,7 @@ bool is98Lite() {
286354
logReturn(ret, "System type: %s", ret ? "98Lite" : "stock");
287355
}
288356

289-
void cleanupRegistry() {
357+
static void cleanupRegistry() {
290358
const char runKey[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";
291359
const char runServicesKey[] = "Software\\Microsoft\\Windows\\CurrentVersion\\RunServices";
292360
const char pnpEnum050C[] = "Enum\\Root\\*PNP0C05\\0000";
@@ -305,7 +373,7 @@ void cleanupRegistry() {
305373
logExit("%s", boolStr(ret));
306374
}
307375

308-
bool ifVredirUnsetDefault(HKEY base, const char *subkey) {
376+
static bool ifVredirUnsetDefault(HKEY base, const char *subkey) {
309377
char tmp[128];
310378
bool ret = true;
311379

@@ -323,7 +391,7 @@ bool ifVredirUnsetDefault(HKEY base, const char *subkey) {
323391
logReturn(true, "Handled VREDIR!", 0);
324392
}
325393

326-
bool setNetworkConfigFlags(HKEY base, const char *subkey, DWORD flags) {
394+
static bool setNetworkConfigFlags(HKEY base, const char *subkey, DWORD flags) {
327395
BYTE tmp[4] = { 0, 0, 0, 0 };
328396
memcpy(tmp, &flags, sizeof(tmp));
329397

@@ -336,23 +404,133 @@ bool setNetworkConfigFlags(HKEY base, const char *subkey, DWORD flags) {
336404
logReturn(true, "Set config flags", 0);
337405
}
338406

339-
bool networkConfigFlagsDisable(HKEY base, const char *subkey) {
407+
static bool networkConfigFlagsDisable(HKEY base, const char *subkey) {
340408
return setNetworkConfigFlags(base, subkey, 0x00000000);
341409
}
342410

343-
bool networkConfigFlagsEnable(HKEY base, const char *subkey) {
411+
static bool networkConfigFlagsEnable(HKEY base, const char *subkey) {
344412
return setNetworkConfigFlags(base, subkey, 0x00000010);
345413
}
346414

415+
static bool stringStartsWith(const char *s1, const char *s2) {
416+
return strncasecmp(s2, s1, strlen(s2)) == 0;
417+
}
418+
419+
static bool assignPwlFileInSystemIni(const char *uppercaseName, const char *pwlFileName) {
420+
char sini[512];
421+
char sbak[512];
422+
char line[1024];
423+
FILE *in = NULL;
424+
FILE *out = NULL;
425+
DWORD ret;
426+
bool success = true;
427+
bool inPasswordListsSection;
428+
429+
logEnter2("User '%s' PWL File '%s'", uppercaseName, pwlFileName);
430+
431+
sprintf(sini, "%s\\%s", getenv("WINDIR"), "SYSTEM.INI");
432+
sprintf(sbak, "%s\\%s", getenv("WINDIR"), "SYSTEM.BAK");
433+
434+
logAndReturnIf(MoveFileA(sini, sbak) != true, false, "Failed to backup SYSTEM.INI", 0);
435+
436+
in = fopen(sbak, "r");
437+
out = fopen(sini, "w");
438+
439+
if (in == NULL || out == NULL) {
440+
fclose(in);
441+
fclose(out);
442+
logReturn(false, "File open error", 0);
443+
}
444+
445+
// Write everything in system.ini BEFORE password lists section
446+
while (fgets(line, sizeof(line), in) != NULL) {
447+
success &= 0 < fwrite(line, 1, strlen(line), out);
448+
if (stringStartsWith(line, "[Password Lists]")) {
449+
inPasswordListsSection = true;
450+
break;
451+
}
452+
}
453+
454+
if (inPasswordListsSection) {
455+
// Write all lines in the password lists section
456+
while (fgets(line, sizeof(line), in) != NULL) {
457+
if (stringStartsWith(line, uppercaseName)) {
458+
// This name is already handled, override the PWL file
459+
success &= 0 < fprintf(out, "%s=%s\n", uppercaseName, pwlFileName);
460+
} else {
461+
// Some other bloke, we don't care
462+
success &= 0 < fwrite(line, 1, strlen(line), out);
463+
}
464+
}
465+
} else {
466+
// We're not in the pasword lists section so we have to create/fill it by hand
467+
success &= 0 < fprintf(out, "\n[Password Lists]\n");
468+
success &= 0 < fprintf(out, "%s=%s\n", uppercaseName, pwlFileName);
469+
}
470+
471+
// Write the rest of the SYSTEM.INI lines
472+
while (fgets(line, sizeof(line), in) != NULL) {
473+
success &= 0 < fwrite(line, 1, strlen(line), out);
474+
}
475+
476+
fprintf(out, "\n");
477+
fclose(in);
478+
fclose(out);
479+
480+
logReturn(false, "%s", success ? "OK" : "Error");
481+
}
482+
483+
static bool setDefaultUser(const char *user) {
484+
char pwlName[32];
485+
char userUpper[32];
486+
char buf[512];
487+
size_t written;
488+
FILE *f = NULL;
489+
logEnter1("User '%s'", user);
490+
491+
logAndReturnIf(strlen(user) > 28, false, "Name is too long", 0);
492+
493+
// Create blank PWL file
494+
if (strlen(user) > 8) {
495+
memcpy(pwlName, user, 8);
496+
sprintf(&pwlName[8], ".PWL");
497+
} else {
498+
strcpy(pwlName, user);
499+
strcat(pwlName, ".PWL");
500+
}
501+
502+
sprintf(buf, "%s\\%s", getenv("WINDIR"), pwlName);
503+
log("Creating blank pwl file '%s'", buf);
504+
505+
f = fopen(buf, "wb");
506+
written = fwrite(__BLANK_PWL, 1, sizeof(__BLANK_PWL), f);
507+
fclose(f);
508+
509+
logAndReturnIf(written == 0, false, "Error writing PWL file", 0);
510+
511+
// create uppercase version.
512+
strcpy(userUpper, user);
513+
CharUpperBuffA(userUpper, strlen(userUpper));
514+
515+
// Try finding
516+
assignPwlFileInSystemIni(userUpper, buf);
517+
518+
logReturn(true, "wrote %lu bytes", (unsigned long) written);
519+
}
520+
347521
// Set Logon provider to Windows Logon so that the login happens automagically
348522
void setWindowsLogon() {
349523
bool ret = true;
350-
const char realModeNet[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Network\\Real Mode Net";
351-
const char netClient[] = "System\\CurrentControlSet\\Services\\Class\\NetClient";
352-
const char enumNetworkFamily[] = "Enum\\Network\\FAMILY";
353-
const char enumNetworkVredir[] = "Enum\\Network\\VREDIR";
354-
const char networkLogon[] = "Network\\Logon";
355-
const char securityProvider[] = "Security\\Provider";
524+
static const char realModeNet[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Network\\Real Mode Net";
525+
static const char netClient[] = "System\\CurrentControlSet\\Services\\Class\\NetClient";
526+
static const char enumNetworkFamily[] = "Enum\\Network\\FAMILY";
527+
static const char enumNetworkVredir[] = "Enum\\Network\\VREDIR";
528+
static const char networkLogon[] = "Network\\Logon";
529+
static const char securityProvider[] = "Security\\Provider";
530+
static const char control[] = "System\\CurrentcontrolSet\\Control";
531+
static const char winLogon[] = "Software\\Microsoft\\Windows\\CurrentVersion\\Winlogon";
532+
533+
char currentUser[32] = "";
356534

357535
BYTE zero[4] = { 0, 0, 0, 0 };
358536

@@ -364,18 +542,37 @@ void setWindowsLogon() {
364542
// In netClient section we need to find the one that is VREDIR.VXD and then set it to DEFAULT.
365543
ret &= regDoForEachSubkey(HKEY_LOCAL_MACHINE, netClient, true, ifVredirUnsetDefault);
366544

367-
// Set ConfigFlags to Enable for Microsoft Family Logon
368-
ret &= regDoForEachSubkey(HKEY_LOCAL_MACHINE, enumNetworkFamily, false, networkConfigFlagsEnable);
545+
if (regKeyExists(HKEY_LOCAL_MACHINE, enumNetworkFamily)) {
546+
// Set ConfigFlags to Enable for Microsoft Family Logon
547+
ret &= regDoForEachSubkey(HKEY_LOCAL_MACHINE, enumNetworkFamily, false, networkConfigFlagsEnable);
369548

370-
// Set ConfigFlags to Disable for Client for Microsoft Networks
371-
ret &= regDoForEachSubkey(HKEY_LOCAL_MACHINE, enumNetworkVredir, false, networkConfigFlagsDisable);
549+
// Set ConfigFlags to Disable for Client for Microsoft Networks
550+
ret &= regDoForEachSubkey(HKEY_LOCAL_MACHINE, enumNetworkVredir, false, networkConfigFlagsDisable);
551+
} else {
552+
// Set ConfigFlags to Enable for Client for Microsoft Networks
553+
ret &= regDoForEachSubkey(HKEY_LOCAL_MACHINE, enumNetworkVredir, false, networkConfigFlagsEnable);
554+
}
372555

373556
// Set primary login provider
374-
ret &= setRegString(HKEY_LOCAL_MACHINE, networkLogon, "PrimaryProvider", "");
557+
ret &= setRegString(HKEY_LOCAL_MACHINE, networkLogon, "PrimaryProvider", "Windows Logon");
375558

376559
// Delete security provider platform type (dunno why)
560+
ret &= createRegKey(HKEY_LOCAL_MACHINE, securityProvider);
377561
ret &= setRegBinary(HKEY_LOCAL_MACHINE, securityProvider, "Platform_Type", zero, sizeof(zero));
378562

563+
// Set auto admin logon. First get current user
564+
if (!getRegString(HKEY_LOCAL_MACHINE, control, "Current User", currentUser, sizeof(currentUser))) {
565+
ret &= getRegString(HKEY_LOCAL_MACHINE, networkLogon, "username", currentUser, sizeof(currentUser));
566+
ret &= setRegString(HKEY_LOCAL_MACHINE, control, "Current User", currentUser);
567+
}
568+
569+
ret &= createRegKey(HKEY_LOCAL_MACHINE, winLogon);
570+
ret &= setRegString(HKEY_LOCAL_MACHINE, winLogon, "AutoAdminLogon", "1");
571+
ret &= setRegString(HKEY_LOCAL_MACHINE, winLogon, "DefaultUserName", currentUser);
572+
ret &= setRegString(HKEY_LOCAL_MACHINE, winLogon, "DefaultPassword", "");
573+
574+
ret &= setDefaultUser(currentUser);
575+
379576
logExit("%s", boolStr(ret));
380577
}
381578

@@ -386,7 +583,6 @@ void doReboot() {
386583
logExit("ExitWindowsEx: %u", (unsigned) ret);
387584
}
388585

389-
390586
int PASCAL WinMain( HINSTANCE currinst, HINSTANCE previnst, LPSTR cmdline, int cmdshow ) {
391587
#ifdef LOGGING
392588
__logFile = CreateFileA(LOGGING_FILE, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

sysprep/postsetup/qisetup.exe

11 KB
Binary file not shown.

0 commit comments

Comments
 (0)