Fix BuildTrusteeWithSid, implement and test BuildTrusteeWithName.
[wine/wine-kai.git] / dlls / advapi32 / tests / security.c
bloba143fd51d049b2e908f1701b88f088e58bb69737
1 /*
2 * Unit tests for security functions
4 * Copyright (c) 2004 Mike McCormack
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <stdio.h>
23 #include "wine/test.h"
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winerror.h"
27 #include "aclapi.h"
29 typedef BOOL (WINAPI *fnConvertSidToStringSidA)( PSID pSid, LPSTR *str );
30 typedef BOOL (WINAPI *fnConvertSidToStringSidW)( PSID pSid, LPWSTR *str );
32 fnConvertSidToStringSidW pConvertSidToStringSidW;
33 fnConvertSidToStringSidA pConvertSidToStringSidA;
35 void test_sid()
37 PSID psid;
38 LPWSTR str = NULL;
39 BOOL r;
40 SID_IDENTIFIER_AUTHORITY auth = { {6,7,0x1a,0x15,0x0e,0x1f} };
41 WCHAR refstr[] = { 'S','-','1','-','1','A','1','5','6','E','7','F','-',
42 '1','2','3','4','5','-','0','-','4','2','9','4','9','6','7','2','9','5',0 };
44 HMODULE hmod = GetModuleHandle("advapi32.dll");
46 pConvertSidToStringSidW = (fnConvertSidToStringSidW)
47 GetProcAddress( hmod, "ConvertSidToStringSidW" );
48 if( !pConvertSidToStringSidW )
49 return;
51 r = AllocateAndInitializeSid( &auth, 3, 12345, 0,-1,0,0,0,0,0,&psid);
52 ok( r, "failed to allocate sid\n" );
53 r = pConvertSidToStringSidW( psid, &str );
54 ok( r, "failed to convert sid\n" );
55 ok( !lstrcmpW( str, refstr ), "incorrect sid\n" );
56 LocalFree( str );
57 FreeSid( psid );
60 void test_trustee()
62 TRUSTEE trustee;
63 PSID psid;
64 DWORD r;
65 LPSTR str = "2jjj";
67 SID_IDENTIFIER_AUTHORITY auth = { {0x11,0x22,0,0,0, 0} };
69 r = AllocateAndInitializeSid( &auth, 1, 42, 0,0,0,0,0,0,0,&psid );
70 ok( r, "failed to init SID\n" );
72 memset( &trustee, 0xff, sizeof trustee );
73 BuildTrusteeWithSidA( &trustee, psid );
75 ok( trustee.pMultipleTrustee == NULL, "pMultipleTrustee wrong\n");
76 ok( trustee.MultipleTrusteeOperation == NO_MULTIPLE_TRUSTEE,
77 "MultipleTrusteeOperation wrong\n");
78 ok( trustee.TrusteeForm == TRUSTEE_IS_SID, "TrusteeForm wrong\n");
79 ok( trustee.TrusteeType == TRUSTEE_IS_UNKNOWN, "TrusteeType wrong\n");
80 ok( trustee.ptstrName == (LPSTR) psid, "ptstrName wrong\n" );
81 FreeSid( psid );
83 /* test BuildTrusteeWithNameA */
84 memset( &trustee, 0xff, sizeof trustee );
85 BuildTrusteeWithNameA( &trustee, str );
87 ok( trustee.pMultipleTrustee == NULL, "pMultipleTrustee wrong\n");
88 ok( trustee.MultipleTrusteeOperation == NO_MULTIPLE_TRUSTEE,
89 "MultipleTrusteeOperation wrong\n");
90 ok( trustee.TrusteeForm == TRUSTEE_IS_NAME, "TrusteeForm wrong\n");
91 ok( trustee.TrusteeType == TRUSTEE_IS_UNKNOWN, "TrusteeType wrong\n");
92 ok( trustee.ptstrName == str, "ptstrName wrong\n" );
95 START_TEST(security)
97 test_sid();
98 test_trustee();