Free the debug info when making a critical section global.
[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 "rpcnterr.h"
26 #include "winternl.h"
27 #include "ntsecapi.h"
28 #include "accctrl.h"
29
30 #include "wine/debug.h"
31 #include "wine/unicode.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
34
35 #define CallWin32ToNt(func) \
36         { NTSTATUS ret; \
37           ret = (func); \
38           if (ret !=STATUS_SUCCESS) \
39           { SetLastError (RtlNtStatusToDosError(ret)); return FALSE; } \
40           return TRUE; \
41         }
42
43 static void dumpLsaAttributes( PLSA_OBJECT_ATTRIBUTES oa )
44 {
45         if (oa)
46         {
47           TRACE("\n\tlength=%lu, rootdir=%p, objectname=%s\n\tattr=0x%08lx, sid=%p qos=%p\n",
48                 oa->Length, oa->RootDirectory,
49                 oa->ObjectName?debugstr_w(oa->ObjectName->Buffer):"null",
50                 oa->Attributes, oa->SecurityDescriptor, oa->SecurityQualityOfService);
51         }
52 }
53
54 /************************************************************
55  *                ADVAPI_IsLocalComputer
56  *
57  * Checks whether the server name indicates local machine.
58  */
59 BOOL ADVAPI_IsLocalComputer(LPCWSTR ServerName)
60 {
61     if (!ServerName)
62     {
63         return TRUE;
64     }
65     else
66     {
67         DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
68         BOOL Result;
69         LPWSTR buf;
70
71         buf = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
72         Result = GetComputerNameW(buf,  &dwSize);
73         if (Result && (ServerName[0] == '\\') && (ServerName[1] == '\\'))
74             ServerName += 2;
75         Result = Result && !lstrcmpW(ServerName, buf);
76         HeapFree(GetProcessHeap(), 0, buf);
77
78         return Result;
79     }
80 }
81
82 #define ADVAPI_ForceLocalComputer(ServerName, FailureCode) \
83     if (!ADVAPI_IsLocalComputer(ServerName)) \
84     { \
85         FIXME("Action Implemented for local computer only. " \
86               "Requested for server %s\n", debugstr_w(ServerName)); \
87         return FailureCode; \
88     }
89
90 /*      ##############################
91         ######  TOKEN FUNCTIONS ######
92         ##############################
93 */
94
95 /******************************************************************************
96  * OpenProcessToken                     [ADVAPI32.@]
97  * Opens the access token associated with a process handle.
98  *
99  * PARAMS
100  *   ProcessHandle [I] Handle to process
101  *   DesiredAccess [I] Desired access to process
102  *   TokenHandle   [O] Pointer to handle of open access token
103  *
104  * RETURNS
105  *  Success: TRUE. TokenHandle contains the access token.
106  *  Failure: FALSE.
107  *
108  * NOTES
109  *  See NtOpenProcessToken.
110  */
111 BOOL WINAPI
112 OpenProcessToken( HANDLE ProcessHandle, DWORD DesiredAccess,
113                   HANDLE *TokenHandle )
114 {
115         CallWin32ToNt(NtOpenProcessToken( ProcessHandle, DesiredAccess, TokenHandle ));
116 }
117
118 /******************************************************************************
119  * OpenThreadToken [ADVAPI32.@]
120  *
121  * Opens the access token associated with a thread handle.
122  *
123  * PARAMS
124  *   ThreadHandle  [I] Handle to process
125  *   DesiredAccess [I] Desired access to the thread
126  *   OpenAsSelf    [I] ???
127  *   TokenHandle   [O] Destination for the token handle
128  *
129  * RETURNS
130  *  Success: TRUE. TokenHandle contains the access token.
131  *  Failure: FALSE.
132  *
133  * NOTES
134  *  See NtOpenThreadToken.
135  */
136 BOOL WINAPI
137 OpenThreadToken( HANDLE ThreadHandle, DWORD DesiredAccess,
138                  BOOL OpenAsSelf, HANDLE *TokenHandle)
139 {
140         CallWin32ToNt (NtOpenThreadToken(ThreadHandle, DesiredAccess, OpenAsSelf, TokenHandle));
141 }
142
143 /******************************************************************************
144  * AdjustTokenPrivileges [ADVAPI32.@]
145  *
146  * Adjust the privileges of an open token handle.
147  * 
148  * PARAMS
149  *  TokenHandle          [I]   Handle from OpenProcessToken() or OpenThreadToken() 
150  *  DisableAllPrivileges [I]   TRUE=Remove all privileges, FALSE=Use NewState
151  *  NewState             [I]   Desired new privileges of the token
152  *  BufferLength         [I]   Length of NewState
153  *  PreviousState        [O]   Destination for the previous state
154  *  ReturnLength         [I/O] Size of PreviousState
155  *
156  *
157  * RETURNS
158  *  Success: TRUE. Privileges are set to NewState and PreviousState is updated.
159  *  Failure: FALSE.
160  *
161  * NOTES
162  *  See NtAdjustPrivilegesToken.
163  */
164 BOOL WINAPI
165 AdjustTokenPrivileges( HANDLE TokenHandle, BOOL DisableAllPrivileges,
166                        LPVOID NewState, DWORD BufferLength,
167                        LPVOID PreviousState, LPDWORD ReturnLength )
168 {
169         CallWin32ToNt(NtAdjustPrivilegesToken(TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength));
170 }
171
172 /******************************************************************************
173  * CheckTokenMembership [ADVAPI32.@]
174  *
175  * Determine if an access token is a member of a SID.
176  * 
177  * PARAMS
178  *   TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
179  *   SidToCheck  [I] SID that possibly contains the token
180  *   IsMember    [O] Destination for result.
181  *
182  * RETURNS
183  *  Success: TRUE. IsMember is TRUE if TokenHandle is a member, FALSE otherwise.
184  *  Failure: FALSE.
185  */
186 BOOL WINAPI
187 CheckTokenMembership( HANDLE TokenHandle, PSID SidToCheck,
188                       PBOOL IsMember )
189 {
190   FIXME("(%p %p %p) stub!\n", TokenHandle, SidToCheck, IsMember);
191
192   *IsMember = TRUE;
193   return(TRUE);
194 }
195
196 /******************************************************************************
197  * GetTokenInformation [ADVAPI32.@]
198  *
199  * PARAMS
200  *   token           [I] Handle from OpenProcessToken() or OpenThreadToken()
201  *   tokeninfoclass  [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
202  *   tokeninfo       [O] Destination for token information
203  *   tokeninfolength [I] Length of tokeninfo
204  *   retlen          [O] Destination for returned token information length
205  *
206  * RETURNS
207  *  Success: TRUE. tokeninfo contains retlen bytes of token information
208  *  Failure: FALSE.
209  *
210  * NOTES
211  *  See NtQueryInformationToken.
212  */
213 BOOL WINAPI
214 GetTokenInformation( HANDLE token, TOKEN_INFORMATION_CLASS tokeninfoclass,
215                      LPVOID tokeninfo, DWORD tokeninfolength, LPDWORD retlen )
216 {
217     TRACE("(%p, %s, %p, %ld, %p): \n",
218           token,
219           (tokeninfoclass == TokenUser) ? "TokenUser" :
220           (tokeninfoclass == TokenGroups) ? "TokenGroups" :
221           (tokeninfoclass == TokenPrivileges) ? "TokenPrivileges" :
222           (tokeninfoclass == TokenOwner) ? "TokenOwner" :
223           (tokeninfoclass == TokenPrimaryGroup) ? "TokenPrimaryGroup" :
224           (tokeninfoclass == TokenDefaultDacl) ? "TokenDefaultDacl" :
225           (tokeninfoclass == TokenSource) ? "TokenSource" :
226           (tokeninfoclass == TokenType) ? "TokenType" :
227           (tokeninfoclass == TokenImpersonationLevel) ? "TokenImpersonationLevel" :
228           (tokeninfoclass == TokenStatistics) ? "TokenStatistics" :
229           (tokeninfoclass == TokenRestrictedSids) ? "TokenRestrictedSids" :
230           (tokeninfoclass == TokenSessionId) ? "TokenSessionId" :
231           (tokeninfoclass == TokenGroupsAndPrivileges) ? "TokenGroupsAndPrivileges" :
232           (tokeninfoclass == TokenSessionReference) ? "TokenSessionReference" :
233           (tokeninfoclass == TokenSandBoxInert) ? "TokenSandBoxInert" :
234           "Unknown",
235           tokeninfo, tokeninfolength, retlen);
236     CallWin32ToNt (NtQueryInformationToken( token, tokeninfoclass, tokeninfo, tokeninfolength, retlen));
237 }
238
239 /******************************************************************************
240  * SetTokenInformation [ADVAPI32.@]
241  *
242  * Set information for an access token.
243  *
244  * PARAMS
245  *   token           [I] Handle from OpenProcessToken() or OpenThreadToken()
246  *   tokeninfoclass  [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
247  *   tokeninfo       [I] Token information to set
248  *   tokeninfolength [I] Length of tokeninfo
249  *
250  * RETURNS
251  *  Success: TRUE. The information for the token is set to tokeninfo.
252  *  Failure: FALSE.
253  */
254 BOOL WINAPI
255 SetTokenInformation( HANDLE token, TOKEN_INFORMATION_CLASS tokeninfoclass,
256                      LPVOID tokeninfo, DWORD tokeninfolength )
257 {
258     FIXME("(%p, %s, %p, %ld): stub\n",
259           token,
260           (tokeninfoclass == TokenUser) ? "TokenUser" :
261           (tokeninfoclass == TokenGroups) ? "TokenGroups" :
262           (tokeninfoclass == TokenPrivileges) ? "TokenPrivileges" :
263           (tokeninfoclass == TokenOwner) ? "TokenOwner" :
264           (tokeninfoclass == TokenPrimaryGroup) ? "TokenPrimaryGroup" :
265           (tokeninfoclass == TokenDefaultDacl) ? "TokenDefaultDacl" :
266           (tokeninfoclass == TokenSource) ? "TokenSource" :
267           (tokeninfoclass == TokenType) ? "TokenType" :
268           (tokeninfoclass == TokenImpersonationLevel) ? "TokenImpersonationLevel" :
269           (tokeninfoclass == TokenStatistics) ? "TokenStatistics" :
270           (tokeninfoclass == TokenRestrictedSids) ? "TokenRestrictedSids" :
271           (tokeninfoclass == TokenSessionId) ? "TokenSessionId" :
272           (tokeninfoclass == TokenGroupsAndPrivileges) ? "TokenGroupsAndPrivileges" :
273           (tokeninfoclass == TokenSessionReference) ? "TokenSessionReference" :
274           (tokeninfoclass == TokenSandBoxInert) ? "TokenSandBoxInert" :
275           "Unknown",
276           tokeninfo, tokeninfolength);
277
278     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
279
280     return FALSE;
281 }
282
283 /*************************************************************************
284  * SetThreadToken [ADVAPI32.@]
285  *
286  * Assigns an 'impersonation token' to a thread so it can assume the
287  * security privledges of another thread or process.  Can also remove
288  * a previously assigned token. 
289  *
290  * PARAMS
291  *   thread          [O] Handle to thread to set the token for
292  *   token           [I] Token to set
293  *
294  * RETURNS
295  *  Success: TRUE. The threads access token is set to token
296  *  Failure: FALSE.
297  *
298  * NOTES
299  *  Only supported on NT or higher. On Win9X this function does nothing.
300  *  See SetTokenInformation.
301  */
302 BOOL WINAPI SetThreadToken(PHANDLE thread, HANDLE token)
303 {
304     FIXME("(%p, %p): stub (NT impl. only)\n", thread, token);
305
306     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
307
308     return FALSE;
309 }
310
311 /*      ##############################
312         ######  SID FUNCTIONS   ######
313         ##############################
314 */
315
316 /******************************************************************************
317  * AllocateAndInitializeSid [ADVAPI32.@]
318  *
319  * PARAMS
320  *   pIdentifierAuthority []
321  *   nSubAuthorityCount   []
322  *   nSubAuthority0       []
323  *   nSubAuthority1       []
324  *   nSubAuthority2       []
325  *   nSubAuthority3       []
326  *   nSubAuthority4       []
327  *   nSubAuthority5       []
328  *   nSubAuthority6       []
329  *   nSubAuthority7       []
330  *   pSid                 []
331  */
332 BOOL WINAPI
333 AllocateAndInitializeSid( PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
334                           BYTE nSubAuthorityCount,
335                           DWORD nSubAuthority0, DWORD nSubAuthority1,
336                           DWORD nSubAuthority2, DWORD nSubAuthority3,
337                           DWORD nSubAuthority4, DWORD nSubAuthority5,
338                           DWORD nSubAuthority6, DWORD nSubAuthority7,
339                           PSID *pSid )
340 {
341         CallWin32ToNt (RtlAllocateAndInitializeSid(
342                 pIdentifierAuthority, nSubAuthorityCount,
343                 nSubAuthority0, nSubAuthority1, nSubAuthority2, nSubAuthority3,
344                 nSubAuthority4, nSubAuthority5, nSubAuthority6, nSubAuthority7,
345                 pSid ));
346 }
347
348 /******************************************************************************
349  * FreeSid [ADVAPI32.@]
350  *
351  * PARAMS
352  *   pSid []
353  */
354 PVOID WINAPI
355 FreeSid( PSID pSid )
356 {
357         RtlFreeSid(pSid);
358         return NULL; /* is documented like this */
359 }
360
361 /******************************************************************************
362  * CopySid [ADVAPI32.@]
363  *
364  * PARAMS
365  *   nDestinationSidLength []
366  *   pDestinationSid       []
367  *   pSourceSid            []
368  */
369 BOOL WINAPI
370 CopySid( DWORD nDestinationSidLength, PSID pDestinationSid, PSID pSourceSid )
371 {
372         return RtlCopySid(nDestinationSidLength, pDestinationSid, pSourceSid);
373 }
374
375 /******************************************************************************
376  * IsValidSid [ADVAPI32.@]
377  *
378  * PARAMS
379  *   pSid []
380  */
381 BOOL WINAPI
382 IsValidSid( PSID pSid )
383 {
384         return RtlValidSid( pSid );
385 }
386
387 /******************************************************************************
388  * EqualSid [ADVAPI32.@]
389  *
390  * PARAMS
391  *   pSid1 []
392  *   pSid2 []
393  */
394 BOOL WINAPI
395 EqualSid( PSID pSid1, PSID pSid2 )
396 {
397         return RtlEqualSid( pSid1, pSid2 );
398 }
399
400 /******************************************************************************
401  * EqualPrefixSid [ADVAPI32.@]
402  */
403 BOOL WINAPI EqualPrefixSid (PSID pSid1, PSID pSid2)
404 {
405         return RtlEqualPrefixSid(pSid1, pSid2);
406 }
407
408 /******************************************************************************
409  * GetSidLengthRequired [ADVAPI32.@]
410  *
411  * PARAMS
412  *   nSubAuthorityCount []
413  */
414 DWORD WINAPI
415 GetSidLengthRequired( BYTE nSubAuthorityCount )
416 {
417         return RtlLengthRequiredSid(nSubAuthorityCount);
418 }
419
420 /******************************************************************************
421  * InitializeSid [ADVAPI32.@]
422  *
423  * PARAMS
424  *   pIdentifierAuthority []
425  */
426 BOOL WINAPI
427 InitializeSid (
428         PSID pSid,
429         PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
430         BYTE nSubAuthorityCount)
431 {
432         return RtlInitializeSid(pSid, pIdentifierAuthority, nSubAuthorityCount);
433 }
434
435 /******************************************************************************
436  * GetSidIdentifierAuthority [ADVAPI32.@]
437  *
438  * PARAMS
439  *   pSid []
440  */
441 PSID_IDENTIFIER_AUTHORITY WINAPI
442 GetSidIdentifierAuthority( PSID pSid )
443 {
444         return RtlIdentifierAuthoritySid(pSid);
445 }
446
447 /******************************************************************************
448  * GetSidSubAuthority [ADVAPI32.@]
449  *
450  * PARAMS
451  *   pSid          []
452  *   nSubAuthority []
453  */
454 PDWORD WINAPI
455 GetSidSubAuthority( PSID pSid, DWORD nSubAuthority )
456 {
457         return RtlSubAuthoritySid(pSid, nSubAuthority);
458 }
459
460 /******************************************************************************
461  * GetSidSubAuthorityCount [ADVAPI32.@]
462  *
463  * PARAMS
464  *   pSid []
465  */
466 PUCHAR WINAPI
467 GetSidSubAuthorityCount (PSID pSid)
468 {
469         return RtlSubAuthorityCountSid(pSid);
470 }
471
472 /******************************************************************************
473  * GetLengthSid [ADVAPI32.@]
474  *
475  * PARAMS
476  *   pSid []
477  */
478 DWORD WINAPI
479 GetLengthSid (PSID pSid)
480 {
481         return RtlLengthSid(pSid);
482 }
483
484 /*      ##############################################
485         ######  SECURITY DESCRIPTOR FUNCTIONS   ######
486         ##############################################
487 */
488
489 /******************************************************************************
490  * InitializeSecurityDescriptor [ADVAPI32.@]
491  *
492  * PARAMS
493  *   pDescr   []
494  *   revision []
495  */
496 BOOL WINAPI
497 InitializeSecurityDescriptor( SECURITY_DESCRIPTOR *pDescr, DWORD revision )
498 {
499         CallWin32ToNt (RtlCreateSecurityDescriptor(pDescr, revision ));
500 }
501
502 /******************************************************************************
503  * GetSecurityDescriptorLength [ADVAPI32.@]
504  */
505 DWORD WINAPI GetSecurityDescriptorLength( SECURITY_DESCRIPTOR *pDescr)
506 {
507         return (RtlLengthSecurityDescriptor(pDescr));
508 }
509
510 /******************************************************************************
511  * GetSecurityDescriptorOwner [ADVAPI32.@]
512  *
513  * PARAMS
514  *   pOwner            []
515  *   lpbOwnerDefaulted []
516  */
517 BOOL WINAPI
518 GetSecurityDescriptorOwner( SECURITY_DESCRIPTOR *pDescr, PSID *pOwner,
519                             LPBOOL lpbOwnerDefaulted )
520 {
521         CallWin32ToNt (RtlGetOwnerSecurityDescriptor( pDescr, pOwner, (PBOOLEAN)lpbOwnerDefaulted ));
522 }
523
524 /******************************************************************************
525  * SetSecurityDescriptorOwner [ADVAPI32.@]
526  *
527  * PARAMS
528  */
529 BOOL WINAPI SetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pSecurityDescriptor,
530                                    PSID pOwner, BOOL bOwnerDefaulted)
531 {
532         CallWin32ToNt (RtlSetOwnerSecurityDescriptor(pSecurityDescriptor, pOwner, bOwnerDefaulted));
533 }
534 /******************************************************************************
535  * GetSecurityDescriptorGroup                   [ADVAPI32.@]
536  */
537 BOOL WINAPI GetSecurityDescriptorGroup(
538         PSECURITY_DESCRIPTOR SecurityDescriptor,
539         PSID *Group,
540         LPBOOL GroupDefaulted)
541 {
542         CallWin32ToNt (RtlGetGroupSecurityDescriptor(SecurityDescriptor, Group, (PBOOLEAN)GroupDefaulted));
543 }
544 /******************************************************************************
545  * SetSecurityDescriptorGroup [ADVAPI32.@]
546  */
547 BOOL WINAPI SetSecurityDescriptorGroup ( PSECURITY_DESCRIPTOR SecurityDescriptor,
548                                            PSID Group, BOOL GroupDefaulted)
549 {
550         CallWin32ToNt (RtlSetGroupSecurityDescriptor( SecurityDescriptor, Group, GroupDefaulted));
551 }
552
553 /******************************************************************************
554  * IsValidSecurityDescriptor [ADVAPI32.@]
555  *
556  * PARAMS
557  *   lpsecdesc []
558  */
559 BOOL WINAPI
560 IsValidSecurityDescriptor( PSECURITY_DESCRIPTOR SecurityDescriptor )
561 {
562         CallWin32ToNt (RtlValidSecurityDescriptor(SecurityDescriptor));
563 }
564
565 /******************************************************************************
566  *  GetSecurityDescriptorDacl                   [ADVAPI32.@]
567  */
568 BOOL WINAPI GetSecurityDescriptorDacl(
569         IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
570         OUT LPBOOL lpbDaclPresent,
571         OUT PACL *pDacl,
572         OUT LPBOOL lpbDaclDefaulted)
573 {
574         CallWin32ToNt (RtlGetDaclSecurityDescriptor(pSecurityDescriptor, (PBOOLEAN)lpbDaclPresent,
575                                                pDacl, (PBOOLEAN)lpbDaclDefaulted));
576 }
577
578 /******************************************************************************
579  *  SetSecurityDescriptorDacl                   [ADVAPI32.@]
580  */
581 BOOL WINAPI
582 SetSecurityDescriptorDacl (
583         PSECURITY_DESCRIPTOR lpsd,
584         BOOL daclpresent,
585         PACL dacl,
586         BOOL dacldefaulted )
587 {
588         CallWin32ToNt (RtlSetDaclSecurityDescriptor (lpsd, daclpresent, dacl, dacldefaulted ));
589 }
590 /******************************************************************************
591  *  GetSecurityDescriptorSacl                   [ADVAPI32.@]
592  */
593 BOOL WINAPI GetSecurityDescriptorSacl(
594         IN PSECURITY_DESCRIPTOR lpsd,
595         OUT LPBOOL lpbSaclPresent,
596         OUT PACL *pSacl,
597         OUT LPBOOL lpbSaclDefaulted)
598 {
599         CallWin32ToNt (RtlGetSaclSecurityDescriptor(lpsd,
600            (PBOOLEAN)lpbSaclPresent, pSacl, (PBOOLEAN)lpbSaclDefaulted));
601 }
602
603 /**************************************************************************
604  * SetSecurityDescriptorSacl                    [ADVAPI32.@]
605  */
606 BOOL WINAPI SetSecurityDescriptorSacl (
607         PSECURITY_DESCRIPTOR lpsd,
608         BOOL saclpresent,
609         PACL lpsacl,
610         BOOL sacldefaulted)
611 {
612         CallWin32ToNt (RtlSetSaclSecurityDescriptor(lpsd, saclpresent, lpsacl, sacldefaulted));
613 }
614 /******************************************************************************
615  * MakeSelfRelativeSD [ADVAPI32.@]
616  *
617  * PARAMS
618  *   lpabssecdesc  []
619  *   lpselfsecdesc []
620  *   lpbuflen      []
621  */
622 BOOL WINAPI
623 MakeSelfRelativeSD(
624         IN PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
625         IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
626         IN OUT LPDWORD lpdwBufferLength)
627 {
628         CallWin32ToNt (RtlMakeSelfRelativeSD(pAbsoluteSecurityDescriptor,pSelfRelativeSecurityDescriptor, lpdwBufferLength));
629 }
630
631 /******************************************************************************
632  * GetSecurityDescriptorControl                 [ADVAPI32.@]
633  */
634
635 BOOL WINAPI GetSecurityDescriptorControl ( PSECURITY_DESCRIPTOR  pSecurityDescriptor,
636                  PSECURITY_DESCRIPTOR_CONTROL pControl, LPDWORD lpdwRevision)
637 {
638         CallWin32ToNt (RtlGetControlSecurityDescriptor(pSecurityDescriptor,pControl,lpdwRevision));
639 }
640
641 /*      ##############################
642         ######  ACL FUNCTIONS   ######
643         ##############################
644 */
645
646 /*************************************************************************
647  * InitializeAcl [ADVAPI32.@]
648  */
649 DWORD WINAPI InitializeAcl(PACL acl, DWORD size, DWORD rev)
650 {
651         CallWin32ToNt (RtlCreateAcl(acl, size, rev));
652 }
653
654 /******************************************************************************
655  *  AddAccessAllowedAce [ADVAPI32.@]
656  */
657 BOOL WINAPI AddAccessAllowedAce(
658         IN OUT PACL pAcl,
659         IN DWORD dwAceRevision,
660         IN DWORD AccessMask,
661         IN PSID pSid)
662 {
663         CallWin32ToNt(RtlAddAccessAllowedAce(pAcl, dwAceRevision, AccessMask, pSid));
664 }
665
666 /******************************************************************************
667  *  AddAccessAllowedAceEx [ADVAPI32.@]
668  */
669 BOOL WINAPI AddAccessAllowedAceEx(
670         IN OUT PACL pAcl,
671         IN DWORD dwAceRevision,
672         IN DWORD AceFlags,
673         IN DWORD AccessMask,
674         IN PSID pSid)
675 {
676         CallWin32ToNt(RtlAddAccessAllowedAceEx(pAcl, dwAceRevision, AceFlags, AccessMask, pSid));
677 }
678
679 /******************************************************************************
680  *  AddAccessDeniedAce [ADVAPI32.@]
681  */
682 BOOL WINAPI AddAccessDeniedAce(
683         IN OUT PACL pAcl,
684         IN DWORD dwAceRevision,
685         IN DWORD AccessMask,
686         IN PSID pSid)
687 {
688         CallWin32ToNt(RtlAddAccessDeniedAce(pAcl, dwAceRevision, AccessMask, pSid));
689 }
690
691 /******************************************************************************
692  *  AddAccessDeniedAceEx [ADVAPI32.@]
693  */
694 BOOL WINAPI AddAccessDeniedAceEx(
695         IN OUT PACL pAcl,
696         IN DWORD dwAceRevision,
697         IN DWORD AceFlags,
698         IN DWORD AccessMask,
699         IN PSID pSid)
700 {
701         CallWin32ToNt(RtlAddAccessDeniedAceEx(pAcl, dwAceRevision, AceFlags, AccessMask, pSid));
702 }
703
704 /******************************************************************************
705  *  AddAce [ADVAPI32.@]
706  */
707 BOOL WINAPI AddAce(
708         IN OUT PACL pAcl,
709         IN DWORD dwAceRevision,
710         IN DWORD dwStartingAceIndex,
711         LPVOID pAceList,
712         DWORD nAceListLength)
713 {
714         CallWin32ToNt(RtlAddAce(pAcl, dwAceRevision, dwStartingAceIndex, pAceList, nAceListLength));
715 }
716
717 /******************************************************************************
718  *  FindFirstFreeAce [ADVAPI32.@]
719  */
720 BOOL WINAPI FindFirstFreeAce(IN PACL pAcl, LPVOID * pAce)
721 {
722         return RtlFirstFreeAce(pAcl, (PACE_HEADER *)pAce);
723 }
724
725 /******************************************************************************
726  * GetAce [ADVAPI32.@]
727  */
728 BOOL WINAPI GetAce(PACL pAcl,DWORD dwAceIndex,LPVOID *pAce )
729 {
730     CallWin32ToNt(RtlGetAce(pAcl, dwAceIndex, pAce));
731 }
732
733 /******************************************************************************
734  * GetAclInformation [ADVAPI32.@]
735  */
736 BOOL WINAPI GetAclInformation(
737   PACL pAcl,
738   LPVOID pAclInformation,
739   DWORD nAclInformationLength,
740   ACL_INFORMATION_CLASS dwAclInformationClass)
741 {
742         FIXME("(%p,%p,%ld,%d): stub\n",pAcl, pAclInformation,
743                 nAclInformationLength, dwAclInformationClass);
744   return FALSE;
745 }
746
747 /******************************************************************************
748  *  IsValidAcl [ADVAPI32.@]
749  */
750 BOOL WINAPI IsValidAcl(IN PACL pAcl)
751 {
752         return RtlValidAcl(pAcl);
753 }
754
755 /*      ##############################
756         ######  MISC FUNCTIONS  ######
757         ##############################
758 */
759
760 static const char * const DefaultPrivNames[] =
761 {
762     NULL, NULL,
763     "SeCreateTokenPrivilege", "SeAssignPrimaryTokenPrivilege",
764     "SeLockMemoryPrivilege", "SeIncreaseQuotaPrivilege",
765     "SeMachineAccountPrivilege", "SeTcbPrivilege",
766     "SeSecurityPrivilege", "SeTakeOwnershipPrivilege",
767     "SeLoadDriverPrivilege", "SeSystemProfilePrivilege",
768     "SeSystemtimePrivilege", "SeProfileSingleProcessPrivilege",
769     "SeIncreaseBasePriorityPrivilege", "SeCreatePagefilePrivilege",
770     "SeCreatePermanentPrivilege", "SeBackupPrivilege",
771     "SeRestorePrivilege", "SeShutdownPrivilege",
772     "SeDebugPrivilege", "SeAuditPrivilege",
773     "SeSystemEnvironmentPrivilege", "SeChangeNotifyPrivilege",
774     "SeRemoteShutdownPrivilege",
775 };
776 #define NUMPRIVS (sizeof DefaultPrivNames/sizeof DefaultPrivNames[0])
777
778 /******************************************************************************
779  * LookupPrivilegeValueW                        [ADVAPI32.@]
780  *
781  * See LookupPrivilegeValueA.
782  */
783 BOOL WINAPI
784 LookupPrivilegeValueW( LPCWSTR lpSystemName, LPCWSTR lpName, PLUID lpLuid )
785 {
786     UINT i;
787     WCHAR priv[0x28];
788
789     TRACE("%s,%s,%p\n",debugstr_w(lpSystemName), debugstr_w(lpName), lpLuid);
790
791     for( i=0; i<NUMPRIVS; i++ )
792     {
793         if( !DefaultPrivNames[i] )
794             continue;
795         MultiByteToWideChar( CP_ACP, 0, DefaultPrivNames[i], -1,
796                              priv, sizeof priv );
797         if( strcmpW( priv, lpName) )
798             continue;
799         lpLuid->LowPart = i;
800         lpLuid->HighPart = 0;
801         TRACE( "%s -> %08lx-%08lx\n",debugstr_w( lpSystemName ),
802                lpLuid->HighPart, lpLuid->LowPart );
803         return TRUE;
804     }
805     return FALSE;
806 }
807
808 /******************************************************************************
809  * LookupPrivilegeValueA                        [ADVAPI32.@]
810  *
811  * Retrieves LUID used on a system to represent the privilege name.
812  *
813  * PARAMS
814  *  lpSystemName [I] Name of the system
815  *  lpName       [I] Name of the privilege
816  *  pLuid        [O] Destination for the resulting LUD
817  *
818  * RETURNS
819  *  Success: TRUE. pLuid contains the requested LUID.
820  *  Failure: FALSE.
821  */
822 BOOL WINAPI
823 LookupPrivilegeValueA( LPCSTR lpSystemName, LPCSTR lpName, PLUID lpLuid )
824 {
825     UNICODE_STRING lpSystemNameW;
826     UNICODE_STRING lpNameW;
827     BOOL ret;
828
829     RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW, lpSystemName);
830     RtlCreateUnicodeStringFromAsciiz(&lpNameW,lpName);
831     ret = LookupPrivilegeValueW(lpSystemNameW.Buffer, lpNameW.Buffer, lpLuid);
832     RtlFreeUnicodeString(&lpNameW);
833     RtlFreeUnicodeString(&lpSystemNameW);
834     return ret;
835 }
836
837
838 /******************************************************************************
839  * LookupPrivilegeNameA                 [ADVAPI32.@]
840  */
841 BOOL WINAPI
842 LookupPrivilegeNameA( LPCSTR lpSystemName, PLUID lpLuid, LPSTR lpName, LPDWORD cchName)
843 {
844     FIXME("%s %p %p %p\n", debugstr_a(lpSystemName), lpLuid, lpName, cchName);
845     return FALSE;
846 }
847
848 /******************************************************************************
849  * LookupPrivilegeNameW                 [ADVAPI32.@]
850  */
851 BOOL WINAPI
852 LookupPrivilegeNameW( LPCWSTR lpSystemName, PLUID lpLuid, LPSTR lpName, LPDWORD cchName)
853 {
854     FIXME("%s %p %p %p\n", debugstr_w(lpSystemName), lpLuid, lpName, cchName);
855     return FALSE;
856 }
857
858 /******************************************************************************
859  * GetFileSecurityA [ADVAPI32.@]
860  *
861  * Obtains Specified information about the security of a file or directory.
862  *
863  * PARAMS
864  *  lpFileName           [I] Name of the file to get info for
865  *  RequestedInformation [I] SE_ flags from "winnt.h"
866  *  pSecurityDescriptor  [O] Destination for security information
867  *  nLength              [I] Length of pSecurityDescriptor
868  *  lpnLengthNeeded      [O] Destination for length of returned security information
869  *
870  * RETURNS
871  *  Success: TRUE. pSecurityDescriptor contains the requested information.
872  *  Failure: FALSE. lpnLengthNeeded contains the required space to return the info. 
873  *
874  * NOTES
875  *  The information returned is constrained by the callers access rights and
876  *  privileges.
877  */
878 BOOL WINAPI
879 GetFileSecurityA( LPCSTR lpFileName,
880                     SECURITY_INFORMATION RequestedInformation,
881                     PSECURITY_DESCRIPTOR pSecurityDescriptor,
882                     DWORD nLength, LPDWORD lpnLengthNeeded )
883 {
884   FIXME("(%s) : stub\n", debugstr_a(lpFileName));
885   return TRUE;
886 }
887
888 /******************************************************************************
889  * GetFileSecurityW [ADVAPI32.@]
890  *
891  * See GetFileSecurityA.
892  */
893 BOOL WINAPI
894 GetFileSecurityW( LPCWSTR lpFileName,
895                     SECURITY_INFORMATION RequestedInformation,
896                     PSECURITY_DESCRIPTOR pSecurityDescriptor,
897                     DWORD nLength, LPDWORD lpnLengthNeeded )
898 {
899   FIXME("(%s) : stub\n", debugstr_w(lpFileName) );
900   return TRUE;
901 }
902
903
904 /******************************************************************************
905  * LookupAccountSidA [ADVAPI32.@]
906  */
907 BOOL WINAPI
908 LookupAccountSidA(
909         IN LPCSTR system,
910         IN PSID sid,
911         OUT LPSTR account,
912         IN OUT LPDWORD accountSize,
913         OUT LPSTR domain,
914         IN OUT LPDWORD domainSize,
915         OUT PSID_NAME_USE name_use )
916 {
917         static const char ac[] = "Administrator";
918         static const char dm[] = "DOMAIN";
919         FIXME("(%s,sid=%p,%p,%p(%lu),%p,%p(%lu),%p): semi-stub\n",
920               debugstr_a(system),sid,
921               account,accountSize,accountSize?*accountSize:0,
922               domain,domainSize,domainSize?*domainSize:0,
923               name_use);
924
925         if (accountSize) *accountSize = strlen(ac)+1;
926         if (account && (*accountSize > strlen(ac)))
927           strcpy(account, ac);
928
929         if (domainSize) *domainSize = strlen(dm)+1;
930         if (domain && (*domainSize > strlen(dm)))
931           strcpy(domain,dm);
932
933         if (name_use) *name_use = SidTypeUser;
934         return TRUE;
935 }
936
937 /******************************************************************************
938  * LookupAccountSidW [ADVAPI32.@]
939  *
940  * PARAMS
941  *   system      []
942  *   sid         []
943  *   account     []
944  *   accountSize []
945  *   domain      []
946  *   domainSize  []
947  *   name_use    []
948  */
949 BOOL WINAPI
950 LookupAccountSidW(
951         IN LPCWSTR system,
952         IN PSID sid,
953         OUT LPWSTR account,
954         IN OUT LPDWORD accountSize,
955         OUT LPWSTR domain,
956         IN OUT LPDWORD domainSize,
957         OUT PSID_NAME_USE name_use )
958 {
959     static const WCHAR ac[] = {'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
960     static const WCHAR dm[] = {'D','O','M','A','I','N',0};
961         FIXME("(%s,sid=%p,%p,%p(%lu),%p,%p(%lu),%p): semi-stub\n",
962               debugstr_w(system),sid,
963               account,accountSize,accountSize?*accountSize:0,
964               domain,domainSize,domainSize?*domainSize:0,
965               name_use);
966
967         if (accountSize) *accountSize = strlenW(ac)+1;
968         if (account && (*accountSize > strlenW(ac)))
969             strcpyW(account, ac);
970
971         if (domainSize) *domainSize = strlenW(dm)+1;
972         if (domain && (*domainSize > strlenW(dm)))
973             strcpyW(domain,dm);
974
975         if (name_use) *name_use = SidTypeUser;
976         return TRUE;
977 }
978
979 /******************************************************************************
980  * SetFileSecurityA [ADVAPI32.@]
981  * Sets the security of a file or directory
982  */
983 BOOL WINAPI SetFileSecurityA( LPCSTR lpFileName,
984                                 SECURITY_INFORMATION RequestedInformation,
985                                 PSECURITY_DESCRIPTOR pSecurityDescriptor)
986 {
987   FIXME("(%s) : stub\n", debugstr_a(lpFileName));
988   return TRUE;
989 }
990
991 /******************************************************************************
992  * SetFileSecurityW [ADVAPI32.@]
993  * Sets the security of a file or directory
994  *
995  * PARAMS
996  *   lpFileName           []
997  *   RequestedInformation []
998  *   pSecurityDescriptor  []
999  */
1000 BOOL WINAPI
1001 SetFileSecurityW( LPCWSTR lpFileName,
1002                     SECURITY_INFORMATION RequestedInformation,
1003                     PSECURITY_DESCRIPTOR pSecurityDescriptor )
1004 {
1005   FIXME("(%s) : stub\n", debugstr_w(lpFileName) );
1006   return TRUE;
1007 }
1008
1009 /******************************************************************************
1010  * QueryWindows31FilesMigration [ADVAPI32.@]
1011  *
1012  * PARAMS
1013  *   x1 []
1014  */
1015 BOOL WINAPI
1016 QueryWindows31FilesMigration( DWORD x1 )
1017 {
1018         FIXME("(%ld):stub\n",x1);
1019         return TRUE;
1020 }
1021
1022 /******************************************************************************
1023  * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.@]
1024  *
1025  * PARAMS
1026  *   x1 []
1027  *   x2 []
1028  *   x3 []
1029  *   x4 []
1030  */
1031 BOOL WINAPI
1032 SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1, DWORD x2, DWORD x3,
1033                                                DWORD x4 )
1034 {
1035         FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx):stub\n",x1,x2,x3,x4);
1036         return TRUE;
1037 }
1038
1039 /******************************************************************************
1040  * LsaOpenPolicy [ADVAPI32.@]
1041  *
1042  * PARAMS
1043  *   x1 []
1044  *   x2 []
1045  *   x3 []
1046  *   x4 []
1047  */
1048 NTSTATUS WINAPI
1049 LsaOpenPolicy(
1050         IN PLSA_UNICODE_STRING SystemName,
1051         IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes,
1052         IN ACCESS_MASK DesiredAccess,
1053         IN OUT PLSA_HANDLE PolicyHandle)
1054 {
1055         FIXME("(%s,%p,0x%08lx,%p):stub\n",
1056               SystemName?debugstr_w(SystemName->Buffer):"null",
1057               ObjectAttributes, DesiredAccess, PolicyHandle);
1058         ADVAPI_ForceLocalComputer(SystemName ? SystemName->Buffer : NULL,
1059                                   STATUS_ACCESS_VIOLATION);
1060         dumpLsaAttributes(ObjectAttributes);
1061         if(PolicyHandle) *PolicyHandle = (LSA_HANDLE)0xcafe;
1062         return STATUS_SUCCESS;
1063 }
1064
1065 /******************************************************************************
1066  * LsaQueryInformationPolicy [ADVAPI32.@]
1067  */
1068 NTSTATUS WINAPI
1069 LsaQueryInformationPolicy(
1070         IN LSA_HANDLE PolicyHandle,
1071         IN POLICY_INFORMATION_CLASS InformationClass,
1072         OUT PVOID *Buffer)
1073 {
1074         FIXME("(%p,0x%08x,%p):stub\n",
1075               PolicyHandle, InformationClass, Buffer);
1076
1077         if(!Buffer) return FALSE;
1078         switch (InformationClass)
1079         {
1080           case PolicyAuditEventsInformation: /* 2 */
1081             {
1082               PPOLICY_AUDIT_EVENTS_INFO p = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(POLICY_AUDIT_EVENTS_INFO));
1083               p->AuditingMode = FALSE; /* no auditing */
1084               *Buffer = p;
1085             }
1086             break;
1087           case PolicyPrimaryDomainInformation: /* 3 */
1088           case PolicyAccountDomainInformation: /* 5 */
1089             {
1090               struct di
1091               { POLICY_PRIMARY_DOMAIN_INFO ppdi;
1092                 SID sid;
1093               };
1094               SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
1095
1096               struct di * xdi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(xdi));
1097               RtlCreateUnicodeStringFromAsciiz(&(xdi->ppdi.Name), "DOMAIN");
1098
1099               xdi->ppdi.Sid = &(xdi->sid);
1100               xdi->sid.Revision = SID_REVISION;
1101               xdi->sid.SubAuthorityCount = 1;
1102               xdi->sid.IdentifierAuthority = localSidAuthority;
1103               xdi->sid.SubAuthority[0] = SECURITY_LOCAL_SYSTEM_RID;
1104               *Buffer = xdi;
1105             }
1106             break;
1107           case  PolicyAuditLogInformation:
1108           case  PolicyPdAccountInformation:
1109           case  PolicyLsaServerRoleInformation:
1110           case  PolicyReplicaSourceInformation:
1111           case  PolicyDefaultQuotaInformation:
1112           case  PolicyModificationInformation:
1113           case  PolicyAuditFullSetInformation:
1114           case  PolicyAuditFullQueryInformation:
1115           case  PolicyDnsDomainInformation:
1116             {
1117               FIXME("category not implemented\n");
1118               return FALSE;
1119             }
1120         }
1121         return TRUE;
1122 }
1123
1124 /******************************************************************************
1125  * LsaLookupSids [ADVAPI32.@]
1126  */
1127 typedef struct
1128 {
1129         SID_NAME_USE Use;
1130         LSA_UNICODE_STRING Name;
1131         LONG DomainIndex;
1132 } LSA_TRANSLATED_NAME, *PLSA_TRANSLATED_NAME;
1133
1134 typedef struct
1135 {
1136         LSA_UNICODE_STRING Name;
1137         PSID Sid;
1138 } LSA_TRUST_INFORMATION, *PLSA_TRUST_INFORMATION;
1139
1140 typedef struct
1141 {
1142         ULONG Entries;
1143         PLSA_TRUST_INFORMATION Domains;
1144 } LSA_REFERENCED_DOMAIN_LIST, *PLSA_REFERENCED_DOMAIN_LIST;
1145
1146 NTSTATUS WINAPI
1147 LsaLookupSids(
1148         IN LSA_HANDLE PolicyHandle,
1149         IN ULONG Count,
1150         IN PSID *Sids,
1151         OUT PLSA_REFERENCED_DOMAIN_LIST *ReferencedDomains,
1152         OUT PLSA_TRANSLATED_NAME *Names )
1153 {
1154         FIXME("%p %lu %p %p %p\n",
1155           PolicyHandle, Count, Sids, ReferencedDomains, Names);
1156         return FALSE;
1157 }
1158
1159 /******************************************************************************
1160  * LsaFreeMemory [ADVAPI32.@]
1161  */
1162 NTSTATUS WINAPI
1163 LsaFreeMemory(IN PVOID Buffer)
1164 {
1165         TRACE("(%p)\n",Buffer);
1166         return HeapFree(GetProcessHeap(), 0, Buffer);
1167 }
1168 /******************************************************************************
1169  * LsaClose [ADVAPI32.@]
1170  */
1171 NTSTATUS WINAPI
1172 LsaClose(IN LSA_HANDLE ObjectHandle)
1173 {
1174         FIXME("(%p):stub\n",ObjectHandle);
1175         return 0xc0000000;
1176 }
1177
1178 /******************************************************************************
1179  * LsaNtStatusToWinError [ADVAPI32.@]
1180  *
1181  * PARAMS
1182  *   Status [I]
1183  */
1184 ULONG WINAPI
1185 LsaNtStatusToWinError(NTSTATUS Status)
1186 {
1187     return RtlNtStatusToDosError(Status);
1188 }
1189
1190 /******************************************************************************
1191  * NotifyBootConfigStatus [ADVAPI32.@]
1192  *
1193  * PARAMS
1194  *   x1 []
1195  */
1196 BOOL WINAPI
1197 NotifyBootConfigStatus( DWORD x1 )
1198 {
1199         FIXME("(0x%08lx):stub\n",x1);
1200         return 1;
1201 }
1202
1203 /******************************************************************************
1204  * RevertToSelf [ADVAPI32.@]
1205  *
1206  * PARAMS
1207  *   void []
1208  */
1209 BOOL WINAPI
1210 RevertToSelf( void )
1211 {
1212         FIXME("(), stub\n");
1213         return TRUE;
1214 }
1215
1216 /******************************************************************************
1217  * ImpersonateSelf [ADVAPI32.@]
1218  */
1219 BOOL WINAPI
1220 ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
1221 {
1222         return RtlImpersonateSelf(ImpersonationLevel);
1223 }
1224
1225 /******************************************************************************
1226  * ImpersonateLoggedOnUser [ADVAPI32.@]
1227  */
1228 BOOL WINAPI ImpersonateLoggedOnUser(HANDLE hToken)
1229 {
1230     FIXME("(%p):stub returning FALSE\n", hToken);
1231     return FALSE;
1232 }
1233
1234 /******************************************************************************
1235  * AccessCheck [ADVAPI32.@]
1236  *
1237  * FIXME check cast LPBOOL to PBOOLEAN
1238  */
1239 BOOL WINAPI
1240 AccessCheck(
1241         PSECURITY_DESCRIPTOR SecurityDescriptor,
1242         HANDLE ClientToken,
1243         DWORD DesiredAccess,
1244         PGENERIC_MAPPING GenericMapping,
1245         PPRIVILEGE_SET PrivilegeSet,
1246         LPDWORD PrivilegeSetLength,
1247         LPDWORD GrantedAccess,
1248         LPBOOL AccessStatus)
1249 {
1250         CallWin32ToNt (NtAccessCheck(SecurityDescriptor, ClientToken, DesiredAccess,
1251           GenericMapping, PrivilegeSet, PrivilegeSetLength, GrantedAccess, (PBOOLEAN)AccessStatus));
1252 }
1253
1254 /*************************************************************************
1255  * SetKernelObjectSecurity [ADVAPI32.@]
1256  */
1257 BOOL WINAPI SetKernelObjectSecurity (
1258         IN HANDLE Handle,
1259         IN SECURITY_INFORMATION SecurityInformation,
1260         IN PSECURITY_DESCRIPTOR SecurityDescriptor )
1261 {
1262         CallWin32ToNt (NtSetSecurityObject (Handle, SecurityInformation, SecurityDescriptor));
1263 }
1264
1265 /******************************************************************************
1266  * LookupAccountNameA [ADVAPI32.@]
1267  */
1268 BOOL WINAPI
1269 LookupAccountNameA(
1270         IN LPCSTR system,
1271         IN LPCSTR account,
1272         OUT PSID sid,
1273         OUT LPDWORD cbSid,
1274         LPSTR ReferencedDomainName,
1275         IN OUT LPDWORD cbReferencedDomainName,
1276         OUT PSID_NAME_USE name_use )
1277 {
1278     FIXME("(%s,%s,%p,%p,%p,%p,%p), stub.\n",system,account,sid,cbSid,ReferencedDomainName,cbReferencedDomainName,name_use);
1279     return FALSE;
1280 }
1281
1282 /******************************************************************************
1283  * PrivilegeCheck [ADVAPI32.@]
1284  */
1285 BOOL WINAPI PrivilegeCheck( HANDLE ClientToken, PPRIVILEGE_SET RequiredPrivileges, LPBOOL pfResult)
1286 {
1287         FIXME("stub %p %p %p\n", ClientToken, RequiredPrivileges, pfResult);
1288         if (pfResult)
1289                 *pfResult=TRUE;
1290         return TRUE;
1291 }
1292
1293 /******************************************************************************
1294  * AccessCheckAndAuditAlarmA [ADVAPI32.@]
1295  */
1296 BOOL WINAPI AccessCheckAndAuditAlarmA(LPCSTR Subsystem, LPVOID HandleId, LPSTR ObjectTypeName,
1297   LPSTR ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD DesiredAccess,
1298   PGENERIC_MAPPING GenericMapping, BOOL ObjectCreation, LPDWORD GrantedAccess,
1299   LPBOOL AccessStatus, LPBOOL pfGenerateOnClose)
1300 {
1301         FIXME("stub (%s,%p,%s,%s,%p,%08lx,%p,%x,%p,%p,%p)\n", debugstr_a(Subsystem),
1302                 HandleId, debugstr_a(ObjectTypeName), debugstr_a(ObjectName),
1303                 SecurityDescriptor, DesiredAccess, GenericMapping,
1304                 ObjectCreation, GrantedAccess, AccessStatus, pfGenerateOnClose);
1305         return TRUE;
1306 }
1307
1308 /******************************************************************************
1309  * AccessCheckAndAuditAlarmW [ADVAPI32.@]
1310  */
1311 BOOL WINAPI AccessCheckAndAuditAlarmW(LPCWSTR Subsystem, LPVOID HandleId, LPWSTR ObjectTypeName,
1312   LPWSTR ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD DesiredAccess,
1313   PGENERIC_MAPPING GenericMapping, BOOL ObjectCreation, LPDWORD GrantedAccess,
1314   LPBOOL AccessStatus, LPBOOL pfGenerateOnClose)
1315 {
1316         FIXME("stub (%s,%p,%s,%s,%p,%08lx,%p,%x,%p,%p,%p)\n", debugstr_w(Subsystem),
1317                 HandleId, debugstr_w(ObjectTypeName), debugstr_w(ObjectName),
1318                 SecurityDescriptor, DesiredAccess, GenericMapping,
1319                 ObjectCreation, GrantedAccess, AccessStatus, pfGenerateOnClose);
1320         return TRUE;
1321 }
1322
1323
1324 /******************************************************************************
1325  * GetSecurityInfoExW [ADVAPI32.@]
1326  */
1327 DWORD WINAPI GetSecurityInfoExW(
1328         HANDLE hObject, SE_OBJECT_TYPE ObjectType, 
1329         SECURITY_INFORMATION SecurityInfo, LPCWSTR lpProvider,
1330         LPCWSTR lpProperty, PACTRL_ACCESSW *ppAccessList, 
1331         PACTRL_AUDITW *ppAuditList, LPWSTR *lppOwner, LPWSTR *lppGroup
1332 )
1333 {
1334   FIXME("stub!\n");
1335   return ERROR_BAD_PROVIDER; 
1336 }
1337
1338 /******************************************************************************
1339  * BuildTrusteeWithSidA [ADVAPI32.@]
1340  */
1341 VOID WINAPI BuildTrusteeWithSidA(PTRUSTEEA pTrustee, PSID pSid)
1342 {
1343     FIXME("%p %p\n", pTrustee, pSid);
1344 }
1345
1346 /******************************************************************************
1347  * BuildTrusteeWithSidW [ADVAPI32.@]
1348  */
1349 VOID WINAPI BuildTrusteeWithSidW(PTRUSTEEW pTrustee, PSID pSid)
1350 {
1351     FIXME("%p %p\n", pTrustee, pSid);
1352 }
1353
1354 /******************************************************************************
1355  * SetEntriesInAclA [ADVAPI32.@]
1356  */
1357 DWORD WINAPI SetEntriesInAclA( ULONG count, PEXPLICIT_ACCESSA pEntries,
1358                                PACL OldAcl, PACL* NewAcl )
1359 {
1360     FIXME("%ld %p %p %p\n",count,pEntries,OldAcl,NewAcl);
1361     return ERROR_CALL_NOT_IMPLEMENTED;
1362 }
1363
1364 /******************************************************************************
1365  * SetEntriesInAclW [ADVAPI32.@]
1366  */
1367 DWORD WINAPI SetEntriesInAclW( ULONG count, PEXPLICIT_ACCESSW pEntries,
1368                                PACL OldAcl, PACL* NewAcl )
1369 {
1370     FIXME("%ld %p %p %p\n",count,pEntries,OldAcl,NewAcl);
1371     return ERROR_CALL_NOT_IMPLEMENTED;
1372 }
1373
1374 /******************************************************************************
1375  * SetNamedSecurityInfoA [ADVAPI32.@]
1376  */
1377 DWORD WINAPI SetNamedSecurityInfoA(LPSTR pObjectName,
1378         SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
1379         PSID psidOwner, PSID psidGroup, PACL pDacl, PACL pSacl)
1380 {
1381     FIXME("%s %d %ld %p %p %p %p\n", debugstr_a(pObjectName), ObjectType,
1382            SecurityInfo, psidOwner, psidGroup, pDacl, pSacl);
1383     return ERROR_CALL_NOT_IMPLEMENTED;
1384 }
1385
1386 /******************************************************************************
1387  * SetNamedSecurityInfoW [ADVAPI32.@]
1388  */
1389 DWORD WINAPI SetNamedSecurityInfoW(LPWSTR pObjectName,
1390         SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
1391         PSID psidOwner, PSID psidGroup, PACL pDacl, PACL pSacl)
1392 {
1393     FIXME("%s %d %ld %p %p %p %p\n", debugstr_w(pObjectName), ObjectType,
1394            SecurityInfo, psidOwner, psidGroup, pDacl, pSacl);
1395     return ERROR_CALL_NOT_IMPLEMENTED;
1396 }