2011-09-20 23:15:51 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: Local Security Authority Server DLL
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: dll/win32/lsasrv/database.c
|
|
|
|
* PURPOSE: LSA object database
|
|
|
|
* COPYRIGHT: Copyright 2011 Eric Kohl
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "lsasrv.h"
|
|
|
|
|
|
|
|
/* GLOBALS *****************************************************************/
|
|
|
|
|
|
|
|
static HANDLE SecurityKeyHandle = NULL;
|
|
|
|
|
2012-10-07 12:10:45 +00:00
|
|
|
SID_IDENTIFIER_AUTHORITY NullSidAuthority = {SECURITY_NULL_SID_AUTHORITY};
|
|
|
|
SID_IDENTIFIER_AUTHORITY WorldSidAuthority = {SECURITY_WORLD_SID_AUTHORITY};
|
|
|
|
SID_IDENTIFIER_AUTHORITY LocalSidAuthority = {SECURITY_LOCAL_SID_AUTHORITY};
|
|
|
|
SID_IDENTIFIER_AUTHORITY CreatorSidAuthority = {SECURITY_CREATOR_SID_AUTHORITY};
|
|
|
|
SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY};
|
|
|
|
|
|
|
|
PSID BuiltinDomainSid = NULL;
|
|
|
|
PSID AccountDomainSid = NULL;
|
|
|
|
UNICODE_STRING BuiltinDomainName = {0, 0, NULL};
|
|
|
|
UNICODE_STRING AccountDomainName = {0, 0, NULL};
|
|
|
|
|
2011-09-20 23:15:51 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS ***************************************************************/
|
|
|
|
|
|
|
|
static NTSTATUS
|
|
|
|
LsapOpenServiceKey(VOID)
|
|
|
|
{
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
UNICODE_STRING KeyName;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
RtlInitUnicodeString(&KeyName,
|
|
|
|
L"\\Registry\\Machine\\SECURITY");
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&KeyName,
|
|
|
|
OBJ_CASE_INSENSITIVE,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
Status = RtlpNtOpenKey(&SecurityKeyHandle,
|
|
|
|
KEY_READ | KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS,
|
|
|
|
&ObjectAttributes,
|
|
|
|
0);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static BOOLEAN
|
|
|
|
LsapIsDatabaseInstalled(VOID)
|
|
|
|
{
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
UNICODE_STRING KeyName;
|
|
|
|
HANDLE KeyHandle;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
RtlInitUnicodeString(&KeyName,
|
|
|
|
L"Policy");
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&KeyName,
|
|
|
|
OBJ_CASE_INSENSITIVE,
|
|
|
|
SecurityKeyHandle,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
Status = RtlpNtOpenKey(&KeyHandle,
|
|
|
|
KEY_READ,
|
|
|
|
&ObjectAttributes,
|
|
|
|
0);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
NtClose(KeyHandle);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static NTSTATUS
|
2011-09-23 18:24:33 +00:00
|
|
|
LsapCreateDatabaseKeys(VOID)
|
2011-09-20 23:15:51 +00:00
|
|
|
{
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
UNICODE_STRING KeyName;
|
|
|
|
HANDLE PolicyKeyHandle = NULL;
|
|
|
|
HANDLE AccountsKeyHandle = NULL;
|
|
|
|
HANDLE DomainsKeyHandle = NULL;
|
|
|
|
HANDLE SecretsKeyHandle = NULL;
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
TRACE("LsapInstallDatabase()\n");
|
|
|
|
|
|
|
|
/* Create the 'Policy' key */
|
|
|
|
RtlInitUnicodeString(&KeyName,
|
|
|
|
L"Policy");
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&KeyName,
|
|
|
|
OBJ_CASE_INSENSITIVE,
|
|
|
|
SecurityKeyHandle,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
Status = NtCreateKey(&PolicyKeyHandle,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
&ObjectAttributes,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
ERR("Failed to create the 'Policy' key (Status: 0x%08lx)\n", Status);
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create the 'Accounts' key */
|
|
|
|
RtlInitUnicodeString(&KeyName,
|
|
|
|
L"Accounts");
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&KeyName,
|
|
|
|
OBJ_CASE_INSENSITIVE,
|
|
|
|
PolicyKeyHandle,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
Status = NtCreateKey(&AccountsKeyHandle,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
&ObjectAttributes,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
ERR("Failed to create the 'Accounts' key (Status: 0x%08lx)\n", Status);
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create the 'Domains' key */
|
|
|
|
RtlInitUnicodeString(&KeyName,
|
|
|
|
L"Domains");
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&KeyName,
|
|
|
|
OBJ_CASE_INSENSITIVE,
|
|
|
|
PolicyKeyHandle,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
Status = NtCreateKey(&DomainsKeyHandle,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
&ObjectAttributes,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
ERR("Failed to create the 'Domains' key (Status: 0x%08lx)\n", Status);
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create the 'Secrets' key */
|
|
|
|
RtlInitUnicodeString(&KeyName,
|
|
|
|
L"Secrets");
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&KeyName,
|
|
|
|
OBJ_CASE_INSENSITIVE,
|
|
|
|
PolicyKeyHandle,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
Status = NtCreateKey(&SecretsKeyHandle,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
&ObjectAttributes,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
ERR("Failed to create the 'Secrets' key (Status: 0x%08lx)\n", Status);
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
Done:
|
|
|
|
if (SecretsKeyHandle != NULL)
|
|
|
|
NtClose(SecretsKeyHandle);
|
|
|
|
|
|
|
|
if (DomainsKeyHandle != NULL)
|
|
|
|
NtClose(DomainsKeyHandle);
|
|
|
|
|
|
|
|
if (AccountsKeyHandle != NULL)
|
|
|
|
NtClose(AccountsKeyHandle);
|
|
|
|
|
|
|
|
if (PolicyKeyHandle != NULL)
|
|
|
|
NtClose(PolicyKeyHandle);
|
|
|
|
|
|
|
|
TRACE("LsapInstallDatabase() done (Status: 0x%08lx)\n", Status);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-30 22:53:37 +00:00
|
|
|
static NTSTATUS
|
|
|
|
LsapCreateRandomDomainSid(OUT PSID *Sid)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER SystemTime;
|
|
|
|
PULONG Seed;
|
|
|
|
|
|
|
|
NtQuerySystemTime(&SystemTime);
|
|
|
|
Seed = &SystemTime.u.LowPart;
|
|
|
|
|
2012-10-07 12:10:45 +00:00
|
|
|
return RtlAllocateAndInitializeSid(&NtAuthority,
|
2012-05-30 22:53:37 +00:00
|
|
|
4,
|
|
|
|
SECURITY_NT_NON_UNIQUE,
|
|
|
|
RtlUniform(Seed),
|
|
|
|
RtlUniform(Seed),
|
|
|
|
RtlUniform(Seed),
|
|
|
|
SECURITY_NULL_RID,
|
|
|
|
SECURITY_NULL_RID,
|
|
|
|
SECURITY_NULL_RID,
|
|
|
|
SECURITY_NULL_RID,
|
|
|
|
Sid);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-23 18:24:33 +00:00
|
|
|
static NTSTATUS
|
|
|
|
LsapCreateDatabaseObjects(VOID)
|
|
|
|
{
|
2012-09-26 16:15:29 +00:00
|
|
|
PLSAP_POLICY_AUDIT_EVENTS_DATA AuditEventsInfo = NULL;
|
2012-09-25 16:08:00 +00:00
|
|
|
POLICY_DEFAULT_QUOTA_INFO QuotaInfo;
|
2012-09-26 16:15:29 +00:00
|
|
|
POLICY_MODIFICATION_INFO ModificationInfo;
|
|
|
|
POLICY_AUDIT_FULL_QUERY_INFO AuditFullInfo = {FALSE, FALSE};
|
|
|
|
POLICY_AUDIT_LOG_INFO AuditLogInfo;
|
2012-09-26 22:51:12 +00:00
|
|
|
GUID DnsDomainGuid;
|
2012-05-30 22:53:37 +00:00
|
|
|
PLSA_DB_OBJECT PolicyObject = NULL;
|
|
|
|
PSID AccountDomainSid = NULL;
|
2012-11-18 15:19:14 +00:00
|
|
|
PSECURITY_DESCRIPTOR PolicySd = NULL;
|
|
|
|
ULONG PolicySdSize = 0;
|
2012-09-26 16:15:29 +00:00
|
|
|
ULONG i;
|
2012-05-06 09:57:31 +00:00
|
|
|
NTSTATUS Status;
|
2011-09-23 18:24:33 +00:00
|
|
|
|
2012-09-25 16:08:00 +00:00
|
|
|
/* Initialize the default quota limits */
|
|
|
|
QuotaInfo.QuotaLimits.PagedPoolLimit = 0x2000000;
|
|
|
|
QuotaInfo.QuotaLimits.NonPagedPoolLimit = 0x100000;
|
|
|
|
QuotaInfo.QuotaLimits.MinimumWorkingSetSize = 0x10000;
|
|
|
|
QuotaInfo.QuotaLimits.MaximumWorkingSetSize = 0xF000000;
|
|
|
|
QuotaInfo.QuotaLimits.PagefileLimit = 0;
|
|
|
|
QuotaInfo.QuotaLimits.TimeLimit.QuadPart = 0;
|
|
|
|
|
2012-09-26 16:15:29 +00:00
|
|
|
/* Initialize the audit log attribute */
|
|
|
|
AuditLogInfo.AuditLogPercentFull = 0;
|
|
|
|
AuditLogInfo.MaximumLogSize = 0; // DWORD
|
|
|
|
AuditLogInfo.AuditRetentionPeriod.QuadPart = 0; // LARGE_INTEGER
|
|
|
|
AuditLogInfo.AuditLogFullShutdownInProgress = 0; // BYTE
|
|
|
|
AuditLogInfo.TimeToShutdown.QuadPart = 0; // LARGE_INTEGER
|
|
|
|
AuditLogInfo.NextAuditRecordId = 0; // DWORD
|
|
|
|
|
2012-09-26 22:51:12 +00:00
|
|
|
/* Initialize the Audit Events attribute */
|
2012-09-26 16:15:29 +00:00
|
|
|
AuditEventsInfo = RtlAllocateHeap(RtlGetProcessHeap(),
|
2012-11-18 15:19:14 +00:00
|
|
|
HEAP_ZERO_MEMORY,
|
2014-01-14 20:24:43 +00:00
|
|
|
sizeof(LSAP_POLICY_AUDIT_EVENTS_DATA));
|
2012-09-26 16:15:29 +00:00
|
|
|
if (AuditEventsInfo == NULL)
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
|
|
|
|
AuditEventsInfo->AuditingMode = FALSE;
|
2014-01-14 20:24:43 +00:00
|
|
|
AuditEventsInfo->MaximumAuditEventCount = POLICY_AUDIT_EVENT_TYPE_COUNT;
|
|
|
|
for (i = 0; i < POLICY_AUDIT_EVENT_TYPE_COUNT; i++)
|
2012-09-26 16:15:29 +00:00
|
|
|
AuditEventsInfo->AuditEvents[i] = 0;
|
|
|
|
|
2012-09-26 22:51:12 +00:00
|
|
|
/* Initialize the DNS Domain GUID attribute */
|
|
|
|
memset(&DnsDomainGuid, 0, sizeof(GUID));
|
|
|
|
|
2012-09-26 16:15:29 +00:00
|
|
|
/* Initialize the modification attribute */
|
|
|
|
ModificationInfo.ModifiedId.QuadPart = 0;
|
|
|
|
NtQuerySystemTime(&ModificationInfo.DatabaseCreationTime);
|
|
|
|
|
2012-05-30 22:53:37 +00:00
|
|
|
/* Create a random domain SID */
|
|
|
|
Status = LsapCreateRandomDomainSid(&AccountDomainSid);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2012-09-26 16:15:29 +00:00
|
|
|
goto done;
|
2012-05-30 22:53:37 +00:00
|
|
|
|
2013-03-10 13:43:13 +00:00
|
|
|
Status = LsapCreatePolicySd(&PolicySd, &PolicySdSize);
|
2012-11-18 15:19:14 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
goto done;
|
|
|
|
|
2011-09-23 18:24:33 +00:00
|
|
|
/* Open the 'Policy' object */
|
2012-05-06 09:57:31 +00:00
|
|
|
Status = LsapOpenDbObject(NULL,
|
2012-09-30 23:50:30 +00:00
|
|
|
NULL,
|
2012-05-06 09:57:31 +00:00
|
|
|
L"Policy",
|
|
|
|
LsaDbPolicyObject,
|
|
|
|
0,
|
2012-12-08 17:18:17 +00:00
|
|
|
TRUE,
|
2012-05-06 09:57:31 +00:00
|
|
|
&PolicyObject);
|
|
|
|
if (!NT_SUCCESS(Status))
|
2012-05-30 22:53:37 +00:00
|
|
|
goto done;
|
2011-09-23 18:24:33 +00:00
|
|
|
|
2012-05-06 09:57:31 +00:00
|
|
|
LsapSetObjectAttribute(PolicyObject,
|
|
|
|
L"PolPrDmN",
|
|
|
|
NULL,
|
|
|
|
0);
|
2011-09-23 18:24:33 +00:00
|
|
|
|
2012-05-06 09:57:31 +00:00
|
|
|
LsapSetObjectAttribute(PolicyObject,
|
|
|
|
L"PolPrDmS",
|
|
|
|
NULL,
|
|
|
|
0);
|
2011-09-23 18:24:33 +00:00
|
|
|
|
2012-05-06 09:57:31 +00:00
|
|
|
LsapSetObjectAttribute(PolicyObject,
|
|
|
|
L"PolAcDmN",
|
|
|
|
NULL,
|
|
|
|
0);
|
2011-09-23 18:24:33 +00:00
|
|
|
|
2012-05-06 09:57:31 +00:00
|
|
|
LsapSetObjectAttribute(PolicyObject,
|
|
|
|
L"PolAcDmS",
|
2012-05-30 22:53:37 +00:00
|
|
|
AccountDomainSid,
|
|
|
|
RtlLengthSid(AccountDomainSid));
|
2011-09-23 18:24:33 +00:00
|
|
|
|
2012-09-25 16:08:00 +00:00
|
|
|
/* Set the default quota limits attribute */
|
|
|
|
LsapSetObjectAttribute(PolicyObject,
|
|
|
|
L"DefQuota",
|
|
|
|
&QuotaInfo,
|
|
|
|
sizeof(POLICY_DEFAULT_QUOTA_INFO));
|
|
|
|
|
2012-09-26 16:15:29 +00:00
|
|
|
/* Set the modification attribute */
|
|
|
|
LsapSetObjectAttribute(PolicyObject,
|
|
|
|
L"PolMod",
|
|
|
|
&ModificationInfo,
|
|
|
|
sizeof(POLICY_MODIFICATION_INFO));
|
|
|
|
|
|
|
|
/* Set the audit full attribute */
|
|
|
|
LsapSetObjectAttribute(PolicyObject,
|
|
|
|
L"PolAdtFl",
|
|
|
|
&AuditFullInfo,
|
|
|
|
sizeof(POLICY_AUDIT_FULL_QUERY_INFO));
|
|
|
|
|
|
|
|
/* Set the audit log attribute */
|
|
|
|
LsapSetObjectAttribute(PolicyObject,
|
|
|
|
L"PolAdtLg",
|
|
|
|
&AuditLogInfo,
|
|
|
|
sizeof(POLICY_AUDIT_LOG_INFO));
|
|
|
|
|
|
|
|
/* Set the audit events attribute */
|
|
|
|
LsapSetObjectAttribute(PolicyObject,
|
|
|
|
L"PolAdtEv",
|
2013-03-10 13:43:13 +00:00
|
|
|
AuditEventsInfo,
|
2014-01-14 20:24:43 +00:00
|
|
|
sizeof(LSAP_POLICY_AUDIT_EVENTS_DATA));
|
2012-09-26 16:15:29 +00:00
|
|
|
|
2012-09-26 22:51:12 +00:00
|
|
|
/* Set the DNS Domain Name attribute */
|
|
|
|
LsapSetObjectAttribute(PolicyObject,
|
|
|
|
L"PolDnDDN",
|
|
|
|
NULL,
|
|
|
|
0);
|
|
|
|
|
|
|
|
/* Set the DNS Forest Name attribute */
|
|
|
|
LsapSetObjectAttribute(PolicyObject,
|
|
|
|
L"PolDnTrN",
|
|
|
|
NULL,
|
|
|
|
0);
|
|
|
|
|
|
|
|
/* Set the DNS Domain GUID attribute */
|
|
|
|
LsapSetObjectAttribute(PolicyObject,
|
|
|
|
L"PolDnDmG",
|
|
|
|
&DnsDomainGuid,
|
|
|
|
sizeof(GUID));
|
|
|
|
|
2012-11-18 15:19:14 +00:00
|
|
|
/* Set the Sceurity Descriptor */
|
|
|
|
LsapSetObjectAttribute(PolicyObject,
|
|
|
|
L"SecDesc",
|
|
|
|
PolicySd,
|
|
|
|
PolicySdSize);
|
|
|
|
|
2012-05-30 22:53:37 +00:00
|
|
|
done:
|
2012-09-26 16:15:29 +00:00
|
|
|
if (AuditEventsInfo != NULL)
|
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, AuditEventsInfo);
|
|
|
|
|
2012-05-30 22:53:37 +00:00
|
|
|
if (PolicyObject != NULL)
|
|
|
|
LsapCloseDbObject(PolicyObject);
|
2011-09-23 18:24:33 +00:00
|
|
|
|
2012-05-30 22:53:37 +00:00
|
|
|
if (AccountDomainSid != NULL)
|
|
|
|
RtlFreeSid(AccountDomainSid);
|
|
|
|
|
2012-11-18 15:19:14 +00:00
|
|
|
if (PolicySd != NULL)
|
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, PolicySd);
|
|
|
|
|
2012-05-30 22:53:37 +00:00
|
|
|
return Status;
|
2011-09-23 18:24:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static NTSTATUS
|
|
|
|
LsapUpdateDatabase(VOID)
|
|
|
|
{
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-07 12:10:45 +00:00
|
|
|
static NTSTATUS
|
|
|
|
LsapGetDomainInfo(VOID)
|
|
|
|
{
|
|
|
|
PLSA_DB_OBJECT PolicyObject = NULL;
|
|
|
|
PUNICODE_STRING DomainName = NULL;
|
|
|
|
ULONG AttributeSize;
|
|
|
|
LPWSTR SidString = NULL;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
/* Get the built-in domain SID and name */
|
|
|
|
Status = RtlAllocateAndInitializeSid(&NtAuthority,
|
|
|
|
1,
|
|
|
|
SECURITY_BUILTIN_DOMAIN_RID,
|
|
|
|
0, 0, 0, 0, 0, 0, 0,
|
|
|
|
&BuiltinDomainSid);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return Status;
|
|
|
|
|
|
|
|
/**/
|
|
|
|
RtlInitUnicodeString(&BuiltinDomainName,
|
|
|
|
L"BUILTIN");
|
|
|
|
|
|
|
|
/* Open the 'Policy' object */
|
|
|
|
Status = LsapOpenDbObject(NULL,
|
|
|
|
NULL,
|
|
|
|
L"Policy",
|
|
|
|
LsaDbPolicyObject,
|
|
|
|
0,
|
2012-12-08 17:18:17 +00:00
|
|
|
TRUE,
|
2012-10-07 12:10:45 +00:00
|
|
|
&PolicyObject);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* Get the account domain SID */
|
|
|
|
AttributeSize = 0;
|
|
|
|
Status = LsapGetObjectAttribute(PolicyObject,
|
|
|
|
L"PolAcDmS",
|
|
|
|
NULL,
|
|
|
|
&AttributeSize);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (AttributeSize > 0)
|
|
|
|
{
|
|
|
|
AccountDomainSid = RtlAllocateHeap(RtlGetProcessHeap(),
|
|
|
|
HEAP_ZERO_MEMORY,
|
|
|
|
AttributeSize);
|
|
|
|
if (AccountDomainSid == NULL)
|
|
|
|
{
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = LsapGetObjectAttribute(PolicyObject,
|
|
|
|
L"PolAcDmS",
|
|
|
|
AccountDomainSid,
|
|
|
|
&AttributeSize);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the account domain name */
|
|
|
|
AttributeSize = 0;
|
|
|
|
Status = LsapGetObjectAttribute(PolicyObject,
|
|
|
|
L"PolAcDmN",
|
|
|
|
NULL,
|
|
|
|
&AttributeSize);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (AttributeSize > 0)
|
|
|
|
{
|
|
|
|
DomainName = RtlAllocateHeap(RtlGetProcessHeap(),
|
|
|
|
HEAP_ZERO_MEMORY,
|
|
|
|
AttributeSize);
|
|
|
|
if (DomainName == NULL)
|
|
|
|
{
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = LsapGetObjectAttribute(PolicyObject,
|
|
|
|
L"PolAcDmN",
|
|
|
|
DomainName,
|
|
|
|
&AttributeSize);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
DomainName->Buffer = (LPWSTR)((ULONG_PTR)DomainName + (ULONG_PTR)DomainName->Buffer);
|
|
|
|
|
|
|
|
AccountDomainName.Length = DomainName->Length;
|
|
|
|
AccountDomainName.MaximumLength = DomainName->Length + sizeof(WCHAR);
|
|
|
|
AccountDomainName.Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
|
|
|
|
HEAP_ZERO_MEMORY,
|
|
|
|
AccountDomainName.MaximumLength);
|
|
|
|
if (AccountDomainName.Buffer == NULL)
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate the account domain name buffer\n");
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlCopyMemory(AccountDomainName.Buffer,
|
|
|
|
DomainName->Buffer,
|
|
|
|
DomainName->Length);
|
|
|
|
}
|
|
|
|
|
|
|
|
ConvertSidToStringSidW(BuiltinDomainSid, &SidString);
|
|
|
|
TRACE("Builtin Domain SID: %S\n", SidString);
|
|
|
|
LocalFree(SidString);
|
|
|
|
SidString = NULL;
|
|
|
|
|
|
|
|
TRACE("Builtin Domain Name: %wZ\n", &BuiltinDomainName);
|
|
|
|
|
|
|
|
ConvertSidToStringSidW(AccountDomainSid, &SidString);
|
|
|
|
TRACE("Account Domain SID: %S\n", SidString);
|
|
|
|
LocalFree(SidString);
|
|
|
|
SidString = NULL;
|
|
|
|
|
|
|
|
TRACE("Account Domain Name: %wZ\n", &AccountDomainName);
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (DomainName != NULL)
|
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, DomainName);
|
|
|
|
|
|
|
|
if (PolicyObject != NULL)
|
|
|
|
LsapCloseDbObject(PolicyObject);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-20 23:15:51 +00:00
|
|
|
NTSTATUS
|
|
|
|
LsapInitDatabase(VOID)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
TRACE("LsapInitDatabase()\n");
|
|
|
|
|
|
|
|
Status = LsapOpenServiceKey();
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
ERR("Failed to open the service key (Status: 0x%08lx)\n", Status);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!LsapIsDatabaseInstalled())
|
|
|
|
{
|
2011-09-23 18:24:33 +00:00
|
|
|
Status = LsapCreateDatabaseKeys();
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
ERR("Failed to create the LSA database keys (Status: 0x%08lx)\n", Status);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = LsapCreateDatabaseObjects();
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
ERR("Failed to create the LSA database objects (Status: 0x%08lx)\n", Status);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = LsapUpdateDatabase();
|
2011-09-20 23:15:51 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2011-09-23 18:24:33 +00:00
|
|
|
ERR("Failed to update the LSA database (Status: 0x%08lx)\n", Status);
|
2011-09-20 23:15:51 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-07 12:10:45 +00:00
|
|
|
Status = LsapGetDomainInfo();
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
ERR("Failed to get the domain information (Status: 0x%08lx)\n", Status);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2011-09-20 23:15:51 +00:00
|
|
|
TRACE("LsapInitDatabase() done\n");
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-06 09:57:31 +00:00
|
|
|
NTSTATUS
|
|
|
|
LsapCreateDbObject(IN PLSA_DB_OBJECT ParentObject,
|
2012-09-30 23:50:30 +00:00
|
|
|
IN LPWSTR ContainerName,
|
2012-05-06 09:57:31 +00:00
|
|
|
IN LPWSTR ObjectName,
|
|
|
|
IN LSA_DB_OBJECT_TYPE ObjectType,
|
|
|
|
IN ACCESS_MASK DesiredAccess,
|
2012-12-08 17:18:17 +00:00
|
|
|
IN BOOLEAN Trusted,
|
2012-05-06 09:57:31 +00:00
|
|
|
OUT PLSA_DB_OBJECT *DbObject)
|
2011-09-20 23:15:51 +00:00
|
|
|
{
|
2012-05-06 09:57:31 +00:00
|
|
|
PLSA_DB_OBJECT NewObject;
|
2011-09-20 23:15:51 +00:00
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
UNICODE_STRING KeyName;
|
|
|
|
HANDLE ParentKeyHandle;
|
2012-09-30 23:50:30 +00:00
|
|
|
HANDLE ContainerKeyHandle = NULL;
|
|
|
|
HANDLE ObjectKeyHandle = NULL;
|
2011-09-20 23:15:51 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
|
2012-05-06 09:57:31 +00:00
|
|
|
if (DbObject == NULL)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if (ParentObject == NULL)
|
2011-09-20 23:15:51 +00:00
|
|
|
ParentKeyHandle = SecurityKeyHandle;
|
2012-05-06 09:57:31 +00:00
|
|
|
else
|
|
|
|
ParentKeyHandle = ParentObject->KeyHandle;
|
2011-09-20 23:15:51 +00:00
|
|
|
|
2012-09-30 23:50:30 +00:00
|
|
|
if (ContainerName != NULL)
|
|
|
|
{
|
|
|
|
/* Open the container key */
|
|
|
|
RtlInitUnicodeString(&KeyName,
|
|
|
|
ContainerName);
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&KeyName,
|
|
|
|
OBJ_CASE_INSENSITIVE,
|
|
|
|
ParentKeyHandle,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
Status = NtOpenKey(&ContainerKeyHandle,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
&ObjectAttributes);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return Status;
|
|
|
|
}
|
2011-09-20 23:15:51 +00:00
|
|
|
|
2012-09-30 23:50:30 +00:00
|
|
|
/* Open the object key */
|
|
|
|
RtlInitUnicodeString(&KeyName,
|
|
|
|
ObjectName);
|
2011-09-20 23:15:51 +00:00
|
|
|
|
2012-09-30 23:50:30 +00:00
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&KeyName,
|
|
|
|
OBJ_CASE_INSENSITIVE,
|
|
|
|
ContainerKeyHandle,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
Status = NtCreateKey(&ObjectKeyHandle,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
&ObjectAttributes,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
NtClose(ContainerKeyHandle);
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2011-09-20 23:15:51 +00:00
|
|
|
{
|
2012-09-30 23:50:30 +00:00
|
|
|
RtlInitUnicodeString(&KeyName,
|
|
|
|
ObjectName);
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&KeyName,
|
|
|
|
OBJ_CASE_INSENSITIVE,
|
|
|
|
ParentKeyHandle,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
Status = NtCreateKey(&ObjectKeyHandle,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
&ObjectAttributes,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return Status;
|
|
|
|
}
|
2011-09-20 23:15:51 +00:00
|
|
|
}
|
2012-05-06 09:57:31 +00:00
|
|
|
|
|
|
|
NewObject = RtlAllocateHeap(RtlGetProcessHeap(),
|
|
|
|
0,
|
|
|
|
sizeof(LSA_DB_OBJECT));
|
|
|
|
if (NewObject == NULL)
|
2011-09-20 23:15:51 +00:00
|
|
|
{
|
2012-05-06 09:57:31 +00:00
|
|
|
NtClose(ObjectKeyHandle);
|
|
|
|
return STATUS_NO_MEMORY;
|
2011-09-20 23:15:51 +00:00
|
|
|
}
|
|
|
|
|
2012-05-06 09:57:31 +00:00
|
|
|
NewObject->Signature = LSAP_DB_SIGNATURE;
|
|
|
|
NewObject->RefCount = 1;
|
|
|
|
NewObject->ObjectType = ObjectType;
|
|
|
|
NewObject->Access = DesiredAccess;
|
|
|
|
NewObject->KeyHandle = ObjectKeyHandle;
|
|
|
|
NewObject->ParentObject = ParentObject;
|
2012-12-08 17:18:17 +00:00
|
|
|
NewObject->Trusted = Trusted;
|
2012-05-06 09:57:31 +00:00
|
|
|
|
|
|
|
if (ParentObject != NULL)
|
|
|
|
ParentObject->RefCount++;
|
|
|
|
|
|
|
|
*DbObject = NewObject;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
LsapOpenDbObject(IN PLSA_DB_OBJECT ParentObject,
|
2012-09-30 23:50:30 +00:00
|
|
|
IN LPWSTR ContainerName,
|
2012-05-06 09:57:31 +00:00
|
|
|
IN LPWSTR ObjectName,
|
|
|
|
IN LSA_DB_OBJECT_TYPE ObjectType,
|
|
|
|
IN ACCESS_MASK DesiredAccess,
|
2012-12-08 17:18:17 +00:00
|
|
|
IN BOOLEAN Trusted,
|
2012-05-06 09:57:31 +00:00
|
|
|
OUT PLSA_DB_OBJECT *DbObject)
|
|
|
|
{
|
|
|
|
PLSA_DB_OBJECT NewObject;
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
UNICODE_STRING KeyName;
|
|
|
|
HANDLE ParentKeyHandle;
|
2012-09-30 23:50:30 +00:00
|
|
|
HANDLE ContainerKeyHandle = NULL;
|
|
|
|
HANDLE ObjectKeyHandle = NULL;
|
2012-05-06 09:57:31 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
if (DbObject == NULL)
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if (ParentObject == NULL)
|
|
|
|
ParentKeyHandle = SecurityKeyHandle;
|
|
|
|
else
|
|
|
|
ParentKeyHandle = ParentObject->KeyHandle;
|
|
|
|
|
2012-09-30 23:50:30 +00:00
|
|
|
if (ContainerName != NULL)
|
|
|
|
{
|
|
|
|
/* Open the container key */
|
|
|
|
RtlInitUnicodeString(&KeyName,
|
|
|
|
ContainerName);
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&KeyName,
|
|
|
|
OBJ_CASE_INSENSITIVE,
|
|
|
|
ParentKeyHandle,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
Status = NtOpenKey(&ContainerKeyHandle,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
&ObjectAttributes);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return Status;
|
|
|
|
}
|
2012-05-06 09:57:31 +00:00
|
|
|
|
2012-09-30 23:50:30 +00:00
|
|
|
/* Open the object key */
|
|
|
|
RtlInitUnicodeString(&KeyName,
|
|
|
|
ObjectName);
|
2012-05-06 09:57:31 +00:00
|
|
|
|
2012-09-30 23:50:30 +00:00
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&KeyName,
|
|
|
|
OBJ_CASE_INSENSITIVE,
|
|
|
|
ContainerKeyHandle,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
Status = NtOpenKey(&ObjectKeyHandle,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
&ObjectAttributes);
|
|
|
|
|
|
|
|
NtClose(ContainerKeyHandle);
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2011-09-20 23:15:51 +00:00
|
|
|
{
|
2012-09-30 23:50:30 +00:00
|
|
|
/* Open the object key */
|
|
|
|
RtlInitUnicodeString(&KeyName,
|
|
|
|
ObjectName);
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&KeyName,
|
|
|
|
OBJ_CASE_INSENSITIVE,
|
|
|
|
ParentKeyHandle,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
Status = NtOpenKey(&ObjectKeyHandle,
|
|
|
|
KEY_ALL_ACCESS,
|
|
|
|
&ObjectAttributes);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return Status;
|
|
|
|
}
|
2011-09-20 23:15:51 +00:00
|
|
|
}
|
|
|
|
|
2012-05-06 09:57:31 +00:00
|
|
|
NewObject = RtlAllocateHeap(RtlGetProcessHeap(),
|
2012-09-30 23:50:30 +00:00
|
|
|
0,
|
2012-11-26 21:55:09 +00:00
|
|
|
sizeof(LSA_DB_OBJECT));
|
2012-05-06 09:57:31 +00:00
|
|
|
if (NewObject == NULL)
|
2011-09-20 23:15:51 +00:00
|
|
|
{
|
|
|
|
NtClose(ObjectKeyHandle);
|
2012-05-06 09:57:31 +00:00
|
|
|
return STATUS_NO_MEMORY;
|
2011-09-20 23:15:51 +00:00
|
|
|
}
|
|
|
|
|
2012-05-06 09:57:31 +00:00
|
|
|
NewObject->Signature = LSAP_DB_SIGNATURE;
|
|
|
|
NewObject->RefCount = 1;
|
|
|
|
NewObject->ObjectType = ObjectType;
|
|
|
|
NewObject->Access = DesiredAccess;
|
|
|
|
NewObject->KeyHandle = ObjectKeyHandle;
|
|
|
|
NewObject->ParentObject = ParentObject;
|
2012-12-08 17:18:17 +00:00
|
|
|
NewObject->Trusted = Trusted;
|
2011-09-20 23:15:51 +00:00
|
|
|
|
|
|
|
if (ParentObject != NULL)
|
|
|
|
ParentObject->RefCount++;
|
|
|
|
|
2012-05-06 09:57:31 +00:00
|
|
|
*DbObject = NewObject;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
2011-09-20 23:15:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
LsapValidateDbObject(LSAPR_HANDLE Handle,
|
|
|
|
LSA_DB_OBJECT_TYPE ObjectType,
|
2012-05-06 09:57:31 +00:00
|
|
|
ACCESS_MASK DesiredAccess,
|
|
|
|
PLSA_DB_OBJECT *DbObject)
|
2011-09-20 23:15:51 +00:00
|
|
|
{
|
2012-05-06 09:57:31 +00:00
|
|
|
PLSA_DB_OBJECT LocalObject = (PLSA_DB_OBJECT)Handle;
|
2011-09-20 23:15:51 +00:00
|
|
|
BOOLEAN bValid = FALSE;
|
|
|
|
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
2012-05-06 09:57:31 +00:00
|
|
|
if (LocalObject->Signature == LSAP_DB_SIGNATURE)
|
2011-09-20 23:15:51 +00:00
|
|
|
{
|
|
|
|
if ((ObjectType == LsaDbIgnoreObject) ||
|
2012-05-06 09:57:31 +00:00
|
|
|
(LocalObject->ObjectType == ObjectType))
|
2011-09-20 23:15:51 +00:00
|
|
|
bValid = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
bValid = FALSE;
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
|
|
|
|
if (bValid == FALSE)
|
|
|
|
return STATUS_INVALID_HANDLE;
|
|
|
|
|
2012-05-06 09:57:31 +00:00
|
|
|
if (DesiredAccess != 0)
|
2011-09-20 23:15:51 +00:00
|
|
|
{
|
2012-05-06 09:57:31 +00:00
|
|
|
/* Check for granted access rights */
|
|
|
|
if ((LocalObject->Access & DesiredAccess) != DesiredAccess)
|
|
|
|
{
|
|
|
|
ERR("LsapValidateDbObject access check failed %08lx %08lx\n",
|
|
|
|
LocalObject->Access, DesiredAccess);
|
|
|
|
return STATUS_ACCESS_DENIED;
|
|
|
|
}
|
2011-09-20 23:15:51 +00:00
|
|
|
}
|
|
|
|
|
2012-05-06 09:57:31 +00:00
|
|
|
if (DbObject != NULL)
|
|
|
|
*DbObject = LocalObject;
|
|
|
|
|
2011-09-20 23:15:51 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NTSTATUS
|
2012-05-06 09:57:31 +00:00
|
|
|
LsapCloseDbObject(PLSA_DB_OBJECT DbObject)
|
2011-09-20 23:15:51 +00:00
|
|
|
{
|
2012-05-06 09:57:31 +00:00
|
|
|
PLSA_DB_OBJECT ParentObject = NULL;
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
2011-09-20 23:15:51 +00:00
|
|
|
|
2012-05-06 09:57:31 +00:00
|
|
|
DbObject->RefCount--;
|
2011-09-20 23:15:51 +00:00
|
|
|
|
2012-05-06 09:57:31 +00:00
|
|
|
if (DbObject->RefCount > 0)
|
|
|
|
return STATUS_SUCCESS;
|
2011-09-20 23:15:51 +00:00
|
|
|
|
|
|
|
if (DbObject->KeyHandle != NULL)
|
|
|
|
NtClose(DbObject->KeyHandle);
|
|
|
|
|
2012-05-06 09:57:31 +00:00
|
|
|
if (DbObject->ParentObject != NULL)
|
|
|
|
ParentObject = DbObject->ParentObject;
|
|
|
|
|
2011-09-20 23:15:51 +00:00
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, DbObject);
|
|
|
|
|
2012-11-25 19:47:54 +00:00
|
|
|
if (ParentObject != NULL)
|
|
|
|
{
|
|
|
|
ParentObject->RefCount--;
|
|
|
|
|
|
|
|
if (ParentObject->RefCount == 0)
|
|
|
|
Status = LsapCloseDbObject(ParentObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
LsapDeleteDbObject(IN PLSA_DB_OBJECT DbObject)
|
|
|
|
{
|
|
|
|
PLSA_DB_OBJECT ParentObject = NULL;
|
|
|
|
WCHAR KeyName[64];
|
2012-11-29 22:02:22 +00:00
|
|
|
ULONG Index;
|
2012-11-25 19:47:54 +00:00
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
DbObject->RefCount--;
|
|
|
|
|
|
|
|
if (DbObject->RefCount > 0)
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
if (DbObject->KeyHandle != NULL)
|
|
|
|
{
|
2012-11-29 22:02:22 +00:00
|
|
|
Index = 0;
|
2012-11-25 19:47:54 +00:00
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
Status = LsapRegEnumerateSubKey(DbObject->KeyHandle,
|
2012-11-29 22:02:22 +00:00
|
|
|
Index,
|
2012-11-25 19:47:54 +00:00
|
|
|
64 * sizeof(WCHAR),
|
|
|
|
KeyName);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
break;
|
|
|
|
|
2012-11-29 22:02:22 +00:00
|
|
|
TRACE("Index: %lu\n", Index);
|
2012-11-25 19:47:54 +00:00
|
|
|
TRACE("Key name: %S\n", KeyName);
|
|
|
|
|
2012-11-29 22:02:22 +00:00
|
|
|
Status = LsapRegDeleteSubKey(DbObject->KeyHandle,
|
|
|
|
KeyName);
|
2012-11-25 19:47:54 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
break;
|
|
|
|
}
|
2012-11-29 22:02:22 +00:00
|
|
|
|
|
|
|
if (Status == STATUS_NO_MORE_ENTRIES)
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
LsapRegDeleteKey(DbObject->KeyHandle);
|
|
|
|
|
2012-11-25 19:47:54 +00:00
|
|
|
NtClose(DbObject->KeyHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DbObject->ParentObject != NULL)
|
|
|
|
ParentObject = DbObject->ParentObject;
|
|
|
|
|
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, DbObject);
|
|
|
|
|
2012-05-06 09:57:31 +00:00
|
|
|
if (ParentObject != NULL)
|
|
|
|
{
|
|
|
|
ParentObject->RefCount--;
|
|
|
|
|
|
|
|
if (ParentObject->RefCount == 0)
|
|
|
|
Status = LsapCloseDbObject(ParentObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
2011-09-20 23:15:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
LsapSetObjectAttribute(PLSA_DB_OBJECT DbObject,
|
|
|
|
LPWSTR AttributeName,
|
|
|
|
LPVOID AttributeData,
|
|
|
|
ULONG AttributeSize)
|
|
|
|
{
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
UNICODE_STRING KeyName;
|
|
|
|
HANDLE AttributeKey;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
RtlInitUnicodeString(&KeyName,
|
|
|
|
AttributeName);
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&KeyName,
|
|
|
|
OBJ_CASE_INSENSITIVE,
|
|
|
|
DbObject->KeyHandle,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
Status = NtCreateKey(&AttributeKey,
|
|
|
|
KEY_SET_VALUE,
|
|
|
|
&ObjectAttributes,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
REG_OPTION_NON_VOLATILE,
|
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2014-01-14 20:24:43 +00:00
|
|
|
ERR("NtCreateKey failed for '%S' with status 0x%lx\n",
|
2013-03-10 13:43:13 +00:00
|
|
|
AttributeName, Status);
|
2011-09-20 23:15:51 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = RtlpNtSetValueKey(AttributeKey,
|
|
|
|
REG_NONE,
|
|
|
|
AttributeData,
|
|
|
|
AttributeSize);
|
|
|
|
|
|
|
|
NtClose(AttributeKey);
|
|
|
|
|
2013-03-10 13:43:13 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2014-01-14 20:24:43 +00:00
|
|
|
ERR("RtlpNtSetValueKey failed for '%S' with status 0x%lx\n",
|
2013-03-10 13:43:13 +00:00
|
|
|
AttributeName, Status);
|
|
|
|
}
|
|
|
|
|
2011-09-20 23:15:51 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
LsapGetObjectAttribute(PLSA_DB_OBJECT DbObject,
|
|
|
|
LPWSTR AttributeName,
|
|
|
|
LPVOID AttributeData,
|
|
|
|
PULONG AttributeSize)
|
|
|
|
{
|
|
|
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
|
|
|
UNICODE_STRING KeyName;
|
|
|
|
HANDLE AttributeKey;
|
|
|
|
ULONG ValueSize;
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
RtlInitUnicodeString(&KeyName,
|
|
|
|
AttributeName);
|
|
|
|
|
|
|
|
InitializeObjectAttributes(&ObjectAttributes,
|
|
|
|
&KeyName,
|
|
|
|
OBJ_CASE_INSENSITIVE,
|
|
|
|
DbObject->KeyHandle,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
Status = NtOpenKey(&AttributeKey,
|
|
|
|
KEY_QUERY_VALUE,
|
|
|
|
&ObjectAttributes);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
ValueSize = *AttributeSize;
|
|
|
|
Status = RtlpNtQueryValueKey(AttributeKey,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&ValueSize,
|
|
|
|
0);
|
|
|
|
if (!NT_SUCCESS(Status) && Status != STATUS_BUFFER_OVERFLOW)
|
|
|
|
{
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (AttributeData == NULL || *AttributeSize == 0)
|
|
|
|
{
|
|
|
|
*AttributeSize = ValueSize;
|
2012-01-07 17:45:26 +00:00
|
|
|
Status = STATUS_SUCCESS;
|
2011-09-20 23:15:51 +00:00
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
else if (*AttributeSize < ValueSize)
|
|
|
|
{
|
|
|
|
*AttributeSize = ValueSize;
|
2012-01-07 17:45:26 +00:00
|
|
|
Status = STATUS_BUFFER_OVERFLOW;
|
2011-09-20 23:15:51 +00:00
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = RtlpNtQueryValueKey(AttributeKey,
|
|
|
|
NULL,
|
|
|
|
AttributeData,
|
|
|
|
&ValueSize,
|
|
|
|
0);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
*AttributeSize = ValueSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
Done:
|
|
|
|
NtClose(AttributeKey);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2012-12-15 11:31:04 +00:00
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
LsapDeleteObjectAttribute(PLSA_DB_OBJECT DbObject,
|
|
|
|
LPWSTR AttributeName)
|
|
|
|
{
|
|
|
|
return LsapRegDeleteSubKey(DbObject->KeyHandle,
|
|
|
|
AttributeName);
|
|
|
|
}
|
|
|
|
|
2011-09-20 23:15:51 +00:00
|
|
|
/* EOF */
|
|
|
|
|