2 * Copyright 1999, 2000 Juergen Schmied <juergen.schmied@debitel.net>
3 * Copyright 2003 CodeWeavers Inc. (Ulrich Czekalla)
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.
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.
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
38 #include "wine/debug.h"
39 #include "wine/unicode.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
43 static BOOL ParseStringSidToSid(LPCWSTR StringSid, PSID pSid, LPDWORD cBytes);
44 static BOOL ParseStringAclToAcl(LPCWSTR StringAcl, LPDWORD lpdwFlags,
45 PACL pAcl, LPDWORD cBytes);
46 static BYTE ParseAceStringFlags(LPCWSTR* StringAcl);
47 static BYTE ParseAceStringType(LPCWSTR* StringAcl);
48 static DWORD ParseAceStringRights(LPCWSTR* StringAcl);
49 static BOOL ParseStringSecurityDescriptorToSecurityDescriptor(
50 LPCWSTR StringSecurityDescriptor,
51 SECURITY_DESCRIPTOR* SecurityDescriptor,
53 static DWORD ParseAclStringFlags(LPCWSTR* StringAcl);
55 typedef struct _ACEFLAG
59 } ACEFLAG, *LPACEFLAG;
61 static SID const sidWorld = { SID_REVISION, 1, { SECURITY_WORLD_SID_AUTHORITY} , { SECURITY_WORLD_RID } };
66 static const WCHAR SDDL_READ_CONTROL[] = {'R','C',0};
67 static const WCHAR SDDL_WRITE_DAC[] = {'W','D',0};
68 static const WCHAR SDDL_WRITE_OWNER[] = {'W','O',0};
69 static const WCHAR SDDL_STANDARD_DELETE[] = {'S','D',0};
70 static const WCHAR SDDL_GENERIC_ALL[] = {'G','A',0};
71 static const WCHAR SDDL_GENERIC_READ[] = {'G','R',0};
72 static const WCHAR SDDL_GENERIC_WRITE[] = {'G','W',0};
73 static const WCHAR SDDL_GENERIC_EXECUTE[] = {'G','X',0};
78 static const WCHAR SDDL_ACCESS_ALLOWED[] = {'A',0};
79 static const WCHAR SDDL_ACCESS_DENIED[] = {'D',0};
80 static const WCHAR SDDL_OBJECT_ACCESS_ALLOWED[] = {'O','A',0};
81 static const WCHAR SDDL_OBJECT_ACCESS_DENIED[] = {'O','D',0};
82 static const WCHAR SDDL_AUDIT[] = {'A','U',0};
83 static const WCHAR SDDL_ALARM[] = {'A','L',0};
84 static const WCHAR SDDL_OBJECT_AUDIT[] = {'O','U',0};
85 static const WCHAR SDDL_OBJECT_ALARMp[] = {'O','L',0};
90 static const WCHAR SDDL_CONTAINER_INHERIT[] = {'C','I',0};
91 static const WCHAR SDDL_OBJECT_INHERIT[] = {'O','I',0};
92 static const WCHAR SDDL_NO_PROPAGATE[] = {'N','P',0};
93 static const WCHAR SDDL_INHERIT_ONLY[] = {'I','O',0};
94 static const WCHAR SDDL_INHERITED[] = {'I','D',0};
95 static const WCHAR SDDL_AUDIT_SUCCESS[] = {'S','A',0};
96 static const WCHAR SDDL_AUDIT_FAILURE[] = {'F','A',0};
98 /* set last error code from NT status and get the proper boolean return value */
99 /* used for functions that are a simple wrapper around the corresponding ntdll API */
100 static inline BOOL set_ntstatus( NTSTATUS status )
102 if (status) SetLastError( RtlNtStatusToDosError( status ));
106 #define WINE_SIZE_OF_WORLD_ACCESS_ACL (sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) + sizeof(sidWorld) - sizeof(DWORD))
108 static void GetWorldAccessACL(PACL pACL)
110 PACCESS_ALLOWED_ACE pACE = (PACCESS_ALLOWED_ACE) (pACL + 1);
112 pACL->AclRevision = ACL_REVISION;
114 pACL->AclSize = WINE_SIZE_OF_WORLD_ACCESS_ACL;
118 pACE->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
119 pACE->Header.AceFlags = CONTAINER_INHERIT_ACE;
120 pACE->Header.AceSize = sizeof(ACCESS_ALLOWED_ACE) + sizeof(sidWorld) - sizeof(DWORD);
121 pACE->Mask = 0xf3ffffff; /* Everything except reserved bits */
122 memcpy(&pACE->SidStart, &sidWorld, sizeof(sidWorld));
125 /************************************************************
126 * ADVAPI_IsLocalComputer
128 * Checks whether the server name indicates local machine.
130 static BOOL ADVAPI_IsLocalComputer(LPCWSTR ServerName)
132 DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
136 if (!ServerName || !ServerName[0])
139 buf = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
140 Result = GetComputerNameW(buf, &dwSize);
141 if (Result && (ServerName[0] == '\\') && (ServerName[1] == '\\'))
143 Result = Result && !lstrcmpW(ServerName, buf);
144 HeapFree(GetProcessHeap(), 0, buf);
149 /* ##############################
150 ###### TOKEN FUNCTIONS ######
151 ##############################
154 /******************************************************************************
155 * OpenProcessToken [ADVAPI32.@]
156 * Opens the access token associated with a process handle.
159 * ProcessHandle [I] Handle to process
160 * DesiredAccess [I] Desired access to process
161 * TokenHandle [O] Pointer to handle of open access token
164 * Success: TRUE. TokenHandle contains the access token.
168 * See NtOpenProcessToken.
171 OpenProcessToken( HANDLE ProcessHandle, DWORD DesiredAccess,
172 HANDLE *TokenHandle )
174 return set_ntstatus(NtOpenProcessToken( ProcessHandle, DesiredAccess, TokenHandle ));
177 /******************************************************************************
178 * OpenThreadToken [ADVAPI32.@]
180 * Opens the access token associated with a thread handle.
183 * ThreadHandle [I] Handle to process
184 * DesiredAccess [I] Desired access to the thread
186 * TokenHandle [O] Destination for the token handle
189 * Success: TRUE. TokenHandle contains the access token.
193 * See NtOpenThreadToken.
196 OpenThreadToken( HANDLE ThreadHandle, DWORD DesiredAccess,
197 BOOL OpenAsSelf, HANDLE *TokenHandle)
199 return set_ntstatus( NtOpenThreadToken(ThreadHandle, DesiredAccess, OpenAsSelf, TokenHandle));
203 AdjustTokenGroups( HANDLE TokenHandle, BOOL ResetToDefault, PTOKEN_GROUPS NewState,
204 DWORD BufferLength, PTOKEN_GROUPS PreviousState, PDWORD ReturnLength )
206 return set_ntstatus( NtAdjustGroupsToken(TokenHandle, ResetToDefault, NewState, BufferLength,
207 PreviousState, ReturnLength));
210 /******************************************************************************
211 * AdjustTokenPrivileges [ADVAPI32.@]
213 * Adjust the privileges of an open token handle.
216 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
217 * DisableAllPrivileges [I] TRUE=Remove all privileges, FALSE=Use NewState
218 * NewState [I] Desired new privileges of the token
219 * BufferLength [I] Length of NewState
220 * PreviousState [O] Destination for the previous state
221 * ReturnLength [I/O] Size of PreviousState
225 * Success: TRUE. Privileges are set to NewState and PreviousState is updated.
229 * See NtAdjustPrivilegesToken.
232 AdjustTokenPrivileges( HANDLE TokenHandle, BOOL DisableAllPrivileges,
233 LPVOID NewState, DWORD BufferLength,
234 LPVOID PreviousState, LPDWORD ReturnLength )
240 status = NtAdjustPrivilegesToken(TokenHandle, DisableAllPrivileges,
241 NewState, BufferLength, PreviousState,
243 SetLastError( RtlNtStatusToDosError( status ));
244 if ((status == STATUS_SUCCESS) || (status == STATUS_NOT_ALL_ASSIGNED))
250 /******************************************************************************
251 * CheckTokenMembership [ADVAPI32.@]
253 * Determine if an access token is a member of a SID.
256 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
257 * SidToCheck [I] SID that possibly contains the token
258 * IsMember [O] Destination for result.
261 * Success: TRUE. IsMember is TRUE if TokenHandle is a member, FALSE otherwise.
265 CheckTokenMembership( HANDLE TokenHandle, PSID SidToCheck,
268 FIXME("(%p %p %p) stub!\n", TokenHandle, SidToCheck, IsMember);
274 /******************************************************************************
275 * GetTokenInformation [ADVAPI32.@]
278 * token [I] Handle from OpenProcessToken() or OpenThreadToken()
279 * tokeninfoclass [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
280 * tokeninfo [O] Destination for token information
281 * tokeninfolength [I] Length of tokeninfo
282 * retlen [O] Destination for returned token information length
285 * Success: TRUE. tokeninfo contains retlen bytes of token information
289 * See NtQueryInformationToken.
292 GetTokenInformation( HANDLE token, TOKEN_INFORMATION_CLASS tokeninfoclass,
293 LPVOID tokeninfo, DWORD tokeninfolength, LPDWORD retlen )
295 TRACE("(%p, %s, %p, %ld, %p): \n",
297 (tokeninfoclass == TokenUser) ? "TokenUser" :
298 (tokeninfoclass == TokenGroups) ? "TokenGroups" :
299 (tokeninfoclass == TokenPrivileges) ? "TokenPrivileges" :
300 (tokeninfoclass == TokenOwner) ? "TokenOwner" :
301 (tokeninfoclass == TokenPrimaryGroup) ? "TokenPrimaryGroup" :
302 (tokeninfoclass == TokenDefaultDacl) ? "TokenDefaultDacl" :
303 (tokeninfoclass == TokenSource) ? "TokenSource" :
304 (tokeninfoclass == TokenType) ? "TokenType" :
305 (tokeninfoclass == TokenImpersonationLevel) ? "TokenImpersonationLevel" :
306 (tokeninfoclass == TokenStatistics) ? "TokenStatistics" :
307 (tokeninfoclass == TokenRestrictedSids) ? "TokenRestrictedSids" :
308 (tokeninfoclass == TokenSessionId) ? "TokenSessionId" :
309 (tokeninfoclass == TokenGroupsAndPrivileges) ? "TokenGroupsAndPrivileges" :
310 (tokeninfoclass == TokenSessionReference) ? "TokenSessionReference" :
311 (tokeninfoclass == TokenSandBoxInert) ? "TokenSandBoxInert" :
313 tokeninfo, tokeninfolength, retlen);
314 return set_ntstatus( NtQueryInformationToken( token, tokeninfoclass, tokeninfo,
315 tokeninfolength, retlen));
318 /******************************************************************************
319 * SetTokenInformation [ADVAPI32.@]
321 * Set information for an access token.
324 * token [I] Handle from OpenProcessToken() or OpenThreadToken()
325 * tokeninfoclass [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
326 * tokeninfo [I] Token information to set
327 * tokeninfolength [I] Length of tokeninfo
330 * Success: TRUE. The information for the token is set to tokeninfo.
334 SetTokenInformation( HANDLE token, TOKEN_INFORMATION_CLASS tokeninfoclass,
335 LPVOID tokeninfo, DWORD tokeninfolength )
337 TRACE("(%p, %s, %p, %ld): stub\n",
339 (tokeninfoclass == TokenUser) ? "TokenUser" :
340 (tokeninfoclass == TokenGroups) ? "TokenGroups" :
341 (tokeninfoclass == TokenPrivileges) ? "TokenPrivileges" :
342 (tokeninfoclass == TokenOwner) ? "TokenOwner" :
343 (tokeninfoclass == TokenPrimaryGroup) ? "TokenPrimaryGroup" :
344 (tokeninfoclass == TokenDefaultDacl) ? "TokenDefaultDacl" :
345 (tokeninfoclass == TokenSource) ? "TokenSource" :
346 (tokeninfoclass == TokenType) ? "TokenType" :
347 (tokeninfoclass == TokenImpersonationLevel) ? "TokenImpersonationLevel" :
348 (tokeninfoclass == TokenStatistics) ? "TokenStatistics" :
349 (tokeninfoclass == TokenRestrictedSids) ? "TokenRestrictedSids" :
350 (tokeninfoclass == TokenSessionId) ? "TokenSessionId" :
351 (tokeninfoclass == TokenGroupsAndPrivileges) ? "TokenGroupsAndPrivileges" :
352 (tokeninfoclass == TokenSessionReference) ? "TokenSessionReference" :
353 (tokeninfoclass == TokenSandBoxInert) ? "TokenSandBoxInert" :
355 tokeninfo, tokeninfolength);
357 return set_ntstatus( NtSetInformationToken( token, tokeninfoclass, tokeninfo, tokeninfolength ));
360 /*************************************************************************
361 * SetThreadToken [ADVAPI32.@]
363 * Assigns an 'impersonation token' to a thread so it can assume the
364 * security privileges of another thread or process. Can also remove
365 * a previously assigned token.
368 * thread [O] Handle to thread to set the token for
369 * token [I] Token to set
372 * Success: TRUE. The threads access token is set to token
376 * Only supported on NT or higher. On Win9X this function does nothing.
377 * See SetTokenInformation.
379 BOOL WINAPI SetThreadToken(PHANDLE thread, HANDLE token)
381 return set_ntstatus( NtSetInformationThread( thread ? *thread : GetCurrentThread(),
382 ThreadImpersonationToken, &token, sizeof token ));
385 /* ##############################
386 ###### SID FUNCTIONS ######
387 ##############################
390 /******************************************************************************
391 * AllocateAndInitializeSid [ADVAPI32.@]
394 * pIdentifierAuthority []
395 * nSubAuthorityCount []
407 AllocateAndInitializeSid( PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
408 BYTE nSubAuthorityCount,
409 DWORD nSubAuthority0, DWORD nSubAuthority1,
410 DWORD nSubAuthority2, DWORD nSubAuthority3,
411 DWORD nSubAuthority4, DWORD nSubAuthority5,
412 DWORD nSubAuthority6, DWORD nSubAuthority7,
415 return set_ntstatus( RtlAllocateAndInitializeSid(
416 pIdentifierAuthority, nSubAuthorityCount,
417 nSubAuthority0, nSubAuthority1, nSubAuthority2, nSubAuthority3,
418 nSubAuthority4, nSubAuthority5, nSubAuthority6, nSubAuthority7,
422 /******************************************************************************
423 * FreeSid [ADVAPI32.@]
432 return NULL; /* is documented like this */
435 /******************************************************************************
436 * CopySid [ADVAPI32.@]
439 * nDestinationSidLength []
444 CopySid( DWORD nDestinationSidLength, PSID pDestinationSid, PSID pSourceSid )
446 return RtlCopySid(nDestinationSidLength, pDestinationSid, pSourceSid);
450 IsTokenRestricted( HANDLE TokenHandle )
452 TOKEN_GROUPS *groups;
457 TRACE("(%p)\n", TokenHandle);
459 status = NtQueryInformationToken(TokenHandle, TokenRestrictedSids, NULL, 0, &size);
460 if (status != STATUS_BUFFER_TOO_SMALL)
463 groups = HeapAlloc(GetProcessHeap(), 0, size);
466 SetLastError(ERROR_OUTOFMEMORY);
470 status = NtQueryInformationToken(TokenHandle, TokenRestrictedSids, groups, size, &size);
471 if (status != STATUS_SUCCESS)
473 HeapFree(GetProcessHeap(), 0, groups);
474 return set_ntstatus(status);
477 if (groups->GroupCount)
482 HeapFree(GetProcessHeap(), 0, groups);
487 /******************************************************************************
488 * IsValidSid [ADVAPI32.@]
494 IsValidSid( PSID pSid )
496 return RtlValidSid( pSid );
499 /******************************************************************************
500 * EqualSid [ADVAPI32.@]
507 EqualSid( PSID pSid1, PSID pSid2 )
509 return RtlEqualSid( pSid1, pSid2 );
512 /******************************************************************************
513 * EqualPrefixSid [ADVAPI32.@]
515 BOOL WINAPI EqualPrefixSid (PSID pSid1, PSID pSid2)
517 return RtlEqualPrefixSid(pSid1, pSid2);
520 /******************************************************************************
521 * GetSidLengthRequired [ADVAPI32.@]
524 * nSubAuthorityCount []
527 GetSidLengthRequired( BYTE nSubAuthorityCount )
529 return RtlLengthRequiredSid(nSubAuthorityCount);
532 /******************************************************************************
533 * InitializeSid [ADVAPI32.@]
536 * pIdentifierAuthority []
541 PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
542 BYTE nSubAuthorityCount)
544 return RtlInitializeSid(pSid, pIdentifierAuthority, nSubAuthorityCount);
548 GetEffectiveRightsFromAclA( PACL pacl, PTRUSTEEA pTrustee, PACCESS_MASK pAccessRights )
550 FIXME("%p %p %p - stub\n", pacl, pTrustee, pAccessRights);
556 GetEffectiveRightsFromAclW( PACL pacl, PTRUSTEEW pTrustee, PACCESS_MASK pAccessRights )
558 FIXME("%p %p %p - stub\n", pacl, pTrustee, pAccessRights);
563 /******************************************************************************
564 * GetSidIdentifierAuthority [ADVAPI32.@]
569 PSID_IDENTIFIER_AUTHORITY WINAPI
570 GetSidIdentifierAuthority( PSID pSid )
572 return RtlIdentifierAuthoritySid(pSid);
575 /******************************************************************************
576 * GetSidSubAuthority [ADVAPI32.@]
583 GetSidSubAuthority( PSID pSid, DWORD nSubAuthority )
585 return RtlSubAuthoritySid(pSid, nSubAuthority);
588 /******************************************************************************
589 * GetSidSubAuthorityCount [ADVAPI32.@]
595 GetSidSubAuthorityCount (PSID pSid)
597 return RtlSubAuthorityCountSid(pSid);
600 /******************************************************************************
601 * GetLengthSid [ADVAPI32.@]
607 GetLengthSid (PSID pSid)
609 return RtlLengthSid(pSid);
612 /* ##############################################
613 ###### SECURITY DESCRIPTOR FUNCTIONS ######
614 ##############################################
617 /******************************************************************************
618 * BuildSecurityDescriptorA [ADVAPI32.@]
625 * cCountOfAccessEntries [I]
626 * pListOfAccessEntries [I]
627 * cCountOfAuditEntries [I]
628 * pListofAuditEntries [I]
630 * lpdwBufferLength [I/O]
633 DWORD WINAPI BuildSecurityDescriptorA(
634 IN PTRUSTEE_A pOwner,
635 IN PTRUSTEE_A pGroup,
636 IN DWORD cCountOfAccessEntries,
637 IN PEXPLICIT_ACCESS_A pListOfAccessEntries,
638 IN DWORD cCountOfAuditEntries,
639 IN PEXPLICIT_ACCESS_A pListofAuditEntries,
640 IN PSECURITY_DESCRIPTOR pOldSD,
641 IN OUT PDWORD lpdwBufferLength,
642 OUT PSECURITY_DESCRIPTOR pNewSD)
644 FIXME("(%p,%p,%ld,%p,%ld,%p,%p,%p,%p) stub!\n",pOwner,pGroup,
645 cCountOfAccessEntries,pListOfAccessEntries,cCountOfAuditEntries,
646 pListofAuditEntries,pOldSD,lpdwBufferLength,pNewSD);
648 return ERROR_CALL_NOT_IMPLEMENTED;
651 /******************************************************************************
652 * BuildSecurityDescriptorW [ADVAPI32.@]
654 * See BuildSecurityDescriptorA.
656 DWORD WINAPI BuildSecurityDescriptorW(
657 IN PTRUSTEE_W pOwner,
658 IN PTRUSTEE_W pGroup,
659 IN DWORD cCountOfAccessEntries,
660 IN PEXPLICIT_ACCESS_W pListOfAccessEntries,
661 IN DWORD cCountOfAuditEntries,
662 IN PEXPLICIT_ACCESS_W pListofAuditEntries,
663 IN PSECURITY_DESCRIPTOR pOldSD,
664 IN OUT PDWORD lpdwBufferLength,
665 OUT PSECURITY_DESCRIPTOR pNewSD)
667 FIXME("(%p,%p,%ld,%p,%ld,%p,%p,%p,%p) stub!\n",pOwner,pGroup,
668 cCountOfAccessEntries,pListOfAccessEntries,cCountOfAuditEntries,
669 pListofAuditEntries,pOldSD,lpdwBufferLength,pNewSD);
671 return ERROR_CALL_NOT_IMPLEMENTED;
674 /******************************************************************************
675 * InitializeSecurityDescriptor [ADVAPI32.@]
682 InitializeSecurityDescriptor( PSECURITY_DESCRIPTOR pDescr, DWORD revision )
684 return set_ntstatus( RtlCreateSecurityDescriptor(pDescr, revision ));
688 /******************************************************************************
689 * MakeAbsoluteSD [ADVAPI32.@]
691 BOOL WINAPI MakeAbsoluteSD (
692 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
693 OUT PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
694 OUT LPDWORD lpdwAbsoluteSecurityDescriptorSize,
696 OUT LPDWORD lpdwDaclSize,
698 OUT LPDWORD lpdwSaclSize,
700 OUT LPDWORD lpdwOwnerSize,
701 OUT PSID pPrimaryGroup,
702 OUT LPDWORD lpdwPrimaryGroupSize)
704 return set_ntstatus( RtlSelfRelativeToAbsoluteSD(pSelfRelativeSecurityDescriptor,
705 pAbsoluteSecurityDescriptor,
706 lpdwAbsoluteSecurityDescriptorSize,
707 pDacl, lpdwDaclSize, pSacl, lpdwSaclSize,
708 pOwner, lpdwOwnerSize,
709 pPrimaryGroup, lpdwPrimaryGroupSize));
712 /******************************************************************************
713 * GetKernelObjectSecurity [ADVAPI32.@]
715 BOOL WINAPI GetKernelObjectSecurity(
717 SECURITY_INFORMATION RequestedInformation,
718 PSECURITY_DESCRIPTOR pSecurityDescriptor,
720 LPDWORD lpnLengthNeeded )
722 TRACE("(%p,0x%08lx,%p,0x%08lx,%p)\n", Handle, RequestedInformation,
723 pSecurityDescriptor, nLength, lpnLengthNeeded);
725 return set_ntstatus( NtQuerySecurityObject(Handle, RequestedInformation, pSecurityDescriptor,
726 nLength, lpnLengthNeeded ));
729 /******************************************************************************
730 * GetPrivateObjectSecurity [ADVAPI32.@]
732 BOOL WINAPI GetPrivateObjectSecurity(
733 PSECURITY_DESCRIPTOR ObjectDescriptor,
734 SECURITY_INFORMATION SecurityInformation,
735 PSECURITY_DESCRIPTOR ResultantDescriptor,
736 DWORD DescriptorLength,
737 PDWORD ReturnLength )
739 TRACE("(%p,0x%08lx,%p,0x%08lx,%p)\n", ObjectDescriptor, SecurityInformation,
740 ResultantDescriptor, DescriptorLength, ReturnLength);
742 return set_ntstatus( NtQuerySecurityObject(ObjectDescriptor, SecurityInformation,
743 ResultantDescriptor, DescriptorLength, ReturnLength ));
746 /******************************************************************************
747 * GetSecurityDescriptorLength [ADVAPI32.@]
749 DWORD WINAPI GetSecurityDescriptorLength( PSECURITY_DESCRIPTOR pDescr)
751 return RtlLengthSecurityDescriptor(pDescr);
754 /******************************************************************************
755 * GetSecurityDescriptorOwner [ADVAPI32.@]
759 * lpbOwnerDefaulted []
762 GetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pDescr, PSID *pOwner,
763 LPBOOL lpbOwnerDefaulted )
766 BOOL ret = set_ntstatus( RtlGetOwnerSecurityDescriptor( pDescr, pOwner, &defaulted ));
767 *lpbOwnerDefaulted = defaulted;
771 /******************************************************************************
772 * SetSecurityDescriptorOwner [ADVAPI32.@]
776 BOOL WINAPI SetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pSecurityDescriptor,
777 PSID pOwner, BOOL bOwnerDefaulted)
779 return set_ntstatus( RtlSetOwnerSecurityDescriptor(pSecurityDescriptor, pOwner, bOwnerDefaulted));
781 /******************************************************************************
782 * GetSecurityDescriptorGroup [ADVAPI32.@]
784 BOOL WINAPI GetSecurityDescriptorGroup(
785 PSECURITY_DESCRIPTOR SecurityDescriptor,
787 LPBOOL GroupDefaulted)
790 BOOL ret = set_ntstatus( RtlGetGroupSecurityDescriptor(SecurityDescriptor, Group, &defaulted ));
791 *GroupDefaulted = defaulted;
794 /******************************************************************************
795 * SetSecurityDescriptorGroup [ADVAPI32.@]
797 BOOL WINAPI SetSecurityDescriptorGroup ( PSECURITY_DESCRIPTOR SecurityDescriptor,
798 PSID Group, BOOL GroupDefaulted)
800 return set_ntstatus( RtlSetGroupSecurityDescriptor( SecurityDescriptor, Group, GroupDefaulted));
803 /******************************************************************************
804 * IsValidSecurityDescriptor [ADVAPI32.@]
810 IsValidSecurityDescriptor( PSECURITY_DESCRIPTOR SecurityDescriptor )
812 return set_ntstatus( RtlValidSecurityDescriptor(SecurityDescriptor));
815 /******************************************************************************
816 * GetSecurityDescriptorDacl [ADVAPI32.@]
818 BOOL WINAPI GetSecurityDescriptorDacl(
819 IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
820 OUT LPBOOL lpbDaclPresent,
822 OUT LPBOOL lpbDaclDefaulted)
824 BOOLEAN present, defaulted;
825 BOOL ret = set_ntstatus( RtlGetDaclSecurityDescriptor(pSecurityDescriptor, &present, pDacl, &defaulted));
826 *lpbDaclPresent = present;
827 *lpbDaclDefaulted = defaulted;
831 /******************************************************************************
832 * SetSecurityDescriptorDacl [ADVAPI32.@]
835 SetSecurityDescriptorDacl (
836 PSECURITY_DESCRIPTOR lpsd,
841 return set_ntstatus( RtlSetDaclSecurityDescriptor (lpsd, daclpresent, dacl, dacldefaulted ) );
843 /******************************************************************************
844 * GetSecurityDescriptorSacl [ADVAPI32.@]
846 BOOL WINAPI GetSecurityDescriptorSacl(
847 IN PSECURITY_DESCRIPTOR lpsd,
848 OUT LPBOOL lpbSaclPresent,
850 OUT LPBOOL lpbSaclDefaulted)
852 BOOLEAN present, defaulted;
853 BOOL ret = set_ntstatus( RtlGetSaclSecurityDescriptor(lpsd, &present, pSacl, &defaulted) );
854 *lpbSaclPresent = present;
855 *lpbSaclDefaulted = defaulted;
859 /**************************************************************************
860 * SetSecurityDescriptorSacl [ADVAPI32.@]
862 BOOL WINAPI SetSecurityDescriptorSacl (
863 PSECURITY_DESCRIPTOR lpsd,
868 return set_ntstatus (RtlSetSaclSecurityDescriptor(lpsd, saclpresent, lpsacl, sacldefaulted));
870 /******************************************************************************
871 * MakeSelfRelativeSD [ADVAPI32.@]
880 IN PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
881 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
882 IN OUT LPDWORD lpdwBufferLength)
884 return set_ntstatus( RtlMakeSelfRelativeSD( pAbsoluteSecurityDescriptor,
885 pSelfRelativeSecurityDescriptor, lpdwBufferLength));
888 /******************************************************************************
889 * GetSecurityDescriptorControl [ADVAPI32.@]
892 BOOL WINAPI GetSecurityDescriptorControl ( PSECURITY_DESCRIPTOR pSecurityDescriptor,
893 PSECURITY_DESCRIPTOR_CONTROL pControl, LPDWORD lpdwRevision)
895 return set_ntstatus( RtlGetControlSecurityDescriptor(pSecurityDescriptor,pControl,lpdwRevision));
898 /* ##############################
899 ###### ACL FUNCTIONS ######
900 ##############################
903 /*************************************************************************
904 * InitializeAcl [ADVAPI32.@]
906 BOOL WINAPI InitializeAcl(PACL acl, DWORD size, DWORD rev)
908 return set_ntstatus( RtlCreateAcl(acl, size, rev));
911 BOOL WINAPI ImpersonateNamedPipeClient( HANDLE hNamedPipe )
913 TRACE("(%p)\n", hNamedPipe);
915 return set_ntstatus( NtFsControlFile(hNamedPipe, NULL, NULL, NULL, NULL,
916 FSCTL_PIPE_IMPERSONATE, NULL, 0, NULL, 0) );
919 /******************************************************************************
920 * AddAccessAllowedAce [ADVAPI32.@]
922 BOOL WINAPI AddAccessAllowedAce(
924 IN DWORD dwAceRevision,
928 return set_ntstatus(RtlAddAccessAllowedAce(pAcl, dwAceRevision, AccessMask, pSid));
931 /******************************************************************************
932 * AddAccessAllowedAceEx [ADVAPI32.@]
934 BOOL WINAPI AddAccessAllowedAceEx(
936 IN DWORD dwAceRevision,
941 return set_ntstatus(RtlAddAccessAllowedAceEx(pAcl, dwAceRevision, AceFlags, AccessMask, pSid));
944 /******************************************************************************
945 * AddAccessDeniedAce [ADVAPI32.@]
947 BOOL WINAPI AddAccessDeniedAce(
949 IN DWORD dwAceRevision,
953 return set_ntstatus(RtlAddAccessDeniedAce(pAcl, dwAceRevision, AccessMask, pSid));
956 /******************************************************************************
957 * AddAccessDeniedAceEx [ADVAPI32.@]
959 BOOL WINAPI AddAccessDeniedAceEx(
961 IN DWORD dwAceRevision,
966 return set_ntstatus(RtlAddAccessDeniedAceEx(pAcl, dwAceRevision, AceFlags, AccessMask, pSid));
969 /******************************************************************************
970 * AddAce [ADVAPI32.@]
974 IN DWORD dwAceRevision,
975 IN DWORD dwStartingAceIndex,
977 DWORD nAceListLength)
979 return set_ntstatus(RtlAddAce(pAcl, dwAceRevision, dwStartingAceIndex, pAceList, nAceListLength));
982 /******************************************************************************
983 * DeleteAce [ADVAPI32.@]
985 BOOL WINAPI DeleteAce(PACL pAcl, DWORD dwAceIndex)
987 return set_ntstatus(RtlDeleteAce(pAcl, dwAceIndex));
990 /******************************************************************************
991 * FindFirstFreeAce [ADVAPI32.@]
993 BOOL WINAPI FindFirstFreeAce(IN PACL pAcl, LPVOID * pAce)
995 return RtlFirstFreeAce(pAcl, (PACE_HEADER *)pAce);
998 /******************************************************************************
999 * GetAce [ADVAPI32.@]
1001 BOOL WINAPI GetAce(PACL pAcl,DWORD dwAceIndex,LPVOID *pAce )
1003 return set_ntstatus(RtlGetAce(pAcl, dwAceIndex, pAce));
1006 /******************************************************************************
1007 * GetAclInformation [ADVAPI32.@]
1009 BOOL WINAPI GetAclInformation(
1011 LPVOID pAclInformation,
1012 DWORD nAclInformationLength,
1013 ACL_INFORMATION_CLASS dwAclInformationClass)
1015 return set_ntstatus(RtlQueryInformationAcl(pAcl, pAclInformation,
1016 nAclInformationLength, dwAclInformationClass));
1019 /******************************************************************************
1020 * IsValidAcl [ADVAPI32.@]
1022 BOOL WINAPI IsValidAcl(IN PACL pAcl)
1024 return RtlValidAcl(pAcl);
1027 /* ##############################
1028 ###### MISC FUNCTIONS ######
1029 ##############################
1032 /******************************************************************************
1033 * AllocateLocallyUniqueId [ADVAPI32.@]
1038 BOOL WINAPI AllocateLocallyUniqueId( PLUID lpLuid )
1040 return set_ntstatus(NtAllocateLocallyUniqueId(lpLuid));
1043 static const WCHAR SE_CREATE_TOKEN_NAME_W[] =
1044 { 'S','e','C','r','e','a','t','e','T','o','k','e','n','P','r','i','v','i','l','e','g','e',0 };
1045 static const WCHAR SE_ASSIGNPRIMARYTOKEN_NAME_W[] =
1046 { '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 };
1047 static const WCHAR SE_LOCK_MEMORY_NAME_W[] =
1048 { 'S','e','L','o','c','k','M','e','m','o','r','y','P','r','i','v','i','l','e','g','e',0 };
1049 static const WCHAR SE_INCREASE_QUOTA_NAME_W[] =
1050 { '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 };
1051 static const WCHAR SE_MACHINE_ACCOUNT_NAME_W[] =
1052 { '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 };
1053 static const WCHAR SE_TCB_NAME_W[] =
1054 { 'S','e','T','c','b','P','r','i','v','i','l','e','g','e',0 };
1055 static const WCHAR SE_SECURITY_NAME_W[] =
1056 { 'S','e','S','e','c','u','r','i','t','y','P','r','i','v','i','l','e','g','e',0 };
1057 static const WCHAR SE_TAKE_OWNERSHIP_NAME_W[] =
1058 { '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 };
1059 static const WCHAR SE_LOAD_DRIVER_NAME_W[] =
1060 { 'S','e','L','o','a','d','D','r','i','v','e','r','P','r','i','v','i','l','e','g','e',0 };
1061 static const WCHAR SE_SYSTEM_PROFILE_NAME_W[] =
1062 { '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 };
1063 static const WCHAR SE_SYSTEMTIME_NAME_W[] =
1064 { 'S','e','S','y','s','t','e','m','t','i','m','e','P','r','i','v','i','l','e','g','e',0 };
1065 static const WCHAR SE_PROF_SINGLE_PROCESS_NAME_W[] =
1066 { '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 };
1067 static const WCHAR SE_INC_BASE_PRIORITY_NAME_W[] =
1068 { '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 };
1069 static const WCHAR SE_CREATE_PAGEFILE_NAME_W[] =
1070 { '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 };
1071 static const WCHAR SE_CREATE_PERMANENT_NAME_W[] =
1072 { '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 };
1073 static const WCHAR SE_BACKUP_NAME_W[] =
1074 { 'S','e','B','a','c','k','u','p','P','r','i','v','i','l','e','g','e',0 };
1075 static const WCHAR SE_RESTORE_NAME_W[] =
1076 { 'S','e','R','e','s','t','o','r','e','P','r','i','v','i','l','e','g','e',0 };
1077 static const WCHAR SE_SHUTDOWN_NAME_W[] =
1078 { 'S','e','S','h','u','t','d','o','w','n','P','r','i','v','i','l','e','g','e',0 };
1079 static const WCHAR SE_DEBUG_NAME_W[] =
1080 { 'S','e','D','e','b','u','g','P','r','i','v','i','l','e','g','e',0 };
1081 static const WCHAR SE_AUDIT_NAME_W[] =
1082 { 'S','e','A','u','d','i','t','P','r','i','v','i','l','e','g','e',0 };
1083 static const WCHAR SE_SYSTEM_ENVIRONMENT_NAME_W[] =
1084 { '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 };
1085 static const WCHAR SE_CHANGE_NOTIFY_NAME_W[] =
1086 { 'S','e','C','h','a','n','g','e','N','o','t','i','f','y','P','r','i','v','i','l','e','g','e',0 };
1087 static const WCHAR SE_REMOTE_SHUTDOWN_NAME_W[] =
1088 { '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 };
1089 static const WCHAR SE_UNDOCK_NAME_W[] =
1090 { 'S','e','U','n','d','o','c','k','P','r','i','v','i','l','e','g','e',0 };
1091 static const WCHAR SE_SYNC_AGENT_NAME_W[] =
1092 { 'S','e','S','y','n','c','A','g','e','n','t','P','r','i','v','i','l','e','g','e',0 };
1093 static const WCHAR SE_ENABLE_DELEGATION_NAME_W[] =
1094 { '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 };
1095 static const WCHAR SE_MANAGE_VOLUME_NAME_W[] =
1096 { 'S','e','M','a','n','a','g','e','V','o','l','u','m','e','P','r','i','v','i','l','e','g','e',0 };
1097 static const WCHAR SE_IMPERSONATE_NAME_W[] =
1098 { 'S','e','I','m','p','e','r','s','o','n','a','t','e','P','r','i','v','i','l','e','g','e',0 };
1099 static const WCHAR SE_CREATE_GLOBAL_NAME_W[] =
1100 { 'S','e','C','r','e','a','t','e','G','l','o','b','a','l','P','r','i','v','i','l','e','g','e',0 };
1102 static const WCHAR * const WellKnownPrivNames[SE_MAX_WELL_KNOWN_PRIVILEGE + 1] =
1106 SE_CREATE_TOKEN_NAME_W,
1107 SE_ASSIGNPRIMARYTOKEN_NAME_W,
1108 SE_LOCK_MEMORY_NAME_W,
1109 SE_INCREASE_QUOTA_NAME_W,
1110 SE_MACHINE_ACCOUNT_NAME_W,
1113 SE_TAKE_OWNERSHIP_NAME_W,
1114 SE_LOAD_DRIVER_NAME_W,
1115 SE_SYSTEM_PROFILE_NAME_W,
1116 SE_SYSTEMTIME_NAME_W,
1117 SE_PROF_SINGLE_PROCESS_NAME_W,
1118 SE_INC_BASE_PRIORITY_NAME_W,
1119 SE_CREATE_PAGEFILE_NAME_W,
1120 SE_CREATE_PERMANENT_NAME_W,
1126 SE_SYSTEM_ENVIRONMENT_NAME_W,
1127 SE_CHANGE_NOTIFY_NAME_W,
1128 SE_REMOTE_SHUTDOWN_NAME_W,
1130 SE_SYNC_AGENT_NAME_W,
1131 SE_ENABLE_DELEGATION_NAME_W,
1132 SE_MANAGE_VOLUME_NAME_W,
1133 SE_IMPERSONATE_NAME_W,
1134 SE_CREATE_GLOBAL_NAME_W,
1137 /******************************************************************************
1138 * LookupPrivilegeValueW [ADVAPI32.@]
1140 * See LookupPrivilegeValueA.
1143 LookupPrivilegeValueW( LPCWSTR lpSystemName, LPCWSTR lpName, PLUID lpLuid )
1147 TRACE("%s,%s,%p\n",debugstr_w(lpSystemName), debugstr_w(lpName), lpLuid);
1149 if (!ADVAPI_IsLocalComputer(lpSystemName))
1151 SetLastError(RPC_S_SERVER_UNAVAILABLE);
1156 SetLastError(ERROR_NO_SUCH_PRIVILEGE);
1159 for( i=SE_MIN_WELL_KNOWN_PRIVILEGE; i<SE_MAX_WELL_KNOWN_PRIVILEGE; i++ )
1161 if( !WellKnownPrivNames[i] )
1163 if( strcmpiW( WellKnownPrivNames[i], lpName) )
1165 lpLuid->LowPart = i;
1166 lpLuid->HighPart = 0;
1167 TRACE( "%s -> %08lx-%08lx\n",debugstr_w( lpSystemName ),
1168 lpLuid->HighPart, lpLuid->LowPart );
1171 SetLastError(ERROR_NO_SUCH_PRIVILEGE);
1175 /******************************************************************************
1176 * LookupPrivilegeValueA [ADVAPI32.@]
1178 * Retrieves LUID used on a system to represent the privilege name.
1181 * lpSystemName [I] Name of the system
1182 * lpName [I] Name of the privilege
1183 * lpLuid [O] Destination for the resulting LUID
1186 * Success: TRUE. lpLuid contains the requested LUID.
1190 LookupPrivilegeValueA( LPCSTR lpSystemName, LPCSTR lpName, PLUID lpLuid )
1192 UNICODE_STRING lpSystemNameW;
1193 UNICODE_STRING lpNameW;
1196 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW, lpSystemName);
1197 RtlCreateUnicodeStringFromAsciiz(&lpNameW,lpName);
1198 ret = LookupPrivilegeValueW(lpSystemNameW.Buffer, lpNameW.Buffer, lpLuid);
1199 RtlFreeUnicodeString(&lpNameW);
1200 RtlFreeUnicodeString(&lpSystemNameW);
1204 BOOL WINAPI LookupPrivilegeDisplayNameA( LPCSTR lpSystemName, LPCSTR lpName, LPSTR lpDisplayName,
1205 LPDWORD cchDisplayName, LPDWORD lpLanguageId )
1207 FIXME("%s %s %s %p %p - stub\n", debugstr_a(lpSystemName), debugstr_a(lpName),
1208 debugstr_a(lpDisplayName), cchDisplayName, lpLanguageId);
1213 BOOL WINAPI LookupPrivilegeDisplayNameW( LPCWSTR lpSystemName, LPCWSTR lpName, LPWSTR lpDisplayName,
1214 LPDWORD cchDisplayName, LPDWORD lpLanguageId )
1216 FIXME("%s %s %s %p %p - stub\n", debugstr_w(lpSystemName), debugstr_w(lpName),
1217 debugstr_w(lpDisplayName), cchDisplayName, lpLanguageId);
1222 /******************************************************************************
1223 * LookupPrivilegeNameA [ADVAPI32.@]
1225 * See LookupPrivilegeNameW
1228 LookupPrivilegeNameA( LPCSTR lpSystemName, PLUID lpLuid, LPSTR lpName,
1231 UNICODE_STRING lpSystemNameW;
1235 TRACE("%s %p %p %p\n", debugstr_a(lpSystemName), lpLuid, lpName, cchName);
1237 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW, lpSystemName);
1238 ret = LookupPrivilegeNameW(lpSystemNameW.Buffer, lpLuid, NULL, &wLen);
1239 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
1241 LPWSTR lpNameW = HeapAlloc(GetProcessHeap(), 0, wLen * sizeof(WCHAR));
1243 ret = LookupPrivilegeNameW(lpSystemNameW.Buffer, lpLuid, lpNameW,
1247 /* Windows crashes if cchName is NULL, so will I */
1248 int len = WideCharToMultiByte(CP_ACP, 0, lpNameW, -1, lpName,
1249 *cchName, NULL, NULL);
1253 /* WideCharToMultiByte failed */
1256 else if (len > *cchName)
1259 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1264 /* WideCharToMultiByte succeeded, output length needs to be
1265 * length not including NULL terminator
1270 HeapFree(GetProcessHeap(), 0, lpNameW);
1272 RtlFreeUnicodeString(&lpSystemNameW);
1276 /******************************************************************************
1277 * LookupPrivilegeNameW [ADVAPI32.@]
1279 * Retrieves the privilege name referred to by the LUID lpLuid.
1282 * lpSystemName [I] Name of the system
1283 * lpLuid [I] Privilege value
1284 * lpName [O] Name of the privilege
1285 * cchName [I/O] Number of characters in lpName.
1288 * Success: TRUE. lpName contains the name of the privilege whose value is
1293 * Only well-known privilege names (those defined in winnt.h) can be retrieved
1294 * using this function.
1295 * If the length of lpName is too small, on return *cchName will contain the
1296 * number of WCHARs needed to contain the privilege, including the NULL
1297 * terminator, and GetLastError will return ERROR_INSUFFICIENT_BUFFER.
1298 * On success, *cchName will contain the number of characters stored in
1299 * lpName, NOT including the NULL terminator.
1302 LookupPrivilegeNameW( LPCWSTR lpSystemName, PLUID lpLuid, LPWSTR lpName,
1307 TRACE("%s,%p,%p,%p\n",debugstr_w(lpSystemName), lpLuid, lpName, cchName);
1309 if (!ADVAPI_IsLocalComputer(lpSystemName))
1311 SetLastError(RPC_S_SERVER_UNAVAILABLE);
1314 if (lpLuid->HighPart || (lpLuid->LowPart < SE_MIN_WELL_KNOWN_PRIVILEGE ||
1315 lpLuid->LowPart > SE_MAX_WELL_KNOWN_PRIVILEGE))
1317 SetLastError(ERROR_NO_SUCH_PRIVILEGE);
1320 privNameLen = strlenW(WellKnownPrivNames[lpLuid->LowPart]);
1321 /* Windows crashes if cchName is NULL, so will I */
1322 if (*cchName <= privNameLen)
1324 *cchName = privNameLen + 1;
1325 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1330 strcpyW(lpName, WellKnownPrivNames[lpLuid->LowPart]);
1331 *cchName = privNameLen;
1336 /******************************************************************************
1337 * GetFileSecurityA [ADVAPI32.@]
1339 * Obtains Specified information about the security of a file or directory.
1342 * lpFileName [I] Name of the file to get info for
1343 * RequestedInformation [I] SE_ flags from "winnt.h"
1344 * pSecurityDescriptor [O] Destination for security information
1345 * nLength [I] Length of pSecurityDescriptor
1346 * lpnLengthNeeded [O] Destination for length of returned security information
1349 * Success: TRUE. pSecurityDescriptor contains the requested information.
1350 * Failure: FALSE. lpnLengthNeeded contains the required space to return the info.
1353 * The information returned is constrained by the callers access rights and
1357 GetFileSecurityA( LPCSTR lpFileName,
1358 SECURITY_INFORMATION RequestedInformation,
1359 PSECURITY_DESCRIPTOR pSecurityDescriptor,
1360 DWORD nLength, LPDWORD lpnLengthNeeded )
1368 len = MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, NULL, 0 );
1369 name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
1370 MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, name, len );
1373 r = GetFileSecurityW( name, RequestedInformation, pSecurityDescriptor,
1374 nLength, lpnLengthNeeded );
1375 HeapFree( GetProcessHeap(), 0, name );
1380 /******************************************************************************
1381 * GetFileSecurityW [ADVAPI32.@]
1383 * See GetFileSecurityA.
1386 GetFileSecurityW( LPCWSTR lpFileName,
1387 SECURITY_INFORMATION RequestedInformation,
1388 PSECURITY_DESCRIPTOR pSecurityDescriptor,
1389 DWORD nLength, LPDWORD lpnLengthNeeded )
1394 SECURITY_DESCRIPTOR_RELATIVE *pSDRelative;
1396 if(INVALID_FILE_ATTRIBUTES == GetFileAttributesW(lpFileName))
1399 FIXME("(%s) : returns fake SECURITY_DESCRIPTOR\n", debugstr_w(lpFileName) );
1401 nNeeded = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
1402 if (RequestedInformation & OWNER_SECURITY_INFORMATION)
1403 nNeeded += sizeof(sidWorld);
1404 if (RequestedInformation & GROUP_SECURITY_INFORMATION)
1405 nNeeded += sizeof(sidWorld);
1406 if (RequestedInformation & DACL_SECURITY_INFORMATION)
1407 nNeeded += WINE_SIZE_OF_WORLD_ACCESS_ACL;
1408 if (RequestedInformation & SACL_SECURITY_INFORMATION)
1409 nNeeded += WINE_SIZE_OF_WORLD_ACCESS_ACL;
1411 *lpnLengthNeeded = nNeeded;
1413 if (nNeeded > nLength)
1416 if (!InitializeSecurityDescriptor(pSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION))
1419 pSDRelative = (PISECURITY_DESCRIPTOR_RELATIVE) pSecurityDescriptor;
1420 pSDRelative->Control |= SE_SELF_RELATIVE;
1421 pBuffer = (LPBYTE) pSDRelative;
1422 iLocNow = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
1424 if (RequestedInformation & OWNER_SECURITY_INFORMATION)
1426 memcpy(pBuffer + iLocNow, &sidWorld, sizeof(sidWorld));
1427 pSDRelative->Owner = iLocNow;
1428 iLocNow += sizeof(sidWorld);
1430 if (RequestedInformation & GROUP_SECURITY_INFORMATION)
1432 memcpy(pBuffer + iLocNow, &sidWorld, sizeof(sidWorld));
1433 pSDRelative->Group = iLocNow;
1434 iLocNow += sizeof(sidWorld);
1436 if (RequestedInformation & DACL_SECURITY_INFORMATION)
1438 GetWorldAccessACL((PACL) (pBuffer + iLocNow));
1439 pSDRelative->Dacl = iLocNow;
1440 iLocNow += WINE_SIZE_OF_WORLD_ACCESS_ACL;
1442 if (RequestedInformation & SACL_SECURITY_INFORMATION)
1444 GetWorldAccessACL((PACL) (pBuffer + iLocNow));
1445 pSDRelative->Sacl = iLocNow;
1446 /* iLocNow += WINE_SIZE_OF_WORLD_ACCESS_ACL; */
1452 /******************************************************************************
1453 * LookupAccountSidA [ADVAPI32.@]
1460 IN OUT LPDWORD accountSize,
1462 IN OUT LPDWORD domainSize,
1463 OUT PSID_NAME_USE name_use )
1465 static const char ac[] = "Administrator";
1466 static const char dm[] = "DOMAIN";
1467 FIXME("(%s,sid=%p,%p,%p(%lu),%p,%p(%lu),%p): semi-stub\n",
1468 debugstr_a(system),sid,
1469 account,accountSize,accountSize?*accountSize:0,
1470 domain,domainSize,domainSize?*domainSize:0,
1473 if (accountSize) *accountSize = strlen(ac)+1;
1474 if (account && (*accountSize > strlen(ac)))
1475 strcpy(account, ac);
1477 if (domainSize) *domainSize = strlen(dm)+1;
1478 if (domain && (*domainSize > strlen(dm)))
1481 if (name_use) *name_use = SidTypeUser;
1485 /******************************************************************************
1486 * LookupAccountSidW [ADVAPI32.@]
1502 IN OUT LPDWORD accountSize,
1504 IN OUT LPDWORD domainSize,
1505 OUT PSID_NAME_USE name_use )
1507 static const WCHAR ac[] = {'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
1508 static const WCHAR dm[] = {'D','O','M','A','I','N',0};
1509 FIXME("(%s,sid=%p,%p,%p(%lu),%p,%p(%lu),%p): semi-stub\n",
1510 debugstr_w(system),sid,
1511 account,accountSize,accountSize?*accountSize:0,
1512 domain,domainSize,domainSize?*domainSize:0,
1515 if (accountSize) *accountSize = strlenW(ac)+1;
1516 if (account && (*accountSize > strlenW(ac)))
1517 strcpyW(account, ac);
1519 if (domainSize) *domainSize = strlenW(dm)+1;
1520 if (domain && (*domainSize > strlenW(dm)))
1523 if (name_use) *name_use = SidTypeUser;
1527 /******************************************************************************
1528 * SetFileSecurityA [ADVAPI32.@]
1529 * Sets the security of a file or directory
1531 BOOL WINAPI SetFileSecurityA( LPCSTR lpFileName,
1532 SECURITY_INFORMATION RequestedInformation,
1533 PSECURITY_DESCRIPTOR pSecurityDescriptor)
1541 len = MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, NULL, 0 );
1542 name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
1543 MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, name, len );
1546 r = SetFileSecurityW( name, RequestedInformation, pSecurityDescriptor );
1547 HeapFree( GetProcessHeap(), 0, name );
1552 /******************************************************************************
1553 * SetFileSecurityW [ADVAPI32.@]
1554 * Sets the security of a file or directory
1558 * RequestedInformation []
1559 * pSecurityDescriptor []
1562 SetFileSecurityW( LPCWSTR lpFileName,
1563 SECURITY_INFORMATION RequestedInformation,
1564 PSECURITY_DESCRIPTOR pSecurityDescriptor )
1566 FIXME("(%s) : stub\n", debugstr_w(lpFileName) );
1570 /******************************************************************************
1571 * QueryWindows31FilesMigration [ADVAPI32.@]
1577 QueryWindows31FilesMigration( DWORD x1 )
1579 FIXME("(%ld):stub\n",x1);
1583 /******************************************************************************
1584 * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.@]
1593 SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1, DWORD x2, DWORD x3,
1596 FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx):stub\n",x1,x2,x3,x4);
1600 /******************************************************************************
1601 * NotifyBootConfigStatus [ADVAPI32.@]
1607 NotifyBootConfigStatus( DWORD x1 )
1609 FIXME("(0x%08lx):stub\n",x1);
1613 /******************************************************************************
1614 * RevertToSelf [ADVAPI32.@]
1616 * Ends the impersonation of a user.
1626 RevertToSelf( void )
1628 HANDLE Token = NULL;
1629 return set_ntstatus( NtSetInformationThread( GetCurrentThread(),
1630 ThreadImpersonationToken, &Token, sizeof(Token) ) );
1633 /******************************************************************************
1634 * ImpersonateSelf [ADVAPI32.@]
1636 * Makes an impersonation token that represents the process user and assigns
1637 * to the current thread.
1640 * ImpersonationLevel [I] Level at which to impersonate.
1647 ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
1649 return set_ntstatus( RtlImpersonateSelf( ImpersonationLevel ) );
1652 /******************************************************************************
1653 * ImpersonateLoggedOnUser [ADVAPI32.@]
1655 BOOL WINAPI ImpersonateLoggedOnUser(HANDLE hToken)
1657 FIXME("(%p):stub returning FALSE\n", hToken);
1661 /******************************************************************************
1662 * AccessCheck [ADVAPI32.@]
1666 PSECURITY_DESCRIPTOR SecurityDescriptor,
1668 DWORD DesiredAccess,
1669 PGENERIC_MAPPING GenericMapping,
1670 PPRIVILEGE_SET PrivilegeSet,
1671 LPDWORD PrivilegeSetLength,
1672 LPDWORD GrantedAccess,
1673 LPBOOL AccessStatus)
1675 NTSTATUS access_status;
1676 BOOL ret = set_ntstatus( NtAccessCheck(SecurityDescriptor, ClientToken, DesiredAccess,
1677 GenericMapping, PrivilegeSet, PrivilegeSetLength,
1678 GrantedAccess, &access_status) );
1679 if (ret) *AccessStatus = set_ntstatus( access_status );
1684 /******************************************************************************
1685 * AccessCheckByType [ADVAPI32.@]
1687 BOOL WINAPI AccessCheckByType(
1688 PSECURITY_DESCRIPTOR pSecurityDescriptor,
1689 PSID PrincipalSelfSid,
1691 DWORD DesiredAccess,
1692 POBJECT_TYPE_LIST ObjectTypeList,
1693 DWORD ObjectTypeListLength,
1694 PGENERIC_MAPPING GenericMapping,
1695 PPRIVILEGE_SET PrivilegeSet,
1696 LPDWORD PrivilegeSetLength,
1697 LPDWORD GrantedAccess,
1698 LPBOOL AccessStatus)
1702 *AccessStatus = TRUE;
1704 return !*AccessStatus;
1707 /******************************************************************************
1708 * MapGenericMask [ADVAPI32.@]
1710 * Maps generic access rights into specific access rights according to the
1714 * AccessMask [I/O] Access rights.
1715 * GenericMapping [I] The mapping between generic and specific rights.
1720 VOID WINAPI MapGenericMask( PDWORD AccessMask, PGENERIC_MAPPING GenericMapping )
1722 RtlMapGenericMask( AccessMask, GenericMapping );
1725 /*************************************************************************
1726 * SetKernelObjectSecurity [ADVAPI32.@]
1728 BOOL WINAPI SetKernelObjectSecurity (
1730 IN SECURITY_INFORMATION SecurityInformation,
1731 IN PSECURITY_DESCRIPTOR SecurityDescriptor )
1733 return set_ntstatus (NtSetSecurityObject (Handle, SecurityInformation, SecurityDescriptor));
1737 /******************************************************************************
1738 * AddAuditAccessAce [ADVAPI32.@]
1740 BOOL WINAPI AddAuditAccessAce(
1742 IN DWORD dwAceRevision,
1743 IN DWORD dwAccessMask,
1745 IN BOOL bAuditSuccess,
1746 IN BOOL bAuditFailure)
1748 return set_ntstatus( RtlAddAuditAccessAce(pAcl, dwAceRevision, dwAccessMask, pSid,
1749 bAuditSuccess, bAuditFailure) );
1752 /******************************************************************************
1753 * LookupAccountNameA [ADVAPI32.@]
1761 LPSTR ReferencedDomainName,
1762 IN OUT LPDWORD cbReferencedDomainName,
1763 OUT PSID_NAME_USE name_use )
1765 /* Default implementation: Always return a default SID */
1766 SID_IDENTIFIER_AUTHORITY identifierAuthority = {SECURITY_NT_AUTHORITY};
1769 static const char dm[] = "DOMAIN";
1771 FIXME("(%s,%s,%p,%p,%p,%p,%p), stub.\n",system,account,sid,cbSid,ReferencedDomainName,cbReferencedDomainName,name_use);
1773 ret = AllocateAndInitializeSid(&identifierAuthority,
1775 SECURITY_BUILTIN_DOMAIN_RID,
1776 DOMAIN_ALIAS_RID_ADMINS,
1782 if(!RtlValidSid(pSid))
1788 if (sid != NULL && (*cbSid >= GetLengthSid(pSid)))
1789 CopySid(*cbSid, sid, pSid);
1790 if (*cbSid < GetLengthSid(pSid))
1792 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1795 *cbSid = GetLengthSid(pSid);
1797 if (ReferencedDomainName != NULL && (*cbReferencedDomainName > strlen(dm)))
1798 strcpy(ReferencedDomainName, dm);
1799 if (*cbReferencedDomainName <= strlen(dm))
1801 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1804 *cbReferencedDomainName = strlen(dm)+1;
1811 /******************************************************************************
1812 * LookupAccountNameW [ADVAPI32.@]
1814 BOOL WINAPI LookupAccountNameW( LPCWSTR lpSystemName, LPCWSTR lpAccountName, PSID Sid,
1815 LPDWORD cbSid, LPWSTR ReferencedDomainName,
1816 LPDWORD cchReferencedDomainName, PSID_NAME_USE peUse )
1818 FIXME("%s %s %p %p %p %p %p - stub\n", debugstr_w(lpSystemName), debugstr_w(lpAccountName),
1819 Sid, cbSid, ReferencedDomainName, cchReferencedDomainName, peUse);
1824 /******************************************************************************
1825 * PrivilegeCheck [ADVAPI32.@]
1827 BOOL WINAPI PrivilegeCheck( HANDLE ClientToken, PPRIVILEGE_SET RequiredPrivileges, LPBOOL pfResult)
1832 TRACE("%p %p %p\n", ClientToken, RequiredPrivileges, pfResult);
1834 ret = set_ntstatus (NtPrivilegeCheck (ClientToken, RequiredPrivileges, &Result));
1840 /******************************************************************************
1841 * AccessCheckAndAuditAlarmA [ADVAPI32.@]
1843 BOOL WINAPI AccessCheckAndAuditAlarmA(LPCSTR Subsystem, LPVOID HandleId, LPSTR ObjectTypeName,
1844 LPSTR ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD DesiredAccess,
1845 PGENERIC_MAPPING GenericMapping, BOOL ObjectCreation, LPDWORD GrantedAccess,
1846 LPBOOL AccessStatus, LPBOOL pfGenerateOnClose)
1848 FIXME("stub (%s,%p,%s,%s,%p,%08lx,%p,%x,%p,%p,%p)\n", debugstr_a(Subsystem),
1849 HandleId, debugstr_a(ObjectTypeName), debugstr_a(ObjectName),
1850 SecurityDescriptor, DesiredAccess, GenericMapping,
1851 ObjectCreation, GrantedAccess, AccessStatus, pfGenerateOnClose);
1855 /******************************************************************************
1856 * AccessCheckAndAuditAlarmW [ADVAPI32.@]
1858 BOOL WINAPI AccessCheckAndAuditAlarmW(LPCWSTR Subsystem, LPVOID HandleId, LPWSTR ObjectTypeName,
1859 LPWSTR ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD DesiredAccess,
1860 PGENERIC_MAPPING GenericMapping, BOOL ObjectCreation, LPDWORD GrantedAccess,
1861 LPBOOL AccessStatus, LPBOOL pfGenerateOnClose)
1863 FIXME("stub (%s,%p,%s,%s,%p,%08lx,%p,%x,%p,%p,%p)\n", debugstr_w(Subsystem),
1864 HandleId, debugstr_w(ObjectTypeName), debugstr_w(ObjectName),
1865 SecurityDescriptor, DesiredAccess, GenericMapping,
1866 ObjectCreation, GrantedAccess, AccessStatus, pfGenerateOnClose);
1870 BOOL WINAPI ObjectCloseAuditAlarmA(LPCSTR SubsystemName, LPVOID HandleId, BOOL GenerateOnClose)
1872 FIXME("stub (%s,%p,%x)\n", debugstr_a(SubsystemName), HandleId, GenerateOnClose);
1877 BOOL WINAPI ObjectCloseAuditAlarmW(LPCWSTR SubsystemName, LPVOID HandleId, BOOL GenerateOnClose)
1879 FIXME("stub (%s,%p,%x)\n", debugstr_w(SubsystemName), HandleId, GenerateOnClose);
1884 BOOL WINAPI ObjectOpenAuditAlarmA(LPCSTR SubsystemName, LPVOID HandleId, LPSTR ObjectTypeName,
1885 LPSTR ObjectName, PSECURITY_DESCRIPTOR pSecurityDescriptor, HANDLE ClientToken, DWORD DesiredAccess,
1886 DWORD GrantedAccess, PPRIVILEGE_SET Privileges, BOOL ObjectCreation, BOOL AccessGranted,
1887 LPBOOL GenerateOnClose)
1889 FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08lx,0x%08lx,%p,%x,%x,%p)\n", debugstr_a(SubsystemName),
1890 HandleId, debugstr_a(ObjectTypeName), debugstr_a(ObjectName), pSecurityDescriptor,
1891 ClientToken, DesiredAccess, GrantedAccess, Privileges, ObjectCreation, AccessGranted,
1897 BOOL WINAPI ObjectOpenAuditAlarmW(LPCWSTR SubsystemName, LPVOID HandleId, LPWSTR ObjectTypeName,
1898 LPWSTR ObjectName, PSECURITY_DESCRIPTOR pSecurityDescriptor, HANDLE ClientToken, DWORD DesiredAccess,
1899 DWORD GrantedAccess, PPRIVILEGE_SET Privileges, BOOL ObjectCreation, BOOL AccessGranted,
1900 LPBOOL GenerateOnClose)
1902 FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08lx,0x%08lx,%p,%x,%x,%p)\n", debugstr_w(SubsystemName),
1903 HandleId, debugstr_w(ObjectTypeName), debugstr_w(ObjectName), pSecurityDescriptor,
1904 ClientToken, DesiredAccess, GrantedAccess, Privileges, ObjectCreation, AccessGranted,
1910 BOOL WINAPI ObjectPrivilegeAuditAlarmA( LPCSTR SubsystemName, LPVOID HandleId, HANDLE ClientToken,
1911 DWORD DesiredAccess, PPRIVILEGE_SET Privileges, BOOL AccessGranted)
1913 FIXME("stub (%s,%p,%p,0x%08lx,%p,%x)\n", debugstr_a(SubsystemName), HandleId, ClientToken,
1914 DesiredAccess, Privileges, AccessGranted);
1919 BOOL WINAPI ObjectPrivilegeAuditAlarmW( LPCWSTR SubsystemName, LPVOID HandleId, HANDLE ClientToken,
1920 DWORD DesiredAccess, PPRIVILEGE_SET Privileges, BOOL AccessGranted)
1922 FIXME("stub (%s,%p,%p,0x%08lx,%p,%x)\n", debugstr_w(SubsystemName), HandleId, ClientToken,
1923 DesiredAccess, Privileges, AccessGranted);
1928 BOOL WINAPI PrivilegedServiceAuditAlarmA( LPCSTR SubsystemName, LPCSTR ServiceName, HANDLE ClientToken,
1929 PPRIVILEGE_SET Privileges, BOOL AccessGranted)
1931 FIXME("stub (%s,%s,%p,%p,%x)\n", debugstr_a(SubsystemName), debugstr_a(ServiceName),
1932 ClientToken, Privileges, AccessGranted);
1937 BOOL WINAPI PrivilegedServiceAuditAlarmW( LPCWSTR SubsystemName, LPCWSTR ServiceName, HANDLE ClientToken,
1938 PPRIVILEGE_SET Privileges, BOOL AccessGranted)
1940 FIXME("stub %s,%s,%p,%p,%x)\n", debugstr_w(SubsystemName), debugstr_w(ServiceName),
1941 ClientToken, Privileges, AccessGranted);
1946 /******************************************************************************
1947 * GetSecurityInfo [ADVAPI32.@]
1949 DWORD WINAPI GetSecurityInfo(
1950 HANDLE hObject, SE_OBJECT_TYPE ObjectType,
1951 SECURITY_INFORMATION SecurityInfo, PSID *ppsidOwner,
1952 PSID *ppsidGroup, PACL *ppDacl, PACL *ppSacl,
1953 PSECURITY_DESCRIPTOR *ppSecurityDescriptor
1957 return ERROR_BAD_PROVIDER;
1960 /******************************************************************************
1961 * GetSecurityInfoExW [ADVAPI32.@]
1963 DWORD WINAPI GetSecurityInfoExW(
1964 HANDLE hObject, SE_OBJECT_TYPE ObjectType,
1965 SECURITY_INFORMATION SecurityInfo, LPCWSTR lpProvider,
1966 LPCWSTR lpProperty, PACTRL_ACCESSW *ppAccessList,
1967 PACTRL_AUDITW *ppAuditList, LPWSTR *lppOwner, LPWSTR *lppGroup
1971 return ERROR_BAD_PROVIDER;
1974 /******************************************************************************
1975 * BuildExplicitAccessWithNameA [ADVAPI32.@]
1977 VOID WINAPI BuildExplicitAccessWithNameA( PEXPLICIT_ACCESSA pExplicitAccess,
1978 LPSTR pTrusteeName, DWORD AccessPermissions,
1979 ACCESS_MODE AccessMode, DWORD Inheritance )
1981 TRACE("%p %s 0x%08lx 0x%08x 0x%08lx\n", pExplicitAccess, debugstr_a(pTrusteeName),
1982 AccessPermissions, AccessMode, Inheritance);
1984 pExplicitAccess->grfAccessPermissions = AccessPermissions;
1985 pExplicitAccess->grfAccessMode = AccessMode;
1986 pExplicitAccess->grfInheritance = Inheritance;
1988 pExplicitAccess->Trustee.pMultipleTrustee = NULL;
1989 pExplicitAccess->Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
1990 pExplicitAccess->Trustee.TrusteeForm = TRUSTEE_IS_NAME;
1991 pExplicitAccess->Trustee.TrusteeType = TRUSTEE_IS_UNKNOWN;
1992 pExplicitAccess->Trustee.ptstrName = pTrusteeName;
1995 /******************************************************************************
1996 * BuildExplicitAccessWithNameW [ADVAPI32.@]
1998 VOID WINAPI BuildExplicitAccessWithNameW( PEXPLICIT_ACCESSW pExplicitAccess,
1999 LPWSTR pTrusteeName, DWORD AccessPermissions,
2000 ACCESS_MODE AccessMode, DWORD Inheritance )
2002 TRACE("%p %s 0x%08lx 0x%08x 0x%08lx\n", pExplicitAccess, debugstr_w(pTrusteeName),
2003 AccessPermissions, AccessMode, Inheritance);
2005 pExplicitAccess->grfAccessPermissions = AccessPermissions;
2006 pExplicitAccess->grfAccessMode = AccessMode;
2007 pExplicitAccess->grfInheritance = Inheritance;
2009 pExplicitAccess->Trustee.pMultipleTrustee = NULL;
2010 pExplicitAccess->Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2011 pExplicitAccess->Trustee.TrusteeForm = TRUSTEE_IS_NAME;
2012 pExplicitAccess->Trustee.TrusteeType = TRUSTEE_IS_UNKNOWN;
2013 pExplicitAccess->Trustee.ptstrName = pTrusteeName;
2016 /******************************************************************************
2017 * BuildTrusteeWithObjectsAndNameA [ADVAPI32.@]
2019 VOID WINAPI BuildTrusteeWithObjectsAndNameA( PTRUSTEEA pTrustee, POBJECTS_AND_NAME_A pObjName,
2020 SE_OBJECT_TYPE ObjectType, LPSTR ObjectTypeName,
2021 LPSTR InheritedObjectTypeName, LPSTR Name )
2023 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee, pObjName,
2024 ObjectType, ObjectTypeName, InheritedObjectTypeName, debugstr_a(Name));
2026 pTrustee->pMultipleTrustee = NULL;
2027 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2028 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_NAME;
2029 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2030 pTrustee->ptstrName = Name;
2033 /******************************************************************************
2034 * BuildTrusteeWithObjectsAndNameW [ADVAPI32.@]
2036 VOID WINAPI BuildTrusteeWithObjectsAndNameW( PTRUSTEEW pTrustee, POBJECTS_AND_NAME_W pObjName,
2037 SE_OBJECT_TYPE ObjectType, LPWSTR ObjectTypeName,
2038 LPWSTR InheritedObjectTypeName, LPWSTR Name )
2040 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee, pObjName,
2041 ObjectType, ObjectTypeName, InheritedObjectTypeName, debugstr_w(Name));
2043 pTrustee->pMultipleTrustee = NULL;
2044 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2045 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_NAME;
2046 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2047 pTrustee->ptstrName = Name;
2050 VOID WINAPI BuildTrusteeWithObjectsAndSidA( PTRUSTEEA pTrustee, POBJECTS_AND_SID pObjSid,
2051 GUID* pObjectGuid, GUID* pInheritedObjectGuid, PSID pSid )
2053 TRACE("%p %p %p %p %p\n", pTrustee, pObjSid, pObjectGuid, pInheritedObjectGuid, pSid);
2055 pTrustee->pMultipleTrustee = NULL;
2056 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2057 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_SID;
2058 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2059 pTrustee->ptstrName = (LPSTR) pSid;
2062 VOID WINAPI BuildTrusteeWithObjectsAndSidW( PTRUSTEEW pTrustee, POBJECTS_AND_SID pObjSid,
2063 GUID* pObjectGuid, GUID* pInheritedObjectGuid, PSID pSid )
2065 TRACE("%p %p %p %p %p\n", pTrustee, pObjSid, pObjectGuid, pInheritedObjectGuid, pSid);
2067 pTrustee->pMultipleTrustee = NULL;
2068 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2069 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_SID;
2070 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2071 pTrustee->ptstrName = (LPWSTR) pSid;
2074 /******************************************************************************
2075 * BuildTrusteeWithSidA [ADVAPI32.@]
2077 VOID WINAPI BuildTrusteeWithSidA(PTRUSTEEA pTrustee, PSID pSid)
2079 TRACE("%p %p\n", pTrustee, pSid);
2081 pTrustee->pMultipleTrustee = NULL;
2082 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2083 pTrustee->TrusteeForm = TRUSTEE_IS_SID;
2084 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2085 pTrustee->ptstrName = (LPSTR) pSid;
2088 /******************************************************************************
2089 * BuildTrusteeWithSidW [ADVAPI32.@]
2091 VOID WINAPI BuildTrusteeWithSidW(PTRUSTEEW pTrustee, PSID pSid)
2093 TRACE("%p %p\n", pTrustee, pSid);
2095 pTrustee->pMultipleTrustee = NULL;
2096 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2097 pTrustee->TrusteeForm = TRUSTEE_IS_SID;
2098 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2099 pTrustee->ptstrName = (LPWSTR) pSid;
2102 /******************************************************************************
2103 * BuildTrusteeWithNameA [ADVAPI32.@]
2105 VOID WINAPI BuildTrusteeWithNameA(PTRUSTEEA pTrustee, LPSTR name)
2107 TRACE("%p %s\n", pTrustee, debugstr_a(name) );
2109 pTrustee->pMultipleTrustee = NULL;
2110 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2111 pTrustee->TrusteeForm = TRUSTEE_IS_NAME;
2112 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2113 pTrustee->ptstrName = name;
2116 /******************************************************************************
2117 * BuildTrusteeWithNameW [ADVAPI32.@]
2119 VOID WINAPI BuildTrusteeWithNameW(PTRUSTEEW pTrustee, LPWSTR name)
2121 TRACE("%p %s\n", pTrustee, debugstr_w(name) );
2123 pTrustee->pMultipleTrustee = NULL;
2124 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2125 pTrustee->TrusteeForm = TRUSTEE_IS_NAME;
2126 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2127 pTrustee->ptstrName = name;
2130 /******************************************************************************
2131 * GetTrusteeFormA [ADVAPI32.@]
2133 TRUSTEE_FORM WINAPI GetTrusteeFormA(PTRUSTEEA pTrustee)
2135 TRACE("(%p)\n", pTrustee);
2138 return TRUSTEE_BAD_FORM;
2140 return pTrustee->TrusteeForm;
2143 /******************************************************************************
2144 * GetTrusteeFormW [ADVAPI32.@]
2146 TRUSTEE_FORM WINAPI GetTrusteeFormW(PTRUSTEEW pTrustee)
2148 TRACE("(%p)\n", pTrustee);
2151 return TRUSTEE_BAD_FORM;
2153 return pTrustee->TrusteeForm;
2156 /******************************************************************************
2157 * GetTrusteeNameA [ADVAPI32.@]
2159 LPSTR WINAPI GetTrusteeNameA(PTRUSTEEA pTrustee)
2161 TRACE("(%p)\n", pTrustee);
2166 return pTrustee->ptstrName;
2169 /******************************************************************************
2170 * GetTrusteeNameW [ADVAPI32.@]
2172 LPWSTR WINAPI GetTrusteeNameW(PTRUSTEEW pTrustee)
2174 TRACE("(%p)\n", pTrustee);
2179 return pTrustee->ptstrName;
2182 /******************************************************************************
2183 * GetTrusteeTypeA [ADVAPI32.@]
2185 TRUSTEE_TYPE WINAPI GetTrusteeTypeA(PTRUSTEEA pTrustee)
2187 TRACE("(%p)\n", pTrustee);
2190 return TRUSTEE_IS_UNKNOWN;
2192 return pTrustee->TrusteeType;
2195 /******************************************************************************
2196 * GetTrusteeTypeW [ADVAPI32.@]
2198 TRUSTEE_TYPE WINAPI GetTrusteeTypeW(PTRUSTEEW pTrustee)
2200 TRACE("(%p)\n", pTrustee);
2203 return TRUSTEE_IS_UNKNOWN;
2205 return pTrustee->TrusteeType;
2208 BOOL WINAPI SetAclInformation( PACL pAcl, LPVOID pAclInformation,
2209 DWORD nAclInformationLength,
2210 ACL_INFORMATION_CLASS dwAclInformationClass )
2212 FIXME("%p %p 0x%08lx 0x%08x - stub\n", pAcl, pAclInformation,
2213 nAclInformationLength, dwAclInformationClass);
2218 /******************************************************************************
2219 * SetEntriesInAclA [ADVAPI32.@]
2221 DWORD WINAPI SetEntriesInAclA( ULONG count, PEXPLICIT_ACCESSA pEntries,
2222 PACL OldAcl, PACL* NewAcl )
2224 FIXME("%ld %p %p %p\n",count,pEntries,OldAcl,NewAcl);
2225 return ERROR_CALL_NOT_IMPLEMENTED;
2228 /******************************************************************************
2229 * SetEntriesInAclW [ADVAPI32.@]
2231 DWORD WINAPI SetEntriesInAclW( ULONG count, PEXPLICIT_ACCESSW pEntries,
2232 PACL OldAcl, PACL* NewAcl )
2234 FIXME("%ld %p %p %p\n",count,pEntries,OldAcl,NewAcl);
2235 return ERROR_CALL_NOT_IMPLEMENTED;
2238 /******************************************************************************
2239 * SetNamedSecurityInfoA [ADVAPI32.@]
2241 DWORD WINAPI SetNamedSecurityInfoA(LPSTR pObjectName,
2242 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
2243 PSID psidOwner, PSID psidGroup, PACL pDacl, PACL pSacl)
2249 TRACE("%s %d %ld %p %p %p %p\n", debugstr_a(pObjectName), ObjectType,
2250 SecurityInfo, psidOwner, psidGroup, pDacl, pSacl);
2254 len = MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, NULL, 0 );
2255 wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR));
2256 MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, wstr, len );
2259 r = SetNamedSecurityInfoW( wstr, ObjectType, SecurityInfo, psidOwner,
2260 psidGroup, pDacl, pSacl );
2262 HeapFree( GetProcessHeap(), 0, wstr );
2267 BOOL WINAPI SetPrivateObjectSecurity( SECURITY_INFORMATION SecurityInformation,
2268 PSECURITY_DESCRIPTOR ModificationDescriptor,
2269 PSECURITY_DESCRIPTOR* ObjectsSecurityDescriptor,
2270 PGENERIC_MAPPING GenericMapping,
2273 FIXME("0x%08lx %p %p %p %p - stub\n", SecurityInformation, ModificationDescriptor,
2274 ObjectsSecurityDescriptor, GenericMapping, Token);
2279 BOOL WINAPI SetSecurityDescriptorControl( PSECURITY_DESCRIPTOR pSecurityDescriptor,
2280 SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest,
2281 SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet )
2283 FIXME("%p 0x%08x 0x%08x - stub\n", pSecurityDescriptor, ControlBitsOfInterest,
2289 BOOL WINAPI AreAllAccessesGranted( DWORD GrantedAccess, DWORD DesiredAccess )
2291 return RtlAreAllAccessesGranted( GrantedAccess, DesiredAccess );
2294 /******************************************************************************
2295 * AreAnyAccessesGranted [ADVAPI32.@]
2297 * Determines whether or not any of a set of specified access permissions have
2298 * been granted or not.
2301 * GrantedAccess [I] The permissions that have been granted.
2302 * DesiredAccess [I] The permissions that you want to have.
2305 * Nonzero if any of the permissions have been granted, zero if none of the
2306 * permissions have been granted.
2309 BOOL WINAPI AreAnyAccessesGranted( DWORD GrantedAccess, DWORD DesiredAccess )
2311 return RtlAreAnyAccessesGranted( GrantedAccess, DesiredAccess );
2314 /******************************************************************************
2315 * SetNamedSecurityInfoW [ADVAPI32.@]
2317 DWORD WINAPI SetNamedSecurityInfoW(LPWSTR pObjectName,
2318 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
2319 PSID psidOwner, PSID psidGroup, PACL pDacl, PACL pSacl)
2321 FIXME("%s %d %ld %p %p %p %p\n", debugstr_w(pObjectName), ObjectType,
2322 SecurityInfo, psidOwner, psidGroup, pDacl, pSacl);
2323 return ERROR_SUCCESS;
2326 /******************************************************************************
2327 * GetExplicitEntriesFromAclA [ADVAPI32.@]
2329 DWORD WINAPI GetExplicitEntriesFromAclA( PACL pacl, PULONG pcCountOfExplicitEntries,
2330 PEXPLICIT_ACCESSA* pListOfExplicitEntries)
2332 FIXME("%p %p %p\n",pacl, pcCountOfExplicitEntries, pListOfExplicitEntries);
2333 return ERROR_CALL_NOT_IMPLEMENTED;
2336 /******************************************************************************
2337 * GetExplicitEntriesFromAclW [ADVAPI32.@]
2339 DWORD WINAPI GetExplicitEntriesFromAclW( PACL pacl, PULONG pcCountOfExplicitEntries,
2340 PEXPLICIT_ACCESSW* pListOfExplicitEntries)
2342 FIXME("%p %p %p\n",pacl, pcCountOfExplicitEntries, pListOfExplicitEntries);
2343 return ERROR_CALL_NOT_IMPLEMENTED;
2347 /******************************************************************************
2348 * ParseAclStringFlags
2350 static DWORD ParseAclStringFlags(LPCWSTR* StringAcl)
2353 LPCWSTR szAcl = *StringAcl;
2355 while (*szAcl != '(')
2359 flags |= SE_DACL_PROTECTED;
2361 else if (*szAcl == 'A')
2365 flags |= SE_DACL_AUTO_INHERIT_REQ;
2366 else if (*szAcl == 'I')
2367 flags |= SE_DACL_AUTO_INHERITED;
2376 /******************************************************************************
2377 * ParseAceStringType
2381 { SDDL_ACCESS_ALLOWED, ACCESS_ALLOWED_ACE_TYPE },
2382 { SDDL_ALARM, SYSTEM_ALARM_ACE_TYPE },
2383 { SDDL_AUDIT, SYSTEM_AUDIT_ACE_TYPE },
2384 { SDDL_ACCESS_DENIED, ACCESS_DENIED_ACE_TYPE },
2386 { SDDL_OBJECT_ACCESS_ALLOWED, ACCESS_ALLOWED_OBJECT_ACE_TYPE },
2387 { SDDL_OBJECT_ACCESS_DENIED, ACCESS_DENIED_OBJECT_ACE_TYPE },
2388 { SDDL_OBJECT_ALARM, SYSTEM_ALARM_OBJECT_ACE_TYPE },
2389 { SDDL_OBJECT_AUDIT, SYSTEM_AUDIT_OBJECT_ACE_TYPE },
2394 static BYTE ParseAceStringType(LPCWSTR* StringAcl)
2397 LPCWSTR szAcl = *StringAcl;
2398 LPACEFLAG lpaf = AceType;
2400 while (lpaf->wstr &&
2401 (len = strlenW(lpaf->wstr)) &&
2402 strncmpW(lpaf->wstr, szAcl, len))
2413 /******************************************************************************
2414 * ParseAceStringFlags
2416 ACEFLAG AceFlags[] =
2418 { SDDL_CONTAINER_INHERIT, CONTAINER_INHERIT_ACE },
2419 { SDDL_AUDIT_FAILURE, FAILED_ACCESS_ACE_FLAG },
2420 { SDDL_INHERITED, INHERITED_ACE },
2421 { SDDL_INHERIT_ONLY, INHERIT_ONLY_ACE },
2422 { SDDL_NO_PROPAGATE, NO_PROPAGATE_INHERIT_ACE },
2423 { SDDL_OBJECT_INHERIT, OBJECT_INHERIT_ACE },
2424 { SDDL_AUDIT_SUCCESS, SUCCESSFUL_ACCESS_ACE_FLAG },
2428 static BYTE ParseAceStringFlags(LPCWSTR* StringAcl)
2432 LPCWSTR szAcl = *StringAcl;
2434 while (*szAcl != ';')
2436 LPACEFLAG lpaf = AceFlags;
2438 while (lpaf->wstr &&
2439 (len = strlenW(lpaf->wstr)) &&
2440 strncmpW(lpaf->wstr, szAcl, len))
2446 flags |= lpaf->value;
2455 /******************************************************************************
2456 * ParseAceStringRights
2458 ACEFLAG AceRights[] =
2460 { SDDL_GENERIC_ALL, GENERIC_ALL },
2461 { SDDL_GENERIC_READ, GENERIC_READ },
2462 { SDDL_GENERIC_WRITE, GENERIC_WRITE },
2463 { SDDL_GENERIC_EXECUTE, GENERIC_EXECUTE },
2464 { SDDL_READ_CONTROL, READ_CONTROL },
2465 { SDDL_STANDARD_DELETE, DELETE },
2466 { SDDL_WRITE_DAC, WRITE_DAC },
2467 { SDDL_WRITE_OWNER, WRITE_OWNER },
2471 static DWORD ParseAceStringRights(LPCWSTR* StringAcl)
2475 LPCWSTR szAcl = *StringAcl;
2477 if ((*szAcl == '0') && (*(szAcl + 1) == 'x'))
2481 while (*p && *p != ';')
2486 rights = strtoulW(szAcl, NULL, 16);
2490 WARN("Invalid rights string format: %s\n", debugstr_wn(szAcl, p - szAcl));
2494 while (*szAcl != ';')
2496 LPACEFLAG lpaf = AceRights;
2498 while (lpaf->wstr &&
2499 (len = strlenW(lpaf->wstr)) &&
2500 strncmpW(lpaf->wstr, szAcl, len))
2508 rights |= lpaf->value;
2518 /******************************************************************************
2519 * ParseStringAclToAcl
2521 * dacl_flags(string_ace1)(string_ace2)... (string_acen)
2523 static BOOL ParseStringAclToAcl(LPCWSTR StringAcl, LPDWORD lpdwFlags,
2524 PACL pAcl, LPDWORD cBytes)
2528 DWORD length = sizeof(ACL);
2529 PACCESS_ALLOWED_ACE pAce = NULL; /* pointer to current ACE */
2531 TRACE("%s\n", debugstr_w(StringAcl));
2536 if (pAcl) /* pAce is only useful if we're setting values */
2537 pAce = (PACCESS_ALLOWED_ACE) ((LPBYTE)pAcl + sizeof(PACL));
2539 /* Parse ACL flags */
2540 *lpdwFlags = ParseAclStringFlags(&StringAcl);
2543 while (*StringAcl == '(')
2547 /* Parse ACE type */
2548 val = ParseAceStringType(&StringAcl);
2550 pAce->Header.AceType = (BYTE) val;
2551 if (*StringAcl != ';')
2555 /* Parse ACE flags */
2556 val = ParseAceStringFlags(&StringAcl);
2558 pAce->Header.AceFlags = (BYTE) val;
2559 if (*StringAcl != ';')
2563 /* Parse ACE rights */
2564 val = ParseAceStringRights(&StringAcl);
2567 if (*StringAcl != ';')
2571 /* Parse ACE object guid */
2572 if (*StringAcl != ';')
2574 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
2579 /* Parse ACE inherit object guid */
2580 if (*StringAcl != ';')
2582 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
2587 /* Parse ACE account sid */
2588 if (ParseStringSidToSid(StringAcl, pAce ? (PSID)&pAce->SidStart : NULL, &sidlen))
2590 while (*StringAcl && *StringAcl != ')')
2594 if (*StringAcl != ')')
2598 length += sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) + sidlen;
2605 WARN("Invalid ACE string format\n");
2610 /******************************************************************************
2611 * ParseStringSecurityDescriptorToSecurityDescriptor
2613 static BOOL ParseStringSecurityDescriptorToSecurityDescriptor(
2614 LPCWSTR StringSecurityDescriptor,
2615 SECURITY_DESCRIPTOR* SecurityDescriptor,
2620 WCHAR tok[MAX_PATH];
2622 LPBYTE lpNext = NULL;
2627 if (SecurityDescriptor)
2628 lpNext = ((LPBYTE) SecurityDescriptor) + sizeof(SECURITY_DESCRIPTOR);
2630 while (*StringSecurityDescriptor)
2632 toktype = *StringSecurityDescriptor;
2634 /* Expect char identifier followed by ':' */
2635 StringSecurityDescriptor++;
2636 if (*StringSecurityDescriptor != ':')
2638 SetLastError(ERROR_INVALID_PARAMETER);
2641 StringSecurityDescriptor++;
2644 lptoken = StringSecurityDescriptor;
2645 while (*lptoken && *lptoken != ':')
2651 len = lptoken - StringSecurityDescriptor;
2652 memcpy( tok, StringSecurityDescriptor, len * sizeof(WCHAR) );
2661 if (!ParseStringSidToSid(tok, (PSID)lpNext, &bytes))
2664 if (SecurityDescriptor)
2666 SecurityDescriptor->Owner = (PSID)(lpNext - (LPBYTE)SecurityDescriptor);
2667 lpNext += bytes; /* Advance to next token */
2679 if (!ParseStringSidToSid(tok, (PSID)lpNext, &bytes))
2682 if (SecurityDescriptor)
2684 SecurityDescriptor->Group = (PSID)(lpNext - (LPBYTE)SecurityDescriptor);
2685 lpNext += bytes; /* Advance to next token */
2698 if (!ParseStringAclToAcl(tok, &flags, (PACL)lpNext, &bytes))
2701 if (SecurityDescriptor)
2703 SecurityDescriptor->Control |= SE_DACL_PRESENT | flags;
2704 SecurityDescriptor->Dacl = (PACL)(lpNext - (LPBYTE)SecurityDescriptor);
2705 lpNext += bytes; /* Advance to next token */
2718 if (!ParseStringAclToAcl(tok, &flags, (PACL)lpNext, &bytes))
2721 if (SecurityDescriptor)
2723 SecurityDescriptor->Control |= SE_SACL_PRESENT | flags;
2724 SecurityDescriptor->Sacl = (PACL)(lpNext - (LPBYTE)SecurityDescriptor);
2725 lpNext += bytes; /* Advance to next token */
2734 FIXME("Unknown token\n");
2735 SetLastError(ERROR_INVALID_PARAMETER);
2739 StringSecurityDescriptor = lptoken;
2748 /******************************************************************************
2749 * ConvertStringSecurityDescriptorToSecurityDescriptorA [ADVAPI32.@]
2751 BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorA(
2752 LPCSTR StringSecurityDescriptor,
2753 DWORD StringSDRevision,
2754 PSECURITY_DESCRIPTOR* SecurityDescriptor,
2755 PULONG SecurityDescriptorSize)
2759 LPWSTR StringSecurityDescriptorW;
2761 len = MultiByteToWideChar(CP_ACP, 0, StringSecurityDescriptor, -1, NULL, 0);
2762 StringSecurityDescriptorW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
2764 if (StringSecurityDescriptorW)
2766 MultiByteToWideChar(CP_ACP, 0, StringSecurityDescriptor, -1, StringSecurityDescriptorW, len);
2768 ret = ConvertStringSecurityDescriptorToSecurityDescriptorW(StringSecurityDescriptorW,
2769 StringSDRevision, SecurityDescriptor,
2770 SecurityDescriptorSize);
2771 HeapFree(GetProcessHeap(), 0, StringSecurityDescriptorW);
2777 /******************************************************************************
2778 * ConvertStringSecurityDescriptorToSecurityDescriptorW [ADVAPI32.@]
2780 BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorW(
2781 LPCWSTR StringSecurityDescriptor,
2782 DWORD StringSDRevision,
2783 PSECURITY_DESCRIPTOR* SecurityDescriptor,
2784 PULONG SecurityDescriptorSize)
2787 SECURITY_DESCRIPTOR* psd;
2790 TRACE("%s\n", debugstr_w(StringSecurityDescriptor));
2792 if (GetVersion() & 0x80000000)
2794 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2797 else if (StringSDRevision != SID_REVISION)
2799 SetLastError(ERROR_UNKNOWN_REVISION);
2803 /* Compute security descriptor length */
2804 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor,
2808 psd = *SecurityDescriptor = (SECURITY_DESCRIPTOR*) LocalAlloc(
2809 GMEM_ZEROINIT, cBytes);
2811 psd->Revision = SID_REVISION;
2812 psd->Control |= SE_SELF_RELATIVE;
2814 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor,
2821 if (SecurityDescriptorSize)
2822 *SecurityDescriptorSize = cBytes;
2827 TRACE(" ret=%d\n", bret);
2831 /******************************************************************************
2832 * ConvertStringSidToSidW [ADVAPI32.@]
2834 BOOL WINAPI ConvertStringSidToSidW(LPCWSTR StringSid, PSID* Sid)
2839 TRACE("%s, %p\n", debugstr_w(StringSid), Sid);
2840 if (GetVersion() & 0x80000000)
2841 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2842 else if (!StringSid || !Sid)
2843 SetLastError(ERROR_INVALID_PARAMETER);
2844 else if (ParseStringSidToSid(StringSid, NULL, &cBytes))
2846 PSID pSid = *Sid = (PSID) LocalAlloc(0, cBytes);
2848 bret = ParseStringSidToSid(StringSid, pSid, &cBytes);
2852 TRACE("returning %s\n", bret ? "TRUE" : "FALSE");
2856 /******************************************************************************
2857 * ConvertStringSidToSidA [ADVAPI32.@]
2859 BOOL WINAPI ConvertStringSidToSidA(LPCSTR StringSid, PSID* Sid)
2863 TRACE("%s, %p\n", debugstr_a(StringSid), Sid);
2864 if (GetVersion() & 0x80000000)
2865 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2866 else if (!StringSid || !Sid)
2867 SetLastError(ERROR_INVALID_PARAMETER);
2870 UINT len = MultiByteToWideChar(CP_ACP, 0, StringSid, -1, NULL, 0);
2871 LPWSTR wStringSid = HeapAlloc(GetProcessHeap(), 0,
2872 len * sizeof(WCHAR));
2874 MultiByteToWideChar(CP_ACP, 0, StringSid, -1, wStringSid, len);
2875 bret = ConvertStringSidToSidW(wStringSid, Sid);
2876 HeapFree(GetProcessHeap(), 0, wStringSid);
2878 TRACE("returning %s\n", bret ? "TRUE" : "FALSE");
2882 /******************************************************************************
2883 * ConvertSidToStringSidW [ADVAPI32.@]
2885 * format of SID string is:
2886 * S-<count>-<auth>-<subauth1>-<subauth2>-<subauth3>...
2888 * <rev> is the revision of the SID encoded as decimal
2889 * <auth> is the identifier authority encoded as hex
2890 * <subauthN> is the subauthority id encoded as decimal
2892 BOOL WINAPI ConvertSidToStringSidW( PSID pSid, LPWSTR *pstr )
2896 WCHAR fmt[] = { 'S','-','%','u','-','%','d',0 };
2897 WCHAR subauthfmt[] = { '-','%','u',0 };
2900 TRACE("%p %p\n", pSid, pstr );
2902 if( !IsValidSid( pSid ) )
2905 if (pisid->Revision != SDDL_REVISION)
2907 if (pisid->IdentifierAuthority.Value[0] ||
2908 pisid->IdentifierAuthority.Value[1])
2910 FIXME("not matching MS' bugs\n");
2914 sz = 14 + pisid->SubAuthorityCount * 11;
2915 str = LocalAlloc( 0, sz*sizeof(WCHAR) );
2916 sprintfW( str, fmt, pisid->Revision, MAKELONG(
2917 MAKEWORD( pisid->IdentifierAuthority.Value[5],
2918 pisid->IdentifierAuthority.Value[4] ),
2919 MAKEWORD( pisid->IdentifierAuthority.Value[3],
2920 pisid->IdentifierAuthority.Value[2] ) ) );
2921 for( i=0; i<pisid->SubAuthorityCount; i++ )
2922 sprintfW( str + strlenW(str), subauthfmt, pisid->SubAuthority[i] );
2928 /******************************************************************************
2929 * ConvertSidToStringSidA [ADVAPI32.@]
2931 BOOL WINAPI ConvertSidToStringSidA(PSID pSid, LPSTR *pstr)
2937 TRACE("%p %p\n", pSid, pstr );
2939 if( !ConvertSidToStringSidW( pSid, &wstr ) )
2942 len = WideCharToMultiByte( CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL );
2943 str = LocalAlloc( 0, len );
2944 WideCharToMultiByte( CP_ACP, 0, wstr, -1, str, len, NULL, NULL );
2952 BOOL WINAPI CreatePrivateObjectSecurity(
2953 PSECURITY_DESCRIPTOR ParentDescriptor,
2954 PSECURITY_DESCRIPTOR CreatorDescriptor,
2955 PSECURITY_DESCRIPTOR* NewDescriptor,
2956 BOOL IsDirectoryObject,
2958 PGENERIC_MAPPING GenericMapping )
2960 FIXME("%p %p %p %d %p %p - stub\n", ParentDescriptor, CreatorDescriptor,
2961 NewDescriptor, IsDirectoryObject, Token, GenericMapping);
2966 BOOL WINAPI DestroyPrivateObjectSecurity( PSECURITY_DESCRIPTOR* ObjectDescriptor )
2968 FIXME("%p - stub\n", ObjectDescriptor);
2973 BOOL WINAPI CreateProcessAsUserA(
2975 LPCSTR lpApplicationName,
2976 LPSTR lpCommandLine,
2977 LPSECURITY_ATTRIBUTES lpProcessAttributes,
2978 LPSECURITY_ATTRIBUTES lpThreadAttributes,
2979 BOOL bInheritHandles,
2980 DWORD dwCreationFlags,
2981 LPVOID lpEnvironment,
2982 LPCSTR lpCurrentDirectory,
2983 LPSTARTUPINFOA lpStartupInfo,
2984 LPPROCESS_INFORMATION lpProcessInformation )
2986 FIXME("%p %s %s %p %p %d 0x%08lx %p %s %p %p - stub\n", hToken, debugstr_a(lpApplicationName),
2987 debugstr_a(lpCommandLine), lpProcessAttributes, lpThreadAttributes, bInheritHandles,
2988 dwCreationFlags, lpEnvironment, debugstr_a(lpCurrentDirectory), lpStartupInfo, lpProcessInformation);
2993 BOOL WINAPI CreateProcessAsUserW(
2995 LPCWSTR lpApplicationName,
2996 LPWSTR lpCommandLine,
2997 LPSECURITY_ATTRIBUTES lpProcessAttributes,
2998 LPSECURITY_ATTRIBUTES lpThreadAttributes,
2999 BOOL bInheritHandles,
3000 DWORD dwCreationFlags,
3001 LPVOID lpEnvironment,
3002 LPCWSTR lpCurrentDirectory,
3003 LPSTARTUPINFOW lpStartupInfo,
3004 LPPROCESS_INFORMATION lpProcessInformation )
3006 FIXME("%p %s %s %p %p %d 0x%08lx %p %s %p %p - semi- stub\n", hToken,
3007 debugstr_w(lpApplicationName), debugstr_w(lpCommandLine), lpProcessAttributes,
3008 lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment,
3009 debugstr_w(lpCurrentDirectory), lpStartupInfo, lpProcessInformation);
3011 /* We should create the process with a suspended main thread */
3012 if (!CreateProcessW (lpApplicationName,
3014 lpProcessAttributes,
3017 dwCreationFlags, /* CREATE_SUSPENDED */
3021 lpProcessInformation))
3029 /******************************************************************************
3030 * ComputeStringSidSize
3032 static DWORD ComputeStringSidSize(LPCWSTR StringSid)
3035 DWORD size = sizeof(SID);
3039 if (*StringSid == '-')
3045 size += (ctok - 3) * sizeof(DWORD);
3050 BOOL WINAPI DuplicateTokenEx(
3051 HANDLE ExistingTokenHandle, DWORD dwDesiredAccess,
3052 LPSECURITY_ATTRIBUTES lpTokenAttributes,
3053 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
3054 TOKEN_TYPE TokenType,
3055 PHANDLE DuplicateTokenHandle )
3057 OBJECT_ATTRIBUTES ObjectAttributes;
3059 TRACE("%p 0x%08lx 0x%08x 0x%08x %p\n", ExistingTokenHandle, dwDesiredAccess,
3060 ImpersonationLevel, TokenType, DuplicateTokenHandle);
3062 InitializeObjectAttributes(
3065 (lpTokenAttributes && lpTokenAttributes->bInheritHandle) ? OBJ_INHERIT : 0,
3067 lpTokenAttributes ? lpTokenAttributes->lpSecurityDescriptor : NULL );
3069 return set_ntstatus( NtDuplicateToken( ExistingTokenHandle,
3074 DuplicateTokenHandle ) );
3077 BOOL WINAPI DuplicateToken(
3078 HANDLE ExistingTokenHandle,
3079 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
3080 PHANDLE DuplicateTokenHandle )
3082 return DuplicateTokenEx( ExistingTokenHandle, TOKEN_IMPERSONATE | TOKEN_QUERY,
3083 NULL, ImpersonationLevel, TokenImpersonation,
3084 DuplicateTokenHandle );
3087 BOOL WINAPI EnumDependentServicesA(
3089 DWORD dwServiceState,
3090 LPENUM_SERVICE_STATUSA lpServices,
3092 LPDWORD pcbBytesNeeded,
3093 LPDWORD lpServicesReturned )
3095 FIXME("%p 0x%08lx %p 0x%08lx %p %p - stub\n", hService, dwServiceState,
3096 lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned);
3101 BOOL WINAPI EnumDependentServicesW(
3103 DWORD dwServiceState,
3104 LPENUM_SERVICE_STATUSW lpServices,
3106 LPDWORD pcbBytesNeeded,
3107 LPDWORD lpServicesReturned )
3109 FIXME("%p 0x%08lx %p 0x%08lx %p %p - stub\n", hService, dwServiceState,
3110 lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned);
3115 /******************************************************************************
3116 * ParseStringSidToSid
3118 static BOOL ParseStringSidToSid(LPCWSTR StringSid, PSID pSid, LPDWORD cBytes)
3123 TRACE("%s, %p, %p\n", debugstr_w(StringSid), pSid, cBytes);
3126 SetLastError(ERROR_INVALID_PARAMETER);
3127 TRACE("StringSid is NULL, returning FALSE\n");
3131 *cBytes = ComputeStringSidSize(StringSid);
3132 if (!pisid) /* Simply compute the size */
3134 TRACE("only size requested, returning TRUE\n");
3138 if (StringSid[0] == 'S' && StringSid[1] == '-') /* S-R-I-S-S */
3140 DWORD i = 0, identAuth;
3141 DWORD csubauth = ((*cBytes - sizeof(SID)) / sizeof(DWORD)) + 1;
3143 StringSid += 2; /* Advance to Revision */
3144 pisid->Revision = atoiW(StringSid);
3146 if (pisid->Revision != SDDL_REVISION)
3148 TRACE("Revision %d is unknown\n", pisid->Revision);
3149 goto lend; /* ERROR_INVALID_SID */
3153 TRACE("SubAuthorityCount is 0\n");
3154 goto lend; /* ERROR_INVALID_SID */
3157 pisid->SubAuthorityCount = csubauth;
3159 /* Advance to identifier authority */
3160 while (*StringSid && *StringSid != '-')
3162 if (*StringSid == '-')
3165 /* MS' implementation can't handle values greater than 2^32 - 1, so
3166 * we don't either; assume most significant bytes are always 0
3168 pisid->IdentifierAuthority.Value[0] = 0;
3169 pisid->IdentifierAuthority.Value[1] = 0;
3170 identAuth = atoiW(StringSid);
3171 pisid->IdentifierAuthority.Value[5] = identAuth & 0xff;
3172 pisid->IdentifierAuthority.Value[4] = (identAuth & 0xff00) >> 8;
3173 pisid->IdentifierAuthority.Value[3] = (identAuth & 0xff0000) >> 16;
3174 pisid->IdentifierAuthority.Value[2] = (identAuth & 0xff000000) >> 24;
3176 /* Advance to first sub authority */
3177 while (*StringSid && *StringSid != '-')
3179 if (*StringSid == '-')
3184 while (*StringSid && *StringSid != '-')
3187 pisid->SubAuthority[i++] = atoiW(StringSid);
3190 if (i != pisid->SubAuthorityCount)
3191 goto lend; /* ERROR_INVALID_SID */
3195 else /* String constant format - Only available in winxp and above */
3197 pisid->Revision = SDDL_REVISION;
3198 pisid->SubAuthorityCount = 1;
3200 FIXME("String constant not supported: %s\n", debugstr_wn(StringSid, 2));
3202 /* TODO: Lookup string of well-known SIDs in table */
3203 pisid->IdentifierAuthority.Value[5] = 0;
3204 pisid->SubAuthority[0] = 0;
3211 SetLastError(ERROR_INVALID_SID);
3213 TRACE("returning %s\n", bret ? "TRUE" : "FALSE");
3217 /******************************************************************************
3218 * GetNamedSecurityInfoA [ADVAPI32.@]
3220 DWORD WINAPI GetNamedSecurityInfoA(LPSTR pObjectName,
3221 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
3222 PSID* ppsidOwner, PSID* ppsidGroup, PACL* ppDacl, PACL* ppSacl,
3223 PSECURITY_DESCRIPTOR* ppSecurityDescriptor)
3229 TRACE("%s %d %ld %p %p %p %p %p\n", pObjectName, ObjectType, SecurityInfo,
3230 ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor);
3234 len = MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, NULL, 0 );
3235 wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR));
3236 MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, wstr, len );
3239 r = GetNamedSecurityInfoW( wstr, ObjectType, SecurityInfo, ppsidOwner,
3240 ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor );
3242 HeapFree( GetProcessHeap(), 0, wstr );
3247 /******************************************************************************
3248 * GetNamedSecurityInfoW [ADVAPI32.@]
3250 DWORD WINAPI GetNamedSecurityInfoW( LPWSTR name, SE_OBJECT_TYPE type,
3251 SECURITY_INFORMATION info, PSID* owner, PSID* group, PACL* dacl,
3252 PACL* sacl, PSECURITY_DESCRIPTOR* descriptor )
3254 DWORD needed, offset;
3255 SECURITY_DESCRIPTOR_RELATIVE *relative;
3258 TRACE( "%s %d %ld %p %p %p %p %p\n", debugstr_w(name), type, info, owner,
3259 group, dacl, sacl, descriptor );
3261 if (!name || !descriptor) return ERROR_INVALID_PARAMETER;
3263 needed = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
3264 if (info & OWNER_SECURITY_INFORMATION)
3265 needed += sizeof(sidWorld);
3266 if (info & GROUP_SECURITY_INFORMATION)
3267 needed += sizeof(sidWorld);
3268 if (info & DACL_SECURITY_INFORMATION)
3269 needed += WINE_SIZE_OF_WORLD_ACCESS_ACL;
3270 if (info & SACL_SECURITY_INFORMATION)
3271 needed += WINE_SIZE_OF_WORLD_ACCESS_ACL;
3273 /* must be freed by caller */
3274 *descriptor = HeapAlloc( GetProcessHeap(), 0, needed );
3275 if (!*descriptor) return ERROR_NOT_ENOUGH_MEMORY;
3277 if (!InitializeSecurityDescriptor( *descriptor, SECURITY_DESCRIPTOR_REVISION ))
3279 HeapFree( GetProcessHeap(), 0, *descriptor );
3280 return ERROR_INVALID_SECURITY_DESCR;
3283 relative = (SECURITY_DESCRIPTOR_RELATIVE *)*descriptor;
3284 relative->Control |= SE_SELF_RELATIVE;
3285 buffer = (BYTE *)relative;
3286 offset = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
3288 if (owner && (info & OWNER_SECURITY_INFORMATION))
3290 memcpy( buffer + offset, &sidWorld, sizeof(sidWorld) );
3291 relative->Owner = offset;
3292 *owner = buffer + offset;
3293 offset += sizeof(sidWorld);
3295 if (group && (info & GROUP_SECURITY_INFORMATION))
3297 memcpy( buffer + offset, &sidWorld, sizeof(sidWorld) );
3298 relative->Group = offset;
3299 *group = buffer + offset;
3300 offset += sizeof(sidWorld);
3302 if (dacl && (info & DACL_SECURITY_INFORMATION))
3304 GetWorldAccessACL( (PACL)(buffer + offset) );
3305 relative->Dacl = offset;
3306 *dacl = (PACL)(buffer + offset);
3307 offset += WINE_SIZE_OF_WORLD_ACCESS_ACL;
3309 if (sacl && (info & SACL_SECURITY_INFORMATION))
3311 GetWorldAccessACL( (PACL)(buffer + offset) );
3312 relative->Sacl = offset;
3313 *sacl = (PACL)(buffer + offset);
3315 return ERROR_SUCCESS;
3318 /******************************************************************************
3319 * DecryptFileW [ADVAPI32.@]
3321 BOOL WINAPI DecryptFileW(LPCWSTR lpFileName, DWORD dwReserved)
3323 FIXME("%s %08lx\n", debugstr_w(lpFileName), dwReserved);
3327 /******************************************************************************
3328 * DecryptFileA [ADVAPI32.@]
3330 BOOL WINAPI DecryptFileA(LPCSTR lpFileName, DWORD dwReserved)
3332 FIXME("%s %08lx\n", debugstr_a(lpFileName), dwReserved);
3336 /******************************************************************************
3337 * EncryptFileW [ADVAPI32.@]
3339 BOOL WINAPI EncryptFileW(LPCWSTR lpFileName)
3341 FIXME("%s\n", debugstr_w(lpFileName));
3345 /******************************************************************************
3346 * EncryptFileA [ADVAPI32.@]
3348 BOOL WINAPI EncryptFileA(LPCSTR lpFileName)
3350 FIXME("%s\n", debugstr_a(lpFileName));
3354 /******************************************************************************
3355 * SetSecurityInfo [ADVAPI32.@]
3357 DWORD WINAPI SetSecurityInfo(HANDLE handle, SE_OBJECT_TYPE ObjectType,
3358 SECURITY_INFORMATION SecurityInfo, PSID psidOwner,
3359 PSID psidGroup, PACL pDacl, PACL pSacl) {
3361 return ERROR_SUCCESS;