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