[SYSSETUP]
authorEric Kohl <eric.kohl@reactos.org>
Sat, 18 Jan 2014 14:26:07 +0000 (14:26 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sat, 18 Jan 2014 14:26:07 +0000 (14:26 +0000)
Use the administrator name, domain and password for the logon hack and store them in the registry for later use by winlogon if the AutoAdminLogon option is enabled.
CORE-7722 #resolve

svn path=/trunk/; revision=61676

reactos/boot/bootdata/hivesft.inf
reactos/dll/win32/syssetup/globals.h
reactos/dll/win32/syssetup/install.c
reactos/dll/win32/syssetup/security.c

index 33e3bea..d862f46 100644 (file)
@@ -1075,8 +1075,8 @@ HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","ConsoleShell",0x00
 HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","Shell",0x00020000,"%SystemRoot%\explorer.exe"\r
 HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","Userinit",0x00020000,"%SystemRoot%\system32\userinit.exe"\r
 HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","AutoAdminLogon",0x00000000,"1"\r
-HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","DefaultUserName",0x00000000,"Administrator"\r
-;HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","DefaultPassword",0x00000000,"Secret"\r
+HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","DefaultDomain",0x00000000,""\r
+HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","DefaultUserName",0x00000000,""\r
 HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon","DefaultPassword",0x00000000,""\r
 \r
 ; Time Zone Servers\r
index 191303d..756a68b 100644 (file)
@@ -56,10 +56,17 @@ typedef struct _SETUPDATA
     LCID LocaleID;
 } SETUPDATA, *PSETUPDATA;
 
+typedef struct _ADMIN_INFO
+{
+    LPWSTR Name;
+    LPWSTR Domain;
+    LPWSTR Password;
+} ADMIN_INFO, *PADMIN_INFO;
 
 extern HINSTANCE hDllInstance;
 extern HINF hSysSetupInf;
 extern SETUPDATA SetupData;
+extern ADMIN_INFO AdminInfo;
 
 BOOL RegisterTypeLibraries (HINF hinf, LPCWSTR szSection);
 
@@ -70,6 +77,9 @@ VOID InstallSecurity(VOID);
 NTSTATUS
 SetAdministratorPassword(LPCWSTR Password);
 
+VOID
+SetAutoAdminLogon(VOID);
+
 /* wizard.c */
 VOID InstallWizard (VOID);
 
index 4eccb7f..ce5024a 100644 (file)
@@ -39,6 +39,7 @@ CMP_WaitNoPendingInstallEvents(DWORD dwTimeout);
 /* GLOBALS ******************************************************************/
 
 HINF hSysSetupInf = INVALID_HANDLE_VALUE;
+ADMIN_INFO AdminInfo;
 
 /* FUNCTIONS ****************************************************************/
 
@@ -905,6 +906,8 @@ InstallReactOS(HINSTANCE hInstance)
 
     InstallSecurity();
 
+    SetAutoAdminLogon();
+
     hShortcutsInf = SetupOpenInfFileW(L"shortcuts.inf",
                                       NULL,
                                       INF_STYLE_WIN4,
@@ -933,7 +936,12 @@ InstallReactOS(HINSTANCE hInstance)
             HANDLE hToken;
             BOOL ret;
 
-            ret = LogonUserW(L"Administrator", L"", L"", LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &hToken);
+            ret = LogonUserW(AdminInfo.Name,
+                             AdminInfo.Domain,
+                             AdminInfo.Password,
+                             LOGON32_LOGON_INTERACTIVE,
+                             LOGON32_PROVIDER_DEFAULT,
+                             &hToken);
             if (!ret)
             {
                 FatalError("LogonUserW() failed!");
@@ -959,6 +967,15 @@ InstallReactOS(HINSTANCE hInstance)
     LogItem(SYSSETUP_SEVERITY_INFORMATION, L"Installing ReactOS done");
     TerminateSetupActionLog();
 
+    if (AdminInfo.Name != NULL)
+        RtlFreeHeap(RtlGetProcessHeap(), 0, AdminInfo.Name);
+
+    if (AdminInfo.Domain != NULL)
+        RtlFreeHeap(RtlGetProcessHeap(), 0, AdminInfo.Domain);
+
+    if (AdminInfo.Password != NULL)
+        RtlFreeHeap(RtlGetProcessHeap(), 0, AdminInfo.Password);
+
     /* Get shutdown privilege */
     if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token))
     {
index 015b7c0..644f3c9 100644 (file)
@@ -317,6 +317,7 @@ NTSTATUS
 SetAdministratorPassword(LPCWSTR Password)
 {
     PPOLICY_ACCOUNT_DOMAIN_INFO OrigInfo = NULL;
+    PUSER_ACCOUNT_NAME_INFORMATION AccountNameInfo = NULL;
     USER_SET_PASSWORD_INFORMATION PasswordInfo;
     LSA_OBJECT_ATTRIBUTES ObjectAttributes;
     LSA_HANDLE PolicyHandle = NULL;
@@ -370,8 +371,8 @@ SetAdministratorPassword(LPCWSTR Password)
     }
 
     Status = SamOpenUser(DomainHandle,
-                         USER_FORCE_PASSWORD_CHANGE,
-                         DOMAIN_USER_RID_ADMIN, /* 500 */
+                         USER_FORCE_PASSWORD_CHANGE | USER_READ_GENERAL,
+                         DOMAIN_USER_RID_ADMIN,
                          &UserHandle);
     if (!NT_SUCCESS(Status))
     {
@@ -391,7 +392,45 @@ SetAdministratorPassword(LPCWSTR Password)
         goto done;
     }
 
+    Status = SamQueryInformationUser(UserHandle,
+                                     UserAccountNameInformation,
+                                     (PVOID*)&AccountNameInfo);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("SamSetInformationUser() failed (Status %08lx)\n", Status);
+        goto done;
+    }
+
+    AdminInfo.Name = RtlAllocateHeap(RtlGetProcessHeap(),
+                                     HEAP_ZERO_MEMORY,
+                                     AccountNameInfo->UserName.Length + sizeof(WCHAR));
+    if (AdminInfo.Name != NULL)
+        RtlCopyMemory(AdminInfo.Name,
+                      AccountNameInfo->UserName.Buffer,
+                      AccountNameInfo->UserName.Length);
+
+    AdminInfo.Domain = RtlAllocateHeap(RtlGetProcessHeap(),
+                                       HEAP_ZERO_MEMORY,
+                                       OrigInfo->DomainName.Length + sizeof(WCHAR));
+    if (AdminInfo.Domain != NULL)
+        RtlCopyMemory(AdminInfo.Domain,
+                      OrigInfo->DomainName.Buffer,
+                      OrigInfo->DomainName.Length);
+
+    AdminInfo.Password = RtlAllocateHeap(RtlGetProcessHeap(),
+                                         0,
+                                         (wcslen(Password) + 1) * sizeof(WCHAR));
+    if (AdminInfo.Password != NULL)
+        wcscpy(AdminInfo.Password, Password);
+
+    DPRINT1("Administrator Name: %S\n", AdminInfo.Name);
+    DPRINT1("Administrator Domain: %S\n", AdminInfo.Domain);
+    DPRINT1("Administrator Password: %S\n", AdminInfo.Password);
+
 done:
+    if (AccountNameInfo != NULL)
+        SamFreeMemory(AccountNameInfo);
+
     if (OrigInfo != NULL)
         LsaFreeMemory(OrigInfo);
 
@@ -412,5 +451,63 @@ done:
     return Status;
 }
 
+
+VOID
+SetAutoAdminLogon(VOID)
+{
+    WCHAR szAutoAdminLogon[2];
+    HKEY hKey = NULL;
+    DWORD dwType;
+    DWORD dwSize;
+    LONG lError;
+
+    lError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
+                           L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon",
+                           0,
+                           KEY_READ | KEY_WRITE,
+                           &hKey);
+    if (lError != ERROR_SUCCESS)
+        return;
+
+    dwSize = 2 * sizeof(WCHAR);
+    lError = RegQueryValueExW(hKey,
+                              L"AutoAdminLogon",
+                              NULL,
+                              &dwType,
+                              (LPBYTE)szAutoAdminLogon,
+                              &dwSize);
+    if (lError != ERROR_SUCCESS)
+        goto done;
+
+    if (wcscmp(szAutoAdminLogon, L"1") == 0)
+    {
+        RegSetValueExW(hKey,
+                       L"DefaultDomain",
+                       0,
+                       REG_SZ,
+                       (LPBYTE)AdminInfo.Domain,
+                       (wcslen(AdminInfo.Domain) + 1) * sizeof(WCHAR));
+
+        RegSetValueExW(hKey,
+                       L"DefaultUserName",
+                       0,
+                       REG_SZ,
+                       (LPBYTE)AdminInfo.Name,
+                       (wcslen(AdminInfo.Name) + 1) * sizeof(WCHAR));
+
+        RegSetValueExW(hKey,
+                       L"DefaultPassword",
+                       0,
+                       REG_SZ,
+                       (LPBYTE)AdminInfo.Password,
+                       (wcslen(AdminInfo.Password) + 1) * sizeof(WCHAR));
+    }
+
+done:
+    if (hKey != NULL)
+        RegCloseKey(hKey);
+}
+
+
 /* EOF */