mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 08:05:43 +00:00
[SYSSETUP]
Set the administrator password (hash) in the SAM database as part of the 2nd stage setup. svn path=/trunk/; revision=59088
This commit is contained in:
parent
019335405c
commit
44352306db
3 changed files with 107 additions and 1 deletions
|
@ -67,6 +67,8 @@ BOOL RegisterTypeLibraries (HINF hinf, LPCWSTR szSection);
|
|||
NTSTATUS SetAccountDomain(LPCWSTR DomainName,
|
||||
PSID DomainSid);
|
||||
VOID InstallSecurity(VOID);
|
||||
NTSTATUS
|
||||
SetAdministratorPassword(LPCWSTR Password);
|
||||
|
||||
/* wizard.c */
|
||||
VOID InstallWizard (VOID);
|
||||
|
|
|
@ -311,3 +311,106 @@ InstallSecurity(VOID)
|
|||
InstallBuiltinAccounts();
|
||||
InstallPrivileges();
|
||||
}
|
||||
|
||||
|
||||
NTSTATUS
|
||||
SetAdministratorPassword(LPCWSTR Password)
|
||||
{
|
||||
PPOLICY_ACCOUNT_DOMAIN_INFO OrigInfo = NULL;
|
||||
USER_SET_PASSWORD_INFORMATION PasswordInfo;
|
||||
LSA_OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
LSA_HANDLE PolicyHandle = NULL;
|
||||
SAM_HANDLE ServerHandle = NULL;
|
||||
SAM_HANDLE DomainHandle = NULL;
|
||||
SAM_HANDLE UserHandle = NULL;
|
||||
NTSTATUS Status;
|
||||
|
||||
DPRINT1("SYSSETUP: SetAdministratorPassword(%S)\n", Password);
|
||||
|
||||
memset(&ObjectAttributes, 0, sizeof(LSA_OBJECT_ATTRIBUTES));
|
||||
ObjectAttributes.Length = sizeof(LSA_OBJECT_ATTRIBUTES);
|
||||
|
||||
Status = LsaOpenPolicy(NULL,
|
||||
&ObjectAttributes,
|
||||
POLICY_VIEW_LOCAL_INFORMATION | POLICY_TRUST_ADMIN,
|
||||
&PolicyHandle);
|
||||
if (Status != STATUS_SUCCESS)
|
||||
{
|
||||
DPRINT1("LsaOpenPolicy() failed (Status: 0x%08lx)\n", Status);
|
||||
return Status;
|
||||
}
|
||||
|
||||
Status = LsaQueryInformationPolicy(PolicyHandle,
|
||||
PolicyAccountDomainInformation,
|
||||
(PVOID *)&OrigInfo);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("LsaQueryInformationPolicy() failed (Status: 0x%08lx)\n", Status);
|
||||
goto done;
|
||||
}
|
||||
|
||||
Status = SamConnect(NULL,
|
||||
&ServerHandle,
|
||||
SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
|
||||
NULL);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("SamConnect() failed (Status: 0x%08lx)\n", Status);
|
||||
goto done;
|
||||
}
|
||||
|
||||
Status = SamOpenDomain(ServerHandle,
|
||||
DOMAIN_LOOKUP,
|
||||
OrigInfo->DomainSid,
|
||||
&DomainHandle);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("SamOpenDomain() failed (Status: 0x%08lx)\n", Status);
|
||||
goto done;
|
||||
}
|
||||
|
||||
Status = SamOpenUser(DomainHandle,
|
||||
USER_FORCE_PASSWORD_CHANGE,
|
||||
DOMAIN_USER_RID_ADMIN, /* 500 */
|
||||
&UserHandle);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("SamOpenUser() failed (Status %08lx)\n", Status);
|
||||
goto done;
|
||||
}
|
||||
|
||||
RtlInitUnicodeString(&PasswordInfo.Password, Password);
|
||||
PasswordInfo.PasswordExpired = FALSE;
|
||||
|
||||
Status = SamSetInformationUser(UserHandle,
|
||||
UserSetPasswordInformation,
|
||||
(PVOID)&PasswordInfo);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT1("SamSetInformationUser() failed (Status %08lx)\n", Status);
|
||||
goto done;
|
||||
}
|
||||
|
||||
done:
|
||||
if (OrigInfo != NULL)
|
||||
LsaFreeMemory(OrigInfo);
|
||||
|
||||
if (PolicyHandle != NULL)
|
||||
LsaClose(PolicyHandle);
|
||||
|
||||
if (UserHandle != NULL)
|
||||
SamCloseHandle(UserHandle);
|
||||
|
||||
if (DomainHandle != NULL)
|
||||
SamCloseHandle(DomainHandle);
|
||||
|
||||
if (ServerHandle != NULL)
|
||||
SamCloseHandle(ServerHandle);
|
||||
|
||||
DPRINT1("SYSSETUP: SetAdministratorPassword() done (Status %08lx)\n", Status);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
||||
|
|
|
@ -709,7 +709,8 @@ ComputerPageDlgProc(HWND hwndDlg,
|
|||
Password++;
|
||||
}
|
||||
|
||||
/* FIXME: Set admin password */
|
||||
/* Set admin password */
|
||||
SetAdministratorPassword(Password1);
|
||||
break;
|
||||
|
||||
case PSN_WIZBACK:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue