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