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
37 #include "wine/debug.h"
38 #include "wine/unicode.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
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,
52 static DWORD ParseAclStringFlags(LPCWSTR* StringAcl);
54 typedef struct _ACEFLAG
58 } ACEFLAG, *LPACEFLAG;
63 static const WCHAR SDDL_READ_CONTROL[] = {'R','C',0};
64 static const WCHAR SDDL_WRITE_DAC[] = {'W','D',0};
65 static const WCHAR SDDL_WRITE_OWNER[] = {'W','O',0};
66 static const WCHAR SDDL_STANDARD_DELETE[] = {'S','D',0};
67 static const WCHAR SDDL_GENERIC_ALL[] = {'G','A',0};
68 static const WCHAR SDDL_GENERIC_READ[] = {'G','R',0};
69 static const WCHAR SDDL_GENERIC_WRITE[] = {'G','W',0};
70 static const WCHAR SDDL_GENERIC_EXECUTE[] = {'G','X',0};
75 static const WCHAR SDDL_ACCESS_ALLOWED[] = {'A',0};
76 static const WCHAR SDDL_ACCESS_DENIED[] = {'D',0};
77 static const WCHAR SDDL_OBJECT_ACCESS_ALLOWED[] = {'O','A',0};
78 static const WCHAR SDDL_OBJECT_ACCESS_DENIED[] = {'O','D',0};
79 static const WCHAR SDDL_AUDIT[] = {'A','U',0};
80 static const WCHAR SDDL_ALARM[] = {'A','L',0};
81 static const WCHAR SDDL_OBJECT_AUDIT[] = {'O','U',0};
82 static const WCHAR SDDL_OBJECT_ALARMp[] = {'O','L',0};
87 static const WCHAR SDDL_CONTAINER_INHERIT[] = {'C','I',0};
88 static const WCHAR SDDL_OBJECT_INHERIT[] = {'O','I',0};
89 static const WCHAR SDDL_NO_PROPAGATE[] = {'N','P',0};
90 static const WCHAR SDDL_INHERIT_ONLY[] = {'I','O',0};
91 static const WCHAR SDDL_INHERITED[] = {'I','D',0};
92 static const WCHAR SDDL_AUDIT_SUCCESS[] = {'S','A',0};
93 static const WCHAR SDDL_AUDIT_FAILURE[] = {'F','A',0};
95 /* set last error code from NT status and get the proper boolean return value */
96 /* used for functions that are a simple wrapper around the corresponding ntdll API */
97 static inline BOOL set_ntstatus( NTSTATUS status )
99 if (status) SetLastError( RtlNtStatusToDosError( status ));
103 static void dumpLsaAttributes( PLSA_OBJECT_ATTRIBUTES oa )
107 TRACE("\n\tlength=%lu, rootdir=%p, objectname=%s\n\tattr=0x%08lx, sid=%p qos=%p\n",
108 oa->Length, oa->RootDirectory,
109 oa->ObjectName?debugstr_w(oa->ObjectName->Buffer):"null",
110 oa->Attributes, oa->SecurityDescriptor, oa->SecurityQualityOfService);
114 /************************************************************
115 * ADVAPI_IsLocalComputer
117 * Checks whether the server name indicates local machine.
119 BOOL ADVAPI_IsLocalComputer(LPCWSTR ServerName)
125 else if (!ServerName[0])
131 DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
135 buf = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
136 Result = GetComputerNameW(buf, &dwSize);
137 if (Result && (ServerName[0] == '\\') && (ServerName[1] == '\\'))
139 Result = Result && !lstrcmpW(ServerName, buf);
140 HeapFree(GetProcessHeap(), 0, buf);
146 #define ADVAPI_ForceLocalComputer(ServerName, FailureCode) \
147 if (!ADVAPI_IsLocalComputer(ServerName)) \
149 FIXME("Action Implemented for local computer only. " \
150 "Requested for server %s\n", debugstr_w(ServerName)); \
151 return FailureCode; \
154 /* ##############################
155 ###### TOKEN FUNCTIONS ######
156 ##############################
159 /******************************************************************************
160 * OpenProcessToken [ADVAPI32.@]
161 * Opens the access token associated with a process handle.
164 * ProcessHandle [I] Handle to process
165 * DesiredAccess [I] Desired access to process
166 * TokenHandle [O] Pointer to handle of open access token
169 * Success: TRUE. TokenHandle contains the access token.
173 * See NtOpenProcessToken.
176 OpenProcessToken( HANDLE ProcessHandle, DWORD DesiredAccess,
177 HANDLE *TokenHandle )
179 return set_ntstatus(NtOpenProcessToken( ProcessHandle, DesiredAccess, TokenHandle ));
182 /******************************************************************************
183 * OpenThreadToken [ADVAPI32.@]
185 * Opens the access token associated with a thread handle.
188 * ThreadHandle [I] Handle to process
189 * DesiredAccess [I] Desired access to the thread
191 * TokenHandle [O] Destination for the token handle
194 * Success: TRUE. TokenHandle contains the access token.
198 * See NtOpenThreadToken.
201 OpenThreadToken( HANDLE ThreadHandle, DWORD DesiredAccess,
202 BOOL OpenAsSelf, HANDLE *TokenHandle)
204 return set_ntstatus( NtOpenThreadToken(ThreadHandle, DesiredAccess, OpenAsSelf, TokenHandle));
208 AdjustTokenGroups( HANDLE TokenHandle, BOOL ResetToDefault, PTOKEN_GROUPS NewState,
209 DWORD BufferLength, PTOKEN_GROUPS PreviousState, PDWORD ReturnLength )
211 return set_ntstatus( NtAdjustGroupsToken(TokenHandle, ResetToDefault, NewState, BufferLength,
212 PreviousState, ReturnLength));
215 /******************************************************************************
216 * AdjustTokenPrivileges [ADVAPI32.@]
218 * Adjust the privileges of an open token handle.
221 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
222 * DisableAllPrivileges [I] TRUE=Remove all privileges, FALSE=Use NewState
223 * NewState [I] Desired new privileges of the token
224 * BufferLength [I] Length of NewState
225 * PreviousState [O] Destination for the previous state
226 * ReturnLength [I/O] Size of PreviousState
230 * Success: TRUE. Privileges are set to NewState and PreviousState is updated.
234 * See NtAdjustPrivilegesToken.
237 AdjustTokenPrivileges( HANDLE TokenHandle, BOOL DisableAllPrivileges,
238 LPVOID NewState, DWORD BufferLength,
239 LPVOID PreviousState, LPDWORD ReturnLength )
241 return set_ntstatus( NtAdjustPrivilegesToken(TokenHandle, DisableAllPrivileges,
242 NewState, BufferLength, PreviousState,
246 /******************************************************************************
247 * CheckTokenMembership [ADVAPI32.@]
249 * Determine if an access token is a member of a SID.
252 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
253 * SidToCheck [I] SID that possibly contains the token
254 * IsMember [O] Destination for result.
257 * Success: TRUE. IsMember is TRUE if TokenHandle is a member, FALSE otherwise.
261 CheckTokenMembership( HANDLE TokenHandle, PSID SidToCheck,
264 FIXME("(%p %p %p) stub!\n", TokenHandle, SidToCheck, IsMember);
270 /******************************************************************************
271 * GetTokenInformation [ADVAPI32.@]
274 * token [I] Handle from OpenProcessToken() or OpenThreadToken()
275 * tokeninfoclass [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
276 * tokeninfo [O] Destination for token information
277 * tokeninfolength [I] Length of tokeninfo
278 * retlen [O] Destination for returned token information length
281 * Success: TRUE. tokeninfo contains retlen bytes of token information
285 * See NtQueryInformationToken.
288 GetTokenInformation( HANDLE token, TOKEN_INFORMATION_CLASS tokeninfoclass,
289 LPVOID tokeninfo, DWORD tokeninfolength, LPDWORD retlen )
291 TRACE("(%p, %s, %p, %ld, %p): \n",
293 (tokeninfoclass == TokenUser) ? "TokenUser" :
294 (tokeninfoclass == TokenGroups) ? "TokenGroups" :
295 (tokeninfoclass == TokenPrivileges) ? "TokenPrivileges" :
296 (tokeninfoclass == TokenOwner) ? "TokenOwner" :
297 (tokeninfoclass == TokenPrimaryGroup) ? "TokenPrimaryGroup" :
298 (tokeninfoclass == TokenDefaultDacl) ? "TokenDefaultDacl" :
299 (tokeninfoclass == TokenSource) ? "TokenSource" :
300 (tokeninfoclass == TokenType) ? "TokenType" :
301 (tokeninfoclass == TokenImpersonationLevel) ? "TokenImpersonationLevel" :
302 (tokeninfoclass == TokenStatistics) ? "TokenStatistics" :
303 (tokeninfoclass == TokenRestrictedSids) ? "TokenRestrictedSids" :
304 (tokeninfoclass == TokenSessionId) ? "TokenSessionId" :
305 (tokeninfoclass == TokenGroupsAndPrivileges) ? "TokenGroupsAndPrivileges" :
306 (tokeninfoclass == TokenSessionReference) ? "TokenSessionReference" :
307 (tokeninfoclass == TokenSandBoxInert) ? "TokenSandBoxInert" :
309 tokeninfo, tokeninfolength, retlen);
310 return set_ntstatus( NtQueryInformationToken( token, tokeninfoclass, tokeninfo,
311 tokeninfolength, retlen));
314 /******************************************************************************
315 * SetTokenInformation [ADVAPI32.@]
317 * Set information for an access token.
320 * token [I] Handle from OpenProcessToken() or OpenThreadToken()
321 * tokeninfoclass [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
322 * tokeninfo [I] Token information to set
323 * tokeninfolength [I] Length of tokeninfo
326 * Success: TRUE. The information for the token is set to tokeninfo.
330 SetTokenInformation( HANDLE token, TOKEN_INFORMATION_CLASS tokeninfoclass,
331 LPVOID tokeninfo, DWORD tokeninfolength )
333 TRACE("(%p, %s, %p, %ld): stub\n",
335 (tokeninfoclass == TokenUser) ? "TokenUser" :
336 (tokeninfoclass == TokenGroups) ? "TokenGroups" :
337 (tokeninfoclass == TokenPrivileges) ? "TokenPrivileges" :
338 (tokeninfoclass == TokenOwner) ? "TokenOwner" :
339 (tokeninfoclass == TokenPrimaryGroup) ? "TokenPrimaryGroup" :
340 (tokeninfoclass == TokenDefaultDacl) ? "TokenDefaultDacl" :
341 (tokeninfoclass == TokenSource) ? "TokenSource" :
342 (tokeninfoclass == TokenType) ? "TokenType" :
343 (tokeninfoclass == TokenImpersonationLevel) ? "TokenImpersonationLevel" :
344 (tokeninfoclass == TokenStatistics) ? "TokenStatistics" :
345 (tokeninfoclass == TokenRestrictedSids) ? "TokenRestrictedSids" :
346 (tokeninfoclass == TokenSessionId) ? "TokenSessionId" :
347 (tokeninfoclass == TokenGroupsAndPrivileges) ? "TokenGroupsAndPrivileges" :
348 (tokeninfoclass == TokenSessionReference) ? "TokenSessionReference" :
349 (tokeninfoclass == TokenSandBoxInert) ? "TokenSandBoxInert" :
351 tokeninfo, tokeninfolength);
353 return set_ntstatus( NtSetInformationToken( token, tokeninfoclass, tokeninfo, tokeninfolength ));
356 /*************************************************************************
357 * SetThreadToken [ADVAPI32.@]
359 * Assigns an 'impersonation token' to a thread so it can assume the
360 * security privileges of another thread or process. Can also remove
361 * a previously assigned token.
364 * thread [O] Handle to thread to set the token for
365 * token [I] Token to set
368 * Success: TRUE. The threads access token is set to token
372 * Only supported on NT or higher. On Win9X this function does nothing.
373 * See SetTokenInformation.
375 BOOL WINAPI SetThreadToken(PHANDLE thread, HANDLE token)
377 return set_ntstatus( NtSetInformationThread( thread ? *thread : GetCurrentThread(),
378 ThreadImpersonationToken, &token, sizeof token ));
381 /* ##############################
382 ###### SID FUNCTIONS ######
383 ##############################
386 /******************************************************************************
387 * AllocateAndInitializeSid [ADVAPI32.@]
390 * pIdentifierAuthority []
391 * nSubAuthorityCount []
403 AllocateAndInitializeSid( PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
404 BYTE nSubAuthorityCount,
405 DWORD nSubAuthority0, DWORD nSubAuthority1,
406 DWORD nSubAuthority2, DWORD nSubAuthority3,
407 DWORD nSubAuthority4, DWORD nSubAuthority5,
408 DWORD nSubAuthority6, DWORD nSubAuthority7,
411 return set_ntstatus( RtlAllocateAndInitializeSid(
412 pIdentifierAuthority, nSubAuthorityCount,
413 nSubAuthority0, nSubAuthority1, nSubAuthority2, nSubAuthority3,
414 nSubAuthority4, nSubAuthority5, nSubAuthority6, nSubAuthority7,
418 /******************************************************************************
419 * FreeSid [ADVAPI32.@]
428 return NULL; /* is documented like this */
431 /******************************************************************************
432 * CopySid [ADVAPI32.@]
435 * nDestinationSidLength []
440 CopySid( DWORD nDestinationSidLength, PSID pDestinationSid, PSID pSourceSid )
442 return RtlCopySid(nDestinationSidLength, pDestinationSid, pSourceSid);
446 IsTokenRestricted( HANDLE TokenHandle )
448 FIXME("%p - stub\n", TokenHandle);
453 /******************************************************************************
454 * IsValidSid [ADVAPI32.@]
460 IsValidSid( PSID pSid )
462 return RtlValidSid( pSid );
465 /******************************************************************************
466 * EqualSid [ADVAPI32.@]
473 EqualSid( PSID pSid1, PSID pSid2 )
475 return RtlEqualSid( pSid1, pSid2 );
478 /******************************************************************************
479 * EqualPrefixSid [ADVAPI32.@]
481 BOOL WINAPI EqualPrefixSid (PSID pSid1, PSID pSid2)
483 return RtlEqualPrefixSid(pSid1, pSid2);
486 /******************************************************************************
487 * GetSidLengthRequired [ADVAPI32.@]
490 * nSubAuthorityCount []
493 GetSidLengthRequired( BYTE nSubAuthorityCount )
495 return RtlLengthRequiredSid(nSubAuthorityCount);
498 /******************************************************************************
499 * InitializeSid [ADVAPI32.@]
502 * pIdentifierAuthority []
507 PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
508 BYTE nSubAuthorityCount)
510 return RtlInitializeSid(pSid, pIdentifierAuthority, nSubAuthorityCount);
514 GetEffectiveRightsFromAclA( PACL pacl, PTRUSTEEA pTrustee, PACCESS_MASK pAccessRights )
516 FIXME("%p %p %p - stub\n", pacl, pTrustee, pAccessRights);
522 GetEffectiveRightsFromAclW( PACL pacl, PTRUSTEEW pTrustee, PACCESS_MASK pAccessRights )
524 FIXME("%p %p %p - stub\n", pacl, pTrustee, pAccessRights);
529 /******************************************************************************
530 * GetSidIdentifierAuthority [ADVAPI32.@]
535 PSID_IDENTIFIER_AUTHORITY WINAPI
536 GetSidIdentifierAuthority( PSID pSid )
538 return RtlIdentifierAuthoritySid(pSid);
541 /******************************************************************************
542 * GetSidSubAuthority [ADVAPI32.@]
549 GetSidSubAuthority( PSID pSid, DWORD nSubAuthority )
551 return RtlSubAuthoritySid(pSid, nSubAuthority);
554 /******************************************************************************
555 * GetSidSubAuthorityCount [ADVAPI32.@]
561 GetSidSubAuthorityCount (PSID pSid)
563 return RtlSubAuthorityCountSid(pSid);
566 /******************************************************************************
567 * GetLengthSid [ADVAPI32.@]
573 GetLengthSid (PSID pSid)
575 return RtlLengthSid(pSid);
578 /* ##############################################
579 ###### SECURITY DESCRIPTOR FUNCTIONS ######
580 ##############################################
583 /******************************************************************************
584 * InitializeSecurityDescriptor [ADVAPI32.@]
591 InitializeSecurityDescriptor( PSECURITY_DESCRIPTOR pDescr, DWORD revision )
593 return set_ntstatus( RtlCreateSecurityDescriptor(pDescr, revision ));
597 /******************************************************************************
598 * MakeAbsoluteSD [ADVAPI32.@]
600 BOOL WINAPI MakeAbsoluteSD (
601 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
602 OUT PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
603 OUT LPDWORD lpdwAbsoluteSecurityDescriptorSize,
605 OUT LPDWORD lpdwDaclSize,
607 OUT LPDWORD lpdwSaclSize,
609 OUT LPDWORD lpdwOwnerSize,
610 OUT PSID pPrimaryGroup,
611 OUT LPDWORD lpdwPrimaryGroupSize)
613 return set_ntstatus( RtlSelfRelativeToAbsoluteSD(pSelfRelativeSecurityDescriptor,
614 pAbsoluteSecurityDescriptor,
615 lpdwAbsoluteSecurityDescriptorSize,
616 pDacl, lpdwDaclSize, pSacl, lpdwSaclSize,
617 pOwner, lpdwOwnerSize,
618 pPrimaryGroup, lpdwPrimaryGroupSize));
621 BOOL WINAPI GetKernelObjectSecurity(
623 SECURITY_INFORMATION RequestedInformation,
624 PSECURITY_DESCRIPTOR pSecurityDescriptor,
626 LPDWORD lpnLengthNeeded )
628 FIXME("%p 0x%08lx %p 0x%08lx %p - stub\n", Handle, RequestedInformation,
629 pSecurityDescriptor, nLength, lpnLengthNeeded);
634 BOOL WINAPI GetPrivateObjectSecurity(
635 PSECURITY_DESCRIPTOR ObjectDescriptor,
636 SECURITY_INFORMATION SecurityInformation,
637 PSECURITY_DESCRIPTOR ResultantDescriptor,
638 DWORD DescriptorLength,
639 PDWORD ReturnLength )
641 FIXME("%p 0x%08lx %p 0x%08lx %p - stub\n", ObjectDescriptor, SecurityInformation,
642 ResultantDescriptor, DescriptorLength, ReturnLength);
647 /******************************************************************************
648 * GetSecurityDescriptorLength [ADVAPI32.@]
650 DWORD WINAPI GetSecurityDescriptorLength( PSECURITY_DESCRIPTOR pDescr)
652 return RtlLengthSecurityDescriptor(pDescr);
655 /******************************************************************************
656 * GetSecurityDescriptorOwner [ADVAPI32.@]
660 * lpbOwnerDefaulted []
663 GetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pDescr, PSID *pOwner,
664 LPBOOL lpbOwnerDefaulted )
667 BOOL ret = set_ntstatus( RtlGetOwnerSecurityDescriptor( pDescr, pOwner, &defaulted ));
668 *lpbOwnerDefaulted = defaulted;
672 /******************************************************************************
673 * SetSecurityDescriptorOwner [ADVAPI32.@]
677 BOOL WINAPI SetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pSecurityDescriptor,
678 PSID pOwner, BOOL bOwnerDefaulted)
680 return set_ntstatus( RtlSetOwnerSecurityDescriptor(pSecurityDescriptor, pOwner, bOwnerDefaulted));
682 /******************************************************************************
683 * GetSecurityDescriptorGroup [ADVAPI32.@]
685 BOOL WINAPI GetSecurityDescriptorGroup(
686 PSECURITY_DESCRIPTOR SecurityDescriptor,
688 LPBOOL GroupDefaulted)
691 BOOL ret = set_ntstatus( RtlGetGroupSecurityDescriptor(SecurityDescriptor, Group, &defaulted ));
692 *GroupDefaulted = defaulted;
695 /******************************************************************************
696 * SetSecurityDescriptorGroup [ADVAPI32.@]
698 BOOL WINAPI SetSecurityDescriptorGroup ( PSECURITY_DESCRIPTOR SecurityDescriptor,
699 PSID Group, BOOL GroupDefaulted)
701 return set_ntstatus( RtlSetGroupSecurityDescriptor( SecurityDescriptor, Group, GroupDefaulted));
704 /******************************************************************************
705 * IsValidSecurityDescriptor [ADVAPI32.@]
711 IsValidSecurityDescriptor( PSECURITY_DESCRIPTOR SecurityDescriptor )
713 return set_ntstatus( RtlValidSecurityDescriptor(SecurityDescriptor));
716 /******************************************************************************
717 * GetSecurityDescriptorDacl [ADVAPI32.@]
719 BOOL WINAPI GetSecurityDescriptorDacl(
720 IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
721 OUT LPBOOL lpbDaclPresent,
723 OUT LPBOOL lpbDaclDefaulted)
725 BOOLEAN present, defaulted;
726 BOOL ret = set_ntstatus( RtlGetDaclSecurityDescriptor(pSecurityDescriptor, &present, pDacl, &defaulted));
727 *lpbDaclPresent = present;
728 *lpbDaclDefaulted = defaulted;
732 /******************************************************************************
733 * SetSecurityDescriptorDacl [ADVAPI32.@]
736 SetSecurityDescriptorDacl (
737 PSECURITY_DESCRIPTOR lpsd,
742 return set_ntstatus( RtlSetDaclSecurityDescriptor (lpsd, daclpresent, dacl, dacldefaulted ) );
744 /******************************************************************************
745 * GetSecurityDescriptorSacl [ADVAPI32.@]
747 BOOL WINAPI GetSecurityDescriptorSacl(
748 IN PSECURITY_DESCRIPTOR lpsd,
749 OUT LPBOOL lpbSaclPresent,
751 OUT LPBOOL lpbSaclDefaulted)
753 BOOLEAN present, defaulted;
754 BOOL ret = set_ntstatus( RtlGetSaclSecurityDescriptor(lpsd, &present, pSacl, &defaulted) );
755 *lpbSaclPresent = present;
756 *lpbSaclDefaulted = defaulted;
760 /**************************************************************************
761 * SetSecurityDescriptorSacl [ADVAPI32.@]
763 BOOL WINAPI SetSecurityDescriptorSacl (
764 PSECURITY_DESCRIPTOR lpsd,
769 return set_ntstatus (RtlSetSaclSecurityDescriptor(lpsd, saclpresent, lpsacl, sacldefaulted));
771 /******************************************************************************
772 * MakeSelfRelativeSD [ADVAPI32.@]
781 IN PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
782 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
783 IN OUT LPDWORD lpdwBufferLength)
785 return set_ntstatus( RtlMakeSelfRelativeSD( pAbsoluteSecurityDescriptor,
786 pSelfRelativeSecurityDescriptor, lpdwBufferLength));
789 /******************************************************************************
790 * GetSecurityDescriptorControl [ADVAPI32.@]
793 BOOL WINAPI GetSecurityDescriptorControl ( PSECURITY_DESCRIPTOR pSecurityDescriptor,
794 PSECURITY_DESCRIPTOR_CONTROL pControl, LPDWORD lpdwRevision)
796 return set_ntstatus( RtlGetControlSecurityDescriptor(pSecurityDescriptor,pControl,lpdwRevision));
799 /* ##############################
800 ###### ACL FUNCTIONS ######
801 ##############################
804 /*************************************************************************
805 * InitializeAcl [ADVAPI32.@]
807 BOOL WINAPI InitializeAcl(PACL acl, DWORD size, DWORD rev)
809 return set_ntstatus( RtlCreateAcl(acl, size, rev));
812 BOOL WINAPI ImpersonateNamedPipeClient( HANDLE hNamedPipe )
814 FIXME("%p - stub\n", hNamedPipe);
819 /******************************************************************************
820 * AddAccessAllowedAce [ADVAPI32.@]
822 BOOL WINAPI AddAccessAllowedAce(
824 IN DWORD dwAceRevision,
828 return set_ntstatus(RtlAddAccessAllowedAce(pAcl, dwAceRevision, AccessMask, pSid));
831 /******************************************************************************
832 * AddAccessAllowedAceEx [ADVAPI32.@]
834 BOOL WINAPI AddAccessAllowedAceEx(
836 IN DWORD dwAceRevision,
841 return set_ntstatus(RtlAddAccessAllowedAceEx(pAcl, dwAceRevision, AceFlags, AccessMask, pSid));
844 /******************************************************************************
845 * AddAccessDeniedAce [ADVAPI32.@]
847 BOOL WINAPI AddAccessDeniedAce(
849 IN DWORD dwAceRevision,
853 return set_ntstatus(RtlAddAccessDeniedAce(pAcl, dwAceRevision, AccessMask, pSid));
856 /******************************************************************************
857 * AddAccessDeniedAceEx [ADVAPI32.@]
859 BOOL WINAPI AddAccessDeniedAceEx(
861 IN DWORD dwAceRevision,
866 return set_ntstatus(RtlAddAccessDeniedAceEx(pAcl, dwAceRevision, AceFlags, AccessMask, pSid));
869 /******************************************************************************
870 * AddAce [ADVAPI32.@]
874 IN DWORD dwAceRevision,
875 IN DWORD dwStartingAceIndex,
877 DWORD nAceListLength)
879 return set_ntstatus(RtlAddAce(pAcl, dwAceRevision, dwStartingAceIndex, pAceList, nAceListLength));
882 /******************************************************************************
883 * DeleteAce [ADVAPI32.@]
885 BOOL WINAPI DeleteAce(PACL pAcl, DWORD dwAceIndex)
887 return set_ntstatus(RtlDeleteAce(pAcl, dwAceIndex));
890 /******************************************************************************
891 * FindFirstFreeAce [ADVAPI32.@]
893 BOOL WINAPI FindFirstFreeAce(IN PACL pAcl, LPVOID * pAce)
895 return RtlFirstFreeAce(pAcl, (PACE_HEADER *)pAce);
898 /******************************************************************************
899 * GetAce [ADVAPI32.@]
901 BOOL WINAPI GetAce(PACL pAcl,DWORD dwAceIndex,LPVOID *pAce )
903 return set_ntstatus(RtlGetAce(pAcl, dwAceIndex, pAce));
906 /******************************************************************************
907 * GetAclInformation [ADVAPI32.@]
909 BOOL WINAPI GetAclInformation(
911 LPVOID pAclInformation,
912 DWORD nAclInformationLength,
913 ACL_INFORMATION_CLASS dwAclInformationClass)
915 return set_ntstatus(RtlQueryInformationAcl(pAcl, pAclInformation,
916 nAclInformationLength, dwAclInformationClass));
919 /******************************************************************************
920 * IsValidAcl [ADVAPI32.@]
922 BOOL WINAPI IsValidAcl(IN PACL pAcl)
924 return RtlValidAcl(pAcl);
927 /* ##############################
928 ###### MISC FUNCTIONS ######
929 ##############################
932 /******************************************************************************
933 * AllocateLocallyUniqueId [ADVAPI32.@]
938 BOOL WINAPI AllocateLocallyUniqueId( PLUID lpLuid )
940 return set_ntstatus(NtAllocateLocallyUniqueId(lpLuid));
943 static const WCHAR SE_CREATE_TOKEN_NAME_W[] =
944 { 'S','e','C','r','e','a','t','e','T','o','k','e','n','P','r','i','v','i','l','e','g','e',0 };
945 static const WCHAR SE_ASSIGNPRIMARYTOKEN_NAME_W[] =
946 { '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 };
947 static const WCHAR SE_LOCK_MEMORY_NAME_W[] =
948 { 'S','e','L','o','c','k','M','e','m','o','r','y','P','r','i','v','i','l','e','g','e',0 };
949 static const WCHAR SE_INCREASE_QUOTA_NAME_W[] =
950 { '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 };
951 static const WCHAR SE_MACHINE_ACCOUNT_NAME_W[] =
952 { '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 };
953 static const WCHAR SE_TCB_NAME_W[] =
954 { 'S','e','T','c','b','P','r','i','v','i','l','e','g','e',0 };
955 static const WCHAR SE_SECURITY_NAME_W[] =
956 { 'S','e','S','e','c','u','r','i','t','y','P','r','i','v','i','l','e','g','e',0 };
957 static const WCHAR SE_TAKE_OWNERSHIP_NAME_W[] =
958 { '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 };
959 static const WCHAR SE_LOAD_DRIVER_NAME_W[] =
960 { 'S','e','L','o','a','d','D','r','i','v','e','r','P','r','i','v','i','l','e','g','e',0 };
961 static const WCHAR SE_SYSTEM_PROFILE_NAME_W[] =
962 { '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 };
963 static const WCHAR SE_SYSTEMTIME_NAME_W[] =
964 { 'S','e','S','y','s','t','e','m','t','i','m','e','P','r','i','v','i','l','e','g','e',0 };
965 static const WCHAR SE_PROF_SINGLE_PROCESS_NAME_W[] =
966 { '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 };
967 static const WCHAR SE_INC_BASE_PRIORITY_NAME_W[] =
968 { '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 };
969 static const WCHAR SE_CREATE_PAGEFILE_NAME_W[] =
970 { '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 };
971 static const WCHAR SE_CREATE_PERMANENT_NAME_W[] =
972 { '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 };
973 static const WCHAR SE_BACKUP_NAME_W[] =
974 { 'S','e','B','a','c','k','u','p','P','r','i','v','i','l','e','g','e',0 };
975 static const WCHAR SE_RESTORE_NAME_W[] =
976 { 'S','e','R','e','s','t','o','r','e','P','r','i','v','i','l','e','g','e',0 };
977 static const WCHAR SE_SHUTDOWN_NAME_W[] =
978 { 'S','e','S','h','u','t','d','o','w','n','P','r','i','v','i','l','e','g','e',0 };
979 static const WCHAR SE_DEBUG_NAME_W[] =
980 { 'S','e','D','e','b','u','g','P','r','i','v','i','l','e','g','e',0 };
981 static const WCHAR SE_AUDIT_NAME_W[] =
982 { 'S','e','A','u','d','i','t','P','r','i','v','i','l','e','g','e',0 };
983 static const WCHAR SE_SYSTEM_ENVIRONMENT_NAME_W[] =
984 { '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 };
985 static const WCHAR SE_CHANGE_NOTIFY_NAME_W[] =
986 { 'S','e','C','h','a','n','g','e','N','o','t','i','f','y','P','r','i','v','i','l','e','g','e',0 };
987 static const WCHAR SE_REMOTE_SHUTDOWN_NAME_W[] =
988 { '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 };
989 static const WCHAR SE_UNDOCK_NAME_W[] =
990 { 'S','e','U','n','d','o','c','k','P','r','i','v','i','l','e','g','e',0 };
991 static const WCHAR SE_SYNC_AGENT_NAME_W[] =
992 { 'S','e','S','y','n','c','A','g','e','n','t','P','r','i','v','i','l','e','g','e',0 };
993 static const WCHAR SE_ENABLE_DELEGATION_NAME_W[] =
994 { '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 };
995 static const WCHAR SE_MANAGE_VOLUME_NAME_W[] =
996 { 'S','e','M','a','n','a','g','e','V','o','l','u','m','e','P','r','i','v','i','l','e','g','e',0 };
997 static const WCHAR SE_IMPERSONATE_NAME_W[] =
998 { 'S','e','I','m','p','e','r','s','o','n','a','t','e','P','r','i','v','i','l','e','g','e',0 };
999 static const WCHAR SE_CREATE_GLOBAL_NAME_W[] =
1000 { 'S','e','C','r','e','a','t','e','G','l','o','b','a','l','P','r','i','v','i','l','e','g','e',0 };
1002 static const WCHAR * const WellKnownPrivNames[SE_MAX_WELL_KNOWN_PRIVILEGE + 1] =
1006 SE_CREATE_TOKEN_NAME_W,
1007 SE_ASSIGNPRIMARYTOKEN_NAME_W,
1008 SE_LOCK_MEMORY_NAME_W,
1009 SE_INCREASE_QUOTA_NAME_W,
1010 SE_MACHINE_ACCOUNT_NAME_W,
1013 SE_TAKE_OWNERSHIP_NAME_W,
1014 SE_LOAD_DRIVER_NAME_W,
1015 SE_SYSTEM_PROFILE_NAME_W,
1016 SE_SYSTEMTIME_NAME_W,
1017 SE_PROF_SINGLE_PROCESS_NAME_W,
1018 SE_INC_BASE_PRIORITY_NAME_W,
1019 SE_CREATE_PAGEFILE_NAME_W,
1020 SE_CREATE_PERMANENT_NAME_W,
1026 SE_SYSTEM_ENVIRONMENT_NAME_W,
1027 SE_CHANGE_NOTIFY_NAME_W,
1028 SE_REMOTE_SHUTDOWN_NAME_W,
1030 SE_SYNC_AGENT_NAME_W,
1031 SE_ENABLE_DELEGATION_NAME_W,
1032 SE_MANAGE_VOLUME_NAME_W,
1033 SE_IMPERSONATE_NAME_W,
1034 SE_CREATE_GLOBAL_NAME_W,
1037 /******************************************************************************
1038 * LookupPrivilegeValueW [ADVAPI32.@]
1040 * See LookupPrivilegeValueA.
1043 LookupPrivilegeValueW( LPCWSTR lpSystemName, LPCWSTR lpName, PLUID lpLuid )
1047 TRACE("%s,%s,%p\n",debugstr_w(lpSystemName), debugstr_w(lpName), lpLuid);
1049 if (!ADVAPI_IsLocalComputer(lpSystemName))
1051 SetLastError(RPC_S_SERVER_UNAVAILABLE);
1056 SetLastError(ERROR_NO_SUCH_PRIVILEGE);
1059 for( i=SE_MIN_WELL_KNOWN_PRIVILEGE; i<SE_MAX_WELL_KNOWN_PRIVILEGE; i++ )
1061 if( !WellKnownPrivNames[i] )
1063 if( strcmpiW( WellKnownPrivNames[i], lpName) )
1065 lpLuid->LowPart = i;
1066 lpLuid->HighPart = 0;
1067 TRACE( "%s -> %08lx-%08lx\n",debugstr_w( lpSystemName ),
1068 lpLuid->HighPart, lpLuid->LowPart );
1071 SetLastError(ERROR_NO_SUCH_PRIVILEGE);
1075 /******************************************************************************
1076 * LookupPrivilegeValueA [ADVAPI32.@]
1078 * Retrieves LUID used on a system to represent the privilege name.
1081 * lpSystemName [I] Name of the system
1082 * lpName [I] Name of the privilege
1083 * lpLuid [O] Destination for the resulting LUID
1086 * Success: TRUE. lpLuid contains the requested LUID.
1090 LookupPrivilegeValueA( LPCSTR lpSystemName, LPCSTR lpName, PLUID lpLuid )
1092 UNICODE_STRING lpSystemNameW;
1093 UNICODE_STRING lpNameW;
1096 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW, lpSystemName);
1097 RtlCreateUnicodeStringFromAsciiz(&lpNameW,lpName);
1098 ret = LookupPrivilegeValueW(lpSystemNameW.Buffer, lpNameW.Buffer, lpLuid);
1099 RtlFreeUnicodeString(&lpNameW);
1100 RtlFreeUnicodeString(&lpSystemNameW);
1104 BOOL WINAPI LookupPrivilegeDisplayNameA( LPCSTR lpSystemName, LPCSTR lpName, LPSTR lpDisplayName,
1105 LPDWORD cchDisplayName, LPDWORD lpLanguageId )
1107 FIXME("%s %s %s %p %p - stub\n", debugstr_a(lpSystemName), debugstr_a(lpName),
1108 debugstr_a(lpDisplayName), cchDisplayName, lpLanguageId);
1113 BOOL WINAPI LookupPrivilegeDisplayNameW( LPCWSTR lpSystemName, LPCWSTR lpName, LPWSTR lpDisplayName,
1114 LPDWORD cchDisplayName, LPDWORD lpLanguageId )
1116 FIXME("%s %s %s %p %p - stub\n", debugstr_w(lpSystemName), debugstr_w(lpName),
1117 debugstr_w(lpDisplayName), cchDisplayName, lpLanguageId);
1122 /******************************************************************************
1123 * LookupPrivilegeNameA [ADVAPI32.@]
1125 * See LookupPrivilegeNameW
1128 LookupPrivilegeNameA( LPCSTR lpSystemName, PLUID lpLuid, LPSTR lpName,
1131 UNICODE_STRING lpSystemNameW;
1135 TRACE("%s %p %p %p\n", debugstr_a(lpSystemName), lpLuid, lpName, cchName);
1137 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW, lpSystemName);
1138 ret = LookupPrivilegeNameW(lpSystemNameW.Buffer, lpLuid, NULL, &wLen);
1139 if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
1141 LPWSTR lpNameW = HeapAlloc(GetProcessHeap(), 0, wLen * sizeof(WCHAR));
1143 ret = LookupPrivilegeNameW(lpSystemNameW.Buffer, lpLuid, lpNameW,
1147 /* Windows crashes if cchName is NULL, so will I */
1148 int len = WideCharToMultiByte(CP_ACP, 0, lpNameW, -1, lpName,
1149 *cchName, NULL, NULL);
1153 /* WideCharToMultiByte failed */
1156 else if (len > *cchName)
1159 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1164 /* WideCharToMultiByte succeeded, output length needs to be
1165 * length not including NULL terminator
1170 HeapFree(GetProcessHeap(), 0, lpNameW);
1172 RtlFreeUnicodeString(&lpSystemNameW);
1176 /******************************************************************************
1177 * LookupPrivilegeNameW [ADVAPI32.@]
1179 * Retrieves the privilege name referred to by the LUID lpLuid.
1182 * lpSystemName [I] Name of the system
1183 * lpLuid [I] Privilege value
1184 * lpName [O] Name of the privilege
1185 * cchName [I/O] Number of characters in lpName.
1188 * Success: TRUE. lpName contains the name of the privilege whose value is
1193 * Only well-known privilege names (those defined in winnt.h) can be retrieved
1194 * using this function.
1195 * If the length of lpName is too small, on return *cchName will contain the
1196 * number of WCHARs needed to contain the privilege, including the NULL
1197 * terminator, and GetLastError will return ERROR_INSUFFICIENT_BUFFER.
1198 * On success, *cchName will contain the number of characters stored in
1199 * lpName, NOT including the NULL terminator.
1202 LookupPrivilegeNameW( LPCWSTR lpSystemName, PLUID lpLuid, LPWSTR lpName,
1207 TRACE("%s,%p,%p,%p\n",debugstr_w(lpSystemName), lpLuid, lpName, cchName);
1209 if (!ADVAPI_IsLocalComputer(lpSystemName))
1211 SetLastError(RPC_S_SERVER_UNAVAILABLE);
1214 if (lpLuid->HighPart || (lpLuid->LowPart < SE_MIN_WELL_KNOWN_PRIVILEGE ||
1215 lpLuid->LowPart > SE_MAX_WELL_KNOWN_PRIVILEGE))
1217 SetLastError(ERROR_NO_SUCH_PRIVILEGE);
1220 privNameLen = strlenW(WellKnownPrivNames[lpLuid->LowPart]);
1221 /* Windows crashes if cchName is NULL, so will I */
1222 if (*cchName <= privNameLen)
1224 *cchName = privNameLen + 1;
1225 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1230 strcpyW(lpName, WellKnownPrivNames[lpLuid->LowPart]);
1231 *cchName = privNameLen;
1236 /******************************************************************************
1237 * GetFileSecurityA [ADVAPI32.@]
1239 * Obtains Specified information about the security of a file or directory.
1242 * lpFileName [I] Name of the file to get info for
1243 * RequestedInformation [I] SE_ flags from "winnt.h"
1244 * pSecurityDescriptor [O] Destination for security information
1245 * nLength [I] Length of pSecurityDescriptor
1246 * lpnLengthNeeded [O] Destination for length of returned security information
1249 * Success: TRUE. pSecurityDescriptor contains the requested information.
1250 * Failure: FALSE. lpnLengthNeeded contains the required space to return the info.
1253 * The information returned is constrained by the callers access rights and
1257 GetFileSecurityA( LPCSTR lpFileName,
1258 SECURITY_INFORMATION RequestedInformation,
1259 PSECURITY_DESCRIPTOR pSecurityDescriptor,
1260 DWORD nLength, LPDWORD lpnLengthNeeded )
1268 len = MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, NULL, 0 );
1269 name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
1270 MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, name, len );
1273 r = GetFileSecurityW( name, RequestedInformation, pSecurityDescriptor,
1274 nLength, lpnLengthNeeded );
1275 HeapFree( GetProcessHeap(), 0, name );
1280 /******************************************************************************
1281 * GetFileSecurityW [ADVAPI32.@]
1283 * See GetFileSecurityA.
1286 GetFileSecurityW( LPCWSTR lpFileName,
1287 SECURITY_INFORMATION RequestedInformation,
1288 PSECURITY_DESCRIPTOR pSecurityDescriptor,
1289 DWORD nLength, LPDWORD lpnLengthNeeded )
1291 FIXME("(%s) : stub\n", debugstr_w(lpFileName) );
1296 /******************************************************************************
1297 * LookupAccountSidA [ADVAPI32.@]
1304 IN OUT LPDWORD accountSize,
1306 IN OUT LPDWORD domainSize,
1307 OUT PSID_NAME_USE name_use )
1309 static const char ac[] = "Administrator";
1310 static const char dm[] = "DOMAIN";
1311 FIXME("(%s,sid=%p,%p,%p(%lu),%p,%p(%lu),%p): semi-stub\n",
1312 debugstr_a(system),sid,
1313 account,accountSize,accountSize?*accountSize:0,
1314 domain,domainSize,domainSize?*domainSize:0,
1317 if (accountSize) *accountSize = strlen(ac)+1;
1318 if (account && (*accountSize > strlen(ac)))
1319 strcpy(account, ac);
1321 if (domainSize) *domainSize = strlen(dm)+1;
1322 if (domain && (*domainSize > strlen(dm)))
1325 if (name_use) *name_use = SidTypeUser;
1329 /******************************************************************************
1330 * LookupAccountSidW [ADVAPI32.@]
1346 IN OUT LPDWORD accountSize,
1348 IN OUT LPDWORD domainSize,
1349 OUT PSID_NAME_USE name_use )
1351 static const WCHAR ac[] = {'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
1352 static const WCHAR dm[] = {'D','O','M','A','I','N',0};
1353 FIXME("(%s,sid=%p,%p,%p(%lu),%p,%p(%lu),%p): semi-stub\n",
1354 debugstr_w(system),sid,
1355 account,accountSize,accountSize?*accountSize:0,
1356 domain,domainSize,domainSize?*domainSize:0,
1359 if (accountSize) *accountSize = strlenW(ac)+1;
1360 if (account && (*accountSize > strlenW(ac)))
1361 strcpyW(account, ac);
1363 if (domainSize) *domainSize = strlenW(dm)+1;
1364 if (domain && (*domainSize > strlenW(dm)))
1367 if (name_use) *name_use = SidTypeUser;
1371 /******************************************************************************
1372 * SetFileSecurityA [ADVAPI32.@]
1373 * Sets the security of a file or directory
1375 BOOL WINAPI SetFileSecurityA( LPCSTR lpFileName,
1376 SECURITY_INFORMATION RequestedInformation,
1377 PSECURITY_DESCRIPTOR pSecurityDescriptor)
1385 len = MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, NULL, 0 );
1386 name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
1387 MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, name, len );
1390 r = SetFileSecurityW( name, RequestedInformation, pSecurityDescriptor );
1391 HeapFree( GetProcessHeap(), 0, name );
1396 /******************************************************************************
1397 * SetFileSecurityW [ADVAPI32.@]
1398 * Sets the security of a file or directory
1402 * RequestedInformation []
1403 * pSecurityDescriptor []
1406 SetFileSecurityW( LPCWSTR lpFileName,
1407 SECURITY_INFORMATION RequestedInformation,
1408 PSECURITY_DESCRIPTOR pSecurityDescriptor )
1410 FIXME("(%s) : stub\n", debugstr_w(lpFileName) );
1414 /******************************************************************************
1415 * QueryWindows31FilesMigration [ADVAPI32.@]
1421 QueryWindows31FilesMigration( DWORD x1 )
1423 FIXME("(%ld):stub\n",x1);
1427 /******************************************************************************
1428 * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.@]
1437 SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1, DWORD x2, DWORD x3,
1440 FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx):stub\n",x1,x2,x3,x4);
1445 LsaEnumerateTrustedDomains(
1446 LSA_HANDLE PolicyHandle,
1447 PLSA_ENUMERATION_HANDLE EnumerationContext,
1449 ULONG PreferedMaximumLength,
1450 PULONG CountReturned)
1452 FIXME("(%p,%p,%p,0x%08lx,%p):stub\n", PolicyHandle, EnumerationContext,
1453 Buffer, PreferedMaximumLength, CountReturned);
1455 if (CountReturned) *CountReturned = 0;
1456 return STATUS_SUCCESS;
1461 LSA_HANDLE PolicyHandle,
1463 PLSA_UNICODE_STRING Names,
1464 PLSA_REFERENCED_DOMAIN_LIST* ReferencedDomains,
1465 PLSA_TRANSLATED_SID* Sids)
1467 FIXME("(%p,0x%08lx,%p,%p,%p):stub\n", PolicyHandle, Count, Names,
1468 ReferencedDomains, Sids);
1470 return STATUS_NONE_MAPPED;
1473 /******************************************************************************
1474 * LsaOpenPolicy [ADVAPI32.@]
1478 * ObjectAttributes [I]
1480 * PolicyHandle [I/O]
1484 IN PLSA_UNICODE_STRING SystemName,
1485 IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes,
1486 IN ACCESS_MASK DesiredAccess,
1487 IN OUT PLSA_HANDLE PolicyHandle)
1489 FIXME("(%s,%p,0x%08lx,%p):stub\n",
1490 SystemName?debugstr_w(SystemName->Buffer):"null",
1491 ObjectAttributes, DesiredAccess, PolicyHandle);
1492 ADVAPI_ForceLocalComputer(SystemName ? SystemName->Buffer : NULL,
1493 STATUS_ACCESS_VIOLATION);
1494 dumpLsaAttributes(ObjectAttributes);
1495 if(PolicyHandle) *PolicyHandle = (LSA_HANDLE)0xcafe;
1496 return STATUS_SUCCESS;
1499 /******************************************************************************
1500 * LsaQueryInformationPolicy [ADVAPI32.@]
1503 LsaQueryInformationPolicy(
1504 IN LSA_HANDLE PolicyHandle,
1505 IN POLICY_INFORMATION_CLASS InformationClass,
1508 FIXME("(%p,0x%08x,%p):stub\n",
1509 PolicyHandle, InformationClass, Buffer);
1511 if(!Buffer) return FALSE;
1512 switch (InformationClass)
1514 case PolicyAuditEventsInformation: /* 2 */
1516 PPOLICY_AUDIT_EVENTS_INFO p = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(POLICY_AUDIT_EVENTS_INFO));
1517 p->AuditingMode = FALSE; /* no auditing */
1521 case PolicyPrimaryDomainInformation: /* 3 */
1522 case PolicyAccountDomainInformation: /* 5 */
1525 { POLICY_PRIMARY_DOMAIN_INFO ppdi;
1528 SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
1530 struct di * xdi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(xdi));
1532 BOOL useDefault = TRUE;
1535 if ((ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1536 "System\\CurrentControlSet\\Services\\VxD\\VNETSUP", 0,
1537 KEY_READ, &key)) == ERROR_SUCCESS)
1540 static const WCHAR wg[] = { 'W','o','r','k','g','r','o','u','p',0 };
1542 ret = RegQueryValueExW(key, wg, NULL, NULL, NULL, &size);
1543 if (ret == ERROR_MORE_DATA || ret == ERROR_SUCCESS)
1545 xdi->ppdi.Name.Buffer = HeapAlloc(GetProcessHeap(),
1546 HEAP_ZERO_MEMORY, size);
1547 if ((ret = RegQueryValueExW(key, wg, NULL, NULL,
1548 (LPBYTE)xdi->ppdi.Name.Buffer, &size)) == ERROR_SUCCESS)
1550 xdi->ppdi.Name.Length = (USHORT)size;
1555 HeapFree(GetProcessHeap(), 0, xdi->ppdi.Name.Buffer);
1556 xdi->ppdi.Name.Buffer = NULL;
1562 RtlCreateUnicodeStringFromAsciiz(&(xdi->ppdi.Name), "DOMAIN");
1563 TRACE("setting domain to %s\n", debugstr_w(xdi->ppdi.Name.Buffer));
1565 xdi->ppdi.Sid = &(xdi->sid);
1566 xdi->sid.Revision = SID_REVISION;
1567 xdi->sid.SubAuthorityCount = 1;
1568 xdi->sid.IdentifierAuthority = localSidAuthority;
1569 xdi->sid.SubAuthority[0] = SECURITY_LOCAL_SYSTEM_RID;
1573 case PolicyAuditLogInformation:
1574 case PolicyPdAccountInformation:
1575 case PolicyLsaServerRoleInformation:
1576 case PolicyReplicaSourceInformation:
1577 case PolicyDefaultQuotaInformation:
1578 case PolicyModificationInformation:
1579 case PolicyAuditFullSetInformation:
1580 case PolicyAuditFullQueryInformation:
1581 case PolicyDnsDomainInformation:
1583 FIXME("category not implemented\n");
1591 LsaSetInformationPolicy(
1592 LSA_HANDLE PolicyHandle,
1593 POLICY_INFORMATION_CLASS InformationClass,
1596 FIXME("(%p,0x%08x,%p):stub\n", PolicyHandle, InformationClass, Buffer);
1598 return STATUS_UNSUCCESSFUL;
1601 /******************************************************************************
1602 * LsaLookupSids [ADVAPI32.@]
1606 IN LSA_HANDLE PolicyHandle,
1609 OUT PLSA_REFERENCED_DOMAIN_LIST *ReferencedDomains,
1610 OUT PLSA_TRANSLATED_NAME *Names )
1612 FIXME("%p %lu %p %p %p\n",
1613 PolicyHandle, Count, Sids, ReferencedDomains, Names);
1617 /******************************************************************************
1618 * LsaFreeMemory [ADVAPI32.@]
1621 LsaFreeMemory(IN PVOID Buffer)
1623 TRACE("(%p)\n",Buffer);
1624 return HeapFree(GetProcessHeap(), 0, Buffer);
1626 /******************************************************************************
1627 * LsaClose [ADVAPI32.@]
1630 LsaClose(IN LSA_HANDLE ObjectHandle)
1632 FIXME("(%p):stub\n",ObjectHandle);
1636 /******************************************************************************
1637 * LsaStorePrivateData [ADVAPI32.@]
1639 NTSTATUS WINAPI LsaStorePrivateData( LSA_HANDLE PolicyHandle,
1640 PLSA_UNICODE_STRING KeyName, PLSA_UNICODE_STRING PrivateData)
1642 FIXME("%p %p %p\n", PolicyHandle, KeyName, PrivateData);
1643 return STATUS_OBJECT_NAME_NOT_FOUND;
1646 /******************************************************************************
1647 * LsaRetrievePrivateData [ADVAPI32.@]
1649 NTSTATUS WINAPI LsaRetrievePrivateData( LSA_HANDLE PolicyHandle,
1650 PLSA_UNICODE_STRING KeyName, PLSA_UNICODE_STRING* PrivateData)
1652 FIXME("%p %p %p\n", PolicyHandle, KeyName, PrivateData);
1653 return STATUS_OBJECT_NAME_NOT_FOUND;
1656 /******************************************************************************
1657 * LsaNtStatusToWinError [ADVAPI32.@]
1663 LsaNtStatusToWinError(NTSTATUS Status)
1665 return RtlNtStatusToDosError(Status);
1668 /******************************************************************************
1669 * NotifyBootConfigStatus [ADVAPI32.@]
1675 NotifyBootConfigStatus( DWORD x1 )
1677 FIXME("(0x%08lx):stub\n",x1);
1681 /******************************************************************************
1682 * RevertToSelf [ADVAPI32.@]
1688 RevertToSelf( void )
1690 FIXME("(), stub\n");
1694 /******************************************************************************
1695 * ImpersonateSelf [ADVAPI32.@]
1698 ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
1700 return RtlImpersonateSelf(ImpersonationLevel);
1703 /******************************************************************************
1704 * ImpersonateLoggedOnUser [ADVAPI32.@]
1706 BOOL WINAPI ImpersonateLoggedOnUser(HANDLE hToken)
1708 FIXME("(%p):stub returning FALSE\n", hToken);
1712 /******************************************************************************
1713 * AccessCheck [ADVAPI32.@]
1717 PSECURITY_DESCRIPTOR SecurityDescriptor,
1719 DWORD DesiredAccess,
1720 PGENERIC_MAPPING GenericMapping,
1721 PPRIVILEGE_SET PrivilegeSet,
1722 LPDWORD PrivilegeSetLength,
1723 LPDWORD GrantedAccess,
1724 LPBOOL AccessStatus)
1726 NTSTATUS access_status;
1727 BOOL ret = set_ntstatus( NtAccessCheck(SecurityDescriptor, ClientToken, DesiredAccess,
1728 GenericMapping, PrivilegeSet, PrivilegeSetLength,
1729 GrantedAccess, &access_status) );
1730 if (ret) *AccessStatus = set_ntstatus( access_status );
1735 /******************************************************************************
1736 * AccessCheckByType [ADVAPI32.@]
1738 BOOL WINAPI AccessCheckByType(
1739 PSECURITY_DESCRIPTOR pSecurityDescriptor,
1740 PSID PrincipalSelfSid,
1742 DWORD DesiredAccess,
1743 POBJECT_TYPE_LIST ObjectTypeList,
1744 DWORD ObjectTypeListLength,
1745 PGENERIC_MAPPING GenericMapping,
1746 PPRIVILEGE_SET PrivilegeSet,
1747 LPDWORD PrivilegeSetLength,
1748 LPDWORD GrantedAccess,
1749 LPBOOL AccessStatus)
1753 *AccessStatus = TRUE;
1755 return !*AccessStatus;
1758 VOID WINAPI MapGenericMask( PDWORD AccessMask, PGENERIC_MAPPING GenericMapping )
1760 FIXME("%p %p - stub\n", AccessMask, GenericMapping);
1762 *AccessMask |= GenericMapping->GenericRead;
1763 *AccessMask |= GenericMapping->GenericWrite;
1764 *AccessMask |= GenericMapping->GenericExecute;
1765 *AccessMask |= GenericMapping->GenericAll;
1768 /*************************************************************************
1769 * SetKernelObjectSecurity [ADVAPI32.@]
1771 BOOL WINAPI SetKernelObjectSecurity (
1773 IN SECURITY_INFORMATION SecurityInformation,
1774 IN PSECURITY_DESCRIPTOR SecurityDescriptor )
1776 return set_ntstatus (NtSetSecurityObject (Handle, SecurityInformation, SecurityDescriptor));
1780 /******************************************************************************
1781 * AddAuditAccessAce [ADVAPI32.@]
1783 BOOL WINAPI AddAuditAccessAce(
1785 IN DWORD dwAceRevision,
1786 IN DWORD dwAccessMask,
1788 IN BOOL bAuditSuccess,
1789 IN BOOL bAuditFailure)
1795 /******************************************************************************
1796 * LookupAccountNameA [ADVAPI32.@]
1804 LPSTR ReferencedDomainName,
1805 IN OUT LPDWORD cbReferencedDomainName,
1806 OUT PSID_NAME_USE name_use )
1808 /* Default implementation: Always return a default SID */
1809 SID_IDENTIFIER_AUTHORITY identifierAuthority = {SECURITY_NT_AUTHORITY};
1812 static const char dm[] = "DOMAIN";
1814 FIXME("(%s,%s,%p,%p,%p,%p,%p), stub.\n",system,account,sid,cbSid,ReferencedDomainName,cbReferencedDomainName,name_use);
1816 ret = AllocateAndInitializeSid(&identifierAuthority,
1818 SECURITY_BUILTIN_DOMAIN_RID,
1819 DOMAIN_ALIAS_RID_ADMINS,
1825 if(!RtlValidSid(pSid))
1831 if (sid != NULL && (*cbSid >= GetLengthSid(pSid)))
1832 CopySid(*cbSid, sid, pSid);
1833 if (*cbSid < GetLengthSid(pSid))
1835 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1838 *cbSid = GetLengthSid(pSid);
1840 if (ReferencedDomainName != NULL && (*cbReferencedDomainName > strlen(dm)))
1841 strcpy(ReferencedDomainName, dm);
1842 if (*cbReferencedDomainName <= strlen(dm))
1844 SetLastError(ERROR_INSUFFICIENT_BUFFER);
1847 *cbReferencedDomainName = strlen(dm)+1;
1854 BOOL WINAPI LookupAccountNameW( LPCWSTR lpSystemName, LPCWSTR lpAccountName, PSID Sid,
1855 LPDWORD cbSid, LPWSTR ReferencedDomainName,
1856 LPDWORD cchReferencedDomainName, PSID_NAME_USE peUse )
1858 FIXME("%s %s %p %p %p %p %p - stub\n", debugstr_w(lpSystemName), debugstr_w(lpAccountName),
1859 Sid, cbSid, ReferencedDomainName, cchReferencedDomainName, peUse);
1864 /******************************************************************************
1865 * PrivilegeCheck [ADVAPI32.@]
1867 BOOL WINAPI PrivilegeCheck( HANDLE ClientToken, PPRIVILEGE_SET RequiredPrivileges, LPBOOL pfResult)
1869 FIXME("stub %p %p %p\n", ClientToken, RequiredPrivileges, pfResult);
1875 /******************************************************************************
1876 * AccessCheckAndAuditAlarmA [ADVAPI32.@]
1878 BOOL WINAPI AccessCheckAndAuditAlarmA(LPCSTR Subsystem, LPVOID HandleId, LPSTR ObjectTypeName,
1879 LPSTR ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD DesiredAccess,
1880 PGENERIC_MAPPING GenericMapping, BOOL ObjectCreation, LPDWORD GrantedAccess,
1881 LPBOOL AccessStatus, LPBOOL pfGenerateOnClose)
1883 FIXME("stub (%s,%p,%s,%s,%p,%08lx,%p,%x,%p,%p,%p)\n", debugstr_a(Subsystem),
1884 HandleId, debugstr_a(ObjectTypeName), debugstr_a(ObjectName),
1885 SecurityDescriptor, DesiredAccess, GenericMapping,
1886 ObjectCreation, GrantedAccess, AccessStatus, pfGenerateOnClose);
1890 /******************************************************************************
1891 * AccessCheckAndAuditAlarmW [ADVAPI32.@]
1893 BOOL WINAPI AccessCheckAndAuditAlarmW(LPCWSTR Subsystem, LPVOID HandleId, LPWSTR ObjectTypeName,
1894 LPWSTR ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD DesiredAccess,
1895 PGENERIC_MAPPING GenericMapping, BOOL ObjectCreation, LPDWORD GrantedAccess,
1896 LPBOOL AccessStatus, LPBOOL pfGenerateOnClose)
1898 FIXME("stub (%s,%p,%s,%s,%p,%08lx,%p,%x,%p,%p,%p)\n", debugstr_w(Subsystem),
1899 HandleId, debugstr_w(ObjectTypeName), debugstr_w(ObjectName),
1900 SecurityDescriptor, DesiredAccess, GenericMapping,
1901 ObjectCreation, GrantedAccess, AccessStatus, pfGenerateOnClose);
1905 BOOL WINAPI ObjectCloseAuditAlarmA(LPCSTR SubsystemName, LPVOID HandleId, BOOL GenerateOnClose)
1907 FIXME("stub (%s,%p,%x)\n", debugstr_a(SubsystemName), HandleId, GenerateOnClose);
1912 BOOL WINAPI ObjectCloseAuditAlarmW(LPCWSTR SubsystemName, LPVOID HandleId, BOOL GenerateOnClose)
1914 FIXME("stub (%s,%p,%x)\n", debugstr_w(SubsystemName), HandleId, GenerateOnClose);
1919 BOOL WINAPI ObjectOpenAuditAlarmA(LPCSTR SubsystemName, LPVOID HandleId, LPSTR ObjectTypeName,
1920 LPSTR ObjectName, PSECURITY_DESCRIPTOR pSecurityDescriptor, HANDLE ClientToken, DWORD DesiredAccess,
1921 DWORD GrantedAccess, PPRIVILEGE_SET Privileges, BOOL ObjectCreation, BOOL AccessGranted,
1922 LPBOOL GenerateOnClose)
1924 FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08lx,0x%08lx,%p,%x,%x,%p)\n", debugstr_a(SubsystemName),
1925 HandleId, debugstr_a(ObjectTypeName), debugstr_a(ObjectName), pSecurityDescriptor,
1926 ClientToken, DesiredAccess, GrantedAccess, Privileges, ObjectCreation, AccessGranted,
1932 BOOL WINAPI ObjectOpenAuditAlarmW(LPCWSTR SubsystemName, LPVOID HandleId, LPWSTR ObjectTypeName,
1933 LPWSTR ObjectName, PSECURITY_DESCRIPTOR pSecurityDescriptor, HANDLE ClientToken, DWORD DesiredAccess,
1934 DWORD GrantedAccess, PPRIVILEGE_SET Privileges, BOOL ObjectCreation, BOOL AccessGranted,
1935 LPBOOL GenerateOnClose)
1937 FIXME("stub (%s,%p,%s,%s,%p,%p,0x%08lx,0x%08lx,%p,%x,%x,%p)\n", debugstr_w(SubsystemName),
1938 HandleId, debugstr_w(ObjectTypeName), debugstr_w(ObjectName), pSecurityDescriptor,
1939 ClientToken, DesiredAccess, GrantedAccess, Privileges, ObjectCreation, AccessGranted,
1945 BOOL WINAPI ObjectPrivilegeAuditAlarmA( LPCSTR SubsystemName, LPVOID HandleId, HANDLE ClientToken,
1946 DWORD DesiredAccess, PPRIVILEGE_SET Privileges, BOOL AccessGranted)
1948 FIXME("stub (%s,%p,%p,0x%08lx,%p,%x)\n", debugstr_a(SubsystemName), HandleId, ClientToken,
1949 DesiredAccess, Privileges, AccessGranted);
1954 BOOL WINAPI ObjectPrivilegeAuditAlarmW( LPCWSTR SubsystemName, LPVOID HandleId, HANDLE ClientToken,
1955 DWORD DesiredAccess, PPRIVILEGE_SET Privileges, BOOL AccessGranted)
1957 FIXME("stub (%s,%p,%p,0x%08lx,%p,%x)\n", debugstr_w(SubsystemName), HandleId, ClientToken,
1958 DesiredAccess, Privileges, AccessGranted);
1963 BOOL WINAPI PrivilegedServiceAuditAlarmA( LPCSTR SubsystemName, LPCSTR ServiceName, HANDLE ClientToken,
1964 PPRIVILEGE_SET Privileges, BOOL AccessGranted)
1966 FIXME("stub (%s,%s,%p,%p,%x)\n", debugstr_a(SubsystemName), debugstr_a(ServiceName),
1967 ClientToken, Privileges, AccessGranted);
1972 BOOL WINAPI PrivilegedServiceAuditAlarmW( LPCWSTR SubsystemName, LPCWSTR ServiceName, HANDLE ClientToken,
1973 PPRIVILEGE_SET Privileges, BOOL AccessGranted)
1975 FIXME("stub %s,%s,%p,%p,%x)\n", debugstr_w(SubsystemName), debugstr_w(ServiceName),
1976 ClientToken, Privileges, AccessGranted);
1981 /******************************************************************************
1982 * GetSecurityInfo [ADVAPI32.@]
1984 DWORD WINAPI GetSecurityInfo(
1985 HANDLE hObject, SE_OBJECT_TYPE ObjectType,
1986 SECURITY_INFORMATION SecurityInfo, PSID *ppsidOwner,
1987 PSID *ppsidGroup, PACL *ppDacl, PACL *ppSacl,
1988 PSECURITY_DESCRIPTOR *ppSecurityDescriptor
1992 return ERROR_BAD_PROVIDER;
1995 /******************************************************************************
1996 * GetSecurityInfoExW [ADVAPI32.@]
1998 DWORD WINAPI GetSecurityInfoExW(
1999 HANDLE hObject, SE_OBJECT_TYPE ObjectType,
2000 SECURITY_INFORMATION SecurityInfo, LPCWSTR lpProvider,
2001 LPCWSTR lpProperty, PACTRL_ACCESSW *ppAccessList,
2002 PACTRL_AUDITW *ppAuditList, LPWSTR *lppOwner, LPWSTR *lppGroup
2006 return ERROR_BAD_PROVIDER;
2009 /******************************************************************************
2010 * BuildExplicitAccessWithNameA [ADVAPI32.@]
2012 VOID WINAPI BuildExplicitAccessWithNameA( PEXPLICIT_ACCESSA pExplicitAccess,
2013 LPSTR pTrusteeName, DWORD AccessPermissions,
2014 ACCESS_MODE AccessMode, DWORD Inheritance )
2016 TRACE("%p %s 0x%08lx 0x%08x 0x%08lx\n", pExplicitAccess, debugstr_a(pTrusteeName),
2017 AccessPermissions, AccessMode, Inheritance);
2019 pExplicitAccess->grfAccessPermissions = AccessPermissions;
2020 pExplicitAccess->grfAccessMode = AccessMode;
2021 pExplicitAccess->grfInheritance = Inheritance;
2023 pExplicitAccess->Trustee.pMultipleTrustee = NULL;
2024 pExplicitAccess->Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2025 pExplicitAccess->Trustee.TrusteeForm = TRUSTEE_IS_NAME;
2026 pExplicitAccess->Trustee.TrusteeType = TRUSTEE_IS_UNKNOWN;
2027 pExplicitAccess->Trustee.ptstrName = pTrusteeName;
2030 /******************************************************************************
2031 * BuildExplicitAccessWithNameW [ADVAPI32.@]
2033 VOID WINAPI BuildExplicitAccessWithNameW( PEXPLICIT_ACCESSW pExplicitAccess,
2034 LPWSTR pTrusteeName, DWORD AccessPermissions,
2035 ACCESS_MODE AccessMode, DWORD Inheritance )
2037 TRACE("%p %s 0x%08lx 0x%08x 0x%08lx\n", pExplicitAccess, debugstr_w(pTrusteeName),
2038 AccessPermissions, AccessMode, Inheritance);
2040 pExplicitAccess->grfAccessPermissions = AccessPermissions;
2041 pExplicitAccess->grfAccessMode = AccessMode;
2042 pExplicitAccess->grfInheritance = Inheritance;
2044 pExplicitAccess->Trustee.pMultipleTrustee = NULL;
2045 pExplicitAccess->Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2046 pExplicitAccess->Trustee.TrusteeForm = TRUSTEE_IS_NAME;
2047 pExplicitAccess->Trustee.TrusteeType = TRUSTEE_IS_UNKNOWN;
2048 pExplicitAccess->Trustee.ptstrName = pTrusteeName;
2051 /******************************************************************************
2052 * BuildTrusteeWithObjectsAndNameA [ADVAPI32.@]
2054 VOID WINAPI BuildTrusteeWithObjectsAndNameA( PTRUSTEEA pTrustee, POBJECTS_AND_NAME_A pObjName,
2055 SE_OBJECT_TYPE ObjectType, LPSTR ObjectTypeName,
2056 LPSTR InheritedObjectTypeName, LPSTR Name )
2058 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee, pObjName,
2059 ObjectType, ObjectTypeName, InheritedObjectTypeName, debugstr_a(Name));
2061 pTrustee->pMultipleTrustee = NULL;
2062 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2063 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_NAME;
2064 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2065 pTrustee->ptstrName = Name;
2068 /******************************************************************************
2069 * BuildTrusteeWithObjectsAndNameW [ADVAPI32.@]
2071 VOID WINAPI BuildTrusteeWithObjectsAndNameW( PTRUSTEEW pTrustee, POBJECTS_AND_NAME_W pObjName,
2072 SE_OBJECT_TYPE ObjectType, LPWSTR ObjectTypeName,
2073 LPWSTR InheritedObjectTypeName, LPWSTR Name )
2075 TRACE("%p %p 0x%08x %p %p %s\n", pTrustee, pObjName,
2076 ObjectType, ObjectTypeName, InheritedObjectTypeName, debugstr_w(Name));
2078 pTrustee->pMultipleTrustee = NULL;
2079 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2080 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_NAME;
2081 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2082 pTrustee->ptstrName = Name;
2085 VOID WINAPI BuildTrusteeWithObjectsAndSidA( PTRUSTEEA pTrustee, POBJECTS_AND_SID pObjSid,
2086 GUID* pObjectGuid, GUID* pInheritedObjectGuid, PSID pSid )
2088 TRACE("%p %p %p %p %p\n", pTrustee, pObjSid, pObjectGuid, pInheritedObjectGuid, pSid);
2090 pTrustee->pMultipleTrustee = NULL;
2091 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2092 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_SID;
2093 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2094 pTrustee->ptstrName = (LPSTR) pSid;
2097 VOID WINAPI BuildTrusteeWithObjectsAndSidW( PTRUSTEEW pTrustee, POBJECTS_AND_SID pObjSid,
2098 GUID* pObjectGuid, GUID* pInheritedObjectGuid, PSID pSid )
2100 TRACE("%p %p %p %p %p\n", pTrustee, pObjSid, pObjectGuid, pInheritedObjectGuid, pSid);
2102 pTrustee->pMultipleTrustee = NULL;
2103 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2104 pTrustee->TrusteeForm = TRUSTEE_IS_OBJECTS_AND_SID;
2105 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2106 pTrustee->ptstrName = (LPWSTR) pSid;
2109 /******************************************************************************
2110 * BuildTrusteeWithSidA [ADVAPI32.@]
2112 VOID WINAPI BuildTrusteeWithSidA(PTRUSTEEA pTrustee, PSID pSid)
2114 TRACE("%p %p\n", pTrustee, pSid);
2116 pTrustee->pMultipleTrustee = NULL;
2117 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2118 pTrustee->TrusteeForm = TRUSTEE_IS_SID;
2119 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2120 pTrustee->ptstrName = (LPSTR) pSid;
2123 /******************************************************************************
2124 * BuildTrusteeWithSidW [ADVAPI32.@]
2126 VOID WINAPI BuildTrusteeWithSidW(PTRUSTEEW pTrustee, PSID pSid)
2128 TRACE("%p %p\n", pTrustee, pSid);
2130 pTrustee->pMultipleTrustee = NULL;
2131 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2132 pTrustee->TrusteeForm = TRUSTEE_IS_SID;
2133 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2134 pTrustee->ptstrName = (LPWSTR) pSid;
2137 /******************************************************************************
2138 * BuildTrusteeWithNameA [ADVAPI32.@]
2140 VOID WINAPI BuildTrusteeWithNameA(PTRUSTEEA pTrustee, LPSTR name)
2142 TRACE("%p %s\n", pTrustee, debugstr_a(name) );
2144 pTrustee->pMultipleTrustee = NULL;
2145 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2146 pTrustee->TrusteeForm = TRUSTEE_IS_NAME;
2147 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2148 pTrustee->ptstrName = name;
2151 /******************************************************************************
2152 * BuildTrusteeWithNameW [ADVAPI32.@]
2154 VOID WINAPI BuildTrusteeWithNameW(PTRUSTEEW pTrustee, LPWSTR name)
2156 TRACE("%p %s\n", pTrustee, debugstr_w(name) );
2158 pTrustee->pMultipleTrustee = NULL;
2159 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
2160 pTrustee->TrusteeForm = TRUSTEE_IS_NAME;
2161 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
2162 pTrustee->ptstrName = name;
2165 BOOL WINAPI SetAclInformation( PACL pAcl, LPVOID pAclInformation,
2166 DWORD nAclInformationLength,
2167 ACL_INFORMATION_CLASS dwAclInformationClass )
2169 FIXME("%p %p 0x%08lx 0x%08x - stub\n", pAcl, pAclInformation,
2170 nAclInformationLength, dwAclInformationClass);
2175 /******************************************************************************
2176 * SetEntriesInAclA [ADVAPI32.@]
2178 DWORD WINAPI SetEntriesInAclA( ULONG count, PEXPLICIT_ACCESSA pEntries,
2179 PACL OldAcl, PACL* NewAcl )
2181 FIXME("%ld %p %p %p\n",count,pEntries,OldAcl,NewAcl);
2182 return ERROR_CALL_NOT_IMPLEMENTED;
2185 /******************************************************************************
2186 * SetEntriesInAclW [ADVAPI32.@]
2188 DWORD WINAPI SetEntriesInAclW( ULONG count, PEXPLICIT_ACCESSW pEntries,
2189 PACL OldAcl, PACL* NewAcl )
2191 FIXME("%ld %p %p %p\n",count,pEntries,OldAcl,NewAcl);
2192 return ERROR_CALL_NOT_IMPLEMENTED;
2195 /******************************************************************************
2196 * SetNamedSecurityInfoA [ADVAPI32.@]
2198 DWORD WINAPI SetNamedSecurityInfoA(LPSTR pObjectName,
2199 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
2200 PSID psidOwner, PSID psidGroup, PACL pDacl, PACL pSacl)
2206 TRACE("%s %d %ld %p %p %p %p\n", debugstr_a(pObjectName), ObjectType,
2207 SecurityInfo, psidOwner, psidGroup, pDacl, pSacl);
2211 len = MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, NULL, 0 );
2212 wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR));
2213 MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, wstr, len );
2216 r = SetNamedSecurityInfoW( wstr, ObjectType, SecurityInfo, psidOwner,
2217 psidGroup, pDacl, pSacl );
2219 HeapFree( GetProcessHeap(), 0, wstr );
2224 BOOL WINAPI SetPrivateObjectSecurity( SECURITY_INFORMATION SecurityInformation,
2225 PSECURITY_DESCRIPTOR ModificationDescriptor,
2226 PSECURITY_DESCRIPTOR* ObjectsSecurityDescriptor,
2227 PGENERIC_MAPPING GenericMapping,
2230 FIXME("0x%08lx %p %p %p %p - stub\n", SecurityInformation, ModificationDescriptor,
2231 ObjectsSecurityDescriptor, GenericMapping, Token);
2236 BOOL WINAPI SetSecurityDescriptorControl( PSECURITY_DESCRIPTOR pSecurityDescriptor,
2237 SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest,
2238 SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet )
2240 FIXME("%p 0x%08x 0x%08x - stub\n", pSecurityDescriptor, ControlBitsOfInterest,
2246 BOOL WINAPI AreAllAccessesGranted( DWORD GrantedAccess, DWORD DesiredAccess )
2248 return RtlAreAllAccessesGranted( GrantedAccess, DesiredAccess );
2251 /******************************************************************************
2252 * AreAnyAccessesGranted [ADVAPI32.@]
2254 * Determines whether or not any of a set of specified access permissions have
2255 * been granted or not.
2258 * GrantedAccess [I] The permissions that have been granted.
2259 * DesiredAccess [I] The permissions that you want to have.
2262 * Nonzero if any of the permissions have been granted, zero if none of the
2263 * permissions have been granted.
2266 BOOL WINAPI AreAnyAccessesGranted( DWORD GrantedAccess, DWORD DesiredAccess )
2268 return RtlAreAnyAccessesGranted( GrantedAccess, DesiredAccess );
2271 /******************************************************************************
2272 * SetNamedSecurityInfoW [ADVAPI32.@]
2274 DWORD WINAPI SetNamedSecurityInfoW(LPWSTR pObjectName,
2275 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
2276 PSID psidOwner, PSID psidGroup, PACL pDacl, PACL pSacl)
2278 FIXME("%s %d %ld %p %p %p %p\n", debugstr_w(pObjectName), ObjectType,
2279 SecurityInfo, psidOwner, psidGroup, pDacl, pSacl);
2280 return ERROR_CALL_NOT_IMPLEMENTED;
2283 /******************************************************************************
2284 * GetExplicitEntriesFromAclA [ADVAPI32.@]
2286 DWORD WINAPI GetExplicitEntriesFromAclA( PACL pacl, PULONG pcCountOfExplicitEntries,
2287 PEXPLICIT_ACCESSA* pListOfExplicitEntries)
2289 FIXME("%p %p %p\n",pacl, pcCountOfExplicitEntries, pListOfExplicitEntries);
2290 return ERROR_CALL_NOT_IMPLEMENTED;
2293 /******************************************************************************
2294 * GetExplicitEntriesFromAclW [ADVAPI32.@]
2296 DWORD WINAPI GetExplicitEntriesFromAclW( PACL pacl, PULONG pcCountOfExplicitEntries,
2297 PEXPLICIT_ACCESSW* pListOfExplicitEntries)
2299 FIXME("%p %p %p\n",pacl, pcCountOfExplicitEntries, pListOfExplicitEntries);
2300 return ERROR_CALL_NOT_IMPLEMENTED;
2304 /******************************************************************************
2305 * ParseAclStringFlags
2307 static DWORD ParseAclStringFlags(LPCWSTR* StringAcl)
2310 LPCWSTR szAcl = *StringAcl;
2312 while (*szAcl != '(')
2316 flags |= SE_DACL_PROTECTED;
2318 else if (*szAcl == 'A')
2322 flags |= SE_DACL_AUTO_INHERIT_REQ;
2323 else if (*szAcl == 'I')
2324 flags |= SE_DACL_AUTO_INHERITED;
2333 /******************************************************************************
2334 * ParseAceStringType
2338 { SDDL_ACCESS_ALLOWED, ACCESS_ALLOWED_ACE_TYPE },
2339 { SDDL_ALARM, SYSTEM_ALARM_ACE_TYPE },
2340 { SDDL_AUDIT, SYSTEM_AUDIT_ACE_TYPE },
2341 { SDDL_ACCESS_DENIED, ACCESS_DENIED_ACE_TYPE },
2343 { SDDL_OBJECT_ACCESS_ALLOWED, ACCESS_ALLOWED_OBJECT_ACE_TYPE },
2344 { SDDL_OBJECT_ACCESS_DENIED, ACCESS_DENIED_OBJECT_ACE_TYPE },
2345 { SDDL_OBJECT_ALARM, SYSTEM_ALARM_OBJECT_ACE_TYPE },
2346 { SDDL_OBJECT_AUDIT, SYSTEM_AUDIT_OBJECT_ACE_TYPE },
2351 static BYTE ParseAceStringType(LPCWSTR* StringAcl)
2354 LPCWSTR szAcl = *StringAcl;
2355 LPACEFLAG lpaf = AceType;
2357 while (lpaf->wstr &&
2358 (len = strlenW(lpaf->wstr)) &&
2359 strncmpW(lpaf->wstr, szAcl, len))
2370 /******************************************************************************
2371 * ParseAceStringFlags
2373 ACEFLAG AceFlags[] =
2375 { SDDL_CONTAINER_INHERIT, CONTAINER_INHERIT_ACE },
2376 { SDDL_AUDIT_FAILURE, FAILED_ACCESS_ACE_FLAG },
2377 { SDDL_INHERITED, INHERITED_ACE },
2378 { SDDL_INHERIT_ONLY, INHERIT_ONLY_ACE },
2379 { SDDL_NO_PROPAGATE, NO_PROPAGATE_INHERIT_ACE },
2380 { SDDL_OBJECT_INHERIT, OBJECT_INHERIT_ACE },
2381 { SDDL_AUDIT_SUCCESS, SUCCESSFUL_ACCESS_ACE_FLAG },
2385 static BYTE ParseAceStringFlags(LPCWSTR* StringAcl)
2389 LPCWSTR szAcl = *StringAcl;
2391 while (*szAcl != ';')
2393 LPACEFLAG lpaf = AceFlags;
2395 while (lpaf->wstr &&
2396 (len = strlenW(lpaf->wstr)) &&
2397 strncmpW(lpaf->wstr, szAcl, len))
2403 flags |= lpaf->value;
2412 /******************************************************************************
2413 * ParseAceStringRights
2415 ACEFLAG AceRights[] =
2417 { SDDL_GENERIC_ALL, GENERIC_ALL },
2418 { SDDL_GENERIC_READ, GENERIC_READ },
2419 { SDDL_GENERIC_WRITE, GENERIC_WRITE },
2420 { SDDL_GENERIC_EXECUTE, GENERIC_EXECUTE },
2421 { SDDL_READ_CONTROL, READ_CONTROL },
2422 { SDDL_STANDARD_DELETE, DELETE },
2423 { SDDL_WRITE_DAC, WRITE_DAC },
2424 { SDDL_WRITE_OWNER, WRITE_OWNER },
2428 static DWORD ParseAceStringRights(LPCWSTR* StringAcl)
2432 LPCWSTR szAcl = *StringAcl;
2434 if ((*szAcl == '0') && (*(szAcl + 1) == 'x'))
2438 while (*p && *p != ';')
2443 rights = strtoulW(szAcl, NULL, 16);
2447 WARN("Invalid rights string format: %s\n", debugstr_wn(szAcl, p - szAcl));
2451 while (*szAcl != ';')
2453 LPACEFLAG lpaf = AceRights;
2455 while (lpaf->wstr &&
2456 (len = strlenW(lpaf->wstr)) &&
2457 strncmpW(lpaf->wstr, szAcl, len))
2465 rights |= lpaf->value;
2475 /******************************************************************************
2476 * ParseStringAclToAcl
2478 * dacl_flags(string_ace1)(string_ace2)... (string_acen)
2480 static BOOL ParseStringAclToAcl(LPCWSTR StringAcl, LPDWORD lpdwFlags,
2481 PACL pAcl, LPDWORD cBytes)
2485 DWORD length = sizeof(ACL);
2486 PACCESS_ALLOWED_ACE pAce = NULL; /* pointer to current ACE */
2488 TRACE("%s\n", debugstr_w(StringAcl));
2493 if (pAcl) /* pAce is only useful if we're setting values */
2494 pAce = (PACCESS_ALLOWED_ACE) ((LPBYTE)pAcl + sizeof(PACL));
2496 /* Parse ACL flags */
2497 *lpdwFlags = ParseAclStringFlags(&StringAcl);
2500 while (*StringAcl == '(')
2504 /* Parse ACE type */
2505 val = ParseAceStringType(&StringAcl);
2507 pAce->Header.AceType = (BYTE) val;
2508 if (*StringAcl != ';')
2512 /* Parse ACE flags */
2513 val = ParseAceStringFlags(&StringAcl);
2515 pAce->Header.AceFlags = (BYTE) val;
2516 if (*StringAcl != ';')
2520 /* Parse ACE rights */
2521 val = ParseAceStringRights(&StringAcl);
2524 if (*StringAcl != ';')
2528 /* Parse ACE object guid */
2529 if (*StringAcl != ';')
2531 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
2536 /* Parse ACE inherit object guid */
2537 if (*StringAcl != ';')
2539 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
2544 /* Parse ACE account sid */
2545 if (ParseStringSidToSid(StringAcl, pAce ? (PSID)&pAce->SidStart : NULL, &sidlen))
2547 while (*StringAcl && *StringAcl != ')')
2551 if (*StringAcl != ')')
2555 length += sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) + sidlen;
2562 WARN("Invalid ACE string format\n");
2567 /******************************************************************************
2568 * ParseStringSecurityDescriptorToSecurityDescriptor
2570 static BOOL ParseStringSecurityDescriptorToSecurityDescriptor(
2571 LPCWSTR StringSecurityDescriptor,
2572 SECURITY_DESCRIPTOR* SecurityDescriptor,
2577 WCHAR tok[MAX_PATH];
2579 LPBYTE lpNext = NULL;
2583 if (SecurityDescriptor)
2584 lpNext = ((LPBYTE) SecurityDescriptor) + sizeof(SECURITY_DESCRIPTOR);
2586 while (*StringSecurityDescriptor)
2588 toktype = *StringSecurityDescriptor;
2590 /* Expect char identifier followed by ':' */
2591 StringSecurityDescriptor++;
2592 if (*StringSecurityDescriptor != ':')
2594 SetLastError(ERROR_INVALID_PARAMETER);
2597 StringSecurityDescriptor++;
2600 lptoken = StringSecurityDescriptor;
2601 while (*lptoken && *lptoken != ':')
2607 strncpyW(tok, StringSecurityDescriptor, lptoken - StringSecurityDescriptor);
2615 if (!ParseStringSidToSid(tok, (PSID)lpNext, &bytes))
2618 if (SecurityDescriptor)
2620 SecurityDescriptor->Owner = (PSID) ((DWORD) lpNext -
2621 (DWORD) SecurityDescriptor);
2622 lpNext += bytes; /* Advance to next token */
2634 if (!ParseStringSidToSid(tok, (PSID)lpNext, &bytes))
2637 if (SecurityDescriptor)
2639 SecurityDescriptor->Group = (PSID) ((DWORD) lpNext -
2640 (DWORD) SecurityDescriptor);
2641 lpNext += bytes; /* Advance to next token */
2654 if (!ParseStringAclToAcl(tok, &flags, (PACL)lpNext, &bytes))
2657 if (SecurityDescriptor)
2659 SecurityDescriptor->Control |= SE_DACL_PRESENT | flags;
2660 SecurityDescriptor->Dacl = (PACL) ((DWORD) lpNext -
2661 (DWORD) SecurityDescriptor);
2662 lpNext += bytes; /* Advance to next token */
2675 if (!ParseStringAclToAcl(tok, &flags, (PACL)lpNext, &bytes))
2678 if (SecurityDescriptor)
2680 SecurityDescriptor->Control |= SE_SACL_PRESENT | flags;
2681 SecurityDescriptor->Sacl = (PACL) ((DWORD) lpNext -
2682 (DWORD) SecurityDescriptor);
2683 lpNext += bytes; /* Advance to next token */
2692 FIXME("Unknown token\n");
2693 SetLastError(ERROR_INVALID_PARAMETER);
2697 StringSecurityDescriptor = lptoken;
2706 /******************************************************************************
2707 * ConvertStringSecurityDescriptorToSecurityDescriptorA [ADVAPI32.@]
2709 BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorA(
2710 LPCSTR StringSecurityDescriptor,
2711 DWORD StringSDRevision,
2712 PSECURITY_DESCRIPTOR* SecurityDescriptor,
2713 PULONG SecurityDescriptorSize)
2717 LPWSTR StringSecurityDescriptorW;
2719 len = MultiByteToWideChar(CP_ACP, 0, StringSecurityDescriptor, -1, NULL, 0);
2720 StringSecurityDescriptorW = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
2722 if (StringSecurityDescriptorW)
2724 MultiByteToWideChar(CP_ACP, 0, StringSecurityDescriptor, -1, StringSecurityDescriptorW, len);
2726 ret = ConvertStringSecurityDescriptorToSecurityDescriptorW(StringSecurityDescriptorW,
2727 StringSDRevision, SecurityDescriptor,
2728 SecurityDescriptorSize);
2729 HeapFree(GetProcessHeap(), 0, StringSecurityDescriptorW);
2735 /******************************************************************************
2736 * ConvertStringSecurityDescriptorToSecurityDescriptorW [ADVAPI32.@]
2738 BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorW(
2739 LPCWSTR StringSecurityDescriptor,
2740 DWORD StringSDRevision,
2741 PSECURITY_DESCRIPTOR* SecurityDescriptor,
2742 PULONG SecurityDescriptorSize)
2745 SECURITY_DESCRIPTOR* psd;
2748 TRACE("%s\n", debugstr_w(StringSecurityDescriptor));
2750 if (GetVersion() & 0x80000000)
2752 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2755 else if (StringSDRevision != SID_REVISION)
2757 SetLastError(ERROR_UNKNOWN_REVISION);
2761 /* Compute security descriptor length */
2762 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor,
2766 psd = *SecurityDescriptor = (SECURITY_DESCRIPTOR*) LocalAlloc(
2767 GMEM_ZEROINIT, cBytes);
2769 psd->Revision = SID_REVISION;
2770 psd->Control |= SE_SELF_RELATIVE;
2772 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor,
2779 if (SecurityDescriptorSize)
2780 *SecurityDescriptorSize = cBytes;
2785 TRACE(" ret=%d\n", bret);
2789 /******************************************************************************
2790 * ConvertStringSidToSidW [ADVAPI32.@]
2792 BOOL WINAPI ConvertStringSidToSidW(LPCWSTR StringSid, PSID* Sid)
2797 TRACE("%s, %p\n", debugstr_w(StringSid), Sid);
2798 if (GetVersion() & 0x80000000)
2799 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2800 else if (!StringSid || !Sid)
2801 SetLastError(ERROR_INVALID_PARAMETER);
2802 else if (ParseStringSidToSid(StringSid, NULL, &cBytes))
2804 PSID pSid = *Sid = (PSID) LocalAlloc(0, cBytes);
2806 bret = ParseStringSidToSid(StringSid, pSid, &cBytes);
2810 TRACE("returning %s\n", bret ? "TRUE" : "FALSE");
2814 /******************************************************************************
2815 * ConvertStringSidToSidA [ADVAPI32.@]
2817 BOOL WINAPI ConvertStringSidToSidA(LPCSTR StringSid, PSID* Sid)
2821 TRACE("%s, %p\n", debugstr_a(StringSid), Sid);
2822 if (GetVersion() & 0x80000000)
2823 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2824 else if (!StringSid || !Sid)
2825 SetLastError(ERROR_INVALID_PARAMETER);
2828 UINT len = MultiByteToWideChar(CP_ACP, 0, StringSid, -1, NULL, 0);
2829 LPWSTR wStringSid = (LPWSTR)HeapAlloc(GetProcessHeap(), 0,
2830 len * sizeof(WCHAR));
2832 MultiByteToWideChar(CP_ACP, 0, StringSid, -1, wStringSid, len);
2833 bret = ConvertStringSidToSidW(wStringSid, Sid);
2834 HeapFree(GetProcessHeap(), 0, wStringSid);
2836 TRACE("returning %s\n", bret ? "TRUE" : "FALSE");
2840 /******************************************************************************
2841 * ConvertSidToStringSidW [ADVAPI32.@]
2843 * format of SID string is:
2844 * S-<count>-<auth>-<subauth1>-<subauth2>-<subauth3>...
2846 * <rev> is the revision of the SID encoded as decimal
2847 * <auth> is the identifier authority encoded as hex
2848 * <subauthN> is the subauthority id encoded as decimal
2850 BOOL WINAPI ConvertSidToStringSidW( PSID pSid, LPWSTR *pstr )
2854 WCHAR fmt[] = { 'S','-','%','u','-','%','d',0 };
2855 WCHAR subauthfmt[] = { '-','%','u',0 };
2858 TRACE("%p %p\n", pSid, pstr );
2860 if( !IsValidSid( pSid ) )
2863 if (pisid->Revision != SDDL_REVISION)
2865 if (pisid->IdentifierAuthority.Value[0] ||
2866 pisid->IdentifierAuthority.Value[1])
2868 FIXME("not matching MS' bugs\n");
2872 sz = 14 + pisid->SubAuthorityCount * 11;
2873 str = LocalAlloc( 0, sz*sizeof(WCHAR) );
2874 sprintfW( str, fmt, pisid->Revision, MAKELONG(
2875 MAKEWORD( pisid->IdentifierAuthority.Value[5],
2876 pisid->IdentifierAuthority.Value[4] ),
2877 MAKEWORD( pisid->IdentifierAuthority.Value[3],
2878 pisid->IdentifierAuthority.Value[2] ) ) );
2879 for( i=0; i<pisid->SubAuthorityCount; i++ )
2880 sprintfW( str + strlenW(str), subauthfmt, pisid->SubAuthority[i] );
2886 /******************************************************************************
2887 * ConvertSidToStringSidA [ADVAPI32.@]
2889 BOOL WINAPI ConvertSidToStringSidA(PSID pSid, LPSTR *pstr)
2895 TRACE("%p %p\n", pSid, pstr );
2897 if( !ConvertSidToStringSidW( pSid, &wstr ) )
2900 len = WideCharToMultiByte( CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL );
2901 str = LocalAlloc( 0, len );
2902 WideCharToMultiByte( CP_ACP, 0, wstr, -1, str, len, NULL, NULL );
2910 BOOL WINAPI CreatePrivateObjectSecurity(
2911 PSECURITY_DESCRIPTOR ParentDescriptor,
2912 PSECURITY_DESCRIPTOR CreatorDescriptor,
2913 PSECURITY_DESCRIPTOR* NewDescriptor,
2914 BOOL IsDirectoryObject,
2916 PGENERIC_MAPPING GenericMapping )
2918 FIXME("%p %p %p %d %p %p - stub\n", ParentDescriptor, CreatorDescriptor,
2919 NewDescriptor, IsDirectoryObject, Token, GenericMapping);
2924 BOOL WINAPI DestroyPrivateObjectSecurity( PSECURITY_DESCRIPTOR* ObjectDescriptor )
2926 FIXME("%p - stub\n", ObjectDescriptor);
2931 BOOL WINAPI CreateProcessAsUserA(
2933 LPCSTR lpApplicationName,
2934 LPSTR lpCommandLine,
2935 LPSECURITY_ATTRIBUTES lpProcessAttributes,
2936 LPSECURITY_ATTRIBUTES lpThreadAttributes,
2937 BOOL bInheritHandles,
2938 DWORD dwCreationFlags,
2939 LPVOID lpEnvironment,
2940 LPCSTR lpCurrentDirectory,
2941 LPSTARTUPINFOA lpStartupInfo,
2942 LPPROCESS_INFORMATION lpProcessInformation )
2944 FIXME("%p %s %s %p %p %d 0x%08lx %p %s %p %p - stub\n", hToken, debugstr_a(lpApplicationName),
2945 debugstr_a(lpCommandLine), lpProcessAttributes, lpThreadAttributes, bInheritHandles,
2946 dwCreationFlags, lpEnvironment, debugstr_a(lpCurrentDirectory), lpStartupInfo, lpProcessInformation);
2951 BOOL WINAPI CreateProcessAsUserW(
2953 LPCWSTR lpApplicationName,
2954 LPWSTR lpCommandLine,
2955 LPSECURITY_ATTRIBUTES lpProcessAttributes,
2956 LPSECURITY_ATTRIBUTES lpThreadAttributes,
2957 BOOL bInheritHandles,
2958 DWORD dwCreationFlags,
2959 LPVOID lpEnvironment,
2960 LPCWSTR lpCurrentDirectory,
2961 LPSTARTUPINFOW lpStartupInfo,
2962 LPPROCESS_INFORMATION lpProcessInformation )
2964 FIXME("%p %s %s %p %p %d 0x%08lx %p %s %p %p - stub\n", hToken, debugstr_w(lpApplicationName),
2965 debugstr_w(lpCommandLine), lpProcessAttributes, lpThreadAttributes, bInheritHandles,
2966 dwCreationFlags, lpEnvironment, debugstr_w(lpCurrentDirectory), lpStartupInfo, lpProcessInformation);
2971 /******************************************************************************
2972 * ComputeStringSidSize
2974 static DWORD ComputeStringSidSize(LPCWSTR StringSid)
2977 DWORD size = sizeof(SID);
2981 if (*StringSid == '-')
2987 size += (ctok - 3) * sizeof(DWORD);
2992 BOOL WINAPI DuplicateTokenEx(
2993 HANDLE ExistingTokenHandle, DWORD dwDesiredAccess,
2994 LPSECURITY_ATTRIBUTES lpTokenAttributes,
2995 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
2996 TOKEN_TYPE TokenType,
2997 PHANDLE DuplicateTokenHandle )
2999 FIXME("%p 0x%08lx 0x%08x 0x%08x %p - stub\n", ExistingTokenHandle, dwDesiredAccess,
3000 ImpersonationLevel, TokenType, DuplicateTokenHandle);
3005 BOOL WINAPI DuplicateToken(
3006 HANDLE ExistingTokenHandle,
3007 SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
3008 PHANDLE DuplicateTokenHandle )
3010 return DuplicateTokenEx( ExistingTokenHandle, 0, NULL, ImpersonationLevel,
3011 TokenImpersonation, DuplicateTokenHandle );
3014 BOOL WINAPI EnumDependentServicesA(
3016 DWORD dwServiceState,
3017 LPENUM_SERVICE_STATUSA lpServices,
3019 LPDWORD pcbBytesNeeded,
3020 LPDWORD lpServicesReturned )
3022 FIXME("%p 0x%08lx %p 0x%08lx %p %p - stub\n", hService, dwServiceState,
3023 lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned);
3028 BOOL WINAPI EnumDependentServicesW(
3030 DWORD dwServiceState,
3031 LPENUM_SERVICE_STATUSW lpServices,
3033 LPDWORD pcbBytesNeeded,
3034 LPDWORD lpServicesReturned )
3036 FIXME("%p 0x%08lx %p 0x%08lx %p %p - stub\n", hService, dwServiceState,
3037 lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned);
3042 /******************************************************************************
3043 * ParseStringSidToSid
3045 static BOOL ParseStringSidToSid(LPCWSTR StringSid, PSID pSid, LPDWORD cBytes)
3050 TRACE("%s, %p, %p\n", debugstr_w(StringSid), pSid, cBytes);
3053 SetLastError(ERROR_INVALID_PARAMETER);
3054 TRACE("StringSid is NULL, returning FALSE\n");
3058 *cBytes = ComputeStringSidSize(StringSid);
3059 if (!pisid) /* Simply compute the size */
3061 TRACE("only size requested, returning TRUE\n");
3065 if (*StringSid != 'S' || *StringSid != '-') /* S-R-I-S-S */
3067 DWORD i = 0, identAuth;
3068 DWORD csubauth = ((*cBytes - sizeof(SID)) / sizeof(DWORD)) + 1;
3070 StringSid += 2; /* Advance to Revision */
3071 pisid->Revision = atoiW(StringSid);
3073 if (pisid->Revision != SDDL_REVISION)
3075 TRACE("Revision %d is unknown\n", pisid->Revision);
3076 goto lend; /* ERROR_INVALID_SID */
3080 TRACE("SubAuthorityCount is 0\n");
3081 goto lend; /* ERROR_INVALID_SID */
3084 pisid->SubAuthorityCount = csubauth;
3086 /* Advance to identifier authority */
3087 while (*StringSid && *StringSid != '-')
3089 if (*StringSid == '-')
3092 /* MS' implementation can't handle values greater than 2^32 - 1, so
3093 * we don't either; assume most significant bytes are always 0
3095 pisid->IdentifierAuthority.Value[0] = 0;
3096 pisid->IdentifierAuthority.Value[1] = 0;
3097 identAuth = atoiW(StringSid);
3098 pisid->IdentifierAuthority.Value[5] = identAuth & 0xff;
3099 pisid->IdentifierAuthority.Value[4] = (identAuth & 0xff00) >> 8;
3100 pisid->IdentifierAuthority.Value[3] = (identAuth & 0xff0000) >> 16;
3101 pisid->IdentifierAuthority.Value[2] = (identAuth & 0xff000000) >> 24;
3103 /* Advance to first sub authority */
3104 while (*StringSid && *StringSid != '-')
3106 if (*StringSid == '-')
3111 while (*StringSid && *StringSid != '-')
3114 pisid->SubAuthority[i++] = atoiW(StringSid);
3117 if (i != pisid->SubAuthorityCount)
3118 goto lend; /* ERROR_INVALID_SID */
3122 else /* String constant format - Only available in winxp and above */
3124 pisid->Revision = SDDL_REVISION;
3125 pisid->SubAuthorityCount = 1;
3127 FIXME("String constant not supported: %s\n", debugstr_wn(StringSid, 2));
3129 /* TODO: Lookup string of well-known SIDs in table */
3130 pisid->IdentifierAuthority.Value[5] = 0;
3131 pisid->SubAuthority[0] = 0;
3138 SetLastError(ERROR_INVALID_SID);
3140 TRACE("returning %s\n", bret ? "TRUE" : "FALSE");
3144 /******************************************************************************
3145 * GetNamedSecurityInfoA [ADVAPI32.@]
3147 DWORD WINAPI GetNamedSecurityInfoA(LPSTR pObjectName,
3148 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
3149 PSID* ppsidOwner, PSID* ppsidGroup, PACL* ppDacl, PACL* ppSacl,
3150 PSECURITY_DESCRIPTOR* ppSecurityDescriptor)
3156 TRACE("%s %d %ld %p %p %p %p %p\n", pObjectName, ObjectType, SecurityInfo,
3157 ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor);
3161 len = MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, NULL, 0 );
3162 wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR));
3163 MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, wstr, len );
3166 r = GetNamedSecurityInfoW( wstr, ObjectType, SecurityInfo, ppsidOwner,
3167 ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor );
3169 HeapFree( GetProcessHeap(), 0, wstr );
3174 /******************************************************************************
3175 * GetNamedSecurityInfoW [ADVAPI32.@]
3177 DWORD WINAPI GetNamedSecurityInfoW(LPWSTR pObjectName,
3178 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
3179 PSID* ppsidOwner, PSID* ppsidGroup, PACL* ppDacl, PACL* ppSacl,
3180 PSECURITY_DESCRIPTOR* ppSecurityDescriptor)
3182 FIXME("%s %d %ld %p %p %p %p %p\n", debugstr_w(pObjectName), ObjectType, SecurityInfo,
3183 ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor);
3184 return ERROR_CALL_NOT_IMPLEMENTED;
3187 /******************************************************************************
3188 * DecryptFileW [ADVAPI32.@]
3190 BOOL WINAPI DecryptFileW(LPCWSTR lpFileName, DWORD dwReserved)
3192 FIXME("%s %08lx\n", debugstr_w(lpFileName), dwReserved);
3196 /******************************************************************************
3197 * DecryptFileA [ADVAPI32.@]
3199 BOOL WINAPI DecryptFileA(LPCSTR lpFileName, DWORD dwReserved)
3201 FIXME("%s %08lx\n", debugstr_a(lpFileName), dwReserved);
3205 /******************************************************************************
3206 * EncryptFileW [ADVAPI32.@]
3208 BOOL WINAPI EncryptFileW(LPCWSTR lpFileName)
3210 FIXME("%s\n", debugstr_w(lpFileName));
3214 /******************************************************************************
3215 * EncryptFileA [ADVAPI32.@]
3217 BOOL WINAPI EncryptFileA(LPCSTR lpFileName)
3219 FIXME("%s\n", debugstr_a(lpFileName));