~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/advapi32/tests/security.c

Version: ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~ [ wine-1.0-rc5 ] ~ [ wine-1.0-rc4 ] ~ [ wine-1.0-rc3 ] ~ [ wine-1.0-rc2 ] ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  1 /*
  2  * Unit tests for security functions
  3  *
  4  * Copyright (c) 2004 Mike McCormack
  5  *
  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.
 10  *
 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.
 15  *
 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 19  */
 20 
 21 #include <stdarg.h>
 22 #include <stdio.h>
 23 
 24 #include "ntstatus.h"
 25 #define WIN32_NO_STATUS
 26 #include "windef.h"
 27 #include "winbase.h"
 28 #include "winerror.h"
 29 #include "aclapi.h"
 30 #include "winnt.h"
 31 #include "sddl.h"
 32 #include "ntsecapi.h"
 33 #include "lmcons.h"
 34 
 35 #include "wine/test.h"
 36 
 37 /* copied from Wine winternl.h - not included in the Windows SDK */
 38 typedef enum _OBJECT_INFORMATION_CLASS {
 39     ObjectBasicInformation,
 40     ObjectNameInformation,
 41     ObjectTypeInformation,
 42     ObjectAllInformation,
 43     ObjectDataInformation
 44 } OBJECT_INFORMATION_CLASS, *POBJECT_INFORMATION_CLASS;
 45 
 46 typedef struct _OBJECT_BASIC_INFORMATION {
 47     ULONG  Attributes;
 48     ACCESS_MASK  GrantedAccess;
 49     ULONG  HandleCount;
 50     ULONG  PointerCount;
 51     ULONG  PagedPoolUsage;
 52     ULONG  NonPagedPoolUsage;
 53     ULONG  Reserved[3];
 54     ULONG  NameInformationLength;
 55     ULONG  TypeInformationLength;
 56     ULONG  SecurityDescriptorLength;
 57     LARGE_INTEGER  CreateTime;
 58 } OBJECT_BASIC_INFORMATION, *POBJECT_BASIC_INFORMATION;
 59 
 60 #define expect_eq(expr, value, type, format) { type ret = expr; ok((value) == ret, #expr " expected " format "  got " format "\n", (value), (ret)); }
 61 
 62 static BOOL (WINAPI *pAddAccessAllowedAceEx)(PACL, DWORD, DWORD, DWORD, PSID);
 63 static BOOL (WINAPI *pAddAccessDeniedAceEx)(PACL, DWORD, DWORD, DWORD, PSID);
 64 static BOOL (WINAPI *pAddAuditAccessAceEx)(PACL, DWORD, DWORD, DWORD, PSID, BOOL, BOOL);
 65 typedef VOID (WINAPI *fnBuildTrusteeWithSidA)( PTRUSTEEA pTrustee, PSID pSid );
 66 typedef VOID (WINAPI *fnBuildTrusteeWithNameA)( PTRUSTEEA pTrustee, LPSTR pName );
 67 typedef VOID (WINAPI *fnBuildTrusteeWithObjectsAndNameA)( PTRUSTEEA pTrustee,
 68                                                           POBJECTS_AND_NAME_A pObjName,
 69                                                           SE_OBJECT_TYPE ObjectType,
 70                                                           LPSTR ObjectTypeName,
 71                                                           LPSTR InheritedObjectTypeName,
 72                                                           LPSTR Name );
 73 typedef VOID (WINAPI *fnBuildTrusteeWithObjectsAndSidA)( PTRUSTEEA pTrustee,
 74                                                          POBJECTS_AND_SID pObjSid,
 75                                                          GUID* pObjectGuid,
 76                                                          GUID* pInheritedObjectGuid,
 77                                                          PSID pSid );
 78 typedef LPSTR (WINAPI *fnGetTrusteeNameA)( PTRUSTEEA pTrustee );
 79 typedef BOOL (WINAPI *fnMakeSelfRelativeSD)( PSECURITY_DESCRIPTOR, PSECURITY_DESCRIPTOR, LPDWORD );
 80 typedef BOOL (WINAPI *fnConvertSidToStringSidA)( PSID pSid, LPSTR *str );
 81 typedef BOOL (WINAPI *fnConvertStringSidToSidA)( LPCSTR str, PSID pSid );
 82 static BOOL (WINAPI *pConvertStringSecurityDescriptorToSecurityDescriptorA)(LPCSTR, DWORD,
 83                                                                             PSECURITY_DESCRIPTOR*, PULONG );
 84 static BOOL (WINAPI *pConvertSecurityDescriptorToStringSecurityDescriptorA)(PSECURITY_DESCRIPTOR, DWORD,
 85                                                                             SECURITY_INFORMATION, LPSTR *, PULONG );
 86 typedef BOOL (WINAPI *fnGetFileSecurityA)(LPCSTR, SECURITY_INFORMATION,
 87                                           PSECURITY_DESCRIPTOR, DWORD, LPDWORD);
 88 static DWORD (WINAPI *pGetNamedSecurityInfoA)(LPSTR, SE_OBJECT_TYPE, SECURITY_INFORMATION,
 89                                               PSID*, PSID*, PACL*, PACL*,
 90                                               PSECURITY_DESCRIPTOR*);
 91 typedef DWORD (WINAPI *fnRtlAdjustPrivilege)(ULONG,BOOLEAN,BOOLEAN,PBOOLEAN);
 92 typedef BOOL (WINAPI *fnCreateWellKnownSid)(WELL_KNOWN_SID_TYPE,PSID,PSID,DWORD*);
 93 typedef BOOL (WINAPI *fnDuplicateTokenEx)(HANDLE,DWORD,LPSECURITY_ATTRIBUTES,
 94                                         SECURITY_IMPERSONATION_LEVEL,TOKEN_TYPE,PHANDLE);
 95 
 96 typedef NTSTATUS (WINAPI *fnLsaQueryInformationPolicy)(LSA_HANDLE,POLICY_INFORMATION_CLASS,PVOID*);
 97 typedef NTSTATUS (WINAPI *fnLsaClose)(LSA_HANDLE);
 98 typedef NTSTATUS (WINAPI *fnLsaFreeMemory)(PVOID);
 99 typedef NTSTATUS (WINAPI *fnLsaOpenPolicy)(PLSA_UNICODE_STRING,PLSA_OBJECT_ATTRIBUTES,ACCESS_MASK,PLSA_HANDLE);
100 static NTSTATUS (WINAPI *pNtQueryObject)(HANDLE,OBJECT_INFORMATION_CLASS,PVOID,ULONG,PULONG);
101 static DWORD (WINAPI *pSetEntriesInAclW)(ULONG, PEXPLICIT_ACCESSW, PACL, PACL*);
102 static BOOL (WINAPI *pSetSecurityDescriptorControl)(PSECURITY_DESCRIPTOR, SECURITY_DESCRIPTOR_CONTROL,
103                                                     SECURITY_DESCRIPTOR_CONTROL);
104 
105 static HMODULE hmod;
106 static int     myARGC;
107 static char**  myARGV;
108 
109 fnBuildTrusteeWithSidA   pBuildTrusteeWithSidA;
110 fnBuildTrusteeWithNameA  pBuildTrusteeWithNameA;
111 fnBuildTrusteeWithObjectsAndNameA pBuildTrusteeWithObjectsAndNameA;
112 fnBuildTrusteeWithObjectsAndSidA pBuildTrusteeWithObjectsAndSidA;
113 fnGetTrusteeNameA pGetTrusteeNameA;
114 fnMakeSelfRelativeSD pMakeSelfRelativeSD;
115 fnConvertSidToStringSidA pConvertSidToStringSidA;
116 fnConvertStringSidToSidA pConvertStringSidToSidA;
117 fnGetFileSecurityA pGetFileSecurityA;
118 fnRtlAdjustPrivilege pRtlAdjustPrivilege;
119 fnCreateWellKnownSid pCreateWellKnownSid;
120 fnDuplicateTokenEx pDuplicateTokenEx;
121 fnLsaQueryInformationPolicy pLsaQueryInformationPolicy;
122 fnLsaClose pLsaClose;
123 fnLsaFreeMemory pLsaFreeMemory;
124 fnLsaOpenPolicy pLsaOpenPolicy;
125 
126 struct sidRef
127 {
128     SID_IDENTIFIER_AUTHORITY auth;
129     const char *refStr;
130 };
131 
132 static void init(void)
133 {
134     HMODULE hntdll;
135 
136     hntdll = GetModuleHandleA("ntdll.dll");
137     pNtQueryObject = (void *)GetProcAddress( hntdll, "NtQueryObject" );
138 
139     hmod = GetModuleHandle("advapi32.dll");
140     pAddAccessAllowedAceEx = (void *)GetProcAddress(hmod, "AddAccessAllowedAceEx");
141     pAddAccessDeniedAceEx = (void *)GetProcAddress(hmod, "AddAccessDeniedAceEx");
142     pAddAuditAccessAceEx = (void *)GetProcAddress(hmod, "AddAuditAccessAceEx");
143     pConvertStringSecurityDescriptorToSecurityDescriptorA =
144         (void *)GetProcAddress(hmod, "ConvertStringSecurityDescriptorToSecurityDescriptorA" );
145     pConvertSecurityDescriptorToStringSecurityDescriptorA =
146         (void *)GetProcAddress(hmod, "ConvertSecurityDescriptorToStringSecurityDescriptorA" );
147     pCreateWellKnownSid = (fnCreateWellKnownSid)GetProcAddress( hmod, "CreateWellKnownSid" );
148     pGetNamedSecurityInfoA = (void *)GetProcAddress(hmod, "GetNamedSecurityInfoA");
149     pMakeSelfRelativeSD = (void *)GetProcAddress(hmod, "MakeSelfRelativeSD");
150     pSetEntriesInAclW = (void *)GetProcAddress(hmod, "SetEntriesInAclW");
151     pSetSecurityDescriptorControl = (void *)GetProcAddress(hmod, "SetSecurityDescriptorControl");
152 
153     myARGC = winetest_get_mainargs( &myARGV );
154 }
155 
156 static void test_str_sid(const char *str_sid)
157 {
158     PSID psid;
159     char *temp;
160 
161     if (pConvertStringSidToSidA(str_sid, &psid))
162     {
163         if (pConvertSidToStringSidA(psid, &temp))
164         {
165             trace(" %s: %s\n", str_sid, temp);
166             LocalFree(temp);
167         }
168         LocalFree(psid);
169     }
170     else
171     {
172         if (GetLastError() != ERROR_INVALID_SID)
173             trace(" %s: couldn't be converted, returned %d\n", str_sid, GetLastError());
174         else
175             trace(" %s: couldn't be converted\n", str_sid);
176     }
177 }
178 
179 static void test_sid(void)
180 {
181     struct sidRef refs[] = {
182      { { {0x00,0x00,0x33,0x44,0x55,0x66} }, "S-1-860116326-1" },
183      { { {0x00,0x00,0x01,0x02,0x03,0x04} }, "S-1-16909060-1"  },
184      { { {0x00,0x00,0x00,0x01,0x02,0x03} }, "S-1-66051-1"     },
185      { { {0x00,0x00,0x00,0x00,0x01,0x02} }, "S-1-258-1"       },
186      { { {0x00,0x00,0x00,0x00,0x00,0x02} }, "S-1-2-1"         },
187      { { {0x00,0x00,0x00,0x00,0x00,0x0c} }, "S-1-12-1"        },
188     };
189     const char noSubAuthStr[] = "S-1-5";
190     unsigned int i;
191     PSID psid = NULL;
192     SID *pisid;
193     BOOL r;
194     LPSTR str = NULL;
195 
196     pConvertSidToStringSidA = (fnConvertSidToStringSidA)
197                     GetProcAddress( hmod, "ConvertSidToStringSidA" );
198     if( !pConvertSidToStringSidA )
199         return;
200     pConvertStringSidToSidA = (fnConvertStringSidToSidA)
201                     GetProcAddress( hmod, "ConvertStringSidToSidA" );
202     if( !pConvertStringSidToSidA )
203         return;
204 
205     r = pConvertStringSidToSidA( NULL, NULL );
206     ok( !r, "expected failure with NULL parameters\n" );
207     if( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED )
208         return;
209     ok( GetLastError() == ERROR_INVALID_PARAMETER,
210      "expected GetLastError() is ERROR_INVALID_PARAMETER, got %d\n",
211      GetLastError() );
212 
213     r = pConvertStringSidToSidA( refs[0].refStr, NULL );
214     ok( !r && GetLastError() == ERROR_INVALID_PARAMETER,
215      "expected GetLastError() is ERROR_INVALID_PARAMETER, got %d\n",
216      GetLastError() );
217 
218     r = pConvertStringSidToSidA( NULL, &str );
219     ok( !r && GetLastError() == ERROR_INVALID_PARAMETER,
220      "expected GetLastError() is ERROR_INVALID_PARAMETER, got %d\n",
221      GetLastError() );
222 
223     r = pConvertStringSidToSidA( noSubAuthStr, &psid );
224     ok( !r,
225      "expected failure with no sub authorities\n" );
226     ok( GetLastError() == ERROR_INVALID_SID,
227      "expected GetLastError() is ERROR_INVALID_SID, got %d\n",
228      GetLastError() );
229 
230     ok(pConvertStringSidToSidA("S-1-5-21-93476-23408-4576", &psid), "ConvertStringSidToSidA failed\n");
231     pisid = (SID *)psid;
232     ok(pisid->SubAuthorityCount == 4, "Invalid sub authority count - expected 4, got %d\n", pisid->SubAuthorityCount);
233     ok(pisid->SubAuthority[0] == 21, "Invalid subauthority 0 - expceted 21, got %d\n", pisid->SubAuthority[0]);
234     ok(pisid->SubAuthority[3] == 4576, "Invalid subauthority 0 - expceted 4576, got %d\n", pisid->SubAuthority[3]);
235     LocalFree(str);
236 
237     for( i = 0; i < sizeof(refs) / sizeof(refs[0]); i++ )
238     {
239         PISID pisid;
240 
241         r = AllocateAndInitializeSid( &refs[i].auth, 1,1,0,0,0,0,0,0,0,
242          &psid );
243         ok( r, "failed to allocate sid\n" );
244         r = pConvertSidToStringSidA( psid, &str );
245         ok( r, "failed to convert sid\n" );
246         if (r)
247         {
248             ok( !strcmp( str, refs[i].refStr ),
249                 "incorrect sid, expected %s, got %s\n", refs[i].refStr, str );
250             LocalFree( str );
251         }
252         if( psid )
253             FreeSid( psid );
254 
255         r = pConvertStringSidToSidA( refs[i].refStr, &psid );
256         ok( r, "failed to parse sid string\n" );
257         pisid = (PISID)psid;
258         ok( pisid &&
259          !memcmp( pisid->IdentifierAuthority.Value, refs[i].auth.Value,
260          sizeof(refs[i].auth) ),
261          "string sid %s didn't parse to expected value\n"
262          "(got 0x%04x%08x, expected 0x%04x%08x)\n",
263          refs[i].refStr,
264          MAKEWORD( pisid->IdentifierAuthority.Value[1],
265          pisid->IdentifierAuthority.Value[0] ),
266          MAKELONG( MAKEWORD( pisid->IdentifierAuthority.Value[5],
267          pisid->IdentifierAuthority.Value[4] ),
268          MAKEWORD( pisid->IdentifierAuthority.Value[3],
269          pisid->IdentifierAuthority.Value[2] ) ),
270          MAKEWORD( refs[i].auth.Value[1], refs[i].auth.Value[0] ),
271          MAKELONG( MAKEWORD( refs[i].auth.Value[5], refs[i].auth.Value[4] ),
272          MAKEWORD( refs[i].auth.Value[3], refs[i].auth.Value[2] ) ) );
273         if( psid )
274             LocalFree( psid );
275     }
276 
277     trace("String SIDs:\n");
278     test_str_sid("AO");
279     test_str_sid("RU");
280     test_str_sid("AN");
281     test_str_sid("AU");
282     test_str_sid("BA");
283     test_str_sid("BG");
284     test_str_sid("BO");
285     test_str_sid("BU");
286     test_str_sid("CA");
287     test_str_sid("CG");
288     test_str_sid("CO");
289     test_str_sid("DA");
290     test_str_sid("DC");
291     test_str_sid("DD");
292     test_str_sid("DG");
293     test_str_sid("DU");
294     test_str_sid("EA");
295     test_str_sid("ED");
296     test_str_sid("WD");
297     test_str_sid("PA");
298     test_str_sid("IU");
299     test_str_sid("LA");
300     test_str_sid("LG");
301     test_str_sid("LS");
302     test_str_sid("SY");
303     test_str_sid("NU");
304     test_str_sid("NO");
305     test_str_sid("NS");
306     test_str_sid("PO");
307     test_str_sid("PS");
308     test_str_sid("PU");
309     test_str_sid("RS");
310     test_str_sid("RD");
311     test_str_sid("RE");
312     test_str_sid("RC");
313     test_str_sid("SA");
314     test_str_sid("SO");
315     test_str_sid("SU");
316 }
317 
318 static void test_trustee(void)
319 {
320     GUID ObjectType = {0x12345678, 0x1234, 0x5678, {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}};
321     GUID InheritedObjectType = {0x23456789, 0x2345, 0x6786, {0x2, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99}};
322     GUID ZeroGuid;
323     OBJECTS_AND_NAME_ oan;
324     OBJECTS_AND_SID oas;
325     TRUSTEE trustee;
326     PSID psid;
327     char szObjectTypeName[] = "ObjectTypeName";
328     char szInheritedObjectTypeName[] = "InheritedObjectTypeName";
329     char szTrusteeName[] = "szTrusteeName";
330     SID_IDENTIFIER_AUTHORITY auth = { {0x11,0x22,0,0,0, 0} };
331 
332     memset( &ZeroGuid, 0x00, sizeof (ZeroGuid) );
333 
334     pBuildTrusteeWithSidA = (fnBuildTrusteeWithSidA)
335                     GetProcAddress( hmod, "BuildTrusteeWithSidA" );
336     pBuildTrusteeWithNameA = (fnBuildTrusteeWithNameA)
337                     GetProcAddress( hmod, "BuildTrusteeWithNameA" );
338     pBuildTrusteeWithObjectsAndNameA = (fnBuildTrusteeWithObjectsAndNameA)
339                     GetProcAddress (hmod, "BuildTrusteeWithObjectsAndNameA" );
340     pBuildTrusteeWithObjectsAndSidA = (fnBuildTrusteeWithObjectsAndSidA)
341                     GetProcAddress (hmod, "BuildTrusteeWithObjectsAndSidA" );
342     pGetTrusteeNameA = (fnGetTrusteeNameA)
343                     GetProcAddress (hmod, "GetTrusteeNameA" );
344     if( !pBuildTrusteeWithSidA || !pBuildTrusteeWithNameA ||
345         !pBuildTrusteeWithObjectsAndNameA || !pBuildTrusteeWithObjectsAndSidA ||
346         !pGetTrusteeNameA )
347         return;
348 
349     if ( ! AllocateAndInitializeSid( &auth, 1, 42, 0,0,0,0,0,0,0,&psid ) )
350     {
351         trace( "failed to init SID\n" );
352        return;
353     }
354 
355     /* test BuildTrusteeWithSidA */
356     memset( &trustee, 0xff, sizeof trustee );
357     pBuildTrusteeWithSidA( &trustee, psid );
358 
359     ok( trustee.pMultipleTrustee == NULL, "pMultipleTrustee wrong\n");
360     ok( trustee.MultipleTrusteeOperation == NO_MULTIPLE_TRUSTEE, 
361         "MultipleTrusteeOperation wrong\n");
362     ok( trustee.TrusteeForm == TRUSTEE_IS_SID, "TrusteeForm wrong\n");
363     ok( trustee.TrusteeType == TRUSTEE_IS_UNKNOWN, "TrusteeType wrong\n");
364     ok( trustee.ptstrName == (LPSTR) psid, "ptstrName wrong\n" );
365 
366     /* test BuildTrusteeWithObjectsAndSidA (test 1) */
367     memset( &trustee, 0xff, sizeof trustee );
368     memset( &oas, 0xff, sizeof(oas) );
369     pBuildTrusteeWithObjectsAndSidA(&trustee, &oas, &ObjectType,
370                                     &InheritedObjectType, psid);
371 
372     ok(trustee.pMultipleTrustee == NULL, "pMultipleTrustee wrong\n");
373     ok(trustee.MultipleTrusteeOperation == NO_MULTIPLE_TRUSTEE, "MultipleTrusteeOperation wrong\n");
374     ok(trustee.TrusteeForm == TRUSTEE_IS_OBJECTS_AND_SID, "TrusteeForm wrong\n");
375     ok(trustee.TrusteeType == TRUSTEE_IS_UNKNOWN, "TrusteeType wrong\n");
376     ok(trustee.ptstrName == (LPSTR)&oas, "ptstrName wrong\n");
377  
378     ok(oas.ObjectsPresent == (ACE_OBJECT_TYPE_PRESENT | ACE_INHERITED_OBJECT_TYPE_PRESENT), "ObjectsPresent wrong\n");
379     ok(!memcmp(&oas.ObjectTypeGuid, &ObjectType, sizeof(GUID)), "ObjectTypeGuid wrong\n");
380     ok(!memcmp(&oas.InheritedObjectTypeGuid, &InheritedObjectType, sizeof(GUID)), "InheritedObjectTypeGuid wrong\n");
381     ok(oas.pSid == psid, "pSid wrong\n");
382 
383     /* test GetTrusteeNameA */
384     ok(pGetTrusteeNameA(&trustee) == (LPSTR)&oas, "GetTrusteeName returned wrong value\n");
385 
386     /* test BuildTrusteeWithObjectsAndSidA (test 2) */
387     memset( &trustee, 0xff, sizeof trustee );
388     memset( &oas, 0xff, sizeof(oas) );
389     pBuildTrusteeWithObjectsAndSidA(&trustee, &oas, NULL,
390                                     &InheritedObjectType, psid);
391 
392     ok(trustee.pMultipleTrustee == NULL, "pMultipleTrustee wrong\n");
393     ok(trustee.MultipleTrusteeOperation == NO_MULTIPLE_TRUSTEE, "MultipleTrusteeOperation wrong\n");
394     ok(trustee.TrusteeForm == TRUSTEE_IS_OBJECTS_AND_SID, "TrusteeForm wrong\n");
395     ok(trustee.TrusteeType == TRUSTEE_IS_UNKNOWN, "TrusteeType wrong\n");
396     ok(trustee.ptstrName == (LPSTR)&oas, "ptstrName wrong\n");
397  
398     ok(oas.ObjectsPresent == ACE_INHERITED_OBJECT_TYPE_PRESENT, "ObjectsPresent wrong\n");
399     ok(!memcmp(&oas.ObjectTypeGuid, &ZeroGuid, sizeof(GUID)), "ObjectTypeGuid wrong\n");
400     ok(!memcmp(&oas.InheritedObjectTypeGuid, &InheritedObjectType, sizeof(GUID)), "InheritedObjectTypeGuid wrong\n");
401     ok(oas.pSid == psid, "pSid wrong\n");
402 
403     FreeSid( psid );
404 
405     /* test BuildTrusteeWithNameA */
406     memset( &trustee, 0xff, sizeof trustee );
407     pBuildTrusteeWithNameA( &trustee, szTrusteeName );
408 
409     ok( trustee.pMultipleTrustee == NULL, "pMultipleTrustee wrong\n");
410     ok( trustee.MultipleTrusteeOperation == NO_MULTIPLE_TRUSTEE, 
411         "MultipleTrusteeOperation wrong\n");
412     ok( trustee.TrusteeForm == TRUSTEE_IS_NAME, "TrusteeForm wrong\n");
413     ok( trustee.TrusteeType == TRUSTEE_IS_UNKNOWN, "TrusteeType wrong\n");
414     ok( trustee.ptstrName == szTrusteeName, "ptstrName wrong\n" );
415 
416     /* test BuildTrusteeWithObjectsAndNameA (test 1) */
417     memset( &trustee, 0xff, sizeof trustee );
418     memset( &oan, 0xff, sizeof(oan) );
419     pBuildTrusteeWithObjectsAndNameA(&trustee, &oan, SE_KERNEL_OBJECT, szObjectTypeName,
420                                      szInheritedObjectTypeName, szTrusteeName);
421 
422     ok(trustee.pMultipleTrustee == NULL, "pMultipleTrustee wrong\n");
423     ok(trustee.MultipleTrusteeOperation == NO_MULTIPLE_TRUSTEE, "MultipleTrusteeOperation wrong\n");
424     ok(trustee.TrusteeForm == TRUSTEE_IS_OBJECTS_AND_NAME, "TrusteeForm wrong\n");
425     ok(trustee.TrusteeType == TRUSTEE_IS_UNKNOWN, "TrusteeType wrong\n");
426     ok(trustee.ptstrName == (LPTSTR)&oan, "ptstrName wrong\n");
427  
428     ok(oan.ObjectsPresent == (ACE_OBJECT_TYPE_PRESENT | ACE_INHERITED_OBJECT_TYPE_PRESENT), "ObjectsPresent wrong\n");
429     ok(oan.ObjectType == SE_KERNEL_OBJECT, "ObjectType wrong\n");
430     ok(oan.InheritedObjectTypeName == szInheritedObjectTypeName, "InheritedObjectTypeName wrong\n");
431     ok(oan.ptstrName == szTrusteeName, "szTrusteeName wrong\n");
432 
433     /* test GetTrusteeNameA */
434     ok(pGetTrusteeNameA(&trustee) == (LPSTR)&oan, "GetTrusteeName returned wrong value\n");
435 
436     /* test BuildTrusteeWithObjectsAndNameA (test 2) */
437     memset( &trustee, 0xff, sizeof trustee );
438     memset( &oan, 0xff, sizeof(oan) );
439     pBuildTrusteeWithObjectsAndNameA(&trustee, &oan, SE_KERNEL_OBJECT, NULL,
440                                      szInheritedObjectTypeName, szTrusteeName);
441 
442     ok(trustee.pMultipleTrustee == NULL, "pMultipleTrustee wrong\n");
443     ok(trustee.MultipleTrusteeOperation == NO_MULTIPLE_TRUSTEE, "MultipleTrusteeOperation wrong\n");
444     ok(trustee.TrusteeForm == TRUSTEE_IS_OBJECTS_AND_NAME, "TrusteeForm wrong\n");
445     ok(trustee.TrusteeType == TRUSTEE_IS_UNKNOWN, "TrusteeType wrong\n");
446     ok(trustee.ptstrName == (LPSTR)&oan, "ptstrName wrong\n");
447  
448     ok(oan.ObjectsPresent == ACE_INHERITED_OBJECT_TYPE_PRESENT, "ObjectsPresent wrong\n");
449     ok(oan.ObjectType == SE_KERNEL_OBJECT, "ObjectType wrong\n");
450     ok(oan.InheritedObjectTypeName == szInheritedObjectTypeName, "InheritedObjectTypeName wrong\n");
451     ok(oan.ptstrName == szTrusteeName, "szTrusteeName wrong\n");
452 
453     /* test BuildTrusteeWithObjectsAndNameA (test 3) */
454     memset( &trustee, 0xff, sizeof trustee );
455     memset( &oan, 0xff, sizeof(oan) );
456     pBuildTrusteeWithObjectsAndNameA(&trustee, &oan, SE_KERNEL_OBJECT, szObjectTypeName,
457                                      NULL, szTrusteeName);
458 
459     ok(trustee.pMultipleTrustee == NULL, "pMultipleTrustee wrong\n");
460     ok(trustee.MultipleTrusteeOperation == NO_MULTIPLE_TRUSTEE, "MultipleTrusteeOperation wrong\n");
461     ok(trustee.TrusteeForm == TRUSTEE_IS_OBJECTS_AND_NAME, "TrusteeForm wrong\n");
462     ok(trustee.TrusteeType == TRUSTEE_IS_UNKNOWN, "TrusteeType wrong\n");
463     ok(trustee.ptstrName == (LPTSTR)&oan, "ptstrName wrong\n");
464  
465     ok(oan.ObjectsPresent == ACE_OBJECT_TYPE_PRESENT, "ObjectsPresent wrong\n");
466     ok(oan.ObjectType == SE_KERNEL_OBJECT, "ObjectType wrong\n");
467     ok(oan.InheritedObjectTypeName == NULL, "InheritedObjectTypeName wrong\n");
468     ok(oan.ptstrName == szTrusteeName, "szTrusteeName wrong\n");
469 }
470  
471 /* If the first isn't defined, assume none is */
472 #ifndef SE_MIN_WELL_KNOWN_PRIVILEGE
473 #define SE_MIN_WELL_KNOWN_PRIVILEGE       2L
474 #define SE_CREATE_TOKEN_PRIVILEGE         2L
475 #define SE_ASSIGNPRIMARYTOKEN_PRIVILEGE   3L
476 #define SE_LOCK_MEMORY_PRIVILEGE          4L
477 #define SE_INCREASE_QUOTA_PRIVILEGE       5L
478 #define SE_MACHINE_ACCOUNT_PRIVILEGE      6L
479 #define SE_TCB_PRIVILEGE                  7L
480 #define SE_SECURITY_PRIVILEGE             8L
481 #define SE_TAKE_OWNERSHIP_PRIVILEGE       9L
482 #define SE_LOAD_DRIVER_PRIVILEGE         10L
483 #define SE_SYSTEM_PROFILE_PRIVILEGE      11L
484 #define SE_SYSTEMTIME_PRIVILEGE          12L
485 #define SE_PROF_SINGLE_PROCESS_PRIVILEGE 13L
486 #define SE_INC_BASE_PRIORITY_PRIVILEGE   14L
487 #define SE_CREATE_PAGEFILE_PRIVILEGE     15L
488 #define SE_CREATE_PERMANENT_PRIVILEGE    16L
489 #define SE_BACKUP_PRIVILEGE              17L
490 #define SE_RESTORE_PRIVILEGE             18L
491 #define SE_SHUTDOWN_PRIVILEGE            19L
492 #define SE_DEBUG_PRIVILEGE               20L
493 #define SE_AUDIT_PRIVILEGE               21L
494 #define SE_SYSTEM_ENVIRONMENT_PRIVILEGE  22L
495 #define SE_CHANGE_NOTIFY_PRIVILLEGE      23L
496 #define SE_REMOTE_SHUTDOWN_PRIVILEGE     24L
497 #define SE_UNDOCK_PRIVILEGE              25L
498 #define SE_SYNC_AGENT_PRIVILEGE          26L
499 #define SE_ENABLE_DELEGATION_PRIVILEGE   27L
500 #define SE_MANAGE_VOLUME_PRIVILEGE       28L
501 #define SE_IMPERSONATE_PRIVILEGE         29L
502 #define SE_CREATE_GLOBAL_PRIVILEGE       30L
503 #define SE_MAX_WELL_KNOWN_PRIVILEGE      SE_CREATE_GLOBAL_PRIVILEGE
504 #endif /* ndef SE_MIN_WELL_KNOWN_PRIVILEGE */
505 
506 static void test_allocateLuid(void)
507 {
508     BOOL (WINAPI *pAllocateLocallyUniqueId)(PLUID);
509     LUID luid1, luid2;
510     BOOL ret;
511 
512     pAllocateLocallyUniqueId = (void*)GetProcAddress(hmod, "AllocateLocallyUniqueId");
513     if (!pAllocateLocallyUniqueId) return;
514 
515     ret = pAllocateLocallyUniqueId(&luid1);
516     if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
517         return;
518 
519     ok(ret,
520      "AllocateLocallyUniqueId failed: %d\n", GetLastError());
521     ret = pAllocateLocallyUniqueId(&luid2);
522     ok( ret,
523      "AllocateLocallyUniqueId failed: %d\n", GetLastError());
524     ok(luid1.LowPart > SE_MAX_WELL_KNOWN_PRIVILEGE || luid1.HighPart != 0,
525      "AllocateLocallyUniqueId returned a well-known LUID\n");
526     ok(luid1.LowPart != luid2.LowPart || luid1.HighPart != luid2.HighPart,
527      "AllocateLocallyUniqueId returned non-unique LUIDs\n");
528     ret = pAllocateLocallyUniqueId(NULL);
529     ok( !ret && GetLastError() == ERROR_NOACCESS,
530      "AllocateLocallyUniqueId(NULL) didn't return ERROR_NOACCESS: %d\n",
531      GetLastError());
532 }
533 
534 static void test_lookupPrivilegeName(void)
535 {
536     BOOL (WINAPI *pLookupPrivilegeNameA)(LPCSTR, PLUID, LPSTR, LPDWORD);
537     char buf[MAX_PATH]; /* arbitrary, seems long enough */
538     DWORD cchName = sizeof(buf);
539     LUID luid = { 0, 0 };
540     LONG i;
541     BOOL ret;
542 
543     /* check whether it's available first */
544     pLookupPrivilegeNameA = (void*)GetProcAddress(hmod, "LookupPrivilegeNameA");
545     if (!pLookupPrivilegeNameA) return;
546     luid.LowPart = SE_CREATE_TOKEN_PRIVILEGE;
547     ret = pLookupPrivilegeNameA(NULL, &luid, buf, &cchName);
548     if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
549         return;
550 
551     /* check with a short buffer */
552     cchName = 0;
553     luid.LowPart = SE_CREATE_TOKEN_PRIVILEGE;
554     ret = pLookupPrivilegeNameA(NULL, &luid, NULL, &cchName);
555     ok( !ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
556      "LookupPrivilegeNameA didn't fail with ERROR_INSUFFICIENT_BUFFER: %d\n",
557      GetLastError());
558     ok(cchName == strlen("SeCreateTokenPrivilege") + 1,
559      "LookupPrivilegeNameA returned an incorrect required length for\n"
560      "SeCreateTokenPrivilege (got %d, expected %d)\n", cchName,
561      lstrlenA("SeCreateTokenPrivilege") + 1);
562     /* check a known value and its returned length on success */
563     cchName = sizeof(buf);
564     ok(pLookupPrivilegeNameA(NULL, &luid, buf, &cchName) &&
565      cchName == strlen("SeCreateTokenPrivilege"),
566      "LookupPrivilegeNameA returned an incorrect output length for\n"
567      "SeCreateTokenPrivilege (got %d, expected %d)\n", cchName,
568      (int)strlen("SeCreateTokenPrivilege"));
569     /* check known values */
570     for (i = SE_MIN_WELL_KNOWN_PRIVILEGE; i < SE_MAX_WELL_KNOWN_PRIVILEGE; i++)
571     {
572         luid.LowPart = i;
573         cchName = sizeof(buf);
574         ret = pLookupPrivilegeNameA(NULL, &luid, buf, &cchName);
575         ok( ret || GetLastError() == ERROR_NO_SUCH_PRIVILEGE,
576          "LookupPrivilegeNameA(0.%d) failed: %d\n", i, GetLastError());
577     }
578     /* check a bogus LUID */
579     luid.LowPart = 0xdeadbeef;
580     cchName = sizeof(buf);
581     ret = pLookupPrivilegeNameA(NULL, &luid, buf, &cchName);
582     ok( !ret && GetLastError() == ERROR_NO_SUCH_PRIVILEGE,
583      "LookupPrivilegeNameA didn't fail with ERROR_NO_SUCH_PRIVILEGE: %d\n",
584      GetLastError());
585     /* check on a bogus system */
586     luid.LowPart = SE_CREATE_TOKEN_PRIVILEGE;
587     cchName = sizeof(buf);
588     ret = pLookupPrivilegeNameA("b0gu5.Nam3", &luid, buf, &cchName);
589     ok( !ret && GetLastError() == RPC_S_SERVER_UNAVAILABLE,
590      "LookupPrivilegeNameA didn't fail with RPC_S_SERVER_UNAVAILABLE: %d\n",
591      GetLastError());
592 }
593 
594 struct NameToLUID
595 {
596     const char *name;
597     DWORD lowPart;
598 };
599 
600 static void test_lookupPrivilegeValue(void)
601 {
602     static const struct NameToLUID privs[] = {
603      { "SeCreateTokenPrivilege", SE_CREATE_TOKEN_PRIVILEGE },
604      { "SeAssignPrimaryTokenPrivilege", SE_ASSIGNPRIMARYTOKEN_PRIVILEGE },
605      { "SeLockMemoryPrivilege", SE_LOCK_MEMORY_PRIVILEGE },
606      { "SeIncreaseQuotaPrivilege", SE_INCREASE_QUOTA_PRIVILEGE },
607      { "SeMachineAccountPrivilege", SE_MACHINE_ACCOUNT_PRIVILEGE },
608      { "SeTcbPrivilege", SE_TCB_PRIVILEGE },
609      { "SeSecurityPrivilege", SE_SECURITY_PRIVILEGE },
610      { "SeTakeOwnershipPrivilege", SE_TAKE_OWNERSHIP_PRIVILEGE },
611      { "SeLoadDriverPrivilege", SE_LOAD_DRIVER_PRIVILEGE },
612      { "SeSystemProfilePrivilege", SE_SYSTEM_PROFILE_PRIVILEGE },
613      { "SeSystemtimePrivilege", SE_SYSTEMTIME_PRIVILEGE },
614      { "SeProfileSingleProcessPrivilege", SE_PROF_SINGLE_PROCESS_PRIVILEGE },
615      { "SeIncreaseBasePriorityPrivilege", SE_INC_BASE_PRIORITY_PRIVILEGE },
616      { "SeCreatePagefilePrivilege", SE_CREATE_PAGEFILE_PRIVILEGE },
617      { "SeCreatePermanentPrivilege", SE_CREATE_PERMANENT_PRIVILEGE },
618      { "SeBackupPrivilege", SE_BACKUP_PRIVILEGE },
619      { "SeRestorePrivilege", SE_RESTORE_PRIVILEGE },
620      { "SeShutdownPrivilege", SE_SHUTDOWN_PRIVILEGE },
621      { "SeDebugPrivilege", SE_DEBUG_PRIVILEGE },
622      { "SeAuditPrivilege", SE_AUDIT_PRIVILEGE },
623      { "SeSystemEnvironmentPrivilege", SE_SYSTEM_ENVIRONMENT_PRIVILEGE },
624      { "SeChangeNotifyPrivilege", SE_CHANGE_NOTIFY_PRIVILLEGE },
625      { "SeRemoteShutdownPrivilege", SE_REMOTE_SHUTDOWN_PRIVILEGE },
626      { "SeUndockPrivilege", SE_UNDOCK_PRIVILEGE },
627      { "SeSyncAgentPrivilege", SE_SYNC_AGENT_PRIVILEGE },
628      { "SeEnableDelegationPrivilege", SE_ENABLE_DELEGATION_PRIVILEGE },
629      { "SeManageVolumePrivilege", SE_MANAGE_VOLUME_PRIVILEGE },
630      { "SeImpersonatePrivilege", SE_IMPERSONATE_PRIVILEGE },
631      { "SeCreateGlobalPrivilege", SE_CREATE_GLOBAL_PRIVILEGE },
632     };
633     BOOL (WINAPI *pLookupPrivilegeValueA)(LPCSTR, LPCSTR, PLUID);
634     int i;
635     LUID luid;
636     BOOL ret;
637 
638     /* check whether it's available first */
639     pLookupPrivilegeValueA = (void*)GetProcAddress(hmod, "LookupPrivilegeValueA");
640     if (!pLookupPrivilegeValueA) return;
641     ret = pLookupPrivilegeValueA(NULL, "SeCreateTokenPrivilege", &luid);
642     if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
643         return;
644 
645     /* check a bogus system name */
646     ret = pLookupPrivilegeValueA("b0gu5.Nam3", "SeCreateTokenPrivilege", &luid);
647     ok( !ret && GetLastError() == RPC_S_SERVER_UNAVAILABLE,
648      "LookupPrivilegeValueA didn't fail with RPC_S_SERVER_UNAVAILABLE: %d\n",
649      GetLastError());
650     /* check a NULL string */
651     ret = pLookupPrivilegeValueA(NULL, 0, &luid);
652     ok( !ret && GetLastError() == ERROR_NO_SUCH_PRIVILEGE,
653      "LookupPrivilegeValueA didn't fail with ERROR_NO_SUCH_PRIVILEGE: %d\n",
654      GetLastError());
655     /* check a bogus privilege name */
656     ret = pLookupPrivilegeValueA(NULL, "SeBogusPrivilege", &luid);
657     ok( !ret && GetLastError() == ERROR_NO_SUCH_PRIVILEGE,
658      "LookupPrivilegeValueA didn't fail with ERROR_NO_SUCH_PRIVILEGE: %d\n",
659      GetLastError());
660     /* check case insensitive */
661     ret = pLookupPrivilegeValueA(NULL, "sEcREATEtOKENpRIVILEGE", &luid);
662     ok( ret,
663      "LookupPrivilegeValueA(NULL, sEcREATEtOKENpRIVILEGE, &luid) failed: %d\n",
664      GetLastError());
665     for (i = 0; i < sizeof(privs) / sizeof(privs[0]); i++)
666     {
667         /* Not all privileges are implemented on all Windows versions, so
668          * don't worry if the call fails
669          */
670         if (pLookupPrivilegeValueA(NULL, privs[i].name, &luid))
671         {
672             ok(luid.LowPart == privs[i].lowPart,
673              "LookupPrivilegeValueA returned an invalid LUID for %s\n",
674              privs[i].name);
675         }
676     }
677 }
678 
679 static void test_luid(void)
680 {
681     test_allocateLuid();
682     test_lookupPrivilegeName();
683     test_lookupPrivilegeValue();
684 }
685 
686 static void test_FileSecurity(void)
687 {
688     char directory[MAX_PATH];
689     DWORD retval, outSize;
690     BOOL result;
691     BYTE buffer[0x40];
692 
693     pGetFileSecurityA = (fnGetFileSecurityA)
694                     GetProcAddress( hmod, "GetFileSecurityA" );
695     if( !pGetFileSecurityA )
696         return;
697 
698     retval = GetTempPathA(sizeof(directory), directory);
699     if (!retval) {
700         trace("GetTempPathA failed\n");
701         return;
702     }
703 
704     strcpy(directory, "\\Should not exist");
705 
706     SetLastError(NO_ERROR);
707     result = pGetFileSecurityA( directory,OWNER_SECURITY_INFORMATION,buffer,0x40,&outSize);
708     ok(!result, "GetFileSecurityA should fail for not existing directories/files\n"); 
709     ok( (GetLastError() == ERROR_FILE_NOT_FOUND ) ||
710         (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) , 
711         "last error ERROR_FILE_NOT_FOUND / ERROR_CALL_NOT_IMPLEMENTED (98) "
712         "expected, got %d\n", GetLastError());
713 }
714 
715 static void test_AccessCheck(void)
716 {
717     PSID EveryoneSid = NULL, AdminSid = NULL, UsersSid = NULL;
718     PACL Acl = NULL;
719     SECURITY_DESCRIPTOR *SecurityDescriptor = NULL;
720     SID_IDENTIFIER_AUTHORITY SIDAuthWorld = { SECURITY_WORLD_SID_AUTHORITY };
721     SID_IDENTIFIER_AUTHORITY SIDAuthNT = { SECURITY_NT_AUTHORITY };
722     GENERIC_MAPPING Mapping = { KEY_READ, KEY_WRITE, KEY_EXECUTE, KEY_ALL_ACCESS };
723     ACCESS_MASK Access;
724     BOOL AccessStatus;
725     HANDLE Token;
726     HANDLE ProcessToken;
727     BOOL ret;
728     DWORD PrivSetLen;
729     PRIVILEGE_SET *PrivSet;
730     BOOL res;
731     HMODULE NtDllModule;
732     BOOLEAN Enabled;
733     DWORD err;
734 
735     NtDllModule = GetModuleHandle("ntdll.dll");
736     if (!NtDllModule)
737     {
738         skip("not running on NT, skipping test\n");
739         return;
740     }
741     pRtlAdjustPrivilege = (fnRtlAdjustPrivilege)
742                           GetProcAddress(NtDllModule, "RtlAdjustPrivilege");
743     if (!pRtlAdjustPrivilege)
744     {
745         skip("missing RtlAdjustPrivilege, skipping test\n");
746         return;
747     }
748 
749     Acl = HeapAlloc(GetProcessHeap(), 0, 256);
750     res = InitializeAcl(Acl, 256, ACL_REVISION);
751     if(!res && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
752     {
753         skip("ACLs not implemented - skipping tests\n");
754         HeapFree(GetProcessHeap(), 0, Acl);
755         return;
756     }
757     ok(res, "InitializeAcl failed with error %d\n", GetLastError());