diff --git a/reactos/dll/win32/syssetup/CMakeLists.txt b/reactos/dll/win32/syssetup/CMakeLists.txt index 06db9f2aa6c..81e7e6ab400 100644 --- a/reactos/dll/win32/syssetup/CMakeLists.txt +++ b/reactos/dll/win32/syssetup/CMakeLists.txt @@ -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 diff --git a/reactos/dll/win32/syssetup/globals.h b/reactos/dll/win32/syssetup/globals.h index 3ea480ac3b9..c99d4103dbb 100644 --- a/reactos/dll/win32/syssetup/globals.h +++ b/reactos/dll/win32/syssetup/globals.h @@ -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); diff --git a/reactos/dll/win32/syssetup/install.c b/reactos/dll/win32/syssetup/install.c index 3121996a6e2..a2faefb47ca 100644 --- a/reactos/dll/win32/syssetup/install.c +++ b/reactos/dll/win32/syssetup/install.c @@ -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 index 00000000000..8b8c7d2d860 --- /dev/null +++ b/reactos/dll/win32/syssetup/security.c @@ -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 + + +/* 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; +} diff --git a/reactos/dll/win32/syssetup/wizard.c b/reactos/dll/win32/syssetup/wizard.c index 4ed23f729b4..8bac2d8b781 100644 --- a/reactos/dll/win32/syssetup/wizard.c +++ b/reactos/dll/win32/syssetup/wizard.c @@ -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; }