Removed the DOS version option, specifying the Windows version should
[wine] / dlls / advapi32 / security.c
1 /*
2  * Copyright 1999, 2000 Juergen Schmied <juergen.schmied@debitel.net>
3  * Copyright 2003 CodeWeavers Inc. (Ulrich Czekalla)
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  */
20
21 #include <stdarg.h>
22 #include <string.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winerror.h"
27 #include "rpcnterr.h"
28 #include "winreg.h"
29 #include "winternl.h"
30 #include "ntstatus.h"
31 #include "ntsecapi.h"
32 #include "accctrl.h"
33 #include "sddl.h"
34 #include "winsvc.h"
35 #include "aclapi.h"
36
37 #include "wine/debug.h"
38 #include "wine/unicode.h"
39
40 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
41
42 static BOOL ParseStringSidToSid(LPCWSTR StringSid, PSID pSid, LPDWORD cBytes);
43 static BOOL ParseStringAclToAcl(LPCWSTR StringAcl, LPDWORD lpdwFlags, 
44     PACL pAcl, LPDWORD cBytes);
45 static BYTE ParseAceStringFlags(LPCWSTR* StringAcl);
46 static BYTE ParseAceStringType(LPCWSTR* StringAcl);
47 static DWORD ParseAceStringRights(LPCWSTR* StringAcl);
48 static BOOL ParseStringSecurityDescriptorToSecurityDescriptor(
49     LPCWSTR StringSecurityDescriptor,
50     SECURITY_DESCRIPTOR* SecurityDescriptor,
51     LPDWORD cBytes);
52 static DWORD ParseAclStringFlags(LPCWSTR* StringAcl);
53
54 typedef struct _ACEFLAG
55 {
56    LPCWSTR wstr;
57    DWORD value;
58 } ACEFLAG, *LPACEFLAG;
59
60 static SID const sidWorld = { SID_REVISION, 1, { SECURITY_WORLD_SID_AUTHORITY} , { SECURITY_WORLD_RID } };
61
62 /*
63  * ACE access rights
64  */
65 static const WCHAR SDDL_READ_CONTROL[]     = {'R','C',0};
66 static const WCHAR SDDL_WRITE_DAC[]        = {'W','D',0};
67 static const WCHAR SDDL_WRITE_OWNER[]      = {'W','O',0};
68 static const WCHAR SDDL_STANDARD_DELETE[]  = {'S','D',0};
69 static const WCHAR SDDL_GENERIC_ALL[]      = {'G','A',0};
70 static const WCHAR SDDL_GENERIC_READ[]     = {'G','R',0};
71 static const WCHAR SDDL_GENERIC_WRITE[]    = {'G','W',0};
72 static const WCHAR SDDL_GENERIC_EXECUTE[]  = {'G','X',0};
73
74 /*
75  * ACE types
76  */
77 static const WCHAR SDDL_ACCESS_ALLOWED[]        = {'A',0};
78 static const WCHAR SDDL_ACCESS_DENIED[]         = {'D',0};
79 static const WCHAR SDDL_OBJECT_ACCESS_ALLOWED[] = {'O','A',0};
80 static const WCHAR SDDL_OBJECT_ACCESS_DENIED[]  = {'O','D',0};
81 static const WCHAR SDDL_AUDIT[]                 = {'A','U',0};
82 static const WCHAR SDDL_ALARM[]                 = {'A','L',0};
83 static const WCHAR SDDL_OBJECT_AUDIT[]          = {'O','U',0};
84 static const WCHAR SDDL_OBJECT_ALARMp[]         = {'O','L',0};
85
86 /*
87  * ACE flags
88  */
89 static const WCHAR SDDL_CONTAINER_INHERIT[]  = {'C','I',0};
90 static const WCHAR SDDL_OBJECT_INHERIT[]     = {'O','I',0};
91 static const WCHAR SDDL_NO_PROPAGATE[]       = {'N','P',0};
92 static const WCHAR SDDL_INHERIT_ONLY[]       = {'I','O',0};
93 static const WCHAR SDDL_INHERITED[]          = {'I','D',0};
94 static const WCHAR SDDL_AUDIT_SUCCESS[]      = {'S','A',0};
95 static const WCHAR SDDL_AUDIT_FAILURE[]      = {'F','A',0};
96
97 /* set last error code from NT status and get the proper boolean return value */
98 /* used for functions that are a simple wrapper around the corresponding ntdll API */
99 static inline BOOL set_ntstatus( NTSTATUS status )
100 {
101     if (status) SetLastError( RtlNtStatusToDosError( status ));
102     return !status;
103 }
104
105 static void dumpLsaAttributes( PLSA_OBJECT_ATTRIBUTES oa )
106 {
107         if (oa)
108         {
109           TRACE("\n\tlength=%lu, rootdir=%p, objectname=%s\n\tattr=0x%08lx, sid=%p qos=%p\n",
110                 oa->Length, oa->RootDirectory,
111                 oa->ObjectName?debugstr_w(oa->ObjectName->Buffer):"null",
112                 oa->Attributes, oa->SecurityDescriptor, oa->SecurityQualityOfService);
113         }
114 }
115
116 #define WINE_SIZE_OF_WORLD_ACCESS_ACL   (sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) + sizeof(sidWorld) - sizeof(DWORD))
117
118 static void GetWorldAccessACL(PACL pACL)
119 {
120     PACCESS_ALLOWED_ACE pACE = (PACCESS_ALLOWED_ACE) (pACL + 1);
121
122     pACL->AclRevision = ACL_REVISION;
123     pACL->Sbz1 = 0;
124     pACL->AclSize = WINE_SIZE_OF_WORLD_ACCESS_ACL;
125     pACL->AceCount = 1;
126     pACL->Sbz2 = 0;
127
128     pACE->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
129     pACE->Header.AceFlags = CONTAINER_INHERIT_ACE;
130     pACE->Header.AceSize = sizeof(ACCESS_ALLOWED_ACE) + sizeof(sidWorld) - sizeof(DWORD);
131     pACE->Mask = 0xf3ffffff; /* Everything except reserved bits */
132     memcpy(&pACE->SidStart, &sidWorld, sizeof(sidWorld));
133 }
134
135 /************************************************************
136  *                ADVAPI_IsLocalComputer
137  *
138  * Checks whether the server name indicates local machine.
139  */
140 static BOOL ADVAPI_IsLocalComputer(LPCWSTR ServerName)
141 {
142     DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
143     BOOL Result;
144     LPWSTR buf;
145
146     if (!ServerName || !ServerName[0])
147         return TRUE;
148     
149     buf = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
150     Result = GetComputerNameW(buf,  &dwSize);
151     if (Result && (ServerName[0] == '\\') && (ServerName[1] == '\\'))
152         ServerName += 2;
153     Result = Result && !lstrcmpW(ServerName, buf);
154     HeapFree(GetProcessHeap(), 0, buf);
155
156     return Result;
157 }
158
159 #define ADVAPI_ForceLocalComputer(ServerName, FailureCode) \
160     if (!ADVAPI_IsLocalComputer(ServerName)) \
161     { \
162         FIXME("Action Implemented for local computer only. " \
163               "Requested for server %s\n", debugstr_w(ServerName)); \
164         return FailureCode; \
165     }
166
167 /*      ##############################
168         ######  TOKEN FUNCTIONS ######
169         ##############################
170 */
171
172 /******************************************************************************
173  * OpenProcessToken                     [ADVAPI32.@]
174  * Opens the access token associated with a process handle.
175  *
176  * PARAMS
177  *   ProcessHandle [I] Handle to process
178  *   DesiredAccess [I] Desired access to process
179  *   TokenHandle   [O] Pointer to handle of open access token
180  *
181  * RETURNS
182  *  Success: TRUE. TokenHandle contains the access token.
183  *  Failure: FALSE.
184  *
185  * NOTES
186  *  See NtOpenProcessToken.
187  */
188 BOOL WINAPI
189 OpenProcessToken( HANDLE ProcessHandle, DWORD DesiredAccess,
190                   HANDLE *TokenHandle )
191 {
192         return set_ntstatus(NtOpenProcessToken( ProcessHandle, DesiredAccess, TokenHandle ));
193 }
194
195 /******************************************************************************
196  * OpenThreadToken [ADVAPI32.@]
197  *
198  * Opens the access token associated with a thread handle.
199  *
200  * PARAMS
201  *   ThreadHandle  [I] Handle to process
202  *   DesiredAccess [I] Desired access to the thread
203  *   OpenAsSelf    [I] ???
204  *   TokenHandle   [O] Destination for the token handle
205  *
206  * RETURNS
207  *  Success: TRUE. TokenHandle contains the access token.
208  *  Failure: FALSE.
209  *
210  * NOTES
211  *  See NtOpenThreadToken.
212  */
213 BOOL WINAPI
214 OpenThreadToken( HANDLE ThreadHandle, DWORD DesiredAccess,
215                  BOOL OpenAsSelf, HANDLE *TokenHandle)
216 {
217         return set_ntstatus( NtOpenThreadToken(ThreadHandle, DesiredAccess, OpenAsSelf, TokenHandle));
218 }
219
220 BOOL WINAPI
221 AdjustTokenGroups( HANDLE TokenHandle, BOOL ResetToDefault, PTOKEN_GROUPS NewState,
222                    DWORD BufferLength, PTOKEN_GROUPS PreviousState, PDWORD ReturnLength )
223 {
224     return set_ntstatus( NtAdjustGroupsToken(TokenHandle, ResetToDefault, NewState, BufferLength,
225                                              PreviousState, ReturnLength));
226 }
227
228 /******************************************************************************
229  * AdjustTokenPrivileges [ADVAPI32.@]
230  *
231  * Adjust the privileges of an open token handle.
232  * 
233  * PARAMS
234  *  TokenHandle          [I]   Handle from OpenProcessToken() or OpenThreadToken() 
235  *  DisableAllPrivileges [I]   TRUE=Remove all privileges, FALSE=Use NewState
236  *  NewState             [I]   Desired new privileges of the token
237  *  BufferLength         [I]   Length of NewState
238  *  PreviousState        [O]   Destination for the previous state
239  *  ReturnLength         [I/O] Size of PreviousState
240  *
241  *
242  * RETURNS
243  *  Success: TRUE. Privileges are set to NewState and PreviousState is updated.
244  *  Failure: FALSE.
245  *
246  * NOTES
247  *  See NtAdjustPrivilegesToken.
248  */
249 BOOL WINAPI
250 AdjustTokenPrivileges( HANDLE TokenHandle, BOOL DisableAllPrivileges,
251                        LPVOID NewState, DWORD BufferLength,
252                        LPVOID PreviousState, LPDWORD ReturnLength )
253 {
254     NTSTATUS status;
255
256     TRACE("\n");
257     
258     status = NtAdjustPrivilegesToken(TokenHandle, DisableAllPrivileges,
259                                                      NewState, BufferLength, PreviousState,
260                                                      ReturnLength);
261     SetLastError( RtlNtStatusToDosError( status ));
262     if ((status == STATUS_SUCCESS) || (status == STATUS_NOT_ALL_ASSIGNED))
263         return TRUE;
264     else
265         return FALSE;
266 }
267
268 /******************************************************************************
269  * CheckTokenMembership [ADVAPI32.@]
270  *
271  * Determine if an access token is a member of a SID.
272  * 
273  * PARAMS
274  *   TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
275  *   SidToCheck  [I] SID that possibly contains the token
276  *   IsMember    [O] Destination for result.
277  *
278  * RETURNS
279  *  Success: TRUE. IsMember is TRUE if TokenHandle is a member, FALSE otherwise.
280  *  Failure: FALSE.
281  */
282 BOOL WINAPI
283 CheckTokenMembership( HANDLE TokenHandle, PSID SidToCheck,
284                       PBOOL IsMember )
285 {
286   FIXME("(%p %p %p) stub!\n", TokenHandle, SidToCheck, IsMember);
287
288   *IsMember = TRUE;
289   return(TRUE);
290 }
291
292 /******************************************************************************
293  * GetTokenInformation [ADVAPI32.@]
294  *
295  * PARAMS
296  *   token           [I] Handle from OpenProcessToken() or OpenThreadToken()
297  *   tokeninfoclass  [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
298  *   tokeninfo       [O] Destination for token information
299  *   tokeninfolength [I] Length of tokeninfo
300  *   retlen          [O] Destination for returned token information length
301  *
302  * RETURNS
303  *  Success: TRUE. tokeninfo contains retlen bytes of token information
304  *  Failure: FALSE.
305  *
306  * NOTES
307  *  See NtQueryInformationToken.
308  */
309 BOOL WINAPI
310 GetTokenInformation( HANDLE token, TOKEN_INFORMATION_CLASS tokeninfoclass,
311                      LPVOID tokeninfo, DWORD tokeninfolength, LPDWORD retlen )
312 {
313     TRACE("(%p, %s, %p, %ld, %p): \n",
314           token,
315           (tokeninfoclass == TokenUser) ? "TokenUser" :
316           (tokeninfoclass == TokenGroups) ? "TokenGroups" :
317           (tokeninfoclass == TokenPrivileges) ? "TokenPrivileges" :
318           (tokeninfoclass == TokenOwner) ? "TokenOwner" :
319           (tokeninfoclass == TokenPrimaryGroup) ? "TokenPrimaryGroup" :
320           (tokeninfoclass == TokenDefaultDacl) ? "TokenDefaultDacl" :
321           (tokeninfoclass == TokenSource) ? "TokenSource" :
322           (tokeninfoclass == TokenType) ? "TokenType" :
323           (tokeninfoclass == TokenImpersonationLevel) ? "TokenImpersonationLevel" :
324           (tokeninfoclass == TokenStatistics) ? "TokenStatistics" :
325           (tokeninfoclass == TokenRestrictedSids) ? "TokenRestrictedSids" :
326           (tokeninfoclass == TokenSessionId) ? "TokenSessionId" :
327           (tokeninfoclass == TokenGroupsAndPrivileges) ? "TokenGroupsAndPrivileges" :
328           (tokeninfoclass == TokenSessionReference) ? "TokenSessionReference" :
329           (tokeninfoclass == TokenSandBoxInert) ? "TokenSandBoxInert" :
330           "Unknown",
331           tokeninfo, tokeninfolength, retlen);
332     return set_ntstatus( NtQueryInformationToken( token, tokeninfoclass, tokeninfo,
333                                                   tokeninfolength, retlen));
334 }
335
336 /******************************************************************************
337  * SetTokenInformation [ADVAPI32.@]
338  *
339  * Set information for an access token.
340  *
341  * PARAMS
342  *   token           [I] Handle from OpenProcessToken() or OpenThreadToken()
343  *   tokeninfoclass  [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
344  *   tokeninfo       [I] Token information to set
345  *   tokeninfolength [I] Length of tokeninfo
346  *
347  * RETURNS
348  *  Success: TRUE. The information for the token is set to tokeninfo.
349  *  Failure: FALSE.
350  */
351 BOOL WINAPI
352 SetTokenInformation( HANDLE token, TOKEN_INFORMATION_CLASS tokeninfoclass,
353                      LPVOID tokeninfo, DWORD tokeninfolength )
354 {
355     TRACE("(%p, %s, %p, %ld): stub\n",
356           token,
357           (tokeninfoclass == TokenUser) ? "TokenUser" :
358           (tokeninfoclass == TokenGroups) ? "TokenGroups" :
359           (tokeninfoclass == TokenPrivileges) ? "TokenPrivileges" :
360           (tokeninfoclass == TokenOwner) ? "TokenOwner" :
361           (tokeninfoclass == TokenPrimaryGroup) ? "TokenPrimaryGroup" :
362           (tokeninfoclass == TokenDefaultDacl) ? "TokenDefaultDacl" :
363           (tokeninfoclass == TokenSource) ? "TokenSource" :
364           (tokeninfoclass == TokenType) ? "TokenType" :
365           (tokeninfoclass == TokenImpersonationLevel) ? "TokenImpersonationLevel" :
366           (tokeninfoclass == TokenStatistics) ? "TokenStatistics" :
367           (tokeninfoclass == TokenRestrictedSids) ? "TokenRestrictedSids" :
368           (tokeninfoclass == TokenSessionId) ? "TokenSessionId" :
369           (tokeninfoclass == TokenGroupsAndPrivileges) ? "TokenGroupsAndPrivileges" :
370           (tokeninfoclass == TokenSessionReference) ? "TokenSessionReference" :
371           (tokeninfoclass == TokenSandBoxInert) ? "TokenSandBoxInert" :
372           "Unknown",
373           tokeninfo, tokeninfolength);
374
375     return set_ntstatus( NtSetInformationToken( token, tokeninfoclass, tokeninfo, tokeninfolength ));
376 }
377
378 /*************************************************************************
379  * SetThreadToken [ADVAPI32.@]
380  *
381  * Assigns an 'impersonation token' to a thread so it can assume the
382  * security privileges of another thread or process.  Can also remove
383  * a previously assigned token. 
384  *
385  * PARAMS
386  *   thread          [O] Handle to thread to set the token for
387  *   token           [I] Token to set
388  *
389  * RETURNS
390  *  Success: TRUE. The threads access token is set to token
391  *  Failure: FALSE.
392  *
393  * NOTES
394  *  Only supported on NT or higher. On Win9X this function does nothing.
395  *  See SetTokenInformation.
396  */
397 BOOL WINAPI SetThreadToken(PHANDLE thread, HANDLE token)
398 {
399     return set_ntstatus( NtSetInformationThread( thread ? *thread : GetCurrentThread(),
400                                                  ThreadImpersonationToken, &token, sizeof token ));
401 }
402
403 /*      ##############################
404         ######  SID FUNCTIONS   ######
405         ##############################
406 */
407
408 /******************************************************************************
409  * AllocateAndInitializeSid [ADVAPI32.@]
410  *
411  * PARAMS
412  *   pIdentifierAuthority []
413  *   nSubAuthorityCount   []
414  *   nSubAuthority0       []
415  *   nSubAuthority1       []
416  *   nSubAuthority2       []
417  *   nSubAuthority3       []
418  *   nSubAuthority4       []
419  *   nSubAuthority5       []
420  *   nSubAuthority6       []
421  *   nSubAuthority7       []
422  *   pSid                 []
423  */
424 BOOL WINAPI
425 AllocateAndInitializeSid( PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
426                           BYTE nSubAuthorityCount,
427                           DWORD nSubAuthority0, DWORD nSubAuthority1,
428                           DWORD nSubAuthority2, DWORD nSubAuthority3,
429                           DWORD nSubAuthority4, DWORD nSubAuthority5,
430                           DWORD nSubAuthority6, DWORD nSubAuthority7,
431                           PSID *pSid )
432 {
433     return set_ntstatus( RtlAllocateAndInitializeSid(
434                              pIdentifierAuthority, nSubAuthorityCount,
435                              nSubAuthority0, nSubAuthority1, nSubAuthority2, nSubAuthority3,
436                              nSubAuthority4, nSubAuthority5, nSubAuthority6, nSubAuthority7,
437                              pSid ));
438 }
439
440 /******************************************************************************
441  * FreeSid [ADVAPI32.@]
442  *
443  * PARAMS
444  *   pSid []
445  */
446 PVOID WINAPI
447 FreeSid( PSID pSid )
448 {
449         RtlFreeSid(pSid);
450         return NULL; /* is documented like this */
451 }
452
453 /******************************************************************************
454  * CopySid [ADVAPI32.@]
455  *
456  * PARAMS
457  *   nDestinationSidLength []
458  *   pDestinationSid       []
459  *   pSourceSid            []
460  */
461 BOOL WINAPI
462 CopySid( DWORD nDestinationSidLength, PSID pDestinationSid, PSID pSourceSid )
463 {
464         return RtlCopySid(nDestinationSidLength, pDestinationSid, pSourceSid);
465 }
466
467 BOOL WINAPI
468 IsTokenRestricted( HANDLE TokenHandle )
469 {
470     FIXME("%p - stub\n", TokenHandle);
471
472     return FALSE;
473 }
474
475 /******************************************************************************
476  * IsValidSid [ADVAPI32.@]
477  *
478  * PARAMS
479  *   pSid []
480  */
481 BOOL WINAPI
482 IsValidSid( PSID pSid )
483 {
484         return RtlValidSid( pSid );
485 }
486
487 /******************************************************************************
488  * EqualSid [ADVAPI32.@]
489  *
490  * PARAMS
491  *   pSid1 []
492  *   pSid2 []
493  */
494 BOOL WINAPI
495 EqualSid( PSID pSid1, PSID pSid2 )
496 {
497         return RtlEqualSid( pSid1, pSid2 );
498 }
499
500 /******************************************************************************
501  * EqualPrefixSid [ADVAPI32.@]
502  */
503 BOOL WINAPI EqualPrefixSid (PSID pSid1, PSID pSid2)
504 {
505         return RtlEqualPrefixSid(pSid1, pSid2);
506 }
507
508 /******************************************************************************
509  * GetSidLengthRequired [ADVAPI32.@]
510  *
511  * PARAMS
512  *   nSubAuthorityCount []
513  */
514 DWORD WINAPI
515 GetSidLengthRequired( BYTE nSubAuthorityCount )
516 {
517         return RtlLengthRequiredSid(nSubAuthorityCount);
518 }
519
520 /******************************************************************************
521  * InitializeSid [ADVAPI32.@]
522  *
523  * PARAMS
524  *   pIdentifierAuthority []
525  */
526 BOOL WINAPI
527 InitializeSid (
528         PSID pSid,
529         PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
530         BYTE nSubAuthorityCount)
531 {
532         return RtlInitializeSid(pSid, pIdentifierAuthority, nSubAuthorityCount);
533 }
534
535 DWORD WINAPI
536 GetEffectiveRightsFromAclA( PACL pacl, PTRUSTEEA pTrustee, PACCESS_MASK pAccessRights )
537 {
538     FIXME("%p %p %p - stub\n", pacl, pTrustee, pAccessRights);
539
540     return 1;
541 }
542
543 DWORD WINAPI
544 GetEffectiveRightsFromAclW( PACL pacl, PTRUSTEEW pTrustee, PACCESS_MASK pAccessRights )
545 {
546     FIXME("%p %p %p - stub\n", pacl, pTrustee, pAccessRights);
547
548     return 1;
549 }
550
551 /******************************************************************************
552  * GetSidIdentifierAuthority [ADVAPI32.@]
553  *
554  * PARAMS
555  *   pSid []
556  */
557 PSID_IDENTIFIER_AUTHORITY WINAPI
558 GetSidIdentifierAuthority( PSID pSid )
559 {
560         return RtlIdentifierAuthoritySid(pSid);
561 }
562
563 /******************************************************************************
564  * GetSidSubAuthority [ADVAPI32.@]
565  *
566  * PARAMS
567  *   pSid          []
568  *   nSubAuthority []
569  */
570 PDWORD WINAPI
571 GetSidSubAuthority( PSID pSid, DWORD nSubAuthority )
572 {
573         return RtlSubAuthoritySid(pSid, nSubAuthority);
574 }
575
576 /******************************************************************************
577  * GetSidSubAuthorityCount [ADVAPI32.@]
578  *
579  * PARAMS
580  *   pSid []
581  */
582 PUCHAR WINAPI
583 GetSidSubAuthorityCount (PSID pSid)
584 {
585         return RtlSubAuthorityCountSid(pSid);
586 }
587
588 /******************************************************************************
589  * GetLengthSid [ADVAPI32.@]
590  *
591  * PARAMS
592  *   pSid []
593  */
594 DWORD WINAPI
595 GetLengthSid (PSID pSid)
596 {
597         return RtlLengthSid(pSid);
598 }
599
600 /*      ##############################################
601         ######  SECURITY DESCRIPTOR FUNCTIONS   ######
602         ##############################################
603 */
604
605 /******************************************************************************
606  * InitializeSecurityDescriptor [ADVAPI32.@]
607  *
608  * PARAMS
609  *   pDescr   []
610  *   revision []
611  */
612 BOOL WINAPI
613 InitializeSecurityDescriptor( PSECURITY_DESCRIPTOR pDescr, DWORD revision )
614 {
615         return set_ntstatus( RtlCreateSecurityDescriptor(pDescr, revision ));
616 }
617
618
619 /******************************************************************************
620  * MakeAbsoluteSD [ADVAPI32.@]
621  */
622 BOOL WINAPI MakeAbsoluteSD (
623         IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
624         OUT PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
625         OUT LPDWORD lpdwAbsoluteSecurityDescriptorSize,
626         OUT PACL pDacl,
627         OUT LPDWORD lpdwDaclSize,
628         OUT PACL pSacl,
629         OUT LPDWORD lpdwSaclSize,
630         OUT PSID pOwner,
631         OUT LPDWORD lpdwOwnerSize,
632         OUT PSID pPrimaryGroup,
633         OUT LPDWORD lpdwPrimaryGroupSize)
634 {
635     return set_ntstatus( RtlSelfRelativeToAbsoluteSD(pSelfRelativeSecurityDescriptor,
636                                                      pAbsoluteSecurityDescriptor,
637                                                      lpdwAbsoluteSecurityDescriptorSize,
638                                                      pDacl, lpdwDaclSize, pSacl, lpdwSaclSize,
639                                                      pOwner, lpdwOwnerSize,
640                                                      pPrimaryGroup, lpdwPrimaryGroupSize));
641 }
642
643 BOOL WINAPI GetKernelObjectSecurity(
644         HANDLE Handle,
645         SECURITY_INFORMATION RequestedInformation,
646         PSECURITY_DESCRIPTOR pSecurityDescriptor,
647         DWORD nLength,
648         LPDWORD lpnLengthNeeded )
649 {
650     FIXME("%p 0x%08lx %p 0x%08lx %p - stub\n", Handle, RequestedInformation,
651           pSecurityDescriptor, nLength, lpnLengthNeeded);
652
653     return FALSE;
654 }
655
656 BOOL WINAPI GetPrivateObjectSecurity(
657         PSECURITY_DESCRIPTOR ObjectDescriptor,
658         SECURITY_INFORMATION SecurityInformation,
659         PSECURITY_DESCRIPTOR ResultantDescriptor,
660         DWORD DescriptorLength,
661         PDWORD ReturnLength )
662 {
663     FIXME("%p 0x%08lx %p 0x%08lx %p - stub\n", ObjectDescriptor, SecurityInformation,
664           ResultantDescriptor, DescriptorLength, ReturnLength);
665
666     return FALSE;
667 }
668
669 /******************************************************************************
670  * GetSecurityDescriptorLength [ADVAPI32.@]
671  */
672 DWORD WINAPI GetSecurityDescriptorLength( PSECURITY_DESCRIPTOR pDescr)
673 {
674         return RtlLengthSecurityDescriptor(pDescr);
675 }
676
677 /******************************************************************************
678  * GetSecurityDescriptorOwner [ADVAPI32.@]
679  *
680  * PARAMS
681  *   pOwner            []
682  *   lpbOwnerDefaulted []
683  */
684 BOOL WINAPI
685 GetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pDescr, PSID *pOwner,
686                             LPBOOL lpbOwnerDefaulted )
687 {
688     BOOLEAN defaulted;
689     BOOL ret = set_ntstatus( RtlGetOwnerSecurityDescriptor( pDescr, pOwner, &defaulted ));
690     *lpbOwnerDefaulted = defaulted;
691     return ret;
692 }
693
694 /******************************************************************************
695  * SetSecurityDescriptorOwner [ADVAPI32.@]
696  *
697  * PARAMS
698  */
699 BOOL WINAPI SetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pSecurityDescriptor,
700                                    PSID pOwner, BOOL bOwnerDefaulted)
701 {
702     return set_ntstatus( RtlSetOwnerSecurityDescriptor(pSecurityDescriptor, pOwner, bOwnerDefaulted));
703 }
704 /******************************************************************************
705  * GetSecurityDescriptorGroup                   [ADVAPI32.@]
706  */
707 BOOL WINAPI GetSecurityDescriptorGroup(
708         PSECURITY_DESCRIPTOR SecurityDescriptor,
709         PSID *Group,
710         LPBOOL GroupDefaulted)
711 {
712     BOOLEAN defaulted;
713     BOOL ret = set_ntstatus( RtlGetGroupSecurityDescriptor(SecurityDescriptor, Group, &defaulted ));
714     *GroupDefaulted = defaulted;
715     return ret;
716 }
717 /******************************************************************************
718  * SetSecurityDescriptorGroup [ADVAPI32.@]
719  */
720 BOOL WINAPI SetSecurityDescriptorGroup ( PSECURITY_DESCRIPTOR SecurityDescriptor,
721                                            PSID Group, BOOL GroupDefaulted)
722 {
723     return set_ntstatus( RtlSetGroupSecurityDescriptor( SecurityDescriptor, Group, GroupDefaulted));
724 }
725
726 /******************************************************************************
727  * IsValidSecurityDescriptor [ADVAPI32.@]
728  *
729  * PARAMS
730  *   lpsecdesc []
731  */
732 BOOL WINAPI
733 IsValidSecurityDescriptor( PSECURITY_DESCRIPTOR SecurityDescriptor )
734 {
735     return set_ntstatus( RtlValidSecurityDescriptor(SecurityDescriptor));
736 }
737
738 /******************************************************************************
739  *  GetSecurityDescriptorDacl                   [ADVAPI32.@]
740  */
741 BOOL WINAPI GetSecurityDescriptorDacl(
742         IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
743         OUT LPBOOL lpbDaclPresent,
744         OUT PACL *pDacl,
745         OUT LPBOOL lpbDaclDefaulted)
746 {
747     BOOLEAN present, defaulted;
748     BOOL ret = set_ntstatus( RtlGetDaclSecurityDescriptor(pSecurityDescriptor, &present, pDacl, &defaulted));
749     *lpbDaclPresent = present;
750     *lpbDaclDefaulted = defaulted;
751     return ret;
752 }
753
754 /******************************************************************************
755  *  SetSecurityDescriptorDacl                   [ADVAPI32.@]
756  */
757 BOOL WINAPI
758 SetSecurityDescriptorDacl (
759         PSECURITY_DESCRIPTOR lpsd,
760         BOOL daclpresent,
761         PACL dacl,
762         BOOL dacldefaulted )
763 {
764     return set_ntstatus( RtlSetDaclSecurityDescriptor (lpsd, daclpresent, dacl, dacldefaulted ) );
765 }
766 /******************************************************************************
767  *  GetSecurityDescriptorSacl                   [ADVAPI32.@]
768  */
769 BOOL WINAPI GetSecurityDescriptorSacl(
770         IN PSECURITY_DESCRIPTOR lpsd,
771         OUT LPBOOL lpbSaclPresent,
772         OUT PACL *pSacl,
773         OUT LPBOOL lpbSaclDefaulted)
774 {
775     BOOLEAN present, defaulted;
776     BOOL ret = set_ntstatus( RtlGetSaclSecurityDescriptor(lpsd, &present, pSacl, &defaulted) );
777     *lpbSaclPresent = present;
778     *lpbSaclDefaulted = defaulted;
779     return ret;
780 }
781
782 /**************************************************************************
783  * SetSecurityDescriptorSacl                    [ADVAPI32.@]
784  */
785 BOOL WINAPI SetSecurityDescriptorSacl (
786         PSECURITY_DESCRIPTOR lpsd,
787         BOOL saclpresent,
788         PACL lpsacl,
789         BOOL sacldefaulted)
790 {
791     return set_ntstatus (RtlSetSaclSecurityDescriptor(lpsd, saclpresent, lpsacl, sacldefaulted));
792 }
793 /******************************************************************************
794  * MakeSelfRelativeSD [ADVAPI32.@]
795  *
796  * PARAMS
797  *   lpabssecdesc  []
798  *   lpselfsecdesc []
799  *   lpbuflen      []
800  */
801 BOOL WINAPI
802 MakeSelfRelativeSD(
803         IN PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
804         IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
805         IN OUT LPDWORD lpdwBufferLength)
806 {
807     return set_ntstatus( RtlMakeSelfRelativeSD( pAbsoluteSecurityDescriptor,
808                                                 pSelfRelativeSecurityDescriptor, lpdwBufferLength));
809 }
810
811 /******************************************************************************
812  * GetSecurityDescriptorControl                 [ADVAPI32.@]
813  */
814
815 BOOL WINAPI GetSecurityDescriptorControl ( PSECURITY_DESCRIPTOR  pSecurityDescriptor,
816                  PSECURITY_DESCRIPTOR_CONTROL pControl, LPDWORD lpdwRevision)
817 {
818     return set_ntstatus( RtlGetControlSecurityDescriptor(pSecurityDescriptor,pControl,lpdwRevision));
819 }
820
821 /*      ##############################
822         ######  ACL FUNCTIONS   ######
823         ##############################
824 */
825
826 /*************************************************************************
827  * InitializeAcl [ADVAPI32.@]
828  */
829 BOOL WINAPI InitializeAcl(PACL acl, DWORD size, DWORD rev)
830 {
831     return set_ntstatus( RtlCreateAcl(acl, size, rev));
832 }
833
834 BOOL WINAPI ImpersonateNamedPipeClient( HANDLE hNamedPipe )
835 {
836     FIXME("%p - stub\n", hNamedPipe);
837
838     return FALSE;
839 }
840
841 /******************************************************************************
842  *  AddAccessAllowedAce [ADVAPI32.@]
843  */
844 BOOL WINAPI AddAccessAllowedAce(
845         IN OUT PACL pAcl,
846         IN DWORD dwAceRevision,
847         IN DWORD AccessMask,
848         IN PSID pSid)
849 {
850     return set_ntstatus(RtlAddAccessAllowedAce(pAcl, dwAceRevision, AccessMask, pSid));
851 }
852
853 /******************************************************************************
854  *  AddAccessAllowedAceEx [ADVAPI32.@]
855  */
856 BOOL WINAPI AddAccessAllowedAceEx(
857         IN OUT PACL pAcl,
858         IN DWORD dwAceRevision,
859         IN DWORD AceFlags,
860         IN DWORD AccessMask,
861         IN PSID pSid)
862 {
863     return set_ntstatus(RtlAddAccessAllowedAceEx(pAcl, dwAceRevision, AceFlags, AccessMask, pSid));
864 }
865
866 /******************************************************************************
867  *  AddAccessDeniedAce [ADVAPI32.@]
868  */
869 BOOL WINAPI AddAccessDeniedAce(
870         IN OUT PACL pAcl,
871         IN DWORD dwAceRevision,
872         IN DWORD AccessMask,
873         IN PSID pSid)
874 {
875     return set_ntstatus(RtlAddAccessDeniedAce(pAcl, dwAceRevision, AccessMask, pSid));
876 }
877
878 /******************************************************************************
879  *  AddAccessDeniedAceEx [ADVAPI32.@]
880  */
881 BOOL WINAPI AddAccessDeniedAceEx(
882         IN OUT PACL pAcl,
883         IN DWORD dwAceRevision,
884         IN DWORD AceFlags,
885         IN DWORD AccessMask,
886         IN PSID pSid)
887 {
888     return set_ntstatus(RtlAddAccessDeniedAceEx(pAcl, dwAceRevision, AceFlags, AccessMask, pSid));
889 }
890
891 /******************************************************************************
892  *  AddAce [ADVAPI32.@]
893  */
894 BOOL WINAPI AddAce(
895         IN OUT PACL pAcl,
896         IN DWORD dwAceRevision,
897         IN DWORD dwStartingAceIndex,
898         LPVOID pAceList,
899         DWORD nAceListLength)
900 {
901     return set_ntstatus(RtlAddAce(pAcl, dwAceRevision, dwStartingAceIndex, pAceList, nAceListLength));
902 }
903
904 /******************************************************************************
905  * DeleteAce [ADVAPI32.@]
906  */
907 BOOL WINAPI DeleteAce(PACL pAcl, DWORD dwAceIndex)
908 {
909     return set_ntstatus(RtlDeleteAce(pAcl, dwAceIndex));
910 }
911
912 /******************************************************************************
913  *  FindFirstFreeAce [ADVAPI32.@]
914  */
915 BOOL WINAPI FindFirstFreeAce(IN PACL pAcl, LPVOID * pAce)
916 {
917         return RtlFirstFreeAce(pAcl, (PACE_HEADER *)pAce);
918 }
919
920 /******************************************************************************
921  * GetAce [ADVAPI32.@]
922  */
923 BOOL WINAPI GetAce(PACL pAcl,DWORD dwAceIndex,LPVOID *pAce )
924 {
925     return set_ntstatus(RtlGetAce(pAcl, dwAceIndex, pAce));
926 }
927
928 /******************************************************************************
929  * GetAclInformation [ADVAPI32.@]
930  */
931 BOOL WINAPI GetAclInformation(
932   PACL pAcl,
933   LPVOID pAclInformation,
934   DWORD nAclInformationLength,
935   ACL_INFORMATION_CLASS dwAclInformationClass)
936 {
937     return set_ntstatus(RtlQueryInformationAcl(pAcl, pAclInformation,
938                                                nAclInformationLength, dwAclInformationClass));
939 }
940
941 /******************************************************************************
942  *  IsValidAcl [ADVAPI32.@]
943  */
944 BOOL WINAPI IsValidAcl(IN PACL pAcl)
945 {
946         return RtlValidAcl(pAcl);
947 }
948
949 /*      ##############################
950         ######  MISC FUNCTIONS  ######
951         ##############################
952 */
953
954 /******************************************************************************
955  * AllocateLocallyUniqueId [ADVAPI32.@]
956  *
957  * PARAMS
958  *   lpLuid []
959  */
960 BOOL WINAPI AllocateLocallyUniqueId( PLUID lpLuid )
961 {
962     return set_ntstatus(NtAllocateLocallyUniqueId(lpLuid));
963 }
964
965 static const WCHAR SE_CREATE_TOKEN_NAME_W[] =
966  { 'S','e','C','r','e','a','t','e','T','o','k','e','n','P','r','i','v','i','l','e','g','e',0 };
967 static const WCHAR SE_ASSIGNPRIMARYTOKEN_NAME_W[] =
968  { 'S','e','A','s','s','i','g','n','P','r','i','m','a','r','y','T','o','k','e','n','P','r','i','v','i','l','e','g','e',0 };
969 static const WCHAR SE_LOCK_MEMORY_NAME_W[] =
970  { 'S','e','L','o','c','k','M','e','m','o','r','y','P','r','i','v','i','l','e','g','e',0 };
971 static const WCHAR SE_INCREASE_QUOTA_NAME_W[] =
972  { 'S','e','I','n','c','r','e','a','s','e','Q','u','o','t','a','P','r','i','v','i','l','e','g','e',0 };
973 static const WCHAR SE_MACHINE_ACCOUNT_NAME_W[] =
974  { 'S','e','M','a','c','h','i','n','e','A','c','c','o','u','n','t','P','r','i','v','i','l','e','g','e',0 };
975 static const WCHAR SE_TCB_NAME_W[] =
976  { 'S','e','T','c','b','P','r','i','v','i','l','e','g','e',0 };
977 static const WCHAR SE_SECURITY_NAME_W[] =
978  { 'S','e','S','e','c','u','r','i','t','y','P','r','i','v','i','l','e','g','e',0 };
979 static const WCHAR SE_TAKE_OWNERSHIP_NAME_W[] =
980  { 'S','e','T','a','k','e','O','w','n','e','r','s','h','i','p','P','r','i','v','i','l','e','g','e',0 };
981 static const WCHAR SE_LOAD_DRIVER_NAME_W[] =
982  { 'S','e','L','o','a','d','D','r','i','v','e','r','P','r','i','v','i','l','e','g','e',0 };
983 static const WCHAR SE_SYSTEM_PROFILE_NAME_W[] =
984  { 'S','e','S','y','s','t','e','m','P','r','o','f','i','l','e','P','r','i','v','i','l','e','g','e',0 };
985 static const WCHAR SE_SYSTEMTIME_NAME_W[] =
986  { 'S','e','S','y','s','t','e','m','t','i','m','e','P','r','i','v','i','l','e','g','e',0 };
987 static const WCHAR SE_PROF_SINGLE_PROCESS_NAME_W[] =
988  { 'S','e','P','r','o','f','i','l','e','S','i','n','g','l','e','P','r','o','c','e','s','s','P','r','i','v','i','l','e','g','e',0 };
989 static const WCHAR SE_INC_BASE_PRIORITY_NAME_W[] =
990  { 'S','e','I','n','c','r','e','a','s','e','B','a','s','e','P','r','i','o','r','i','t','y','P','r','i','v','i','l','e','g','e',0 };
991 static const WCHAR SE_CREATE_PAGEFILE_NAME_W[] =
992  { 'S','e','C','r','e','a','t','e','P','a','g','e','f','i','l','e','P','r','i','v','i','l','e','g','e',0 };
993 static const WCHAR SE_CREATE_PERMANENT_NAME_W[] =
994  { 'S','e','C','r','e','a','t','e','P','e','r','m','a','n','e','n','t','P','r','i','v','i','l','e','g','e',0 };
995 static const WCHAR SE_BACKUP_NAME_W[] =
996  { 'S','e','B','a','c','k','u','p','P','r','i','v','i','l','e','g','e',0 };
997 static const WCHAR SE_RESTORE_NAME_W[] =
998  { 'S','e','R','e','s','t','o','r','e','P','r','i','v','i','l','e','g','e',0 };
999 static const WCHAR SE_SHUTDOWN_NAME_W[] =
1000  { 'S','e','S','h','u','t','d','o','w','n','P','r','i','v','i','l','e','g','e',0 };
1001 static const WCHAR SE_DEBUG_NAME_W[] =
1002  { 'S','e','D','e','b','u','g','P','r','i','v','i','l','e','g','e',0 };
1003 static const WCHAR SE_AUDIT_NAME_W[] =
1004  { 'S','e','A','u','d','i','t','P','r','i','v','i','l','e','g','e',0 };
1005 static const WCHAR SE_SYSTEM_ENVIRONMENT_NAME_W[] =
1006  { 'S','e','S','y','s','t','e','m','E','n','v','i','r','o','n','m','e','n','t','P','r','i','v','i','l','e','g','e',0 };
1007 static const WCHAR SE_CHANGE_NOTIFY_NAME_W[] =
1008  { 'S','e','C','h','a','n','g','e','N','o','t','i','f','y','P','r','i','v','i','l','e','g','e',0 };
1009 static const WCHAR SE_REMOTE_SHUTDOWN_NAME_W[] =
1010  { 'S','e','R','e','m','o','t','e','S','h','u','t','d','o','w','n','P','r','i','v','i','l','e','g','e',0 };
1011 static const WCHAR SE_UNDOCK_NAME_W[] =
1012  { 'S','e','U','n','d','o','c','k','P','r','i','v','i','l','e','g','e',0 };
1013 static const WCHAR SE_SYNC_AGENT_NAME_W[] =
1014  { 'S','e','S','y','n','c','A','g','e','n','t','P','r','i','v','i','l','e','g','e',0 };
1015 static const WCHAR SE_ENABLE_DELEGATION_NAME_W[] =
1016  { 'S','e','E','n','a','b','l','e','D','e','l','e','g','a','t','i','o','n','P','r','i','v','i','l','e','g','e',0 };
1017 static const WCHAR SE_MANAGE_VOLUME_NAME_W[] =
1018  { 'S','e','M','a','n','a','g','e','V','o','l','u','m','e','P','r','i','v','i','l','e','g','e',0 };
1019 static const WCHAR SE_IMPERSONATE_NAME_W[] =
1020  { 'S','e','I','m','p','e','r','s','o','n','a','t','e','P','r','i','v','i','l','e','g','e',0 };
1021 static const WCHAR SE_CREATE_GLOBAL_NAME_W[] =
1022  { 'S','e','C','r','e','a','t','e','G','l','o','b','a','l','P','r','i','v','i','l','e','g','e',0 };
1023
1024 static const WCHAR * const WellKnownPrivNames[SE_MAX_WELL_KNOWN_PRIVILEGE + 1] =
1025 {
1026     NULL,
1027     NULL,
1028     SE_CREATE_TOKEN_NAME_W,
1029     SE_ASSIGNPRIMARYTOKEN_NAME_W,
1030     SE_LOCK_MEMORY_NAME_W,
1031     SE_INCREASE_QUOTA_NAME_W,
1032     SE_MACHINE_ACCOUNT_NAME_W,
1033     SE_TCB_NAME_W,
1034     SE_SECURITY_NAME_W,
1035     SE_TAKE_OWNERSHIP_NAME_W,
1036     SE_LOAD_DRIVER_NAME_W,
1037     SE_SYSTEM_PROFILE_NAME_W,
1038     SE_SYSTEMTIME_NAME_W,
1039     SE_PROF_SINGLE_PROCESS_NAME_W,
1040     SE_INC_BASE_PRIORITY_NAME_W,
1041     SE_CREATE_PAGEFILE_NAME_W,
1042     SE_CREATE_PERMANENT_NAME_W,
1043     SE_BACKUP_NAME_W,
1044     SE_RESTORE_NAME_W,
1045     SE_SHUTDOWN_NAME_W,
1046     SE_DEBUG_NAME_W,
1047     SE_AUDIT_NAME_W,
1048     SE_SYSTEM_ENVIRONMENT_NAME_W,
1049     SE_CHANGE_NOTIFY_NAME_W,
1050     SE_REMOTE_SHUTDOWN_NAME_W,
1051     SE_UNDOCK_NAME_W,
1052     SE_SYNC_AGENT_NAME_W,
1053     SE_ENABLE_DELEGATION_NAME_W,
1054     SE_MANAGE_VOLUME_NAME_W,
1055     SE_IMPERSONATE_NAME_W,
1056     SE_CREATE_GLOBAL_NAME_W,
1057 };
1058
1059 /******************************************************************************
1060  * LookupPrivilegeValueW                        [ADVAPI32.@]
1061  *
1062  * See LookupPrivilegeValueA.
1063  */
1064 BOOL WINAPI
1065 LookupPrivilegeValueW( LPCWSTR lpSystemName, LPCWSTR lpName, PLUID lpLuid )
1066 {
1067     UINT i;
1068
1069     TRACE("%s,%s,%p\n",debugstr_w(lpSystemName), debugstr_w(lpName), lpLuid);
1070
1071     if (!ADVAPI_IsLocalComputer(lpSystemName))
1072     {
1073         SetLastError(RPC_S_SERVER_UNAVAILABLE);
1074         return FALSE;
1075     }
1076     if (!lpName)
1077     {
1078         SetLastError(ERROR_NO_SUCH_PRIVILEGE);
1079         return FALSE;
1080     }
1081     for( i=SE_MIN_WELL_KNOWN_PRIVILEGE; i<SE_MAX_WELL_KNOWN_PRIVILEGE; i++ )
1082     {
1083         if( !WellKnownPrivNames[i] )
1084             continue;
1085         if( strcmpiW( WellKnownPrivNames[i], lpName) )
1086             continue;
1087         lpLuid->LowPart = i;
1088         lpLuid->HighPart = 0;
1089         TRACE( "%s -> %08lx-%08lx\n",debugstr_w( lpSystemName ),
1090                lpLuid->HighPart, lpLuid->LowPart );
1091         return TRUE;
1092     }
1093     SetLastError(ERROR_NO_SUCH_PRIVILEGE);
1094     return FALSE;
1095 }
1096
1097 /******************************************************************************
1098  * LookupPrivilegeValueA                        [ADVAPI32.@]
1099  *
1100  * Retrieves LUID used on a system to represent the privilege name.
1101  *
1102  * PARAMS
1103  *  lpSystemName [I] Name of the system
1104  *  lpName       [I] Name of the privilege
1105  *  lpLuid       [O] Destination for the resulting LUID
1106  *
1107  * RETURNS
1108  *  Success: TRUE. lpLuid contains the requested LUID.
1109  *  Failure: FALSE.
1110  */
1111 BOOL WINAPI
1112 LookupPrivilegeValueA( LPCSTR lpSystemName, LPCSTR lpName, PLUID lpLuid )
1113 {
1114     UNICODE_STRING lpSystemNameW;
1115     UNICODE_STRING lpNameW;
1116     BOOL ret;
1117
1118     RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW, lpSystemName);
1119     RtlCreateUnicodeStringFromAsciiz(&lpNameW,lpName);
1120     ret = LookupPrivilegeValueW(lpSystemNameW.Buffer, lpNameW.Buffer, lpLuid);
1121     RtlFreeUnicodeString(&lpNameW);
1122     RtlFreeUnicodeString(&lpSystemNameW);
1123     return ret;
1124 }
1125
1126 BOOL WINAPI LookupPrivilegeDisplayNameA( LPCSTR lpSystemName, LPCSTR lpName, LPSTR lpDisplayName,
1127                                          LPDWORD cchDisplayName, LPDWORD lpLanguageId )
1128 {
1129     FIXME("%s %s %s %p %p - stub\n", debugstr_a(lpSystemName), debugstr_a(lpName),
1130           debugstr_a(lpDisplayName), cchDisplayName, lpLanguageId);
1131
1132     return FALSE;
1133 }
1134
1135 BOOL WINAPI LookupPrivilegeDisplayNameW( LPCWSTR lpSystemName, LPCWSTR lpName, LPWSTR lpDisplayName,
1136                                          LPDWORD cchDisplayName, LPDWORD lpLanguageId )
1137 {
1138     FIXME("%s %s %s %p %p - stub\n", debugstr_w(lpSystemName), debugstr_w(lpName),
1139           debugstr_w(lpDisplayName), cchDisplayName, lpLanguageId);
1140
1141     return FALSE;
1142 }
1143
1144 /******************************************************************************
1145  * LookupPrivilegeNameA                 [ADVAPI32.@]
1146  *
1147  * See LookupPrivilegeNameW
1148  */
1149 BOOL WINAPI
1150 LookupPrivilegeNameA( LPCSTR lpSystemName, PLUID lpLuid, LPSTR lpName,
1151  LPDWORD cchName)
1152 {
1153     UNICODE_STRING lpSystemNameW;
1154     BOOL ret;
1155     DWORD wLen = 0;
1156
1157     TRACE("%s %p %p %p\n", debugstr_a(lpSystemName), lpLuid, lpName, cchName);
1158
1159     RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW, lpSystemName);
1160     ret = LookupPrivilegeNameW(lpSystemNameW.Buffer, lpLuid, NULL, &wLen);
1161     if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
1162     {
1163         LPWSTR lpNameW = HeapAlloc(GetProcessHeap(), 0, wLen * sizeof(WCHAR));
1164
1165         ret = LookupPrivilegeNameW(lpSystemNameW.Buffer, lpLuid, lpNameW,
1166          &wLen);
1167         if (ret)
1168         {
1169             /* Windows crashes if cchName is NULL, so will I */
1170             int len = WideCharToMultiByte(CP_ACP, 0, lpNameW, -1, lpName,
1171              *cchName, NULL, NULL);
1172
1173             if (len == 0)
1174             {
1175                 /* WideCharToMultiByte failed */
1176                 ret = FALSE;
1177             }
1178             else if (len > *cchName)
1179             {
1180                 *cchName = len;
1181                 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1182                 ret = FALSE;
1183             }
1184             else
1185             {
1186                 /* WideCharToMultiByte succeeded, output length needs to be
1187                  * length not including NULL terminator
1188                  */
1189                 *cchName = len - 1;
1190             }
1191         }
1192         HeapFree(GetProcessHeap(), 0, lpNameW);
1193     }
1194     RtlFreeUnicodeString(&lpSystemNameW);
1195     return ret;
1196 }
1197
1198 /******************************************************************************
1199  * LookupPrivilegeNameW                 [ADVAPI32.@]
1200  *
1201  * Retrieves the privilege name referred to by the LUID lpLuid.
1202  *
1203  * PARAMS
1204  *  lpSystemName [I]   Name of the system
1205  *  lpLuid       [I]   Privilege value
1206  *  lpName       [O]   Name of the privilege
1207  *  cchName      [I/O] Number of characters in lpName.
1208  *
1209  * RETURNS
1210  *  Success: TRUE. lpName contains the name of the privilege whose value is
1211  *  *lpLuid.
1212  *  Failure: FALSE.
1213  *
1214  * REMARKS
1215  *  Only well-known privilege names (those defined in winnt.h) can be retrieved
1216  *  using this function.
1217  *  If the length of lpName is too small, on return *cchName will contain the
1218  *  number of WCHARs needed to contain the privilege, including the NULL
1219  *  terminator, and GetLastError will return ERROR_INSUFFICIENT_BUFFER.
1220  *  On success, *cchName will contain the number of characters stored in
1221  *  lpName, NOT including the NULL terminator.
1222  */
1223 BOOL WINAPI
1224 LookupPrivilegeNameW( LPCWSTR lpSystemName, PLUID lpLuid, LPWSTR lpName,
1225  LPDWORD cchName)
1226 {
1227     size_t privNameLen;
1228
1229     TRACE("%s,%p,%p,%p\n",debugstr_w(lpSystemName), lpLuid, lpName, cchName);
1230
1231     if (!ADVAPI_IsLocalComputer(lpSystemName))
1232     {
1233         SetLastError(RPC_S_SERVER_UNAVAILABLE);
1234         return FALSE;
1235     }
1236     if (lpLuid->HighPart || (lpLuid->LowPart < SE_MIN_WELL_KNOWN_PRIVILEGE ||
1237      lpLuid->LowPart > SE_MAX_WELL_KNOWN_PRIVILEGE))
1238     {
1239         SetLastError(ERROR_NO_SUCH_PRIVILEGE);
1240         return FALSE;
1241     }
1242     privNameLen = strlenW(WellKnownPrivNames[lpLuid->LowPart]);
1243     /* Windows crashes if cchName is NULL, so will I */
1244     if (*cchName <= privNameLen)
1245     {
1246         *cchName = privNameLen + 1;
1247         SetLastError(ERROR_INSUFFICIENT_BUFFER);
1248         return FALSE;
1249     }
1250     else
1251     {
1252         strcpyW(lpName, WellKnownPrivNames[lpLuid->LowPart]);
1253         *cchName = privNameLen;
1254         return TRUE;
1255     }
1256 }
1257
1258 /******************************************************************************
1259  * GetFileSecurityA [ADVAPI32.@]
1260  *
1261  * Obtains Specified information about the security of a file or directory.
1262  *
1263  * PARAMS
1264  *  lpFileName           [I] Name of the file to get info for
1265  *  RequestedInformation [I] SE_ flags from "winnt.h"
1266  *  pSecurityDescriptor  [O] Destination for security information
1267  *  nLength              [I] Length of pSecurityDescriptor
1268  *  lpnLengthNeeded      [O] Destination for length of returned security information
1269  *
1270  * RETURNS
1271  *  Success: TRUE. pSecurityDescriptor contains the requested information.
1272  *  Failure: FALSE. lpnLengthNeeded contains the required space to return the info. 
1273  *
1274  * NOTES
1275  *  The information returned is constrained by the callers access rights and
1276  *  privileges.
1277  */
1278 BOOL WINAPI
1279 GetFileSecurityA( LPCSTR lpFileName,
1280                     SECURITY_INFORMATION RequestedInformation,
1281                     PSECURITY_DESCRIPTOR pSecurityDescriptor,
1282                     DWORD nLength, LPDWORD lpnLengthNeeded )
1283 {
1284     DWORD len;
1285     BOOL r;
1286     LPWSTR name = NULL;
1287
1288     if( lpFileName )
1289     {
1290         len = MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, NULL, 0 );
1291         name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
1292         MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, name, len );
1293     }
1294
1295     r = GetFileSecurityW( name, RequestedInformation, pSecurityDescriptor,
1296                           nLength, lpnLengthNeeded );
1297     HeapFree( GetProcessHeap(), 0, name );
1298
1299     return r;
1300 }
1301
1302 /******************************************************************************
1303  * GetFileSecurityW [ADVAPI32.@]
1304  *
1305  * See GetFileSecurityA.
1306  */
1307 BOOL WINAPI
1308 GetFileSecurityW( LPCWSTR lpFileName,
1309                     SECURITY_INFORMATION RequestedInformation,
1310                     PSECURITY_DESCRIPTOR pSecurityDescriptor,
1311                     DWORD nLength, LPDWORD lpnLengthNeeded )
1312 {
1313     DWORD               nNeeded;
1314     LPBYTE      pBuffer;
1315     DWORD               iLocNow;
1316     SECURITY_DESCRIPTOR_RELATIVE *pSDRelative;
1317
1318     if(INVALID_FILE_ATTRIBUTES == GetFileAttributesW(lpFileName))
1319         return FALSE;
1320
1321     FIXME("(%s) : returns fake SECURITY_DESCRIPTOR\n", debugstr_w(lpFileName) );
1322
1323     nNeeded = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
1324     if (RequestedInformation & OWNER_SECURITY_INFORMATION)
1325         nNeeded += sizeof(sidWorld);
1326     if (RequestedInformation & GROUP_SECURITY_INFORMATION)
1327         nNeeded += sizeof(sidWorld);
1328     if (RequestedInformation & DACL_SECURITY_INFORMATION)
1329         nNeeded += WINE_SIZE_OF_WORLD_ACCESS_ACL;
1330     if (RequestedInformation & SACL_SECURITY_INFORMATION)
1331         nNeeded += WINE_SIZE_OF_WORLD_ACCESS_ACL;
1332
1333     *lpnLengthNeeded = nNeeded;
1334
1335     if (nNeeded > nLength)
1336             return TRUE;
1337
1338     if (!InitializeSecurityDescriptor(pSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION))
1339         return FALSE;
1340
1341     pSDRelative = (PISECURITY_DESCRIPTOR_RELATIVE) pSecurityDescriptor;
1342     pSDRelative->Control |= SE_SELF_RELATIVE;
1343     pBuffer = (LPBYTE) pSDRelative;
1344     iLocNow = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
1345
1346     if (RequestedInformation & OWNER_SECURITY_INFORMATION)
1347     {
1348         memcpy(pBuffer + iLocNow, &sidWorld, sizeof(sidWorld));
1349         pSDRelative->Owner = iLocNow;
1350         iLocNow += sizeof(sidWorld);
1351     }
1352     if (RequestedInformation & GROUP_SECURITY_INFORMATION)
1353     {
1354         memcpy(pBuffer + iLocNow, &sidWorld, sizeof(sidWorld));
1355         pSDRelative->Group = iLocNow;
1356         iLocNow += sizeof(sidWorld);
1357     }
1358     if (RequestedInformation & DACL_SECURITY_INFORMATION)
1359     {
1360         GetWorldAccessACL((PACL) (pBuffer + iLocNow));
1361         pSDRelative->Dacl = iLocNow;
1362         iLocNow += WINE_SIZE_OF_WORLD_ACCESS_ACL;
1363     }
1364     if (RequestedInformation & SACL_SECURITY_INFORMATION)
1365     {
1366         GetWorldAccessACL((PACL) (pBuffer + iLocNow));
1367         pSDRelative->Sacl = iLocNow;
1368         /* iLocNow += WINE_SIZE_OF_WORLD_ACCESS_ACL; */
1369     }
1370     return TRUE;
1371 }
1372
1373
1374 /******************************************************************************
1375  * LookupAccountSidA [ADVAPI32.@]
1376  */
1377 BOOL WINAPI
1378 LookupAccountSidA(
1379         IN LPCSTR system,
1380         IN PSID sid,
1381         OUT LPSTR account,
1382         IN OUT LPDWORD accountSize,
1383         OUT LPSTR domain,
1384         IN OUT LPDWORD domainSize,
1385         OUT PSID_NAME_USE name_use )
1386 {
1387         static const char ac[] = "Administrator";
1388         static const char dm[] = "DOMAIN";
1389         FIXME("(%s,sid=%p,%p,%p(%lu),%p,%p(%lu),%p): semi-stub\n",
1390               debugstr_a(system),sid,
1391               account,accountSize,accountSize?*accountSize:0,
1392               domain,domainSize,domainSize?*domainSize:0,
1393               name_use);
1394
1395         if (accountSize) *accountSize = strlen(ac)+1;
1396         if (account && (*accountSize > strlen(ac)))
1397           strcpy(account, ac);
1398
1399         if (domainSize) *domainSize = strlen(dm)+1;
1400         if (domain && (*domainSize > strlen(dm)))
1401           strcpy(domain,dm);
1402
1403         if (name_use) *name_use = SidTypeUser;
1404         return TRUE;
1405 }
1406
1407 /******************************************************************************
1408  * LookupAccountSidW [ADVAPI32.@]
1409  *
1410  * PARAMS
1411  *   system      []
1412  *   sid         []
1413  *   account     []
1414  *   accountSize []
1415  *   domain      []
1416  *   domainSize  []
1417  *   name_use    []
1418  */
1419 BOOL WINAPI
1420 LookupAccountSidW(
1421         IN LPCWSTR system,
1422         IN PSID sid,
1423         OUT LPWSTR account,
1424         IN OUT LPDWORD accountSize,
1425         OUT LPWSTR domain,
1426         IN OUT LPDWORD domainSize,
1427         OUT PSID_NAME_USE name_use )
1428 {
1429     static const WCHAR ac[] = {'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
1430     static const WCHAR dm[] = {'D','O','M','A','I','N',0};
1431         FIXME("(%s,sid=%p,%p,%p(%lu),%p,%p(%lu),%p): semi-stub\n",
1432               debugstr_w(system),sid,
1433               account,accountSize,accountSize?*accountSize:0,
1434               domain,domainSize,domainSize?*domainSize:0,
1435               name_use);
1436
1437         if (accountSize) *accountSize = strlenW(ac)+1;
1438         if (account && (*accountSize > strlenW(ac)))
1439             strcpyW(account, ac);
1440
1441         if (domainSize) *domainSize = strlenW(dm)+1;
1442         if (domain && (*domainSize > strlenW(dm)))
1443             strcpyW(domain,dm);
1444
1445         if (name_use) *name_use = SidTypeUser;
1446         return TRUE;
1447 }
1448
1449 /******************************************************************************
1450  * SetFileSecurityA [ADVAPI32.@]
1451  * Sets the security of a file or directory
1452  */
1453 BOOL WINAPI SetFileSecurityA( LPCSTR lpFileName,
1454                                 SECURITY_INFORMATION RequestedInformation,
1455                                 PSECURITY_DESCRIPTOR pSecurityDescriptor)
1456 {
1457     DWORD len;
1458     BOOL r;
1459     LPWSTR name = NULL;
1460
1461     if( lpFileName )
1462     {
1463         len = MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, NULL, 0 );
1464         name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
1465         MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, name, len );
1466     }
1467
1468     r = SetFileSecurityW( name, RequestedInformation, pSecurityDescriptor );
1469     HeapFree( GetProcessHeap(), 0, name );
1470
1471     return r;
1472 }
1473
1474 /******************************************************************************
1475  * SetFileSecurityW [ADVAPI32.@]
1476  * Sets the security of a file or directory
1477  *
1478  * PARAMS
1479  *   lpFileName           []
1480  *   RequestedInformation []
1481  *   pSecurityDescriptor  []
1482  */
1483 BOOL WINAPI
1484 SetFileSecurityW( LPCWSTR lpFileName,
1485                     SECURITY_INFORMATION RequestedInformation,
1486                     PSECURITY_DESCRIPTOR pSecurityDescriptor )
1487 {
1488   FIXME("(%s) : stub\n", debugstr_w(lpFileName) );
1489   return TRUE;
1490 }
1491
1492 /******************************************************************************
1493  * QueryWindows31FilesMigration [ADVAPI32.@]
1494  *
1495  * PARAMS
1496  *   x1 []
1497  */
1498 BOOL WINAPI
1499 QueryWindows31FilesMigration( DWORD x1 )
1500 {
1501         FIXME("(%ld):stub\n",x1);
1502         return TRUE;
1503 }
1504
1505 /******************************************************************************
1506  * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.@]
1507  *
1508  * PARAMS
1509  *   x1 []
1510  *   x2 []
1511  *   x3 []
1512  *   x4 []
1513  */
1514 BOOL WINAPI
1515 SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1, DWORD x2, DWORD x3,
1516                                                DWORD x4 )
1517 {
1518         FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx):stub\n",x1,x2,x3,x4);
1519         return TRUE;
1520 }
1521
1522 NTSTATUS WINAPI
1523 LsaEnumerateTrustedDomains(
1524     LSA_HANDLE PolicyHandle,
1525     PLSA_ENUMERATION_HANDLE EnumerationContext,
1526     PVOID* Buffer,
1527     ULONG PreferedMaximumLength,
1528     PULONG CountReturned)
1529 {
1530     FIXME("(%p,%p,%p,0x%08lx,%p):stub\n", PolicyHandle, EnumerationContext,
1531           Buffer, PreferedMaximumLength, CountReturned);
1532
1533     if (CountReturned) *CountReturned = 0;
1534     return STATUS_SUCCESS;
1535 }
1536
1537 NTSTATUS WINAPI
1538 LsaLookupNames(
1539   LSA_HANDLE PolicyHandle,
1540   ULONG Count,
1541   PLSA_UNICODE_STRING Names,
1542   PLSA_REFERENCED_DOMAIN_LIST* ReferencedDomains,
1543   PLSA_TRANSLATED_SID* Sids)
1544 {
1545     FIXME("(%p,0x%08lx,%p,%p,%p):stub\n", PolicyHandle, Count, Names,
1546           ReferencedDomains, Sids);
1547
1548     return STATUS_NONE_MAPPED;
1549 }
1550
1551 /******************************************************************************
1552  * LsaOpenPolicy [ADVAPI32.@]
1553  *
1554  * PARAMS
1555  *   SystemName       [I]
1556  *   ObjectAttributes [I]
1557  *   DesiredAccess    [I]
1558  *   PolicyHandle     [I/O]
1559  */
1560 NTSTATUS WINAPI
1561 LsaOpenPolicy(
1562         IN PLSA_UNICODE_STRING SystemName,
1563         IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes,
1564         IN ACCESS_MASK DesiredAccess,
1565         IN OUT PLSA_HANDLE PolicyHandle)
1566 {
1567         FIXME("(%s,%p,0x%08lx,%p):stub\n",
1568               SystemName?debugstr_w(SystemName->Buffer):"null",
1569               ObjectAttributes, DesiredAccess, PolicyHandle);
1570         ADVAPI_ForceLocalComputer(SystemName ? SystemName->Buffer : NULL,
1571                                   STATUS_ACCESS_VIOLATION);
1572         dumpLsaAttributes(ObjectAttributes);
1573         if(PolicyHandle) *PolicyHandle = (LSA_HANDLE)0xcafe;
1574         return STATUS_SUCCESS;
1575 }
1576
1577 /******************************************************************************
1578  * LsaQueryInformationPolicy [ADVAPI32.@]
1579  */
1580 NTSTATUS WINAPI
1581 LsaQueryInformationPolicy(
1582         IN LSA_HANDLE PolicyHandle,
1583         IN POLICY_INFORMATION_CLASS InformationClass,
1584         OUT PVOID *Buffer)
1585 {
1586         FIXME("(%p,0x%08x,%p):stub\n",
1587               PolicyHandle, InformationClass, Buffer);
1588
1589         if(!Buffer) return FALSE;
1590         switch (InformationClass)
1591         {
1592           case PolicyAuditEventsInformation: /* 2 */
1593             {
1594               PPOLICY_AUDIT_EVENTS_INFO p = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(POLICY_AUDIT_EVENTS_INFO));
1595               p->AuditingMode = FALSE; /* no auditing */
1596               *Buffer = p;
1597             }
1598             break;
1599           case PolicyPrimaryDomainInformation: /* 3 */
1600           case PolicyAccountDomainInformation: /* 5 */
1601             {
1602               struct di
1603               { POLICY_PRIMARY_DOMAIN_INFO ppdi;
1604                 SID sid;
1605               };
1606               SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
1607
1608               struct di * xdi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(xdi));
1609               HKEY key;
1610               BOOL useDefault = TRUE;
1611               LONG ret;
1612
1613               if ((ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1614                "System\\CurrentControlSet\\Services\\VxD\\VNETSUP", 0,
1615                KEY_READ, &key)) == ERROR_SUCCESS)
1616               {
1617                   DWORD size = 0;
1618                   static const WCHAR wg[] = { 'W','o','r','k','g','r','o','u','p',0 };
1619
1620                   ret = RegQueryValueExW(key, wg, NULL, NULL, NULL, &size);
1621                   if (ret == ERROR_MORE_DATA || ret == ERROR_SUCCESS)
1622                   {
1623                       xdi->ppdi.Name.Buffer = HeapAlloc(GetProcessHeap(),
1624                        HEAP_ZERO_MEMORY, size);
1625                       if ((ret = RegQueryValueExW(key, wg, NULL, NULL,
1626                        (LPBYTE)xdi->ppdi.Name.Buffer, &size)) == ERROR_SUCCESS)
1627                       {
1628                           xdi->ppdi.Name.Length = (USHORT)size;
1629                           useDefault = FALSE;
1630                       }
1631                       else
1632                       {
1633                           HeapFree(GetProcessHeap(), 0, xdi->ppdi.Name.Buffer);
1634                           xdi->ppdi.Name.Buffer = NULL;
1635                       }
1636                   }
1637                   RegCloseKey(key);
1638               }
1639               if (useDefault)
1640                   RtlCreateUnicodeStringFromAsciiz(&(xdi->ppdi.Name), "DOMAIN");
1641               TRACE("setting domain to %s\n", debugstr_w(xdi->ppdi.Name.Buffer));
1642
1643               xdi->ppdi.Sid = &(xdi->sid);
1644               xdi->sid.Revision = SID_REVISION;
1645               xdi->sid.SubAuthorityCount = 1;
1646               xdi->sid.IdentifierAuthority = localSidAuthority;
1647               xdi->sid.SubAuthority[0] = SECURITY_LOCAL_SYSTEM_RID;
1648               *Buffer = xdi;
1649             }
1650             break;
1651           case  PolicyAuditLogInformation:
1652           case  PolicyPdAccountInformation:
1653           case  PolicyLsaServerRoleInformation:
1654           case  PolicyReplicaSourceInformation:
1655           case  PolicyDefaultQuotaInformation:
1656           case  PolicyModificationInformation:
1657           case  PolicyAuditFullSetInformation:
1658           case  PolicyAuditFullQueryInformation:
1659           case  PolicyDnsDomainInformation:
1660             {
1661               FIXME("category not implemented\n");
1662               return FALSE;
1663             }
1664         }
1665         return TRUE;
1666 }
1667
1668 /******************************************************************************
1669  * LsaSetInformationPolicy [ADVAPI32.@]
1670  */
1671 NTSTATUS WINAPI
1672 LsaSetInformationPolicy(
1673     LSA_HANDLE PolicyHandle,
1674     POLICY_INFORMATION_CLASS InformationClass,
1675     PVOID Buffer)
1676 {
1677     FIXME("(%p,0x%08x,%p):stub\n", PolicyHandle, InformationClass, Buffer);
1678
1679     return STATUS_UNSUCCESSFUL;    
1680 }
1681
1682 /******************************************************************************
1683  * LsaLookupSids [ADVAPI32.@]
1684  */
1685 NTSTATUS WINAPI
1686 LsaLookupSids(
1687         IN LSA_HANDLE PolicyHandle,
1688         IN ULONG Count,
1689         IN PSID *Sids,
1690         OUT PLSA_REFERENCED_DOMAIN_LIST *ReferencedDomains,
1691         OUT PLSA_TRANSLATED_NAME *Names )
1692 {
1693         FIXME("%p %lu %p %p %p\n",
1694           PolicyHandle, Count, Sids, ReferencedDomains, Names);
1695         return FALSE;
1696 }
1697
1698 /******************************************************************************
1699  * LsaFreeMemory [ADVAPI32.@]
1700  */
1701 NTSTATUS WINAPI
1702 LsaFreeMemory(IN PVOID Buffer)
1703 {
1704         TRACE("(%p)\n",Buffer);
1705         return HeapFree(GetProcessHeap(), 0, Buffer);
1706 }
1707 /******************************************************************************
1708  * LsaClose [ADVAPI32.@]
1709  */
1710 NTSTATUS WINAPI
1711 LsaClose(IN LSA_HANDLE ObjectHandle)
1712 {
1713         FIXME("(%p):stub\n",ObjectHandle);
1714         return 0xc0000000;
1715 }
1716
1717 /******************************************************************************
1718  * LsaStorePrivateData [ADVAPI32.@]
1719  */
1720 NTSTATUS WINAPI LsaStorePrivateData( LSA_HANDLE PolicyHandle,
1721     PLSA_UNICODE_STRING KeyName, PLSA_UNICODE_STRING PrivateData)
1722 {
1723     FIXME("%p %p %p\n", PolicyHandle, KeyName, PrivateData);
1724     return STATUS_OBJECT_NAME_NOT_FOUND;
1725 }
1726
1727 /******************************************************************************
1728  * LsaRetrievePrivateData [ADVAPI32.@]
1729  */
1730 NTSTATUS WINAPI LsaRetrievePrivateData( LSA_HANDLE PolicyHandle,
1731     PLSA_UNICODE_STRING KeyName, PLSA_UNICODE_STRING* PrivateData)
1732 {
1733     FIXME("%p %p %p\n", PolicyHandle, KeyName, PrivateData);
1734     return STATUS_OBJECT_NAME_NOT_FOUND;
1735 }
1736
1737 /******************************************************************************
1738  * LsaNtStatusToWinError [ADVAPI32.@]
1739  *
1740  * PARAMS
1741  *   Status [I]
1742  */
1743 ULONG WINAPI
1744 LsaNtStatusToWinError(NTSTATUS Status)
1745 {
1746     return RtlNtStatusToDosError(Status);
1747 }
1748
1749 /******************************************************************************
1750  * NotifyBootConfigStatus [ADVAPI32.@]
1751  *
1752  * PARAMS
1753  *   x1 []
1754  */
1755 BOOL WINAPI
1756 NotifyBootConfigStatus( DWORD x1 )
1757 {
1758         FIXME("(0x%08lx):stub\n",x1);
1759         return 1;
1760 }
1761
1762 /******************************************************************************
1763  * RevertToSelf [ADVAPI32.@]
1764  *
1765  * PARAMS
1766  *   void []
1767  */
1768 BOOL WINAPI
1769 RevertToSelf( void )
1770 {
1771         FIXME("(), stub\n");
1772         return TRUE;
1773 }
1774
1775 /******************************************************************************
1776  * ImpersonateSelf [ADVAPI32.@]
1777  */
1778 BOOL WINAPI
1779 ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
1780 {
1781         return RtlImpersonateSelf(ImpersonationLevel);
1782 }
1783
1784 /******************************************************************************
1785  * ImpersonateLoggedOnUser [ADVAPI32.@]
1786  */
1787 BOOL WINAPI ImpersonateLoggedOnUser(HANDLE hToken)
1788 {
1789     FIXME("(%p):stub returning FALSE\n", hToken);
1790     return FALSE;
1791 }
1792
1793 /******************************************************************************
1794  * AccessCheck [ADVAPI32.@]
1795  */
1796 BOOL WINAPI
1797 AccessCheck(
1798         PSECURITY_DESCRIPTOR SecurityDescriptor,
1799         HANDLE ClientToken,
1800         DWORD DesiredAccess,
1801         PGENERIC_MAPPING GenericMapping,
1802         PPRIVILEGE_SET PrivilegeSet,
1803         LPDWORD PrivilegeSetLength,
1804         LPDWORD GrantedAccess,
1805         LPBOOL AccessStatus)
1806 {
1807     NTSTATUS access_status;
1808     BOOL ret = set_ntstatus( NtAccessCheck(SecurityDescriptor, ClientToken, DesiredAccess,
1809                                            GenericMapping, PrivilegeSet, PrivilegeSetLength,
1810                                            GrantedAccess, &access_status) );
1811     if (ret) *AccessStatus = set_ntstatus( access_status );
1812     return ret;
1813 }
1814
1815
1816 /******************************************************************************
1817  * AccessCheckByType [ADVAPI32.@]
1818  */
1819 BOOL WINAPI AccessCheckByType(
1820     PSECURITY_DESCRIPTOR pSecurityDescriptor, 
1821     PSID PrincipalSelfSid,
1822     HANDLE ClientToken, 
1823     DWORD DesiredAccess, 
1824     POBJECT_TYPE_LIST ObjectTypeList,
1825     DWORD ObjectTypeListLength,
1826     PGENERIC_MAPPING GenericMapping,
1827     PPRIVILEGE_SET PrivilegeSet,
1828     LPDWORD PrivilegeSetLength, 
1829     LPDWORD GrantedAccess,
1830     LPBOOL AccessStatus)
1831 {
1832         FIXME("stub\n");
1833
1834         *AccessStatus = TRUE;
1835
1836         return !*AccessStatus;
1837 }
1838
1839 VOID WINAPI MapGenericMask( PDWORD AccessMask, PGENERIC_MAPPING GenericMapping )
1840 {
1841         FIXME("%p %p - stub\n", AccessMask, GenericMapping);
1842
1843     *AccessMask |= GenericMapping->GenericRead;
1844     *AccessMask |= GenericMapping->GenericWrite;
1845     *AccessMask |= GenericMapping->GenericExecute;
1846     *AccessMask |= GenericMapping->GenericAll;
1847 }
1848
1849 /*************************************************************************
1850  * SetKernelObjectSecurity [ADVAPI32.@]
1851  */
1852 BOOL WINAPI SetKernelObjectSecurity (
1853         IN HANDLE Handle,
1854         IN SECURITY_INFORMATION SecurityInformation,
1855         IN PSECURITY_DESCRIPTOR SecurityDescriptor )
1856 {
1857     return set_ntstatus (NtSetSecurityObject (Handle, SecurityInformation, SecurityDescriptor));
1858 }
1859
1860
1861 /******************************************************************************
1862  *  AddAuditAccessAce [ADVAPI32.@]
1863  */
1864 BOOL WINAPI AddAuditAccessAce(
1865         IN OUT PACL pAcl,
1866         IN DWORD dwAceRevision,
1867         IN DWORD dwAccessMask,
1868         IN PSID pSid,
1869         IN BOOL bAuditSuccess,
1870         IN BOOL bAuditFailure)
1871 {
1872         FIXME("Stub\n");
1873         return TRUE;
1874 }
1875
1876 /******************************************************************************
1877  * LookupAccountNameA [ADVAPI32.@]
1878  */
1879 BOOL WINAPI
1880 LookupAccountNameA(
1881         IN LPCSTR system,
1882         IN LPCSTR account,
1883         OUT PSID sid,
1884         OUT LPDWORD cbSid,
1885         LPSTR ReferencedDomainName,
1886         IN OUT LPDWORD cbReferencedDomainName,
1887         OUT PSID_NAME_USE name_use )
1888 {
1889     /* Default implementation: Always return a default SID */
1890     SID_IDENTIFIER_AUTHORITY identifierAuthority = {SECURITY_NT_AUTHORITY};
1891     BOOL ret;
1892     PSID pSid;
1893     static const char dm[] = "DOMAIN";
1894
1895     FIXME("(%s,%s,%p,%p,%p,%p,%p), stub.\n",system,account,sid,cbSid,ReferencedDomainName,cbReferencedDomainName,name_use);
1896
1897     ret = AllocateAndInitializeSid(&identifierAuthority,
1898         2,
1899         SECURITY_BUILTIN_DOMAIN_RID,
1900         DOMAIN_ALIAS_RID_ADMINS,
1901         0, 0, 0, 0, 0, 0,
1902         &pSid);
1903
1904     if (!ret)
1905        return FALSE;
1906     if(!RtlValidSid(pSid))
1907     {
1908        FreeSid(pSid);
1909        return FALSE;
1910     }
1911
1912     if (sid != NULL && (*cbSid >= GetLengthSid(pSid)))
1913        CopySid(*cbSid, sid, pSid);
1914     if (*cbSid < GetLengthSid(pSid))
1915     {
1916        SetLastError(ERROR_INSUFFICIENT_BUFFER);
1917        ret = FALSE;
1918     }
1919     *cbSid = GetLengthSid(pSid);
1920     
1921     if (ReferencedDomainName != NULL && (*cbReferencedDomainName > strlen(dm)))
1922       strcpy(ReferencedDomainName, dm);
1923     if (*cbReferencedDomainName <= strlen(dm))
1924     {
1925        SetLastError(ERROR_INSUFFICIENT_BUFFER);
1926        ret = FALSE;
1927     }
1928     *cbReferencedDomainName = strlen(dm)+1;
1929
1930     FreeSid(pSid);
1931
1932     return ret;
1933 }
1934
1935 /******************************************************************************
1936  * LookupAccountNameW [ADVAPI32.@]
1937  */
1938 BOOL WINAPI LookupAccountNameW( LPCWSTR lpSystemName, LPCWSTR lpAccountName, PSID Sid,
1939                                 LPDWORD cbSid, LPWSTR ReferencedDomainName,
1940                                 LPDWORD cchReferencedDomainName, PSID_NAME_USE peUse )
1941 {
1942     FIXME("%s %s %p %p %p %p %p - stub\n", debugstr_w(lpSystemName), debugstr_w(lpAccountName),
1943           Sid, cbSid, ReferencedDomainName, cchReferencedDomainName, peUse);
1944
1945     return FALSE;
1946 }
1947
1948 /******************************************************************************
1949  * PrivilegeCheck [ADVAPI32.@]
1950  */
1951 BOOL WINAPI PrivilegeCheck( HANDLE ClientToken, PPRIVILEGE_SET RequiredPrivileges, LPBOOL pfResult)
1952 {
1953     BOOL ret;
1954     BOOLEAN Result;
1955
1956     TRACE("%p %p %p\n", ClientToken, RequiredPrivileges, pfResult);
1957
1958     ret = set_ntstatus (NtPrivilegeCheck (ClientToken, RequiredPrivileges, &Result));
1959     if (ret)
1960         *pfResult = Result;
1961     return ret;
1962 }
1963
1964 /******************************************************************************
1965  * AccessCheckAndAuditAlarmA [ADVAPI32.@]
1966  */
1967 BOOL WINAPI AccessCheckAndAuditAlarmA(LPCSTR Subsystem, LPVOID HandleId, LPSTR ObjectTypeName,
1968   LPSTR ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD DesiredAccess,
1969   PGENERIC_MAPPING GenericMapping, BOOL ObjectCreation, LPDWORD GrantedAccess,
1970   LPBOOL AccessStatus, LPBOOL pfGenerateOnClose)
1971 {
1972         FIXME("stub (%s,%p,%s,%s,%p,%08lx,%p,%x,%p,%p,%p)\n", debugstr_a(Subsystem),
1973                 HandleId, debugstr_a(ObjectTypeName), debugstr_a(ObjectName),
1974                 SecurityDescriptor, DesiredAccess, GenericMapping,
1975                 ObjectCreation, GrantedAccess, AccessStatus, pfGenerateOnClose);
1976         return TRUE;
1977 }
1978
1979 /******************************************************************************
1980  * AccessCheckAndAuditAlarmW [ADVAPI32.@]
1981  */
1982 BOOL WINAPI AccessCheckAndAuditAlarmW(LPCWSTR Subsystem, LPVOID HandleId, LPWSTR ObjectTypeName,
1983   LPWSTR ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD DesiredAccess,
1984   PGENERIC_MAPPING GenericMapping, BOOL ObjectCreation, LPDWORD GrantedAccess,
1985   LPBOOL AccessStatus, LPBOOL pfGenerateOnClose)
1986 {
1987         FIXME("stub (%s,%p,%s,%s,%p,%08lx,%p,%x,%p,%p,%p)\n", debugstr_w(Subsystem),
1988                 HandleId, debugstr_w(ObjectTypeName), debugstr_w(ObjectName),
1989                 SecurityDescriptor, DesiredAccess, GenericMapping,
1990                 ObjectCreation, GrantedAccess, AccessStatus, pfGenerateOnClose);
1991         return TRUE;
1992 }
1993
1994 BOOL WINAPI ObjectCloseAuditAlarmA(LPCSTR SubsystemName, LPVOID HandleId, BOOL GenerateOnClose)
1995 {
1996     FIXME("stub (%s,%p,%x)\n", debugstr_a(SubsystemName), HandleId, GenerateOnClose);
1997
1998     return TRUE;
1999 }
2000
2001 BOOL WINAPI ObjectCloseAuditAlarmW(LPCWSTR SubsystemName, LPVOID HandleId, BOOL GenerateOnClose)
2002 {
2003     FIXME("stub (%s,%p,%x)\n", debugstr_w(SubsystemName), HandleId, GenerateOnClose);
2004
2005     return TRUE;
2006 }
2007
2008 BOOL WINAPI ObjectOpenAuditAlarmA(LPCSTR SubsystemName, LPVOID HandleId, LPSTR ObjectTypeName,
2009   LPSTR ObjectName, PSECURITY_DESCRIPTOR pSecurityDescriptor, HANDLE ClientToken, DWORD DesiredAccess,
2010   DWORD GrantedAccess, PPRIVILEGE_SET Privileges, BOOL ObjectCreation, BOOL AccessGranted,
2011   LPBOOL GenerateOnClose)
2012 {
2013         FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08lx,0x%08lx,%p,%x,%x,%p)\n", debugstr_a(SubsystemName),
2014                 HandleId, debugstr_a(ObjectTypeName), debugstr_a(ObjectName), pSecurityDescriptor,
2015         ClientToken, DesiredAccess, GrantedAccess, Privileges, ObjectCreation, AccessGranted,
2016         GenerateOnClose);
2017
2018     return TRUE;
2019 }
2020
2021 BOOL WINAPI ObjectOpenAuditAlarmW(LPCWSTR SubsystemName, LPVOID HandleId, LPWSTR ObjectTypeName,
2022   LPWSTR ObjectName, PSECURITY_DESCRIPTOR pSecurityDescriptor, HANDLE ClientToken, DWORD DesiredAccess,
2023   DWORD GrantedAccess, PPRIVILEGE_SET Privileges, BOOL ObjectCreation, BOOL AccessGranted,
2024   LPBOOL GenerateOnClose)
2025 {
2026     FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08lx,0x%08lx,%p,%x,%x,%p)\n", debugstr_w(SubsystemName),
2027         HandleId, debugstr_w(ObjectTypeName), debugstr_w(ObjectName), pSecurityDescriptor,
2028         ClientToken, DesiredAccess, GrantedAccess, Privileges, ObjectCreation, AccessGranted,
2029         GenerateOnClose);
2030
2031     return TRUE;
2032 }
2033
2034 BOOL WINAPI ObjectPrivilegeAuditAlarmA( LPCSTR SubsystemName, LPVOID HandleId, HANDLE ClientToken,
2035   DWORD DesiredAccess, PPRIVILEGE_SET Privileges, BOOL AccessGranted)
2036 {
2037     FIXME("stub (%s,%p,%p,0x%08lx,%p,%x)\n", debugstr_a(SubsystemName), HandleId, ClientToken,
2038           DesiredAccess, Privileges, AccessGranted);
2039
2040     return TRUE;
2041 }
2042
2043 BOOL WINAPI ObjectPrivilegeAuditAlarmW( LPCWSTR SubsystemName, LPVOID HandleId, HANDLE ClientToken,
2044   DWORD DesiredAccess, PPRIVILEGE_SET Privileges, BOOL AccessGranted)
2045 {
2046     FIXME("stub (%s,%p,%p,0x%08lx,%p,%x)\n", debugstr_w(SubsystemName), HandleId, ClientToken,
2047           DesiredAccess, Privileges, AccessGranted);
2048
2049     return TRUE;
2050 }
2051
2052 BOOL WINAPI PrivilegedServiceAuditAlarmA( LPCSTR SubsystemName, LPCSTR ServiceName, HANDLE ClientToken,
2053                                    PPRIVILEGE_SET Privileges, BOOL AccessGranted)
2054 {
2055     FIXME("stub (%s,%s,%p,%p,%x)\n", debugstr_a(SubsystemName), debugstr_a(ServiceName),
2056           ClientToken, Privileges, AccessGranted);
2057
2058     return TRUE;
2059 }
2060
2061 BOOL WINAPI PrivilegedServiceAuditAlarmW( LPCWSTR SubsystemName, LPCWSTR ServiceName, HANDLE ClientToken,
2062                                    PPRIVILEGE_SET Privileges, BOOL AccessGranted)
2063 {
2064     FIXME("stub %s,%s,%p,%p,%x)\n", debugstr_w(SubsystemName), debugstr_w(ServiceName),
2065           ClientToken, Privileges, AccessGranted);
2066
2067     return TRUE;
2068 }
2069
2070 /******************************************************************************
2071  * GetSecurityInfo [ADVAPI32.@]
2072  */
2073 DWORD WINAPI GetSecurityInfo(
2074     HANDLE hObject, SE_OBJECT_TYPE ObjectType,
2075     SECURITY_INFORMATION SecurityInfo, PSID *ppsidOwner,
2076     PSID *ppsidGroup, PACL *ppDacl, PACL *ppSacl,
2077     PSECURITY_DESCRIPTOR *ppSecurityDescriptor
2078 )
2079 {
2080   FIXME("stub!\n");
2081   return ERROR_BAD_PROVIDER;
2082 }
2083
2084 /******************************************************************************
2085  * GetSecurityInfoExW [ADVAPI32.@]
2086  */
2087 DWORD WINAPI GetSecurityInfoExW(
2088         HANDLE hObject, SE_OBJECT_TYPE ObjectType, 
2089         SECURITY_INFORMATION SecurityInfo, LPCWSTR lpProvider,
2090         LPCWSTR lpProperty, PACTRL_ACCESSW *ppAccessList, 
2091         PACTRL_AUDITW *ppAuditList, LPWSTR *lppOwner, LPWSTR *lppGroup
2092 )
2093 {
2094   FIXME("stub!\n");
2095   return ERROR_BAD_PROVIDER; 
2096 }
2097
2098 /******************************************************************************
2099  * BuildExplicitAccessWithNameA [ADVAPI32.@]
2100  */
2101 VOID WINAPI BuildExplicitAccessWithNameA( PEXPLICIT_ACCESSA pExplicitAccess,
2102                                           LPSTR pTrusteeName, DWORD AccessPermissions,
2103                                           ACCESS_MODE AccessMode, DWORD Inheritance )
2104 {
2105     TRACE("%p %s 0x%08lx 0x%08x 0x%08lx\n", pExplicitAccess, debugstr_a(pTrusteeName),
2106           AccessPermissions, AccessMode, Inheritance);
2107
2108     pExplicitAccess->grfAccessPermissions = AccessPermissions;
2109     pExplicitAccess->grfAccessMode = AccessMode;
2110     pExplicitAccess->grfInheritance = Inheritance;
2111
2112     pExplicitAccess->Trustee.pMultipleTrustee = NULL;
2113     pExplicitAccess->Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2114     pExplicitAccess->Trustee.TrusteeForm = TRUSTEE_IS_NAME;
2115     pExplicitAccess->Trustee.TrusteeType = TRUSTEE_IS_UNKNOWN;
2116     pExplicitAccess->Trustee.ptstrName = pTrusteeName;
2117 }
2118
2119 /******************************************************************************
2120  * BuildExplicitAccessWithNameW [ADVAPI32.@]
2121  */
2122 VOID WINAPI BuildExplicitAccessWithNameW( PEXPLICIT_ACCESSW pExplicitAccess,
2123                                           LPWSTR pTrusteeName, DWORD AccessPermissions,
2124                                           ACCESS_MODE AccessMode, DWORD Inheritance )
2125 {
2126     TRACE("%p %s 0x%08lx 0x%08x 0x%08lx\n", pExplicitAccess, debugstr_w(pTrusteeName),
2127           AccessPermissions, AccessMode, Inheritance);
2128
2129     pExplicitAccess->grfAccessPermissions = AccessPermissions;
2130     pExplicitAccess->grfAccessMode = AccessMode;
2131     pExplicitAccess->grfInheritance = Inheritance;
2132
2133     pExplicitAccess->Trustee.pMultipleTrustee = NULL;
2134     pExplicitAccess->Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2135     pExplicitAccess->Trustee.TrusteeForm = TRUSTEE_IS_NAME;
2136     pExplicitAccess->Trustee.TrusteeType = TRUSTEE_IS_UNKNOWN;
2137     pExplicitAccess->Trustee.ptstrName = pTrusteeName;
2138 }
2139
2140 /******************************************************************************
2141  * BuildTrusteeWithObjectsAndNameA [ADVAPI32.@]
2142  */
2143 VOID WINAPI BuildTrusteeWithObjectsAndNameA( PTRUSTEEA pTrustee, POBJECTS_AND_NAME_A pObjName,
2144                                              SE_OBJECT_TYPE ObjectType, LPSTR ObjectTypeName,
2145                                              LPSTR InheritedObjectTypeName, LPSTR Name )
2146 {
2147     TRACE("%p %p 0x%08x %p %p %s\n", pTrustee, pObjName,
2148           ObjectType, ObjectTypeName, InheritedObjectTypeName, debugstr_a(Name));
2149
2150     pTrustee->pMultipleTrustee = NULL;
2151     pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2152     pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_NAME;
2153     pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2154     pTrustee->ptstrName = Name;
2155 }
2156
2157 /******************************************************************************
2158  * BuildTrusteeWithObjectsAndNameW [ADVAPI32.@]
2159  */
2160 VOID WINAPI BuildTrusteeWithObjectsAndNameW( PTRUSTEEW pTrustee, POBJECTS_AND_NAME_W pObjName,
2161                                              SE_OBJECT_TYPE ObjectType, LPWSTR ObjectTypeName,
2162                                              LPWSTR InheritedObjectTypeName, LPWSTR Name )
2163 {
2164     TRACE("%p %p 0x%08x %p %p %s\n", pTrustee, pObjName,
2165           ObjectType, ObjectTypeName, InheritedObjectTypeName, debugstr_w(Name));
2166
2167     pTrustee->pMultipleTrustee = NULL;
2168     pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2169     pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_NAME;
2170     pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2171     pTrustee->ptstrName = Name;
2172 }
2173
2174 VOID WINAPI BuildTrusteeWithObjectsAndSidA( PTRUSTEEA pTrustee, POBJECTS_AND_SID pObjSid,
2175                                             GUID* pObjectGuid, GUID* pInheritedObjectGuid, PSID pSid )
2176 {
2177     TRACE("%p %p %p %p %p\n", pTrustee, pObjSid, pObjectGuid, pInheritedObjectGuid, pSid);
2178
2179     pTrustee->pMultipleTrustee = NULL;
2180     pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2181     pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_SID;
2182     pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2183     pTrustee->ptstrName = (LPSTR) pSid;
2184 }
2185
2186 VOID WINAPI BuildTrusteeWithObjectsAndSidW( PTRUSTEEW pTrustee, POBJECTS_AND_SID pObjSid,
2187                                             GUID* pObjectGuid, GUID* pInheritedObjectGuid, PSID pSid )
2188 {
2189     TRACE("%p %p %p %p %p\n", pTrustee, pObjSid, pObjectGuid, pInheritedObjectGuid, pSid);
2190
2191     pTrustee->pMultipleTrustee = NULL;
2192     pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2193     pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_SID;
2194     pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2195     pTrustee->ptstrName = (LPWSTR) pSid;
2196 }
2197
2198 /******************************************************************************
2199  * BuildTrusteeWithSidA [ADVAPI32.@]
2200  */
2201 VOID WINAPI BuildTrusteeWithSidA(PTRUSTEEA pTrustee, PSID pSid)
2202 {
2203     TRACE("%p %p\n", pTrustee, pSid);
2204
2205     pTrustee->pMultipleTrustee = NULL;
2206     pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2207     pTrustee->TrusteeForm = TRUSTEE_IS_SID;
2208     pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2209     pTrustee->ptstrName = (LPSTR) pSid;
2210 }
2211
2212 /******************************************************************************
2213  * BuildTrusteeWithSidW [ADVAPI32.@]
2214  */
2215 VOID WINAPI BuildTrusteeWithSidW(PTRUSTEEW pTrustee, PSID pSid)
2216 {
2217     TRACE("%p %p\n", pTrustee, pSid);
2218
2219     pTrustee->pMultipleTrustee = NULL;
2220     pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2221     pTrustee->TrusteeForm = TRUSTEE_IS_SID;
2222     pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2223     pTrustee->ptstrName = (LPWSTR) pSid;
2224 }
2225
2226 /******************************************************************************
2227  * BuildTrusteeWithNameA [ADVAPI32.@]
2228  */
2229 VOID WINAPI BuildTrusteeWithNameA(PTRUSTEEA pTrustee, LPSTR name)
2230 {
2231     TRACE("%p %s\n", pTrustee, debugstr_a(name) );
2232
2233     pTrustee->pMultipleTrustee = NULL;
2234     pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2235     pTrustee->TrusteeForm = TRUSTEE_IS_NAME;
2236     pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2237     pTrustee->ptstrName = name;
2238 }
2239
2240 /******************************************************************************
2241  * BuildTrusteeWithNameW [ADVAPI32.@]
2242  */
2243 VOID WINAPI BuildTrusteeWithNameW(PTRUSTEEW pTrustee, LPWSTR name)
2244 {
2245     TRACE("%p %s\n", pTrustee, debugstr_w(name) );
2246
2247     pTrustee->pMultipleTrustee = NULL;
2248     pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2249     pTrustee->TrusteeForm = TRUSTEE_IS_NAME;
2250     pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2251     pTrustee->ptstrName = name;
2252 }
2253
2254 BOOL WINAPI SetAclInformation( PACL pAcl, LPVOID pAclInformation,
2255                                DWORD nAclInformationLength,
2256                                ACL_INFORMATION_CLASS dwAclInformationClass )
2257 {
2258     FIXME("%p %p 0x%08lx 0x%08x - stub\n", pAcl, pAclInformation,
2259           nAclInformationLength, dwAclInformationClass);
2260
2261     return TRUE;
2262 }
2263
2264 /******************************************************************************
2265  * SetEntriesInAclA [ADVAPI32.@]
2266  */
2267 DWORD WINAPI SetEntriesInAclA( ULONG count, PEXPLICIT_ACCESSA pEntries,
2268                                PACL OldAcl, PACL* NewAcl )
2269 {
2270     FIXME("%ld %p %p %p\n",count,pEntries,OldAcl,NewAcl);
2271     return ERROR_CALL_NOT_IMPLEMENTED;
2272 }
2273
2274 /******************************************************************************
2275  * SetEntriesInAclW [ADVAPI32.@]
2276  */
2277 DWORD WINAPI SetEntriesInAclW( ULONG count, PEXPLICIT_ACCESSW pEntries,
2278                                PACL OldAcl, PACL* NewAcl )
2279 {
2280     FIXME("%ld %p %p %p\n",count,pEntries,OldAcl,NewAcl);
2281     return ERROR_CALL_NOT_IMPLEMENTED;
2282 }
2283
2284 /******************************************************************************
2285  * SetNamedSecurityInfoA [ADVAPI32.@]
2286  */
2287 DWORD WINAPI SetNamedSecurityInfoA(LPSTR pObjectName,
2288         SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
2289         PSID psidOwner, PSID psidGroup, PACL pDacl, PACL pSacl)
2290 {
2291     DWORD len;
2292     LPWSTR wstr = NULL;
2293     DWORD r;
2294
2295     TRACE("%s %d %ld %p %p %p %p\n", debugstr_a(pObjectName), ObjectType,
2296            SecurityInfo, psidOwner, psidGroup, pDacl, pSacl);
2297
2298     if( pObjectName )
2299     {
2300         len = MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, NULL, 0 );
2301         wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR));
2302         MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, wstr, len );
2303     }
2304
2305     r = SetNamedSecurityInfoW( wstr, ObjectType, SecurityInfo, psidOwner,
2306                            psidGroup, pDacl, pSacl );
2307
2308     HeapFree( GetProcessHeap(), 0, wstr );
2309
2310     return r;
2311 }
2312
2313 BOOL WINAPI SetPrivateObjectSecurity( SECURITY_INFORMATION SecurityInformation,
2314     PSECURITY_DESCRIPTOR ModificationDescriptor,
2315     PSECURITY_DESCRIPTOR* ObjectsSecurityDescriptor,
2316     PGENERIC_MAPPING GenericMapping,
2317     HANDLE Token )
2318 {
2319     FIXME("0x%08lx %p %p %p %p - stub\n", SecurityInformation, ModificationDescriptor,
2320           ObjectsSecurityDescriptor, GenericMapping, Token);
2321
2322     return TRUE;
2323 }
2324
2325 BOOL WINAPI SetSecurityDescriptorControl( PSECURITY_DESCRIPTOR pSecurityDescriptor,
2326   SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest,
2327   SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet )
2328 {
2329     FIXME("%p 0x%08x 0x%08x - stub\n", pSecurityDescriptor, ControlBitsOfInterest,
2330           ControlBitsToSet);
2331
2332     return TRUE;
2333 }
2334
2335 BOOL WINAPI AreAllAccessesGranted( DWORD GrantedAccess, DWORD DesiredAccess )
2336 {
2337     return RtlAreAllAccessesGranted( GrantedAccess, DesiredAccess );
2338 }
2339
2340 /******************************************************************************
2341  * AreAnyAccessesGranted [ADVAPI32.@]
2342  *
2343  * Determines whether or not any of a set of specified access permissions have
2344  * been granted or not.
2345  *
2346  * PARAMS
2347  *   GrantedAccess [I] The permissions that have been granted.
2348  *   DesiredAccess [I] The permissions that you want to have.
2349  *
2350  * RETURNS
2351  *   Nonzero if any of the permissions have been granted, zero if none of the
2352  *   permissions have been granted.
2353  */
2354
2355 BOOL WINAPI AreAnyAccessesGranted( DWORD GrantedAccess, DWORD DesiredAccess )
2356 {
2357     return RtlAreAnyAccessesGranted( GrantedAccess, DesiredAccess );
2358 }
2359
2360 /******************************************************************************
2361  * SetNamedSecurityInfoW [ADVAPI32.@]
2362  */
2363 DWORD WINAPI SetNamedSecurityInfoW(LPWSTR pObjectName,
2364         SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
2365         PSID psidOwner, PSID psidGroup, PACL pDacl, PACL pSacl)
2366 {
2367     FIXME("%s %d %ld %p %p %p %p\n", debugstr_w(pObjectName), ObjectType,
2368            SecurityInfo, psidOwner, psidGroup, pDacl, pSacl);
2369     return ERROR_SUCCESS;
2370 }
2371
2372 /******************************************************************************
2373  * GetExplicitEntriesFromAclA [ADVAPI32.@]
2374  */
2375 DWORD WINAPI GetExplicitEntriesFromAclA( PACL pacl, PULONG pcCountOfExplicitEntries,
2376         PEXPLICIT_ACCESSA* pListOfExplicitEntries)
2377 {
2378     FIXME("%p %p %p\n",pacl, pcCountOfExplicitEntries, pListOfExplicitEntries);
2379     return ERROR_CALL_NOT_IMPLEMENTED;
2380 }
2381
2382 /******************************************************************************
2383  * GetExplicitEntriesFromAclW [ADVAPI32.@]
2384  */
2385 DWORD WINAPI GetExplicitEntriesFromAclW( PACL pacl, PULONG pcCountOfExplicitEntries,
2386         PEXPLICIT_ACCESSW* pListOfExplicitEntries)
2387 {
2388     FIXME("%p %p %p\n",pacl, pcCountOfExplicitEntries, pListOfExplicitEntries);
2389     return ERROR_CALL_NOT_IMPLEMENTED;
2390 }
2391
2392
2393 /******************************************************************************
2394  * ParseAclStringFlags
2395  */
2396 static DWORD ParseAclStringFlags(LPCWSTR* StringAcl)
2397 {
2398     DWORD flags = 0;
2399     LPCWSTR szAcl = *StringAcl;
2400
2401     while (*szAcl != '(')
2402     {
2403         if (*szAcl == 'P')
2404         {
2405             flags |= SE_DACL_PROTECTED;
2406         }
2407         else if (*szAcl == 'A')
2408         {
2409             szAcl++;
2410             if (*szAcl == 'R')
2411                 flags |= SE_DACL_AUTO_INHERIT_REQ;
2412             else if (*szAcl == 'I')
2413                 flags |= SE_DACL_AUTO_INHERITED;
2414         }
2415         szAcl++;
2416     }
2417
2418     *StringAcl = szAcl;
2419     return flags;
2420 }
2421
2422 /******************************************************************************
2423  * ParseAceStringType
2424  */
2425 ACEFLAG AceType[] =
2426 {
2427     { SDDL_ACCESS_ALLOWED, ACCESS_ALLOWED_ACE_TYPE },
2428     { SDDL_ALARM,          SYSTEM_ALARM_ACE_TYPE },
2429     { SDDL_AUDIT,          SYSTEM_AUDIT_ACE_TYPE },
2430     { SDDL_ACCESS_DENIED,  ACCESS_DENIED_ACE_TYPE },
2431     /*
2432     { SDDL_OBJECT_ACCESS_ALLOWED, ACCESS_ALLOWED_OBJECT_ACE_TYPE },
2433     { SDDL_OBJECT_ACCESS_DENIED,  ACCESS_DENIED_OBJECT_ACE_TYPE },
2434     { SDDL_OBJECT_ALARM,          SYSTEM_ALARM_OBJECT_ACE_TYPE },
2435     { SDDL_OBJECT_AUDIT,          SYSTEM_AUDIT_OBJECT_ACE_TYPE },
2436     */
2437     { NULL, 0 },
2438 };
2439
2440 static BYTE ParseAceStringType(LPCWSTR* StringAcl)
2441 {
2442     UINT len = 0;
2443     LPCWSTR szAcl = *StringAcl;
2444     LPACEFLAG lpaf = AceType;
2445
2446     while (lpaf->wstr &&
2447         (len = strlenW(lpaf->wstr)) &&
2448         strncmpW(lpaf->wstr, szAcl, len))
2449         lpaf++;
2450
2451     if (!lpaf->wstr)
2452         return 0;
2453
2454     *StringAcl += len;
2455     return lpaf->value;
2456 }
2457
2458
2459 /******************************************************************************
2460  * ParseAceStringFlags
2461  */
2462 ACEFLAG AceFlags[] =
2463 {
2464     { SDDL_CONTAINER_INHERIT, CONTAINER_INHERIT_ACE },
2465     { SDDL_AUDIT_FAILURE,     FAILED_ACCESS_ACE_FLAG },
2466     { SDDL_INHERITED,         INHERITED_ACE },
2467     { SDDL_INHERIT_ONLY,      INHERIT_ONLY_ACE },
2468     { SDDL_NO_PROPAGATE,      NO_PROPAGATE_INHERIT_ACE },
2469     { SDDL_OBJECT_INHERIT,    OBJECT_INHERIT_ACE },
2470     { SDDL_AUDIT_SUCCESS,     SUCCESSFUL_ACCESS_ACE_FLAG },
2471     { NULL, 0 },
2472 };
2473
2474 static BYTE ParseAceStringFlags(LPCWSTR* StringAcl)
2475 {
2476     UINT len = 0;
2477     BYTE flags = 0;
2478     LPCWSTR szAcl = *StringAcl;
2479
2480     while (*szAcl != ';')
2481     {
2482         LPACEFLAG lpaf = AceFlags;
2483
2484         while (lpaf->wstr &&
2485                (len = strlenW(lpaf->wstr)) &&
2486                strncmpW(lpaf->wstr, szAcl, len))
2487             lpaf++;
2488
2489         if (!lpaf->wstr)
2490             return 0;
2491
2492         flags |= lpaf->value;
2493         szAcl += len;
2494     }
2495
2496     *StringAcl = szAcl;
2497     return flags;
2498 }
2499
2500
2501 /******************************************************************************
2502  * ParseAceStringRights
2503  */
2504 ACEFLAG AceRights[] =
2505 {
2506     { SDDL_GENERIC_ALL,     GENERIC_ALL },
2507     { SDDL_GENERIC_READ,    GENERIC_READ },
2508     { SDDL_GENERIC_WRITE,   GENERIC_WRITE },
2509     { SDDL_GENERIC_EXECUTE, GENERIC_EXECUTE },
2510     { SDDL_READ_CONTROL,    READ_CONTROL },
2511     { SDDL_STANDARD_DELETE, DELETE },
2512     { SDDL_WRITE_DAC,       WRITE_DAC },
2513     { SDDL_WRITE_OWNER,     WRITE_OWNER },
2514     { NULL, 0 },
2515 };
2516
2517 static DWORD ParseAceStringRights(LPCWSTR* StringAcl)
2518 {
2519     UINT len = 0;
2520     DWORD rights = 0;
2521     LPCWSTR szAcl = *StringAcl;
2522
2523     if ((*szAcl == '0') && (*(szAcl + 1) == 'x'))
2524     {
2525         LPCWSTR p = szAcl;
2526
2527         while (*p && *p != ';')
2528             p++;
2529
2530         if (p - szAcl <= 8)
2531         {
2532             rights = strtoulW(szAcl, NULL, 16);
2533             *StringAcl = p;
2534         }
2535         else
2536             WARN("Invalid rights string format: %s\n", debugstr_wn(szAcl, p - szAcl));
2537     }
2538     else
2539     {
2540         while (*szAcl != ';')
2541         {
2542             LPACEFLAG lpaf = AceRights;
2543
2544             while (lpaf->wstr &&
2545                (len = strlenW(lpaf->wstr)) &&
2546                strncmpW(lpaf->wstr, szAcl, len))
2547             {
2548                lpaf++;
2549             }
2550
2551             if (!lpaf->wstr)
2552                 return 0;
2553
2554             rights |= lpaf->value;
2555             szAcl += len;
2556         }
2557     }
2558
2559     *StringAcl = szAcl;
2560     return rights;
2561 }
2562
2563
2564 /******************************************************************************
2565  * ParseStringAclToAcl
2566  * 
2567  * dacl_flags(string_ace1)(string_ace2)... (string_acen) 
2568  */
2569 static BOOL ParseStringAclToAcl(LPCWSTR StringAcl, LPDWORD lpdwFlags, 
2570     PACL pAcl, LPDWORD cBytes)
2571 {
2572     DWORD val;
2573     DWORD sidlen;
2574     DWORD length = sizeof(ACL);
2575     PACCESS_ALLOWED_ACE pAce = NULL; /* pointer to current ACE */
2576
2577     TRACE("%s\n", debugstr_w(StringAcl));
2578
2579     if (!StringAcl)
2580         return FALSE;
2581
2582     if (pAcl) /* pAce is only useful if we're setting values */
2583         pAce = (PACCESS_ALLOWED_ACE) ((LPBYTE)pAcl + sizeof(PACL));
2584
2585     /* Parse ACL flags */
2586     *lpdwFlags = ParseAclStringFlags(&StringAcl);
2587
2588     /* Parse ACE */
2589     while (*StringAcl == '(')
2590     {
2591         StringAcl++;
2592
2593         /* Parse ACE type */
2594         val = ParseAceStringType(&StringAcl);
2595         if (pAce)
2596             pAce->Header.AceType = (BYTE) val;
2597         if (*StringAcl != ';')
2598             goto lerr;
2599         StringAcl++;
2600
2601         /* Parse ACE flags */
2602         val = ParseAceStringFlags(&StringAcl);
2603         if (pAce)
2604             pAce->Header.AceFlags = (BYTE) val;
2605         if (*StringAcl != ';')
2606             goto lerr;
2607         StringAcl++;
2608
2609         /* Parse ACE rights */
2610         val = ParseAceStringRights(&StringAcl);
2611         if (pAce)
2612             pAce->Mask = val;
2613         if (*StringAcl != ';')
2614             goto lerr;
2615         StringAcl++;
2616
2617         /* Parse ACE object guid */
2618         if (*StringAcl != ';')
2619         {
2620             FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
2621             goto lerr;
2622         }
2623         StringAcl++;
2624
2625         /* Parse ACE inherit object guid */
2626         if (*StringAcl != ';')
2627         {
2628             FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
2629             goto lerr;
2630         }
2631         StringAcl++;
2632
2633         /* Parse ACE account sid */
2634         if (ParseStringSidToSid(StringAcl, pAce ? (PSID)&pAce->SidStart : NULL, &sidlen))
2635         {
2636             while (*StringAcl && *StringAcl != ')')
2637                 StringAcl++;
2638         }
2639
2640         if (*StringAcl != ')')
2641             goto lerr;
2642         StringAcl++;
2643
2644         length += sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) + sidlen;
2645     }
2646
2647     *cBytes = length;
2648     return TRUE;
2649
2650 lerr:
2651     WARN("Invalid ACE string format\n");
2652     return FALSE;
2653 }
2654
2655
2656 /******************************************************************************
2657  * ParseStringSecurityDescriptorToSecurityDescriptor
2658  */
2659 static BOOL ParseStringSecurityDescriptorToSecurityDescriptor(
2660     LPCWSTR StringSecurityDescriptor,
2661     SECURITY_DESCRIPTOR* SecurityDescriptor,
2662     LPDWORD cBytes)
2663 {
2664     BOOL bret = FALSE;
2665     WCHAR toktype;
2666     WCHAR tok[MAX_PATH];
2667     LPCWSTR lptoken;
2668     LPBYTE lpNext = NULL;
2669     DWORD len;
2670
2671     *cBytes = 0;
2672
2673     if (SecurityDescriptor)
2674         lpNext = ((LPBYTE) SecurityDescriptor) + sizeof(SECURITY_DESCRIPTOR);
2675
2676     while (*StringSecurityDescriptor)
2677     {
2678         toktype = *StringSecurityDescriptor;
2679
2680         /* Expect char identifier followed by ':' */
2681         StringSecurityDescriptor++;
2682         if (*StringSecurityDescriptor != ':')
2683         {
2684             SetLastError(ERROR_INVALID_PARAMETER);
2685             goto lend;
2686         }
2687         StringSecurityDescriptor++;
2688
2689         /* Extract token */
2690         lptoken = StringSecurityDescriptor;
2691         while (*lptoken && *lptoken != ':')
2692             lptoken++;
2693
2694         if (*lptoken)
2695             lptoken--;
2696
2697         len = lptoken - StringSecurityDescriptor;
2698         memcpy( tok, StringSecurityDescriptor, len * sizeof(WCHAR) );
2699         tok[len] = 0;
2700
2701         switch (toktype)
2702         {
2703             case 'O':
2704             {
2705                 DWORD bytes;
2706
2707                 if (!ParseStringSidToSid(tok, (PSID)lpNext, &bytes))
2708                     goto lend;
2709
2710                 if (SecurityDescriptor)
2711                 {
2712                     SecurityDescriptor->Owner = (PSID) ((DWORD) lpNext -
2713                         (DWORD) SecurityDescriptor);
2714                     lpNext += bytes; /* Advance to next token */
2715                 }
2716
2717                 *cBytes += bytes;
2718
2719                 break;
2720             }
2721
2722             case 'G':
2723             {
2724                 DWORD bytes;
2725
2726                 if (!ParseStringSidToSid(tok, (PSID)lpNext, &bytes))
2727                     goto lend;
2728
2729                 if (SecurityDescriptor)
2730                 {
2731                     SecurityDescriptor->Group = (PSID) ((DWORD) lpNext - 
2732                         (DWORD) SecurityDescriptor);
2733                     lpNext += bytes; /* Advance to next token */
2734                 }
2735
2736                 *cBytes += bytes;
2737
2738                 break;
2739             }
2740
2741             case 'D':
2742             {
2743                 DWORD flags;
2744                 DWORD bytes;
2745
2746                 if (!ParseStringAclToAcl(tok, &flags, (PACL)lpNext, &bytes))
2747                     goto lend;
2748
2749                 if (SecurityDescriptor)
2750                 {
2751                     SecurityDescriptor->Control |= SE_DACL_PRESENT | flags;
2752                     SecurityDescriptor->Dacl = (PACL) ((DWORD) lpNext -
2753                         (DWORD) SecurityDescriptor);
2754                     lpNext += bytes; /* Advance to next token */
2755                 }
2756
2757                 *cBytes += bytes;
2758
2759                 break;
2760             }
2761
2762             case 'S':
2763             {
2764                 DWORD flags;
2765                 DWORD bytes;
2766
2767                 if (!ParseStringAclToAcl(tok, &flags, (PACL)lpNext, &bytes))
2768                     goto lend;
2769
2770                 if (SecurityDescriptor)
2771                 {
2772                     SecurityDescriptor->Control |= SE_SACL_PRESENT | flags;
2773                     SecurityDescriptor->Sacl = (PACL) ((DWORD) lpNext -
2774                         (DWORD) SecurityDescriptor);
2775                     lpNext += bytes; /* Advance to next token */
2776                 }
2777
2778                 *cBytes += bytes;
2779
2780                 break;
2781             }
2782
2783             default:
2784                 FIXME("Unknown token\n");
2785                 SetLastError(ERROR_INVALID_PARAMETER);
2786                 goto lend;
2787         }
2788
2789         StringSecurityDescriptor = lptoken;
2790     }
2791
2792     bret = TRUE;
2793
2794 lend:
2795     return bret;
2796 }
2797
2798 /******************************************************************************
2799  * ConvertStringSecurityDescriptorToSecurityDescriptorA [ADVAPI32.@]
2800  */
2801 BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorA(
2802         LPCSTR StringSecurityDescriptor,
2803         DWORD StringSDRevision,
2804         PSECURITY_DESCRIPTOR* SecurityDescriptor,
2805         PULONG SecurityDescriptorSize)
2806 {
2807     UINT len;
2808     BOOL ret = FALSE;
2809     LPWSTR StringSecurityDescriptorW;
2810
2811     len = MultiByteToWideChar(CP_ACP, 0, StringSecurityDescriptor, -1, NULL, 0);
2812     StringSecurityDescriptorW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
2813
2814     if (StringSecurityDescriptorW)
2815     {
2816         MultiByteToWideChar(CP_ACP, 0, StringSecurityDescriptor, -1, StringSecurityDescriptorW, len);
2817
2818         ret = ConvertStringSecurityDescriptorToSecurityDescriptorW(StringSecurityDescriptorW,
2819                                                                    StringSDRevision, SecurityDescriptor,
2820                                                                    SecurityDescriptorSize);
2821         HeapFree(GetProcessHeap(), 0, StringSecurityDescriptorW);
2822     }
2823
2824     return ret;
2825 }
2826
2827 /******************************************************************************
2828  * ConvertStringSecurityDescriptorToSecurityDescriptorW [ADVAPI32.@]
2829  */
2830 BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorW(
2831         LPCWSTR StringSecurityDescriptor,
2832         DWORD StringSDRevision,
2833         PSECURITY_DESCRIPTOR* SecurityDescriptor,
2834         PULONG SecurityDescriptorSize)
2835 {
2836     DWORD cBytes;
2837     SECURITY_DESCRIPTOR* psd;
2838     BOOL bret = FALSE;
2839
2840     TRACE("%s\n", debugstr_w(StringSecurityDescriptor));
2841
2842     if (GetVersion() & 0x80000000)
2843     {
2844         SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2845         goto lend;
2846     }
2847     else if (StringSDRevision != SID_REVISION)
2848     {
2849         SetLastError(ERROR_UNKNOWN_REVISION);
2850         goto lend;
2851     }
2852
2853     /* Compute security descriptor length */
2854     if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor,
2855         NULL, &cBytes))
2856         goto lend;
2857
2858     psd = *SecurityDescriptor = (SECURITY_DESCRIPTOR*) LocalAlloc(
2859         GMEM_ZEROINIT, cBytes);
2860
2861     psd->Revision = SID_REVISION;
2862     psd->Control |= SE_SELF_RELATIVE;
2863
2864     if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor,
2865         psd, &cBytes))
2866     {
2867         LocalFree(psd);
2868         goto lend;
2869     }
2870
2871     if (SecurityDescriptorSize)
2872         *SecurityDescriptorSize = cBytes;
2873
2874     bret = TRUE;
2875  
2876 lend:
2877     TRACE(" ret=%d\n", bret);
2878     return bret;
2879 }
2880
2881 /******************************************************************************
2882  * ConvertStringSidToSidW [ADVAPI32.@]
2883  */
2884 BOOL WINAPI ConvertStringSidToSidW(LPCWSTR StringSid, PSID* Sid)
2885 {
2886     BOOL bret = FALSE;
2887     DWORD cBytes;
2888
2889     TRACE("%s, %p\n", debugstr_w(StringSid), Sid);
2890     if (GetVersion() & 0x80000000)
2891         SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2892     else if (!StringSid || !Sid)
2893         SetLastError(ERROR_INVALID_PARAMETER);
2894     else if (ParseStringSidToSid(StringSid, NULL, &cBytes))
2895     {
2896         PSID pSid = *Sid = (PSID) LocalAlloc(0, cBytes);
2897
2898         bret = ParseStringSidToSid(StringSid, pSid, &cBytes);
2899         if (!bret)
2900             LocalFree(*Sid); 
2901     }
2902     TRACE("returning %s\n", bret ? "TRUE" : "FALSE");
2903     return bret;
2904 }
2905
2906 /******************************************************************************
2907  * ConvertStringSidToSidA [ADVAPI32.@]
2908  */
2909 BOOL WINAPI ConvertStringSidToSidA(LPCSTR StringSid, PSID* Sid)
2910 {
2911     BOOL bret = FALSE;
2912
2913     TRACE("%s, %p\n", debugstr_a(StringSid), Sid);
2914     if (GetVersion() & 0x80000000)
2915         SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2916     else if (!StringSid || !Sid)
2917         SetLastError(ERROR_INVALID_PARAMETER);
2918     else
2919     {
2920         UINT len = MultiByteToWideChar(CP_ACP, 0, StringSid, -1, NULL, 0);
2921         LPWSTR wStringSid = HeapAlloc(GetProcessHeap(), 0,
2922          len * sizeof(WCHAR));
2923
2924         MultiByteToWideChar(CP_ACP, 0, StringSid, -1, wStringSid, len);
2925         bret = ConvertStringSidToSidW(wStringSid, Sid);
2926         HeapFree(GetProcessHeap(), 0, wStringSid);
2927     }
2928     TRACE("returning %s\n", bret ? "TRUE" : "FALSE");
2929     return bret;
2930 }
2931
2932 /******************************************************************************
2933  * ConvertSidToStringSidW [ADVAPI32.@]
2934  *
2935  *  format of SID string is:
2936  *    S-<count>-<auth>-<subauth1>-<subauth2>-<subauth3>...
2937  *  where
2938  *    <rev> is the revision of the SID encoded as decimal
2939  *    <auth> is the identifier authority encoded as hex
2940  *    <subauthN> is the subauthority id encoded as decimal
2941  */
2942 BOOL WINAPI ConvertSidToStringSidW( PSID pSid, LPWSTR *pstr )
2943 {
2944     DWORD sz, i;
2945     LPWSTR str;
2946     WCHAR fmt[] = { 'S','-','%','u','-','%','d',0 };
2947     WCHAR subauthfmt[] = { '-','%','u',0 };
2948     SID* pisid=pSid;
2949
2950     TRACE("%p %p\n", pSid, pstr );
2951
2952     if( !IsValidSid( pSid ) )
2953         return FALSE;
2954
2955     if (pisid->Revision != SDDL_REVISION)
2956         return FALSE;
2957     if (pisid->IdentifierAuthority.Value[0] ||
2958      pisid->IdentifierAuthority.Value[1])
2959     {
2960         FIXME("not matching MS' bugs\n");
2961         return FALSE;
2962     }
2963
2964     sz = 14 + pisid->SubAuthorityCount * 11;
2965     str = LocalAlloc( 0, sz*sizeof(WCHAR) );
2966     sprintfW( str, fmt, pisid->Revision, MAKELONG(
2967      MAKEWORD( pisid->IdentifierAuthority.Value[5],
2968      pisid->IdentifierAuthority.Value[4] ),
2969      MAKEWORD( pisid->IdentifierAuthority.Value[3],
2970      pisid->IdentifierAuthority.Value[2] ) ) );
2971     for( i=0; i<pisid->SubAuthorityCount; i++ )
2972         sprintfW( str + strlenW(str), subauthfmt, pisid->SubAuthority[i] );
2973     *pstr = str;
2974
2975     return TRUE;
2976 }
2977
2978 /******************************************************************************
2979  * ConvertSidToStringSidA [ADVAPI32.@]
2980  */
2981 BOOL WINAPI ConvertSidToStringSidA(PSID pSid, LPSTR *pstr)
2982 {
2983     LPWSTR wstr = NULL;
2984     LPSTR str;
2985     UINT len;
2986
2987     TRACE("%p %p\n", pSid, pstr );
2988
2989     if( !ConvertSidToStringSidW( pSid, &wstr ) )
2990         return FALSE;
2991
2992     len = WideCharToMultiByte( CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL );
2993     str = LocalAlloc( 0, len );
2994     WideCharToMultiByte( CP_ACP, 0, wstr, -1, str, len, NULL, NULL );
2995     LocalFree( wstr );
2996
2997     *pstr = str;
2998
2999     return TRUE;
3000 }
3001
3002 BOOL WINAPI CreatePrivateObjectSecurity(
3003         PSECURITY_DESCRIPTOR ParentDescriptor,
3004         PSECURITY_DESCRIPTOR CreatorDescriptor,
3005         PSECURITY_DESCRIPTOR* NewDescriptor,
3006         BOOL IsDirectoryObject,
3007         HANDLE Token,
3008         PGENERIC_MAPPING GenericMapping )
3009 {
3010     FIXME("%p %p %p %d %p %p - stub\n", ParentDescriptor, CreatorDescriptor,
3011           NewDescriptor, IsDirectoryObject, Token, GenericMapping);
3012
3013     return FALSE;
3014 }
3015
3016 BOOL WINAPI DestroyPrivateObjectSecurity( PSECURITY_DESCRIPTOR* ObjectDescriptor )
3017 {
3018     FIXME("%p - stub\n", ObjectDescriptor);
3019
3020     return TRUE;
3021 }
3022
3023 BOOL WINAPI CreateProcessAsUserA(
3024         HANDLE hToken,
3025         LPCSTR lpApplicationName,
3026         LPSTR lpCommandLine,
3027         LPSECURITY_ATTRIBUTES lpProcessAttributes,
3028         LPSECURITY_ATTRIBUTES lpThreadAttributes,
3029         BOOL bInheritHandles,
3030         DWORD dwCreationFlags,
3031         LPVOID lpEnvironment,
3032         LPCSTR lpCurrentDirectory,
3033         LPSTARTUPINFOA lpStartupInfo,
3034         LPPROCESS_INFORMATION lpProcessInformation )
3035 {
3036     FIXME("%p %s %s %p %p %d 0x%08lx %p %s %p %p - stub\n", hToken, debugstr_a(lpApplicationName),
3037           debugstr_a(lpCommandLine), lpProcessAttributes, lpThreadAttributes, bInheritHandles,
3038           dwCreationFlags, lpEnvironment, debugstr_a(lpCurrentDirectory), lpStartupInfo, lpProcessInformation);
3039
3040     return FALSE;
3041 }
3042
3043 BOOL WINAPI CreateProcessAsUserW(
3044         HANDLE hToken,
3045         LPCWSTR lpApplicationName,
3046         LPWSTR lpCommandLine,
3047         LPSECURITY_ATTRIBUTES lpProcessAttributes,
3048         LPSECURITY_ATTRIBUTES lpThreadAttributes,
3049         BOOL bInheritHandles,
3050         DWORD dwCreationFlags,
3051         LPVOID lpEnvironment,
3052         LPCWSTR lpCurrentDirectory,
3053         LPSTARTUPINFOW lpStartupInfo,
3054         LPPROCESS_INFORMATION lpProcessInformation )
3055 {
3056     FIXME("%p %s %s %p %p %d 0x%08lx %p %s %p %p - semi- stub\n", hToken, 
3057           debugstr_w(lpApplicationName), debugstr_w(lpCommandLine), lpProcessAttributes,
3058           lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, 
3059           debugstr_w(lpCurrentDirectory), lpStartupInfo, lpProcessInformation);
3060
3061     /* We should create the process with a suspended main thread */
3062     if (!CreateProcessW (lpApplicationName,
3063                          lpCommandLine,
3064                          lpProcessAttributes,
3065                          lpThreadAttributes,
3066                          bInheritHandles,
3067                          dwCreationFlags, /* CREATE_SUSPENDED */
3068                          lpEnvironment,
3069                          lpCurrentDirectory,
3070                          lpStartupInfo,
3071                          lpProcessInformation))
3072     {
3073       return FALSE;
3074     }
3075
3076     return TRUE;
3077 }
3078
3079 /******************************************************************************
3080  * ComputeStringSidSize
3081  */
3082 static DWORD ComputeStringSidSize(LPCWSTR StringSid)
3083 {
3084     int ctok = 0;
3085     DWORD size = sizeof(SID);
3086
3087     while (*StringSid)
3088     {
3089         if (*StringSid == '-')
3090             ctok++;
3091         StringSid++;
3092     }
3093
3094     if (ctok > 3)
3095         size += (ctok - 3) * sizeof(DWORD);
3096
3097     return size;
3098 }
3099
3100 BOOL WINAPI DuplicateTokenEx(
3101         HANDLE ExistingTokenHandle, DWORD dwDesiredAccess,
3102         LPSECURITY_ATTRIBUTES lpTokenAttributes,
3103         SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
3104         TOKEN_TYPE TokenType,
3105         PHANDLE DuplicateTokenHandle )
3106 {
3107     OBJECT_ATTRIBUTES ObjectAttributes;
3108
3109     TRACE("%p 0x%08lx 0x%08x 0x%08x %p\n", ExistingTokenHandle, dwDesiredAccess,
3110           ImpersonationLevel, TokenType, DuplicateTokenHandle);
3111
3112     InitializeObjectAttributes(
3113         &ObjectAttributes,
3114         NULL,
3115         (lpTokenAttributes && lpTokenAttributes->bInheritHandle) ? OBJ_INHERIT : 0,
3116         NULL,
3117         lpTokenAttributes ? lpTokenAttributes->lpSecurityDescriptor : NULL );
3118
3119     return set_ntstatus( NtDuplicateToken( ExistingTokenHandle,
3120                                            dwDesiredAccess,
3121                                            &ObjectAttributes,
3122                                            ImpersonationLevel,
3123                                            TokenType,
3124                                            DuplicateTokenHandle ) );
3125 }
3126
3127 BOOL WINAPI DuplicateToken(
3128         HANDLE ExistingTokenHandle,
3129         SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
3130         PHANDLE DuplicateTokenHandle )
3131 {
3132     return DuplicateTokenEx( ExistingTokenHandle, TOKEN_IMPERSONATE | TOKEN_QUERY,
3133                              NULL, ImpersonationLevel, TokenImpersonation,
3134                              DuplicateTokenHandle );
3135 }
3136
3137 BOOL WINAPI EnumDependentServicesA(
3138         SC_HANDLE hService,
3139         DWORD dwServiceState,
3140         LPENUM_SERVICE_STATUSA lpServices,
3141         DWORD cbBufSize,
3142         LPDWORD pcbBytesNeeded,
3143         LPDWORD lpServicesReturned )
3144 {
3145     FIXME("%p 0x%08lx %p 0x%08lx %p %p - stub\n", hService, dwServiceState,
3146           lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned);
3147
3148     return FALSE;
3149 }
3150
3151 BOOL WINAPI EnumDependentServicesW(
3152         SC_HANDLE hService,
3153         DWORD dwServiceState,
3154         LPENUM_SERVICE_STATUSW lpServices,
3155         DWORD cbBufSize,
3156         LPDWORD pcbBytesNeeded,
3157         LPDWORD lpServicesReturned )
3158 {
3159     FIXME("%p 0x%08lx %p 0x%08lx %p %p - stub\n", hService, dwServiceState,
3160           lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned);
3161
3162     return FALSE;
3163 }
3164
3165 /******************************************************************************
3166  * ParseStringSidToSid
3167  */
3168 static BOOL ParseStringSidToSid(LPCWSTR StringSid, PSID pSid, LPDWORD cBytes)
3169 {
3170     BOOL bret = FALSE;
3171     SID* pisid=pSid;
3172
3173     TRACE("%s, %p, %p\n", debugstr_w(StringSid), pSid, cBytes);
3174     if (!StringSid)
3175     {
3176         SetLastError(ERROR_INVALID_PARAMETER);
3177         TRACE("StringSid is NULL, returning FALSE\n");
3178         return FALSE;
3179     }
3180
3181     *cBytes = ComputeStringSidSize(StringSid);
3182     if (!pisid) /* Simply compute the size */
3183     {
3184         TRACE("only size requested, returning TRUE\n");
3185         return TRUE;
3186     }
3187
3188     if (*StringSid != 'S' || *StringSid != '-') /* S-R-I-S-S */
3189     {
3190         DWORD i = 0, identAuth;
3191         DWORD csubauth = ((*cBytes - sizeof(SID)) / sizeof(DWORD)) + 1;
3192
3193         StringSid += 2; /* Advance to Revision */
3194         pisid->Revision = atoiW(StringSid);
3195
3196         if (pisid->Revision != SDDL_REVISION)
3197         {
3198             TRACE("Revision %d is unknown\n", pisid->Revision);
3199             goto lend; /* ERROR_INVALID_SID */
3200         }
3201         if (csubauth == 0)
3202         {
3203             TRACE("SubAuthorityCount is 0\n");
3204             goto lend; /* ERROR_INVALID_SID */
3205         }
3206
3207         pisid->SubAuthorityCount = csubauth;
3208
3209         /* Advance to identifier authority */
3210         while (*StringSid && *StringSid != '-')
3211             StringSid++;
3212         if (*StringSid == '-')
3213             StringSid++;
3214
3215         /* MS' implementation can't handle values greater than 2^32 - 1, so
3216          * we don't either; assume most significant bytes are always 0
3217          */
3218         pisid->IdentifierAuthority.Value[0] = 0;
3219         pisid->IdentifierAuthority.Value[1] = 0;
3220         identAuth = atoiW(StringSid);
3221         pisid->IdentifierAuthority.Value[5] = identAuth & 0xff;
3222         pisid->IdentifierAuthority.Value[4] = (identAuth & 0xff00) >> 8;
3223         pisid->IdentifierAuthority.Value[3] = (identAuth & 0xff0000) >> 16;
3224         pisid->IdentifierAuthority.Value[2] = (identAuth & 0xff000000) >> 24;
3225
3226         /* Advance to first sub authority */
3227         while (*StringSid && *StringSid != '-')
3228             StringSid++;
3229         if (*StringSid == '-')
3230             StringSid++;
3231
3232         while (*StringSid)
3233         {       
3234             while (*StringSid && *StringSid != '-')
3235                 StringSid++;
3236
3237             pisid->SubAuthority[i++] = atoiW(StringSid);
3238         }
3239
3240         if (i != pisid->SubAuthorityCount)
3241             goto lend; /* ERROR_INVALID_SID */
3242
3243         bret = TRUE;
3244     }
3245     else /* String constant format  - Only available in winxp and above */
3246     {
3247         pisid->Revision = SDDL_REVISION;
3248         pisid->SubAuthorityCount = 1;
3249
3250         FIXME("String constant not supported: %s\n", debugstr_wn(StringSid, 2));
3251
3252         /* TODO: Lookup string of well-known SIDs in table */
3253         pisid->IdentifierAuthority.Value[5] = 0;
3254         pisid->SubAuthority[0] = 0;
3255
3256         bret = TRUE;
3257     }
3258
3259 lend:
3260     if (!bret)
3261         SetLastError(ERROR_INVALID_SID);
3262
3263     TRACE("returning %s\n", bret ? "TRUE" : "FALSE");
3264     return bret;
3265 }
3266
3267 /******************************************************************************
3268  * GetNamedSecurityInfoA [ADVAPI32.@]
3269  */
3270 DWORD WINAPI GetNamedSecurityInfoA(LPSTR pObjectName,
3271         SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
3272         PSID* ppsidOwner, PSID* ppsidGroup, PACL* ppDacl, PACL* ppSacl,
3273         PSECURITY_DESCRIPTOR* ppSecurityDescriptor)
3274 {
3275     DWORD len;
3276     LPWSTR wstr = NULL;
3277     DWORD r;
3278
3279     TRACE("%s %d %ld %p %p %p %p %p\n", pObjectName, ObjectType, SecurityInfo,
3280         ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor);
3281
3282     if( pObjectName )
3283     {
3284         len = MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, NULL, 0 );
3285         wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR));
3286         MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, wstr, len );
3287     }
3288
3289     r = GetNamedSecurityInfoW( wstr, ObjectType, SecurityInfo, ppsidOwner,
3290                            ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor );
3291
3292     HeapFree( GetProcessHeap(), 0, wstr );
3293
3294     return r;
3295 }
3296
3297 /******************************************************************************
3298  * GetNamedSecurityInfoW [ADVAPI32.@]
3299  */
3300 DWORD WINAPI GetNamedSecurityInfoW( LPWSTR name, SE_OBJECT_TYPE type,
3301     SECURITY_INFORMATION info, PSID* owner, PSID* group, PACL* dacl,
3302     PACL* sacl, PSECURITY_DESCRIPTOR* descriptor )
3303 {
3304     DWORD needed, offset;
3305     SECURITY_DESCRIPTOR_RELATIVE *relative;
3306     BYTE *buffer;
3307
3308     TRACE( "%s %d %ld %p %p %p %p %p\n", debugstr_w(name), type, info, owner,
3309            group, dacl, sacl, descriptor );
3310
3311     if (!name || !descriptor) return ERROR_INVALID_PARAMETER;
3312
3313     needed = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
3314     if (info & OWNER_SECURITY_INFORMATION)
3315         needed += sizeof(sidWorld);
3316     if (info & GROUP_SECURITY_INFORMATION)
3317         needed += sizeof(sidWorld);
3318     if (info & DACL_SECURITY_INFORMATION)
3319         needed += WINE_SIZE_OF_WORLD_ACCESS_ACL;
3320     if (info & SACL_SECURITY_INFORMATION)
3321         needed += WINE_SIZE_OF_WORLD_ACCESS_ACL;
3322
3323     /* must be freed by caller */
3324     *descriptor = HeapAlloc( GetProcessHeap(), 0, needed );
3325     if (!*descriptor) return ERROR_NOT_ENOUGH_MEMORY;
3326
3327     if (!InitializeSecurityDescriptor( *descriptor, SECURITY_DESCRIPTOR_REVISION ))
3328     {
3329         HeapFree( GetProcessHeap(), 0, *descriptor );
3330         return ERROR_INVALID_SECURITY_DESCR;
3331     }
3332
3333     relative = (SECURITY_DESCRIPTOR_RELATIVE *)*descriptor;
3334     relative->Control |= SE_SELF_RELATIVE;
3335     buffer = (BYTE *)relative;
3336     offset = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
3337
3338     if (owner && (info & OWNER_SECURITY_INFORMATION))
3339     {
3340         memcpy( buffer + offset, &sidWorld, sizeof(sidWorld) );
3341         relative->Owner = offset;
3342         *owner = buffer + offset;
3343         offset += sizeof(sidWorld);
3344     }
3345     if (group && (info & GROUP_SECURITY_INFORMATION))
3346     {
3347         memcpy( buffer + offset, &sidWorld, sizeof(sidWorld) );
3348         relative->Group = offset;
3349         *group = buffer + offset;
3350         offset += sizeof(sidWorld);
3351     }
3352     if (dacl && (info & DACL_SECURITY_INFORMATION))
3353     {
3354         GetWorldAccessACL( (PACL)(buffer + offset) );
3355         relative->Dacl = offset;
3356         *dacl = (PACL)(buffer + offset);
3357         offset += WINE_SIZE_OF_WORLD_ACCESS_ACL;
3358     }
3359     if (sacl && (info & SACL_SECURITY_INFORMATION))
3360     {
3361         GetWorldAccessACL( (PACL)(buffer + offset) );
3362         relative->Sacl = offset;
3363         *sacl = (PACL)(buffer + offset);
3364     }
3365     return ERROR_SUCCESS;
3366 }
3367
3368 /******************************************************************************
3369  * DecryptFileW [ADVAPI32.@]
3370  */
3371 BOOL WINAPI DecryptFileW(LPCWSTR lpFileName, DWORD dwReserved)
3372 {
3373     FIXME("%s %08lx\n", debugstr_w(lpFileName), dwReserved);
3374     return TRUE;
3375 }
3376
3377 /******************************************************************************
3378  * DecryptFileA [ADVAPI32.@]
3379  */
3380 BOOL WINAPI DecryptFileA(LPCSTR lpFileName, DWORD dwReserved)
3381 {
3382     FIXME("%s %08lx\n", debugstr_a(lpFileName), dwReserved);
3383     return TRUE;
3384 }
3385
3386 /******************************************************************************
3387  * EncryptFileW [ADVAPI32.@]
3388  */
3389 BOOL WINAPI EncryptFileW(LPCWSTR lpFileName)
3390 {
3391     FIXME("%s\n", debugstr_w(lpFileName));
3392     return TRUE;
3393 }
3394
3395 /******************************************************************************
3396  * EncryptFileA [ADVAPI32.@]
3397  */
3398 BOOL WINAPI EncryptFileA(LPCSTR lpFileName)
3399 {
3400     FIXME("%s\n", debugstr_a(lpFileName));
3401     return TRUE;
3402 }
3403
3404 /******************************************************************************
3405  * SetSecurityInfo [ADVAPI32.@]
3406  */
3407 DWORD WINAPI SetSecurityInfo(HANDLE handle, SE_OBJECT_TYPE ObjectType, 
3408                       SECURITY_INFORMATION SecurityInfo, PSID psidOwner,
3409                       PSID psidGroup, PACL pDacl, PACL pSacl) {
3410     FIXME("stub\n");
3411     return ERROR_SUCCESS;
3412 }