Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / clr / src / BCL / System / Security / PermissionSetTriple.cs / 1 / PermissionSetTriple.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*==============================================================================
**
** Class: PermissionSetTriple
**
** Purpose: Container class for holding an AppDomain's Grantset and Refused sets.
** Also used for CompressedStacks which brings in the third PermissionSet.
** Hence, the name PermissionSetTriple.
**
=============================================================================*/
namespace System.Security
{
using IEnumerator = System.Collections.IEnumerator;
using System.Security;
using System.Security.Permissions;
using System.Runtime.InteropServices;
[Serializable()]
sealed internal class PermissionSetTriple
{
unsafe static private RuntimeMethodHandle s_emptyRMH = new RuntimeMethodHandle(null);
static private PermissionToken s_zoneToken;
static private PermissionToken s_urlToken;
internal PermissionSet AssertSet;
internal PermissionSet GrantSet;
internal PermissionSet RefusedSet;
internal PermissionSetTriple()
{
Reset();
}
internal PermissionSetTriple(PermissionSetTriple triple)
{
this.AssertSet = triple.AssertSet;
this.GrantSet = triple.GrantSet;
this.RefusedSet = triple.RefusedSet;
}
internal void Reset()
{
AssertSet = null;
GrantSet = null;
RefusedSet = null;
}
internal bool IsEmpty()
{
return (AssertSet == null && GrantSet == null && RefusedSet == null);
}
private PermissionToken ZoneToken
{
get
{
if (s_zoneToken == null)
s_zoneToken = PermissionToken.GetToken(typeof(ZoneIdentityPermission));
return s_zoneToken;
}
}
private PermissionToken UrlToken
{
get
{
if (s_urlToken == null)
s_urlToken = PermissionToken.GetToken(typeof(UrlIdentityPermission));
return s_urlToken;
}
}
internal bool Update(PermissionSetTriple psTriple, out PermissionSetTriple retTriple)
{
retTriple = null;
// Special case: unrestricted assert. Note: dcs.Assert.IsUnrestricted => dcs.Grant.IsUnrestricted
if (psTriple.AssertSet != null && psTriple.AssertSet.IsUnrestricted())
{
return true; // stop construction
}
retTriple = UpdateAssert(psTriple.AssertSet);
UpdateGrant(psTriple.GrantSet);
UpdateRefused(psTriple.RefusedSet);
return false;
}
internal PermissionSetTriple UpdateAssert(PermissionSet in_a)
{
PermissionSetTriple retTriple = null;
if (in_a != null)
{
BCLDebug.Assert((!in_a.IsUnrestricted()), "Cannot be unrestricted here");
// if we're already asserting in_a, nothing to do
if (in_a.IsSubsetOf(AssertSet))
return null;
PermissionSet retPs;
if (GrantSet != null)
retPs = in_a.Intersect(GrantSet); // Restrict the assert to what we've already been granted
else
{
GrantSet = new PermissionSet(true);
retPs = in_a.Copy(); // Currently unrestricted Grant: assert the whole assert set
}
bool bFailedToCompress;
// removes anything that is already in the refused set from the assert set
retPs = PermissionSet.RemoveRefusedPermissionSet(retPs, RefusedSet, out bFailedToCompress);
if (!bFailedToCompress)
bFailedToCompress = PermissionSet.IsIntersectingAssertedPermissions(retPs, AssertSet);
if (bFailedToCompress)
{
retTriple = new PermissionSetTriple(this);
this.Reset();
this.GrantSet = retTriple.GrantSet.Copy();
}
if (AssertSet == null)
AssertSet = retPs;
else
AssertSet.InplaceUnion(retPs);
}
return retTriple;
}
internal void UpdateGrant(PermissionSet in_g, out ZoneIdentityPermission z,out UrlIdentityPermission u)
{
z = null;
u = null;
if (in_g != null)
{
if (GrantSet == null)
GrantSet = in_g.Copy();
else
GrantSet.InplaceIntersect(in_g);
z = (ZoneIdentityPermission)in_g.GetPermission(ZoneToken);
u = (UrlIdentityPermission)in_g.GetPermission(UrlToken);
}
}
internal void UpdateGrant(PermissionSet in_g)
{
if (in_g != null)
{
if (GrantSet == null)
GrantSet = in_g.Copy();
else
GrantSet.InplaceIntersect(in_g);
}
}
internal void UpdateRefused(PermissionSet in_r)
{
if (in_r != null)
{
if (RefusedSet == null)
RefusedSet = in_r.Copy();
else
RefusedSet.InplaceUnion(in_r);
}
}
static bool CheckAssert(PermissionSet pSet, CodeAccessPermission demand, PermissionToken permToken)
{
if (pSet != null)
{
pSet.CheckDecoded(demand, permToken);
CodeAccessPermission perm = (CodeAccessPermission)pSet.GetPermission(demand);
// If the assert set does contain the demanded permission, halt the stackwalk
try
{
if ((pSet.IsUnrestricted() && demand.CanUnrestrictedOverride()) || demand.CheckAssert(perm))
{
return SecurityRuntime.StackHalt;
}
}
catch (ArgumentException)
{
}
}
return SecurityRuntime.StackContinue;
}
static bool CheckAssert(PermissionSet assertPset, PermissionSet demandSet, out PermissionSet newDemandSet)
{
newDemandSet = null;
if (assertPset!= null)
{
assertPset.CheckDecoded(demandSet);
// If this frame asserts a superset of the demand set we're done
if (demandSet.CheckAssertion(assertPset))
return SecurityRuntime.StackHalt;
PermissionSet.RemoveAssertedPermissionSet(demandSet, assertPset, out newDemandSet);
}
return SecurityRuntime.StackContinue;
}
internal bool CheckDemand(CodeAccessPermission demand, PermissionToken permToken, RuntimeMethodHandle rmh)
{
if (CheckAssert(AssertSet, demand, permToken) == SecurityRuntime.StackHalt)
return SecurityRuntime.StackHalt;
CodeAccessSecurityEngine.CheckHelper(GrantSet, RefusedSet, demand, permToken, rmh, null, SecurityAction.Demand, true);
return SecurityRuntime.StackContinue;
}
internal bool CheckSetDemand(PermissionSet demandSet , out PermissionSet alteredDemandset, RuntimeMethodHandle rmh)
{
alteredDemandset = null;
if (CheckAssert(AssertSet, demandSet, out alteredDemandset) == SecurityRuntime.StackHalt)
return SecurityRuntime.StackHalt;
if (alteredDemandset != null)
demandSet = alteredDemandset; // note that this does not modify demandSet external to this function.
CodeAccessSecurityEngine.CheckSetHelper(GrantSet, RefusedSet, demandSet, rmh, null, SecurityAction.Demand, true);
return SecurityRuntime.StackContinue;
}
internal bool CheckDemandNoThrow(CodeAccessPermission demand, PermissionToken permToken)
{
BCLDebug.Assert(AssertSet == null, "AssertSet not null");
return CodeAccessSecurityEngine.CheckHelper(GrantSet, RefusedSet, demand, permToken, s_emptyRMH, null, SecurityAction.Demand, false);
}
internal bool CheckSetDemandNoThrow(PermissionSet demandSet)
{
BCLDebug.Assert(AssertSet == null, "AssertSet not null");
return CodeAccessSecurityEngine.CheckSetHelper(GrantSet, RefusedSet, demandSet, s_emptyRMH, null, SecurityAction.Demand, false);
}
///
/// Check to see if the triple satisfies a demand for the permission represented by the flag.
///
///
/// If the triple asserts for one of the bits in the flags, it is zeroed out.
///
/// set of flags to check (See PermissionType)
internal bool CheckFlags(ref int flags)
{
if (AssertSet != null)
{
// remove any permissions which were asserted for
int assertFlags = SecurityManager.GetSpecialFlags(AssertSet, null);
if ((flags & assertFlags) != 0)
flags = flags & ~assertFlags;
}
return (SecurityManager.GetSpecialFlags(GrantSet, RefusedSet) & flags) == flags;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*==============================================================================
**
** Class: PermissionSetTriple
**
** Purpose: Container class for holding an AppDomain's Grantset and Refused sets.
** Also used for CompressedStacks which brings in the third PermissionSet.
** Hence, the name PermissionSetTriple.
**
=============================================================================*/
namespace System.Security
{
using IEnumerator = System.Collections.IEnumerator;
using System.Security;
using System.Security.Permissions;
using System.Runtime.InteropServices;
[Serializable()]
sealed internal class PermissionSetTriple
{
unsafe static private RuntimeMethodHandle s_emptyRMH = new RuntimeMethodHandle(null);
static private PermissionToken s_zoneToken;
static private PermissionToken s_urlToken;
internal PermissionSet AssertSet;
internal PermissionSet GrantSet;
internal PermissionSet RefusedSet;
internal PermissionSetTriple()
{
Reset();
}
internal PermissionSetTriple(PermissionSetTriple triple)
{
this.AssertSet = triple.AssertSet;
this.GrantSet = triple.GrantSet;
this.RefusedSet = triple.RefusedSet;
}
internal void Reset()
{
AssertSet = null;
GrantSet = null;
RefusedSet = null;
}
internal bool IsEmpty()
{
return (AssertSet == null && GrantSet == null && RefusedSet == null);
}
private PermissionToken ZoneToken
{
get
{
if (s_zoneToken == null)
s_zoneToken = PermissionToken.GetToken(typeof(ZoneIdentityPermission));
return s_zoneToken;
}
}
private PermissionToken UrlToken
{
get
{
if (s_urlToken == null)
s_urlToken = PermissionToken.GetToken(typeof(UrlIdentityPermission));
return s_urlToken;
}
}
internal bool Update(PermissionSetTriple psTriple, out PermissionSetTriple retTriple)
{
retTriple = null;
// Special case: unrestricted assert. Note: dcs.Assert.IsUnrestricted => dcs.Grant.IsUnrestricted
if (psTriple.AssertSet != null && psTriple.AssertSet.IsUnrestricted())
{
return true; // stop construction
}
retTriple = UpdateAssert(psTriple.AssertSet);
UpdateGrant(psTriple.GrantSet);
UpdateRefused(psTriple.RefusedSet);
return false;
}
internal PermissionSetTriple UpdateAssert(PermissionSet in_a)
{
PermissionSetTriple retTriple = null;
if (in_a != null)
{
BCLDebug.Assert((!in_a.IsUnrestricted()), "Cannot be unrestricted here");
// if we're already asserting in_a, nothing to do
if (in_a.IsSubsetOf(AssertSet))
return null;
PermissionSet retPs;
if (GrantSet != null)
retPs = in_a.Intersect(GrantSet); // Restrict the assert to what we've already been granted
else
{
GrantSet = new PermissionSet(true);
retPs = in_a.Copy(); // Currently unrestricted Grant: assert the whole assert set
}
bool bFailedToCompress;
// removes anything that is already in the refused set from the assert set
retPs = PermissionSet.RemoveRefusedPermissionSet(retPs, RefusedSet, out bFailedToCompress);
if (!bFailedToCompress)
bFailedToCompress = PermissionSet.IsIntersectingAssertedPermissions(retPs, AssertSet);
if (bFailedToCompress)
{
retTriple = new PermissionSetTriple(this);
this.Reset();
this.GrantSet = retTriple.GrantSet.Copy();
}
if (AssertSet == null)
AssertSet = retPs;
else
AssertSet.InplaceUnion(retPs);
}
return retTriple;
}
internal void UpdateGrant(PermissionSet in_g, out ZoneIdentityPermission z,out UrlIdentityPermission u)
{
z = null;
u = null;
if (in_g != null)
{
if (GrantSet == null)
GrantSet = in_g.Copy();
else
GrantSet.InplaceIntersect(in_g);
z = (ZoneIdentityPermission)in_g.GetPermission(ZoneToken);
u = (UrlIdentityPermission)in_g.GetPermission(UrlToken);
}
}
internal void UpdateGrant(PermissionSet in_g)
{
if (in_g != null)
{
if (GrantSet == null)
GrantSet = in_g.Copy();
else
GrantSet.InplaceIntersect(in_g);
}
}
internal void UpdateRefused(PermissionSet in_r)
{
if (in_r != null)
{
if (RefusedSet == null)
RefusedSet = in_r.Copy();
else
RefusedSet.InplaceUnion(in_r);
}
}
static bool CheckAssert(PermissionSet pSet, CodeAccessPermission demand, PermissionToken permToken)
{
if (pSet != null)
{
pSet.CheckDecoded(demand, permToken);
CodeAccessPermission perm = (CodeAccessPermission)pSet.GetPermission(demand);
// If the assert set does contain the demanded permission, halt the stackwalk
try
{
if ((pSet.IsUnrestricted() && demand.CanUnrestrictedOverride()) || demand.CheckAssert(perm))
{
return SecurityRuntime.StackHalt;
}
}
catch (ArgumentException)
{
}
}
return SecurityRuntime.StackContinue;
}
static bool CheckAssert(PermissionSet assertPset, PermissionSet demandSet, out PermissionSet newDemandSet)
{
newDemandSet = null;
if (assertPset!= null)
{
assertPset.CheckDecoded(demandSet);
// If this frame asserts a superset of the demand set we're done
if (demandSet.CheckAssertion(assertPset))
return SecurityRuntime.StackHalt;
PermissionSet.RemoveAssertedPermissionSet(demandSet, assertPset, out newDemandSet);
}
return SecurityRuntime.StackContinue;
}
internal bool CheckDemand(CodeAccessPermission demand, PermissionToken permToken, RuntimeMethodHandle rmh)
{
if (CheckAssert(AssertSet, demand, permToken) == SecurityRuntime.StackHalt)
return SecurityRuntime.StackHalt;
CodeAccessSecurityEngine.CheckHelper(GrantSet, RefusedSet, demand, permToken, rmh, null, SecurityAction.Demand, true);
return SecurityRuntime.StackContinue;
}
internal bool CheckSetDemand(PermissionSet demandSet , out PermissionSet alteredDemandset, RuntimeMethodHandle rmh)
{
alteredDemandset = null;
if (CheckAssert(AssertSet, demandSet, out alteredDemandset) == SecurityRuntime.StackHalt)
return SecurityRuntime.StackHalt;
if (alteredDemandset != null)
demandSet = alteredDemandset; // note that this does not modify demandSet external to this function.
CodeAccessSecurityEngine.CheckSetHelper(GrantSet, RefusedSet, demandSet, rmh, null, SecurityAction.Demand, true);
return SecurityRuntime.StackContinue;
}
internal bool CheckDemandNoThrow(CodeAccessPermission demand, PermissionToken permToken)
{
BCLDebug.Assert(AssertSet == null, "AssertSet not null");
return CodeAccessSecurityEngine.CheckHelper(GrantSet, RefusedSet, demand, permToken, s_emptyRMH, null, SecurityAction.Demand, false);
}
internal bool CheckSetDemandNoThrow(PermissionSet demandSet)
{
BCLDebug.Assert(AssertSet == null, "AssertSet not null");
return CodeAccessSecurityEngine.CheckSetHelper(GrantSet, RefusedSet, demandSet, s_emptyRMH, null, SecurityAction.Demand, false);
}
///
/// Check to see if the triple satisfies a demand for the permission represented by the flag.
///
///
/// If the triple asserts for one of the bits in the flags, it is zeroed out.
///
/// set of flags to check (See PermissionType)
internal bool CheckFlags(ref int flags)
{
if (AssertSet != null)
{
// remove any permissions which were asserted for
int assertFlags = SecurityManager.GetSpecialFlags(AssertSet, null);
if ((flags & assertFlags) != 0)
flags = flags & ~assertFlags;
}
return (SecurityManager.GetSpecialFlags(GrantSet, RefusedSet) & flags) == flags;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- OleDbParameter.cs
- PersistenceContextEnlistment.cs
- EntityDataReader.cs
- VariableExpressionConverter.cs
- HttpModulesSection.cs
- DeclarativeCatalogPart.cs
- RepeatBehaviorConverter.cs
- HtmlContainerControl.cs
- ButtonStandardAdapter.cs
- StructuralCache.cs
- Pts.cs
- DataServiceQueryProvider.cs
- FixedSOMLineCollection.cs
- Animatable.cs
- DataGridViewTopLeftHeaderCell.cs
- oledbmetadatacolumnnames.cs
- XmlUnspecifiedAttribute.cs
- SkipStoryboardToFill.cs
- Console.cs
- SqlGenericUtil.cs
- OpacityConverter.cs
- ComplexBindingPropertiesAttribute.cs
- PropertySourceInfo.cs
- SystemBrushes.cs
- TaiwanCalendar.cs
- RootBuilder.cs
- MediaTimeline.cs
- BaseHashHelper.cs
- PropertyStore.cs
- DrawingContext.cs
- InstanceDataCollection.cs
- StorageModelBuildProvider.cs
- DataGridTextBox.cs
- DataSetFieldSchema.cs
- PeerPresenceInfo.cs
- AspNetSynchronizationContext.cs
- HashAlgorithm.cs
- StringTraceRecord.cs
- CodeSubDirectoriesCollection.cs
- ObjectMaterializedEventArgs.cs
- HttpContext.cs
- MimeTypeMapper.cs
- DocumentApplicationJournalEntry.cs
- CollectionBuilder.cs
- AlignmentYValidation.cs
- IntSecurity.cs
- SoapReflector.cs
- OleDbRowUpdatingEvent.cs
- LocalServiceSecuritySettingsElement.cs
- ImageUrlEditor.cs
- KeyEvent.cs
- AsnEncodedData.cs
- DependencyPropertyValueSerializer.cs
- ComplexPropertyEntry.cs
- ComponentTray.cs
- PTProvider.cs
- ProviderException.cs
- TiffBitmapEncoder.cs
- UnsafeNativeMethodsPenimc.cs
- JournalEntryListConverter.cs
- BufferedGraphicsContext.cs
- XmlSecureResolver.cs
- BindableTemplateBuilder.cs
- ModulesEntry.cs
- RunInstallerAttribute.cs
- TextParagraphView.cs
- TextContainerHelper.cs
- xmlsaver.cs
- SynchronizationFilter.cs
- SelectionItemProviderWrapper.cs
- GatewayDefinition.cs
- UnsafeNativeMethods.cs
- StringFreezingAttribute.cs
- PagerStyle.cs
- QueryableDataSource.cs
- AppDomainUnloadedException.cs
- Serializer.cs
- TemplateKeyConverter.cs
- UmAlQuraCalendar.cs
- CalendarDataBindingHandler.cs
- WindowsAuthenticationModule.cs
- TextEmbeddedObject.cs
- DataPager.cs
- ServiceElementCollection.cs
- VectorAnimationUsingKeyFrames.cs
- HttpListener.cs
- IntegerCollectionEditor.cs
- HttpModule.cs
- Image.cs
- CatalogPartCollection.cs
- WebPartDisplayModeCollection.cs
- ExpressionConverter.cs
- ParameterBuilder.cs
- HtmlTableCellCollection.cs
- MgmtConfigurationRecord.cs
- WeakReferenceEnumerator.cs
- DataError.cs
- DecoderFallback.cs
- HwndProxyElementProvider.cs
- basenumberconverter.cs