Author: ekohl
Date: Sun Sep 29 08:53:24 2013
New Revision: 60443
URL:
http://svn.reactos.org/svn/reactos?rev=60443&view=rev
Log:
[SAMSRV]
SamrDeleteAlias: Remove all members from an alias before it will be deleted.
Modified:
trunk/reactos/dll/win32/samsrv/alias.c
trunk/reactos/dll/win32/samsrv/samrpc.c
trunk/reactos/dll/win32/samsrv/samsrv.h
Modified: trunk/reactos/dll/win32/samsrv/alias.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/samsrv/alias.c?r…
==============================================================================
--- trunk/reactos/dll/win32/samsrv/alias.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/samsrv/alias.c [iso-8859-1] Sun Sep 29 08:53:24 2013
@@ -218,4 +218,159 @@
return Status;
}
+
+NTSTATUS
+SampGetMembersInAlias(IN PSAM_DB_OBJECT AliasObject,
+ OUT PULONG MemberCount,
+ OUT PSAMPR_SID_INFORMATION *MemberArray)
+{
+ HANDLE MembersKeyHandle = NULL;
+ PSAMPR_SID_INFORMATION Members = NULL;
+ ULONG Count = 0;
+ ULONG DataLength;
+ ULONG Index;
+ NTSTATUS Status;
+
+ /* Open the members key of the alias object */
+ Status = SampRegOpenKey(AliasObject->KeyHandle,
+ L"Members",
+ KEY_READ,
+ &MembersKeyHandle);
+ if (!NT_SUCCESS(Status))
+ {
+ ERR("SampRegOpenKey failed with status 0x%08lx\n", Status);
+ goto done;
+ }
+
+ /* Get the number of members */
+ Status = SampRegQueryKeyInfo(MembersKeyHandle,
+ NULL,
+ &Count);
+ if (!NT_SUCCESS(Status))
+ {
+ ERR("SampRegQueryKeyInfo failed with status 0x%08lx\n", Status);
+ goto done;
+ }
+
+ /* Allocate the member array */
+ Members = midl_user_allocate(Count * sizeof(SAMPR_SID_INFORMATION));
+ if (Members == NULL)
+ {
+ Status = STATUS_INSUFFICIENT_RESOURCES;
+ goto done;
+ }
+
+ /* Enumerate the members */
+ Index = 0;
+ while (TRUE)
+ {
+ /* Get the size of the next SID */
+ DataLength = 0;
+ Status = SampRegEnumerateValue(MembersKeyHandle,
+ Index,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ &DataLength);
+ if (!NT_SUCCESS(Status))
+ {
+ if (Status == STATUS_NO_MORE_ENTRIES)
+ Status = STATUS_SUCCESS;
+ break;
+ }
+
+ /* Allocate a buffer for the SID */
+ Members[Index].SidPointer = midl_user_allocate(DataLength);
+ if (Members[Index].SidPointer == NULL)
+ {
+ Status = STATUS_INSUFFICIENT_RESOURCES;
+ goto done;
+ }
+
+ /* Read the SID into the buffer */
+ Status = SampRegEnumerateValue(MembersKeyHandle,
+ Index,
+ NULL,
+ NULL,
+ NULL,
+ (PVOID)Members[Index].SidPointer,
+ &DataLength);
+ if (!NT_SUCCESS(Status))
+ {
+ goto done;
+ }
+
+ Index++;
+ }
+
+ if (NT_SUCCESS(Status))
+ {
+ *MemberCount = Count;
+ *MemberArray = Members;
+ }
+
+done:
+ return Status;
+}
+
+
+NTSTATUS
+SampRemoveAllMembersFromAlias(IN PSAM_DB_OBJECT AliasObject)
+{
+ HANDLE MembersKeyHandle = NULL;
+ PSAMPR_SID_INFORMATION MemberArray = NULL;
+ ULONG MemberCount = 0;
+ ULONG Index;
+ NTSTATUS Status;
+
+ TRACE("(%p)\n", AliasObject);
+
+ /* Open the members key of the alias object */
+ Status = SampRegOpenKey(AliasObject->KeyHandle,
+ L"Members",
+ KEY_READ,
+ &MembersKeyHandle);
+ if (!NT_SUCCESS(Status))
+ {
+ ERR("SampRegOpenKey failed (Status 0x%08lx)\n", Status);
+ goto done;
+ }
+
+ /* Get a list of all members of the alias */
+ Status = SampGetMembersInAlias(AliasObject,
+ &MemberCount,
+ &MemberArray);
+ if (!NT_SUCCESS(Status))
+ {
+ ERR("SampGetMembersInAlias failed (Status 0x%08lx)\n", Status);
+ goto done;
+ }
+
+ /* Remove all members from the alias */
+ for (Index = 0; Index < MemberCount; Index++)
+ {
+ Status = SampRemoveMemberFromAlias(AliasObject,
+ MemberArray[Index].SidPointer);
+ if (!NT_SUCCESS(Status))
+ goto done;
+ }
+
+done:
+ if (MemberArray != NULL)
+ {
+ for (Index = 0; Index < MemberCount; Index++)
+ {
+ if (MemberArray[Index].SidPointer != NULL)
+ midl_user_free(MemberArray[Index].SidPointer);
+ }
+
+ midl_user_free(MemberArray);
+ }
+
+ SampRegCloseKey(&MembersKeyHandle);
+
+ return Status;
+}
+
/* EOF */
Modified: trunk/reactos/dll/win32/samsrv/samrpc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/samsrv/samrpc.c?…
==============================================================================
--- trunk/reactos/dll/win32/samsrv/samrpc.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/samsrv/samrpc.c [iso-8859-1] Sun Sep 29 08:53:24 2013
@@ -4980,7 +4980,13 @@
goto done;
}
- /* FIXME: Remove all members from the alias */
+ /* Remove all members from the alias */
+ Status = SampRemoveAllMembersFromAlias(AliasObject);
+ if (!NT_SUCCESS(Status))
+ {
+ TRACE("SampRemoveAllMembersFromAlias() failed (Status 0x%08lx)\n",
Status);
+ goto done;
+ }
/* Delete the alias from the database */
Status = SampDeleteAccountDbObject(AliasObject);
@@ -5085,10 +5091,8 @@
OUT PSAMPR_PSID_ARRAY_OUT Members)
{
PSAM_DB_OBJECT AliasObject;
- HANDLE MembersKeyHandle = NULL;
PSAMPR_SID_INFORMATION MemberArray = NULL;
- ULONG ValueCount = 0;
- ULONG DataLength;
+ ULONG MemberCount = 0;
ULONG Index;
NTSTATUS Status;
@@ -5109,83 +5113,14 @@
goto done;
}
- /* Open the members key of the alias objct */
- Status = SampRegOpenKey(AliasObject->KeyHandle,
- L"Members",
- KEY_READ,
- &MembersKeyHandle);
- if (!NT_SUCCESS(Status))
- {
- ERR("SampRegOpenKey failed with status 0x%08lx\n", Status);
- goto done;
- }
-
- /* Get the number of members */
- Status = SampRegQueryKeyInfo(MembersKeyHandle,
- NULL,
- &ValueCount);
- if (!NT_SUCCESS(Status))
- {
- ERR("SampRegQueryKeyInfo failed with status 0x%08lx\n", Status);
- goto done;
- }
-
- /* Allocate the member array */
- MemberArray = midl_user_allocate(ValueCount * sizeof(SAMPR_SID_INFORMATION));
- if (MemberArray == NULL)
- {
- Status = STATUS_INSUFFICIENT_RESOURCES;
- goto done;
- }
-
- /* Enumerate the members */
- Index = 0;
- while (TRUE)
- {
- /* Get the size of the next SID */
- DataLength = 0;
- Status = SampRegEnumerateValue(MembersKeyHandle,
- Index,
- NULL,
- NULL,
- NULL,
- NULL,
- &DataLength);
- if (!NT_SUCCESS(Status))
- {
- if (Status == STATUS_NO_MORE_ENTRIES)
- Status = STATUS_SUCCESS;
- break;
- }
-
- /* Allocate a buffer for the SID */
- MemberArray[Index].SidPointer = midl_user_allocate(DataLength);
- if (MemberArray[Index].SidPointer == NULL)
- {
- Status = STATUS_INSUFFICIENT_RESOURCES;
- goto done;
- }
-
- /* Read the SID into the buffer */
- Status = SampRegEnumerateValue(MembersKeyHandle,
- Index,
- NULL,
- NULL,
- NULL,
- (PVOID)MemberArray[Index].SidPointer,
- &DataLength);
- if (!NT_SUCCESS(Status))
- {
- goto done;
- }
-
- Index++;
- }
+ Status = SampGetMembersInAlias(AliasObject,
+ &MemberCount,
+ &MemberArray);
/* Return the number of members and the member array */
if (NT_SUCCESS(Status))
{
- Members->Count = ValueCount;
+ Members->Count = MemberCount;
Members->Sids = MemberArray;
}
@@ -5195,7 +5130,7 @@
{
if (MemberArray != NULL)
{
- for (Index = 0; Index < ValueCount; Index++)
+ for (Index = 0; Index < MemberCount; Index++)
{
if (MemberArray[Index].SidPointer != NULL)
midl_user_free(MemberArray[Index].SidPointer);
@@ -5204,9 +5139,6 @@
midl_user_free(MemberArray);
}
}
-
- /* Close the members key */
- SampRegCloseKey(&MembersKeyHandle);
RtlReleaseResource(&SampResource);
Modified: trunk/reactos/dll/win32/samsrv/samsrv.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/samsrv/samsrv.h?…
==============================================================================
--- trunk/reactos/dll/win32/samsrv/samsrv.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/samsrv/samsrv.h [iso-8859-1] Sun Sep 29 08:53:24 2013
@@ -141,6 +141,14 @@
SampRemoveMemberFromAlias(IN PSAM_DB_OBJECT AliasObject,
IN PRPC_SID MemberId);
+NTSTATUS
+SampGetMembersInAlias(IN PSAM_DB_OBJECT AliasObject,
+ OUT PULONG MemberCount,
+ OUT PSAMPR_SID_INFORMATION *MemberArray);
+
+NTSTATUS
+SampRemoveAllMembersFromAlias(IN PSAM_DB_OBJECT AliasObject);
+
/* database.c */