Fix BuildTrusteeWithSid, implement and test BuildTrusteeWithName.
[wine/multimedia.git] / dlls / advapi32 / security.c
blobefa19b9768caf4740881aae8b078a51e126644a0
1 /*
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
19 * FIXME: for all functions thunking down to Rtl* functions: implement SetLastError()
22 #include <stdarg.h>
23 #include <string.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "rpcnterr.h"
29 #include "winreg.h"
30 #include "winternl.h"
31 #include "ntstatus.h"
32 #include "ntsecapi.h"
33 #include "accctrl.h"
34 #include "sddl.h"
36 #include "aclapi.h"
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,
52 LPDWORD cBytes);
53 static DWORD ParseAclStringFlags(LPCWSTR* StringAcl);
55 typedef struct _ACEFLAG
57 LPCWSTR wstr;
58 DWORD value;
59 } ACEFLAG, *LPACEFLAG;
62 * ACE access rights
64 static const WCHAR SDDL_READ_CONTROL[] = {'R','C',0};
65 static const WCHAR SDDL_WRITE_DAC[] = {'W','D',0};
66 static const WCHAR SDDL_WRITE_OWNER[] = {'W','O',0};
67 static const WCHAR SDDL_STANDARD_DELETE[] = {'S','D',0};
68 static const WCHAR SDDL_GENERIC_ALL[] = {'G','A',0};
69 static const WCHAR SDDL_GENERIC_READ[] = {'G','R',0};
70 static const WCHAR SDDL_GENERIC_WRITE[] = {'G','W',0};
71 static const WCHAR SDDL_GENERIC_EXECUTE[] = {'G','X',0};
74 * ACE types
76 static const WCHAR SDDL_ACCESS_ALLOWED[] = {'A',0};
77 static const WCHAR SDDL_ACCESS_DENIED[] = {'D',0};
78 static const WCHAR SDDL_OBJECT_ACCESS_ALLOWED[] = {'O','A',0};
79 static const WCHAR SDDL_OBJECT_ACCESS_DENIED[] = {'O','D',0};
80 static const WCHAR SDDL_AUDIT[] = {'A','U',0};
81 static const WCHAR SDDL_ALARM[] = {'A','L',0};
82 static const WCHAR SDDL_OBJECT_AUDIT[] = {'O','U',0};
83 static const WCHAR SDDL_OBJECT_ALARMp[] = {'O','L',0};
86 * ACE flags
88 static const WCHAR SDDL_CONTAINER_INHERIT[] = {'C','I',0};
89 static const WCHAR SDDL_OBJECT_INHERIT[] = {'O','I',0};
90 static const WCHAR SDDL_NO_PROPAGATE[] = {'N','P',0};
91 static const WCHAR SDDL_INHERIT_ONLY[] = {'I','O',0};
92 static const WCHAR SDDL_INHERITED[] = {'I','D',0};
93 static const WCHAR SDDL_AUDIT_SUCCESS[] = {'S','A',0};
94 static const WCHAR SDDL_AUDIT_FAILURE[] = {'F','A',0};
96 #define CallWin32ToNt(func) \
97 { NTSTATUS ret; \
98 ret = (func); \
99 if (ret !=STATUS_SUCCESS) \
100 { SetLastError (RtlNtStatusToDosError(ret)); return FALSE; } \
101 return TRUE; \
104 static void dumpLsaAttributes( PLSA_OBJECT_ATTRIBUTES oa )
106 if (oa)
108 TRACE("\n\tlength=%lu, rootdir=%p, objectname=%s\n\tattr=0x%08lx, sid=%p qos=%p\n",
109 oa->Length, oa->RootDirectory,
110 oa->ObjectName?debugstr_w(oa->ObjectName->Buffer):"null",
111 oa->Attributes, oa->SecurityDescriptor, oa->SecurityQualityOfService);
115 /************************************************************
116 * ADVAPI_IsLocalComputer
118 * Checks whether the server name indicates local machine.
120 BOOL ADVAPI_IsLocalComputer(LPCWSTR ServerName)
122 if (!ServerName)
124 return TRUE;
126 else
128 DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
129 BOOL Result;
130 LPWSTR buf;
132 buf = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
133 Result = GetComputerNameW(buf, &dwSize);
134 if (Result && (ServerName[0] == '\\') && (ServerName[1] == '\\'))
135 ServerName += 2;
136 Result = Result && !lstrcmpW(ServerName, buf);
137 HeapFree(GetProcessHeap(), 0, buf);
139 return Result;
143 #define ADVAPI_ForceLocalComputer(ServerName, FailureCode) \
144 if (!ADVAPI_IsLocalComputer(ServerName)) \
146 FIXME("Action Implemented for local computer only. " \
147 "Requested for server %s\n", debugstr_w(ServerName)); \
148 return FailureCode; \
151 /* ##############################
152 ###### TOKEN FUNCTIONS ######
153 ##############################
156 /******************************************************************************
157 * OpenProcessToken [ADVAPI32.@]
158 * Opens the access token associated with a process handle.
160 * PARAMS
161 * ProcessHandle [I] Handle to process
162 * DesiredAccess [I] Desired access to process
163 * TokenHandle [O] Pointer to handle of open access token
165 * RETURNS
166 * Success: TRUE. TokenHandle contains the access token.
167 * Failure: FALSE.
169 * NOTES
170 * See NtOpenProcessToken.
172 BOOL WINAPI
173 OpenProcessToken( HANDLE ProcessHandle, DWORD DesiredAccess,
174 HANDLE *TokenHandle )
176 CallWin32ToNt(NtOpenProcessToken( ProcessHandle, DesiredAccess, TokenHandle ));
179 /******************************************************************************
180 * OpenThreadToken [ADVAPI32.@]
182 * Opens the access token associated with a thread handle.
184 * PARAMS
185 * ThreadHandle [I] Handle to process
186 * DesiredAccess [I] Desired access to the thread
187 * OpenAsSelf [I] ???
188 * TokenHandle [O] Destination for the token handle
190 * RETURNS
191 * Success: TRUE. TokenHandle contains the access token.
192 * Failure: FALSE.
194 * NOTES
195 * See NtOpenThreadToken.
197 BOOL WINAPI
198 OpenThreadToken( HANDLE ThreadHandle, DWORD DesiredAccess,
199 BOOL OpenAsSelf, HANDLE *TokenHandle)
201 CallWin32ToNt (NtOpenThreadToken(ThreadHandle, DesiredAccess, OpenAsSelf, TokenHandle));
204 /******************************************************************************
205 * AdjustTokenPrivileges [ADVAPI32.@]
207 * Adjust the privileges of an open token handle.
209 * PARAMS
210 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
211 * DisableAllPrivileges [I] TRUE=Remove all privileges, FALSE=Use NewState
212 * NewState [I] Desired new privileges of the token
213 * BufferLength [I] Length of NewState
214 * PreviousState [O] Destination for the previous state
215 * ReturnLength [I/O] Size of PreviousState
218 * RETURNS
219 * Success: TRUE. Privileges are set to NewState and PreviousState is updated.
220 * Failure: FALSE.
222 * NOTES
223 * See NtAdjustPrivilegesToken.
225 BOOL WINAPI
226 AdjustTokenPrivileges( HANDLE TokenHandle, BOOL DisableAllPrivileges,
227 LPVOID NewState, DWORD BufferLength,
228 LPVOID PreviousState, LPDWORD ReturnLength )
230 CallWin32ToNt(NtAdjustPrivilegesToken(TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength));
233 /******************************************************************************
234 * CheckTokenMembership [ADVAPI32.@]
236 * Determine if an access token is a member of a SID.
238 * PARAMS
239 * TokenHandle [I] Handle from OpenProcessToken() or OpenThreadToken()
240 * SidToCheck [I] SID that possibly contains the token
241 * IsMember [O] Destination for result.
243 * RETURNS
244 * Success: TRUE. IsMember is TRUE if TokenHandle is a member, FALSE otherwise.
245 * Failure: FALSE.
247 BOOL WINAPI
248 CheckTokenMembership( HANDLE TokenHandle, PSID SidToCheck,
249 PBOOL IsMember )
251 FIXME("(%p %p %p) stub!\n", TokenHandle, SidToCheck, IsMember);
253 *IsMember = TRUE;
254 return(TRUE);
257 /******************************************************************************
258 * GetTokenInformation [ADVAPI32.@]
260 * PARAMS
261 * token [I] Handle from OpenProcessToken() or OpenThreadToken()
262 * tokeninfoclass [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
263 * tokeninfo [O] Destination for token information
264 * tokeninfolength [I] Length of tokeninfo
265 * retlen [O] Destination for returned token information length
267 * RETURNS
268 * Success: TRUE. tokeninfo contains retlen bytes of token information
269 * Failure: FALSE.
271 * NOTES
272 * See NtQueryInformationToken.
274 BOOL WINAPI
275 GetTokenInformation( HANDLE token, TOKEN_INFORMATION_CLASS tokeninfoclass,
276 LPVOID tokeninfo, DWORD tokeninfolength, LPDWORD retlen )
278 TRACE("(%p, %s, %p, %ld, %p): \n",
279 token,
280 (tokeninfoclass == TokenUser) ? "TokenUser" :
281 (tokeninfoclass == TokenGroups) ? "TokenGroups" :
282 (tokeninfoclass == TokenPrivileges) ? "TokenPrivileges" :
283 (tokeninfoclass == TokenOwner) ? "TokenOwner" :
284 (tokeninfoclass == TokenPrimaryGroup) ? "TokenPrimaryGroup" :
285 (tokeninfoclass == TokenDefaultDacl) ? "TokenDefaultDacl" :
286 (tokeninfoclass == TokenSource) ? "TokenSource" :
287 (tokeninfoclass == TokenType) ? "TokenType" :
288 (tokeninfoclass == TokenImpersonationLevel) ? "TokenImpersonationLevel" :
289 (tokeninfoclass == TokenStatistics) ? "TokenStatistics" :
290 (tokeninfoclass == TokenRestrictedSids) ? "TokenRestrictedSids" :
291 (tokeninfoclass == TokenSessionId) ? "TokenSessionId" :
292 (tokeninfoclass == TokenGroupsAndPrivileges) ? "TokenGroupsAndPrivileges" :
293 (tokeninfoclass == TokenSessionReference) ? "TokenSessionReference" :
294 (tokeninfoclass == TokenSandBoxInert) ? "TokenSandBoxInert" :
295 "Unknown",
296 tokeninfo, tokeninfolength, retlen);
297 CallWin32ToNt (NtQueryInformationToken( token, tokeninfoclass, tokeninfo, tokeninfolength, retlen));
300 /******************************************************************************
301 * SetTokenInformation [ADVAPI32.@]
303 * Set information for an access token.
305 * PARAMS
306 * token [I] Handle from OpenProcessToken() or OpenThreadToken()
307 * tokeninfoclass [I] A TOKEN_INFORMATION_CLASS from "winnt.h"
308 * tokeninfo [I] Token information to set
309 * tokeninfolength [I] Length of tokeninfo
311 * RETURNS
312 * Success: TRUE. The information for the token is set to tokeninfo.
313 * Failure: FALSE.
315 BOOL WINAPI
316 SetTokenInformation( HANDLE token, TOKEN_INFORMATION_CLASS tokeninfoclass,
317 LPVOID tokeninfo, DWORD tokeninfolength )
319 FIXME("(%p, %s, %p, %ld): stub\n",
320 token,
321 (tokeninfoclass == TokenUser) ? "TokenUser" :
322 (tokeninfoclass == TokenGroups) ? "TokenGroups" :
323 (tokeninfoclass == TokenPrivileges) ? "TokenPrivileges" :
324 (tokeninfoclass == TokenOwner) ? "TokenOwner" :
325 (tokeninfoclass == TokenPrimaryGroup) ? "TokenPrimaryGroup" :
326 (tokeninfoclass == TokenDefaultDacl) ? "TokenDefaultDacl" :
327 (tokeninfoclass == TokenSource) ? "TokenSource" :
328 (tokeninfoclass == TokenType) ? "TokenType" :
329 (tokeninfoclass == TokenImpersonationLevel) ? "TokenImpersonationLevel" :
330 (tokeninfoclass == TokenStatistics) ? "TokenStatistics" :
331 (tokeninfoclass == TokenRestrictedSids) ? "TokenRestrictedSids" :
332 (tokeninfoclass == TokenSessionId) ? "TokenSessionId" :
333 (tokeninfoclass == TokenGroupsAndPrivileges) ? "TokenGroupsAndPrivileges" :
334 (tokeninfoclass == TokenSessionReference) ? "TokenSessionReference" :
335 (tokeninfoclass == TokenSandBoxInert) ? "TokenSandBoxInert" :
336 "Unknown",
337 tokeninfo, tokeninfolength);
339 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
341 return FALSE;
344 /*************************************************************************
345 * SetThreadToken [ADVAPI32.@]
347 * Assigns an 'impersonation token' to a thread so it can assume the
348 * security privileges of another thread or process. Can also remove
349 * a previously assigned token.
351 * PARAMS
352 * thread [O] Handle to thread to set the token for
353 * token [I] Token to set
355 * RETURNS
356 * Success: TRUE. The threads access token is set to token
357 * Failure: FALSE.
359 * NOTES
360 * Only supported on NT or higher. On Win9X this function does nothing.
361 * See SetTokenInformation.
363 BOOL WINAPI SetThreadToken(PHANDLE thread, HANDLE token)
365 CallWin32ToNt (NtSetInformationThread( thread ? *thread : GetCurrentThread(),
366 ThreadImpersonationToken, &token, sizeof token ));
369 /* ##############################
370 ###### SID FUNCTIONS ######
371 ##############################
374 /******************************************************************************
375 * AllocateAndInitializeSid [ADVAPI32.@]
377 * PARAMS
378 * pIdentifierAuthority []
379 * nSubAuthorityCount []
380 * nSubAuthority0 []
381 * nSubAuthority1 []
382 * nSubAuthority2 []
383 * nSubAuthority3 []
384 * nSubAuthority4 []
385 * nSubAuthority5 []
386 * nSubAuthority6 []
387 * nSubAuthority7 []
388 * pSid []
390 BOOL WINAPI
391 AllocateAndInitializeSid( PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
392 BYTE nSubAuthorityCount,
393 DWORD nSubAuthority0, DWORD nSubAuthority1,
394 DWORD nSubAuthority2, DWORD nSubAuthority3,
395 DWORD nSubAuthority4, DWORD nSubAuthority5,
396 DWORD nSubAuthority6, DWORD nSubAuthority7,
397 PSID *pSid )
399 CallWin32ToNt (RtlAllocateAndInitializeSid(
400 pIdentifierAuthority, nSubAuthorityCount,
401 nSubAuthority0, nSubAuthority1, nSubAuthority2, nSubAuthority3,
402 nSubAuthority4, nSubAuthority5, nSubAuthority6, nSubAuthority7,
403 pSid ));
406 /******************************************************************************
407 * FreeSid [ADVAPI32.@]
409 * PARAMS
410 * pSid []
412 PVOID WINAPI
413 FreeSid( PSID pSid )
415 RtlFreeSid(pSid);
416 return NULL; /* is documented like this */
419 /******************************************************************************
420 * CopySid [ADVAPI32.@]
422 * PARAMS
423 * nDestinationSidLength []
424 * pDestinationSid []
425 * pSourceSid []
427 BOOL WINAPI
428 CopySid( DWORD nDestinationSidLength, PSID pDestinationSid, PSID pSourceSid )
430 return RtlCopySid(nDestinationSidLength, pDestinationSid, pSourceSid);
433 /******************************************************************************
434 * IsValidSid [ADVAPI32.@]
436 * PARAMS
437 * pSid []
439 BOOL WINAPI
440 IsValidSid( PSID pSid )
442 return RtlValidSid( pSid );
445 /******************************************************************************
446 * EqualSid [ADVAPI32.@]
448 * PARAMS
449 * pSid1 []
450 * pSid2 []
452 BOOL WINAPI
453 EqualSid( PSID pSid1, PSID pSid2 )
455 return RtlEqualSid( pSid1, pSid2 );
458 /******************************************************************************
459 * EqualPrefixSid [ADVAPI32.@]
461 BOOL WINAPI EqualPrefixSid (PSID pSid1, PSID pSid2)
463 return RtlEqualPrefixSid(pSid1, pSid2);
466 /******************************************************************************
467 * GetSidLengthRequired [ADVAPI32.@]
469 * PARAMS
470 * nSubAuthorityCount []
472 DWORD WINAPI
473 GetSidLengthRequired( BYTE nSubAuthorityCount )
475 return RtlLengthRequiredSid(nSubAuthorityCount);
478 /******************************************************************************
479 * InitializeSid [ADVAPI32.@]
481 * PARAMS
482 * pIdentifierAuthority []
484 BOOL WINAPI
485 InitializeSid (
486 PSID pSid,
487 PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
488 BYTE nSubAuthorityCount)
490 return RtlInitializeSid(pSid, pIdentifierAuthority, nSubAuthorityCount);
493 /******************************************************************************
494 * GetSidIdentifierAuthority [ADVAPI32.@]
496 * PARAMS
497 * pSid []
499 PSID_IDENTIFIER_AUTHORITY WINAPI
500 GetSidIdentifierAuthority( PSID pSid )
502 return RtlIdentifierAuthoritySid(pSid);
505 /******************************************************************************
506 * GetSidSubAuthority [ADVAPI32.@]
508 * PARAMS
509 * pSid []
510 * nSubAuthority []
512 PDWORD WINAPI
513 GetSidSubAuthority( PSID pSid, DWORD nSubAuthority )
515 return RtlSubAuthoritySid(pSid, nSubAuthority);
518 /******************************************************************************
519 * GetSidSubAuthorityCount [ADVAPI32.@]
521 * PARAMS
522 * pSid []
524 PUCHAR WINAPI
525 GetSidSubAuthorityCount (PSID pSid)
527 return RtlSubAuthorityCountSid(pSid);
530 /******************************************************************************
531 * GetLengthSid [ADVAPI32.@]
533 * PARAMS
534 * pSid []
536 DWORD WINAPI
537 GetLengthSid (PSID pSid)
539 return RtlLengthSid(pSid);
542 /* ##############################################
543 ###### SECURITY DESCRIPTOR FUNCTIONS ######
544 ##############################################
547 /******************************************************************************
548 * InitializeSecurityDescriptor [ADVAPI32.@]
550 * PARAMS
551 * pDescr []
552 * revision []
554 BOOL WINAPI
555 InitializeSecurityDescriptor( PSECURITY_DESCRIPTOR pDescr, DWORD revision )
557 CallWin32ToNt (RtlCreateSecurityDescriptor(pDescr, revision ));
561 /******************************************************************************
562 * MakeAbsoluteSD [ADVAPI32.@]
564 BOOL WINAPI MakeAbsoluteSD (
565 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
566 OUT PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
567 OUT LPDWORD lpdwAbsoluteSecurityDescriptorSize,
568 OUT PACL pDacl,
569 OUT LPDWORD lpdwDaclSize,
570 OUT PACL pSacl,
571 OUT LPDWORD lpdwSaclSize,
572 OUT PSID pOwner,
573 OUT LPDWORD lpdwOwnerSize,
574 OUT PSID pPrimaryGroup,
575 OUT LPDWORD lpdwPrimaryGroupSize)
577 CallWin32ToNt (RtlSelfRelativeToAbsoluteSD(pSelfRelativeSecurityDescriptor,
578 pAbsoluteSecurityDescriptor, lpdwAbsoluteSecurityDescriptorSize,
579 pDacl, lpdwDaclSize, pSacl, lpdwSaclSize, pOwner, lpdwOwnerSize,
580 pPrimaryGroup, lpdwPrimaryGroupSize));
584 /******************************************************************************
585 * GetSecurityDescriptorLength [ADVAPI32.@]
587 DWORD WINAPI GetSecurityDescriptorLength( PSECURITY_DESCRIPTOR pDescr)
589 return (RtlLengthSecurityDescriptor(pDescr));
592 /******************************************************************************
593 * GetSecurityDescriptorOwner [ADVAPI32.@]
595 * PARAMS
596 * pOwner []
597 * lpbOwnerDefaulted []
599 BOOL WINAPI
600 GetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pDescr, PSID *pOwner,
601 LPBOOL lpbOwnerDefaulted )
603 CallWin32ToNt (RtlGetOwnerSecurityDescriptor( pDescr, pOwner, (PBOOLEAN)lpbOwnerDefaulted ));
606 /******************************************************************************
607 * SetSecurityDescriptorOwner [ADVAPI32.@]
609 * PARAMS
611 BOOL WINAPI SetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pSecurityDescriptor,
612 PSID pOwner, BOOL bOwnerDefaulted)
614 CallWin32ToNt (RtlSetOwnerSecurityDescriptor(pSecurityDescriptor, pOwner, bOwnerDefaulted));
616 /******************************************************************************
617 * GetSecurityDescriptorGroup [ADVAPI32.@]
619 BOOL WINAPI GetSecurityDescriptorGroup(
620 PSECURITY_DESCRIPTOR SecurityDescriptor,
621 PSID *Group,
622 LPBOOL GroupDefaulted)
624 CallWin32ToNt (RtlGetGroupSecurityDescriptor(SecurityDescriptor, Group, (PBOOLEAN)GroupDefaulted));
626 /******************************************************************************
627 * SetSecurityDescriptorGroup [ADVAPI32.@]
629 BOOL WINAPI SetSecurityDescriptorGroup ( PSECURITY_DESCRIPTOR SecurityDescriptor,
630 PSID Group, BOOL GroupDefaulted)
632 CallWin32ToNt (RtlSetGroupSecurityDescriptor( SecurityDescriptor, Group, GroupDefaulted));
635 /******************************************************************************
636 * IsValidSecurityDescriptor [ADVAPI32.@]
638 * PARAMS
639 * lpsecdesc []
641 BOOL WINAPI
642 IsValidSecurityDescriptor( PSECURITY_DESCRIPTOR SecurityDescriptor )
644 CallWin32ToNt (RtlValidSecurityDescriptor(SecurityDescriptor));
647 /******************************************************************************
648 * GetSecurityDescriptorDacl [ADVAPI32.@]
650 BOOL WINAPI GetSecurityDescriptorDacl(
651 IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
652 OUT LPBOOL lpbDaclPresent,
653 OUT PACL *pDacl,
654 OUT LPBOOL lpbDaclDefaulted)
656 CallWin32ToNt (RtlGetDaclSecurityDescriptor(pSecurityDescriptor, (PBOOLEAN)lpbDaclPresent,
657 pDacl, (PBOOLEAN)lpbDaclDefaulted));
660 /******************************************************************************
661 * SetSecurityDescriptorDacl [ADVAPI32.@]
663 BOOL WINAPI
664 SetSecurityDescriptorDacl (
665 PSECURITY_DESCRIPTOR lpsd,
666 BOOL daclpresent,
667 PACL dacl,
668 BOOL dacldefaulted )
670 CallWin32ToNt (RtlSetDaclSecurityDescriptor (lpsd, daclpresent, dacl, dacldefaulted ));
672 /******************************************************************************
673 * GetSecurityDescriptorSacl [ADVAPI32.@]
675 BOOL WINAPI GetSecurityDescriptorSacl(
676 IN PSECURITY_DESCRIPTOR lpsd,
677 OUT LPBOOL lpbSaclPresent,
678 OUT PACL *pSacl,
679 OUT LPBOOL lpbSaclDefaulted)
681 CallWin32ToNt (RtlGetSaclSecurityDescriptor(lpsd,
682 (PBOOLEAN)lpbSaclPresent, pSacl, (PBOOLEAN)lpbSaclDefaulted));
685 /**************************************************************************
686 * SetSecurityDescriptorSacl [ADVAPI32.@]
688 BOOL WINAPI SetSecurityDescriptorSacl (
689 PSECURITY_DESCRIPTOR lpsd,
690 BOOL saclpresent,
691 PACL lpsacl,
692 BOOL sacldefaulted)
694 CallWin32ToNt (RtlSetSaclSecurityDescriptor(lpsd, saclpresent, lpsacl, sacldefaulted));
696 /******************************************************************************
697 * MakeSelfRelativeSD [ADVAPI32.@]
699 * PARAMS
700 * lpabssecdesc []
701 * lpselfsecdesc []
702 * lpbuflen []
704 BOOL WINAPI
705 MakeSelfRelativeSD(
706 IN PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
707 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
708 IN OUT LPDWORD lpdwBufferLength)
710 CallWin32ToNt (RtlMakeSelfRelativeSD(pAbsoluteSecurityDescriptor,pSelfRelativeSecurityDescriptor, lpdwBufferLength));
713 /******************************************************************************
714 * GetSecurityDescriptorControl [ADVAPI32.@]
717 BOOL WINAPI GetSecurityDescriptorControl ( PSECURITY_DESCRIPTOR pSecurityDescriptor,
718 PSECURITY_DESCRIPTOR_CONTROL pControl, LPDWORD lpdwRevision)
720 CallWin32ToNt (RtlGetControlSecurityDescriptor(pSecurityDescriptor,pControl,lpdwRevision));
723 /* ##############################
724 ###### ACL FUNCTIONS ######
725 ##############################
728 /*************************************************************************
729 * InitializeAcl [ADVAPI32.@]
731 DWORD WINAPI InitializeAcl(PACL acl, DWORD size, DWORD rev)
733 CallWin32ToNt (RtlCreateAcl(acl, size, rev));
736 /******************************************************************************
737 * AddAccessAllowedAce [ADVAPI32.@]
739 BOOL WINAPI AddAccessAllowedAce(
740 IN OUT PACL pAcl,
741 IN DWORD dwAceRevision,
742 IN DWORD AccessMask,
743 IN PSID pSid)
745 CallWin32ToNt(RtlAddAccessAllowedAce(pAcl, dwAceRevision, AccessMask, pSid));
748 /******************************************************************************
749 * AddAccessAllowedAceEx [ADVAPI32.@]
751 BOOL WINAPI AddAccessAllowedAceEx(
752 IN OUT PACL pAcl,
753 IN DWORD dwAceRevision,
754 IN DWORD AceFlags,
755 IN DWORD AccessMask,
756 IN PSID pSid)
758 CallWin32ToNt(RtlAddAccessAllowedAceEx(pAcl, dwAceRevision, AceFlags, AccessMask, pSid));
761 /******************************************************************************
762 * AddAccessDeniedAce [ADVAPI32.@]
764 BOOL WINAPI AddAccessDeniedAce(
765 IN OUT PACL pAcl,
766 IN DWORD dwAceRevision,
767 IN DWORD AccessMask,
768 IN PSID pSid)
770 CallWin32ToNt(RtlAddAccessDeniedAce(pAcl, dwAceRevision, AccessMask, pSid));
773 /******************************************************************************
774 * AddAccessDeniedAceEx [ADVAPI32.@]
776 BOOL WINAPI AddAccessDeniedAceEx(
777 IN OUT PACL pAcl,
778 IN DWORD dwAceRevision,
779 IN DWORD AceFlags,
780 IN DWORD AccessMask,
781 IN PSID pSid)
783 CallWin32ToNt(RtlAddAccessDeniedAceEx(pAcl, dwAceRevision, AceFlags, AccessMask, pSid));
786 /******************************************************************************
787 * AddAce [ADVAPI32.@]
789 BOOL WINAPI AddAce(
790 IN OUT PACL pAcl,
791 IN DWORD dwAceRevision,
792 IN DWORD dwStartingAceIndex,
793 LPVOID pAceList,
794 DWORD nAceListLength)
796 CallWin32ToNt(RtlAddAce(pAcl, dwAceRevision, dwStartingAceIndex, pAceList, nAceListLength));
799 /******************************************************************************
800 * DeleteAce [ADVAPI32.@]
802 BOOL WINAPI DeleteAce(PACL pAcl, DWORD dwAceIndex)
804 CallWin32ToNt(RtlDeleteAce(pAcl, dwAceIndex));
807 /******************************************************************************
808 * FindFirstFreeAce [ADVAPI32.@]
810 BOOL WINAPI FindFirstFreeAce(IN PACL pAcl, LPVOID * pAce)
812 return RtlFirstFreeAce(pAcl, (PACE_HEADER *)pAce);
815 /******************************************************************************
816 * GetAce [ADVAPI32.@]
818 BOOL WINAPI GetAce(PACL pAcl,DWORD dwAceIndex,LPVOID *pAce )
820 CallWin32ToNt(RtlGetAce(pAcl, dwAceIndex, pAce));
823 /******************************************************************************
824 * GetAclInformation [ADVAPI32.@]
826 BOOL WINAPI GetAclInformation(
827 PACL pAcl,
828 LPVOID pAclInformation,
829 DWORD nAclInformationLength,
830 ACL_INFORMATION_CLASS dwAclInformationClass)
832 CallWin32ToNt(RtlQueryInformationAcl(pAcl, pAclInformation,
833 nAclInformationLength, dwAclInformationClass));
836 /******************************************************************************
837 * IsValidAcl [ADVAPI32.@]
839 BOOL WINAPI IsValidAcl(IN PACL pAcl)
841 return RtlValidAcl(pAcl);
844 /* ##############################
845 ###### MISC FUNCTIONS ######
846 ##############################
849 static const char * const DefaultPrivNames[] =
851 NULL, NULL,
852 "SeCreateTokenPrivilege", "SeAssignPrimaryTokenPrivilege",
853 "SeLockMemoryPrivilege", "SeIncreaseQuotaPrivilege",
854 "SeUnsolicitedInputPrivilege", "SeMachineAccountPrivilege",
855 "SeTcbPrivilege", "SeSecurityPrivilege",
856 "SeTakeOwnershipPrivilege", "SeLoadDriverPrivilege",
857 "SeSystemProfilePrivilege", "SeSystemtimePrivilege",
858 "SeProfileSingleProcessPrivilege", "SeIncreaseBasePriorityPrivilege",
859 "SeCreatePagefilePrivilege", "SeCreatePermanentPrivilege",
860 "SeBackupPrivilege", "SeRestorePrivilege",
861 "SeShutdownPrivilege", "SeDebugPrivilege",
862 "SeAuditPrivilege", "SeSystemEnvironmentPrivilege",
863 "SeChangeNotifyPrivilege", "SeRemoteShutdownPrivilege",
864 "SeUndockPrivilege", "SeSyncAgentPrivilege",
865 "SeEnableDelegationPrivilege", "SeManageVolumePrivilege",
866 "SeImpersonatePrivilege", "SeCreateGlobalPrivilege",
868 #define NUMPRIVS (sizeof DefaultPrivNames/sizeof DefaultPrivNames[0])
870 /******************************************************************************
871 * LookupPrivilegeValueW [ADVAPI32.@]
873 * See LookupPrivilegeValueA.
875 BOOL WINAPI
876 LookupPrivilegeValueW( LPCWSTR lpSystemName, LPCWSTR lpName, PLUID lpLuid )
878 UINT i;
879 WCHAR priv[0x28];
881 TRACE("%s,%s,%p\n",debugstr_w(lpSystemName), debugstr_w(lpName), lpLuid);
883 for( i=0; i<NUMPRIVS; i++ )
885 if( !DefaultPrivNames[i] )
886 continue;
887 MultiByteToWideChar( CP_ACP, 0, DefaultPrivNames[i], -1,
888 priv, sizeof priv );
889 if( strcmpW( priv, lpName) )
890 continue;
891 lpLuid->LowPart = i;
892 lpLuid->HighPart = 0;
893 TRACE( "%s -> %08lx-%08lx\n",debugstr_w( lpSystemName ),
894 lpLuid->HighPart, lpLuid->LowPart );
895 return TRUE;
897 return FALSE;
900 /******************************************************************************
901 * LookupPrivilegeValueA [ADVAPI32.@]
903 * Retrieves LUID used on a system to represent the privilege name.
905 * PARAMS
906 * lpSystemName [I] Name of the system
907 * lpName [I] Name of the privilege
908 * lpLuid [O] Destination for the resulting LUID
910 * RETURNS
911 * Success: TRUE. lpLuid contains the requested LUID.
912 * Failure: FALSE.
914 BOOL WINAPI
915 LookupPrivilegeValueA( LPCSTR lpSystemName, LPCSTR lpName, PLUID lpLuid )
917 UNICODE_STRING lpSystemNameW;
918 UNICODE_STRING lpNameW;
919 BOOL ret;
921 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW, lpSystemName);
922 RtlCreateUnicodeStringFromAsciiz(&lpNameW,lpName);
923 ret = LookupPrivilegeValueW(lpSystemNameW.Buffer, lpNameW.Buffer, lpLuid);
924 RtlFreeUnicodeString(&lpNameW);
925 RtlFreeUnicodeString(&lpSystemNameW);
926 return ret;
930 /******************************************************************************
931 * LookupPrivilegeNameA [ADVAPI32.@]
933 BOOL WINAPI
934 LookupPrivilegeNameA( LPCSTR lpSystemName, PLUID lpLuid, LPSTR lpName, LPDWORD cchName)
936 FIXME("%s %p %p %p\n", debugstr_a(lpSystemName), lpLuid, lpName, cchName);
937 return FALSE;
940 /******************************************************************************
941 * LookupPrivilegeNameW [ADVAPI32.@]
943 BOOL WINAPI
944 LookupPrivilegeNameW( LPCWSTR lpSystemName, PLUID lpLuid, LPWSTR lpName, LPDWORD cchName)
946 FIXME("%s %p %p %p\n", debugstr_w(lpSystemName), lpLuid, lpName, cchName);
947 return FALSE;
950 /******************************************************************************
951 * GetFileSecurityA [ADVAPI32.@]
953 * Obtains Specified information about the security of a file or directory.
955 * PARAMS
956 * lpFileName [I] Name of the file to get info for
957 * RequestedInformation [I] SE_ flags from "winnt.h"
958 * pSecurityDescriptor [O] Destination for security information
959 * nLength [I] Length of pSecurityDescriptor
960 * lpnLengthNeeded [O] Destination for length of returned security information
962 * RETURNS
963 * Success: TRUE. pSecurityDescriptor contains the requested information.
964 * Failure: FALSE. lpnLengthNeeded contains the required space to return the info.
966 * NOTES
967 * The information returned is constrained by the callers access rights and
968 * privileges.
970 BOOL WINAPI
971 GetFileSecurityA( LPCSTR lpFileName,
972 SECURITY_INFORMATION RequestedInformation,
973 PSECURITY_DESCRIPTOR pSecurityDescriptor,
974 DWORD nLength, LPDWORD lpnLengthNeeded )
976 DWORD len;
977 BOOL r;
978 LPWSTR name = NULL;
980 if( lpFileName )
982 len = MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, NULL, 0 );
983 name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
984 MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, name, len );
987 r = GetFileSecurityW( name, RequestedInformation, pSecurityDescriptor,
988 nLength, lpnLengthNeeded );
989 if( name )
990 HeapFree( GetProcessHeap(), 0, name );
992 return r;
995 /******************************************************************************
996 * GetFileSecurityW [ADVAPI32.@]
998 * See GetFileSecurityA.
1000 BOOL WINAPI
1001 GetFileSecurityW( LPCWSTR lpFileName,
1002 SECURITY_INFORMATION RequestedInformation,
1003 PSECURITY_DESCRIPTOR pSecurityDescriptor,
1004 DWORD nLength, LPDWORD lpnLengthNeeded )
1006 FIXME("(%s) : stub\n", debugstr_w(lpFileName) );
1007 return TRUE;
1011 /******************************************************************************
1012 * LookupAccountSidA [ADVAPI32.@]
1014 BOOL WINAPI
1015 LookupAccountSidA(
1016 IN LPCSTR system,
1017 IN PSID sid,
1018 OUT LPSTR account,
1019 IN OUT LPDWORD accountSize,
1020 OUT LPSTR domain,
1021 IN OUT LPDWORD domainSize,
1022 OUT PSID_NAME_USE name_use )
1024 static const char ac[] = "Administrator";
1025 static const char dm[] = "DOMAIN";
1026 FIXME("(%s,sid=%p,%p,%p(%lu),%p,%p(%lu),%p): semi-stub\n",
1027 debugstr_a(system),sid,
1028 account,accountSize,accountSize?*accountSize:0,
1029 domain,domainSize,domainSize?*domainSize:0,
1030 name_use);
1032 if (accountSize) *accountSize = strlen(ac)+1;
1033 if (account && (*accountSize > strlen(ac)))
1034 strcpy(account, ac);
1036 if (domainSize) *domainSize = strlen(dm)+1;
1037 if (domain && (*domainSize > strlen(dm)))
1038 strcpy(domain,dm);
1040 if (name_use) *name_use = SidTypeUser;
1041 return TRUE;
1044 /******************************************************************************
1045 * LookupAccountSidW [ADVAPI32.@]
1047 * PARAMS
1048 * system []
1049 * sid []
1050 * account []
1051 * accountSize []
1052 * domain []
1053 * domainSize []
1054 * name_use []
1056 BOOL WINAPI
1057 LookupAccountSidW(
1058 IN LPCWSTR system,
1059 IN PSID sid,
1060 OUT LPWSTR account,
1061 IN OUT LPDWORD accountSize,
1062 OUT LPWSTR domain,
1063 IN OUT LPDWORD domainSize,
1064 OUT PSID_NAME_USE name_use )
1066 static const WCHAR ac[] = {'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
1067 static const WCHAR dm[] = {'D','O','M','A','I','N',0};
1068 FIXME("(%s,sid=%p,%p,%p(%lu),%p,%p(%lu),%p): semi-stub\n",
1069 debugstr_w(system),sid,
1070 account,accountSize,accountSize?*accountSize:0,
1071 domain,domainSize,domainSize?*domainSize:0,
1072 name_use);
1074 if (accountSize) *accountSize = strlenW(ac)+1;
1075 if (account && (*accountSize > strlenW(ac)))
1076 strcpyW(account, ac);
1078 if (domainSize) *domainSize = strlenW(dm)+1;
1079 if (domain && (*domainSize > strlenW(dm)))
1080 strcpyW(domain,dm);
1082 if (name_use) *name_use = SidTypeUser;
1083 return TRUE;
1086 /******************************************************************************
1087 * SetFileSecurityA [ADVAPI32.@]
1088 * Sets the security of a file or directory
1090 BOOL WINAPI SetFileSecurityA( LPCSTR lpFileName,
1091 SECURITY_INFORMATION RequestedInformation,
1092 PSECURITY_DESCRIPTOR pSecurityDescriptor)
1094 DWORD len;
1095 BOOL r;
1096 LPWSTR name = NULL;
1098 if( lpFileName )
1100 len = MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, NULL, 0 );
1101 name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
1102 MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, name, len );
1105 r = SetFileSecurityW( name, RequestedInformation, pSecurityDescriptor );
1106 if( name )
1107 HeapFree( GetProcessHeap(), 0, name );
1109 return r;
1112 /******************************************************************************
1113 * SetFileSecurityW [ADVAPI32.@]
1114 * Sets the security of a file or directory
1116 * PARAMS
1117 * lpFileName []
1118 * RequestedInformation []
1119 * pSecurityDescriptor []
1121 BOOL WINAPI
1122 SetFileSecurityW( LPCWSTR lpFileName,
1123 SECURITY_INFORMATION RequestedInformation,
1124 PSECURITY_DESCRIPTOR pSecurityDescriptor )
1126 FIXME("(%s) : stub\n", debugstr_w(lpFileName) );
1127 return TRUE;
1130 /******************************************************************************
1131 * QueryWindows31FilesMigration [ADVAPI32.@]
1133 * PARAMS
1134 * x1 []
1136 BOOL WINAPI
1137 QueryWindows31FilesMigration( DWORD x1 )
1139 FIXME("(%ld):stub\n",x1);
1140 return TRUE;
1143 /******************************************************************************
1144 * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.@]
1146 * PARAMS
1147 * x1 []
1148 * x2 []
1149 * x3 []
1150 * x4 []
1152 BOOL WINAPI
1153 SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1, DWORD x2, DWORD x3,
1154 DWORD x4 )
1156 FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx):stub\n",x1,x2,x3,x4);
1157 return TRUE;
1160 /******************************************************************************
1161 * LsaOpenPolicy [ADVAPI32.@]
1163 * PARAMS
1164 * x1 []
1165 * x2 []
1166 * x3 []
1167 * x4 []
1169 NTSTATUS WINAPI
1170 LsaOpenPolicy(
1171 IN PLSA_UNICODE_STRING SystemName,
1172 IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes,
1173 IN ACCESS_MASK DesiredAccess,
1174 IN OUT PLSA_HANDLE PolicyHandle)
1176 FIXME("(%s,%p,0x%08lx,%p):stub\n",
1177 SystemName?debugstr_w(SystemName->Buffer):"null",
1178 ObjectAttributes, DesiredAccess, PolicyHandle);
1179 ADVAPI_ForceLocalComputer(SystemName ? SystemName->Buffer : NULL,
1180 STATUS_ACCESS_VIOLATION);
1181 dumpLsaAttributes(ObjectAttributes);
1182 if(PolicyHandle) *PolicyHandle = (LSA_HANDLE)0xcafe;
1183 return STATUS_SUCCESS;
1186 /******************************************************************************
1187 * LsaQueryInformationPolicy [ADVAPI32.@]
1189 NTSTATUS WINAPI
1190 LsaQueryInformationPolicy(
1191 IN LSA_HANDLE PolicyHandle,
1192 IN POLICY_INFORMATION_CLASS InformationClass,
1193 OUT PVOID *Buffer)
1195 FIXME("(%p,0x%08x,%p):stub\n",
1196 PolicyHandle, InformationClass, Buffer);
1198 if(!Buffer) return FALSE;
1199 switch (InformationClass)
1201 case PolicyAuditEventsInformation: /* 2 */
1203 PPOLICY_AUDIT_EVENTS_INFO p = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(POLICY_AUDIT_EVENTS_INFO));
1204 p->AuditingMode = FALSE; /* no auditing */
1205 *Buffer = p;
1207 break;
1208 case PolicyPrimaryDomainInformation: /* 3 */
1209 case PolicyAccountDomainInformation: /* 5 */
1211 struct di
1212 { POLICY_PRIMARY_DOMAIN_INFO ppdi;
1213 SID sid;
1215 SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
1217 struct di * xdi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(xdi));
1218 HKEY key;
1219 BOOL useDefault = TRUE;
1220 LONG ret;
1222 if ((ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1223 "System\\CurrentControlSet\\Services\\VxD\\VNETSUP", 0,
1224 KEY_READ, &key)) == ERROR_SUCCESS)
1226 DWORD size = 0;
1227 static const WCHAR wg[] = { 'W','o','r','k','g','r','o','u','p',0 };
1229 ret = RegQueryValueExW(key, wg, NULL, NULL, NULL, &size);
1230 if (ret == ERROR_MORE_DATA || ret == ERROR_SUCCESS)
1232 xdi->ppdi.Name.Buffer = HeapAlloc(GetProcessHeap(),
1233 HEAP_ZERO_MEMORY, size);
1234 if ((ret = RegQueryValueExW(key, wg, NULL, NULL,
1235 (LPBYTE)xdi->ppdi.Name.Buffer, &size)) == ERROR_SUCCESS)
1237 xdi->ppdi.Name.Length = (USHORT)size;
1238 useDefault = FALSE;
1240 else
1242 HeapFree(GetProcessHeap(), 0, xdi->ppdi.Name.Buffer);
1243 xdi->ppdi.Name.Buffer = NULL;
1246 RegCloseKey(key);
1248 if (useDefault)
1249 RtlCreateUnicodeStringFromAsciiz(&(xdi->ppdi.Name), "DOMAIN");
1250 TRACE("setting domain to %s\n", debugstr_w(xdi->ppdi.Name.Buffer));
1252 xdi->ppdi.Sid = &(xdi->sid);
1253 xdi->sid.Revision = SID_REVISION;
1254 xdi->sid.SubAuthorityCount = 1;
1255 xdi->sid.IdentifierAuthority = localSidAuthority;
1256 xdi->sid.SubAuthority[0] = SECURITY_LOCAL_SYSTEM_RID;
1257 *Buffer = xdi;
1259 break;
1260 case PolicyAuditLogInformation:
1261 case PolicyPdAccountInformation:
1262 case PolicyLsaServerRoleInformation:
1263 case PolicyReplicaSourceInformation:
1264 case PolicyDefaultQuotaInformation:
1265 case PolicyModificationInformation:
1266 case PolicyAuditFullSetInformation:
1267 case PolicyAuditFullQueryInformation:
1268 case PolicyDnsDomainInformation:
1270 FIXME("category not implemented\n");
1271 return FALSE;
1274 return TRUE;
1277 /******************************************************************************
1278 * LsaLookupSids [ADVAPI32.@]
1280 NTSTATUS WINAPI
1281 LsaLookupSids(
1282 IN LSA_HANDLE PolicyHandle,
1283 IN ULONG Count,
1284 IN PSID *Sids,
1285 OUT PLSA_REFERENCED_DOMAIN_LIST *ReferencedDomains,
1286 OUT PLSA_TRANSLATED_NAME *Names )
1288 FIXME("%p %lu %p %p %p\n",
1289 PolicyHandle, Count, Sids, ReferencedDomains, Names);
1290 return FALSE;
1293 /******************************************************************************
1294 * LsaFreeMemory [ADVAPI32.@]
1296 NTSTATUS WINAPI
1297 LsaFreeMemory(IN PVOID Buffer)
1299 TRACE("(%p)\n",Buffer);
1300 return HeapFree(GetProcessHeap(), 0, Buffer);
1302 /******************************************************************************
1303 * LsaClose [ADVAPI32.@]
1305 NTSTATUS WINAPI
1306 LsaClose(IN LSA_HANDLE ObjectHandle)
1308 FIXME("(%p):stub\n",ObjectHandle);
1309 return 0xc0000000;
1312 /******************************************************************************
1313 * LsaNtStatusToWinError [ADVAPI32.@]
1315 * PARAMS
1316 * Status [I]
1318 ULONG WINAPI
1319 LsaNtStatusToWinError(NTSTATUS Status)
1321 return RtlNtStatusToDosError(Status);
1324 /******************************************************************************
1325 * NotifyBootConfigStatus [ADVAPI32.@]
1327 * PARAMS
1328 * x1 []
1330 BOOL WINAPI
1331 NotifyBootConfigStatus( DWORD x1 )
1333 FIXME("(0x%08lx):stub\n",x1);
1334 return 1;
1337 /******************************************************************************
1338 * RevertToSelf [ADVAPI32.@]
1340 * PARAMS
1341 * void []
1343 BOOL WINAPI
1344 RevertToSelf( void )
1346 FIXME("(), stub\n");
1347 return TRUE;
1350 /******************************************************************************
1351 * ImpersonateSelf [ADVAPI32.@]
1353 BOOL WINAPI
1354 ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
1356 return RtlImpersonateSelf(ImpersonationLevel);
1359 /******************************************************************************
1360 * ImpersonateLoggedOnUser [ADVAPI32.@]
1362 BOOL WINAPI ImpersonateLoggedOnUser(HANDLE hToken)
1364 FIXME("(%p):stub returning FALSE\n", hToken);
1365 return FALSE;
1368 /******************************************************************************
1369 * AccessCheck [ADVAPI32.@]
1371 * FIXME check cast LPBOOL to PBOOLEAN
1373 BOOL WINAPI
1374 AccessCheck(
1375 PSECURITY_DESCRIPTOR SecurityDescriptor,
1376 HANDLE ClientToken,
1377 DWORD DesiredAccess,
1378 PGENERIC_MAPPING GenericMapping,
1379 PPRIVILEGE_SET PrivilegeSet,
1380 LPDWORD PrivilegeSetLength,
1381 LPDWORD GrantedAccess,
1382 LPBOOL AccessStatus)
1384 CallWin32ToNt (NtAccessCheck(SecurityDescriptor, ClientToken, DesiredAccess,
1385 GenericMapping, PrivilegeSet, PrivilegeSetLength, GrantedAccess, (PBOOLEAN)AccessStatus));
1389 /******************************************************************************
1390 * AccessCheckByType [ADVAPI32.@]
1392 BOOL WINAPI AccessCheckByType(
1393 PSECURITY_DESCRIPTOR pSecurityDescriptor,
1394 PSID PrincipalSelfSid,
1395 HANDLE ClientToken,
1396 DWORD DesiredAccess,
1397 POBJECT_TYPE_LIST ObjectTypeList,
1398 DWORD ObjectTypeListLength,
1399 PGENERIC_MAPPING GenericMapping,
1400 PPRIVILEGE_SET PrivilegeSet,
1401 LPDWORD PrivilegeSetLength,
1402 LPDWORD GrantedAccess,
1403 LPBOOL AccessStatus)
1405 FIXME("stub\n");
1407 *AccessStatus = TRUE;
1409 return !*AccessStatus;
1413 /*************************************************************************
1414 * SetKernelObjectSecurity [ADVAPI32.@]
1416 BOOL WINAPI SetKernelObjectSecurity (
1417 IN HANDLE Handle,
1418 IN SECURITY_INFORMATION SecurityInformation,
1419 IN PSECURITY_DESCRIPTOR SecurityDescriptor )
1421 CallWin32ToNt (NtSetSecurityObject (Handle, SecurityInformation, SecurityDescriptor));
1425 /******************************************************************************
1426 * AddAuditAccessAce [ADVAPI32.@]
1428 BOOL WINAPI AddAuditAccessAce(
1429 IN OUT PACL pAcl,
1430 IN DWORD dwAceRevision,
1431 IN DWORD dwAccessMask,
1432 IN PSID pSid,
1433 IN BOOL bAuditSuccess,
1434 IN BOOL bAuditFailure)
1436 FIXME("Stub\n");
1437 return TRUE;
1440 /******************************************************************************
1441 * LookupAccountNameA [ADVAPI32.@]
1443 BOOL WINAPI
1444 LookupAccountNameA(
1445 IN LPCSTR system,
1446 IN LPCSTR account,
1447 OUT PSID sid,
1448 OUT LPDWORD cbSid,
1449 LPSTR ReferencedDomainName,
1450 IN OUT LPDWORD cbReferencedDomainName,
1451 OUT PSID_NAME_USE name_use )
1453 FIXME("(%s,%s,%p,%p,%p,%p,%p), stub.\n",system,account,sid,cbSid,ReferencedDomainName,cbReferencedDomainName,name_use);
1454 return FALSE;
1457 /******************************************************************************
1458 * PrivilegeCheck [ADVAPI32.@]
1460 BOOL WINAPI PrivilegeCheck( HANDLE ClientToken, PPRIVILEGE_SET RequiredPrivileges, LPBOOL pfResult)
1462 FIXME("stub %p %p %p\n", ClientToken, RequiredPrivileges, pfResult);
1463 if (pfResult)
1464 *pfResult=TRUE;
1465 return TRUE;
1468 /******************************************************************************
1469 * AccessCheckAndAuditAlarmA [ADVAPI32.@]
1471 BOOL WINAPI AccessCheckAndAuditAlarmA(LPCSTR Subsystem, LPVOID HandleId, LPSTR ObjectTypeName,
1472 LPSTR ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD DesiredAccess,
1473 PGENERIC_MAPPING GenericMapping, BOOL ObjectCreation, LPDWORD GrantedAccess,
1474 LPBOOL AccessStatus, LPBOOL pfGenerateOnClose)
1476 FIXME("stub (%s,%p,%s,%s,%p,%08lx,%p,%x,%p,%p,%p)\n", debugstr_a(Subsystem),
1477 HandleId, debugstr_a(ObjectTypeName), debugstr_a(ObjectName),
1478 SecurityDescriptor, DesiredAccess, GenericMapping,
1479 ObjectCreation, GrantedAccess, AccessStatus, pfGenerateOnClose);
1480 return TRUE;
1483 /******************************************************************************
1484 * AccessCheckAndAuditAlarmW [ADVAPI32.@]
1486 BOOL WINAPI AccessCheckAndAuditAlarmW(LPCWSTR Subsystem, LPVOID HandleId, LPWSTR ObjectTypeName,
1487 LPWSTR ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD DesiredAccess,
1488 PGENERIC_MAPPING GenericMapping, BOOL ObjectCreation, LPDWORD GrantedAccess,
1489 LPBOOL AccessStatus, LPBOOL pfGenerateOnClose)
1491 FIXME("stub (%s,%p,%s,%s,%p,%08lx,%p,%x,%p,%p,%p)\n", debugstr_w(Subsystem),
1492 HandleId, debugstr_w(ObjectTypeName), debugstr_w(ObjectName),
1493 SecurityDescriptor, DesiredAccess, GenericMapping,
1494 ObjectCreation, GrantedAccess, AccessStatus, pfGenerateOnClose);
1495 return TRUE;
1499 /******************************************************************************
1500 * GetSecurityInfoExW [ADVAPI32.@]
1502 DWORD WINAPI GetSecurityInfoExW(
1503 HANDLE hObject, SE_OBJECT_TYPE ObjectType,
1504 SECURITY_INFORMATION SecurityInfo, LPCWSTR lpProvider,
1505 LPCWSTR lpProperty, PACTRL_ACCESSW *ppAccessList,
1506 PACTRL_AUDITW *ppAuditList, LPWSTR *lppOwner, LPWSTR *lppGroup
1509 FIXME("stub!\n");
1510 return ERROR_BAD_PROVIDER;
1513 /******************************************************************************
1514 * BuildTrusteeWithSidA [ADVAPI32.@]
1516 VOID WINAPI BuildTrusteeWithSidA(PTRUSTEEA pTrustee, PSID pSid)
1518 TRACE("%p %p\n", pTrustee, pSid);
1520 pTrustee->pMultipleTrustee = NULL;
1521 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
1522 pTrustee->TrusteeForm = TRUSTEE_IS_SID;
1523 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
1524 pTrustee->ptstrName = (LPSTR) pSid;
1527 /******************************************************************************
1528 * BuildTrusteeWithSidW [ADVAPI32.@]
1530 VOID WINAPI BuildTrusteeWithSidW(PTRUSTEEW pTrustee, PSID pSid)
1532 TRACE("%p %p\n", pTrustee, pSid);
1534 pTrustee->pMultipleTrustee = NULL;
1535 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
1536 pTrustee->TrusteeForm = TRUSTEE_IS_SID;
1537 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
1538 pTrustee->ptstrName = (LPWSTR) pSid;
1541 /******************************************************************************
1542 * BuildTrusteeWithNameA [ADVAPI32.@]
1544 VOID WINAPI BuildTrusteeWithNameA(PTRUSTEEA pTrustee, LPSTR name)
1546 TRACE("%p %s\n", pTrustee, debugstr_a(name) );
1548 pTrustee->pMultipleTrustee = NULL;
1549 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
1550 pTrustee->TrusteeForm = TRUSTEE_IS_NAME;
1551 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
1552 pTrustee->ptstrName = name;
1555 /******************************************************************************
1556 * BuildTrusteeWithNameW [ADVAPI32.@]
1558 VOID WINAPI BuildTrusteeWithNameW(PTRUSTEEW pTrustee, LPWSTR name)
1560 TRACE("%p %s\n", pTrustee, debugstr_w(name) );
1562 pTrustee->pMultipleTrustee = NULL;
1563 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
1564 pTrustee->TrusteeForm = TRUSTEE_IS_NAME;
1565 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
1566 pTrustee->ptstrName = name;
1569 /******************************************************************************
1570 * SetEntriesInAclA [ADVAPI32.@]
1572 DWORD WINAPI SetEntriesInAclA( ULONG count, PEXPLICIT_ACCESSA pEntries,
1573 PACL OldAcl, PACL* NewAcl )
1575 FIXME("%ld %p %p %p\n",count,pEntries,OldAcl,NewAcl);
1576 return ERROR_CALL_NOT_IMPLEMENTED;
1579 /******************************************************************************
1580 * SetEntriesInAclW [ADVAPI32.@]
1582 DWORD WINAPI SetEntriesInAclW( ULONG count, PEXPLICIT_ACCESSW pEntries,
1583 PACL OldAcl, PACL* NewAcl )
1585 FIXME("%ld %p %p %p\n",count,pEntries,OldAcl,NewAcl);
1586 return ERROR_CALL_NOT_IMPLEMENTED;
1589 /******************************************************************************
1590 * SetNamedSecurityInfoA [ADVAPI32.@]
1592 DWORD WINAPI SetNamedSecurityInfoA(LPSTR pObjectName,
1593 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
1594 PSID psidOwner, PSID psidGroup, PACL pDacl, PACL pSacl)
1596 DWORD len;
1597 LPWSTR wstr = NULL;
1598 DWORD r;
1600 TRACE("%s %d %ld %p %p %p %p\n", debugstr_a(pObjectName), ObjectType,
1601 SecurityInfo, psidOwner, psidGroup, pDacl, pSacl);
1603 if( pObjectName )
1605 len = MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, NULL, 0 );
1606 wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR));
1607 MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, wstr, len );
1610 r = SetNamedSecurityInfoW( wstr, ObjectType, SecurityInfo, psidOwner,
1611 psidGroup, pDacl, pSacl );
1613 if( wstr )
1614 HeapFree( GetProcessHeap(), 0, wstr );
1616 return r;
1619 /******************************************************************************
1620 * AreAnyAccessesGranted [ADVAPI32.@]
1622 * Determines whether or not any of a set of specified access permissions have
1623 * been granted or not.
1625 * PARAMS
1626 * GrantedAccess [I] The permissions that have been granted.
1627 * DesiredAccess [I] The permissions that you want to have.
1629 * RETURNS
1630 * Nonzero if any of the permissions have been granted, zero if none of the
1631 * permissions have been granted.
1634 BOOL WINAPI AreAnyAccessesGranted( DWORD GrantedAccess, DWORD DesiredAccess )
1636 return (GrantedAccess & DesiredAccess) != 0;
1639 /******************************************************************************
1640 * SetNamedSecurityInfoW [ADVAPI32.@]
1642 DWORD WINAPI SetNamedSecurityInfoW(LPWSTR pObjectName,
1643 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
1644 PSID psidOwner, PSID psidGroup, PACL pDacl, PACL pSacl)
1646 FIXME("%s %d %ld %p %p %p %p\n", debugstr_w(pObjectName), ObjectType,
1647 SecurityInfo, psidOwner, psidGroup, pDacl, pSacl);
1648 return ERROR_CALL_NOT_IMPLEMENTED;
1651 /******************************************************************************
1652 * GetExplicitEntriesFromAclA [ADVAPI32.@]
1654 DWORD WINAPI GetExplicitEntriesFromAclA( PACL pacl, PULONG pcCountOfExplicitEntries,
1655 PEXPLICIT_ACCESSA* pListOfExplicitEntries)
1657 FIXME("%p %p %p\n",pacl, pcCountOfExplicitEntries, pListOfExplicitEntries);
1658 return ERROR_CALL_NOT_IMPLEMENTED;
1661 /******************************************************************************
1662 * GetExplicitEntriesFromAclW [ADVAPI32.@]
1664 DWORD WINAPI GetExplicitEntriesFromAclW( PACL pacl, PULONG pcCountOfExplicitEntries,
1665 PEXPLICIT_ACCESSW* pListOfExplicitEntries)
1667 FIXME("%p %p %p\n",pacl, pcCountOfExplicitEntries, pListOfExplicitEntries);
1668 return ERROR_CALL_NOT_IMPLEMENTED;
1672 /******************************************************************************
1673 * ParseAclStringFlags
1675 static DWORD ParseAclStringFlags(LPCWSTR* StringAcl)
1677 DWORD flags = 0;
1678 LPCWSTR szAcl = *StringAcl;
1680 while (*szAcl != '(')
1682 if (*szAcl == 'P')
1684 flags |= SE_DACL_PROTECTED;
1686 else if (*szAcl == 'A')
1688 szAcl++;
1689 if (*szAcl == 'R')
1690 flags |= SE_DACL_AUTO_INHERIT_REQ;
1691 else if (*szAcl == 'I')
1692 flags |= SE_DACL_AUTO_INHERITED;
1694 szAcl++;
1697 *StringAcl = szAcl;
1698 return flags;
1701 /******************************************************************************
1702 * ParseAceStringType
1704 ACEFLAG AceType[] =
1706 { SDDL_ACCESS_ALLOWED, ACCESS_ALLOWED_ACE_TYPE },
1707 { SDDL_ALARM, SYSTEM_ALARM_ACE_TYPE },
1708 { SDDL_AUDIT, SYSTEM_AUDIT_ACE_TYPE },
1709 { SDDL_ACCESS_DENIED, ACCESS_DENIED_ACE_TYPE },
1711 { SDDL_OBJECT_ACCESS_ALLOWED, ACCESS_ALLOWED_OBJECT_ACE_TYPE },
1712 { SDDL_OBJECT_ACCESS_DENIED, ACCESS_DENIED_OBJECT_ACE_TYPE },
1713 { SDDL_OBJECT_ALARM, SYSTEM_ALARM_OBJECT_ACE_TYPE },
1714 { SDDL_OBJECT_AUDIT, SYSTEM_AUDIT_OBJECT_ACE_TYPE },
1716 { NULL, 0 },
1719 static BYTE ParseAceStringType(LPCWSTR* StringAcl)
1721 UINT len = 0;
1722 LPCWSTR szAcl = *StringAcl;
1723 LPACEFLAG lpaf = AceType;
1725 while (lpaf->wstr &&
1726 (len = strlenW(lpaf->wstr)) &&
1727 strncmpW(lpaf->wstr, szAcl, len))
1728 lpaf++;
1730 if (!lpaf->wstr)
1731 return 0;
1733 *StringAcl += len;
1734 return lpaf->value;
1738 /******************************************************************************
1739 * ParseAceStringFlags
1741 ACEFLAG AceFlags[] =
1743 { SDDL_CONTAINER_INHERIT, CONTAINER_INHERIT_ACE },
1744 { SDDL_AUDIT_FAILURE, FAILED_ACCESS_ACE_FLAG },
1745 { SDDL_INHERITED, INHERITED_ACE },
1746 { SDDL_INHERIT_ONLY, INHERIT_ONLY_ACE },
1747 { SDDL_NO_PROPAGATE, NO_PROPAGATE_INHERIT_ACE },
1748 { SDDL_OBJECT_INHERIT, OBJECT_INHERIT_ACE },
1749 { SDDL_AUDIT_SUCCESS, SUCCESSFUL_ACCESS_ACE_FLAG },
1750 { NULL, 0 },
1753 static BYTE ParseAceStringFlags(LPCWSTR* StringAcl)
1755 UINT len = 0;
1756 BYTE flags = 0;
1757 LPCWSTR szAcl = *StringAcl;
1759 while (*szAcl != ';')
1761 LPACEFLAG lpaf = AceFlags;
1763 while (lpaf->wstr &&
1764 (len = strlenW(lpaf->wstr)) &&
1765 strncmpW(lpaf->wstr, szAcl, len))
1766 lpaf++;
1768 if (!lpaf->wstr)
1769 return 0;
1771 flags |= lpaf->value;
1772 szAcl += len;
1775 *StringAcl = szAcl;
1776 return flags;
1780 /******************************************************************************
1781 * ParseAceStringRights
1783 ACEFLAG AceRights[] =
1785 { SDDL_GENERIC_ALL, GENERIC_ALL },
1786 { SDDL_GENERIC_READ, GENERIC_READ },
1787 { SDDL_GENERIC_WRITE, GENERIC_WRITE },
1788 { SDDL_GENERIC_EXECUTE, GENERIC_EXECUTE },
1789 { SDDL_READ_CONTROL, READ_CONTROL },
1790 { SDDL_STANDARD_DELETE, DELETE },
1791 { SDDL_WRITE_DAC, WRITE_DAC },
1792 { SDDL_WRITE_OWNER, WRITE_OWNER },
1793 { NULL, 0 },
1796 static DWORD ParseAceStringRights(LPCWSTR* StringAcl)
1798 UINT len = 0;
1799 DWORD rights = 0;
1800 LPCWSTR szAcl = *StringAcl;
1802 if ((*szAcl == '0') && (*(szAcl + 1) == 'x'))
1804 LPCWSTR p = szAcl;
1806 while (*p && *p != ';')
1807 p++;
1809 if (p - szAcl <= 8)
1811 rights = strtoulW(szAcl, NULL, 16);
1812 *StringAcl = p;
1814 else
1815 WARN("Invalid rights string format: %s\n", debugstr_wn(szAcl, p - szAcl));
1817 else
1819 while (*szAcl != ';')
1821 LPACEFLAG lpaf = AceRights;
1823 while (lpaf->wstr &&
1824 (len = strlenW(lpaf->wstr)) &&
1825 strncmpW(lpaf->wstr, szAcl, len))
1827 lpaf++;
1830 if (!lpaf->wstr)
1831 return 0;
1833 rights |= lpaf->value;
1834 szAcl += len;
1838 *StringAcl = szAcl;
1839 return rights;
1843 /******************************************************************************
1844 * ParseStringAclToAcl
1846 * dacl_flags(string_ace1)(string_ace2)... (string_acen)
1848 static BOOL ParseStringAclToAcl(LPCWSTR StringAcl, LPDWORD lpdwFlags,
1849 PACL pAcl, LPDWORD cBytes)
1851 DWORD val;
1852 DWORD sidlen;
1853 DWORD length = sizeof(ACL);
1854 PACCESS_ALLOWED_ACE pAce = NULL; /* pointer to current ACE */
1856 TRACE("%s\n", debugstr_w(StringAcl));
1858 if (!StringAcl)
1859 return FALSE;
1861 if (pAcl) /* pAce is only useful if we're setting values */
1862 pAce = (PACCESS_ALLOWED_ACE) ((LPBYTE)pAcl + sizeof(PACL));
1864 /* Parse ACL flags */
1865 *lpdwFlags = ParseAclStringFlags(&StringAcl);
1867 /* Parse ACE */
1868 while (*StringAcl == '(')
1870 StringAcl++;
1872 /* Parse ACE type */
1873 val = ParseAceStringType(&StringAcl);
1874 if (pAce)
1875 pAce->Header.AceType = (BYTE) val;
1876 if (*StringAcl != ';')
1877 goto lerr;
1878 StringAcl++;
1880 /* Parse ACE flags */
1881 val = ParseAceStringFlags(&StringAcl);
1882 if (pAce)
1883 pAce->Header.AceFlags = (BYTE) val;
1884 if (*StringAcl != ';')
1885 goto lerr;
1886 StringAcl++;
1888 /* Parse ACE rights */
1889 val = ParseAceStringRights(&StringAcl);
1890 if (pAce)
1891 pAce->Mask = val;
1892 if (*StringAcl != ';')
1893 goto lerr;
1894 StringAcl++;
1896 /* Parse ACE object guid */
1897 if (*StringAcl != ';')
1899 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
1900 goto lerr;
1902 StringAcl++;
1904 /* Parse ACE inherit object guid */
1905 if (*StringAcl != ';')
1907 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
1908 goto lerr;
1910 StringAcl++;
1912 /* Parse ACE account sid */
1913 if (ParseStringSidToSid(StringAcl, pAce ? (PSID)&pAce->SidStart : NULL, &sidlen))
1915 while (*StringAcl && *StringAcl != ')')
1916 StringAcl++;
1919 if (*StringAcl != ')')
1920 goto lerr;
1921 StringAcl++;
1923 length += sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) + sidlen;
1926 *cBytes = length;
1927 return TRUE;
1929 lerr:
1930 WARN("Invalid ACE string format\n");
1931 return FALSE;
1935 /******************************************************************************
1936 * ParseStringSecurityDescriptorToSecurityDescriptor
1938 static BOOL ParseStringSecurityDescriptorToSecurityDescriptor(
1939 LPCWSTR StringSecurityDescriptor,
1940 SECURITY_DESCRIPTOR* SecurityDescriptor,
1941 LPDWORD cBytes)
1943 BOOL bret = FALSE;
1944 WCHAR toktype;
1945 WCHAR tok[MAX_PATH];
1946 LPCWSTR lptoken;
1947 LPBYTE lpNext = NULL;
1949 *cBytes = 0;
1951 if (SecurityDescriptor)
1952 lpNext = ((LPBYTE) SecurityDescriptor) + sizeof(SECURITY_DESCRIPTOR);
1954 while (*StringSecurityDescriptor)
1956 toktype = *StringSecurityDescriptor;
1958 /* Expect char identifier followed by ':' */
1959 StringSecurityDescriptor++;
1960 if (*StringSecurityDescriptor != ':')
1962 SetLastError(ERROR_INVALID_PARAMETER);
1963 goto lend;
1965 StringSecurityDescriptor++;
1967 /* Extract token */
1968 lptoken = StringSecurityDescriptor;
1969 while (*lptoken && *lptoken != ':')
1970 lptoken++;
1972 if (*lptoken)
1973 lptoken--;
1975 strncpyW(tok, StringSecurityDescriptor, lptoken - StringSecurityDescriptor);
1977 switch (toktype)
1979 case 'O':
1981 DWORD bytes;
1983 if (!ParseStringSidToSid(tok, (PSID)lpNext, &bytes))
1984 goto lend;
1986 if (SecurityDescriptor)
1988 SecurityDescriptor->Owner = (PSID) ((DWORD) lpNext -
1989 (DWORD) SecurityDescriptor);
1990 lpNext += bytes; /* Advance to next token */
1993 *cBytes += bytes;
1995 break;
1998 case 'G':
2000 DWORD bytes;
2002 if (!ParseStringSidToSid(tok, (PSID)lpNext, &bytes))
2003 goto lend;
2005 if (SecurityDescriptor)
2007 SecurityDescriptor->Group = (PSID) ((DWORD) lpNext -
2008 (DWORD) SecurityDescriptor);
2009 lpNext += bytes; /* Advance to next token */
2012 *cBytes += bytes;
2014 break;
2017 case 'D':
2019 DWORD flags;
2020 DWORD bytes;
2022 if (!ParseStringAclToAcl(tok, &flags, (PACL)lpNext, &bytes))
2023 goto lend;
2025 if (SecurityDescriptor)
2027 SecurityDescriptor->Control |= SE_DACL_PRESENT | flags;
2028 SecurityDescriptor->Dacl = (PACL) ((DWORD) lpNext -
2029 (DWORD) SecurityDescriptor);
2030 lpNext += bytes; /* Advance to next token */
2033 *cBytes += bytes;
2035 break;
2038 case 'S':
2040 DWORD flags;
2041 DWORD bytes;
2043 if (!ParseStringAclToAcl(tok, &flags, (PACL)lpNext, &bytes))
2044 goto lend;
2046 if (SecurityDescriptor)
2048 SecurityDescriptor->Control |= SE_SACL_PRESENT | flags;
2049 SecurityDescriptor->Sacl = (PACL) ((DWORD) lpNext -
2050 (DWORD) SecurityDescriptor);
2051 lpNext += bytes; /* Advance to next token */
2054 *cBytes += bytes;
2056 break;
2059 default:
2060 FIXME("Unknown token\n");
2061 SetLastError(ERROR_INVALID_PARAMETER);
2062 goto lend;
2065 StringSecurityDescriptor = lptoken;
2068 bret = TRUE;
2070 lend:
2071 return bret;
2074 /******************************************************************************
2075 * ConvertStringSecurityDescriptorToSecurityDescriptorW [ADVAPI32.@]
2077 BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorW(
2078 LPCWSTR StringSecurityDescriptor,
2079 DWORD StringSDRevision,
2080 PSECURITY_DESCRIPTOR* SecurityDescriptor,
2081 PULONG SecurityDescriptorSize)
2083 DWORD cBytes;
2084 SECURITY_DESCRIPTOR* psd;
2085 BOOL bret = FALSE;
2087 TRACE("%s\n", debugstr_w(StringSecurityDescriptor));
2089 if (GetVersion() & 0x80000000)
2091 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2092 goto lend;
2094 else if (StringSDRevision != SID_REVISION)
2096 SetLastError(ERROR_UNKNOWN_REVISION);
2097 goto lend;
2100 /* Compute security descriptor length */
2101 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor,
2102 NULL, &cBytes))
2103 goto lend;
2105 psd = *SecurityDescriptor = (SECURITY_DESCRIPTOR*) LocalAlloc(
2106 GMEM_ZEROINIT, cBytes);
2108 psd->Revision = SID_REVISION;
2109 psd->Control |= SE_SELF_RELATIVE;
2111 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor,
2112 psd, &cBytes))
2114 LocalFree(psd);
2115 goto lend;
2118 if (SecurityDescriptorSize)
2119 *SecurityDescriptorSize = cBytes;
2121 bret = TRUE;
2123 lend:
2124 TRACE(" ret=%d\n", bret);
2125 return bret;
2128 /******************************************************************************
2129 * ConvertStringSidToSidW [ADVAPI32.@]
2131 BOOL WINAPI ConvertStringSidToSidW(LPCWSTR StringSid, PSID* Sid)
2133 BOOL bret = FALSE;
2134 DWORD cBytes;
2136 if (GetVersion() & 0x80000000)
2137 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2138 else if (ParseStringSidToSid(StringSid, NULL, &cBytes))
2140 PSID pSid = *Sid = (PSID) LocalAlloc(0, cBytes);
2142 bret = ParseStringSidToSid(StringSid, pSid, &cBytes);
2143 if (!bret)
2144 LocalFree(*Sid);
2147 return bret;
2150 /******************************************************************************
2151 * ConvertSidToStringSidW [ADVAPI32.@]
2153 * format of SID string is:
2154 * S-<count>-<auth>-<subauth1>-<subauth2>-<subauth3>...
2155 * where
2156 * <rev> is the revision of the SID encoded as decimal
2157 * <auth> is the identifier authority encoded as hex
2158 * <subauthN> is the subauthority id encoded as decimal
2160 BOOL WINAPI ConvertSidToStringSidW( PSID pSid, LPWSTR *pstr )
2162 DWORD sz, i;
2163 LPWSTR str;
2164 WCHAR fmt[] = {
2165 'S','-','%','u','-','%','2','X','%','2','X','%','X','%','X','%','X','%','X',0 };
2166 WCHAR subauthfmt[] = { '-','%','u',0 };
2167 SID* pisid=pSid;
2169 TRACE("%p %p\n", pSid, pstr );
2171 if( !IsValidSid( pSid ) )
2172 return FALSE;
2174 if (pisid->Revision != SDDL_REVISION)
2175 return FALSE;
2177 sz = 14 + pisid->SubAuthorityCount * 11;
2178 str = LocalAlloc( 0, sz*sizeof(WCHAR) );
2179 sprintfW( str, fmt, pisid->Revision,
2180 pisid->IdentifierAuthority.Value[2],
2181 pisid->IdentifierAuthority.Value[3],
2182 pisid->IdentifierAuthority.Value[0]&0x0f,
2183 pisid->IdentifierAuthority.Value[4]&0x0f,
2184 pisid->IdentifierAuthority.Value[1]&0x0f,
2185 pisid->IdentifierAuthority.Value[5]&0x0f);
2186 for( i=0; i<pisid->SubAuthorityCount; i++ )
2187 sprintfW( str + strlenW(str), subauthfmt, pisid->SubAuthority[i] );
2188 *pstr = str;
2190 return TRUE;
2193 /******************************************************************************
2194 * ConvertSidToStringSidA [ADVAPI32.@]
2196 BOOL WINAPI ConvertSidToStringSidA(PSID pSid, LPSTR *pstr)
2198 LPWSTR wstr = NULL;
2199 LPSTR str;
2200 UINT len;
2202 TRACE("%p %p\n", pSid, pstr );
2204 if( !ConvertSidToStringSidW( pSid, &wstr ) )
2205 return FALSE;
2207 len = WideCharToMultiByte( CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL );
2208 str = LocalAlloc( 0, len );
2209 WideCharToMultiByte( CP_ACP, 0, wstr, -1, str, len, NULL, NULL );
2210 LocalFree( wstr );
2212 *pstr = str;
2214 return TRUE;
2217 /******************************************************************************
2218 * ComputeStringSidSize
2220 static DWORD ComputeStringSidSize(LPCWSTR StringSid)
2222 int ctok = 0;
2223 DWORD size = sizeof(SID);
2225 while (*StringSid)
2227 if (*StringSid == '-')
2228 ctok++;
2229 StringSid++;
2232 if (ctok > 3)
2233 size += (ctok - 3) * sizeof(DWORD);
2235 return size;
2238 /******************************************************************************
2239 * ParseStringSidToSid
2241 static BOOL ParseStringSidToSid(LPCWSTR StringSid, PSID pSid, LPDWORD cBytes)
2243 BOOL bret = FALSE;
2244 SID* pisid=pSid;
2246 if (!StringSid)
2248 SetLastError(ERROR_INVALID_PARAMETER);
2249 return FALSE;
2252 *cBytes = ComputeStringSidSize(StringSid);
2253 if (!pisid) /* Simply compute the size */
2254 return TRUE;
2256 if (*StringSid != 'S' || *StringSid != '-') /* S-R-I-S-S */
2258 int i = 0;
2259 int csubauth = ((*cBytes - sizeof(SID)) / sizeof(DWORD)) + 1;
2261 StringSid += 2; /* Advance to Revision */
2262 pisid->Revision = atoiW(StringSid);
2264 if (pisid->Revision != SDDL_REVISION)
2265 goto lend; /* ERROR_INVALID_SID */
2267 pisid->SubAuthorityCount = csubauth;
2269 while (*StringSid && *StringSid != '-')
2270 StringSid++; /* Advance to identifier authority */
2272 pisid->IdentifierAuthority.Value[5] = atoiW(StringSid);
2274 if (pisid->IdentifierAuthority.Value[5] > 5)
2275 goto lend; /* ERROR_INVALID_SID */
2277 while (*StringSid)
2279 while (*StringSid && *StringSid != '-')
2280 StringSid++;
2282 pisid->SubAuthority[i++] = atoiW(StringSid);
2285 if (i != pisid->SubAuthorityCount)
2286 goto lend; /* ERROR_INVALID_SID */
2288 bret = TRUE;
2290 else /* String constant format - Only available in winxp and above */
2292 pisid->Revision = SDDL_REVISION;
2293 pisid->SubAuthorityCount = 1;
2295 FIXME("String constant not supported: %s\n", debugstr_wn(StringSid, 2));
2297 /* TODO: Lookup string of well-known SIDs in table */
2298 pisid->IdentifierAuthority.Value[5] = 0;
2299 pisid->SubAuthority[0] = 0;
2301 bret = TRUE;
2304 lend:
2305 if (!bret)
2306 SetLastError(ERROR_INVALID_SID);
2308 return bret;
2311 /******************************************************************************
2312 * GetNamedSecurityInfoA [ADVAPI32.@]
2314 DWORD WINAPI GetNamedSecurityInfoA(LPSTR pObjectName,
2315 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
2316 PSID* ppsidOwner, PSID* ppsidGroup, PACL* ppDacl, PACL* ppSacl,
2317 PSECURITY_DESCRIPTOR* ppSecurityDescriptor)
2319 DWORD len;
2320 LPWSTR wstr = NULL;
2321 DWORD r;
2323 TRACE("%s %d %ld %p %p %p %p %p\n", pObjectName, ObjectType, SecurityInfo,
2324 ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor);
2326 if( pObjectName )
2328 len = MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, NULL, 0 );
2329 wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR));
2330 MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, wstr, len );
2333 r = GetNamedSecurityInfoW( wstr, ObjectType, SecurityInfo, ppsidOwner,
2334 ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor );
2336 if( wstr )
2337 HeapFree( GetProcessHeap(), 0, wstr );
2339 return r;
2342 /******************************************************************************
2343 * GetNamedSecurityInfoW [ADVAPI32.@]
2345 DWORD WINAPI GetNamedSecurityInfoW(LPWSTR pObjectName,
2346 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
2347 PSID* ppsidOwner, PSID* ppsidGroup, PACL* ppDacl, PACL* ppSacl,
2348 PSECURITY_DESCRIPTOR* ppSecurityDescriptor)
2350 FIXME("%s %d %ld %p %p %p %p %p\n", debugstr_w(pObjectName), ObjectType, SecurityInfo,
2351 ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor);
2352 return ERROR_CALL_NOT_IMPLEMENTED;