Authors: Dmitry Timoshkov <dmitry@codeweavers.com>, Eric Kohl <ekohl@codeweavers...
[wine] / dlls / advapi32 / security.c
1 /*
2  * dlls/advapi32/security.c
3  *  FIXME: for all functions thunking down to Rtl* functions:  implement SetLastError()
4  */
5 #include <string.h>
6
7 #include "windef.h"
8 #include "winerror.h"
9 #include "heap.h"
10 #include "ntddk.h"
11 #include "ntsecapi.h"
12 #include "debugtools.h"
13
14 DEFAULT_DEBUG_CHANNEL(advapi);
15
16 #define CallWin32ToNt(func) \
17         { NTSTATUS ret; \
18           ret = (func); \
19           if (ret !=STATUS_SUCCESS) \
20           { SetLastError (RtlNtStatusToDosError(ret)); return FALSE; } \
21           return TRUE; \
22         }
23
24 static void dumpLsaAttributes( PLSA_OBJECT_ATTRIBUTES oa )
25 {
26         if (oa)
27         {
28           TRACE("\n\tlength=%lu, rootdir=0x%08x, objectname=%s\n\tattr=0x%08lx, sid=%p qos=%p\n",
29                 oa->Length, oa->RootDirectory,
30                 oa->ObjectName?debugstr_w(oa->ObjectName->Buffer):"null",
31                 oa->Attributes, oa->SecurityDescriptor, oa->SecurityQualityOfService);
32         }
33 }
34
35 /*      ##############################
36         ######  TOKEN FUNCTIONS ######
37         ##############################
38 */
39
40 /******************************************************************************
41  * OpenProcessToken                     [ADVAPI32.@]
42  * Opens the access token associated with a process
43  *
44  * PARAMS
45  *   ProcessHandle [I] Handle to process
46  *   DesiredAccess [I] Desired access to process
47  *   TokenHandle   [O] Pointer to handle of open access token
48  *
49  * RETURNS STD
50  */
51 BOOL WINAPI
52 OpenProcessToken( HANDLE ProcessHandle, DWORD DesiredAccess, 
53                   HANDLE *TokenHandle )
54 {
55         CallWin32ToNt(NtOpenProcessToken( ProcessHandle, DesiredAccess, TokenHandle ));
56 }
57
58 /******************************************************************************
59  * OpenThreadToken [ADVAPI32.@]
60  *
61  * PARAMS
62  *   thread        []
63  *   desiredaccess []
64  *   openasself    []
65  *   thandle       []
66  */
67 BOOL WINAPI
68 OpenThreadToken( HANDLE ThreadHandle, DWORD DesiredAccess, 
69                  BOOL OpenAsSelf, HANDLE *TokenHandle)
70 {
71         CallWin32ToNt (NtOpenThreadToken(ThreadHandle, DesiredAccess, OpenAsSelf, TokenHandle));
72 }
73
74 /******************************************************************************
75  * AdjustTokenPrivileges [ADVAPI32.@]
76  *
77  * PARAMS
78  *   TokenHandle          []
79  *   DisableAllPrivileges []
80  *   NewState             []
81  *   BufferLength         []
82  *   PreviousState        []
83  *   ReturnLength         []
84  */
85 BOOL WINAPI
86 AdjustTokenPrivileges( HANDLE TokenHandle, BOOL DisableAllPrivileges,
87                        LPVOID NewState, DWORD BufferLength, 
88                        LPVOID PreviousState, LPDWORD ReturnLength )
89 {
90         CallWin32ToNt(NtAdjustPrivilegesToken(TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength));
91 }
92
93 /******************************************************************************
94  * CheckTokenMembership [ADVAPI32.@]
95  *
96  * PARAMS
97  *   TokenHandle []
98  *   SidToCheck  []
99  *   IsMember    []
100  */
101 BOOL WINAPI
102 CheckTokenMembership( HANDLE TokenHandle, PSID SidToCheck,
103                       PBOOL IsMember )
104 {
105   FIXME("(0x%08x %p %p) stub!\n", TokenHandle, SidToCheck, IsMember);
106
107   *IsMember = TRUE;
108   return(TRUE);
109 }
110
111 /******************************************************************************
112  * GetTokenInformation [ADVAPI32.@]
113  *
114  * PARAMS
115  *   token           []
116  *   tokeninfoclass  []
117  *   tokeninfo       []
118  *   tokeninfolength []
119  *   retlen          []
120  *
121  */
122 BOOL WINAPI
123 GetTokenInformation( HANDLE token, TOKEN_INFORMATION_CLASS tokeninfoclass, 
124                      LPVOID tokeninfo, DWORD tokeninfolength, LPDWORD retlen )
125 {
126         CallWin32ToNt (NtQueryInformationToken( token, tokeninfoclass, tokeninfo, tokeninfolength, retlen));
127 }
128
129 /*************************************************************************
130  * SetThreadToken [ADVAPI32.@]
131  *
132  * Assigns an "impersonation token" to a thread so it can assume the
133  * security privledges of another thread or process.  Can also remove
134  * a previously assigned token.  Only supported on NT - it's a stub 
135  * exactly like this one on Win9X.
136  *
137  */
138
139 BOOL WINAPI SetThreadToken(PHANDLE thread, HANDLE token)
140 {
141     FIXME("(%p, %x): stub (NT impl. only)\n", thread, token);
142
143     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
144
145     return FALSE;
146 }
147
148 /*      ##############################
149         ######  SID FUNCTIONS   ######
150         ##############################
151 */
152
153 /******************************************************************************
154  * AllocateAndInitializeSid [ADVAPI32.@]
155  *
156  * PARAMS
157  *   pIdentifierAuthority []
158  *   nSubAuthorityCount   []
159  *   nSubAuthority0       []
160  *   nSubAuthority1       []
161  *   nSubAuthority2       []
162  *   nSubAuthority3       []
163  *   nSubAuthority4       []
164  *   nSubAuthority5       []
165  *   nSubAuthority6       []
166  *   nSubAuthority7       []
167  *   pSid                 []
168  */
169 BOOL WINAPI
170 AllocateAndInitializeSid( PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
171                           BYTE nSubAuthorityCount,
172                           DWORD nSubAuthority0, DWORD nSubAuthority1,
173                           DWORD nSubAuthority2, DWORD nSubAuthority3,
174                           DWORD nSubAuthority4, DWORD nSubAuthority5,
175                           DWORD nSubAuthority6, DWORD nSubAuthority7,
176                           PSID *pSid )
177 {
178         CallWin32ToNt (RtlAllocateAndInitializeSid(
179                 pIdentifierAuthority, nSubAuthorityCount, 
180                 nSubAuthority0, nSubAuthority1, nSubAuthority2, nSubAuthority3,
181                 nSubAuthority4, nSubAuthority5, nSubAuthority6, nSubAuthority7,
182                 pSid ));
183 }
184
185 /******************************************************************************
186  * FreeSid [ADVAPI32.@]
187  *
188  * PARAMS
189  *   pSid []
190  */
191 PVOID WINAPI
192 FreeSid( PSID pSid )
193 {
194         RtlFreeSid(pSid); 
195         return NULL; /* is documented like this */
196 }
197
198 /******************************************************************************
199  * CopySid [ADVAPI32.@]
200  *
201  * PARAMS
202  *   nDestinationSidLength []
203  *   pDestinationSid       []
204  *   pSourceSid            []
205  */
206 BOOL WINAPI
207 CopySid( DWORD nDestinationSidLength, PSID pDestinationSid, PSID pSourceSid )
208 {
209         return RtlCopySid(nDestinationSidLength, pDestinationSid, pSourceSid);
210 }
211
212 /******************************************************************************
213  * IsValidSid [ADVAPI32.@]
214  *
215  * PARAMS
216  *   pSid []
217  */
218 BOOL WINAPI
219 IsValidSid( PSID pSid )
220 {
221         return RtlValidSid( pSid );
222 }
223
224 /******************************************************************************
225  * EqualSid [ADVAPI32.@]
226  *
227  * PARAMS
228  *   pSid1 []
229  *   pSid2 []
230  */
231 BOOL WINAPI
232 EqualSid( PSID pSid1, PSID pSid2 )
233 {
234         return RtlEqualSid( pSid1, pSid2 );
235 }
236
237 /******************************************************************************
238  * EqualPrefixSid [ADVAPI32.@]
239  */
240 BOOL WINAPI EqualPrefixSid (PSID pSid1, PSID pSid2) 
241 {
242         return RtlEqualPrefixSid(pSid1, pSid2);
243 }
244
245 /******************************************************************************
246  * GetSidLengthRequired [ADVAPI32.@]
247  *
248  * PARAMS
249  *   nSubAuthorityCount []
250  */
251 DWORD WINAPI
252 GetSidLengthRequired( BYTE nSubAuthorityCount )
253 {
254         return RtlLengthRequiredSid(nSubAuthorityCount);
255 }
256
257 /******************************************************************************
258  * InitializeSid [ADVAPI32.@]
259  *
260  * PARAMS
261  *   pIdentifierAuthority []
262  */
263 BOOL WINAPI
264 InitializeSid (
265         PSID pSid,
266         PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
267         BYTE nSubAuthorityCount)
268 {
269         return RtlInitializeSid(pSid, pIdentifierAuthority, nSubAuthorityCount);
270 }
271
272 /******************************************************************************
273  * GetSidIdentifierAuthority [ADVAPI32.@]
274  *
275  * PARAMS
276  *   pSid []
277  */
278 PSID_IDENTIFIER_AUTHORITY WINAPI
279 GetSidIdentifierAuthority( PSID pSid )
280 {
281         return RtlIdentifierAuthoritySid(pSid);
282 }
283
284 /******************************************************************************
285  * GetSidSubAuthority [ADVAPI32.@]
286  *
287  * PARAMS
288  *   pSid          []
289  *   nSubAuthority []
290  */
291 PDWORD WINAPI
292 GetSidSubAuthority( PSID pSid, DWORD nSubAuthority )
293 {
294         return RtlSubAuthoritySid(pSid, nSubAuthority);
295 }
296
297 /******************************************************************************
298  * GetSidSubAuthorityCount [ADVAPI32.@]
299  *
300  * PARAMS
301  *   pSid []
302  */
303 PUCHAR WINAPI
304 GetSidSubAuthorityCount (PSID pSid)
305 {
306         return RtlSubAuthorityCountSid(pSid);
307 }
308
309 /******************************************************************************
310  * GetLengthSid [ADVAPI32.@]
311  *
312  * PARAMS
313  *   pSid []
314  */
315 DWORD WINAPI
316 GetLengthSid (PSID pSid)
317 {
318         return RtlLengthSid(pSid);
319 }
320
321 /*      ##############################################
322         ######  SECURITY DESCRIPTOR FUNCTIONS   ######
323         ##############################################
324 */
325         
326 /******************************************************************************
327  * InitializeSecurityDescriptor [ADVAPI32.@]
328  *
329  * PARAMS
330  *   pDescr   []
331  *   revision []
332  */
333 BOOL WINAPI
334 InitializeSecurityDescriptor( SECURITY_DESCRIPTOR *pDescr, DWORD revision )
335 {
336         CallWin32ToNt (RtlCreateSecurityDescriptor(pDescr, revision ));
337 }
338
339 /******************************************************************************
340  * GetSecurityDescriptorLength [ADVAPI32.@]
341  */
342 DWORD WINAPI GetSecurityDescriptorLength( SECURITY_DESCRIPTOR *pDescr)
343 {
344         return (RtlLengthSecurityDescriptor(pDescr));
345 }
346
347 /******************************************************************************
348  * GetSecurityDescriptorOwner [ADVAPI32.@]
349  *
350  * PARAMS
351  *   pOwner            []
352  *   lpbOwnerDefaulted []
353  */
354 BOOL WINAPI
355 GetSecurityDescriptorOwner( SECURITY_DESCRIPTOR *pDescr, PSID *pOwner,
356                             LPBOOL lpbOwnerDefaulted )
357 {
358         CallWin32ToNt (RtlGetOwnerSecurityDescriptor( pDescr, pOwner, (PBOOLEAN)lpbOwnerDefaulted ));
359 }
360
361 /******************************************************************************
362  * SetSecurityDescriptorOwner [ADVAPI32.@]
363  *
364  * PARAMS
365  */
366 BOOL WINAPI SetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pSecurityDescriptor, 
367                                    PSID pOwner, BOOL bOwnerDefaulted)
368 {
369         CallWin32ToNt (RtlSetOwnerSecurityDescriptor(pSecurityDescriptor, pOwner, bOwnerDefaulted));
370 }
371 /******************************************************************************
372  * GetSecurityDescriptorGroup                   [ADVAPI32.@]
373  */
374 BOOL WINAPI GetSecurityDescriptorGroup(
375         PSECURITY_DESCRIPTOR SecurityDescriptor,
376         PSID *Group,
377         LPBOOL GroupDefaulted)
378 {
379         CallWin32ToNt (RtlGetGroupSecurityDescriptor(SecurityDescriptor, Group, (PBOOLEAN)GroupDefaulted));
380 }       
381 /******************************************************************************
382  * SetSecurityDescriptorGroup [ADVAPI32.@]
383  */
384 BOOL WINAPI SetSecurityDescriptorGroup ( PSECURITY_DESCRIPTOR SecurityDescriptor,
385                                            PSID Group, BOOL GroupDefaulted)
386 {
387         CallWin32ToNt (RtlSetGroupSecurityDescriptor( SecurityDescriptor, Group, GroupDefaulted));
388 }
389
390 /******************************************************************************
391  * IsValidSecurityDescriptor [ADVAPI32.@]
392  *
393  * PARAMS
394  *   lpsecdesc []
395  */
396 BOOL WINAPI
397 IsValidSecurityDescriptor( PSECURITY_DESCRIPTOR SecurityDescriptor )
398 {
399         CallWin32ToNt (RtlValidSecurityDescriptor(SecurityDescriptor));
400 }
401
402 /******************************************************************************
403  *  GetSecurityDescriptorDacl                   [ADVAPI32.@]
404  */
405 BOOL WINAPI GetSecurityDescriptorDacl(
406         IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
407         OUT LPBOOL lpbDaclPresent,
408         OUT PACL *pDacl,
409         OUT LPBOOL lpbDaclDefaulted)
410 {
411         CallWin32ToNt (RtlGetDaclSecurityDescriptor(pSecurityDescriptor, (PBOOLEAN)lpbDaclPresent,
412                                                pDacl, (PBOOLEAN)lpbDaclDefaulted));
413 }       
414
415 /******************************************************************************
416  *  SetSecurityDescriptorDacl                   [ADVAPI32.@]
417  */
418 BOOL WINAPI 
419 SetSecurityDescriptorDacl (
420         PSECURITY_DESCRIPTOR lpsd,
421         BOOL daclpresent,
422         PACL dacl,
423         BOOL dacldefaulted )
424 {
425         CallWin32ToNt (RtlSetDaclSecurityDescriptor (lpsd, daclpresent, dacl, dacldefaulted ));
426 }
427 /******************************************************************************
428  *  GetSecurityDescriptorSacl                   [ADVAPI32.@]
429  */
430 BOOL WINAPI GetSecurityDescriptorSacl(
431         IN PSECURITY_DESCRIPTOR lpsd,
432         OUT LPBOOL lpbSaclPresent,
433         OUT PACL *pSacl,
434         OUT LPBOOL lpbSaclDefaulted)
435 {
436         CallWin32ToNt (RtlGetSaclSecurityDescriptor(lpsd,
437            (PBOOLEAN)lpbSaclPresent, pSacl, (PBOOLEAN)lpbSaclDefaulted));
438 }       
439
440 /**************************************************************************
441  * SetSecurityDescriptorSacl                    [ADVAPI32.@]
442  */
443 BOOL WINAPI SetSecurityDescriptorSacl (
444         PSECURITY_DESCRIPTOR lpsd,
445         BOOL saclpresent,
446         PACL lpsacl,
447         BOOL sacldefaulted)
448 {
449         CallWin32ToNt (RtlSetSaclSecurityDescriptor(lpsd, saclpresent, lpsacl, sacldefaulted));
450 }
451 /******************************************************************************
452  * MakeSelfRelativeSD [ADVAPI32.@]
453  *
454  * PARAMS
455  *   lpabssecdesc  []
456  *   lpselfsecdesc []
457  *   lpbuflen      []
458  */
459 BOOL WINAPI
460 MakeSelfRelativeSD(
461         IN PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
462         IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
463         IN OUT LPDWORD lpdwBufferLength)
464 {
465         CallWin32ToNt (RtlMakeSelfRelativeSD(pAbsoluteSecurityDescriptor,pSelfRelativeSecurityDescriptor, lpdwBufferLength));
466 }
467
468 /******************************************************************************
469  * GetSecurityDescriptorControl                 [ADVAPI32.@]
470  */
471
472 BOOL WINAPI GetSecurityDescriptorControl ( PSECURITY_DESCRIPTOR  pSecurityDescriptor,
473                  PSECURITY_DESCRIPTOR_CONTROL pControl, LPDWORD lpdwRevision)
474 {
475         CallWin32ToNt (RtlGetControlSecurityDescriptor(pSecurityDescriptor,pControl,lpdwRevision));
476 }               
477
478 /*      ##############################
479         ######  ACL FUNCTIONS   ######
480         ##############################
481 */
482
483 /*************************************************************************
484  * InitializeAcl [ADVAPI32.@]
485  */
486 DWORD WINAPI InitializeAcl(PACL acl, DWORD size, DWORD rev)
487 {
488         CallWin32ToNt (RtlCreateAcl(acl, size, rev));
489 }
490
491 /*      ##############################
492         ######  MISC FUNCTIONS  ######
493         ##############################
494 */
495
496 /******************************************************************************
497  * LookupPrivilegeValueW                        [ADVAPI32.@]
498  * Retrieves LUID used on a system to represent the privilege name.
499  *
500  * NOTES
501  *   lpLuid should be PLUID
502  *
503  * PARAMS
504  *   lpSystemName [I] Address of string specifying the system
505  *   lpName       [I] Address of string specifying the privilege
506  *   lpLuid       [I] Address of locally unique identifier
507  *
508  * RETURNS STD
509  */
510 BOOL WINAPI
511 LookupPrivilegeValueW( LPCWSTR lpSystemName, LPCWSTR lpName, LPVOID lpLuid )
512 {
513     FIXME("(%s,%s,%p): stub\n",debugstr_w(lpSystemName), 
514         debugstr_w(lpName), lpLuid);
515     return TRUE;
516 }
517
518 /******************************************************************************
519  * LookupPrivilegeValueA                        [ADVAPI32.@]
520  */
521 BOOL WINAPI
522 LookupPrivilegeValueA( LPCSTR lpSystemName, LPCSTR lpName, LPVOID lpLuid )
523 {
524     LPWSTR lpSystemNameW = HEAP_strdupAtoW(GetProcessHeap(), 0, lpSystemName);
525     LPWSTR lpNameW = HEAP_strdupAtoW(GetProcessHeap(), 0, lpName);
526     BOOL ret;
527
528     ret = LookupPrivilegeValueW( lpSystemNameW, lpNameW, lpLuid);
529     HeapFree(GetProcessHeap(), 0, lpNameW);
530     HeapFree(GetProcessHeap(), 0, lpSystemNameW);
531     return ret;
532 }
533
534 /******************************************************************************
535  * GetFileSecurityA [ADVAPI32.@]
536  *
537  * Obtains Specified information about the security of a file or directory
538  * The information obtained is constrained by the callers access rights and
539  * privileges
540  */
541 BOOL WINAPI
542 GetFileSecurityA( LPCSTR lpFileName, 
543                     SECURITY_INFORMATION RequestedInformation,
544                     PSECURITY_DESCRIPTOR pSecurityDescriptor,
545                     DWORD nLength, LPDWORD lpnLengthNeeded )
546 {
547   FIXME("(%s) : stub\n", debugstr_a(lpFileName));
548   return TRUE;
549 }
550
551 /******************************************************************************
552  * GetFileSecurityW [ADVAPI32.@]
553  *
554  * Obtains Specified information about the security of a file or directory
555  * The information obtained is constrained by the callers access rights and
556  * privileges
557  *
558  * PARAMS
559  *   lpFileName           []
560  *   RequestedInformation []
561  *   pSecurityDescriptor  []
562  *   nLength              []
563  *   lpnLengthNeeded      []
564  */
565 BOOL WINAPI
566 GetFileSecurityW( LPCWSTR lpFileName, 
567                     SECURITY_INFORMATION RequestedInformation,
568                     PSECURITY_DESCRIPTOR pSecurityDescriptor,
569                     DWORD nLength, LPDWORD lpnLengthNeeded )
570 {
571   FIXME("(%s) : stub\n", debugstr_w(lpFileName) ); 
572   return TRUE;
573 }
574
575
576 /******************************************************************************
577  * LookupAccountSidA [ADVAPI32.@]
578  */
579 BOOL WINAPI
580 LookupAccountSidA(
581         IN LPCSTR system,
582         IN PSID sid,
583         OUT LPSTR account,
584         IN OUT LPDWORD accountSize,
585         OUT LPSTR domain,
586         IN OUT LPDWORD domainSize,
587         OUT PSID_NAME_USE name_use )
588 {
589         static const char ac[] = "Administrator";
590         static const char dm[] = "DOMAIN";
591         FIXME("(%s,sid=%p,%p,%p(%lu),%p,%p(%lu),%p): semi-stub\n",
592               debugstr_a(system),sid,
593               account,accountSize,accountSize?*accountSize:0,
594               domain,domainSize,domainSize?*domainSize:0,
595               name_use);
596
597         if (accountSize) *accountSize = strlen(ac)+1;
598         if (account && (*accountSize > strlen(ac)))
599           strcpy(account, ac);
600
601         if (domainSize) *domainSize = strlen(dm)+1;
602         if (domain && (*domainSize > strlen(dm)))
603           strcpy(domain,dm);
604
605         if (name_use) *name_use = SidTypeUser;
606         return TRUE;
607 }
608
609 /******************************************************************************
610  * LookupAccountSidW [ADVAPI32.@]
611  *
612  * PARAMS
613  *   system      []
614  *   sid         []
615  *   account     []
616  *   accountSize []
617  *   domain      []
618  *   domainSize  []
619  *   name_use    []
620  */
621 BOOL WINAPI
622 LookupAccountSidW(
623         IN LPCWSTR system,
624         IN PSID sid,
625         OUT LPWSTR account,
626         IN OUT LPDWORD accountSize,
627         OUT LPWSTR domain,
628         IN OUT LPDWORD domainSize,
629         OUT PSID_NAME_USE name_use )
630 {
631     static const WCHAR ac[] = {'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
632     static const WCHAR dm[] = {'D','O','M','A','I','N',0};
633         FIXME("(%s,sid=%p,%p,%p(%lu),%p,%p(%lu),%p): semi-stub\n",
634               debugstr_w(system),sid,
635               account,accountSize,accountSize?*accountSize:0,
636               domain,domainSize,domainSize?*domainSize:0,
637               name_use);
638
639         if (accountSize) *accountSize = strlenW(ac)+1;
640         if (account && (*accountSize > strlenW(ac)))
641             strcpyW(account, ac);
642
643         if (domainSize) *domainSize = strlenW(dm)+1;
644         if (domain && (*domainSize > strlenW(dm)))
645             strcpyW(domain,dm);
646
647         if (name_use) *name_use = SidTypeUser;
648         return TRUE;
649 }
650
651 /******************************************************************************
652  * SetFileSecurityA [ADVAPI32.@]
653  * Sets the security of a file or directory
654  */
655 BOOL WINAPI SetFileSecurityA( LPCSTR lpFileName,
656                                 SECURITY_INFORMATION RequestedInformation,
657                                 PSECURITY_DESCRIPTOR pSecurityDescriptor)
658 {
659   FIXME("(%s) : stub\n", debugstr_a(lpFileName));
660   return TRUE;
661 }
662
663 /******************************************************************************
664  * SetFileSecurityW [ADVAPI32.@]
665  * Sets the security of a file or directory
666  *
667  * PARAMS
668  *   lpFileName           []
669  *   RequestedInformation []
670  *   pSecurityDescriptor  []
671  */
672 BOOL WINAPI
673 SetFileSecurityW( LPCWSTR lpFileName, 
674                     SECURITY_INFORMATION RequestedInformation,
675                     PSECURITY_DESCRIPTOR pSecurityDescriptor )
676 {
677   FIXME("(%s) : stub\n", debugstr_w(lpFileName) ); 
678   return TRUE;
679 }
680
681 /******************************************************************************
682  * QueryWindows31FilesMigration [ADVAPI32.@]
683  *
684  * PARAMS
685  *   x1 []
686  */
687 BOOL WINAPI
688 QueryWindows31FilesMigration( DWORD x1 )
689 {
690         FIXME("(%ld):stub\n",x1);
691         return TRUE;
692 }
693
694 /******************************************************************************
695  * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.@]
696  *
697  * PARAMS
698  *   x1 []
699  *   x2 []
700  *   x3 []
701  *   x4 []
702  */
703 BOOL WINAPI
704 SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1, DWORD x2, DWORD x3,
705                                                DWORD x4 )
706 {
707         FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx):stub\n",x1,x2,x3,x4);
708         return TRUE;
709 }
710
711 /******************************************************************************
712  * LsaOpenPolicy [ADVAPI32.@]
713  *
714  * PARAMS
715  *   x1 []
716  *   x2 []
717  *   x3 []
718  *   x4 []
719  */
720 NTSTATUS WINAPI
721 LsaOpenPolicy(
722         IN PLSA_UNICODE_STRING SystemName,
723         IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes,
724         IN ACCESS_MASK DesiredAccess,
725         IN OUT PLSA_HANDLE PolicyHandle)
726 {
727         FIXME("(%s,%p,0x%08lx,%p):stub\n",
728               SystemName?debugstr_w(SystemName->Buffer):"null",
729               ObjectAttributes, DesiredAccess, PolicyHandle);
730         dumpLsaAttributes(ObjectAttributes);
731         if(PolicyHandle) *PolicyHandle = (LSA_HANDLE)0xcafe;
732         return TRUE;
733 }
734
735 /******************************************************************************
736  * LsaQueryInformationPolicy [ADVAPI32.@]
737  */
738 NTSTATUS WINAPI
739 LsaQueryInformationPolicy( 
740         IN LSA_HANDLE PolicyHandle,
741         IN POLICY_INFORMATION_CLASS InformationClass,
742         OUT PVOID *Buffer)
743 {
744         FIXME("(%p,0x%08x,%p):stub\n",
745               PolicyHandle, InformationClass, Buffer);
746
747         if(!Buffer) return FALSE;
748         switch (InformationClass)
749         {
750           case PolicyAuditEventsInformation: /* 2 */
751             {
752               PPOLICY_AUDIT_EVENTS_INFO p = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(POLICY_AUDIT_EVENTS_INFO));
753               p->AuditingMode = FALSE; /* no auditing */
754               *Buffer = p;
755             }
756             break;
757           case PolicyPrimaryDomainInformation: /* 3 */
758           case PolicyAccountDomainInformation: /* 5 */
759             {
760               struct di
761               { POLICY_PRIMARY_DOMAIN_INFO ppdi;
762                 SID sid;
763               };
764               SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
765                 
766               struct di * xdi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(xdi));
767               RtlInitUnicodeString(&(xdi->ppdi.Name), HEAP_strdupAtoW(GetProcessHeap(),0,"DOMAIN"));
768               xdi->ppdi.Sid = &(xdi->sid);
769               xdi->sid.Revision = SID_REVISION;
770               xdi->sid.SubAuthorityCount = 1;
771               xdi->sid.IdentifierAuthority = localSidAuthority;
772               xdi->sid.SubAuthority[0] = SECURITY_LOCAL_SYSTEM_RID;
773               *Buffer = xdi;
774             }
775             break;
776           case  PolicyAuditLogInformation:      
777           case  PolicyPdAccountInformation:     
778           case  PolicyLsaServerRoleInformation:
779           case  PolicyReplicaSourceInformation:
780           case  PolicyDefaultQuotaInformation:
781           case  PolicyModificationInformation:
782           case  PolicyAuditFullSetInformation:
783           case  PolicyAuditFullQueryInformation:
784           case  PolicyDnsDomainInformation:
785             {
786               FIXME("category not implemented\n");
787               return FALSE;
788             }
789         }
790         return TRUE; 
791 }                         
792
793 /******************************************************************************
794  * LsaLookupSids [ADVAPI32.@]
795  */
796 typedef struct
797 {
798         SID_NAME_USE Use;
799         LSA_UNICODE_STRING Name;
800         LONG DomainIndex;
801 } LSA_TRANSLATED_NAME, *PLSA_TRANSLATED_NAME;
802
803 typedef struct 
804 {
805         LSA_UNICODE_STRING Name;
806         PSID Sid;
807 } LSA_TRUST_INFORMATION, *PLSA_TRUST_INFORMATION;
808
809 typedef struct 
810 {
811         ULONG Entries;
812         PLSA_TRUST_INFORMATION Domains;
813 } LSA_REFERENCED_DOMAIN_LIST, *PLSA_REFERENCED_DOMAIN_LIST;
814
815 NTSTATUS WINAPI
816 LsaLookupSids(
817         IN LSA_HANDLE PolicyHandle,
818         IN ULONG Count,
819         IN PSID *Sids,
820         OUT PLSA_REFERENCED_DOMAIN_LIST *ReferencedDomains,
821         OUT PLSA_TRANSLATED_NAME *Names )
822 {
823         FIXME("%p %lu %p %p %p\n",
824           PolicyHandle, Count, Sids, ReferencedDomains, Names);
825         return FALSE;
826 }
827
828 /******************************************************************************
829  * LsaFreeMemory [ADVAPI32.@]
830  */
831 NTSTATUS WINAPI
832 LsaFreeMemory(IN PVOID Buffer)
833 {
834         TRACE("(%p)\n",Buffer);
835         return HeapFree(GetProcessHeap(), 0, Buffer);
836 }
837 /******************************************************************************
838  * LsaClose [ADVAPI32.@]
839  */
840 NTSTATUS WINAPI
841 LsaClose(IN LSA_HANDLE ObjectHandle)
842 {
843         FIXME("(%p):stub\n",ObjectHandle);
844         return 0xc0000000;
845 }
846 /******************************************************************************
847  * NotifyBootConfigStatus [ADVAPI32.@]
848  *
849  * PARAMS
850  *   x1 []
851  */
852 BOOL WINAPI
853 NotifyBootConfigStatus( DWORD x1 )
854 {
855         FIXME("(0x%08lx):stub\n",x1);
856         return 1;
857 }
858
859 /******************************************************************************
860  * RevertToSelf [ADVAPI32.@]
861  *
862  * PARAMS
863  *   void []
864  */
865 BOOL WINAPI
866 RevertToSelf( void )
867 {
868         FIXME("(), stub\n");
869         return TRUE;
870 }
871
872 /******************************************************************************
873  * ImpersonateSelf [ADVAPI32.@]
874  */
875 BOOL WINAPI
876 ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
877 {
878         return RtlImpersonateSelf(ImpersonationLevel);
879 }
880
881 /******************************************************************************
882  * AccessCheck [ADVAPI32.@]
883  *
884  * FIXME check cast LPBOOL to PBOOLEAN
885  */
886 BOOL WINAPI
887 AccessCheck(
888         PSECURITY_DESCRIPTOR SecurityDescriptor,
889         HANDLE ClientToken,
890         DWORD DesiredAccess,
891         PGENERIC_MAPPING GenericMapping,
892         PPRIVILEGE_SET PrivilegeSet,
893         LPDWORD PrivilegeSetLength,
894         LPDWORD GrantedAccess,
895         LPBOOL AccessStatus)
896 {
897         CallWin32ToNt (NtAccessCheck(SecurityDescriptor, ClientToken, DesiredAccess,
898           GenericMapping, PrivilegeSet, PrivilegeSetLength, GrantedAccess, (PBOOLEAN)AccessStatus));
899 }
900
901 /*************************************************************************
902  * SetKernelObjectSecurity [ADVAPI32.@]
903  */
904 BOOL WINAPI SetKernelObjectSecurity (
905         IN HANDLE Handle,
906         IN SECURITY_INFORMATION SecurityInformation,
907         IN PSECURITY_DESCRIPTOR SecurityDescriptor )
908 {
909         CallWin32ToNt (NtSetSecurityObject (Handle, SecurityInformation, SecurityDescriptor));
910 }
911
912 /******************************************************************************
913  *  AddAccessAllowedAce [ADVAPI32.@]
914  */
915 BOOL WINAPI AddAccessAllowedAce(
916         IN OUT PACL pAcl,
917         IN DWORD dwAceRevision,
918         IN DWORD AccessMask,
919         IN PSID pSid)
920 {
921         return RtlAddAccessAllowedAce(pAcl, dwAceRevision, AccessMask, pSid);
922 }
923
924 /******************************************************************************
925  * LookupAccountNameA [ADVAPI32.@]
926  */
927 BOOL WINAPI
928 LookupAccountNameA(
929         IN LPCSTR system,
930         IN LPCSTR account,
931         OUT PSID sid,
932         OUT LPDWORD cbSid,
933         LPSTR ReferencedDomainName,
934         IN OUT LPDWORD cbReferencedDomainName,
935         OUT PSID_NAME_USE name_use )
936 {
937     FIXME("(%s,%s,%p,%p,%p,%p,%p), stub.\n",system,account,sid,cbSid,ReferencedDomainName,cbReferencedDomainName,name_use);
938     return FALSE;
939 }
940
941 /******************************************************************************
942  * GetAce [ADVAPI32.@]
943  */
944 BOOL WINAPI GetAce(PACL pAcl,DWORD dwAceIndex,LPVOID *pAce )
945 {
946     CallWin32ToNt(RtlGetAce(pAcl, dwAceIndex, pAce));
947 }