Reactos

[NETAPI32] NetUserGetInfo: Build and return the users SID for level 4 and 23.

+85 -13
+6
dll/win32/netapi32/netapi32.h
··· 58 58 IN ULONG RelativeId, 59 59 OUT PSID *DestSid); 60 60 61 + VOID 62 + CopySidFromSidAndRid( 63 + _Out_ PSID DstSid, 64 + _In_ PSID SrcSid, 65 + _In_ ULONG RelativeId); 66 + 61 67 /* wksta.c */ 62 68 63 69 BOOL
+49 -13
dll/win32/netapi32/user.c
··· 39 39 SAM_HANDLE ServerHandle; 40 40 SAM_HANDLE BuiltinDomainHandle; 41 41 SAM_HANDLE AccountDomainHandle; 42 + PSID AccountDomainSid; 42 43 43 44 SAM_ENUMERATE_HANDLE EnumerationContext; 44 45 PSAM_RID_ENUMERATION Buffer; ··· 400 401 static 401 402 NET_API_STATUS 402 403 BuildUserInfoBuffer(SAM_HANDLE UserHandle, 404 + PSID AccountDomainSid, 403 405 DWORD level, 404 406 ULONG RelativeId, 405 407 LPVOID *Buffer) ··· 508 510 if (UserInfo->LogonHours.UnitsPerWeek > 0) 509 511 Size += (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8; 510 512 511 - /* FIXME: usri4_user_sid */ 513 + Size += RtlLengthSid(AccountDomainSid) + sizeof(ULONG); 512 514 break; 513 515 514 516 case 10: ··· 547 549 UserInfo->FullName.Length + sizeof(WCHAR) + 548 550 UserInfo->AdminComment.Length + sizeof(WCHAR); 549 551 550 - /* FIXME: usri23_user_sid */ 552 + Size += RtlLengthSid(AccountDomainSid) + sizeof(ULONG); 551 553 break; 552 554 553 555 default: ··· 993 995 UserInfo4->usri4_country_code = UserInfo->CountryCode; 994 996 UserInfo4->usri4_code_page = UserInfo->CodePage; 995 997 996 - /* FIXME: usri4_user_sid */ 998 + UserInfo4->usri4_user_sid = (PVOID)Ptr; 999 + CopySidFromSidAndRid(UserInfo4->usri4_user_sid, AccountDomainSid, RelativeId); 1000 + Ptr = (LPWSTR)((ULONG_PTR)Ptr + RtlLengthSid(AccountDomainSid) + sizeof(ULONG)); 997 1001 998 1002 UserInfo4->usri4_primary_group_id = UserInfo->PrimaryGroupId; 999 1003 ··· 1216 1220 UserInfo23->usri23_flags = GetAccountFlags(UserInfo->UserAccountControl, 1217 1221 Dacl); 1218 1222 1219 - /* FIXME: usri23_user_sid */ 1223 + UserInfo23->usri23_user_sid = (PVOID)Ptr; 1224 + CopySidFromSidAndRid(UserInfo23->usri23_user_sid, AccountDomainSid, RelativeId); 1225 + Ptr = (LPWSTR)((ULONG_PTR)Ptr + RtlLengthSid(AccountDomainSid) + sizeof(ULONG)); 1220 1226 break; 1221 1227 } 1222 1228 ··· 2484 2490 goto done; 2485 2491 } 2486 2492 2487 - Status = OpenAccountDomain(EnumContext->ServerHandle, 2488 - (servername != NULL) ? &ServerName : NULL, 2489 - DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP, 2490 - &EnumContext->AccountDomainHandle); 2493 + /* Get the Account Domain SID */ 2494 + Status = GetAccountDomainSid((servername != NULL) ? &ServerName : NULL, 2495 + &EnumContext->AccountDomainSid); 2491 2496 if (!NT_SUCCESS(Status)) 2492 2497 { 2493 - ERR("OpenAccountDomain failed (Status %08lx)\n", Status); 2498 + ERR("GetAccountDomainSid failed (Status %08lx)\n", Status); 2499 + ApiStatus = NetpNtStatusToApiStatus(Status); 2500 + goto done; 2501 + } 2502 + 2503 + /* Open the Account Domain */ 2504 + Status = SamOpenDomain(EnumContext->ServerHandle, 2505 + DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP, 2506 + EnumContext->AccountDomainSid, 2507 + &EnumContext->AccountDomainHandle); 2508 + if (!NT_SUCCESS(Status)) 2509 + { 2510 + ERR("SamOpenDomain failed (Status %08lx)\n", Status); 2494 2511 ApiStatus = NetpNtStatusToApiStatus(Status); 2495 2512 goto done; 2496 2513 } ··· 2567 2584 } 2568 2585 2569 2586 ApiStatus = BuildUserInfoBuffer(UserHandle, 2587 + EnumContext->AccountDomainSid, 2570 2588 level, 2571 2589 CurrentUser->RelativeId, 2572 2590 &Buffer); ··· 2600 2618 2601 2619 if (EnumContext->AccountDomainHandle != NULL) 2602 2620 SamCloseHandle(EnumContext->AccountDomainHandle); 2621 + 2622 + if (EnumContext->AccountDomainSid != NULL) 2623 + RtlFreeHeap(RtlGetProcessHeap(), 0, EnumContext->AccountDomainSid); 2603 2624 2604 2625 if (EnumContext->ServerHandle != NULL) 2605 2626 SamCloseHandle(EnumContext->ServerHandle); ··· 2816 2837 PULONG RelativeIds = NULL; 2817 2838 PSID_NAME_USE Use = NULL; 2818 2839 LPVOID Buffer = NULL; 2840 + PSID AccountDomainSid = NULL; 2819 2841 NET_API_STATUS ApiStatus = NERR_Success; 2820 2842 NTSTATUS Status = STATUS_SUCCESS; 2821 2843 ··· 2839 2861 goto done; 2840 2862 } 2841 2863 2864 + /* Get the Account Domain SID */ 2865 + Status = GetAccountDomainSid((servername != NULL) ? &ServerName : NULL, 2866 + &AccountDomainSid); 2867 + if (!NT_SUCCESS(Status)) 2868 + { 2869 + ERR("GetAccountDomainSid failed (Status %08lx)\n", Status); 2870 + ApiStatus = NetpNtStatusToApiStatus(Status); 2871 + goto done; 2872 + } 2873 + 2842 2874 /* Open the Account Domain */ 2843 - Status = OpenAccountDomain(ServerHandle, 2844 - (servername != NULL) ? &ServerName : NULL, 2845 - DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP, 2846 - &AccountDomainHandle); 2875 + Status = SamOpenDomain(ServerHandle, 2876 + DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP, 2877 + AccountDomainSid, 2878 + &AccountDomainHandle); 2847 2879 if (!NT_SUCCESS(Status)) 2848 2880 { 2849 2881 ERR("OpenAccountDomain failed (Status %08lx)\n", Status); ··· 2890 2922 } 2891 2923 2892 2924 ApiStatus = BuildUserInfoBuffer(UserHandle, 2925 + AccountDomainSid, 2893 2926 level, 2894 2927 RelativeIds[0], 2895 2928 &Buffer); ··· 2911 2944 2912 2945 if (AccountDomainHandle != NULL) 2913 2946 SamCloseHandle(AccountDomainHandle); 2947 + 2948 + if (AccountDomainSid != NULL) 2949 + RtlFreeHeap(RtlGetProcessHeap(), 0, AccountDomainSid); 2914 2950 2915 2951 if (ServerHandle != NULL) 2916 2952 SamCloseHandle(ServerHandle);
+30
dll/win32/netapi32/utils.c
··· 215 215 return NERR_Success; 216 216 } 217 217 218 + 219 + VOID 220 + CopySidFromSidAndRid( 221 + _Out_ PSID DstSid, 222 + _In_ PSID SrcSid, 223 + _In_ ULONG RelativeId) 224 + { 225 + UCHAR RidCount; 226 + ULONG i; 227 + PULONG p, q; 228 + 229 + RidCount = *RtlSubAuthorityCountSid(SrcSid); 230 + if (RidCount >= 8) 231 + return; 232 + 233 + RtlInitializeSid(DstSid, 234 + RtlIdentifierAuthoritySid(SrcSid), 235 + RidCount + 1); 236 + 237 + for (i = 0; i < (ULONG)RidCount; i++) 238 + { 239 + p = RtlSubAuthoritySid(SrcSid, i); 240 + q = RtlSubAuthoritySid(DstSid, i); 241 + *q = *p; 242 + } 243 + 244 + q = RtlSubAuthoritySid(DstSid, (ULONG)RidCount); 245 + *q = RelativeId; 246 + } 247 + 218 248 /* EOF */