Add a test for RtlAllocateAndInitializeSid, make it pass under Wine

Dmitry Timoshkov dmitry at baikal.ru
Mon Nov 14 08:26:30 CST 2005


Hello,

Changelog:
    Dmitry Timoshkov <dmitry at codeweavers.com>
    Add a test for RtlAllocateAndInitializeSid, make it pass under Wine.

diff -up cvs/hq/wine/dlls/ntdll/sec.c wine/dlls/ntdll/sec.c
--- cvs/hq/wine/dlls/ntdll/sec.c	2005-11-10 11:28:31.000000000 +0800
+++ wine/dlls/ntdll/sec.c	2005-11-14 22:18:37.000000000 +0800
@@ -135,41 +135,41 @@ NTSTATUS WINAPI RtlAllocateAndInitialize
 	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 (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;
-
-	return STATUS_SUCCESS;
+    if (!(tmp_sid= RtlAllocateHeap( GetProcessHeap(), 0,
+                                    RtlLengthRequiredSid(nSubAuthorityCount))))
+        return STATUS_NO_MEMORY;
+
+    tmp_sid->Revision = SID_REVISION;
+
+    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 -up cvs/hq/wine/dlls/ntdll/tests/rtl.c wine/dlls/ntdll/tests/rtl.c
--- cvs/hq/wine/dlls/ntdll/tests/rtl.c	2005-09-05 19:44:49.000000000 +0900
+++ wine/dlls/ntdll/tests/rtl.c	2005-11-14 22:20:30.000000000 +0800
@@ -64,6 +64,8 @@ static BOOLEAN   (WINAPI * pRtlIsValidIn
 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();
 }






More information about the wine-patches mailing list