From 37cceb6db53672996323aa4a759b976c46973252 Mon Sep 17 00:00:00 2001 From: David Hall Date: Tue, 9 Apr 2019 11:46:27 -0600 Subject: [PATCH] BREAKING CHANGE: Removed methods that can cause unpredictable results due to ACE size differences. --- Security/AccessControl/AccCtrlHelper.cs | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/Security/AccessControl/AccCtrlHelper.cs b/Security/AccessControl/AccCtrlHelper.cs index 9a59c669..18efe41a 100644 --- a/Security/AccessControl/AccCtrlHelper.cs +++ b/Security/AccessControl/AccCtrlHelper.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using System.Security.AccessControl; using System.Security.Principal; +using Vanara.Extensions; using Vanara.InteropServices; using Vanara.PInvoke; using static Vanara.PInvoke.AdvApi32; @@ -57,25 +58,9 @@ namespace Vanara.Security.AccessControl /// Helper methods for working with Access Control structures. public static class AccessControlHelper { - public static ACCESS_ALLOWED_ACE GetAce(this PACL pAcl, int aceIndex) - { - if (AdvApi32.GetAce(pAcl, aceIndex, out var acePtr)) - return (ACCESS_ALLOWED_ACE)Marshal.PtrToStructure((IntPtr)acePtr, typeof(ACCESS_ALLOWED_ACE)); - throw new System.ComponentModel.Win32Exception(); - } + public static uint GetAceCount(this PACL pAcl) => pAcl.GetAclInformation().AceCount; - public static IEnumerable GetAces(this PACL pAcl) - { - var cnt = GetAceCount(pAcl); - for (var i = 0; i < cnt; i++) - yield return GetAce(pAcl, i); - } - - public static uint GetAceCount(this PACL pAcl) => GetAclInfo(pAcl).AceCount; - - public static ACL_SIZE_INFORMATION GetAclInfo(PACL pAcl) => pAcl.GetAclInformation(); - - public static uint GetAclSize(PACL pAcl) => GetAclInfo(pAcl).AclBytesInUse; + public static uint GetAclSize(PACL pAcl) => pAcl.GetAclInformation().AclBytesInUse; public static uint GetEffectiveRights(this PSID pSid, PSECURITY_DESCRIPTOR pSD) {