[SYSSETUP]
authorEric Kohl <eric.kohl@reactos.org>
Sun, 13 May 2012 16:16:18 +0000 (16:16 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sun, 13 May 2012 16:16:18 +0000 (16:16 +0000)
Set the account domain name and account domain sid by using LSA functions instead of the samlib hack.

svn path=/trunk/; revision=56573

reactos/dll/win32/syssetup/CMakeLists.txt
reactos/dll/win32/syssetup/globals.h
reactos/dll/win32/syssetup/install.c
reactos/dll/win32/syssetup/security.c [new file with mode: 0644]
reactos/dll/win32/syssetup/wizard.c

index 06db9f2..81e7e6a 100644 (file)
@@ -8,6 +8,7 @@ list(APPEND SOURCE
     dllmain.c
     install.c
     logfile.c
+    security.c
     wizard.c
     syssetup.rc
     ${CMAKE_CURRENT_BINARY_DIR}/syssetup_stubs.c
index 3ea480a..c99d410 100644 (file)
@@ -61,6 +61,10 @@ extern HINSTANCE hDllInstance;
 extern HINF hSysSetupInf;
 extern SETUPDATA SetupData;
 
+/* security.c */
+NTSTATUS SetAccountDomain(LPCWSTR DomainName,
+                          PSID DomainSid);
+
 /* wizard.c */
 VOID InstallWizard (VOID);
 
index 3121996..a2faefb 100644 (file)
@@ -908,9 +908,9 @@ InstallReactOS(HINSTANCE hInstance)
     }
 
     /* Set the Domain SID (aka Computer SID) */
-    if (!SamSetDomainSid(DomainSid))
+    if (SetAccountDomain(NULL, DomainSid) != STATUS_SUCCESS)
     {
-        FatalError("SamSetDomainSid() failed!");
+        FatalError("SetAccountDomain() failed!");
         RtlFreeSid(DomainSid);
         return 0;
     }
diff --git a/reactos/dll/win32/syssetup/security.c b/reactos/dll/win32/syssetup/security.c
new file mode 100644 (file)
index 0000000..8b8c7d2
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * COPYRIGHT:         See COPYING in the top level directory
+ * PROJECT:           ReactOS system libraries
+ * PURPOSE:           System setup
+ * FILE:              dll/win32/syssetup/security.c
+ * PROGRAMER:         Eric Kohl
+ */
+
+/* INCLUDES *****************************************************************/
+
+#include "precomp.h"
+
+#define NDEBUG
+#include <debug.h>
+
+
+/* FUNCTIONS ****************************************************************/
+
+NTSTATUS
+SetAccountDomain(LPCWSTR DomainName,
+                 PSID DomainSid)
+{
+    PPOLICY_ACCOUNT_DOMAIN_INFO OrigInfo = NULL;
+    POLICY_ACCOUNT_DOMAIN_INFO Info;
+    LSA_OBJECT_ATTRIBUTES ObjectAttributes;
+    LSA_HANDLE PolicyHandle;
+    NTSTATUS Status;
+
+    memset(&ObjectAttributes, 0, sizeof(LSA_OBJECT_ATTRIBUTES));
+    ObjectAttributes.Length = sizeof(LSA_OBJECT_ATTRIBUTES);
+
+    Status = LsaOpenPolicy(NULL,
+                           &ObjectAttributes,
+                           POLICY_TRUST_ADMIN,
+                           &PolicyHandle);
+    if (Status != STATUS_SUCCESS)
+    {
+        DPRINT("LsaOpenPolicy failed (Status: 0x%08lx)\n", Status);
+        return Status;
+    }
+
+    Status = LsaQueryInformationPolicy(PolicyHandle,
+                                       PolicyAccountDomainInformation,
+                                       (PVOID *)&OrigInfo);
+    if (Status == STATUS_SUCCESS && OrigInfo != NULL)
+    {
+        if (DomainName == NULL)
+        {
+            Info.DomainName.Buffer = OrigInfo->DomainName.Buffer;
+            Info.DomainName.Length = OrigInfo->DomainName.Length;
+            Info.DomainName.MaximumLength = OrigInfo->DomainName.MaximumLength;
+        }
+        else
+        {
+            Info.DomainName.Buffer = (LPWSTR)DomainName;
+            Info.DomainName.Length = wcslen(DomainName) * sizeof(WCHAR);
+            Info.DomainName.MaximumLength = Info.DomainName.Length + sizeof(WCHAR);
+        }
+
+        if (DomainSid == NULL)
+            Info.DomainSid = OrigInfo->DomainSid;
+        else
+            Info.DomainSid = DomainSid;
+    }
+    else
+    {
+        Info.DomainName.Buffer = (LPWSTR)DomainName;
+        Info.DomainName.Length = wcslen(DomainName) * sizeof(WCHAR);
+        Info.DomainName.MaximumLength = Info.DomainName.Length + sizeof(WCHAR);
+        Info.DomainSid = DomainSid;
+    }
+
+    Status = LsaSetInformationPolicy(PolicyHandle,
+                                     PolicyAccountDomainInformation,
+                                     (PVOID)&Info);
+    if (Status != STATUS_SUCCESS)
+    {
+        DPRINT("LsaSetInformationPolicy failed (Status: 0x%08lx)\n", Status);
+    }
+
+    if (OrigInfo != NULL)
+        LsaFreeMemory(OrigInfo);
+
+    LsaClose(PolicyHandle);
+
+    return Status;
+}
index 4ed23f7..8bac2d8 100644 (file)
@@ -521,46 +521,6 @@ OwnerPageDlgProc(HWND hwndDlg,
     return FALSE;
 }
 
-static
-NTSTATUS
-SetAccountDomain(LPWSTR DomainName)
-{
-    POLICY_ACCOUNT_DOMAIN_INFO Info;
-    LSA_OBJECT_ATTRIBUTES ObjectAttributes;
-    LSA_HANDLE PolicyHandle;
-    NTSTATUS Status;
-
-    memset(&ObjectAttributes, 0, sizeof(LSA_OBJECT_ATTRIBUTES));
-    ObjectAttributes.Length = sizeof(LSA_OBJECT_ATTRIBUTES);
-
-    Status = LsaOpenPolicy(NULL,
-                           &ObjectAttributes,
-                           POLICY_TRUST_ADMIN,
-                           &PolicyHandle);
-    if (Status != STATUS_SUCCESS)
-    {
-        DPRINT("LsaOpenPolicy failed (Status: 0x%08lx)\n", Status);
-        return Status;
-    }
-
-    Info.DomainName.Buffer = DomainName;
-    Info.DomainName.Length = wcslen(DomainName) * sizeof(WCHAR);
-    Info.DomainName.MaximumLength = Info.DomainName.Length + sizeof(WCHAR);
-    Info.DomainSid = NULL;
-
-    Status = LsaSetInformationPolicy(PolicyHandle,
-                                     PolicyAccountDomainInformation,
-                                     (PVOID)&Info);
-    if (Status != STATUS_SUCCESS)
-    {
-        DPRINT("LsaSetInformationPolicy failed (Status: 0x%08lx)\n", Status);
-    }
-
-    LsaClose(PolicyHandle);
-
-    return Status;
-}
-
 static
 BOOL
 WriteComputerSettings(WCHAR * ComputerName, HWND hwndDlg)
@@ -587,7 +547,7 @@ WriteComputerSettings(WCHAR * ComputerName, HWND hwndDlg)
     SetComputerNameExW(ComputerNamePhysicalDnsHostname, ComputerName);
 
     /* Set the account domain name */
-    SetAccountDomain(ComputerName);
+    SetAccountDomain(ComputerName, NULL);
 
     return TRUE;
 }