mirror of
https://github.com/reactos/reactos.git
synced 2025-01-02 20:43:18 +00:00
Simplify the policy handle creation and destruction. This fixes two winetest failures.
svn path=/trunk/; revision=45473
This commit is contained in:
parent
28dd879706
commit
534f9adf45
1 changed files with 55 additions and 72 deletions
|
@ -10,88 +10,76 @@
|
||||||
|
|
||||||
#include <wine/debug.h>
|
#include <wine/debug.h>
|
||||||
|
|
||||||
#define POLICY_DELETE (RTL_HANDLE_VALID << 1)
|
typedef struct _LSA_DB_HANDLE
|
||||||
typedef struct _LSAR_POLICY_HANDLE
|
|
||||||
{
|
{
|
||||||
ULONG Flags;
|
ULONG Signature;
|
||||||
|
ULONG Type;
|
||||||
LONG RefCount;
|
LONG RefCount;
|
||||||
ACCESS_MASK AccessGranted;
|
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_CRITICAL_SECTION PolicyHandleTableLock;
|
||||||
static RTL_HANDLE_TABLE PolicyHandleTable;
|
|
||||||
|
|
||||||
WINE_DEFAULT_DEBUG_CHANNEL(lsasrv);
|
WINE_DEFAULT_DEBUG_CHANNEL(lsasrv);
|
||||||
|
|
||||||
|
|
||||||
/* FUNCTIONS ***************************************************************/
|
/* FUNCTIONS ***************************************************************/
|
||||||
|
|
||||||
static NTSTATUS
|
static LSAPR_HANDLE
|
||||||
ReferencePolicyHandle(
|
LsapCreateDbHandle(ULONG Type)
|
||||||
IN LSA_HANDLE ObjectHandle,
|
|
||||||
IN ACCESS_MASK DesiredAccess,
|
|
||||||
OUT PLSAR_POLICY_HANDLE *Policy)
|
|
||||||
{
|
{
|
||||||
PLSAR_POLICY_HANDLE ReferencedPolicy;
|
PLSA_DB_HANDLE DbHandle;
|
||||||
NTSTATUS Status = STATUS_SUCCESS;
|
|
||||||
|
|
||||||
RtlEnterCriticalSection(&PolicyHandleTableLock);
|
// RtlEnterCriticalSection(&PolicyHandleTableLock);
|
||||||
|
|
||||||
if (RtlIsValidIndexHandle(&PolicyHandleTable,
|
DbHandle = (PLSA_DB_HANDLE)RtlAllocateHeap(RtlGetProcessHeap(),
|
||||||
HandleToUlong(ObjectHandle),
|
0,
|
||||||
(PRTL_HANDLE_TABLE_ENTRY*)&ReferencedPolicy) &&
|
sizeof(LSA_DB_HANDLE));
|
||||||
!(ReferencedPolicy->Flags & POLICY_DELETE))
|
if (DbHandle != NULL)
|
||||||
{
|
{
|
||||||
if (RtlAreAllAccessesGranted(ReferencedPolicy->AccessGranted,
|
DbHandle->Signature = LSAP_DB_SIGNATURE;
|
||||||
DesiredAccess))
|
DbHandle->RefCount = 1;
|
||||||
{
|
DbHandle->Type = Type;
|
||||||
ReferencedPolicy->RefCount++;
|
|
||||||
*Policy = ReferencedPolicy;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
Status = STATUS_ACCESS_DENIED;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
Status = STATUS_INVALID_HANDLE;
|
|
||||||
|
|
||||||
RtlLeaveCriticalSection(&PolicyHandleTableLock);
|
// RtlLeaveCriticalSection(&PolicyHandleTableLock);
|
||||||
|
|
||||||
return Status;
|
return (LSAPR_HANDLE)DbHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VOID
|
|
||||||
DereferencePolicyHandle(
|
static BOOL
|
||||||
IN OUT PLSAR_POLICY_HANDLE Policy,
|
LsapValidateDbHandle(LSAPR_HANDLE Handle)
|
||||||
IN BOOLEAN Delete)
|
|
||||||
{
|
{
|
||||||
RtlEnterCriticalSection(&PolicyHandleTableLock);
|
PLSA_DB_HANDLE DbHandle = (PLSA_DB_HANDLE)Handle;
|
||||||
|
BOOL bValid = FALSE;
|
||||||
|
|
||||||
if (Delete)
|
_SEH2_TRY
|
||||||
{
|
{
|
||||||
Policy->Flags |= POLICY_DELETE;
|
if (DbHandle->Signature == LSAP_DB_SIGNATURE)
|
||||||
Policy->RefCount--;
|
bValid = TRUE;
|
||||||
|
|
||||||
ASSERT(Policy->RefCount != 0);
|
|
||||||
}
|
}
|
||||||
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
||||||
if (--Policy->RefCount == 0)
|
|
||||||
{
|
{
|
||||||
ASSERT(Policy->Flags & POLICY_DELETE);
|
bValid = FALSE;
|
||||||
RtlFreeHandle(&PolicyHandleTable,
|
|
||||||
(PRTL_HANDLE_TABLE_ENTRY)Policy);
|
|
||||||
}
|
}
|
||||||
|
_SEH2_END;
|
||||||
|
|
||||||
RtlLeaveCriticalSection(&PolicyHandleTableLock);
|
|
||||||
|
return bValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
LsarStartRpcServer(VOID)
|
LsarStartRpcServer(VOID)
|
||||||
{
|
{
|
||||||
RPC_STATUS Status;
|
RPC_STATUS Status;
|
||||||
|
|
||||||
RtlInitializeCriticalSection(&PolicyHandleTableLock);
|
RtlInitializeCriticalSection(&PolicyHandleTableLock);
|
||||||
RtlInitializeHandleTable(0x1000,
|
|
||||||
sizeof(LSAR_POLICY_HANDLE),
|
|
||||||
&PolicyHandleTable);
|
|
||||||
|
|
||||||
TRACE("LsarStartRpcServer() called");
|
TRACE("LsarStartRpcServer() called");
|
||||||
|
|
||||||
|
@ -135,29 +123,21 @@ void __RPC_USER LSAPR_HANDLE_rundown(LSAPR_HANDLE hHandle)
|
||||||
NTSTATUS LsarClose(
|
NTSTATUS LsarClose(
|
||||||
LSAPR_HANDLE *ObjectHandle)
|
LSAPR_HANDLE *ObjectHandle)
|
||||||
{
|
{
|
||||||
PLSAR_POLICY_HANDLE Policy = NULL;
|
NTSTATUS Status = STATUS_SUCCESS;
|
||||||
NTSTATUS Status;
|
|
||||||
|
|
||||||
TRACE("0x%p\n", ObjectHandle);
|
TRACE("0x%p\n", ObjectHandle);
|
||||||
|
|
||||||
#if 1
|
// RtlEnterCriticalSection(&PolicyHandleTableLock);
|
||||||
/* This is our fake handle, don't go too much long way */
|
|
||||||
if (*ObjectHandle == (LSA_HANDLE)0xcafe)
|
|
||||||
{
|
|
||||||
*ObjectHandle = NULL;
|
|
||||||
Status = STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Status = ReferencePolicyHandle((LSA_HANDLE)*ObjectHandle,
|
if (LsapValidateDbHandle(*ObjectHandle))
|
||||||
0,
|
|
||||||
&Policy);
|
|
||||||
if (NT_SUCCESS(Status))
|
|
||||||
{
|
{
|
||||||
/* delete the handle */
|
RtlFreeHeap(RtlGetProcessHeap(), 0, *ObjectHandle);
|
||||||
DereferencePolicyHandle(Policy,
|
*ObjectHandle = NULL;
|
||||||
TRUE);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
Status = STATUS_INVALID_HANDLE;
|
||||||
|
|
||||||
|
// RtlLeaveCriticalSection(&PolicyHandleTableLock);
|
||||||
|
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
@ -227,18 +207,21 @@ NTSTATUS LsarOpenPolicy(
|
||||||
ACCESS_MASK DesiredAccess,
|
ACCESS_MASK DesiredAccess,
|
||||||
LSAPR_HANDLE *PolicyHandle)
|
LSAPR_HANDLE *PolicyHandle)
|
||||||
{
|
{
|
||||||
#if 1
|
NTSTATUS Status = STATUS_SUCCESS;
|
||||||
|
|
||||||
TRACE("LsarOpenPolicy called!\n");
|
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");
|
TRACE("LsarOpenPolicy done!\n");
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
return Status;
|
||||||
#else
|
|
||||||
UNIMPLEMENTED;
|
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue