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
23 #include "wine/test.h"
30 typedef BOOL (WINAPI *fnConvertSidToStringSidA)( PSID pSid, LPSTR *str );
31 typedef BOOL (WINAPI *fnConvertStringSidToSidA)( LPCSTR str, PSID pSid );
33 fnConvertSidToStringSidA pConvertSidToStringSidA;
34 fnConvertStringSidToSidA pConvertStringSidToSidA;
38 SID_IDENTIFIER_AUTHORITY auth;
44 struct sidRef refs[] = {
45 { { {0x00,0x00,0x33,0x44,0x55,0x66} }, "S-1-860116326-1" },
46 { { {0x00,0x00,0x01,0x02,0x03,0x04} }, "S-1-16909060-1" },
47 { { {0x00,0x00,0x00,0x01,0x02,0x03} }, "S-1-66051-1" },
48 { { {0x00,0x00,0x00,0x00,0x01,0x02} }, "S-1-258-1" },
49 { { {0x00,0x00,0x00,0x00,0x00,0x02} }, "S-1-2-1" },
50 { { {0x00,0x00,0x00,0x00,0x00,0x0c} }, "S-1-12-1" },
52 const char noSubAuthStr[] = "S-1-5";
53 HMODULE hmod = GetModuleHandle("advapi32.dll");
59 pConvertSidToStringSidA = (fnConvertSidToStringSidA)
60 GetProcAddress( hmod, "ConvertSidToStringSidA" );
61 if( !pConvertSidToStringSidA )
63 pConvertStringSidToSidA = (fnConvertStringSidToSidA)
64 GetProcAddress( hmod, "ConvertStringSidToSidA" );
65 if( !pConvertStringSidToSidA )
68 r = pConvertStringSidToSidA( NULL, NULL );
69 ok( !r, "expected failure with NULL parameters\n" );
70 if( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED )
72 ok( GetLastError() == ERROR_INVALID_PARAMETER,
73 "expected GetLastError() is ERROR_INVALID_PARAMETER, got %ld\n",
76 r = pConvertStringSidToSidA( refs[0].refStr, NULL );
77 ok( !r && GetLastError() == ERROR_INVALID_PARAMETER,
78 "expected GetLastError() is ERROR_INVALID_PARAMETER, got %ld\n",
81 r = pConvertStringSidToSidA( NULL, &str );
82 ok( !r && GetLastError() == ERROR_INVALID_PARAMETER,
83 "expected GetLastError() is ERROR_INVALID_PARAMETER, got %ld\n",
86 r = pConvertStringSidToSidA( noSubAuthStr, &psid );
88 "expected failure with no sub authorities\n" );
89 ok( GetLastError() == ERROR_INVALID_SID,
90 "expected GetLastError() is ERROR_INVALID_SID, got %ld\n",
93 for( i = 0; i < sizeof(refs) / sizeof(refs[0]); i++ )
97 r = AllocateAndInitializeSid( &refs[i].auth, 1,1,0,0,0,0,0,0,0,
99 ok( r, "failed to allocate sid\n" );
100 r = pConvertSidToStringSidA( psid, &str );
101 ok( r, "failed to convert sid\n" );
102 ok( !strcmp( str, refs[i].refStr ),
103 "incorrect sid, expected %s, got %s\n", refs[i].refStr, str );
109 r = pConvertStringSidToSidA( refs[i].refStr, &psid );
110 ok( r, "failed to parse sid string\n" );
113 !memcmp( pisid->IdentifierAuthority.Value, refs[i].auth.Value,
114 sizeof(refs[i].auth) ),
115 "string sid %s didn't parse to expected value\n"
116 "(got 0x%04x%08lx, expected 0x%04x%08lx)\n",
118 MAKEWORD( pisid->IdentifierAuthority.Value[1],
119 pisid->IdentifierAuthority.Value[0] ),
120 MAKELONG( MAKEWORD( pisid->IdentifierAuthority.Value[5],
121 pisid->IdentifierAuthority.Value[4] ),
122 MAKEWORD( pisid->IdentifierAuthority.Value[3],
123 pisid->IdentifierAuthority.Value[2] ) ),
124 MAKEWORD( refs[i].auth.Value[1], refs[i].auth.Value[0] ),
125 MAKELONG( MAKEWORD( refs[i].auth.Value[5], refs[i].auth.Value[4] ),
126 MAKEWORD( refs[i].auth.Value[3], refs[i].auth.Value[2] ) ) );
139 SID_IDENTIFIER_AUTHORITY auth = { {0x11,0x22,0,0,0, 0} };
141 r = AllocateAndInitializeSid( &auth, 1, 42, 0,0,0,0,0,0,0,&psid );
142 ok( r, "failed to init SID\n" );
144 memset( &trustee, 0xff, sizeof trustee );
145 BuildTrusteeWithSidA( &trustee, psid );
147 ok( trustee.pMultipleTrustee == NULL, "pMultipleTrustee wrong\n");
148 ok( trustee.MultipleTrusteeOperation == NO_MULTIPLE_TRUSTEE,
149 "MultipleTrusteeOperation wrong\n");
150 ok( trustee.TrusteeForm == TRUSTEE_IS_SID, "TrusteeForm wrong\n");
151 ok( trustee.TrusteeType == TRUSTEE_IS_UNKNOWN, "TrusteeType wrong\n");
152 ok( trustee.ptstrName == (LPSTR) psid, "ptstrName wrong\n" );
155 /* test BuildTrusteeWithNameA */
156 memset( &trustee, 0xff, sizeof trustee );
157 BuildTrusteeWithNameA( &trustee, str );
159 ok( trustee.pMultipleTrustee == NULL, "pMultipleTrustee wrong\n");
160 ok( trustee.MultipleTrusteeOperation == NO_MULTIPLE_TRUSTEE,
161 "MultipleTrusteeOperation wrong\n");
162 ok( trustee.TrusteeForm == TRUSTEE_IS_NAME, "TrusteeForm wrong\n");
163 ok( trustee.TrusteeType == TRUSTEE_IS_UNKNOWN, "TrusteeType wrong\n");
164 ok( trustee.ptstrName == str, "ptstrName wrong\n" );