https://git.reactos.org/?p=reactos.git;a=commitdiff;h=0425d866bf22d1037110f…
commit 0425d866bf22d1037110fbbafddd5ee2e5e33142
Author: Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Mon Mar 11 22:28:42 2019 +0100
Commit: Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Mon Mar 11 22:31:36 2019 +0100
[NETAPI32] NetUserGetInfo: Build and return the users SID for level 4 and 23.
---
dll/win32/netapi32/netapi32.h | 6 +++++
dll/win32/netapi32/user.c | 62 ++++++++++++++++++++++++++++++++++---------
dll/win32/netapi32/utils.c | 30 +++++++++++++++++++++
3 files changed, 85 insertions(+), 13 deletions(-)
diff --git a/dll/win32/netapi32/netapi32.h b/dll/win32/netapi32/netapi32.h
index 722e333e911..b2b8fe617aa 100644
--- a/dll/win32/netapi32/netapi32.h
+++ b/dll/win32/netapi32/netapi32.h
@@ -58,6 +58,12 @@ BuildSidFromSidAndRid(IN PSID SrcSid,
IN ULONG RelativeId,
OUT PSID *DestSid);
+VOID
+CopySidFromSidAndRid(
+ _Out_ PSID DstSid,
+ _In_ PSID SrcSid,
+ _In_ ULONG RelativeId);
+
/* wksta.c */
BOOL
diff --git a/dll/win32/netapi32/user.c b/dll/win32/netapi32/user.c
index 3e29bc48c64..0ac1cf32085 100644
--- a/dll/win32/netapi32/user.c
+++ b/dll/win32/netapi32/user.c
@@ -39,6 +39,7 @@ typedef struct _ENUM_CONTEXT
SAM_HANDLE ServerHandle;
SAM_HANDLE BuiltinDomainHandle;
SAM_HANDLE AccountDomainHandle;
+ PSID AccountDomainSid;
SAM_ENUMERATE_HANDLE EnumerationContext;
PSAM_RID_ENUMERATION Buffer;
@@ -400,6 +401,7 @@ FreeUserInfo(PUSER_ALL_INFORMATION UserInfo)
static
NET_API_STATUS
BuildUserInfoBuffer(SAM_HANDLE UserHandle,
+ PSID AccountDomainSid,
DWORD level,
ULONG RelativeId,
LPVOID *Buffer)
@@ -508,7 +510,7 @@ BuildUserInfoBuffer(SAM_HANDLE UserHandle,
if (UserInfo->LogonHours.UnitsPerWeek > 0)
Size += (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8;
- /* FIXME: usri4_user_sid */
+ Size += RtlLengthSid(AccountDomainSid) + sizeof(ULONG);
break;
case 10:
@@ -547,7 +549,7 @@ BuildUserInfoBuffer(SAM_HANDLE UserHandle,
UserInfo->FullName.Length + sizeof(WCHAR) +
UserInfo->AdminComment.Length + sizeof(WCHAR);
- /* FIXME: usri23_user_sid */
+ Size += RtlLengthSid(AccountDomainSid) + sizeof(ULONG);
break;
default:
@@ -993,7 +995,9 @@ BuildUserInfoBuffer(SAM_HANDLE UserHandle,
UserInfo4->usri4_country_code = UserInfo->CountryCode;
UserInfo4->usri4_code_page = UserInfo->CodePage;
- /* FIXME: usri4_user_sid */
+ UserInfo4->usri4_user_sid = (PVOID)Ptr;
+ CopySidFromSidAndRid(UserInfo4->usri4_user_sid, AccountDomainSid,
RelativeId);
+ Ptr = (LPWSTR)((ULONG_PTR)Ptr + RtlLengthSid(AccountDomainSid) +
sizeof(ULONG));
UserInfo4->usri4_primary_group_id = UserInfo->PrimaryGroupId;
@@ -1216,7 +1220,9 @@ BuildUserInfoBuffer(SAM_HANDLE UserHandle,
UserInfo23->usri23_flags =
GetAccountFlags(UserInfo->UserAccountControl,
Dacl);
- /* FIXME: usri23_user_sid */
+ UserInfo23->usri23_user_sid = (PVOID)Ptr;
+ CopySidFromSidAndRid(UserInfo23->usri23_user_sid, AccountDomainSid,
RelativeId);
+ Ptr = (LPWSTR)((ULONG_PTR)Ptr + RtlLengthSid(AccountDomainSid) +
sizeof(ULONG));
break;
}
@@ -2484,13 +2490,24 @@ NetUserEnum(LPCWSTR servername,
goto done;
}
- Status = OpenAccountDomain(EnumContext->ServerHandle,
- (servername != NULL) ? &ServerName : NULL,
- DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
- &EnumContext->AccountDomainHandle);
+ /* Get the Account Domain SID */
+ Status = GetAccountDomainSid((servername != NULL) ? &ServerName : NULL,
+ &EnumContext->AccountDomainSid);
if (!NT_SUCCESS(Status))
{
- ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
+ ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);
+ ApiStatus = NetpNtStatusToApiStatus(Status);
+ goto done;
+ }
+
+ /* Open the Account Domain */
+ Status = SamOpenDomain(EnumContext->ServerHandle,
+ DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
+ EnumContext->AccountDomainSid,
+ &EnumContext->AccountDomainHandle);
+ if (!NT_SUCCESS(Status))
+ {
+ ERR("SamOpenDomain failed (Status %08lx)\n", Status);
ApiStatus = NetpNtStatusToApiStatus(Status);
goto done;
}
@@ -2567,6 +2584,7 @@ NetUserEnum(LPCWSTR servername,
}
ApiStatus = BuildUserInfoBuffer(UserHandle,
+ EnumContext->AccountDomainSid,
level,
CurrentUser->RelativeId,
&Buffer);
@@ -2601,6 +2619,9 @@ done:
if (EnumContext->AccountDomainHandle != NULL)
SamCloseHandle(EnumContext->AccountDomainHandle);
+ if (EnumContext->AccountDomainSid != NULL)
+ RtlFreeHeap(RtlGetProcessHeap(), 0, EnumContext->AccountDomainSid);
+
if (EnumContext->ServerHandle != NULL)
SamCloseHandle(EnumContext->ServerHandle);
@@ -2816,6 +2837,7 @@ NetUserGetInfo(LPCWSTR servername,
PULONG RelativeIds = NULL;
PSID_NAME_USE Use = NULL;
LPVOID Buffer = NULL;
+ PSID AccountDomainSid = NULL;
NET_API_STATUS ApiStatus = NERR_Success;
NTSTATUS Status = STATUS_SUCCESS;
@@ -2839,11 +2861,21 @@ NetUserGetInfo(LPCWSTR servername,
goto done;
}
+ /* Get the Account Domain SID */
+ Status = GetAccountDomainSid((servername != NULL) ? &ServerName : NULL,
+ &AccountDomainSid);
+ if (!NT_SUCCESS(Status))
+ {
+ ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);
+ ApiStatus = NetpNtStatusToApiStatus(Status);
+ goto done;
+ }
+
/* Open the Account Domain */
- Status = OpenAccountDomain(ServerHandle,
- (servername != NULL) ? &ServerName : NULL,
- DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
- &AccountDomainHandle);
+ Status = SamOpenDomain(ServerHandle,
+ DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
+ AccountDomainSid,
+ &AccountDomainHandle);
if (!NT_SUCCESS(Status))
{
ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
@@ -2890,6 +2922,7 @@ NetUserGetInfo(LPCWSTR servername,
}
ApiStatus = BuildUserInfoBuffer(UserHandle,
+ AccountDomainSid,
level,
RelativeIds[0],
&Buffer);
@@ -2912,6 +2945,9 @@ done:
if (AccountDomainHandle != NULL)
SamCloseHandle(AccountDomainHandle);
+ if (AccountDomainSid != NULL)
+ RtlFreeHeap(RtlGetProcessHeap(), 0, AccountDomainSid);
+
if (ServerHandle != NULL)
SamCloseHandle(ServerHandle);
diff --git a/dll/win32/netapi32/utils.c b/dll/win32/netapi32/utils.c
index 125dbe7f89c..cbc2d4f700b 100644
--- a/dll/win32/netapi32/utils.c
+++ b/dll/win32/netapi32/utils.c
@@ -215,4 +215,34 @@ BuildSidFromSidAndRid(IN PSID SrcSid,
return NERR_Success;
}
+
+VOID
+CopySidFromSidAndRid(
+ _Out_ PSID DstSid,
+ _In_ PSID SrcSid,
+ _In_ ULONG RelativeId)
+{
+ UCHAR RidCount;
+ ULONG i;
+ PULONG p, q;
+
+ RidCount = *RtlSubAuthorityCountSid(SrcSid);
+ if (RidCount >= 8)
+ return;
+
+ RtlInitializeSid(DstSid,
+ RtlIdentifierAuthoritySid(SrcSid),
+ RidCount + 1);
+
+ for (i = 0; i < (ULONG)RidCount; i++)
+ {
+ p = RtlSubAuthoritySid(SrcSid, i);
+ q = RtlSubAuthoritySid(DstSid, i);
+ *q = *p;
+ }
+
+ q = RtlSubAuthoritySid(DstSid, (ULONG)RidCount);
+ *q = RelativeId;
+}
+
/* EOF */