From adf48a3cc77e35245e9f9151d982f787af82eeda Mon Sep 17 00:00:00 2001 From: Dmitry Timoshkov Date: Tue, 15 Nov 2005 12:03:46 +0000 Subject: [PATCH] Add a test for RtlAllocateAndInitializeSid, make it pass under Wine. --- dlls/ntdll/sec.c | 52 +++++++++++++++++++++++++------------------------- dlls/ntdll/tests/rtl.c | 25 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 26 deletions(-) diff --git a/dlls/ntdll/sec.c b/dlls/ntdll/sec.c index 4133cdcf44e..cb13d491dd0 100644 --- a/dlls/ntdll/sec.c +++ b/dlls/ntdll/sec.c @@ -135,41 +135,41 @@ NTSTATUS WINAPI RtlAllocateAndInitializeSid ( DWORD nSubAuthority6, DWORD nSubAuthority7, PSID *pSid ) { + SID *tmp_sid; - TRACE("(%p, 0x%04x,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,%p)\n", + TRACE("(%p, 0x%04x,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,%p)\n", pIdentifierAuthority,nSubAuthorityCount, nSubAuthority0, nSubAuthority1, nSubAuthority2, nSubAuthority3, nSubAuthority4, nSubAuthority5, nSubAuthority6, nSubAuthority7, pSid); - if (!(*pSid = RtlAllocateHeap( GetProcessHeap(), 0, - RtlLengthRequiredSid(nSubAuthorityCount)))) - return STATUS_NO_MEMORY; + if (nSubAuthorityCount > 8) return STATUS_INVALID_SID; - ((SID*)*pSid)->Revision = SID_REVISION; + if (!(tmp_sid= RtlAllocateHeap( GetProcessHeap(), 0, + RtlLengthRequiredSid(nSubAuthorityCount)))) + return STATUS_NO_MEMORY; - if (pIdentifierAuthority) - memcpy(&((SID*)*pSid)->IdentifierAuthority, pIdentifierAuthority, sizeof (SID_IDENTIFIER_AUTHORITY)); - *RtlSubAuthorityCountSid(*pSid) = nSubAuthorityCount; - - if (nSubAuthorityCount > 0) - *RtlSubAuthoritySid(*pSid, 0) = nSubAuthority0; - if (nSubAuthorityCount > 1) - *RtlSubAuthoritySid(*pSid, 1) = nSubAuthority1; - if (nSubAuthorityCount > 2) - *RtlSubAuthoritySid(*pSid, 2) = nSubAuthority2; - if (nSubAuthorityCount > 3) - *RtlSubAuthoritySid(*pSid, 3) = nSubAuthority3; - if (nSubAuthorityCount > 4) - *RtlSubAuthoritySid(*pSid, 4) = nSubAuthority4; - if (nSubAuthorityCount > 5) - *RtlSubAuthoritySid(*pSid, 5) = nSubAuthority5; - if (nSubAuthorityCount > 6) - *RtlSubAuthoritySid(*pSid, 6) = nSubAuthority6; - if (nSubAuthorityCount > 7) - *RtlSubAuthoritySid(*pSid, 7) = nSubAuthority7; + tmp_sid->Revision = SID_REVISION; - return STATUS_SUCCESS; + if (pIdentifierAuthority) + memcpy(&tmp_sid->IdentifierAuthority, pIdentifierAuthority, sizeof(SID_IDENTIFIER_AUTHORITY)); + tmp_sid->SubAuthorityCount = nSubAuthorityCount; + + switch( nSubAuthorityCount ) + { + case 8: tmp_sid->SubAuthority[7]= nSubAuthority7; + case 7: tmp_sid->SubAuthority[6]= nSubAuthority6; + case 6: tmp_sid->SubAuthority[5]= nSubAuthority5; + case 5: tmp_sid->SubAuthority[4]= nSubAuthority4; + case 4: tmp_sid->SubAuthority[3]= nSubAuthority3; + case 3: tmp_sid->SubAuthority[2]= nSubAuthority2; + case 2: tmp_sid->SubAuthority[1]= nSubAuthority1; + case 1: tmp_sid->SubAuthority[0]= nSubAuthority0; + break; + } + *pSid = tmp_sid; + return STATUS_SUCCESS; } + /****************************************************************************** * RtlEqualSid [NTDLL.@] * diff --git a/dlls/ntdll/tests/rtl.c b/dlls/ntdll/tests/rtl.c index 89f64838b99..fe79e36885e 100644 --- a/dlls/ntdll/tests/rtl.c +++ b/dlls/ntdll/tests/rtl.c @@ -64,6 +64,8 @@ static BOOLEAN (WINAPI * pRtlIsValidIndexHandle)(const RTL_HANDLE_TABLE *, ULO static NTSTATUS (WINAPI * pRtlDestroyHandleTable)(RTL_HANDLE_TABLE *); static RTL_HANDLE * (WINAPI * pRtlAllocateHandle)(RTL_HANDLE_TABLE *, ULONG *); static BOOLEAN (WINAPI * pRtlFreeHandle)(RTL_HANDLE_TABLE *, RTL_HANDLE *); +static NTSTATUS (WINAPI *pRtlAllocateAndInitializeSid)(PSID_IDENTIFIER_AUTHORITY,BYTE,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,DWORD,PSID*); +static NTSTATUS (WINAPI *pRtlFreeSid)(PSID); #define LEN 16 static const char* src_src = "This is a test!"; /* 16 bytes long, incl NUL */ static ULONG src_aligned_block[4]; @@ -93,6 +95,8 @@ static void InitFunctionPtrs(void) pRtlDestroyHandleTable = (void *)GetProcAddress(hntdll, "RtlDestroyHandleTable"); pRtlAllocateHandle = (void *)GetProcAddress(hntdll, "RtlAllocateHandle"); pRtlFreeHandle = (void *)GetProcAddress(hntdll, "RtlFreeHandle"); + pRtlAllocateAndInitializeSid = (void *)GetProcAddress(hntdll, "RtlAllocateAndInitializeSid"); + pRtlFreeSid = (void *)GetProcAddress(hntdll, "RtlFreeSid"); } strcpy((char*)src_aligned_block, src_src); ok(strlen(src) == 15, "Source must be 16 bytes long!\n"); @@ -878,6 +882,25 @@ static void test_HandleTables(void) ok(status == STATUS_SUCCESS, "RtlDestroyHandleTable failed with error 0x%08lx\n", status); } +static void test_RtlAllocateAndInitializeSid(void) +{ + NTSTATUS ret; + SID_IDENTIFIER_AUTHORITY sia = {{ 1, 2, 3, 4, 5, 6 }}; + PSID psid; + + ret = pRtlAllocateAndInitializeSid(&sia, 0, 1, 2, 3, 4, 5, 6, 7, 8, &psid); + ok(!ret, "RtlAllocateAndInitializeSid error %08lx\n", ret); + ret = pRtlFreeSid(psid); + ok(!ret, "RtlFreeSid error %08lx\n", ret); + + /* these tests crash on XP + ret = pRtlAllocateAndInitializeSid(NULL, 0, 1, 2, 3, 4, 5, 6, 7, 8, &psid); + ret = pRtlAllocateAndInitializeSid(&sia, 0, 1, 2, 3, 4, 5, 6, 7, 8, NULL);*/ + + ret = pRtlAllocateAndInitializeSid(&sia, 9, 1, 2, 3, 4, 5, 6, 7, 8, &psid); + ok(ret == STATUS_INVALID_SID, "wrong error %08lx\n", ret); +} + START_TEST(rtl) { InitFunctionPtrs(); @@ -908,4 +931,6 @@ START_TEST(rtl) test_RtlComputeCrc32(); if (pRtlInitializeHandleTable) test_HandleTables(); + if (pRtlAllocateAndInitializeSid) + test_RtlAllocateAndInitializeSid(); } -- 2.11.4.GIT