From 3ba8c1dc0b0ca0ad8167e44ec69d96f2d71b38ae Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sun, 25 Nov 2012 19:47:54 +0000 Subject: [PATCH] [LSASRV] - Implement LsarDeleteObject. - Store the object name in the database object in order to be able to delete the objects key later. svn path=/trunk/; revision=57769 --- reactos/dll/win32/lsasrv/database.c | 66 ++++++++++++++++++++++++++++- reactos/dll/win32/lsasrv/lsarpc.c | 37 +++++++++++++++- reactos/dll/win32/lsasrv/lsasrv.h | 4 ++ 3 files changed, 104 insertions(+), 3 deletions(-) diff --git a/reactos/dll/win32/lsasrv/database.c b/reactos/dll/win32/lsasrv/database.c index 9303636a3f4..ba278288ea8 100644 --- a/reactos/dll/win32/lsasrv/database.c +++ b/reactos/dll/win32/lsasrv/database.c @@ -796,7 +796,7 @@ LsapOpenDbObject(IN PLSA_DB_OBJECT ParentObject, NewObject = RtlAllocateHeap(RtlGetProcessHeap(), 0, - sizeof(LSA_DB_OBJECT)); + sizeof(LSA_DB_OBJECT) + wcslen(ObjectName) + sizeof(WCHAR)); if (NewObject == NULL) { NtClose(ObjectKeyHandle); @@ -809,6 +809,7 @@ LsapOpenDbObject(IN PLSA_DB_OBJECT ParentObject, NewObject->Access = DesiredAccess; NewObject->KeyHandle = ObjectKeyHandle; NewObject->ParentObject = ParentObject; + wcscpy(NewObject->Name, ObjectName); if (ParentObject != NULL) ParentObject->RefCount++; @@ -895,6 +896,69 @@ LsapCloseDbObject(PLSA_DB_OBJECT DbObject) } +NTSTATUS +LsapDeleteDbObject(IN PLSA_DB_OBJECT DbObject) +{ + PLSA_DB_OBJECT ParentObject = NULL; + WCHAR KeyName[64]; + ULONG EnumIndex; + + NTSTATUS Status = STATUS_SUCCESS; + + DbObject->RefCount--; + + if (DbObject->RefCount > 0) + return STATUS_SUCCESS; + + if (DbObject->KeyHandle != NULL) + { + EnumIndex = 0; + + while (TRUE) + { + Status = LsapRegEnumerateSubKey(DbObject->KeyHandle, + EnumIndex, + 64 * sizeof(WCHAR), + KeyName); + if (!NT_SUCCESS(Status)) + break; + + TRACE("EnumIndex: %lu\n", EnumIndex); + TRACE("Key name: %S\n", KeyName); + + Status = LsapRegDeleteKey(DbObject->KeyHandle, + KeyName); + if (!NT_SUCCESS(Status)) + break; + +// EnumIndex++; + } + + NtClose(DbObject->KeyHandle); + } + + if (DbObject->ParentObject != NULL) + { + ParentObject = DbObject->ParentObject; + + LsapRegDeleteKey(ParentObject->KeyHandle, + DbObject->Name); + } + + RtlFreeHeap(RtlGetProcessHeap(), 0, DbObject); + + if (ParentObject != NULL) + { + ParentObject->RefCount--; + + if (ParentObject->RefCount == 0) + Status = LsapCloseDbObject(ParentObject); + } + + return Status; +} + + NTSTATUS LsapSetObjectAttribute(PLSA_DB_OBJECT DbObject, LPWSTR AttributeName, diff --git a/reactos/dll/win32/lsasrv/lsarpc.c b/reactos/dll/win32/lsasrv/lsarpc.c index 0d91ee090a6..67375f0156b 100644 --- a/reactos/dll/win32/lsasrv/lsarpc.c +++ b/reactos/dll/win32/lsasrv/lsarpc.c @@ -1968,8 +1968,41 @@ NTSTATUS WINAPI LsarLookupPrivilegeDisplayName( NTSTATUS WINAPI LsarDeleteObject( LSAPR_HANDLE *ObjectHandle) { - UNIMPLEMENTED; - return STATUS_NOT_IMPLEMENTED; + PLSA_DB_OBJECT DbObject; + NTSTATUS Status; + + TRACE("(%p)\n", ObjectHandle); + + if (ObjectHandle == NULL) + return STATUS_INVALID_PARAMETER; + + /* Validate the ObjectHandle */ + Status = LsapValidateDbObject(*ObjectHandle, + LsaDbIgnoreObject, + DELETE, + &DbObject); + if (!NT_SUCCESS(Status)) + { + ERR("LsapValidateDbObject returned 0x%08lx\n", Status); + return Status; + } + + /* You cannot delete the policy object */ + if (DbObject->ObjectType == LsaDbPolicyObject) + return STATUS_INVALID_PARAMETER; + + /* Delete the database object */ + Status = LsapDeleteDbObject(DbObject); + if (!NT_SUCCESS(Status)) + { + ERR("LsapDeleteDbObject returned 0x%08lx\n", Status); + return Status; + } + + /* Invalidate the object handle */ + *ObjectHandle = NULL; + + return STATUS_SUCCESS; } diff --git a/reactos/dll/win32/lsasrv/lsasrv.h b/reactos/dll/win32/lsasrv/lsasrv.h index e8182441c9e..33af276382f 100644 --- a/reactos/dll/win32/lsasrv/lsasrv.h +++ b/reactos/dll/win32/lsasrv/lsasrv.h @@ -48,6 +48,7 @@ typedef struct _LSA_DB_OBJECT ACCESS_MASK Access; HANDLE KeyHandle; struct _LSA_DB_OBJECT *ParentObject; + WCHAR Name[0]; } LSA_DB_OBJECT, *PLSA_DB_OBJECT; #define LSAP_DB_SIGNATURE 0x12345678 @@ -106,6 +107,9 @@ LsapValidateDbObject(IN LSAPR_HANDLE Handle, NTSTATUS LsapCloseDbObject(IN PLSA_DB_OBJECT DbObject); +NTSTATUS +LsapDeleteDbObject(IN PLSA_DB_OBJECT DbObject); + NTSTATUS LsapGetObjectAttribute(PLSA_DB_OBJECT DbObject, LPWSTR AttributeName,