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