4 * Copyright 1996-1998 Marcus Meissner
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
35 #include "wine/exception.h"
38 #include "wine/debug.h"
40 #include "stackframe.h"
44 #include "ntdll_misc.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
49 #define NT_SUCCESS(status) (status == STATUS_SUCCESS)
51 /* filter for page-fault exceptions */
52 static WINE_EXCEPTION_FILTER(page_fault)
54 if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION)
55 return EXCEPTION_EXECUTE_HANDLER;
56 return EXCEPTION_CONTINUE_SEARCH;
63 /******************************************************************************
64 * RtlAllocateAndInitializeSid [NTDLL.@]
67 BOOLEAN WINAPI RtlAllocateAndInitializeSid (
68 PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
69 BYTE nSubAuthorityCount,
70 DWORD nSubAuthority0, DWORD nSubAuthority1,
71 DWORD nSubAuthority2, DWORD nSubAuthority3,
72 DWORD nSubAuthority4, DWORD nSubAuthority5,
73 DWORD nSubAuthority6, DWORD nSubAuthority7,
76 TRACE("(%p, 0x%04x,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,%p)\n",
77 pIdentifierAuthority,nSubAuthorityCount,
78 nSubAuthority0, nSubAuthority1, nSubAuthority2, nSubAuthority3,
79 nSubAuthority4, nSubAuthority5, nSubAuthority6, nSubAuthority7, pSid);
81 if (!(*pSid = RtlAllocateHeap( ntdll_get_process_heap(), 0,
82 RtlLengthRequiredSid(nSubAuthorityCount))))
85 (*pSid)->Revision = SID_REVISION;
87 if (pIdentifierAuthority)
88 memcpy(&(*pSid)->IdentifierAuthority, pIdentifierAuthority, sizeof (SID_IDENTIFIER_AUTHORITY));
89 *RtlSubAuthorityCountSid(*pSid) = nSubAuthorityCount;
91 if (nSubAuthorityCount > 0)
92 *RtlSubAuthoritySid(*pSid, 0) = nSubAuthority0;
93 if (nSubAuthorityCount > 1)
94 *RtlSubAuthoritySid(*pSid, 1) = nSubAuthority1;
95 if (nSubAuthorityCount > 2)
96 *RtlSubAuthoritySid(*pSid, 2) = nSubAuthority2;
97 if (nSubAuthorityCount > 3)
98 *RtlSubAuthoritySid(*pSid, 3) = nSubAuthority3;
99 if (nSubAuthorityCount > 4)
100 *RtlSubAuthoritySid(*pSid, 4) = nSubAuthority4;
101 if (nSubAuthorityCount > 5)
102 *RtlSubAuthoritySid(*pSid, 5) = nSubAuthority5;
103 if (nSubAuthorityCount > 6)
104 *RtlSubAuthoritySid(*pSid, 6) = nSubAuthority6;
105 if (nSubAuthorityCount > 7)
106 *RtlSubAuthoritySid(*pSid, 7) = nSubAuthority7;
108 return STATUS_SUCCESS;
110 /******************************************************************************
111 * RtlEqualSid [NTDLL.@]
113 * Determine if two SIDs are equal.
116 * pSid1 [I] Source SID
117 * pSid2 [I] SID to compare with
120 * TRUE, if pSid1 is equal to pSid2,
123 BOOL WINAPI RtlEqualSid( PSID pSid1, PSID pSid2 )
125 if (!RtlValidSid(pSid1) || !RtlValidSid(pSid2))
128 if (*RtlSubAuthorityCountSid(pSid1) != *RtlSubAuthorityCountSid(pSid2))
131 if (memcmp(pSid1, pSid2, RtlLengthSid(pSid1)) != 0)
137 /******************************************************************************
138 * RtlEqualPrefixSid [NTDLL.@]
140 BOOL WINAPI RtlEqualPrefixSid (PSID pSid1, PSID pSid2)
142 if (!RtlValidSid(pSid1) || !RtlValidSid(pSid2))
145 if (*RtlSubAuthorityCountSid(pSid1) != *RtlSubAuthorityCountSid(pSid2))
148 if (memcmp(pSid1, pSid2, RtlLengthRequiredSid(pSid1->SubAuthorityCount - 1)) != 0)
155 /******************************************************************************
156 * RtlFreeSid [NTDLL.@]
158 * Free the resources used by a SID.
161 * pSid [I] SID to Free.
166 DWORD WINAPI RtlFreeSid(PSID pSid)
168 TRACE("(%p)\n", pSid);
169 RtlFreeHeap( ntdll_get_process_heap(), 0, pSid );
170 return STATUS_SUCCESS;
173 /**************************************************************************
174 * RtlLengthRequiredSid [NTDLL.@]
176 * Determine the amount of memory a SID will use
179 * nrofsubauths [I] Number of Sub Authorities in the SID.
182 * The size, in bytes, of a SID with nrofsubauths Sub Authorities.
184 DWORD WINAPI RtlLengthRequiredSid(DWORD nrofsubauths)
186 return (nrofsubauths-1)*sizeof(DWORD) + sizeof(SID);
189 /**************************************************************************
190 * RtlLengthSid [NTDLL.@]
192 * Determine the amount of memory a SID is using
195 * pSid [I] SID to ge the size of.
198 * The size, in bytes, of pSid.
200 DWORD WINAPI RtlLengthSid(PSID pSid)
202 TRACE("sid=%p\n",pSid);
204 return RtlLengthRequiredSid(*RtlSubAuthorityCountSid(pSid));
207 /**************************************************************************
208 * RtlInitializeSid [NTDLL.@]
213 * pSid [I] SID to initialise
214 * pIdentifierAuthority [I] Identifier Authority
215 * nSubAuthorityCount [I] Number of Sub Authorities
218 * Success: TRUE. pSid is initialised withe the details given.
219 * Failure: FALSE, if nSubAuthorityCount is >= SID_MAX_SUB_AUTHORITIES.
221 BOOL WINAPI RtlInitializeSid(
223 PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
224 BYTE nSubAuthorityCount)
227 if (nSubAuthorityCount >= SID_MAX_SUB_AUTHORITIES)
230 pSid->Revision = SID_REVISION;
231 pSid->SubAuthorityCount = nSubAuthorityCount;
232 if (pIdentifierAuthority)
233 memcpy(&pSid->IdentifierAuthority, pIdentifierAuthority, sizeof (SID_IDENTIFIER_AUTHORITY));
235 for (i = 0; i < nSubAuthorityCount; i++)
236 *RtlSubAuthoritySid(pSid, i) = 0;
241 /**************************************************************************
242 * RtlSubAuthoritySid [NTDLL.@]
244 * Return the Sub Authority of a SID
247 * pSid [I] SID to get the Sub Authority from.
248 * nSubAuthority [I] Sub Authority number.
251 * A pointer to The Sub Authority value of pSid.
253 LPDWORD WINAPI RtlSubAuthoritySid( PSID pSid, DWORD nSubAuthority )
255 return &(pSid->SubAuthority[nSubAuthority]);
258 /**************************************************************************
259 * RtlIdentifierAuthoritySid [NTDLL.@]
261 * Return the Identifier Authority of a SID.
264 * pSid [I] SID to get the Identifier Authority from.
267 * A pointer to the Identifier Authority value of pSid.
269 PSID_IDENTIFIER_AUTHORITY WINAPI RtlIdentifierAuthoritySid( PSID pSid )
271 return &(pSid->IdentifierAuthority);
274 /**************************************************************************
275 * RtlSubAuthorityCountSid [NTDLL.@]
277 * Get the number of Sub Authorities in a SID.
280 * pSid [I] SID to get the count from.
283 * A pointer to the Sub Authority count of pSid.
285 LPBYTE WINAPI RtlSubAuthorityCountSid(PSID pSid)
287 return &(pSid->SubAuthorityCount);
290 /**************************************************************************
291 * RtlCopySid [NTDLL.@]
293 DWORD WINAPI RtlCopySid( DWORD nDestinationSidLength, PSID pDestinationSid, PSID pSourceSid )
295 if (!pSourceSid || !RtlValidSid(pSourceSid) ||
296 (nDestinationSidLength < RtlLengthSid(pSourceSid)))
299 if (nDestinationSidLength < (pSourceSid->SubAuthorityCount*4+8))
302 memmove(pDestinationSid, pSourceSid, pSourceSid->SubAuthorityCount*4+8);
305 /******************************************************************************
306 * RtlValidSid [NTDLL.@]
308 * Determine if a SID is valid.
311 * pSid [I] SID to check
314 * TRUE if pSid is valid,
317 BOOLEAN WINAPI RtlValidSid( PSID pSid )
323 if (!pSid || pSid->Revision != SID_REVISION ||
324 pSid->SubAuthorityCount > SID_MAX_SUB_AUTHORITIES)
331 WARN("(%p): invalid pointer!\n", pSid);
340 * security descriptor functions
343 /**************************************************************************
344 * RtlCreateSecurityDescriptor [NTDLL.@]
346 * Initialise a SECURITY_DESCRIPTOR.
349 * lpsd [O] Descriptor to initialise.
350 * rev [I] Revision, must be set to SECURITY_DESCRIPTOR_REVISION.
353 * Success: STATUS_SUCCESS.
354 * Failure: STATUS_UNKNOWN_REVISION if rev is incorrect.
356 NTSTATUS WINAPI RtlCreateSecurityDescriptor(
357 PSECURITY_DESCRIPTOR lpsd,
360 if (rev!=SECURITY_DESCRIPTOR_REVISION)
361 return STATUS_UNKNOWN_REVISION;
362 memset(lpsd,'\0',sizeof(*lpsd));
363 lpsd->Revision = SECURITY_DESCRIPTOR_REVISION;
364 return STATUS_SUCCESS;
366 /**************************************************************************
367 * RtlValidSecurityDescriptor [NTDLL.@]
369 * Determine if a SECURITY_DESCRIPTOR is valid.
372 * SecurityDescriptor [I] Descriptor to check.
375 * Success: STATUS_SUCCESS.
376 * Failure: STATUS_INVALID_SECURITY_DESCR or STATUS_UNKNOWN_REVISION.
378 NTSTATUS WINAPI RtlValidSecurityDescriptor(
379 PSECURITY_DESCRIPTOR SecurityDescriptor)
381 if ( ! SecurityDescriptor )
382 return STATUS_INVALID_SECURITY_DESCR;
383 if ( SecurityDescriptor->Revision != SECURITY_DESCRIPTOR_REVISION )
384 return STATUS_UNKNOWN_REVISION;
386 return STATUS_SUCCESS;
389 /**************************************************************************
390 * RtlLengthSecurityDescriptor [NTDLL.@]
392 ULONG WINAPI RtlLengthSecurityDescriptor(
393 PSECURITY_DESCRIPTOR SecurityDescriptor)
396 Size = SECURITY_DESCRIPTOR_MIN_LENGTH;
397 if ( SecurityDescriptor == NULL )
400 if ( SecurityDescriptor->Owner != NULL )
401 Size += SecurityDescriptor->Owner->SubAuthorityCount;
402 if ( SecurityDescriptor->Group != NULL )
403 Size += SecurityDescriptor->Group->SubAuthorityCount;
406 if ( SecurityDescriptor->Sacl != NULL )
407 Size += SecurityDescriptor->Sacl->AclSize;
408 if ( SecurityDescriptor->Dacl != NULL )
409 Size += SecurityDescriptor->Dacl->AclSize;
414 /******************************************************************************
415 * RtlGetDaclSecurityDescriptor [NTDLL.@]
418 NTSTATUS WINAPI RtlGetDaclSecurityDescriptor(
419 IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
420 OUT PBOOLEAN lpbDaclPresent,
422 OUT PBOOLEAN lpbDaclDefaulted)
424 TRACE("(%p,%p,%p,%p)\n",
425 pSecurityDescriptor, lpbDaclPresent, *pDacl, lpbDaclDefaulted);
427 if (pSecurityDescriptor->Revision != SECURITY_DESCRIPTOR_REVISION)
428 return STATUS_UNKNOWN_REVISION ;
430 if ( (*lpbDaclPresent = (SE_DACL_PRESENT & pSecurityDescriptor->Control) ? 1 : 0) )
432 if ( SE_SELF_RELATIVE & pSecurityDescriptor->Control)
433 { *pDacl = (PACL) ((LPBYTE)pSecurityDescriptor + (DWORD)pSecurityDescriptor->Dacl);
436 { *pDacl = pSecurityDescriptor->Dacl;
440 *lpbDaclDefaulted = (( SE_DACL_DEFAULTED & pSecurityDescriptor->Control ) ? 1 : 0);
442 return STATUS_SUCCESS;
445 /**************************************************************************
446 * RtlSetDaclSecurityDescriptor [NTDLL.@]
448 NTSTATUS WINAPI RtlSetDaclSecurityDescriptor (
449 PSECURITY_DESCRIPTOR lpsd,
452 BOOLEAN dacldefaulted )
454 if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
455 return STATUS_UNKNOWN_REVISION;
456 if (lpsd->Control & SE_SELF_RELATIVE)
457 return STATUS_INVALID_SECURITY_DESCR;
460 { lpsd->Control &= ~SE_DACL_PRESENT;
464 lpsd->Control |= SE_DACL_PRESENT;
468 lpsd->Control |= SE_DACL_DEFAULTED;
470 lpsd->Control &= ~SE_DACL_DEFAULTED;
472 return STATUS_SUCCESS;
475 /******************************************************************************
476 * RtlGetSaclSecurityDescriptor [NTDLL.@]
479 NTSTATUS WINAPI RtlGetSaclSecurityDescriptor(
480 IN PSECURITY_DESCRIPTOR pSecurityDescriptor,
481 OUT PBOOLEAN lpbSaclPresent,
483 OUT PBOOLEAN lpbSaclDefaulted)
485 TRACE("(%p,%p,%p,%p)\n",
486 pSecurityDescriptor, lpbSaclPresent, *pSacl, lpbSaclDefaulted);
488 if (pSecurityDescriptor->Revision != SECURITY_DESCRIPTOR_REVISION)
489 return STATUS_UNKNOWN_REVISION ;
491 if ( (*lpbSaclPresent = (SE_SACL_PRESENT & pSecurityDescriptor->Control) ? 1 : 0) )
493 if ( SE_SELF_RELATIVE & pSecurityDescriptor->Control)
494 { *pSacl = (PACL) ((LPBYTE)pSecurityDescriptor + (DWORD)pSecurityDescriptor->Sacl);
497 { *pSacl = pSecurityDescriptor->Sacl;
501 *lpbSaclDefaulted = (( SE_SACL_DEFAULTED & pSecurityDescriptor->Control ) ? 1 : 0);
503 return STATUS_SUCCESS;
506 /**************************************************************************
507 * RtlSetSaclSecurityDescriptor [NTDLL.@]
509 NTSTATUS WINAPI RtlSetSaclSecurityDescriptor (
510 PSECURITY_DESCRIPTOR lpsd,
513 BOOLEAN sacldefaulted)
515 if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
516 return STATUS_UNKNOWN_REVISION;
517 if (lpsd->Control & SE_SELF_RELATIVE)
518 return STATUS_INVALID_SECURITY_DESCR;
520 lpsd->Control &= ~SE_SACL_PRESENT;
523 lpsd->Control |= SE_SACL_PRESENT;
526 lpsd->Control |= SE_SACL_DEFAULTED;
528 lpsd->Control &= ~SE_SACL_DEFAULTED;
529 return STATUS_SUCCESS;
532 /**************************************************************************
533 * RtlGetOwnerSecurityDescriptor [NTDLL.@]
535 NTSTATUS WINAPI RtlGetOwnerSecurityDescriptor(
536 PSECURITY_DESCRIPTOR SecurityDescriptor,
538 PBOOLEAN OwnerDefaulted)
540 if ( !SecurityDescriptor || !Owner || !OwnerDefaulted )
541 return STATUS_INVALID_PARAMETER;
543 *Owner = SecurityDescriptor->Owner;
544 if ( *Owner != NULL ) {
545 if ( SecurityDescriptor->Control & SE_OWNER_DEFAULTED )
546 *OwnerDefaulted = TRUE;
548 *OwnerDefaulted = FALSE;
550 return STATUS_SUCCESS;
553 /**************************************************************************
554 * RtlSetOwnerSecurityDescriptor [NTDLL.@]
556 NTSTATUS WINAPI RtlSetOwnerSecurityDescriptor(
557 PSECURITY_DESCRIPTOR lpsd,
559 BOOLEAN ownerdefaulted)
561 if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
562 return STATUS_UNKNOWN_REVISION;
563 if (lpsd->Control & SE_SELF_RELATIVE)
564 return STATUS_INVALID_SECURITY_DESCR;
568 lpsd->Control |= SE_OWNER_DEFAULTED;
570 lpsd->Control &= ~SE_OWNER_DEFAULTED;
571 return STATUS_SUCCESS;
574 /**************************************************************************
575 * RtlSetGroupSecurityDescriptor [NTDLL.@]
577 NTSTATUS WINAPI RtlSetGroupSecurityDescriptor (
578 PSECURITY_DESCRIPTOR lpsd,
580 BOOLEAN groupdefaulted)
582 if (lpsd->Revision!=SECURITY_DESCRIPTOR_REVISION)
583 return STATUS_UNKNOWN_REVISION;
584 if (lpsd->Control & SE_SELF_RELATIVE)
585 return STATUS_INVALID_SECURITY_DESCR;
589 lpsd->Control |= SE_GROUP_DEFAULTED;
591 lpsd->Control &= ~SE_GROUP_DEFAULTED;
592 return STATUS_SUCCESS;
594 /**************************************************************************
595 * RtlGetGroupSecurityDescriptor [NTDLL.@]
597 NTSTATUS WINAPI RtlGetGroupSecurityDescriptor(
598 PSECURITY_DESCRIPTOR SecurityDescriptor,
600 PBOOLEAN GroupDefaulted)
602 if ( !SecurityDescriptor || !Group || !GroupDefaulted )
603 return STATUS_INVALID_PARAMETER;
605 *Group = SecurityDescriptor->Group;
606 if ( *Group != NULL ) {
607 if ( SecurityDescriptor->Control & SE_GROUP_DEFAULTED )
608 *GroupDefaulted = TRUE;
610 *GroupDefaulted = FALSE;
612 return STATUS_SUCCESS;
615 /**************************************************************************
616 * RtlMakeSelfRelativeSD [NTDLL.@]
618 NTSTATUS WINAPI RtlMakeSelfRelativeSD(
619 IN PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
620 IN PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,
621 IN OUT LPDWORD lpdwBufferLength)
623 FIXME("(%p,%p,%p(%lu))\n", pAbsoluteSecurityDescriptor,
624 pSelfRelativeSecurityDescriptor, lpdwBufferLength,*lpdwBufferLength);
625 return STATUS_SUCCESS;
629 * access control list's
632 /**************************************************************************
633 * RtlCreateAcl [NTDLL.@]
636 * This should return NTSTATUS
638 NTSTATUS WINAPI RtlCreateAcl(PACL acl,DWORD size,DWORD rev)
640 TRACE("%p 0x%08lx 0x%08lx\n", acl, size, rev);
642 if (rev!=ACL_REVISION)
643 return STATUS_INVALID_PARAMETER;
644 if (size<sizeof(ACL))
645 return STATUS_BUFFER_TOO_SMALL;
647 return STATUS_INVALID_PARAMETER;
649 memset(acl,'\0',sizeof(ACL));
650 acl->AclRevision = rev;
653 return STATUS_SUCCESS;
656 /**************************************************************************
657 * RtlFirstFreeAce [NTDLL.@]
658 * looks for the AceCount+1 ACE, and if it is still within the alloced
659 * ACL, return a pointer to it
661 BOOLEAN WINAPI RtlFirstFreeAce(
669 ace = (PACE_HEADER)(acl+1);
670 for (i=0;i<acl->AceCount;i++) {
671 if ((DWORD)ace>=(((DWORD)acl)+acl->AclSize))
673 ace = (PACE_HEADER)(((BYTE*)ace)+ace->AceSize);
675 if ((DWORD)ace>=(((DWORD)acl)+acl->AclSize))
681 /**************************************************************************
682 * RtlAddAce [NTDLL.@]
684 NTSTATUS WINAPI RtlAddAce(
688 PACE_HEADER acestart,
691 PACE_HEADER ace,targetace;
694 if (acl->AclRevision != ACL_REVISION)
695 return STATUS_INVALID_PARAMETER;
696 if (!RtlFirstFreeAce(acl,&targetace))
697 return STATUS_INVALID_PARAMETER;
698 nrofaces=0;ace=acestart;
699 while (((DWORD)ace-(DWORD)acestart)<acelen) {
701 ace = (PACE_HEADER)(((BYTE*)ace)+ace->AceSize);
703 if ((DWORD)targetace+acelen>(DWORD)acl+acl->AclSize) /* too much aces */
704 return STATUS_INVALID_PARAMETER;
705 memcpy((LPBYTE)targetace,acestart,acelen);
706 acl->AceCount+=nrofaces;
707 return STATUS_SUCCESS;
710 /******************************************************************************
711 * RtlAddAccessAllowedAce [NTDLL.@]
713 NTSTATUS WINAPI RtlAddAccessAllowedAce(
715 IN DWORD dwAceRevision,
719 return RtlAddAccessAllowedAceEx( pAcl, dwAceRevision, 0, AccessMask, pSid);
722 /******************************************************************************
723 * RtlAddAccessAllowedAceEx [NTDLL.@]
725 NTSTATUS WINAPI RtlAddAccessAllowedAceEx(
727 IN DWORD dwAceRevision,
733 ACCESS_ALLOWED_ACE * pAaAce;
736 TRACE("(%p,0x%08lx,0x%08lx,%p)\n",
737 pAcl, dwAceRevision, AccessMask, pSid);
739 if (!RtlValidSid(pSid))
740 return STATUS_INVALID_SID;
741 if (!RtlValidAcl(pAcl))
742 return STATUS_INVALID_ACL;
744 dwLengthSid = RtlLengthSid(pSid);
745 if (!RtlFirstFreeAce(pAcl, (PACE_HEADER *) &pAaAce))
746 return STATUS_INVALID_ACL;
749 return STATUS_ALLOTTED_SPACE_EXCEEDED;
751 dwSpaceLeft = (DWORD)pAcl + pAcl->AclSize - (DWORD)pAaAce;
752 if (dwSpaceLeft < sizeof(*pAaAce) - sizeof(pAaAce->SidStart) + dwLengthSid)
753 return STATUS_ALLOTTED_SPACE_EXCEEDED;
755 pAaAce->Header.AceType = ACCESS_ALLOWED_ACE_TYPE;
756 pAaAce->Header.AceFlags = AceFlags;
757 pAaAce->Header.AceSize = sizeof(*pAaAce) - sizeof(pAaAce->SidStart) + dwLengthSid;
758 pAaAce->Mask = AccessMask;
760 RtlCopySid(dwLengthSid, (PSID)&pAaAce->SidStart, pSid);
761 return STATUS_SUCCESS;
764 /******************************************************************************
765 * RtlAddAccessDeniedAce [NTDLL.@]
767 NTSTATUS WINAPI RtlAddAccessDeniedAce(
769 IN DWORD dwAceRevision,
773 return RtlAddAccessDeniedAceEx( pAcl, dwAceRevision, 0, AccessMask, pSid);
776 /******************************************************************************
777 * RtlAddAccessDeniedAceEx [NTDLL.@]
779 NTSTATUS WINAPI RtlAddAccessDeniedAceEx(
781 IN DWORD dwAceRevision,
788 ACCESS_DENIED_ACE * pAdAce;
790 TRACE("(%p,0x%08lx,0x%08lx,%p)\n",
791 pAcl, dwAceRevision, AccessMask, pSid);
793 if (!RtlValidSid(pSid))
794 return STATUS_INVALID_SID;
795 if (!RtlValidAcl(pAcl))
796 return STATUS_INVALID_ACL;
798 dwLengthSid = RtlLengthSid(pSid);
799 if (!RtlFirstFreeAce(pAcl, (PACE_HEADER *) &pAdAce))
800 return STATUS_INVALID_ACL;
803 return STATUS_ALLOTTED_SPACE_EXCEEDED;
805 dwSpaceLeft = (DWORD)pAcl + pAcl->AclSize - (DWORD)pAdAce;
806 if (dwSpaceLeft < sizeof(*pAdAce) - sizeof(pAdAce->SidStart) + dwLengthSid)
807 return STATUS_ALLOTTED_SPACE_EXCEEDED;
809 pAdAce->Header.AceType = ACCESS_DENIED_ACE_TYPE;
810 pAdAce->Header.AceFlags = AceFlags;
811 pAdAce->Header.AceSize = sizeof(*pAdAce) - sizeof(pAdAce->SidStart) + dwLengthSid;
812 pAdAce->Mask = AccessMask;
814 RtlCopySid(dwLengthSid, (PSID)&pAdAce->SidStart, pSid);
815 return STATUS_SUCCESS;
818 /******************************************************************************
819 * RtlValidAcl [NTDLL.@]
821 BOOLEAN WINAPI RtlValidAcl(PACL pAcl)
824 TRACE("(%p)\n", pAcl);
831 if (pAcl->AclRevision != ACL_REVISION)
835 ace = (PACE_HEADER)(pAcl+1);
837 for (i=0;i<=pAcl->AceCount;i++)
839 if ((char *)ace > (char *)pAcl + pAcl->AclSize)
844 ace = (PACE_HEADER)(((BYTE*)ace)+ace->AceSize);
850 WARN("(%p): invalid pointer!\n", pAcl);
857 /******************************************************************************
858 * RtlGetAce [NTDLL.@]
860 DWORD WINAPI RtlGetAce(PACL pAcl,DWORD dwAceIndex,LPVOID *pAce )
864 TRACE("(%p,%ld,%p)\n",pAcl,dwAceIndex,pAce);
866 if ((dwAceIndex < 0) || (dwAceIndex > pAcl->AceCount))
867 return STATUS_INVALID_PARAMETER;
869 ace = (PACE_HEADER)(pAcl + 1);
870 for (;dwAceIndex;dwAceIndex--)
871 ace = (PACE_HEADER)(((BYTE*)ace)+ace->AceSize);
873 *pAce = (LPVOID) ace;
875 return STATUS_SUCCESS;
882 /******************************************************************************
883 * RtlAdjustPrivilege [NTDLL.@]
885 DWORD WINAPI RtlAdjustPrivilege(DWORD x1,DWORD x2,DWORD x3,DWORD x4)
887 FIXME("(0x%08lx,0x%08lx,0x%08lx,0x%08lx),stub!\n",x1,x2,x3,x4);
891 /******************************************************************************
892 * RtlImpersonateSelf [NTDLL.@]
895 RtlImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
897 FIXME("(%08x), stub\n", ImpersonationLevel);
901 /******************************************************************************
902 * NtAccessCheck [NTDLL.@]
903 * ZwAccessCheck [NTDLL.@]
907 IN PSECURITY_DESCRIPTOR SecurityDescriptor,
908 IN HANDLE ClientToken,
909 IN ACCESS_MASK DesiredAccess,
910 IN PGENERIC_MAPPING GenericMapping,
911 OUT PPRIVILEGE_SET PrivilegeSet,
912 OUT PULONG ReturnLength,
913 OUT PULONG GrantedAccess,
914 OUT PBOOLEAN AccessStatus)
916 FIXME("(%p, %p, %08lx, %p, %p, %p, %p, %p), stub\n",
917 SecurityDescriptor, ClientToken, DesiredAccess, GenericMapping,
918 PrivilegeSet, ReturnLength, GrantedAccess, AccessStatus);
919 *AccessStatus = TRUE;
920 return STATUS_SUCCESS;
923 /******************************************************************************
924 * NtSetSecurityObject [NTDLL.@]
929 IN SECURITY_INFORMATION SecurityInformation,
930 IN PSECURITY_DESCRIPTOR SecurityDescriptor)
932 FIXME("%p 0x%08lx %p\n", Handle, SecurityInformation, SecurityDescriptor);
933 return STATUS_SUCCESS;
936 /******************************************************************************
937 * RtlGetControlSecurityDescriptor (NTDLL.@)
940 NTSTATUS WINAPI RtlGetControlSecurityDescriptor(
941 PSECURITY_DESCRIPTOR pSecurityDescriptor,
942 PSECURITY_DESCRIPTOR_CONTROL pControl,
943 LPDWORD lpdwRevision)
945 FIXME("(%p,%p,%p),stub!\n",pSecurityDescriptor,pControl,lpdwRevision);
946 return STATUS_SUCCESS;
949 /******************************************************************************
950 * RtlConvertSidToUnicodeString (NTDLL.@)
952 * The returned SID is used to access the USER registry hive usually
954 * the native function returns something like
955 * "S-1-5-21-0000000000-000000000-0000000000-500";
957 NTSTATUS WINAPI RtlConvertSidToUnicodeString(
958 PUNICODE_STRING String,
960 BOOLEAN AllocateString)
962 const char *p = wine_get_user_name();
966 FIXME("(%p %p %u)\n", String, Sid, AllocateString);
968 RtlInitAnsiString(&AnsiStr, p);
969 status = RtlAnsiStringToUnicodeString(String, &AnsiStr, AllocateString);
971 TRACE("%s (%u %u)\n",debugstr_w(String->Buffer),String->Length,String->MaximumLength);