Author: ekohl
Date: Sun Feb 7 00:06:57 2010
New Revision: 45473
URL:
http://svn.reactos.org/svn/reactos?rev=45473&view=rev
Log:
Simplify the policy handle creation and destruction. This fixes two winetest failures.
Modified:
trunk/reactos/dll/win32/lsasrv/lsarpc.c
Modified: trunk/reactos/dll/win32/lsasrv/lsarpc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/lsasrv/lsarpc.c?…
==============================================================================
--- trunk/reactos/dll/win32/lsasrv/lsarpc.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/lsasrv/lsarpc.c [iso-8859-1] Sun Feb 7 00:06:57 2010
@@ -10,78 +10,69 @@
#include <wine/debug.h>
-#define POLICY_DELETE (RTL_HANDLE_VALID << 1)
-typedef struct _LSAR_POLICY_HANDLE
-{
- ULONG Flags;
+typedef struct _LSA_DB_HANDLE
+{
+ ULONG Signature;
+ ULONG Type;
LONG RefCount;
ACCESS_MASK AccessGranted;
-} LSAR_POLICY_HANDLE, *PLSAR_POLICY_HANDLE;
+} LSA_DB_HANDLE, *PLSA_DB_HANDLE;
+
+#define LSAP_DB_SIGNATURE 0x12345678
static RTL_CRITICAL_SECTION PolicyHandleTableLock;
-static RTL_HANDLE_TABLE PolicyHandleTable;
WINE_DEFAULT_DEBUG_CHANNEL(lsasrv);
+
/* FUNCTIONS ***************************************************************/
-static NTSTATUS
-ReferencePolicyHandle(
- IN LSA_HANDLE ObjectHandle,
- IN ACCESS_MASK DesiredAccess,
- OUT PLSAR_POLICY_HANDLE *Policy)
-{
- PLSAR_POLICY_HANDLE ReferencedPolicy;
- NTSTATUS Status = STATUS_SUCCESS;
-
- RtlEnterCriticalSection(&PolicyHandleTableLock);
-
- if (RtlIsValidIndexHandle(&PolicyHandleTable,
- HandleToUlong(ObjectHandle),
- (PRTL_HANDLE_TABLE_ENTRY*)&ReferencedPolicy)
&&
- !(ReferencedPolicy->Flags & POLICY_DELETE))
+static LSAPR_HANDLE
+LsapCreateDbHandle(ULONG Type)
+{
+ PLSA_DB_HANDLE DbHandle;
+
+// RtlEnterCriticalSection(&PolicyHandleTableLock);
+
+ DbHandle = (PLSA_DB_HANDLE)RtlAllocateHeap(RtlGetProcessHeap(),
+ 0,
+ sizeof(LSA_DB_HANDLE));
+ if (DbHandle != NULL)
{
- if (RtlAreAllAccessesGranted(ReferencedPolicy->AccessGranted,
- DesiredAccess))
- {
- ReferencedPolicy->RefCount++;
- *Policy = ReferencedPolicy;
- }
- else
- Status = STATUS_ACCESS_DENIED;
+ DbHandle->Signature = LSAP_DB_SIGNATURE;
+ DbHandle->RefCount = 1;
+ DbHandle->Type = Type;
}
- else
- Status = STATUS_INVALID_HANDLE;
-
- RtlLeaveCriticalSection(&PolicyHandleTableLock);
-
- return Status;
-}
-
-static VOID
-DereferencePolicyHandle(
- IN OUT PLSAR_POLICY_HANDLE Policy,
- IN BOOLEAN Delete)
-{
- RtlEnterCriticalSection(&PolicyHandleTableLock);
-
- if (Delete)
+
+// RtlLeaveCriticalSection(&PolicyHandleTableLock);
+
+ return (LSAPR_HANDLE)DbHandle;
+}
+
+
+static BOOL
+LsapValidateDbHandle(LSAPR_HANDLE Handle)
+{
+ PLSA_DB_HANDLE DbHandle = (PLSA_DB_HANDLE)Handle;
+ BOOL bValid = FALSE;
+
+ _SEH2_TRY
{
- Policy->Flags |= POLICY_DELETE;
- Policy->RefCount--;
-
- ASSERT(Policy->RefCount != 0);
+ if (DbHandle->Signature == LSAP_DB_SIGNATURE)
+ bValid = TRUE;
}
-
- if (--Policy->RefCount == 0)
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- ASSERT(Policy->Flags & POLICY_DELETE);
- RtlFreeHandle(&PolicyHandleTable,
- (PRTL_HANDLE_TABLE_ENTRY)Policy);
+ bValid = FALSE;
}
-
- RtlLeaveCriticalSection(&PolicyHandleTableLock);
-}
+ _SEH2_END;
+
+
+ return bValid;
+}
+
+
+
VOID
LsarStartRpcServer(VOID)
@@ -89,9 +80,6 @@
RPC_STATUS Status;
RtlInitializeCriticalSection(&PolicyHandleTableLock);
- RtlInitializeHandleTable(0x1000,
- sizeof(LSAR_POLICY_HANDLE),
- &PolicyHandleTable);
TRACE("LsarStartRpcServer() called");
@@ -135,29 +123,21 @@
NTSTATUS LsarClose(
LSAPR_HANDLE *ObjectHandle)
{
- PLSAR_POLICY_HANDLE Policy = NULL;
- NTSTATUS Status;
+ NTSTATUS Status = STATUS_SUCCESS;
TRACE("0x%p\n", ObjectHandle);
-#if 1
- /* This is our fake handle, don't go too much long way */
- if (*ObjectHandle == (LSA_HANDLE)0xcafe)
+// RtlEnterCriticalSection(&PolicyHandleTableLock);
+
+ if (LsapValidateDbHandle(*ObjectHandle))
{
+ RtlFreeHeap(RtlGetProcessHeap(), 0, *ObjectHandle);
*ObjectHandle = NULL;
- Status = STATUS_SUCCESS;
}
-#endif
-
- Status = ReferencePolicyHandle((LSA_HANDLE)*ObjectHandle,
- 0,
- &Policy);
- if (NT_SUCCESS(Status))
- {
- /* delete the handle */
- DereferencePolicyHandle(Policy,
- TRUE);
- }
+ else
+ Status = STATUS_INVALID_HANDLE;
+
+// RtlLeaveCriticalSection(&PolicyHandleTableLock);
return Status;
}
@@ -227,18 +207,21 @@
ACCESS_MASK DesiredAccess,
LSAPR_HANDLE *PolicyHandle)
{
-#if 1
+ NTSTATUS Status = STATUS_SUCCESS;
+
TRACE("LsarOpenPolicy called!\n");
- *PolicyHandle = (LSAPR_HANDLE)0xcafe;
+ RtlEnterCriticalSection(&PolicyHandleTableLock);
+
+ *PolicyHandle = LsapCreateDbHandle(0);
+ if (*PolicyHandle == NULL)
+ Status = STATUS_INSUFFICIENT_RESOURCES;
+
+ RtlLeaveCriticalSection(&PolicyHandleTableLock);
TRACE("LsarOpenPolicy done!\n");
- return STATUS_SUCCESS;
-#else
- UNIMPLEMENTED;
- return STATUS_NOT_IMPLEMENTED;
-#endif
+ return Status;
}