mirror of
https://github.com/reactos/reactos.git
synced 2025-06-20 07:36:05 +00:00
[SAMLIB/SAMSRV]
- Implement SamLookupIdsInDomain and SamrLookupIdsInDomain. svn path=/trunk/; revision=57057
This commit is contained in:
parent
67f22b7b53
commit
0015122a38
4 changed files with 395 additions and 8 deletions
|
@ -646,6 +646,116 @@ SamLookupDomainInSamServer(IN SAM_HANDLE ServerHandle,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NTSTATUS
|
||||||
|
NTAPI
|
||||||
|
SamLookupIdsInDomain(IN SAM_HANDLE DomainHandle,
|
||||||
|
IN ULONG Count,
|
||||||
|
IN PULONG RelativeIds,
|
||||||
|
OUT PUNICODE_STRING *Names,
|
||||||
|
OUT PSID_NAME_USE *Use)
|
||||||
|
{
|
||||||
|
SAMPR_RETURNED_USTRING_ARRAY NamesBuffer = {0, NULL};
|
||||||
|
SAMPR_ULONG_ARRAY UseBuffer = {0, NULL};
|
||||||
|
ULONG i;
|
||||||
|
NTSTATUS Status;
|
||||||
|
|
||||||
|
TRACE("SamLookupIdsInDomain(%p %lu %p %p %p)\n",
|
||||||
|
DomainHandle, Count, RelativeIds, Names, Use);
|
||||||
|
|
||||||
|
*Names = NULL;
|
||||||
|
*Use = NULL;
|
||||||
|
|
||||||
|
RpcTryExcept
|
||||||
|
{
|
||||||
|
Status = SamrLookupIdsInDomain((SAMPR_HANDLE)DomainHandle,
|
||||||
|
Count,
|
||||||
|
RelativeIds,
|
||||||
|
&NamesBuffer,
|
||||||
|
&UseBuffer);
|
||||||
|
}
|
||||||
|
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
|
||||||
|
{
|
||||||
|
Status = I_RpcMapWin32Status(RpcExceptionCode());
|
||||||
|
}
|
||||||
|
RpcEndExcept;
|
||||||
|
|
||||||
|
if (NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
*Names = midl_user_allocate(Count * sizeof(RPC_UNICODE_STRING));
|
||||||
|
if (*Names == NULL)
|
||||||
|
{
|
||||||
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < Count; i++)
|
||||||
|
{
|
||||||
|
(*Names)[i].Buffer = midl_user_allocate(NamesBuffer.Element[i].MaximumLength);
|
||||||
|
if ((*Names)[i].Buffer == NULL)
|
||||||
|
{
|
||||||
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*Use = midl_user_allocate(Count * sizeof(SID_NAME_USE));
|
||||||
|
if (*Use == NULL)
|
||||||
|
{
|
||||||
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < Count; i++)
|
||||||
|
{
|
||||||
|
(*Names)[i].Length = NamesBuffer.Element[i].Length;
|
||||||
|
(*Names)[i].MaximumLength = NamesBuffer.Element[i].MaximumLength;
|
||||||
|
|
||||||
|
RtlCopyMemory((*Names)[i].Buffer,
|
||||||
|
NamesBuffer.Element[i].Buffer,
|
||||||
|
NamesBuffer.Element[i].Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
RtlCopyMemory(*Use,
|
||||||
|
UseBuffer.Element,
|
||||||
|
Count * sizeof(SID_NAME_USE));
|
||||||
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
if (*Names != NULL)
|
||||||
|
{
|
||||||
|
for (i = 0; i < Count; i++)
|
||||||
|
{
|
||||||
|
if ((*Names)[i].Buffer != NULL)
|
||||||
|
midl_user_free((*Names)[i].Buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
midl_user_free(*Names);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*Use != NULL)
|
||||||
|
midl_user_free(*Use);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NamesBuffer.Element != NULL)
|
||||||
|
{
|
||||||
|
for (i = 0; i < NamesBuffer.Count; i++)
|
||||||
|
{
|
||||||
|
if (NamesBuffer.Element[i].Buffer != NULL)
|
||||||
|
midl_user_free(NamesBuffer.Element[i].Buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
midl_user_free(NamesBuffer.Element);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (UseBuffer.Element != NULL)
|
||||||
|
midl_user_free(UseBuffer.Element);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
SamLookupNamesInDomain(IN SAM_HANDLE DomainHandle,
|
SamLookupNamesInDomain(IN SAM_HANDLE DomainHandle,
|
||||||
|
@ -664,9 +774,6 @@ SamLookupNamesInDomain(IN SAM_HANDLE DomainHandle,
|
||||||
*RelativeIds = NULL;
|
*RelativeIds = NULL;
|
||||||
*Use = NULL;
|
*Use = NULL;
|
||||||
|
|
||||||
RidBuffer.Element = NULL;
|
|
||||||
UseBuffer.Element = NULL;
|
|
||||||
|
|
||||||
RpcTryExcept
|
RpcTryExcept
|
||||||
{
|
{
|
||||||
Status = SamrLookupNamesInDomain((SAMPR_HANDLE)DomainHandle,
|
Status = SamrLookupNamesInDomain((SAMPR_HANDLE)DomainHandle,
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
@ stdcall SamGetMembersInAlias(ptr ptr ptr)
|
@ stdcall SamGetMembersInAlias(ptr ptr ptr)
|
||||||
@ stub SamGetMembersInGroup
|
@ stub SamGetMembersInGroup
|
||||||
@ stdcall SamLookupDomainInSamServer(ptr ptr ptr)
|
@ stdcall SamLookupDomainInSamServer(ptr ptr ptr)
|
||||||
@ stub SamLookupIdsInDomain
|
@ stdcall SamLookupIdsInDomain(ptr long ptr ptr ptr)
|
||||||
@ stdcall SamLookupNamesInDomain(ptr long ptr ptr ptr)
|
@ stdcall SamLookupNamesInDomain(ptr long ptr ptr ptr)
|
||||||
@ stdcall SamOpenAlias(ptr long long ptr)
|
@ stdcall SamOpenAlias(ptr long long ptr)
|
||||||
@ stdcall SamOpenDomain(ptr long ptr ptr)
|
@ stdcall SamOpenDomain(ptr long ptr ptr)
|
||||||
|
|
|
@ -2925,6 +2925,9 @@ SamrLookupNamesInDomain(IN SAMPR_HANDLE DomainHandle,
|
||||||
SampRegCloseKey(AccountsKeyHandle);
|
SampRegCloseKey(AccountsKeyHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!NT_SUCCESS(Status) && Status != STATUS_OBJECT_NAME_NOT_FOUND)
|
||||||
|
break;
|
||||||
|
|
||||||
/* Return alias account */
|
/* Return alias account */
|
||||||
if (NT_SUCCESS(Status) && RelativeId != 0)
|
if (NT_SUCCESS(Status) && RelativeId != 0)
|
||||||
{
|
{
|
||||||
|
@ -2961,6 +2964,9 @@ SamrLookupNamesInDomain(IN SAMPR_HANDLE DomainHandle,
|
||||||
SampRegCloseKey(AccountsKeyHandle);
|
SampRegCloseKey(AccountsKeyHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!NT_SUCCESS(Status) && Status != STATUS_OBJECT_NAME_NOT_FOUND)
|
||||||
|
break;
|
||||||
|
|
||||||
/* Return group account */
|
/* Return group account */
|
||||||
if (NT_SUCCESS(Status) && RelativeId != 0)
|
if (NT_SUCCESS(Status) && RelativeId != 0)
|
||||||
{
|
{
|
||||||
|
@ -2997,6 +3003,9 @@ SamrLookupNamesInDomain(IN SAMPR_HANDLE DomainHandle,
|
||||||
SampRegCloseKey(AccountsKeyHandle);
|
SampRegCloseKey(AccountsKeyHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!NT_SUCCESS(Status) && Status != STATUS_OBJECT_NAME_NOT_FOUND)
|
||||||
|
break;
|
||||||
|
|
||||||
/* Return user account */
|
/* Return user account */
|
||||||
if (NT_SUCCESS(Status) && RelativeId != 0)
|
if (NT_SUCCESS(Status) && RelativeId != 0)
|
||||||
{
|
{
|
||||||
|
@ -3050,13 +3059,276 @@ done:
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
SamrLookupIdsInDomain(IN SAMPR_HANDLE DomainHandle,
|
SamrLookupIdsInDomain(IN SAMPR_HANDLE DomainHandle,
|
||||||
IN unsigned long Count,
|
IN ULONG Count,
|
||||||
IN unsigned long *RelativeIds,
|
IN ULONG *RelativeIds,
|
||||||
OUT PSAMPR_RETURNED_USTRING_ARRAY Names,
|
OUT PSAMPR_RETURNED_USTRING_ARRAY Names,
|
||||||
OUT PSAMPR_ULONG_ARRAY Use)
|
OUT PSAMPR_ULONG_ARRAY Use)
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED;
|
PSAM_DB_OBJECT DomainObject;
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
WCHAR RidString[9];
|
||||||
|
HANDLE AccountsKeyHandle;
|
||||||
|
HANDLE AccountKeyHandle;
|
||||||
|
ULONG MappedCount = 0;
|
||||||
|
ULONG DataLength;
|
||||||
|
ULONG i;
|
||||||
|
NTSTATUS Status;
|
||||||
|
|
||||||
|
TRACE("SamrLookupIdsInDomain(%p %lu %p %p %p)\n",
|
||||||
|
DomainHandle, Count, RelativeIds, Names, Use);
|
||||||
|
|
||||||
|
/* Validate the domain handle */
|
||||||
|
Status = SampValidateDbObject(DomainHandle,
|
||||||
|
SamDbDomainObject,
|
||||||
|
DOMAIN_LOOKUP,
|
||||||
|
&DomainObject);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
TRACE("failed with status 0x%08lx\n", Status);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
Names->Count = 0;
|
||||||
|
Use->Count = 0;
|
||||||
|
|
||||||
|
if (Count == 0)
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
|
||||||
|
/* Allocate the names array */
|
||||||
|
Names->Element = midl_user_allocate(Count * sizeof(ULONG));
|
||||||
|
if (Names->Element == NULL)
|
||||||
|
{
|
||||||
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Allocate the use array */
|
||||||
|
Use->Element = midl_user_allocate(Count * sizeof(ULONG));
|
||||||
|
if (Use->Element == NULL)
|
||||||
|
{
|
||||||
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
Names->Count = Count;
|
||||||
|
Use->Count = Count;
|
||||||
|
|
||||||
|
for (i = 0; i < Count; i++)
|
||||||
|
{
|
||||||
|
TRACE("RID: %lu\n", RelativeIds[i]);
|
||||||
|
|
||||||
|
swprintf(RidString, L"%08lx", RelativeIds[i]);
|
||||||
|
|
||||||
|
/* Lookup aliases */
|
||||||
|
Status = SampRegOpenKey(DomainObject->KeyHandle,
|
||||||
|
L"Aliases",
|
||||||
|
KEY_READ,
|
||||||
|
&AccountsKeyHandle);
|
||||||
|
if (NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
Status = SampRegOpenKey(AccountsKeyHandle,
|
||||||
|
RidString,
|
||||||
|
KEY_READ,
|
||||||
|
&AccountKeyHandle);
|
||||||
|
if (NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DataLength = 0;
|
||||||
|
Status = SampRegQueryValue(AccountKeyHandle,
|
||||||
|
L"Name",
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
&DataLength);
|
||||||
|
if (NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
Names->Element[i].Buffer = midl_user_allocate(DataLength);
|
||||||
|
if (Names->Element[i].Buffer == NULL)
|
||||||
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
|
||||||
|
if (NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
Names->Element[i].MaximumLength = DataLength;
|
||||||
|
Names->Element[i].Length = DataLength - sizeof(WCHAR);
|
||||||
|
|
||||||
|
Status = SampRegQueryValue(AccountKeyHandle,
|
||||||
|
L"Name",
|
||||||
|
NULL,
|
||||||
|
Names->Element[i].Buffer,
|
||||||
|
&DataLength);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SampRegCloseKey(AccountKeyHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
SampRegCloseKey(AccountsKeyHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!NT_SUCCESS(Status) && Status != STATUS_OBJECT_NAME_NOT_FOUND)
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Return alias account */
|
||||||
|
if (NT_SUCCESS(Status) && Names->Element[i].Buffer != NULL)
|
||||||
|
{
|
||||||
|
TRACE("Name: %S\n", Names->Element[i].Buffer);
|
||||||
|
Use->Element[i] = SidTypeAlias;
|
||||||
|
MappedCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Lookup groups */
|
||||||
|
Status = SampRegOpenKey(DomainObject->KeyHandle,
|
||||||
|
L"Groups",
|
||||||
|
KEY_READ,
|
||||||
|
&AccountsKeyHandle);
|
||||||
|
if (NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
Status = SampRegOpenKey(AccountsKeyHandle,
|
||||||
|
RidString,
|
||||||
|
KEY_READ,
|
||||||
|
&AccountKeyHandle);
|
||||||
|
if (NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DataLength = 0;
|
||||||
|
Status = SampRegQueryValue(AccountKeyHandle,
|
||||||
|
L"Name",
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
&DataLength);
|
||||||
|
if (NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
Names->Element[i].Buffer = midl_user_allocate(DataLength);
|
||||||
|
if (Names->Element[i].Buffer == NULL)
|
||||||
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
|
||||||
|
if (NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
Names->Element[i].MaximumLength = DataLength;
|
||||||
|
Names->Element[i].Length = DataLength - sizeof(WCHAR);
|
||||||
|
|
||||||
|
Status = SampRegQueryValue(AccountKeyHandle,
|
||||||
|
L"Name",
|
||||||
|
NULL,
|
||||||
|
Names->Element[i].Buffer,
|
||||||
|
&DataLength);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SampRegCloseKey(AccountKeyHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
SampRegCloseKey(AccountsKeyHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!NT_SUCCESS(Status) && Status != STATUS_OBJECT_NAME_NOT_FOUND)
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Return group account */
|
||||||
|
if (NT_SUCCESS(Status) && Names->Element[i].Buffer != NULL)
|
||||||
|
{
|
||||||
|
TRACE("Name: %S\n", Names->Element[i].Buffer);
|
||||||
|
Use->Element[i] = SidTypeGroup;
|
||||||
|
MappedCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Lookup users */
|
||||||
|
Status = SampRegOpenKey(DomainObject->KeyHandle,
|
||||||
|
L"Users",
|
||||||
|
KEY_READ,
|
||||||
|
&AccountsKeyHandle);
|
||||||
|
if (NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
Status = SampRegOpenKey(AccountsKeyHandle,
|
||||||
|
RidString,
|
||||||
|
KEY_READ,
|
||||||
|
&AccountKeyHandle);
|
||||||
|
if (NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
DataLength = 0;
|
||||||
|
Status = SampRegQueryValue(AccountKeyHandle,
|
||||||
|
L"Name",
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
&DataLength);
|
||||||
|
if (NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
TRACE("DataLength: %lu\n", DataLength);
|
||||||
|
|
||||||
|
Names->Element[i].Buffer = midl_user_allocate(DataLength);
|
||||||
|
if (Names->Element[i].Buffer == NULL)
|
||||||
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
|
||||||
|
if (NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
Names->Element[i].MaximumLength = DataLength;
|
||||||
|
Names->Element[i].Length = DataLength - sizeof(WCHAR);
|
||||||
|
|
||||||
|
Status = SampRegQueryValue(AccountKeyHandle,
|
||||||
|
L"Name",
|
||||||
|
NULL,
|
||||||
|
Names->Element[i].Buffer,
|
||||||
|
&DataLength);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SampRegCloseKey(AccountKeyHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
SampRegCloseKey(AccountsKeyHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!NT_SUCCESS(Status) && Status != STATUS_OBJECT_NAME_NOT_FOUND)
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Return user account */
|
||||||
|
if (NT_SUCCESS(Status) && Names->Element[i].Buffer != NULL)
|
||||||
|
{
|
||||||
|
TRACE("Name: %S\n", Names->Element[i].Buffer);
|
||||||
|
Use->Element[i] = SidTypeUser;
|
||||||
|
MappedCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return unknown account */
|
||||||
|
Use->Element[i] = SidTypeUnknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
|
if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
|
||||||
|
Status = STATUS_SUCCESS;
|
||||||
|
|
||||||
|
if (NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
if (MappedCount == 0)
|
||||||
|
Status = STATUS_NONE_MAPPED;
|
||||||
|
else if (MappedCount < Count)
|
||||||
|
Status = STATUS_SOME_NOT_MAPPED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (Names->Element != NULL)
|
||||||
|
{
|
||||||
|
for (i = 0; i < Count; i++)
|
||||||
|
{
|
||||||
|
if (Names->Element[i].Buffer != NULL)
|
||||||
|
midl_user_free(Names->Element[i].Buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
midl_user_free(Names->Element);
|
||||||
|
Names->Element = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Names->Count = 0;
|
||||||
|
|
||||||
|
if (Use->Element != NULL)
|
||||||
|
{
|
||||||
|
midl_user_free(Use->Element);
|
||||||
|
Use->Element = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Use->Count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -424,6 +424,14 @@ SamLookupDomainInSamServer(IN SAM_HANDLE ServerHandle,
|
||||||
IN PUNICODE_STRING Name,
|
IN PUNICODE_STRING Name,
|
||||||
OUT PSID *DomainId);
|
OUT PSID *DomainId);
|
||||||
|
|
||||||
|
NTSTATUS
|
||||||
|
NTAPI
|
||||||
|
SamLookupIdsInDomain(IN SAM_HANDLE DomainHandle,
|
||||||
|
IN ULONG Count,
|
||||||
|
IN PULONG RelativeIds,
|
||||||
|
OUT PUNICODE_STRING *Names,
|
||||||
|
OUT PSID_NAME_USE *Use);
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
SamLookupNamesInDomain(IN SAM_HANDLE DomainHandle,
|
SamLookupNamesInDomain(IN SAM_HANDLE DomainHandle,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue