Added GetSecurityInfo stub.
[wine/multimedia.git] / dlls / advapi32 / security.c
blob7015c729c49d1d3a0484d3255060607499266818
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 TRACE("(%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 CallWin32ToNt (NtSetInformationToken( token, tokeninfoclass, tokeninfo, tokeninfolength ));
342 /*************************************************************************
343 * SetThreadToken [ADVAPI32.@]
345 * Assigns an 'impersonation token' to a thread so it can assume the
346 * security privileges of another thread or process. Can also remove
347 * a previously assigned token.
349 * PARAMS
350 * thread [O] Handle to thread to set the token for
351 * token [I] Token to set
353 * RETURNS
354 * Success: TRUE. The threads access token is set to token
355 * Failure: FALSE.
357 * NOTES
358 * Only supported on NT or higher. On Win9X this function does nothing.
359 * See SetTokenInformation.
361 BOOL WINAPI SetThreadToken(PHANDLE thread, HANDLE token)
363 CallWin32ToNt (NtSetInformationThread( thread ? *thread : GetCurrentThread(),
364 ThreadImpersonationToken, &token, sizeof token ));
367 /* ##############################
368 ###### SID FUNCTIONS ######
369 ##############################
372 /******************************************************************************
373 * AllocateAndInitializeSid [ADVAPI32.@]
375 * PARAMS
376 * pIdentifierAuthority []
377 * nSubAuthorityCount []
378 * nSubAuthority0 []
379 * nSubAuthority1 []
380 * nSubAuthority2 []
381 * nSubAuthority3 []
382 * nSubAuthority4 []
383 * nSubAuthority5 []
384 * nSubAuthority6 []
385 * nSubAuthority7 []
386 * pSid []
388 BOOL WINAPI
389 AllocateAndInitializeSid( PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
390 BYTE nSubAuthorityCount,
391 DWORD nSubAuthority0, DWORD nSubAuthority1,
392 DWORD nSubAuthority2, DWORD nSubAuthority3,
393 DWORD nSubAuthority4, DWORD nSubAuthority5,
394 DWORD nSubAuthority6, DWORD nSubAuthority7,
395 PSID *pSid )
397 CallWin32ToNt (RtlAllocateAndInitializeSid(
398 pIdentifierAuthority, nSubAuthorityCount,
399 nSubAuthority0, nSubAuthority1, nSubAuthority2, nSubAuthority3,
400 nSubAuthority4, nSubAuthority5, nSubAuthority6, nSubAuthority7,
401 pSid ));
404 /******************************************************************************
405 * FreeSid [ADVAPI32.@]
407 * PARAMS
408 * pSid []
410 PVOID WINAPI
411 FreeSid( PSID pSid )
413 RtlFreeSid(pSid);
414 return NULL; /* is documented like this */
417 /******************************************************************************
418 * CopySid [ADVAPI32.@]
420 * PARAMS
421 * nDestinationSidLength []
422 * pDestinationSid []
423 * pSourceSid []
425 BOOL WINAPI
426 CopySid( DWORD nDestinationSidLength, PSID pDestinationSid, PSID pSourceSid )
428 return RtlCopySid(nDestinationSidLength, pDestinationSid, pSourceSid);
431 /******************************************************************************
432 * IsValidSid [ADVAPI32.@]
434 * PARAMS
435 * pSid []
437 BOOL WINAPI
438 IsValidSid( PSID pSid )
440 return RtlValidSid( pSid );
443 /******************************************************************************
444 * EqualSid [ADVAPI32.@]
446 * PARAMS
447 * pSid1 []
448 * pSid2 []
450 BOOL WINAPI
451 EqualSid( PSID pSid1, PSID pSid2 )
453 return RtlEqualSid( pSid1, pSid2 );
456 /******************************************************************************
457 * EqualPrefixSid [ADVAPI32.@]
459 BOOL WINAPI EqualPrefixSid (PSID pSid1, PSID pSid2)
461 return RtlEqualPrefixSid(pSid1, pSid2);
464 /******************************************************************************
465 * GetSidLengthRequired [ADVAPI32.@]
467 * PARAMS
468 * nSubAuthorityCount []
470 DWORD WINAPI
471 GetSidLengthRequired( BYTE nSubAuthorityCount )
473 return RtlLengthRequiredSid(nSubAuthorityCount);
476 /******************************************************************************
477 * InitializeSid [ADVAPI32.@]
479 * PARAMS
480 * pIdentifierAuthority []
482 BOOL WINAPI
483 InitializeSid (
484 PSID pSid,
485 PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
486 BYTE nSubAuthorityCount)
488 return RtlInitializeSid(pSid, pIdentifierAuthority, nSubAuthorityCount);
491 /******************************************************************************
492 * GetSidIdentifierAuthority [ADVAPI32.@]
494 * PARAMS
495 * pSid []
497 PSID_IDENTIFIER_AUTHORITY WINAPI
498 GetSidIdentifierAuthority( PSID pSid )
500 return RtlIdentifierAuthoritySid(pSid);
503 /******************************************************************************
504 * GetSidSubAuthority [ADVAPI32.@]
506 * PARAMS
507 * pSid []
508 * nSubAuthority []
510 PDWORD WINAPI
511 GetSidSubAuthority( PSID pSid, DWORD nSubAuthority )
513 return RtlSubAuthoritySid(pSid, nSubAuthority);
516 /******************************************************************************
517 * GetSidSubAuthorityCount [ADVAPI32.@]
519 * PARAMS
520 * pSid []
522 PUCHAR WINAPI
523 GetSidSubAuthorityCount (PSID pSid)
525 return RtlSubAuthorityCountSid(pSid);
528 /******************************************************************************
529 * GetLengthSid [ADVAPI32.@]
531 * PARAMS
532 * pSid []
534 DWORD WINAPI
535 GetLengthSid (PSID pSid)
537 return RtlLengthSid(pSid);
540 /* ##############################################
541 ###### SECURITY DESCRIPTOR FUNCTIONS ######
542 ##############################################
545 /******************************************************************************
546 * InitializeSecurityDescriptor [ADVAPI32.@]
548 * PARAMS
549 * pDescr []
550 * revision []
552 BOOL WINAPI
553 InitializeSecurityDescriptor( PSECURITY_DESCRIPTOR pDescr, DWORD revision )
555 CallWin32ToNt (RtlCreateSecurityDescriptor(pDescr, revision ));
559 /******************************************************************************
560 * MakeAbsoluteSD [ADVAPI32.@]
562 BOOL WINAPI MakeAbsoluteSD (
563 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
564 OUT PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
565 OUT LPDWORD lpdwAbsoluteSecurityDescriptorSize,
566 OUT PACL pDacl,
567 OUT LPDWORD lpdwDaclSize,
568 OUT PACL pSacl,
569 OUT LPDWORD lpdwSaclSize,
570 OUT PSID pOwner,
571 OUT LPDWORD lpdwOwnerSize,
572 OUT PSID pPrimaryGroup,
573 OUT LPDWORD lpdwPrimaryGroupSize)
575 CallWin32ToNt (RtlSelfRelativeToAbsoluteSD(pSelfRelativeSecurityDescriptor,
576 pAbsoluteSecurityDescriptor, lpdwAbsoluteSecurityDescriptorSize,
577 pDacl, lpdwDaclSize, pSacl, lpdwSaclSize, pOwner, lpdwOwnerSize,
578 pPrimaryGroup, lpdwPrimaryGroupSize));
582 /******************************************************************************
583 * GetSecurityDescriptorLength [ADVAPI32.@]
585 DWORD WINAPI GetSecurityDescriptorLength( PSECURITY_DESCRIPTOR pDescr)
587 return (RtlLengthSecurityDescriptor(pDescr));
590 /******************************************************************************
591 * GetSecurityDescriptorOwner [ADVAPI32.@]
593 * PARAMS
594 * pOwner []
595 * lpbOwnerDefaulted []
597 BOOL WINAPI
598 GetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pDescr, PSID *pOwner,
599 LPBOOL lpbOwnerDefaulted )
601 CallWin32ToNt (RtlGetOwnerSecurityDescriptor( pDescr, pOwner, (PBOOLEAN)lpbOwnerDefaulted ));
604 /******************************************************************************
605 * SetSecurityDescriptorOwner [ADVAPI32.@]
607 * PARAMS
609 BOOL WINAPI SetSecurityDescriptorOwner( PSECURITY_DESCRIPTOR pSecurityDescriptor,
610 PSID pOwner, BOOL bOwnerDefaulted)
612 CallWin32ToNt (RtlSetOwnerSecurityDescriptor(pSecurityDescriptor, pOwner, bOwnerDefaulted));
614 /******************************************************************************
615 * GetSecurityDescriptorGroup [ADVAPI32.@]
617 BOOL WINAPI GetSecurityDescriptorGroup(
618 PSECURITY_DESCRIPTOR SecurityDescriptor,
619 PSID *Group,
620 LPBOOL GroupDefaulted)
622 CallWin32ToNt (RtlGetGroupSecurityDescriptor(SecurityDescriptor, Group, (PBOOLEAN)GroupDefaulted));
624 /******************************************************************************
625 * SetSecurityDescriptorGroup [ADVAPI32.@]
627 BOOL WINAPI SetSecurityDescriptorGroup ( PSECURITY_DESCRIPTOR SecurityDescriptor,
628 PSID Group, BOOL GroupDefaulted)
630 CallWin32ToNt (RtlSetGroupSecurityDescriptor( SecurityDescriptor, Group, GroupDefaulted));
633 /******************************************************************************
634 * IsValidSecurityDescriptor [ADVAPI32.@]
636 * PARAMS
637 * lpsecdesc []
639 BOOL WINAPI
640 IsValidSecurityDescriptor( PSECURITY_DESCRIPTOR SecurityDescriptor )
642 CallWin32ToNt (RtlValidSecurityDescriptor(SecurityDescriptor));
645 /******************************************************************************
646 * GetSecurityDescriptorDacl [ADVAPI32.@]
648 BOOL WINAPI GetSecurityDescriptorDacl(
649 IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
650 OUT LPBOOL lpbDaclPresent,
651 OUT PACL *pDacl,
652 OUT LPBOOL lpbDaclDefaulted)
654 CallWin32ToNt (RtlGetDaclSecurityDescriptor(pSecurityDescriptor, (PBOOLEAN)lpbDaclPresent,
655 pDacl, (PBOOLEAN)lpbDaclDefaulted));
658 /******************************************************************************
659 * SetSecurityDescriptorDacl [ADVAPI32.@]
661 BOOL WINAPI
662 SetSecurityDescriptorDacl (
663 PSECURITY_DESCRIPTOR lpsd,
664 BOOL daclpresent,
665 PACL dacl,
666 BOOL dacldefaulted )
668 CallWin32ToNt (RtlSetDaclSecurityDescriptor (lpsd, daclpresent, dacl, dacldefaulted ));
670 /******************************************************************************
671 * GetSecurityDescriptorSacl [ADVAPI32.@]
673 BOOL WINAPI GetSecurityDescriptorSacl(
674 IN PSECURITY_DESCRIPTOR lpsd,
675 OUT LPBOOL lpbSaclPresent,
676 OUT PACL *pSacl,
677 OUT LPBOOL lpbSaclDefaulted)
679 CallWin32ToNt (RtlGetSaclSecurityDescriptor(lpsd,
680 (PBOOLEAN)lpbSaclPresent, pSacl, (PBOOLEAN)lpbSaclDefaulted));
683 /**************************************************************************
684 * SetSecurityDescriptorSacl [ADVAPI32.@]
686 BOOL WINAPI SetSecurityDescriptorSacl (
687 PSECURITY_DESCRIPTOR lpsd,
688 BOOL saclpresent,
689 PACL lpsacl,
690 BOOL sacldefaulted)
692 CallWin32ToNt (RtlSetSaclSecurityDescriptor(lpsd, saclpresent, lpsacl, sacldefaulted));
694 /******************************************************************************
695 * MakeSelfRelativeSD [ADVAPI32.@]
697 * PARAMS
698 * lpabssecdesc []
699 * lpselfsecdesc []
700 * lpbuflen []
702 BOOL WINAPI
703 MakeSelfRelativeSD(
704 IN PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
705 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
706 IN OUT LPDWORD lpdwBufferLength)
708 CallWin32ToNt (RtlMakeSelfRelativeSD(pAbsoluteSecurityDescriptor,pSelfRelativeSecurityDescriptor, lpdwBufferLength));
711 /******************************************************************************
712 * GetSecurityDescriptorControl [ADVAPI32.@]
715 BOOL WINAPI GetSecurityDescriptorControl ( PSECURITY_DESCRIPTOR pSecurityDescriptor,
716 PSECURITY_DESCRIPTOR_CONTROL pControl, LPDWORD lpdwRevision)
718 CallWin32ToNt (RtlGetControlSecurityDescriptor(pSecurityDescriptor,pControl,lpdwRevision));
721 /* ##############################
722 ###### ACL FUNCTIONS ######
723 ##############################
726 /*************************************************************************
727 * InitializeAcl [ADVAPI32.@]
729 DWORD WINAPI InitializeAcl(PACL acl, DWORD size, DWORD rev)
731 CallWin32ToNt (RtlCreateAcl(acl, size, rev));
734 /******************************************************************************
735 * AddAccessAllowedAce [ADVAPI32.@]
737 BOOL WINAPI AddAccessAllowedAce(
738 IN OUT PACL pAcl,
739 IN DWORD dwAceRevision,
740 IN DWORD AccessMask,
741 IN PSID pSid)
743 CallWin32ToNt(RtlAddAccessAllowedAce(pAcl, dwAceRevision, AccessMask, pSid));
746 /******************************************************************************
747 * AddAccessAllowedAceEx [ADVAPI32.@]
749 BOOL WINAPI AddAccessAllowedAceEx(
750 IN OUT PACL pAcl,
751 IN DWORD dwAceRevision,
752 IN DWORD AceFlags,
753 IN DWORD AccessMask,
754 IN PSID pSid)
756 CallWin32ToNt(RtlAddAccessAllowedAceEx(pAcl, dwAceRevision, AceFlags, AccessMask, pSid));
759 /******************************************************************************
760 * AddAccessDeniedAce [ADVAPI32.@]
762 BOOL WINAPI AddAccessDeniedAce(
763 IN OUT PACL pAcl,
764 IN DWORD dwAceRevision,
765 IN DWORD AccessMask,
766 IN PSID pSid)
768 CallWin32ToNt(RtlAddAccessDeniedAce(pAcl, dwAceRevision, AccessMask, pSid));
771 /******************************************************************************
772 * AddAccessDeniedAceEx [ADVAPI32.@]
774 BOOL WINAPI AddAccessDeniedAceEx(
775 IN OUT PACL pAcl,
776 IN DWORD dwAceRevision,
777 IN DWORD AceFlags,
778 IN DWORD AccessMask,
779 IN PSID pSid)
781 CallWin32ToNt(RtlAddAccessDeniedAceEx(pAcl, dwAceRevision, AceFlags, AccessMask, pSid));
784 /******************************************************************************
785 * AddAce [ADVAPI32.@]
787 BOOL WINAPI AddAce(
788 IN OUT PACL pAcl,
789 IN DWORD dwAceRevision,
790 IN DWORD dwStartingAceIndex,
791 LPVOID pAceList,
792 DWORD nAceListLength)
794 CallWin32ToNt(RtlAddAce(pAcl, dwAceRevision, dwStartingAceIndex, pAceList, nAceListLength));
797 /******************************************************************************
798 * DeleteAce [ADVAPI32.@]
800 BOOL WINAPI DeleteAce(PACL pAcl, DWORD dwAceIndex)
802 CallWin32ToNt(RtlDeleteAce(pAcl, dwAceIndex));
805 /******************************************************************************
806 * FindFirstFreeAce [ADVAPI32.@]
808 BOOL WINAPI FindFirstFreeAce(IN PACL pAcl, LPVOID * pAce)
810 return RtlFirstFreeAce(pAcl, (PACE_HEADER *)pAce);
813 /******************************************************************************
814 * GetAce [ADVAPI32.@]
816 BOOL WINAPI GetAce(PACL pAcl,DWORD dwAceIndex,LPVOID *pAce )
818 CallWin32ToNt(RtlGetAce(pAcl, dwAceIndex, pAce));
821 /******************************************************************************
822 * GetAclInformation [ADVAPI32.@]
824 BOOL WINAPI GetAclInformation(
825 PACL pAcl,
826 LPVOID pAclInformation,
827 DWORD nAclInformationLength,
828 ACL_INFORMATION_CLASS dwAclInformationClass)
830 CallWin32ToNt(RtlQueryInformationAcl(pAcl, pAclInformation,
831 nAclInformationLength, dwAclInformationClass));
834 /******************************************************************************
835 * IsValidAcl [ADVAPI32.@]
837 BOOL WINAPI IsValidAcl(IN PACL pAcl)
839 return RtlValidAcl(pAcl);
842 /* ##############################
843 ###### MISC FUNCTIONS ######
844 ##############################
847 static const char * const DefaultPrivNames[] =
849 NULL, NULL,
850 "SeCreateTokenPrivilege", "SeAssignPrimaryTokenPrivilege",
851 "SeLockMemoryPrivilege", "SeIncreaseQuotaPrivilege",
852 "SeUnsolicitedInputPrivilege", "SeMachineAccountPrivilege",
853 "SeTcbPrivilege", "SeSecurityPrivilege",
854 "SeTakeOwnershipPrivilege", "SeLoadDriverPrivilege",
855 "SeSystemProfilePrivilege", "SeSystemtimePrivilege",
856 "SeProfileSingleProcessPrivilege", "SeIncreaseBasePriorityPrivilege",
857 "SeCreatePagefilePrivilege", "SeCreatePermanentPrivilege",
858 "SeBackupPrivilege", "SeRestorePrivilege",
859 "SeShutdownPrivilege", "SeDebugPrivilege",
860 "SeAuditPrivilege", "SeSystemEnvironmentPrivilege",
861 "SeChangeNotifyPrivilege", "SeRemoteShutdownPrivilege",
862 "SeUndockPrivilege", "SeSyncAgentPrivilege",
863 "SeEnableDelegationPrivilege", "SeManageVolumePrivilege",
864 "SeImpersonatePrivilege", "SeCreateGlobalPrivilege",
866 #define NUMPRIVS (sizeof DefaultPrivNames/sizeof DefaultPrivNames[0])
868 /******************************************************************************
869 * LookupPrivilegeValueW [ADVAPI32.@]
871 * See LookupPrivilegeValueA.
873 BOOL WINAPI
874 LookupPrivilegeValueW( LPCWSTR lpSystemName, LPCWSTR lpName, PLUID lpLuid )
876 UINT i;
877 WCHAR priv[0x28];
879 TRACE("%s,%s,%p\n",debugstr_w(lpSystemName), debugstr_w(lpName), lpLuid);
881 for( i=0; i<NUMPRIVS; i++ )
883 if( !DefaultPrivNames[i] )
884 continue;
885 MultiByteToWideChar( CP_ACP, 0, DefaultPrivNames[i], -1,
886 priv, sizeof priv );
887 if( strcmpW( priv, lpName) )
888 continue;
889 lpLuid->LowPart = i;
890 lpLuid->HighPart = 0;
891 TRACE( "%s -> %08lx-%08lx\n",debugstr_w( lpSystemName ),
892 lpLuid->HighPart, lpLuid->LowPart );
893 return TRUE;
895 return FALSE;
898 /******************************************************************************
899 * LookupPrivilegeValueA [ADVAPI32.@]
901 * Retrieves LUID used on a system to represent the privilege name.
903 * PARAMS
904 * lpSystemName [I] Name of the system
905 * lpName [I] Name of the privilege
906 * lpLuid [O] Destination for the resulting LUID
908 * RETURNS
909 * Success: TRUE. lpLuid contains the requested LUID.
910 * Failure: FALSE.
912 BOOL WINAPI
913 LookupPrivilegeValueA( LPCSTR lpSystemName, LPCSTR lpName, PLUID lpLuid )
915 UNICODE_STRING lpSystemNameW;
916 UNICODE_STRING lpNameW;
917 BOOL ret;
919 RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW, lpSystemName);
920 RtlCreateUnicodeStringFromAsciiz(&lpNameW,lpName);
921 ret = LookupPrivilegeValueW(lpSystemNameW.Buffer, lpNameW.Buffer, lpLuid);
922 RtlFreeUnicodeString(&lpNameW);
923 RtlFreeUnicodeString(&lpSystemNameW);
924 return ret;
928 /******************************************************************************
929 * LookupPrivilegeNameA [ADVAPI32.@]
931 BOOL WINAPI
932 LookupPrivilegeNameA( LPCSTR lpSystemName, PLUID lpLuid, LPSTR lpName, LPDWORD cchName)
934 FIXME("%s %p %p %p\n", debugstr_a(lpSystemName), lpLuid, lpName, cchName);
935 return FALSE;
938 /******************************************************************************
939 * LookupPrivilegeNameW [ADVAPI32.@]
941 BOOL WINAPI
942 LookupPrivilegeNameW( LPCWSTR lpSystemName, PLUID lpLuid, LPWSTR lpName, LPDWORD cchName)
944 FIXME("%s %p %p %p\n", debugstr_w(lpSystemName), lpLuid, lpName, cchName);
945 return FALSE;
948 /******************************************************************************
949 * GetFileSecurityA [ADVAPI32.@]
951 * Obtains Specified information about the security of a file or directory.
953 * PARAMS
954 * lpFileName [I] Name of the file to get info for
955 * RequestedInformation [I] SE_ flags from "winnt.h"
956 * pSecurityDescriptor [O] Destination for security information
957 * nLength [I] Length of pSecurityDescriptor
958 * lpnLengthNeeded [O] Destination for length of returned security information
960 * RETURNS
961 * Success: TRUE. pSecurityDescriptor contains the requested information.
962 * Failure: FALSE. lpnLengthNeeded contains the required space to return the info.
964 * NOTES
965 * The information returned is constrained by the callers access rights and
966 * privileges.
968 BOOL WINAPI
969 GetFileSecurityA( LPCSTR lpFileName,
970 SECURITY_INFORMATION RequestedInformation,
971 PSECURITY_DESCRIPTOR pSecurityDescriptor,
972 DWORD nLength, LPDWORD lpnLengthNeeded )
974 DWORD len;
975 BOOL r;
976 LPWSTR name = NULL;
978 if( lpFileName )
980 len = MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, NULL, 0 );
981 name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
982 MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, name, len );
985 r = GetFileSecurityW( name, RequestedInformation, pSecurityDescriptor,
986 nLength, lpnLengthNeeded );
987 if( name )
988 HeapFree( GetProcessHeap(), 0, name );
990 return r;
993 /******************************************************************************
994 * GetFileSecurityW [ADVAPI32.@]
996 * See GetFileSecurityA.
998 BOOL WINAPI
999 GetFileSecurityW( LPCWSTR lpFileName,
1000 SECURITY_INFORMATION RequestedInformation,
1001 PSECURITY_DESCRIPTOR pSecurityDescriptor,
1002 DWORD nLength, LPDWORD lpnLengthNeeded )
1004 FIXME("(%s) : stub\n", debugstr_w(lpFileName) );
1005 return TRUE;
1009 /******************************************************************************
1010 * LookupAccountSidA [ADVAPI32.@]
1012 BOOL WINAPI
1013 LookupAccountSidA(
1014 IN LPCSTR system,
1015 IN PSID sid,
1016 OUT LPSTR account,
1017 IN OUT LPDWORD accountSize,
1018 OUT LPSTR domain,
1019 IN OUT LPDWORD domainSize,
1020 OUT PSID_NAME_USE name_use )
1022 static const char ac[] = "Administrator";
1023 static const char dm[] = "DOMAIN";
1024 FIXME("(%s,sid=%p,%p,%p(%lu),%p,%p(%lu),%p): semi-stub\n",
1025 debugstr_a(system),sid,
1026 account,accountSize,accountSize?*accountSize:0,
1027 domain,domainSize,domainSize?*domainSize:0,
1028 name_use);
1030 if (accountSize) *accountSize = strlen(ac)+1;
1031 if (account && (*accountSize > strlen(ac)))
1032 strcpy(account, ac);
1034 if (domainSize) *domainSize = strlen(dm)+1;
1035 if (domain && (*domainSize > strlen(dm)))
1036 strcpy(domain,dm);
1038 if (name_use) *name_use = SidTypeUser;
1039 return TRUE;
1042 /******************************************************************************
1043 * LookupAccountSidW [ADVAPI32.@]
1045 * PARAMS
1046 * system []
1047 * sid []
1048 * account []
1049 * accountSize []
1050 * domain []
1051 * domainSize []
1052 * name_use []
1054 BOOL WINAPI
1055 LookupAccountSidW(
1056 IN LPCWSTR system,
1057 IN PSID sid,
1058 OUT LPWSTR account,
1059 IN OUT LPDWORD accountSize,
1060 OUT LPWSTR domain,
1061 IN OUT LPDWORD domainSize,
1062 OUT PSID_NAME_USE name_use )
1064 static const WCHAR ac[] = {'A','d','m','i','n','i','s','t','r','a','t','o','r',0};
1065 static const WCHAR dm[] = {'D','O','M','A','I','N',0};
1066 FIXME("(%s,sid=%p,%p,%p(%lu),%p,%p(%lu),%p): semi-stub\n",
1067 debugstr_w(system),sid,
1068 account,accountSize,accountSize?*accountSize:0,
1069 domain,domainSize,domainSize?*domainSize:0,
1070 name_use);
1072 if (accountSize) *accountSize = strlenW(ac)+1;
1073 if (account && (*accountSize > strlenW(ac)))
1074 strcpyW(account, ac);
1076 if (domainSize) *domainSize = strlenW(dm)+1;
1077 if (domain && (*domainSize > strlenW(dm)))
1078 strcpyW(domain,dm);
1080 if (name_use) *name_use = SidTypeUser;
1081 return TRUE;
1084 /******************************************************************************
1085 * SetFileSecurityA [ADVAPI32.@]
1086 * Sets the security of a file or directory
1088 BOOL WINAPI SetFileSecurityA( LPCSTR lpFileName,
1089 SECURITY_INFORMATION RequestedInformation,
1090 PSECURITY_DESCRIPTOR pSecurityDescriptor)
1092 DWORD len;
1093 BOOL r;
1094 LPWSTR name = NULL;
1096 if( lpFileName )
1098 len = MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, NULL, 0 );
1099 name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
1100 MultiByteToWideChar( CP_ACP, 0, lpFileName, -1, name, len );
1103 r = SetFileSecurityW( name, RequestedInformation, pSecurityDescriptor );
1104 if( name )
1105 HeapFree( GetProcessHeap(), 0, name );
1107 return r;
1110 /******************************************************************************
1111 * SetFileSecurityW [ADVAPI32.@]
1112 * Sets the security of a file or directory
1114 * PARAMS
1115 * lpFileName []
1116 * RequestedInformation []
1117 * pSecurityDescriptor []
1119 BOOL WINAPI
1120 SetFileSecurityW( LPCWSTR lpFileName,
1121 SECURITY_INFORMATION RequestedInformation,
1122 PSECURITY_DESCRIPTOR pSecurityDescriptor )
1124 FIXME("(%s) : stub\n", debugstr_w(lpFileName) );
1125 return TRUE;
1128 /******************************************************************************
1129 * QueryWindows31FilesMigration [ADVAPI32.@]
1131 * PARAMS
1132 * x1 []
1134 BOOL WINAPI
1135 QueryWindows31FilesMigration( DWORD x1 )
1137 FIXME("(%ld):stub\n",x1);
1138 return TRUE;
1141 /******************************************************************************
1142 * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.@]
1144 * PARAMS
1145 * x1 []
1146 * x2 []
1147 * x3 []
1148 * x4 []
1150 BOOL WINAPI
1151 SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1, DWORD x2, DWORD x3,
1152 DWORD x4 )
1154 FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx):stub\n",x1,x2,x3,x4);
1155 return TRUE;
1158 /******************************************************************************
1159 * LsaOpenPolicy [ADVAPI32.@]
1161 * PARAMS
1162 * x1 []
1163 * x2 []
1164 * x3 []
1165 * x4 []
1167 NTSTATUS WINAPI
1168 LsaOpenPolicy(
1169 IN PLSA_UNICODE_STRING SystemName,
1170 IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes,
1171 IN ACCESS_MASK DesiredAccess,
1172 IN OUT PLSA_HANDLE PolicyHandle)
1174 FIXME("(%s,%p,0x%08lx,%p):stub\n",
1175 SystemName?debugstr_w(SystemName->Buffer):"null",
1176 ObjectAttributes, DesiredAccess, PolicyHandle);
1177 ADVAPI_ForceLocalComputer(SystemName ? SystemName->Buffer : NULL,
1178 STATUS_ACCESS_VIOLATION);
1179 dumpLsaAttributes(ObjectAttributes);
1180 if(PolicyHandle) *PolicyHandle = (LSA_HANDLE)0xcafe;
1181 return STATUS_SUCCESS;
1184 /******************************************************************************
1185 * LsaQueryInformationPolicy [ADVAPI32.@]
1187 NTSTATUS WINAPI
1188 LsaQueryInformationPolicy(
1189 IN LSA_HANDLE PolicyHandle,
1190 IN POLICY_INFORMATION_CLASS InformationClass,
1191 OUT PVOID *Buffer)
1193 FIXME("(%p,0x%08x,%p):stub\n",
1194 PolicyHandle, InformationClass, Buffer);
1196 if(!Buffer) return FALSE;
1197 switch (InformationClass)
1199 case PolicyAuditEventsInformation: /* 2 */
1201 PPOLICY_AUDIT_EVENTS_INFO p = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(POLICY_AUDIT_EVENTS_INFO));
1202 p->AuditingMode = FALSE; /* no auditing */
1203 *Buffer = p;
1205 break;
1206 case PolicyPrimaryDomainInformation: /* 3 */
1207 case PolicyAccountDomainInformation: /* 5 */
1209 struct di
1210 { POLICY_PRIMARY_DOMAIN_INFO ppdi;
1211 SID sid;
1213 SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
1215 struct di * xdi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(xdi));
1216 HKEY key;
1217 BOOL useDefault = TRUE;
1218 LONG ret;
1220 if ((ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
1221 "System\\CurrentControlSet\\Services\\VxD\\VNETSUP", 0,
1222 KEY_READ, &key)) == ERROR_SUCCESS)
1224 DWORD size = 0;
1225 static const WCHAR wg[] = { 'W','o','r','k','g','r','o','u','p',0 };
1227 ret = RegQueryValueExW(key, wg, NULL, NULL, NULL, &size);
1228 if (ret == ERROR_MORE_DATA || ret == ERROR_SUCCESS)
1230 xdi->ppdi.Name.Buffer = HeapAlloc(GetProcessHeap(),
1231 HEAP_ZERO_MEMORY, size);
1232 if ((ret = RegQueryValueExW(key, wg, NULL, NULL,
1233 (LPBYTE)xdi->ppdi.Name.Buffer, &size)) == ERROR_SUCCESS)
1235 xdi->ppdi.Name.Length = (USHORT)size;
1236 useDefault = FALSE;
1238 else
1240 HeapFree(GetProcessHeap(), 0, xdi->ppdi.Name.Buffer);
1241 xdi->ppdi.Name.Buffer = NULL;
1244 RegCloseKey(key);
1246 if (useDefault)
1247 RtlCreateUnicodeStringFromAsciiz(&(xdi->ppdi.Name), "DOMAIN");
1248 TRACE("setting domain to %s\n", debugstr_w(xdi->ppdi.Name.Buffer));
1250 xdi->ppdi.Sid = &(xdi->sid);
1251 xdi->sid.Revision = SID_REVISION;
1252 xdi->sid.SubAuthorityCount = 1;
1253 xdi->sid.IdentifierAuthority = localSidAuthority;
1254 xdi->sid.SubAuthority[0] = SECURITY_LOCAL_SYSTEM_RID;
1255 *Buffer = xdi;
1257 break;
1258 case PolicyAuditLogInformation:
1259 case PolicyPdAccountInformation:
1260 case PolicyLsaServerRoleInformation:
1261 case PolicyReplicaSourceInformation:
1262 case PolicyDefaultQuotaInformation:
1263 case PolicyModificationInformation:
1264 case PolicyAuditFullSetInformation:
1265 case PolicyAuditFullQueryInformation:
1266 case PolicyDnsDomainInformation:
1268 FIXME("category not implemented\n");
1269 return FALSE;
1272 return TRUE;
1275 /******************************************************************************
1276 * LsaLookupSids [ADVAPI32.@]
1278 NTSTATUS WINAPI
1279 LsaLookupSids(
1280 IN LSA_HANDLE PolicyHandle,
1281 IN ULONG Count,
1282 IN PSID *Sids,
1283 OUT PLSA_REFERENCED_DOMAIN_LIST *ReferencedDomains,
1284 OUT PLSA_TRANSLATED_NAME *Names )
1286 FIXME("%p %lu %p %p %p\n",
1287 PolicyHandle, Count, Sids, ReferencedDomains, Names);
1288 return FALSE;
1291 /******************************************************************************
1292 * LsaFreeMemory [ADVAPI32.@]
1294 NTSTATUS WINAPI
1295 LsaFreeMemory(IN PVOID Buffer)
1297 TRACE("(%p)\n",Buffer);
1298 return HeapFree(GetProcessHeap(), 0, Buffer);
1300 /******************************************************************************
1301 * LsaClose [ADVAPI32.@]
1303 NTSTATUS WINAPI
1304 LsaClose(IN LSA_HANDLE ObjectHandle)
1306 FIXME("(%p):stub\n",ObjectHandle);
1307 return 0xc0000000;
1310 /******************************************************************************
1311 * LsaNtStatusToWinError [ADVAPI32.@]
1313 * PARAMS
1314 * Status [I]
1316 ULONG WINAPI
1317 LsaNtStatusToWinError(NTSTATUS Status)
1319 return RtlNtStatusToDosError(Status);
1322 /******************************************************************************
1323 * NotifyBootConfigStatus [ADVAPI32.@]
1325 * PARAMS
1326 * x1 []
1328 BOOL WINAPI
1329 NotifyBootConfigStatus( DWORD x1 )
1331 FIXME("(0x%08lx):stub\n",x1);
1332 return 1;
1335 /******************************************************************************
1336 * RevertToSelf [ADVAPI32.@]
1338 * PARAMS
1339 * void []
1341 BOOL WINAPI
1342 RevertToSelf( void )
1344 FIXME("(), stub\n");
1345 return TRUE;
1348 /******************************************************************************
1349 * ImpersonateSelf [ADVAPI32.@]
1351 BOOL WINAPI
1352 ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
1354 return RtlImpersonateSelf(ImpersonationLevel);
1357 /******************************************************************************
1358 * ImpersonateLoggedOnUser [ADVAPI32.@]
1360 BOOL WINAPI ImpersonateLoggedOnUser(HANDLE hToken)
1362 FIXME("(%p):stub returning FALSE\n", hToken);
1363 return FALSE;
1366 /******************************************************************************
1367 * AccessCheck [ADVAPI32.@]
1369 * FIXME check cast LPBOOL to PBOOLEAN
1371 BOOL WINAPI
1372 AccessCheck(
1373 PSECURITY_DESCRIPTOR SecurityDescriptor,
1374 HANDLE ClientToken,
1375 DWORD DesiredAccess,
1376 PGENERIC_MAPPING GenericMapping,
1377 PPRIVILEGE_SET PrivilegeSet,
1378 LPDWORD PrivilegeSetLength,
1379 LPDWORD GrantedAccess,
1380 LPBOOL AccessStatus)
1382 CallWin32ToNt (NtAccessCheck(SecurityDescriptor, ClientToken, DesiredAccess,
1383 GenericMapping, PrivilegeSet, PrivilegeSetLength, GrantedAccess, (PBOOLEAN)AccessStatus));
1387 /******************************************************************************
1388 * AccessCheckByType [ADVAPI32.@]
1390 BOOL WINAPI AccessCheckByType(
1391 PSECURITY_DESCRIPTOR pSecurityDescriptor,
1392 PSID PrincipalSelfSid,
1393 HANDLE ClientToken,
1394 DWORD DesiredAccess,
1395 POBJECT_TYPE_LIST ObjectTypeList,
1396 DWORD ObjectTypeListLength,
1397 PGENERIC_MAPPING GenericMapping,
1398 PPRIVILEGE_SET PrivilegeSet,
1399 LPDWORD PrivilegeSetLength,
1400 LPDWORD GrantedAccess,
1401 LPBOOL AccessStatus)
1403 FIXME("stub\n");
1405 *AccessStatus = TRUE;
1407 return !*AccessStatus;
1411 /*************************************************************************
1412 * SetKernelObjectSecurity [ADVAPI32.@]
1414 BOOL WINAPI SetKernelObjectSecurity (
1415 IN HANDLE Handle,
1416 IN SECURITY_INFORMATION SecurityInformation,
1417 IN PSECURITY_DESCRIPTOR SecurityDescriptor )
1419 CallWin32ToNt (NtSetSecurityObject (Handle, SecurityInformation, SecurityDescriptor));
1423 /******************************************************************************
1424 * AddAuditAccessAce [ADVAPI32.@]
1426 BOOL WINAPI AddAuditAccessAce(
1427 IN OUT PACL pAcl,
1428 IN DWORD dwAceRevision,
1429 IN DWORD dwAccessMask,
1430 IN PSID pSid,
1431 IN BOOL bAuditSuccess,
1432 IN BOOL bAuditFailure)
1434 FIXME("Stub\n");
1435 return TRUE;
1438 /******************************************************************************
1439 * LookupAccountNameA [ADVAPI32.@]
1441 BOOL WINAPI
1442 LookupAccountNameA(
1443 IN LPCSTR system,
1444 IN LPCSTR account,
1445 OUT PSID sid,
1446 OUT LPDWORD cbSid,
1447 LPSTR ReferencedDomainName,
1448 IN OUT LPDWORD cbReferencedDomainName,
1449 OUT PSID_NAME_USE name_use )
1451 FIXME("(%s,%s,%p,%p,%p,%p,%p), stub.\n",system,account,sid,cbSid,ReferencedDomainName,cbReferencedDomainName,name_use);
1452 return FALSE;
1455 /******************************************************************************
1456 * PrivilegeCheck [ADVAPI32.@]
1458 BOOL WINAPI PrivilegeCheck( HANDLE ClientToken, PPRIVILEGE_SET RequiredPrivileges, LPBOOL pfResult)
1460 FIXME("stub %p %p %p\n", ClientToken, RequiredPrivileges, pfResult);
1461 if (pfResult)
1462 *pfResult=TRUE;
1463 return TRUE;
1466 /******************************************************************************
1467 * AccessCheckAndAuditAlarmA [ADVAPI32.@]
1469 BOOL WINAPI AccessCheckAndAuditAlarmA(LPCSTR Subsystem, LPVOID HandleId, LPSTR ObjectTypeName,
1470 LPSTR ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD DesiredAccess,
1471 PGENERIC_MAPPING GenericMapping, BOOL ObjectCreation, LPDWORD GrantedAccess,
1472 LPBOOL AccessStatus, LPBOOL pfGenerateOnClose)
1474 FIXME("stub (%s,%p,%s,%s,%p,%08lx,%p,%x,%p,%p,%p)\n", debugstr_a(Subsystem),
1475 HandleId, debugstr_a(ObjectTypeName), debugstr_a(ObjectName),
1476 SecurityDescriptor, DesiredAccess, GenericMapping,
1477 ObjectCreation, GrantedAccess, AccessStatus, pfGenerateOnClose);
1478 return TRUE;
1481 /******************************************************************************
1482 * AccessCheckAndAuditAlarmW [ADVAPI32.@]
1484 BOOL WINAPI AccessCheckAndAuditAlarmW(LPCWSTR Subsystem, LPVOID HandleId, LPWSTR ObjectTypeName,
1485 LPWSTR ObjectName, PSECURITY_DESCRIPTOR SecurityDescriptor, DWORD DesiredAccess,
1486 PGENERIC_MAPPING GenericMapping, BOOL ObjectCreation, LPDWORD GrantedAccess,
1487 LPBOOL AccessStatus, LPBOOL pfGenerateOnClose)
1489 FIXME("stub (%s,%p,%s,%s,%p,%08lx,%p,%x,%p,%p,%p)\n", debugstr_w(Subsystem),
1490 HandleId, debugstr_w(ObjectTypeName), debugstr_w(ObjectName),
1491 SecurityDescriptor, DesiredAccess, GenericMapping,
1492 ObjectCreation, GrantedAccess, AccessStatus, pfGenerateOnClose);
1493 return TRUE;
1497 /******************************************************************************
1498 * GetSecurityInfo [ADVAPI32.@]
1500 DWORD WINAPI GetSecurityInfo(
1501 HANDLE hObject, SE_OBJECT_TYPE ObjectType,
1502 SECURITY_INFORMATION SecurityInfo, PSID *ppsidOwner,
1503 PSID *ppsidGroup, PACL *ppDacl, PACL *ppSacl,
1504 PSECURITY_DESCRIPTOR *ppSecurityDescriptor
1507 FIXME("stub!\n");
1508 return ERROR_BAD_PROVIDER;
1511 /******************************************************************************
1512 * GetSecurityInfoExW [ADVAPI32.@]
1514 DWORD WINAPI GetSecurityInfoExW(
1515 HANDLE hObject, SE_OBJECT_TYPE ObjectType,
1516 SECURITY_INFORMATION SecurityInfo, LPCWSTR lpProvider,
1517 LPCWSTR lpProperty, PACTRL_ACCESSW *ppAccessList,
1518 PACTRL_AUDITW *ppAuditList, LPWSTR *lppOwner, LPWSTR *lppGroup
1521 FIXME("stub!\n");
1522 return ERROR_BAD_PROVIDER;
1525 /******************************************************************************
1526 * BuildTrusteeWithSidA [ADVAPI32.@]
1528 VOID WINAPI BuildTrusteeWithSidA(PTRUSTEEA pTrustee, PSID pSid)
1530 TRACE("%p %p\n", pTrustee, pSid);
1532 pTrustee->pMultipleTrustee = NULL;
1533 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
1534 pTrustee->TrusteeForm = TRUSTEE_IS_SID;
1535 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
1536 pTrustee->ptstrName = (LPSTR) pSid;
1539 /******************************************************************************
1540 * BuildTrusteeWithSidW [ADVAPI32.@]
1542 VOID WINAPI BuildTrusteeWithSidW(PTRUSTEEW pTrustee, PSID pSid)
1544 TRACE("%p %p\n", pTrustee, pSid);
1546 pTrustee->pMultipleTrustee = NULL;
1547 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
1548 pTrustee->TrusteeForm = TRUSTEE_IS_SID;
1549 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
1550 pTrustee->ptstrName = (LPWSTR) pSid;
1553 /******************************************************************************
1554 * BuildTrusteeWithNameA [ADVAPI32.@]
1556 VOID WINAPI BuildTrusteeWithNameA(PTRUSTEEA pTrustee, LPSTR name)
1558 TRACE("%p %s\n", pTrustee, debugstr_a(name) );
1560 pTrustee->pMultipleTrustee = NULL;
1561 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
1562 pTrustee->TrusteeForm = TRUSTEE_IS_NAME;
1563 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
1564 pTrustee->ptstrName = name;
1567 /******************************************************************************
1568 * BuildTrusteeWithNameW [ADVAPI32.@]
1570 VOID WINAPI BuildTrusteeWithNameW(PTRUSTEEW pTrustee, LPWSTR name)
1572 TRACE("%p %s\n", pTrustee, debugstr_w(name) );
1574 pTrustee->pMultipleTrustee = NULL;
1575 pTrustee->MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
1576 pTrustee->TrusteeForm = TRUSTEE_IS_NAME;
1577 pTrustee->TrusteeType = TRUSTEE_IS_UNKNOWN;
1578 pTrustee->ptstrName = name;
1581 /******************************************************************************
1582 * SetEntriesInAclA [ADVAPI32.@]
1584 DWORD WINAPI SetEntriesInAclA( ULONG count, PEXPLICIT_ACCESSA pEntries,
1585 PACL OldAcl, PACL* NewAcl )
1587 FIXME("%ld %p %p %p\n",count,pEntries,OldAcl,NewAcl);
1588 return ERROR_CALL_NOT_IMPLEMENTED;
1591 /******************************************************************************
1592 * SetEntriesInAclW [ADVAPI32.@]
1594 DWORD WINAPI SetEntriesInAclW( ULONG count, PEXPLICIT_ACCESSW pEntries,
1595 PACL OldAcl, PACL* NewAcl )
1597 FIXME("%ld %p %p %p\n",count,pEntries,OldAcl,NewAcl);
1598 return ERROR_CALL_NOT_IMPLEMENTED;
1601 /******************************************************************************
1602 * SetNamedSecurityInfoA [ADVAPI32.@]
1604 DWORD WINAPI SetNamedSecurityInfoA(LPSTR pObjectName,
1605 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
1606 PSID psidOwner, PSID psidGroup, PACL pDacl, PACL pSacl)
1608 DWORD len;
1609 LPWSTR wstr = NULL;
1610 DWORD r;
1612 TRACE("%s %d %ld %p %p %p %p\n", debugstr_a(pObjectName), ObjectType,
1613 SecurityInfo, psidOwner, psidGroup, pDacl, pSacl);
1615 if( pObjectName )
1617 len = MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, NULL, 0 );
1618 wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR));
1619 MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, wstr, len );
1622 r = SetNamedSecurityInfoW( wstr, ObjectType, SecurityInfo, psidOwner,
1623 psidGroup, pDacl, pSacl );
1625 if( wstr )
1626 HeapFree( GetProcessHeap(), 0, wstr );
1628 return r;
1631 /******************************************************************************
1632 * AreAnyAccessesGranted [ADVAPI32.@]
1634 * Determines whether or not any of a set of specified access permissions have
1635 * been granted or not.
1637 * PARAMS
1638 * GrantedAccess [I] The permissions that have been granted.
1639 * DesiredAccess [I] The permissions that you want to have.
1641 * RETURNS
1642 * Nonzero if any of the permissions have been granted, zero if none of the
1643 * permissions have been granted.
1646 BOOL WINAPI AreAnyAccessesGranted( DWORD GrantedAccess, DWORD DesiredAccess )
1648 return (GrantedAccess & DesiredAccess) != 0;
1651 /******************************************************************************
1652 * SetNamedSecurityInfoW [ADVAPI32.@]
1654 DWORD WINAPI SetNamedSecurityInfoW(LPWSTR pObjectName,
1655 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
1656 PSID psidOwner, PSID psidGroup, PACL pDacl, PACL pSacl)
1658 FIXME("%s %d %ld %p %p %p %p\n", debugstr_w(pObjectName), ObjectType,
1659 SecurityInfo, psidOwner, psidGroup, pDacl, pSacl);
1660 return ERROR_CALL_NOT_IMPLEMENTED;
1663 /******************************************************************************
1664 * GetExplicitEntriesFromAclA [ADVAPI32.@]
1666 DWORD WINAPI GetExplicitEntriesFromAclA( PACL pacl, PULONG pcCountOfExplicitEntries,
1667 PEXPLICIT_ACCESSA* pListOfExplicitEntries)
1669 FIXME("%p %p %p\n",pacl, pcCountOfExplicitEntries, pListOfExplicitEntries);
1670 return ERROR_CALL_NOT_IMPLEMENTED;
1673 /******************************************************************************
1674 * GetExplicitEntriesFromAclW [ADVAPI32.@]
1676 DWORD WINAPI GetExplicitEntriesFromAclW( PACL pacl, PULONG pcCountOfExplicitEntries,
1677 PEXPLICIT_ACCESSW* pListOfExplicitEntries)
1679 FIXME("%p %p %p\n",pacl, pcCountOfExplicitEntries, pListOfExplicitEntries);
1680 return ERROR_CALL_NOT_IMPLEMENTED;
1684 /******************************************************************************
1685 * ParseAclStringFlags
1687 static DWORD ParseAclStringFlags(LPCWSTR* StringAcl)
1689 DWORD flags = 0;
1690 LPCWSTR szAcl = *StringAcl;
1692 while (*szAcl != '(')
1694 if (*szAcl == 'P')
1696 flags |= SE_DACL_PROTECTED;
1698 else if (*szAcl == 'A')
1700 szAcl++;
1701 if (*szAcl == 'R')
1702 flags |= SE_DACL_AUTO_INHERIT_REQ;
1703 else if (*szAcl == 'I')
1704 flags |= SE_DACL_AUTO_INHERITED;
1706 szAcl++;
1709 *StringAcl = szAcl;
1710 return flags;
1713 /******************************************************************************
1714 * ParseAceStringType
1716 ACEFLAG AceType[] =
1718 { SDDL_ACCESS_ALLOWED, ACCESS_ALLOWED_ACE_TYPE },
1719 { SDDL_ALARM, SYSTEM_ALARM_ACE_TYPE },
1720 { SDDL_AUDIT, SYSTEM_AUDIT_ACE_TYPE },
1721 { SDDL_ACCESS_DENIED, ACCESS_DENIED_ACE_TYPE },
1723 { SDDL_OBJECT_ACCESS_ALLOWED, ACCESS_ALLOWED_OBJECT_ACE_TYPE },
1724 { SDDL_OBJECT_ACCESS_DENIED, ACCESS_DENIED_OBJECT_ACE_TYPE },
1725 { SDDL_OBJECT_ALARM, SYSTEM_ALARM_OBJECT_ACE_TYPE },
1726 { SDDL_OBJECT_AUDIT, SYSTEM_AUDIT_OBJECT_ACE_TYPE },
1728 { NULL, 0 },
1731 static BYTE ParseAceStringType(LPCWSTR* StringAcl)
1733 UINT len = 0;
1734 LPCWSTR szAcl = *StringAcl;
1735 LPACEFLAG lpaf = AceType;
1737 while (lpaf->wstr &&
1738 (len = strlenW(lpaf->wstr)) &&
1739 strncmpW(lpaf->wstr, szAcl, len))
1740 lpaf++;
1742 if (!lpaf->wstr)
1743 return 0;
1745 *StringAcl += len;
1746 return lpaf->value;
1750 /******************************************************************************
1751 * ParseAceStringFlags
1753 ACEFLAG AceFlags[] =
1755 { SDDL_CONTAINER_INHERIT, CONTAINER_INHERIT_ACE },
1756 { SDDL_AUDIT_FAILURE, FAILED_ACCESS_ACE_FLAG },
1757 { SDDL_INHERITED, INHERITED_ACE },
1758 { SDDL_INHERIT_ONLY, INHERIT_ONLY_ACE },
1759 { SDDL_NO_PROPAGATE, NO_PROPAGATE_INHERIT_ACE },
1760 { SDDL_OBJECT_INHERIT, OBJECT_INHERIT_ACE },
1761 { SDDL_AUDIT_SUCCESS, SUCCESSFUL_ACCESS_ACE_FLAG },
1762 { NULL, 0 },
1765 static BYTE ParseAceStringFlags(LPCWSTR* StringAcl)
1767 UINT len = 0;
1768 BYTE flags = 0;
1769 LPCWSTR szAcl = *StringAcl;
1771 while (*szAcl != ';')
1773 LPACEFLAG lpaf = AceFlags;
1775 while (lpaf->wstr &&
1776 (len = strlenW(lpaf->wstr)) &&
1777 strncmpW(lpaf->wstr, szAcl, len))
1778 lpaf++;
1780 if (!lpaf->wstr)
1781 return 0;
1783 flags |= lpaf->value;
1784 szAcl += len;
1787 *StringAcl = szAcl;
1788 return flags;
1792 /******************************************************************************
1793 * ParseAceStringRights
1795 ACEFLAG AceRights[] =
1797 { SDDL_GENERIC_ALL, GENERIC_ALL },
1798 { SDDL_GENERIC_READ, GENERIC_READ },
1799 { SDDL_GENERIC_WRITE, GENERIC_WRITE },
1800 { SDDL_GENERIC_EXECUTE, GENERIC_EXECUTE },
1801 { SDDL_READ_CONTROL, READ_CONTROL },
1802 { SDDL_STANDARD_DELETE, DELETE },
1803 { SDDL_WRITE_DAC, WRITE_DAC },
1804 { SDDL_WRITE_OWNER, WRITE_OWNER },
1805 { NULL, 0 },
1808 static DWORD ParseAceStringRights(LPCWSTR* StringAcl)
1810 UINT len = 0;
1811 DWORD rights = 0;
1812 LPCWSTR szAcl = *StringAcl;
1814 if ((*szAcl == '0') && (*(szAcl + 1) == 'x'))
1816 LPCWSTR p = szAcl;
1818 while (*p && *p != ';')
1819 p++;
1821 if (p - szAcl <= 8)
1823 rights = strtoulW(szAcl, NULL, 16);
1824 *StringAcl = p;
1826 else
1827 WARN("Invalid rights string format: %s\n", debugstr_wn(szAcl, p - szAcl));
1829 else
1831 while (*szAcl != ';')
1833 LPACEFLAG lpaf = AceRights;
1835 while (lpaf->wstr &&
1836 (len = strlenW(lpaf->wstr)) &&
1837 strncmpW(lpaf->wstr, szAcl, len))
1839 lpaf++;
1842 if (!lpaf->wstr)
1843 return 0;
1845 rights |= lpaf->value;
1846 szAcl += len;
1850 *StringAcl = szAcl;
1851 return rights;
1855 /******************************************************************************
1856 * ParseStringAclToAcl
1858 * dacl_flags(string_ace1)(string_ace2)... (string_acen)
1860 static BOOL ParseStringAclToAcl(LPCWSTR StringAcl, LPDWORD lpdwFlags,
1861 PACL pAcl, LPDWORD cBytes)
1863 DWORD val;
1864 DWORD sidlen;
1865 DWORD length = sizeof(ACL);
1866 PACCESS_ALLOWED_ACE pAce = NULL; /* pointer to current ACE */
1868 TRACE("%s\n", debugstr_w(StringAcl));
1870 if (!StringAcl)
1871 return FALSE;
1873 if (pAcl) /* pAce is only useful if we're setting values */
1874 pAce = (PACCESS_ALLOWED_ACE) ((LPBYTE)pAcl + sizeof(PACL));
1876 /* Parse ACL flags */
1877 *lpdwFlags = ParseAclStringFlags(&StringAcl);
1879 /* Parse ACE */
1880 while (*StringAcl == '(')
1882 StringAcl++;
1884 /* Parse ACE type */
1885 val = ParseAceStringType(&StringAcl);
1886 if (pAce)
1887 pAce->Header.AceType = (BYTE) val;
1888 if (*StringAcl != ';')
1889 goto lerr;
1890 StringAcl++;
1892 /* Parse ACE flags */
1893 val = ParseAceStringFlags(&StringAcl);
1894 if (pAce)
1895 pAce->Header.AceFlags = (BYTE) val;
1896 if (*StringAcl != ';')
1897 goto lerr;
1898 StringAcl++;
1900 /* Parse ACE rights */
1901 val = ParseAceStringRights(&StringAcl);
1902 if (pAce)
1903 pAce->Mask = val;
1904 if (*StringAcl != ';')
1905 goto lerr;
1906 StringAcl++;
1908 /* Parse ACE object guid */
1909 if (*StringAcl != ';')
1911 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
1912 goto lerr;
1914 StringAcl++;
1916 /* Parse ACE inherit object guid */
1917 if (*StringAcl != ';')
1919 FIXME("Support for *_OBJECT_ACE_TYPE not implemented\n");
1920 goto lerr;
1922 StringAcl++;
1924 /* Parse ACE account sid */
1925 if (ParseStringSidToSid(StringAcl, pAce ? (PSID)&pAce->SidStart : NULL, &sidlen))
1927 while (*StringAcl && *StringAcl != ')')
1928 StringAcl++;
1931 if (*StringAcl != ')')
1932 goto lerr;
1933 StringAcl++;
1935 length += sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) + sidlen;
1938 *cBytes = length;
1939 return TRUE;
1941 lerr:
1942 WARN("Invalid ACE string format\n");
1943 return FALSE;
1947 /******************************************************************************
1948 * ParseStringSecurityDescriptorToSecurityDescriptor
1950 static BOOL ParseStringSecurityDescriptorToSecurityDescriptor(
1951 LPCWSTR StringSecurityDescriptor,
1952 SECURITY_DESCRIPTOR* SecurityDescriptor,
1953 LPDWORD cBytes)
1955 BOOL bret = FALSE;
1956 WCHAR toktype;
1957 WCHAR tok[MAX_PATH];
1958 LPCWSTR lptoken;
1959 LPBYTE lpNext = NULL;
1961 *cBytes = 0;
1963 if (SecurityDescriptor)
1964 lpNext = ((LPBYTE) SecurityDescriptor) + sizeof(SECURITY_DESCRIPTOR);
1966 while (*StringSecurityDescriptor)
1968 toktype = *StringSecurityDescriptor;
1970 /* Expect char identifier followed by ':' */
1971 StringSecurityDescriptor++;
1972 if (*StringSecurityDescriptor != ':')
1974 SetLastError(ERROR_INVALID_PARAMETER);
1975 goto lend;
1977 StringSecurityDescriptor++;
1979 /* Extract token */
1980 lptoken = StringSecurityDescriptor;
1981 while (*lptoken && *lptoken != ':')
1982 lptoken++;
1984 if (*lptoken)
1985 lptoken--;
1987 strncpyW(tok, StringSecurityDescriptor, lptoken - StringSecurityDescriptor);
1989 switch (toktype)
1991 case 'O':
1993 DWORD bytes;
1995 if (!ParseStringSidToSid(tok, (PSID)lpNext, &bytes))
1996 goto lend;
1998 if (SecurityDescriptor)
2000 SecurityDescriptor->Owner = (PSID) ((DWORD) lpNext -
2001 (DWORD) SecurityDescriptor);
2002 lpNext += bytes; /* Advance to next token */
2005 *cBytes += bytes;
2007 break;
2010 case 'G':
2012 DWORD bytes;
2014 if (!ParseStringSidToSid(tok, (PSID)lpNext, &bytes))
2015 goto lend;
2017 if (SecurityDescriptor)
2019 SecurityDescriptor->Group = (PSID) ((DWORD) lpNext -
2020 (DWORD) SecurityDescriptor);
2021 lpNext += bytes; /* Advance to next token */
2024 *cBytes += bytes;
2026 break;
2029 case 'D':
2031 DWORD flags;
2032 DWORD bytes;
2034 if (!ParseStringAclToAcl(tok, &flags, (PACL)lpNext, &bytes))
2035 goto lend;
2037 if (SecurityDescriptor)
2039 SecurityDescriptor->Control |= SE_DACL_PRESENT | flags;
2040 SecurityDescriptor->Dacl = (PACL) ((DWORD) lpNext -
2041 (DWORD) SecurityDescriptor);
2042 lpNext += bytes; /* Advance to next token */
2045 *cBytes += bytes;
2047 break;
2050 case 'S':
2052 DWORD flags;
2053 DWORD bytes;
2055 if (!ParseStringAclToAcl(tok, &flags, (PACL)lpNext, &bytes))
2056 goto lend;
2058 if (SecurityDescriptor)
2060 SecurityDescriptor->Control |= SE_SACL_PRESENT | flags;
2061 SecurityDescriptor->Sacl = (PACL) ((DWORD) lpNext -
2062 (DWORD) SecurityDescriptor);
2063 lpNext += bytes; /* Advance to next token */
2066 *cBytes += bytes;
2068 break;
2071 default:
2072 FIXME("Unknown token\n");
2073 SetLastError(ERROR_INVALID_PARAMETER);
2074 goto lend;
2077 StringSecurityDescriptor = lptoken;
2080 bret = TRUE;
2082 lend:
2083 return bret;
2086 /******************************************************************************
2087 * ConvertStringSecurityDescriptorToSecurityDescriptorW [ADVAPI32.@]
2089 BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorW(
2090 LPCWSTR StringSecurityDescriptor,
2091 DWORD StringSDRevision,
2092 PSECURITY_DESCRIPTOR* SecurityDescriptor,
2093 PULONG SecurityDescriptorSize)
2095 DWORD cBytes;
2096 SECURITY_DESCRIPTOR* psd;
2097 BOOL bret = FALSE;
2099 TRACE("%s\n", debugstr_w(StringSecurityDescriptor));
2101 if (GetVersion() & 0x80000000)
2103 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2104 goto lend;
2106 else if (StringSDRevision != SID_REVISION)
2108 SetLastError(ERROR_UNKNOWN_REVISION);
2109 goto lend;
2112 /* Compute security descriptor length */
2113 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor,
2114 NULL, &cBytes))
2115 goto lend;
2117 psd = *SecurityDescriptor = (SECURITY_DESCRIPTOR*) LocalAlloc(
2118 GMEM_ZEROINIT, cBytes);
2120 psd->Revision = SID_REVISION;
2121 psd->Control |= SE_SELF_RELATIVE;
2123 if (!ParseStringSecurityDescriptorToSecurityDescriptor(StringSecurityDescriptor,
2124 psd, &cBytes))
2126 LocalFree(psd);
2127 goto lend;
2130 if (SecurityDescriptorSize)
2131 *SecurityDescriptorSize = cBytes;
2133 bret = TRUE;
2135 lend:
2136 TRACE(" ret=%d\n", bret);
2137 return bret;
2140 /******************************************************************************
2141 * ConvertStringSidToSidW [ADVAPI32.@]
2143 BOOL WINAPI ConvertStringSidToSidW(LPCWSTR StringSid, PSID* Sid)
2145 BOOL bret = FALSE;
2146 DWORD cBytes;
2148 if (GetVersion() & 0x80000000)
2149 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
2150 else if (ParseStringSidToSid(StringSid, NULL, &cBytes))
2152 PSID pSid = *Sid = (PSID) LocalAlloc(0, cBytes);
2154 bret = ParseStringSidToSid(StringSid, pSid, &cBytes);
2155 if (!bret)
2156 LocalFree(*Sid);
2159 return bret;
2162 /******************************************************************************
2163 * ConvertSidToStringSidW [ADVAPI32.@]
2165 * format of SID string is:
2166 * S-<count>-<auth>-<subauth1>-<subauth2>-<subauth3>...
2167 * where
2168 * <rev> is the revision of the SID encoded as decimal
2169 * <auth> is the identifier authority encoded as hex
2170 * <subauthN> is the subauthority id encoded as decimal
2172 BOOL WINAPI ConvertSidToStringSidW( PSID pSid, LPWSTR *pstr )
2174 DWORD sz, i;
2175 LPWSTR str;
2176 WCHAR fmt[] = {
2177 'S','-','%','u','-','%','2','X','%','2','X','%','X','%','X','%','X','%','X',0 };
2178 WCHAR subauthfmt[] = { '-','%','u',0 };
2179 SID* pisid=pSid;
2181 TRACE("%p %p\n", pSid, pstr );
2183 if( !IsValidSid( pSid ) )
2184 return FALSE;
2186 if (pisid->Revision != SDDL_REVISION)
2187 return FALSE;
2189 sz = 14 + pisid->SubAuthorityCount * 11;
2190 str = LocalAlloc( 0, sz*sizeof(WCHAR) );
2191 sprintfW( str, fmt, pisid->Revision,
2192 pisid->IdentifierAuthority.Value[2],
2193 pisid->IdentifierAuthority.Value[3],
2194 pisid->IdentifierAuthority.Value[0]&0x0f,
2195 pisid->IdentifierAuthority.Value[4]&0x0f,
2196 pisid->IdentifierAuthority.Value[1]&0x0f,
2197 pisid->IdentifierAuthority.Value[5]&0x0f);
2198 for( i=0; i<pisid->SubAuthorityCount; i++ )
2199 sprintfW( str + strlenW(str), subauthfmt, pisid->SubAuthority[i] );
2200 *pstr = str;
2202 return TRUE;
2205 /******************************************************************************
2206 * ConvertSidToStringSidA [ADVAPI32.@]
2208 BOOL WINAPI ConvertSidToStringSidA(PSID pSid, LPSTR *pstr)
2210 LPWSTR wstr = NULL;
2211 LPSTR str;
2212 UINT len;
2214 TRACE("%p %p\n", pSid, pstr );
2216 if( !ConvertSidToStringSidW( pSid, &wstr ) )
2217 return FALSE;
2219 len = WideCharToMultiByte( CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL );
2220 str = LocalAlloc( 0, len );
2221 WideCharToMultiByte( CP_ACP, 0, wstr, -1, str, len, NULL, NULL );
2222 LocalFree( wstr );
2224 *pstr = str;
2226 return TRUE;
2229 /******************************************************************************
2230 * ComputeStringSidSize
2232 static DWORD ComputeStringSidSize(LPCWSTR StringSid)
2234 int ctok = 0;
2235 DWORD size = sizeof(SID);
2237 while (*StringSid)
2239 if (*StringSid == '-')
2240 ctok++;
2241 StringSid++;
2244 if (ctok > 3)
2245 size += (ctok - 3) * sizeof(DWORD);
2247 return size;
2250 /******************************************************************************
2251 * ParseStringSidToSid
2253 static BOOL ParseStringSidToSid(LPCWSTR StringSid, PSID pSid, LPDWORD cBytes)
2255 BOOL bret = FALSE;
2256 SID* pisid=pSid;
2258 if (!StringSid)
2260 SetLastError(ERROR_INVALID_PARAMETER);
2261 return FALSE;
2264 *cBytes = ComputeStringSidSize(StringSid);
2265 if (!pisid) /* Simply compute the size */
2266 return TRUE;
2268 if (*StringSid != 'S' || *StringSid != '-') /* S-R-I-S-S */
2270 int i = 0;
2271 int csubauth = ((*cBytes - sizeof(SID)) / sizeof(DWORD)) + 1;
2273 StringSid += 2; /* Advance to Revision */
2274 pisid->Revision = atoiW(StringSid);
2276 if (pisid->Revision != SDDL_REVISION)
2277 goto lend; /* ERROR_INVALID_SID */
2279 pisid->SubAuthorityCount = csubauth;
2281 while (*StringSid && *StringSid != '-')
2282 StringSid++; /* Advance to identifier authority */
2284 pisid->IdentifierAuthority.Value[5] = atoiW(StringSid);
2286 if (pisid->IdentifierAuthority.Value[5] > 5)
2287 goto lend; /* ERROR_INVALID_SID */
2289 while (*StringSid)
2291 while (*StringSid && *StringSid != '-')
2292 StringSid++;
2294 pisid->SubAuthority[i++] = atoiW(StringSid);
2297 if (i != pisid->SubAuthorityCount)
2298 goto lend; /* ERROR_INVALID_SID */
2300 bret = TRUE;
2302 else /* String constant format - Only available in winxp and above */
2304 pisid->Revision = SDDL_REVISION;
2305 pisid->SubAuthorityCount = 1;
2307 FIXME("String constant not supported: %s\n", debugstr_wn(StringSid, 2));
2309 /* TODO: Lookup string of well-known SIDs in table */
2310 pisid->IdentifierAuthority.Value[5] = 0;
2311 pisid->SubAuthority[0] = 0;
2313 bret = TRUE;
2316 lend:
2317 if (!bret)
2318 SetLastError(ERROR_INVALID_SID);
2320 return bret;
2323 /******************************************************************************
2324 * GetNamedSecurityInfoA [ADVAPI32.@]
2326 DWORD WINAPI GetNamedSecurityInfoA(LPSTR pObjectName,
2327 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
2328 PSID* ppsidOwner, PSID* ppsidGroup, PACL* ppDacl, PACL* ppSacl,
2329 PSECURITY_DESCRIPTOR* ppSecurityDescriptor)
2331 DWORD len;
2332 LPWSTR wstr = NULL;
2333 DWORD r;
2335 TRACE("%s %d %ld %p %p %p %p %p\n", pObjectName, ObjectType, SecurityInfo,
2336 ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor);
2338 if( pObjectName )
2340 len = MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, NULL, 0 );
2341 wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR));
2342 MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, wstr, len );
2345 r = GetNamedSecurityInfoW( wstr, ObjectType, SecurityInfo, ppsidOwner,
2346 ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor );
2348 if( wstr )
2349 HeapFree( GetProcessHeap(), 0, wstr );
2351 return r;
2354 /******************************************************************************
2355 * GetNamedSecurityInfoW [ADVAPI32.@]
2357 DWORD WINAPI GetNamedSecurityInfoW(LPWSTR pObjectName,
2358 SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo,
2359 PSID* ppsidOwner, PSID* ppsidGroup, PACL* ppDacl, PACL* ppSacl,
2360 PSECURITY_DESCRIPTOR* ppSecurityDescriptor)
2362 FIXME("%s %d %ld %p %p %p %p %p\n", debugstr_w(pObjectName), ObjectType, SecurityInfo,
2363 ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor);
2364 return ERROR_CALL_NOT_IMPLEMENTED;