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