[SYSSETUP]

Set the account domain name and account domain sid by using LSA functions instead of the samlib hack.

svn path=/trunk/; revision=56573
This commit is contained in:
Eric Kohl 2012-05-13 16:16:18 +00:00
parent dadcc449dd
commit b209ab9884
5 changed files with 95 additions and 43 deletions

View 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

View 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);

View 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;
}

View file

@ -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;
}

View 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;
}