internal bool CheckDeny(PermissionSet deniedSet, out IPermission firstPermThatFailed) { firstPermThatFailed = null; if (deniedSet == null || deniedSet.FastIsEmpty() || this.FastIsEmpty()) return true; if(this.m_Unrestricted && deniedSet.m_Unrestricted) return false; CodeAccessPermission permThis, permThat; PermissionSetEnumeratorInternal enumThis = new PermissionSetEnumeratorInternal(this); while (enumThis.MoveNext()) { permThis = enumThis.Current as CodeAccessPermission; if(permThis == null || permThis.IsSubsetOf(null)) continue; // ignore non-CAS permissions in the grant set. if (deniedSet.m_Unrestricted) { firstPermThatFailed = permThis; return false; } permThat = (CodeAccessPermission)deniedSet.GetPermission(enumThis.GetCurrentIndex()); if (!permThis.CheckDeny(permThat)) { firstPermThatFailed = permThis; return false; } } if(this.m_Unrestricted) { PermissionSetEnumeratorInternal enumThat = new PermissionSetEnumeratorInternal(deniedSet); while (enumThat.MoveNext()) { if(enumThat.Current is IPermission) return false; } } return true; }
internal static void RemoveAssertedPermissionSet(PermissionSet demandSet, PermissionSet assertSet, out PermissionSet alteredDemandSet) { Contract.Assert(!assertSet.IsUnrestricted(), "Cannot call this function if assertSet is unrestricted"); alteredDemandSet = null; PermissionSetEnumeratorInternal enumerator = new PermissionSetEnumeratorInternal(demandSet); while (enumerator.MoveNext()) { CodeAccessPermission demandDerm = (CodeAccessPermission)enumerator.Current; int i = enumerator.GetCurrentIndex(); if (demandDerm != null) { CodeAccessPermission assertPerm = (CodeAccessPermission)assertSet.GetPermission(i); try { if (demandDerm.CheckAssert(assertPerm)) { if (alteredDemandSet == null) alteredDemandSet = demandSet.Copy(); alteredDemandSet.RemovePermission(i); } } catch (ArgumentException) { } } } return; }
internal static bool IsIntersectingAssertedPermissions(PermissionSet assertSet1, PermissionSet assertSet2) { bool isIntersecting = false; if (assertSet1 != null && assertSet2 != null) { PermissionSetEnumeratorInternal enumerator = new PermissionSetEnumeratorInternal(assertSet2); while (enumerator.MoveNext()) { CodeAccessPermission perm2 = (CodeAccessPermission)enumerator.Current; int i = enumerator.GetCurrentIndex(); if (perm2 != null) { CodeAccessPermission perm1 = (CodeAccessPermission)assertSet1.GetPermission(i); try { if (perm1 != null && !perm1.Equals(perm2)) { isIntersecting = true; // Same type of permission, but with different flags or something - cannot union them } } catch (ArgumentException) { isIntersecting = true; //assume worst case } } } } return isIntersecting; }
internal static PermissionSet RemoveRefusedPermissionSet(PermissionSet assertSet, PermissionSet refusedSet, out bool bFailedToCompress) { Contract.Assert((assertSet == null || !assertSet.IsUnrestricted()), "Cannot be unrestricted here"); PermissionSet retPs = null; bFailedToCompress = false; if (assertSet == null) return null; if (refusedSet != null) { if (refusedSet.IsUnrestricted()) return null; // we're refusing everything...cannot assert anything now. PermissionSetEnumeratorInternal enumerator = new PermissionSetEnumeratorInternal(refusedSet); while (enumerator.MoveNext()) { CodeAccessPermission refusedPerm = (CodeAccessPermission)enumerator.Current; int i = enumerator.GetCurrentIndex(); if (refusedPerm != null) { CodeAccessPermission perm = (CodeAccessPermission)assertSet.GetPermission(i); try { if (refusedPerm.Intersect(perm) != null) { if (refusedPerm.Equals(perm)) { if (retPs == null) retPs = assertSet.Copy(); retPs.RemovePermission(i); } else { // Asserting a permission, part of which is already denied/refused // cannot compress this assert bFailedToCompress = true; return assertSet; } } } catch (ArgumentException) { // Any exception during removing a refused set from assert set => we play it safe and not assert that perm if (retPs == null) retPs = assertSet.Copy(); retPs.RemovePermission(i); } } } } if (retPs != null) return retPs; return assertSet; }
internal bool CheckDeny(PermissionSet deniedSet, out IPermission firstPermThatFailed) { firstPermThatFailed = null; if (((deniedSet != null) && !deniedSet.FastIsEmpty()) && !this.FastIsEmpty()) { if (this.m_Unrestricted && deniedSet.m_Unrestricted) { return false; } PermissionSetEnumeratorInternal internal2 = new PermissionSetEnumeratorInternal(this); while (internal2.MoveNext()) { CodeAccessPermission current = internal2.Current as CodeAccessPermission; if ((current != null) && !current.IsSubsetOf(null)) { if (deniedSet.m_Unrestricted) { firstPermThatFailed = current; return false; } CodeAccessPermission permission = (CodeAccessPermission) deniedSet.GetPermission(internal2.GetCurrentIndex()); if (!current.CheckDeny(permission)) { firstPermThatFailed = current; return false; } } } if (this.m_Unrestricted) { PermissionSetEnumeratorInternal internal3 = new PermissionSetEnumeratorInternal(deniedSet); while (internal3.MoveNext()) { if (internal3.Current is IPermission) { return false; } } } } return true; }
internal static PermissionSet RemoveRefusedPermissionSet(PermissionSet assertSet, PermissionSet refusedSet, out bool bFailedToCompress) { PermissionSet set = null; bFailedToCompress = false; if (assertSet == null) { return null; } if (refusedSet != null) { if (refusedSet.IsUnrestricted()) { return null; } PermissionSetEnumeratorInternal internal2 = new PermissionSetEnumeratorInternal(refusedSet); while (internal2.MoveNext()) { CodeAccessPermission current = (CodeAccessPermission) internal2.Current; int currentIndex = internal2.GetCurrentIndex(); if (current != null) { CodeAccessPermission permission = (CodeAccessPermission) assertSet.GetPermission(currentIndex); try { if (current.Intersect(permission) == null) { continue; } if (current.Equals(permission)) { if (set == null) { set = assertSet.Copy(); } set.RemovePermission(currentIndex); continue; } bFailedToCompress = true; return assertSet; } catch (ArgumentException) { if (set == null) { set = assertSet.Copy(); } set.RemovePermission(currentIndex); continue; } } } } if (set != null) { return set; } return assertSet; }
internal static void RemoveAssertedPermissionSet(PermissionSet demandSet, PermissionSet assertSet, out PermissionSet alteredDemandSet) { alteredDemandSet = null; PermissionSetEnumeratorInternal internal2 = new PermissionSetEnumeratorInternal(demandSet); while (internal2.MoveNext()) { CodeAccessPermission current = (CodeAccessPermission) internal2.Current; int currentIndex = internal2.GetCurrentIndex(); if (current != null) { CodeAccessPermission permission = (CodeAccessPermission) assertSet.GetPermission(currentIndex); try { if (current.CheckAssert(permission)) { if (alteredDemandSet == null) { alteredDemandSet = demandSet.Copy(); } alteredDemandSet.RemovePermission(currentIndex); } continue; } catch (ArgumentException) { continue; } } } }
internal static bool IsIntersectingAssertedPermissions(PermissionSet assertSet1, PermissionSet assertSet2) { bool flag = false; if ((assertSet1 != null) && (assertSet2 != null)) { PermissionSetEnumeratorInternal internal2 = new PermissionSetEnumeratorInternal(assertSet2); while (internal2.MoveNext()) { CodeAccessPermission current = (CodeAccessPermission) internal2.Current; int currentIndex = internal2.GetCurrentIndex(); if (current != null) { CodeAccessPermission permission = (CodeAccessPermission) assertSet1.GetPermission(currentIndex); try { if ((permission != null) && !permission.Equals(current)) { flag = true; } continue; } catch (ArgumentException) { flag = true; continue; } } } } return flag; }