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