https://git.reactos.org/?p=reactos.git;a=commitdiff;h=fb8edf90a002cefd0d99a…
commit fb8edf90a002cefd0d99adb4316f12e6d6840418
Author: Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Sun Jul 4 12:45:19 2021 +0200
Commit: Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Sun Jul 4 12:45:19 2021 +0200
[SAMSRV] Start work on the display cache
Initialize the cache and fill it on demand
---
dll/win32/samsrv/CMakeLists.txt | 1 +
dll/win32/samsrv/display.c | 202 ++++++++++++++++++++++++++++++++++++++++
dll/win32/samsrv/samrpc.c | 41 +++++++-
dll/win32/samsrv/samsrv.c | 4 +
dll/win32/samsrv/samsrv.h | 18 ++++
5 files changed, 264 insertions(+), 2 deletions(-)
diff --git a/dll/win32/samsrv/CMakeLists.txt b/dll/win32/samsrv/CMakeLists.txt
index f3303d61eed..c62b0cf2bf7 100644
--- a/dll/win32/samsrv/CMakeLists.txt
+++ b/dll/win32/samsrv/CMakeLists.txt
@@ -9,6 +9,7 @@ spec2def(samsrv.dll samsrv.spec ADD_IMPORTLIB)
list(APPEND SOURCE
alias.c
database.c
+ display.c
domain.c
group.c
registry.c
diff --git a/dll/win32/samsrv/display.c b/dll/win32/samsrv/display.c
new file mode 100644
index 00000000000..3a5087dade5
--- /dev/null
+++ b/dll/win32/samsrv/display.c
@@ -0,0 +1,202 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: Security Account Manager (SAM) Server
+ * FILE: reactos/dll/win32/samsrv/display.c
+ * PURPOSE: Display cache
+ *
+ * PROGRAMMERS: Eric Kohl
+ */
+
+#include "samsrv.h"
+
+#include <winuser.h>
+
+/* GLOBALS *****************************************************************/
+
+typedef struct _USER_ENTRY
+{
+ LIST_ENTRY ListEntry;
+ SAMPR_DOMAIN_DISPLAY_USER User;
+} USER_ENTRY, *PUSER_ENTRY;
+
+
+static LIST_ENTRY UserListHead;
+static BOOLEAN UserListFilled = FALSE;
+static ULONG UserListCount = 0;
+
+//static LIST_HEAD MachineListHead;
+//static LIST_HEAD GroupListHead;
+
+
+
+/* FUNCTIONS ***************************************************************/
+
+static
+NTSTATUS
+SampFillUserDisplayCache(
+ _In_ PSAM_DB_OBJECT DomainObject)
+{
+ HANDLE UsersKeyHandle = NULL;
+ WCHAR UserKeyName[64];
+ ULONG EnumIndex;
+ ULONG NameLength;
+ ULONG Rid;
+ PSAM_DB_OBJECT UserObject;
+ SAM_USER_FIXED_DATA FixedUserData;
+ ULONG Size;
+ ULONG DataType;
+ PUSER_ENTRY UserEntry;
+ NTSTATUS Status;
+
+ FIXME("SampFillUserDisplayCache(%p)\n", DomainObject);
+
+ if (UserListFilled)
+ {
+ FIXME("Already filled!\n");
+ return STATUS_SUCCESS;
+ }
+
+ Status = SampRegOpenKey(DomainObject->KeyHandle,
+ L"Users",
+ KEY_ALL_ACCESS, /* FIXME */
+ &UsersKeyHandle);
+ if (!NT_SUCCESS(Status))
+ goto done;
+
+ for (EnumIndex = 0; ; EnumIndex++)
+ {
+ FIXME("EnumIndex: %lu\n", EnumIndex);
+ NameLength = 64 * sizeof(WCHAR);
+ Status = SampRegEnumerateSubKey(UsersKeyHandle,
+ EnumIndex,
+ NameLength,
+ UserKeyName);
+ if (!NT_SUCCESS(Status))
+ {
+ if (Status == STATUS_NO_MORE_ENTRIES)
+ Status = STATUS_SUCCESS;
+ break;
+ }
+
+ FIXME("User name: %S\n", UserKeyName);
+ FIXME("Name length: %lu\n", NameLength);
+
+ Rid = wcstoul(UserKeyName, NULL, 16);
+ if (Rid == 0 || Rid == ULONG_MAX)
+ continue;
+
+ FIXME("Rid: 0x%lx\n", Rid);
+ Status = SampOpenDbObject(DomainObject,
+ L"Users",
+ UserKeyName,
+ Rid,
+ SamDbUserObject,
+ 0,
+ &UserObject);
+ if (NT_SUCCESS(Status))
+ {
+ Size = sizeof(SAM_USER_FIXED_DATA);
+ Status = SampGetObjectAttribute(UserObject,
+ L"F",
+ &DataType,
+ (LPVOID)&FixedUserData,
+ &Size);
+ if (NT_SUCCESS(Status))
+ {
+ FIXME("Account control: 0x%lx\n",
FixedUserData.UserAccountControl);
+
+ if (FixedUserData.UserAccountControl & USER_NORMAL_ACCOUNT)
+ {
+ UserEntry = RtlAllocateHeap(RtlGetProcessHeap(),
+ HEAP_ZERO_MEMORY,
+ sizeof(USER_ENTRY));
+ if (UserEntry != NULL)
+ {
+
+ UserEntry->User.Rid = Rid;
+ UserEntry->User.AccountControl =
FixedUserData.UserAccountControl;
+
+ /* FIXME: Add remaining attributes */
+
+ InsertTailList(&UserListHead, &UserEntry->ListEntry);
+ UserListCount++;
+ }
+ }
+ }
+
+ SampCloseDbObject(UserObject);
+ }
+ }
+
+done:
+ if (Status == STATUS_SUCCESS)
+ UserListFilled = TRUE;
+
+ FIXME("SampFillUserDisplayCache() done (Status 0x%08lx)\n", Status);
+
+ return Status;
+}
+
+
+
+NTSTATUS
+SampInitializeDisplayCache(VOID)
+{
+ TRACE("SampInitializeDisplayCache()\n");
+
+ InitializeListHead(&UserListHead);
+ UserListFilled = FALSE;
+ UserListCount = 0;
+
+// InitializeListHead(&MachineListHead);
+// MachineListFilled = FALSE;
+// MachineListCount = 0;
+
+// InitializeListHead(&GroupListHead);
+// GroupListFilled = FALSE;
+// GroupListCount = 0;
+
+ return STATUS_SUCCESS;
+}
+
+
+NTSTATUS
+SampShutdownDisplayCache(VOID)
+{
+ TRACE("SampShutdownDisplayCache()\n");
+ return STATUS_SUCCESS;
+}
+
+
+NTSTATUS
+SampFillDisplayCache(
+ _In_ PSAM_DB_OBJECT DomainObject,
+ _In_ DOMAIN_DISPLAY_INFORMATION DisplayInformationClass)
+{
+ NTSTATUS Status;
+
+ TRACE("SampFillDisplayCache()\n");
+
+ switch (DisplayInformationClass)
+ {
+ case DomainDisplayUser:
+ Status = SampFillUserDisplayCache(DomainObject);
+ break;
+/*
+ case DomainDisplayMachine:
+ Status = SampFillMachineDisplayCache(DomainObject);
+ break;
+
+ case DomainDisplayGroup:
+ Status = SampFillGroupDisplayCache(DomainObject);
+ break;
+*/
+ default:
+ Status = STATUS_INVALID_INFO_CLASS;
+ break;
+ }
+
+ return Status;
+}
+
+/* EOF */
diff --git a/dll/win32/samsrv/samrpc.c b/dll/win32/samsrv/samrpc.c
index 518ac75e0b5..a693324f1d3 100644
--- a/dll/win32/samsrv/samrpc.c
+++ b/dll/win32/samsrv/samrpc.c
@@ -125,6 +125,7 @@ void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
void __RPC_USER SAMPR_HANDLE_rundown(SAMPR_HANDLE hHandle)
{
+ FIXME("SAMPR_HANDLE_rundown(%p)\n", hHandle);
}
@@ -487,6 +488,12 @@ SamrShutdownSamServer(IN SAMPR_HANDLE ServerHandle)
/* Shut the server down */
RpcMgmtStopServerListening(0);
+ Status = SampShutdownDisplayCache();
+ if (!NT_SUCCESS(Status))
+ {
+ ERR("SampShutdownDisplayCache() failed (Status 0x%08lx)\n", Status);
+ }
+
return STATUS_SUCCESS;
}
@@ -9428,12 +9435,42 @@ SamrQueryDisplayInformation3(IN SAMPR_HANDLE DomainHandle,
OUT unsigned long *TotalReturned,
OUT PSAMPR_DISPLAY_INFO_BUFFER Buffer)
{
- TRACE("SamrQueryDisplayInformation3(%p %lu %lu %lu %lu %p %p %p)\n",
+ PSAM_DB_OBJECT DomainObject;
+ NTSTATUS Status;
+
+ FIXME("SamrQueryDisplayInformation3(%p %lu %lu %lu %lu %p %p %p)\n",
DomainHandle, DisplayInformationClass, Index,
EntryCount, PreferredMaximumLength, TotalAvailable,
TotalReturned, Buffer);
- UNIMPLEMENTED;
+ RtlAcquireResourceShared(&SampResource,
+ TRUE);
+
+ /* Validate the domain handle */
+ Status = SampValidateDbObject(DomainHandle,
+ SamDbDomainObject,
+ DOMAIN_LIST_ACCOUNTS,
+ &DomainObject);
+ if (!NT_SUCCESS(Status))
+ {
+ ERR("SampValidateDbObject() failed (Status 0x%08lx)\n", Status);
+ goto done;
+ }
+
+ Status = SampFillDisplayCache(DomainObject,
+ DisplayInformationClass);
+ if (!NT_SUCCESS(Status))
+ {
+ ERR("SampFillDisplayCache() failed (Status 0x%08lx)\n", Status);
+ goto done;
+ }
+
+done:
+ TRACE("returns with status 0x%08lx\n", Status);
+
+ RtlReleaseResource(&SampResource);
+
+// return Status;
return STATUS_NOT_IMPLEMENTED;
}
diff --git a/dll/win32/samsrv/samsrv.c b/dll/win32/samsrv/samsrv.c
index 5e4fd9d96f3..57aa5fb6bb7 100644
--- a/dll/win32/samsrv/samsrv.c
+++ b/dll/win32/samsrv/samsrv.c
@@ -120,6 +120,10 @@ SamIInitialize(VOID)
return Status;
}
+ Status = SampInitializeDisplayCache();
+ if (!NT_SUCCESS(Status))
+ return Status;
+
RtlInitializeResource(&SampResource);
/* Initialize the SAM database */
diff --git a/dll/win32/samsrv/samsrv.h b/dll/win32/samsrv/samsrv.h
index e16308c9338..0211e4ebf18 100644
--- a/dll/win32/samsrv/samsrv.h
+++ b/dll/win32/samsrv/samsrv.h
@@ -122,6 +122,7 @@ extern ENCRYPTED_LM_OWF_PASSWORD EmptyLmHash;
extern RTL_RESOURCE SampResource;
extern NT_PRODUCT_TYPE SampProductType;
+
/* alias.c */
NTSTATUS
@@ -207,6 +208,21 @@ SampSetObjectAttributeString(PSAM_DB_OBJECT DbObject,
LPWSTR AttributeName,
PRPC_UNICODE_STRING String);
+
+/* display.c */
+
+NTSTATUS
+SampInitializeDisplayCache(VOID);
+
+NTSTATUS
+SampShutdownDisplayCache(VOID);
+
+NTSTATUS
+SampFillDisplayCache(
+ _In_ PSAM_DB_OBJECT DomainObject,
+ _In_ DOMAIN_DISPLAY_INFORMATION DisplayInformationClass);
+
+
/* domain.c */
NTSTATUS
@@ -233,6 +249,7 @@ SampCreateAccountSid(IN PSAM_DB_OBJECT DomainObject,
IN ULONG ulRelativeId,
IN OUT PSID *AccountSid);
+
/* group.h */
NTSTATUS
@@ -343,6 +360,7 @@ SampCreateUserSD(IN PSID UserSid,
OUT PSECURITY_DESCRIPTOR *UserSd,
OUT PULONG Size);
+
/* setup.c */
BOOL