Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -0,0 +1,411 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// EnvironmentPermission.cs
//
// <OWNER>[....]</OWNER>
//
namespace System.Security.Permissions {
using System.Security;
using System;
using SecurityElement = System.Security.SecurityElement;
using System.Security.Util;
using System.IO;
using System.Globalization;
using System.Diagnostics.Contracts;
[Serializable]
[Flags]
[System.Runtime.InteropServices.ComVisible(true)]
public enum EnvironmentPermissionAccess
{
NoAccess = 0x00,
Read = 0x01,
Write = 0x02,
AllAccess = 0x03,
}
[Serializable]
internal class EnvironmentStringExpressionSet : StringExpressionSet
{
public EnvironmentStringExpressionSet()
: base( true, null, false )
{
}
public EnvironmentStringExpressionSet( String str )
: base( true, str, false )
{
}
protected override StringExpressionSet CreateNewEmpty()
{
return new EnvironmentStringExpressionSet();
}
protected override bool StringSubsetString( String left, String right, bool ignoreCase )
{
return (ignoreCase?(String.Compare( left, right, StringComparison.OrdinalIgnoreCase) == 0):
(String.Compare( left, right, StringComparison.Ordinal) == 0));
}
protected override String ProcessWholeString( String str )
{
return str;
}
protected override String ProcessSingleString( String str )
{
return str;
}
[SecuritySafeCritical]
public override string ToString()
{
// SafeCritical: we're not storing path information in the strings, so exposing them out is fine ...
// they're just the same strings that came in to the .ctor.
return base.UnsafeToString();
}
}
[System.Runtime.InteropServices.ComVisible(true)]
[Serializable]
sealed public class EnvironmentPermission : CodeAccessPermission, IUnrestrictedPermission, IBuiltInPermission
{
private StringExpressionSet m_read;
private StringExpressionSet m_write;
private bool m_unrestricted;
public EnvironmentPermission(PermissionState state)
{
if (state == PermissionState.Unrestricted)
m_unrestricted = true;
else if (state == PermissionState.None)
m_unrestricted = false;
else
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPermissionState"));
}
public EnvironmentPermission( EnvironmentPermissionAccess flag, String pathList )
{
SetPathList( flag, pathList );
}
public void SetPathList( EnvironmentPermissionAccess flag, String pathList )
{
VerifyFlag( flag );
m_unrestricted = false;
if ((flag & EnvironmentPermissionAccess.Read) != 0)
m_read = null;
if ((flag & EnvironmentPermissionAccess.Write) != 0)
m_write = null;
AddPathList( flag, pathList );
}
[System.Security.SecuritySafeCritical] // auto-generated
public void AddPathList( EnvironmentPermissionAccess flag, String pathList )
{
VerifyFlag( flag );
if (FlagIsSet( flag, EnvironmentPermissionAccess.Read ))
{
if (m_read == null)
m_read = new EnvironmentStringExpressionSet();
m_read.AddExpressions( pathList );
}
if (FlagIsSet( flag, EnvironmentPermissionAccess.Write ))
{
if (m_write == null)
m_write = new EnvironmentStringExpressionSet();
m_write.AddExpressions( pathList );
}
}
public String GetPathList( EnvironmentPermissionAccess flag )
{
VerifyFlag( flag );
ExclusiveFlag( flag );
if (FlagIsSet( flag, EnvironmentPermissionAccess.Read ))
{
if (m_read == null)
{
return "";
}
return m_read.ToString();
}
if (FlagIsSet( flag, EnvironmentPermissionAccess.Write ))
{
if (m_write == null)
{
return "";
}
return m_write.ToString();
}
/* not reached */
return "";
}
private void VerifyFlag( EnvironmentPermissionAccess flag )
{
if ((flag & ~EnvironmentPermissionAccess.AllAccess) != 0)
throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)flag));
Contract.EndContractBlock();
}
private void ExclusiveFlag( EnvironmentPermissionAccess flag )
{
if (flag == EnvironmentPermissionAccess.NoAccess)
{
throw new ArgumentException( Environment.GetResourceString("Arg_EnumNotSingleFlag") );
}
if (((int)flag & ((int)flag-1)) != 0)
{
throw new ArgumentException( Environment.GetResourceString("Arg_EnumNotSingleFlag") );
}
Contract.EndContractBlock();
}
private bool FlagIsSet( EnvironmentPermissionAccess flag, EnvironmentPermissionAccess question )
{
return (flag & question) != 0;
}
private bool IsEmpty()
{
return (!m_unrestricted &&
(this.m_read == null || this.m_read.IsEmpty()) &&
(this.m_write == null || this.m_write.IsEmpty()));
}
//------------------------------------------------------
//
// CODEACCESSPERMISSION IMPLEMENTATION
//
//------------------------------------------------------
public bool IsUnrestricted()
{
return m_unrestricted;
}
//------------------------------------------------------
//
// IPERMISSION IMPLEMENTATION
//
//------------------------------------------------------
[System.Security.SecuritySafeCritical] // auto-generated
public override bool IsSubsetOf(IPermission target)
{
if (target == null)
{
return this.IsEmpty();
}
try
{
EnvironmentPermission operand = (EnvironmentPermission)target;
if (operand.IsUnrestricted())
return true;
else if (this.IsUnrestricted())
return false;
else
return ((this.m_read == null || this.m_read.IsSubsetOf( operand.m_read )) &&
(this.m_write == null || this.m_write.IsSubsetOf( operand.m_write )));
}
catch (InvalidCastException)
{
throw new
ArgumentException(
Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)
);
}
}
[System.Security.SecuritySafeCritical] // auto-generated
public override IPermission Intersect(IPermission target)
{
if (target == null)
{
return null;
}
else if (!VerifyType(target))
{
throw new
ArgumentException(
Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)
);
}
else if (this.IsUnrestricted())
{
return target.Copy();
}
EnvironmentPermission operand = (EnvironmentPermission)target;
if (operand.IsUnrestricted())
{
return this.Copy();
}
StringExpressionSet intersectRead = this.m_read == null ? null : this.m_read.Intersect( operand.m_read );
StringExpressionSet intersectWrite = this.m_write == null ? null : this.m_write.Intersect( operand.m_write );
if ((intersectRead == null || intersectRead.IsEmpty()) &&
(intersectWrite == null || intersectWrite.IsEmpty()))
{
return null;
}
EnvironmentPermission intersectPermission = new EnvironmentPermission(PermissionState.None);
intersectPermission.m_unrestricted = false;
intersectPermission.m_read = intersectRead;
intersectPermission.m_write = intersectWrite;
return intersectPermission;
}
[System.Security.SecuritySafeCritical] // auto-generated
public override IPermission Union(IPermission other)
{
if (other == null)
{
return this.Copy();
}
else if (!VerifyType(other))
{
throw new
ArgumentException(
Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)
);
}
EnvironmentPermission operand = (EnvironmentPermission)other;
if (this.IsUnrestricted() || operand.IsUnrestricted())
{
return new EnvironmentPermission( PermissionState.Unrestricted );
}
StringExpressionSet unionRead = this.m_read == null ? operand.m_read : this.m_read.Union( operand.m_read );
StringExpressionSet unionWrite = this.m_write == null ? operand.m_write : this.m_write.Union( operand.m_write );
if ((unionRead == null || unionRead.IsEmpty()) &&
(unionWrite == null || unionWrite.IsEmpty()))
{
return null;
}
EnvironmentPermission unionPermission = new EnvironmentPermission(PermissionState.None);
unionPermission.m_unrestricted = false;
unionPermission.m_read = unionRead;
unionPermission.m_write = unionWrite;
return unionPermission;
}
public override IPermission Copy()
{
EnvironmentPermission copy = new EnvironmentPermission(PermissionState.None);
if (this.m_unrestricted)
{
copy.m_unrestricted = true;
}
else
{
copy.m_unrestricted = false;
if (this.m_read != null)
{
copy.m_read = this.m_read.Copy();
}
if (this.m_write != null)
{
copy.m_write = this.m_write.Copy();
}
}
return copy;
}
#if FEATURE_CAS_POLICY
public override SecurityElement ToXml()
{
SecurityElement esd = CodeAccessPermission.CreatePermissionElement( this, "System.Security.Permissions.EnvironmentPermission" );
if (!IsUnrestricted())
{
if (this.m_read != null && !this.m_read.IsEmpty())
{
esd.AddAttribute( "Read", SecurityElement.Escape( m_read.ToString() ) );
}
if (this.m_write != null && !this.m_write.IsEmpty())
{
esd.AddAttribute( "Write", SecurityElement.Escape( m_write.ToString() ) );
}
}
else
{
esd.AddAttribute( "Unrestricted", "true" );
}
return esd;
}
public override void FromXml(SecurityElement esd)
{
CodeAccessPermission.ValidateElement( esd, this );
String et;
if (XMLUtil.IsUnrestricted(esd))
{
m_unrestricted = true;
return;
}
m_unrestricted = false;
m_read = null;
m_write = null;
et = esd.Attribute( "Read" );
if (et != null)
{
m_read = new EnvironmentStringExpressionSet( et );
}
et = esd.Attribute( "Write" );
if (et != null)
{
m_write = new EnvironmentStringExpressionSet( et );
}
}
#endif // FEATURE_CAS_POLICY
/// <internalonly/>
int IBuiltInPermission.GetTokenIndex()
{
return EnvironmentPermission.GetTokenIndex();
}
internal static int GetTokenIndex()
{
return BuiltInPermissionIndex.EnvironmentPermissionIndex;
}
}
}

View File

@@ -0,0 +1,195 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// FileDialogPermission.cs
//
// <OWNER>[....]</OWNER>
//
namespace System.Security.Permissions {
using System;
using System.Text;
using System.Security;
using System.Security.Util;
using System.IO;
using System.Runtime.Serialization;
using System.Reflection;
using System.Collections;
using System.Globalization;
using System.Diagnostics.Contracts;
[Serializable]
[Flags]
[System.Runtime.InteropServices.ComVisible(true)]
public enum FileDialogPermissionAccess {
None = 0x00,
Open = 0x01,
Save = 0x02,
OpenSave = Open | Save
}
[Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class FileDialogPermission : CodeAccessPermission, IUnrestrictedPermission, IBuiltInPermission {
FileDialogPermissionAccess access;
public FileDialogPermission(PermissionState state) {
if (state == PermissionState.Unrestricted) {
SetUnrestricted(true);
}
else if (state == PermissionState.None) {
SetUnrestricted(false);
Reset();
}
else {
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPermissionState"));
}
}
public FileDialogPermission(FileDialogPermissionAccess access) {
VerifyAccess(access);
this.access = access;
}
public FileDialogPermissionAccess Access {
get {
return access;
}
set {
VerifyAccess(value);
access = value;
}
}
public override IPermission Copy() {
return new FileDialogPermission(this.access);
}
#if FEATURE_CAS_POLICY
public override void FromXml(SecurityElement esd) {
CodeAccessPermission.ValidateElement(esd, this);
if (XMLUtil.IsUnrestricted(esd)) {
SetUnrestricted(true);
return;
}
access = FileDialogPermissionAccess.None;
string accessXml = esd.Attribute("Access");
if (accessXml != null)
access = (FileDialogPermissionAccess)Enum.Parse(typeof(FileDialogPermissionAccess), accessXml);
}
#endif // FEATURE_CAS_POLICY
/// <internalonly/>
int IBuiltInPermission.GetTokenIndex() {
return FileDialogPermission.GetTokenIndex();
}
internal static int GetTokenIndex() {
return BuiltInPermissionIndex.FileDialogPermissionIndex;
}
public override IPermission Intersect(IPermission target) {
if (target == null) {
return null;
}
else if (!VerifyType(target)) {
throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
}
FileDialogPermission operand = (FileDialogPermission)target;
FileDialogPermissionAccess intersectAccess = access & operand.Access;
if (intersectAccess == FileDialogPermissionAccess.None)
return null;
else
return new FileDialogPermission(intersectAccess);
}
public override bool IsSubsetOf(IPermission target) {
if (target == null) {
// Only safe subset if this is empty
return access == FileDialogPermissionAccess.None;
}
try {
FileDialogPermission operand = (FileDialogPermission)target;
if (operand.IsUnrestricted()) {
return true;
}
else if (this.IsUnrestricted()) {
return false;
}
else {
int open = (int)(access & FileDialogPermissionAccess.Open);
int save = (int)(access & FileDialogPermissionAccess.Save);
int openTarget = (int)(operand.Access & FileDialogPermissionAccess.Open);
int saveTarget = (int)(operand.Access & FileDialogPermissionAccess.Save);
return open <= openTarget && save <= saveTarget;
}
}
catch (InvalidCastException) {
throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
}
}
public bool IsUnrestricted() {
return access == FileDialogPermissionAccess.OpenSave;
}
void Reset() {
access = FileDialogPermissionAccess.None;
}
void SetUnrestricted( bool unrestricted ) {
if (unrestricted) {
access = FileDialogPermissionAccess.OpenSave;
}
}
#if FEATURE_CAS_POLICY
public override SecurityElement ToXml() {
SecurityElement esd = CodeAccessPermission.CreatePermissionElement( this, "System.Security.Permissions.FileDialogPermission" );
if (!IsUnrestricted()) {
if (access != FileDialogPermissionAccess.None) {
esd.AddAttribute("Access", Enum.GetName(typeof(FileDialogPermissionAccess), access));
}
}
else {
esd.AddAttribute("Unrestricted", "true");
}
return esd;
}
#endif // FEATURE_CAS_POLICY
public override IPermission Union(IPermission target) {
if (target == null) {
return this.Copy();
}
else if (!VerifyType(target)) {
throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
}
FileDialogPermission operand = (FileDialogPermission)target;
return new FileDialogPermission(access | operand.Access);
}
static void VerifyAccess(FileDialogPermissionAccess access) {
if ((access & ~FileDialogPermissionAccess.OpenSave) != 0 ) {
throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)access));
}
Contract.EndContractBlock();
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,125 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// GacIdentityPermission.cs
//
// <OWNER>[....]</OWNER>
//
namespace System.Security.Permissions
{
using System;
#if FEATURE_CAS_POLICY
using SecurityElement = System.Security.SecurityElement;
#endif // FEATURE_CAS_POLICY
using System.Globalization;
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false )]
[System.Runtime.InteropServices.ComVisible(true)]
[Serializable]
#pragma warning disable 618
sealed public class GacIdentityPermissionAttribute : CodeAccessSecurityAttribute
#pragma warning restore 618
{
#pragma warning disable 618
public GacIdentityPermissionAttribute( SecurityAction action )
#pragma warning restore 618
: base( action )
{
}
public override IPermission CreatePermission()
{
return new GacIdentityPermission();
}
}
[System.Runtime.InteropServices.ComVisible(true)]
[Serializable]
sealed public class GacIdentityPermission : CodeAccessPermission, IBuiltInPermission
{
//------------------------------------------------------
//
// PUBLIC CONSTRUCTORS
//
//------------------------------------------------------
public GacIdentityPermission(PermissionState state)
{
if (state != PermissionState.Unrestricted && state != PermissionState.None)
{
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPermissionState"));
}
}
public GacIdentityPermission()
{
}
//------------------------------------------------------
//
// IPERMISSION IMPLEMENTATION
//
//------------------------------------------------------
public override IPermission Copy()
{
return new GacIdentityPermission();
}
public override bool IsSubsetOf(IPermission target)
{
if (target == null)
return false;
if (!(target is GacIdentityPermission))
throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
return true;
}
public override IPermission Intersect(IPermission target)
{
if (target == null)
return null;
if (!(target is GacIdentityPermission))
throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
return this.Copy();
}
public override IPermission Union(IPermission target)
{
if (target == null)
return this.Copy();
if (!(target is GacIdentityPermission))
throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
return this.Copy();
}
#if FEATURE_CAS_POLICY
public override SecurityElement ToXml()
{
SecurityElement securityElement = CodeAccessPermission.CreatePermissionElement( this, "System.Security.Permissions.GacIdentityPermission" );
return securityElement;
}
public override void FromXml(SecurityElement securityElement)
{
CodeAccessPermission.ValidateElement(securityElement, this);
}
#endif // FEATURE_CAS_POLICY
/// <internalonly/>
int IBuiltInPermission.GetTokenIndex()
{
return GacIdentityPermission.GetTokenIndex();
}
internal static int GetTokenIndex()
{
return BuiltInPermissionIndex.GacIdentityPermissionIndex;
}
}
}

View File

@@ -0,0 +1,300 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// HostProtectionPermission.cs
//
// <OWNER>[....]</OWNER>
//
namespace System.Security.Permissions
{
using System;
using System.IO;
using System.Security.Util;
using System.Text;
using System.Threading;
using System.Runtime.Remoting;
using System.Security;
using System.Runtime.Serialization;
using System.Reflection;
using System.Globalization;
using System.Diagnostics.Contracts;
// Keep this enum in [....] with tools\ngen\ngen.cpp and inc\mscoree.idl
[Serializable]
[Flags]
[System.Runtime.InteropServices.ComVisible(true)]
public enum HostProtectionResource
{
None = 0x0,
//--------------------------------
Synchronization = 0x1,
SharedState = 0x2,
ExternalProcessMgmt = 0x4,
SelfAffectingProcessMgmt = 0x8,
ExternalThreading = 0x10,
SelfAffectingThreading = 0x20,
SecurityInfrastructure = 0x40,
UI = 0x80,
MayLeakOnAbort = 0x100,
//---------------------------------
All = 0x1ff,
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly | AttributeTargets.Delegate, AllowMultiple = true, Inherited = false )]
[System.Runtime.InteropServices.ComVisible(true)]
[Serializable]
#pragma warning disable 618
sealed public class HostProtectionAttribute : CodeAccessSecurityAttribute
#pragma warning restore 618
{
private HostProtectionResource m_resources = HostProtectionResource.None;
public HostProtectionAttribute()
#pragma warning disable 618
: base( SecurityAction.LinkDemand )
#pragma warning restore 618
{
}
#pragma warning disable 618
public HostProtectionAttribute( SecurityAction action )
#pragma warning restore 618
: base( action )
{
#pragma warning disable 618
if (action != SecurityAction.LinkDemand)
#pragma warning restore 618
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag"));
Contract.EndContractBlock();
}
public HostProtectionResource Resources {
get { return m_resources; }
set { m_resources = value; }
}
public bool Synchronization {
get { return (m_resources & HostProtectionResource.Synchronization) != 0; }
set { m_resources = (value ? m_resources | HostProtectionResource.Synchronization : m_resources & ~HostProtectionResource.Synchronization); }
}
public bool SharedState {
get { return (m_resources & HostProtectionResource.SharedState) != 0; }
set { m_resources = (value ? m_resources | HostProtectionResource.SharedState : m_resources & ~HostProtectionResource.SharedState); }
}
public bool ExternalProcessMgmt {
get { return (m_resources & HostProtectionResource.ExternalProcessMgmt) != 0; }
set { m_resources = (value ? m_resources | HostProtectionResource.ExternalProcessMgmt : m_resources & ~HostProtectionResource.ExternalProcessMgmt); }
}
public bool SelfAffectingProcessMgmt {
get { return (m_resources & HostProtectionResource.SelfAffectingProcessMgmt) != 0; }
set { m_resources = (value ? m_resources | HostProtectionResource.SelfAffectingProcessMgmt : m_resources & ~HostProtectionResource.SelfAffectingProcessMgmt); }
}
public bool ExternalThreading {
get { return (m_resources & HostProtectionResource.ExternalThreading) != 0; }
set { m_resources = (value ? m_resources | HostProtectionResource.ExternalThreading : m_resources & ~HostProtectionResource.ExternalThreading); }
}
public bool SelfAffectingThreading {
get { return (m_resources & HostProtectionResource.SelfAffectingThreading) != 0; }
set { m_resources = (value ? m_resources | HostProtectionResource.SelfAffectingThreading : m_resources & ~HostProtectionResource.SelfAffectingThreading); }
}
[System.Runtime.InteropServices.ComVisible(true)]
public bool SecurityInfrastructure {
get { return (m_resources & HostProtectionResource.SecurityInfrastructure) != 0; }
set { m_resources = (value ? m_resources | HostProtectionResource.SecurityInfrastructure : m_resources & ~HostProtectionResource.SecurityInfrastructure); }
}
public bool UI {
get { return (m_resources & HostProtectionResource.UI) != 0; }
set { m_resources = (value ? m_resources | HostProtectionResource.UI : m_resources & ~HostProtectionResource.UI); }
}
public bool MayLeakOnAbort {
get { return (m_resources & HostProtectionResource.MayLeakOnAbort) != 0; }
set { m_resources = (value ? m_resources | HostProtectionResource.MayLeakOnAbort : m_resources & ~HostProtectionResource.MayLeakOnAbort); }
}
public override IPermission CreatePermission()
{
if (m_unrestricted)
{
return new HostProtectionPermission( PermissionState.Unrestricted );
}
else
{
return new HostProtectionPermission( m_resources );
}
}
}
[Serializable]
sealed internal class HostProtectionPermission : CodeAccessPermission, IUnrestrictedPermission, IBuiltInPermission
{
//------------------------------------------------------
//
// GLOBALS
//
//------------------------------------------------------
// This value is set by PermissionSet.FilterHostProtectionPermissions. It is only used for
// constructing a HostProtectionException object. Changing it will not affect HostProtection.
internal static volatile HostProtectionResource protectedResources = HostProtectionResource.None;
//------------------------------------------------------
//
// MEMBERS
//
//------------------------------------------------------
private HostProtectionResource m_resources;
//------------------------------------------------------
//
// CONSTRUCTORS
//
//------------------------------------------------------
public HostProtectionPermission(PermissionState state)
{
if (state == PermissionState.Unrestricted)
Resources = HostProtectionResource.All;
else if (state == PermissionState.None)
Resources = HostProtectionResource.None;
else
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPermissionState"));
}
public HostProtectionPermission(HostProtectionResource resources)
{
Resources = resources;
}
//------------------------------------------------------
//
// IPermission interface implementation
//
//------------------------------------------------------
public bool IsUnrestricted()
{
return Resources == HostProtectionResource.All;
}
//------------------------------------------------------
//
// Properties
//
//------------------------------------------------------
public HostProtectionResource Resources
{
set
{
if(value < HostProtectionResource.None || value > HostProtectionResource.All)
throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)value));
Contract.EndContractBlock();
m_resources = value;
}
get
{
return m_resources;
}
}
//------------------------------------------------------
//
// IPermission interface implementation
//
//------------------------------------------------------
public override bool IsSubsetOf(IPermission target)
{
if (target == null)
return m_resources == HostProtectionResource.None;
if(this.GetType() != target.GetType())
throw new ArgumentException( Environment.GetResourceString("Argument_WrongType", this.GetType().FullName) );
return ((uint)this.m_resources & (uint)((HostProtectionPermission)target).m_resources) == (uint)this.m_resources;
}
public override IPermission Union(IPermission target)
{
if (target == null)
return(this.Copy());
if(this.GetType() != target.GetType())
throw new ArgumentException( Environment.GetResourceString("Argument_WrongType", this.GetType().FullName) );
HostProtectionResource newResources = (HostProtectionResource)((uint)this.m_resources | (uint)((HostProtectionPermission)target).m_resources);
return new HostProtectionPermission(newResources);
}
public override IPermission Intersect(IPermission target)
{
if (target == null)
return null;
if(this.GetType() != target.GetType())
throw new ArgumentException( Environment.GetResourceString("Argument_WrongType", this.GetType().FullName) );
HostProtectionResource newResources = (HostProtectionResource)((uint)this.m_resources & (uint)((HostProtectionPermission)target).m_resources);
if(newResources == HostProtectionResource.None)
return null;
return new HostProtectionPermission(newResources);
}
public override IPermission Copy()
{
return new HostProtectionPermission(m_resources);
}
#if FEATURE_CAS_POLICY
//------------------------------------------------------
//
// XML
//
//------------------------------------------------------
public override SecurityElement ToXml()
{
SecurityElement esd = CodeAccessPermission.CreatePermissionElement( this, this.GetType().FullName );
if(IsUnrestricted())
esd.AddAttribute( "Unrestricted", "true" );
else
esd.AddAttribute( "Resources", XMLUtil.BitFieldEnumToString( typeof( HostProtectionResource ), Resources ) );
return esd;
}
public override void FromXml(SecurityElement esd)
{
CodeAccessPermission.ValidateElement( esd, this );
if (XMLUtil.IsUnrestricted( esd ))
Resources = HostProtectionResource.All;
else
{
String resources = esd.Attribute( "Resources" );
if (resources == null)
Resources = HostProtectionResource.None;
else
Resources = (HostProtectionResource)Enum.Parse( typeof( HostProtectionResource ), resources );
}
}
#endif // FEATURE_CAS_POLICY
//------------------------------------------------------
//
// OBJECT OVERRIDES
//
//------------------------------------------------------
/// <internalonly/>
int IBuiltInPermission.GetTokenIndex()
{
return HostProtectionPermission.GetTokenIndex();
}
internal static int GetTokenIndex()
{
return BuiltInPermissionIndex.HostProtectionPermissionIndex;
}
}
}

View File

@@ -0,0 +1,81 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// IBuiltInPermission.cs
//
// <OWNER>[....]</OWNER>
//
namespace System.Security.Permissions
{
internal interface IBuiltInPermission
{
int GetTokenIndex();
}
internal static class BuiltInPermissionIndex
{
internal const int NUM_BUILTIN_UNRESTRICTED = 10;
internal const int NUM_BUILTIN_NORMAL = 7;
// Unrestricted permissions
internal const int EnvironmentPermissionIndex = 0;
internal const int FileDialogPermissionIndex = 1;
internal const int FileIOPermissionIndex = 2;
internal const int IsolatedStorageFilePermissionIndex = 3;
internal const int ReflectionPermissionIndex = 4;
#if !FEATURE_PAL
internal const int RegistryPermissionIndex = 5;
#endif // !FEATURE_PAL
internal const int SecurityPermissionIndex = 6;
internal const int UIPermissionIndex = 7;
internal const int PrincipalPermissionIndex = 8;
internal const int HostProtectionPermissionIndex = 9;
// Normal permissions
#if !FEATURE_PAL
internal const int PublisherIdentityPermissionIndex = 0 + NUM_BUILTIN_UNRESTRICTED;
#endif // !FEATURE_PAL
internal const int SiteIdentityPermissionIndex = 1 + NUM_BUILTIN_UNRESTRICTED;
internal const int StrongNameIdentityPermissionIndex = 2 + NUM_BUILTIN_UNRESTRICTED;
internal const int UrlIdentityPermissionIndex = 3 + NUM_BUILTIN_UNRESTRICTED;
internal const int ZoneIdentityPermissionIndex = 4 + NUM_BUILTIN_UNRESTRICTED;
internal const int GacIdentityPermissionIndex = 5 + NUM_BUILTIN_UNRESTRICTED;
#if !FEATURE_PAL
internal const int KeyContainerPermissionIndex = 6 + NUM_BUILTIN_UNRESTRICTED;
#endif // !FEATURE_PAL
}
[Serializable]
internal enum BuiltInPermissionFlag
{
// Unrestricted permissions
EnvironmentPermission = 0x1,
FileDialogPermission = 0x2,
FileIOPermission = 0x4,
IsolatedStorageFilePermission = 0x8,
ReflectionPermission = 0x10,
#if !FEATURE_PAL
RegistryPermission = 0x20,
#endif // !FEATURE_PAL
SecurityPermission = 0x40,
UIPermission = 0x80,
PrincipalPermission = 0x100,
// Normal permissions
#if !FEATURE_PAL
PublisherIdentityPermission = 0x200,
#endif // !FEATURE_PAL
SiteIdentityPermission = 0x400,
StrongNameIdentityPermission = 0x800,
UrlIdentityPermission = 0x1000,
ZoneIdentityPermission = 0x2000,
#if !FEATURE_PAL
KeyContainerPermission = 0x4000,
#endif // !FEATURE_PAL
}
}

View File

@@ -0,0 +1,178 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
//
// <OWNER>[....]</OWNER>
//
// Purpose : This permission is used to controls/administer access to
// IsolatedStorageFile
//
namespace System.Security.Permissions {
using System.Globalization;
[Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
sealed public class IsolatedStorageFilePermission : IsolatedStoragePermission, IBuiltInPermission
{
public IsolatedStorageFilePermission(PermissionState state)
: base(state) { }
internal IsolatedStorageFilePermission(IsolatedStorageContainment UsageAllowed,
long ExpirationDays, bool PermanentData)
: base(UsageAllowed, ExpirationDays, PermanentData) { }
//------------------------------------------------------
//
// IPERMISSION IMPLEMENTATION
//
//------------------------------------------------------
public override IPermission Union(IPermission target)
{
if (target == null)
{
return this.Copy();
}
else if (!VerifyType(target))
{
throw new
ArgumentException(
Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)
);
}
IsolatedStorageFilePermission operand = (IsolatedStorageFilePermission)target;
if (this.IsUnrestricted() || operand.IsUnrestricted())
{
return new IsolatedStorageFilePermission( PermissionState.Unrestricted );
}
else
{
IsolatedStorageFilePermission union;
union = new IsolatedStorageFilePermission( PermissionState.None );
union.m_userQuota = max(m_userQuota,operand.m_userQuota);
union.m_machineQuota = max(m_machineQuota,operand.m_machineQuota);
union.m_expirationDays = max(m_expirationDays,operand.m_expirationDays);
union.m_permanentData = m_permanentData || operand.m_permanentData;
union.m_allowed = (IsolatedStorageContainment)max((long)m_allowed,(long)operand.m_allowed);
return union;
}
}
public override bool IsSubsetOf(IPermission target)
{
if (target == null)
{
return ((m_userQuota == 0) &&
(m_machineQuota == 0) &&
(m_expirationDays == 0) &&
(m_permanentData == false) &&
(m_allowed == IsolatedStorageContainment.None));
}
try
{
IsolatedStorageFilePermission operand = (IsolatedStorageFilePermission)target;
if (operand.IsUnrestricted())
return true;
return ((operand.m_userQuota >= m_userQuota) &&
(operand.m_machineQuota >= m_machineQuota) &&
(operand.m_expirationDays >= m_expirationDays) &&
(operand.m_permanentData || !m_permanentData) &&
(operand.m_allowed >= m_allowed));
}
catch (InvalidCastException)
{
throw new
ArgumentException(
Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)
);
}
}
public override IPermission Intersect(IPermission target)
{
if (target == null)
return null;
else if (!VerifyType(target))
{
throw new
ArgumentException(
Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)
);
}
IsolatedStorageFilePermission operand = (IsolatedStorageFilePermission)target;
if(operand.IsUnrestricted())
return Copy();
else if(IsUnrestricted())
return target.Copy();
IsolatedStorageFilePermission intersection;
intersection = new IsolatedStorageFilePermission( PermissionState.None );
intersection.m_userQuota = min(m_userQuota,operand.m_userQuota);
intersection.m_machineQuota = min(m_machineQuota,operand.m_machineQuota);
intersection.m_expirationDays = min(m_expirationDays,operand.m_expirationDays);
intersection.m_permanentData = m_permanentData && operand.m_permanentData;
intersection.m_allowed = (IsolatedStorageContainment)min((long)m_allowed,(long)operand.m_allowed);
if ((intersection.m_userQuota == 0) &&
(intersection.m_machineQuota == 0) &&
(intersection.m_expirationDays == 0) &&
(intersection.m_permanentData == false) &&
(intersection.m_allowed == IsolatedStorageContainment.None))
return null;
return intersection;
}
public override IPermission Copy()
{
IsolatedStorageFilePermission copy ;
copy = new IsolatedStorageFilePermission(PermissionState.Unrestricted);
if(!IsUnrestricted()){
copy.m_userQuota = m_userQuota;
copy.m_machineQuota = m_machineQuota;
copy.m_expirationDays = m_expirationDays;
copy.m_permanentData = m_permanentData;
copy.m_allowed = m_allowed;
}
return copy;
}
/// <internalonly/>
int IBuiltInPermission.GetTokenIndex()
{
return IsolatedStorageFilePermission.GetTokenIndex();
}
internal static int GetTokenIndex()
{
return BuiltInPermissionIndex.IsolatedStorageFilePermissionIndex;
}
//------------------------------------------------------
//
// IsolatedStoragePermission OVERRIDES
//
//------------------------------------------------------
#if FEATURE_CAS_POLICY
[System.Runtime.InteropServices.ComVisible(false)]
public override SecurityElement ToXml()
{
return base.ToXml( "System.Security.Permissions.IsolatedStorageFilePermission" );
}
#endif // FEATURE_CAS_POLICY
}
}

View File

@@ -0,0 +1,276 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// <OWNER>[....]</OWNER>
//
namespace System.Security.Permissions {
using System;
using System.IO;
using System.Security;
using System.Security.Util;
using System.Globalization;
[Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum IsolatedStorageContainment {
None = 0x00,
DomainIsolationByUser = 0x10,
ApplicationIsolationByUser = 0x15,
AssemblyIsolationByUser = 0x20,
DomainIsolationByMachine = 0x30,
AssemblyIsolationByMachine = 0x40,
ApplicationIsolationByMachine = 0x45,
DomainIsolationByRoamingUser = 0x50,
AssemblyIsolationByRoamingUser = 0x60,
ApplicationIsolationByRoamingUser = 0x65,
AdministerIsolatedStorageByUser = 0x70,
//AdministerIsolatedStorageByMachine = 0x80,
UnrestrictedIsolatedStorage = 0xF0
};
[Serializable]
#if !FEATURE_CORECLR
[SecurityPermissionAttribute( SecurityAction.InheritanceDemand, ControlEvidence = true, ControlPolicy = true )]
#endif
[System.Runtime.InteropServices.ComVisible(true)]
abstract public class IsolatedStoragePermission
: CodeAccessPermission, IUnrestrictedPermission
{
//------------------------------------------------------
//
// PRIVATE STATE DATA
//
//------------------------------------------------------
/// <internalonly/>
internal long m_userQuota;
/// <internalonly/>
internal long m_machineQuota;
/// <internalonly/>
internal long m_expirationDays;
/// <internalonly/>
internal bool m_permanentData;
/// <internalonly/>
internal IsolatedStorageContainment m_allowed;
//------------------------------------------------------
//
// CONSTRUCTORS
//
//------------------------------------------------------
protected IsolatedStoragePermission(PermissionState state)
{
if (state == PermissionState.Unrestricted)
{
m_userQuota = Int64.MaxValue;
m_machineQuota = Int64.MaxValue;
m_expirationDays = Int64.MaxValue ;
m_permanentData = true;
m_allowed = IsolatedStorageContainment.UnrestrictedIsolatedStorage;
}
else if (state == PermissionState.None)
{
m_userQuota = 0;
m_machineQuota = 0;
m_expirationDays = 0;
m_permanentData = false;
m_allowed = IsolatedStorageContainment.None;
}
else
{
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPermissionState"));
}
}
internal IsolatedStoragePermission(IsolatedStorageContainment UsageAllowed,
long ExpirationDays, bool PermanentData)
{
m_userQuota = 0; // typical demand won't include quota
m_machineQuota = 0; // typical demand won't include quota
m_expirationDays = ExpirationDays;
m_permanentData = PermanentData;
m_allowed = UsageAllowed;
}
internal IsolatedStoragePermission(IsolatedStorageContainment UsageAllowed,
long ExpirationDays, bool PermanentData, long UserQuota)
{
m_machineQuota = 0;
m_userQuota = UserQuota;
m_expirationDays = ExpirationDays;
m_permanentData = PermanentData;
m_allowed = UsageAllowed;
}
//------------------------------------------------------
//
// PUBLIC ACCESSOR METHODS
//
//------------------------------------------------------
// properties
public long UserQuota {
set{
m_userQuota = value;
}
get{
return m_userQuota;
}
}
#if false
internal long MachineQuota {
set{
m_machineQuota = value;
}
get{
return m_machineQuota;
}
}
internal long ExpirationDays {
set{
m_expirationDays = value;
}
get{
return m_expirationDays;
}
}
internal bool PermanentData {
set{
m_permanentData = value;
}
get{
return m_permanentData;
}
}
#endif
public IsolatedStorageContainment UsageAllowed {
set{
m_allowed = value;
}
get{
return m_allowed;
}
}
//------------------------------------------------------
//
// CODEACCESSPERMISSION IMPLEMENTATION
//
//------------------------------------------------------
public bool IsUnrestricted()
{
return m_allowed == IsolatedStorageContainment.UnrestrictedIsolatedStorage;
}
//------------------------------------------------------
//
// INTERNAL METHODS
//
//------------------------------------------------------
internal static long min(long x,long y) {return x>y?y:x;}
internal static long max(long x,long y) {return x<y?y:x;}
#if FEATURE_CAS_POLICY
//------------------------------------------------------
//
// PUBLIC ENCODING METHODS
//
//------------------------------------------------------
private const String _strUserQuota = "UserQuota";
private const String _strMachineQuota = "MachineQuota";
private const String _strExpiry = "Expiry";
private const String _strPermDat = "Permanent";
public override SecurityElement ToXml()
{
return ToXml ( this.GetType().FullName );
}
internal SecurityElement ToXml(String permName)
{
SecurityElement esd = CodeAccessPermission.CreatePermissionElement( this, permName );
if (!IsUnrestricted())
{
esd.AddAttribute( "Allowed", Enum.GetName( typeof( IsolatedStorageContainment ), m_allowed ) );
if (m_userQuota>0)
{
esd.AddAttribute(_strUserQuota, (m_userQuota).ToString(CultureInfo.InvariantCulture)) ;
}
if (m_machineQuota>0)
{
esd.AddAttribute(_strMachineQuota, (m_machineQuota).ToString(CultureInfo.InvariantCulture)) ;
}
if (m_expirationDays>0)
{
esd.AddAttribute( _strExpiry, (m_expirationDays).ToString(CultureInfo.InvariantCulture)) ;
}
if (m_permanentData)
{
esd.AddAttribute(_strPermDat, (m_permanentData).ToString()) ;
}
}
else
{
esd.AddAttribute( "Unrestricted", "true" );
}
return esd;
}
public override void FromXml(SecurityElement esd)
{
CodeAccessPermission.ValidateElement( esd, this );
m_allowed = IsolatedStorageContainment.None; // default if no match
if (XMLUtil.IsUnrestricted(esd))
{
m_allowed = IsolatedStorageContainment.UnrestrictedIsolatedStorage;
}
else
{
String allowed = esd.Attribute( "Allowed" );
if (allowed != null)
m_allowed = (IsolatedStorageContainment)Enum.Parse( typeof( IsolatedStorageContainment ), allowed );
}
if (m_allowed == IsolatedStorageContainment.UnrestrictedIsolatedStorage)
{
m_userQuota = Int64.MaxValue;
m_machineQuota = Int64.MaxValue;
m_expirationDays = Int64.MaxValue ;
m_permanentData = true;
}
else
{
String param;
param = esd.Attribute (_strUserQuota) ;
m_userQuota = param != null ? Int64.Parse(param, CultureInfo.InvariantCulture) : 0 ;
param = esd.Attribute (_strMachineQuota) ;
m_machineQuota = param != null ? Int64.Parse(param, CultureInfo.InvariantCulture) : 0 ;
param = esd.Attribute (_strExpiry) ;
m_expirationDays = param != null ? Int64.Parse(param, CultureInfo.InvariantCulture) : 0 ;
param = esd.Attribute (_strPermDat) ;
m_permanentData = param != null ? (Boolean.Parse(param)) : false ;
}
}
#endif // FEATURE_CAS_POLICY
}
}

View File

@@ -0,0 +1,19 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// IUnrestrictedPermission.cs
//
// <OWNER>[....]</OWNER>
//
namespace System.Security.Permissions {
using System;
[System.Runtime.InteropServices.ComVisible(true)]
public interface IUnrestrictedPermission
{
bool IsUnrestricted();
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,25 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// PermissionState.cs
//
// <OWNER>[....]</OWNER>
//
// The Runtime policy manager. Maintains a set of IdentityMapper objects that map
// inbound evidence to groups. Resolves an identity into a set of permissions
//
namespace System.Security.Permissions {
using System;
[Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum PermissionState
{
Unrestricted = 1,
None = 0,
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,324 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// PublisherIdentityPermission.cs
//
// <OWNER>[....]</OWNER>
//
namespace System.Security.Permissions
{
using System;
using SecurityElement = System.Security.SecurityElement;
using X509Certificate = System.Security.Cryptography.X509Certificates.X509Certificate;
using System.Security.Util;
using System.IO;
using System.Collections;
using System.Globalization;
[System.Runtime.InteropServices.ComVisible(true)]
[Serializable]
sealed public class PublisherIdentityPermission : CodeAccessPermission, IBuiltInPermission
{
//------------------------------------------------------
//
// PRIVATE STATE DATA
//
//------------------------------------------------------
private bool m_unrestricted;
private X509Certificate[] m_certs;
//------------------------------------------------------
//
// PUBLIC CONSTRUCTORS
//
//------------------------------------------------------
public PublisherIdentityPermission(PermissionState state)
{
if (state == PermissionState.Unrestricted)
{
m_unrestricted = true;
}
else if (state == PermissionState.None)
{
m_unrestricted = false;
}
else
{
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPermissionState"));
}
}
public PublisherIdentityPermission( X509Certificate certificate )
{
Certificate = certificate;
}
//------------------------------------------------------
//
// PUBLIC ACCESSOR METHODS
//
//------------------------------------------------------
public X509Certificate Certificate
{
set
{
CheckCertificate(value);
m_unrestricted = false;
m_certs = new X509Certificate[1];
m_certs[0] = new X509Certificate(value);
}
get
{
if(m_certs == null || m_certs.Length < 1)
return null;
if(m_certs.Length > 1)
throw new NotSupportedException(Environment.GetResourceString("NotSupported_AmbiguousIdentity"));
if(m_certs[0] == null)
return null;
return new X509Certificate(m_certs[0]);
}
}
//------------------------------------------------------
//
// PRIVATE AND PROTECTED HELPERS FOR ACCESSORS AND CONSTRUCTORS
//
//------------------------------------------------------
private static void CheckCertificate( X509Certificate certificate )
{
if (certificate == null)
{
throw new ArgumentNullException( "certificate" );
}
if (certificate.GetRawCertData() == null) {
throw new ArgumentException(Environment.GetResourceString("Argument_UninitializedCertificate"));
}
}
//------------------------------------------------------
//
// CODEACCESSPERMISSION IMPLEMENTATION
//
//------------------------------------------------------
//------------------------------------------------------
//
// IPERMISSION IMPLEMENTATION
//
//------------------------------------------------------
public override IPermission Copy()
{
PublisherIdentityPermission perm = new PublisherIdentityPermission(PermissionState.None);
perm.m_unrestricted = m_unrestricted;
if(this.m_certs != null)
{
perm.m_certs = new X509Certificate[this.m_certs.Length];
int n;
for(n = 0; n < this.m_certs.Length; n++)
perm.m_certs[n] = (m_certs[n] == null ? null : new X509Certificate(m_certs[n]));
}
return perm;
}
public override bool IsSubsetOf(IPermission target)
{
if (target == null)
{
if(m_unrestricted)
return false;
if(m_certs == null)
return true;
if(m_certs.Length == 0)
return true;
return false;
}
PublisherIdentityPermission that = target as PublisherIdentityPermission;
if(that == null)
throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
if(that.m_unrestricted)
return true;
if(m_unrestricted)
return false;
if(this.m_certs != null)
{
foreach(X509Certificate certThis in this.m_certs)
{
bool bOK = false;
if(that.m_certs != null)
{
foreach(X509Certificate certThat in that.m_certs)
{
if(certThis.Equals(certThat))
{
bOK = true;
break;
}
}
}
if(!bOK)
return false;
}
}
return true;
}
public override IPermission Intersect(IPermission target)
{
if (target == null)
return null;
PublisherIdentityPermission that = target as PublisherIdentityPermission;
if(that == null)
throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
if(this.m_unrestricted && that.m_unrestricted)
{
PublisherIdentityPermission res = new PublisherIdentityPermission(PermissionState.None);
res.m_unrestricted = true;
return res;
}
if(this.m_unrestricted)
return that.Copy();
if(that.m_unrestricted)
return this.Copy();
if(this.m_certs == null || that.m_certs == null || this.m_certs.Length == 0 || that.m_certs.Length == 0)
return null;
ArrayList alCerts = new ArrayList();
foreach(X509Certificate certThis in this.m_certs)
{
foreach(X509Certificate certThat in that.m_certs)
{
if(certThis.Equals(certThat))
alCerts.Add(new X509Certificate(certThis));
}
}
if(alCerts.Count == 0)
return null;
PublisherIdentityPermission result = new PublisherIdentityPermission(PermissionState.None);
result.m_certs = (X509Certificate[])alCerts.ToArray(typeof(X509Certificate));
return result;
}
public override IPermission Union(IPermission target)
{
if (target == null)
{
if((this.m_certs == null || this.m_certs.Length == 0) && !this.m_unrestricted)
return null;
return this.Copy();
}
PublisherIdentityPermission that = target as PublisherIdentityPermission;
if(that == null)
throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
if(this.m_unrestricted || that.m_unrestricted)
{
PublisherIdentityPermission res = new PublisherIdentityPermission(PermissionState.None);
res.m_unrestricted = true;
return res;
}
if (this.m_certs == null || this.m_certs.Length == 0)
{
if(that.m_certs == null || that.m_certs.Length == 0)
return null;
return that.Copy();
}
if(that.m_certs == null || that.m_certs.Length == 0)
return this.Copy();
ArrayList alCerts = new ArrayList();
foreach(X509Certificate certThis in this.m_certs)
alCerts.Add(certThis);
foreach(X509Certificate certThat in that.m_certs)
{
bool bDupe = false;
foreach(X509Certificate cert in alCerts)
{
if(certThat.Equals(cert))
{
bDupe = true;
break;
}
}
if(!bDupe)
alCerts.Add(certThat);
}
PublisherIdentityPermission result = new PublisherIdentityPermission(PermissionState.None);
result.m_certs = (X509Certificate[])alCerts.ToArray(typeof(X509Certificate));
return result;
}
#if FEATURE_CAS_POLICY
public override void FromXml(SecurityElement esd)
{
m_unrestricted = false;
m_certs = null;
CodeAccessPermission.ValidateElement( esd, this );
String unr = esd.Attribute( "Unrestricted" );
if(unr != null && String.Compare(unr, "true", StringComparison.OrdinalIgnoreCase) == 0)
{
m_unrestricted = true;
return;
}
String elem = esd.Attribute( "X509v3Certificate" );
ArrayList al = new ArrayList();
if(elem != null)
al.Add(new X509Certificate(System.Security.Util.Hex.DecodeHexString(elem)));
ArrayList alChildren = esd.Children;
if(alChildren != null)
{
foreach(SecurityElement child in alChildren)
{
elem = child.Attribute( "X509v3Certificate" );
if(elem != null)
al.Add(new X509Certificate(System.Security.Util.Hex.DecodeHexString(elem)));
}
}
if(al.Count != 0)
m_certs = (X509Certificate[])al.ToArray(typeof(X509Certificate));
}
public override SecurityElement ToXml()
{
SecurityElement esd = CodeAccessPermission.CreatePermissionElement( this, "System.Security.Permissions.PublisherIdentityPermission" );
if (m_unrestricted)
esd.AddAttribute( "Unrestricted", "true" );
else if (m_certs != null)
{
if (m_certs.Length == 1)
esd.AddAttribute( "X509v3Certificate", m_certs[0].GetRawCertDataString() );
else
{
int n;
for(n = 0; n < m_certs.Length; n++)
{
SecurityElement child = new SecurityElement("Cert");
child.AddAttribute( "X509v3Certificate", m_certs[n].GetRawCertDataString() );
esd.AddChild(child);
}
}
}
return esd;
}
#endif // FEATURE_CAS_POLICY
/// <internalonly/>
int IBuiltInPermission.GetTokenIndex()
{
return PublisherIdentityPermission.GetTokenIndex();
}
internal static int GetTokenIndex()
{
return BuiltInPermissionIndex.PublisherIdentityPermissionIndex;
}
}
}

View File

@@ -0,0 +1,319 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// ReflectionPermission.cs
//
// <OWNER>[....]</OWNER>
//
namespace System.Security.Permissions
{
using System;
using System.IO;
using System.Security.Util;
using System.Text;
using System.Runtime.InteropServices;
using System.Runtime.Remoting;
using System.Security;
using System.Reflection;
using System.Globalization;
using System.Diagnostics.Contracts;
[ComVisible(true)]
[Flags]
[Serializable]
public enum ReflectionPermissionFlag
{
NoFlags = 0x00,
[Obsolete("This API has been deprecated. http://go.microsoft.com/fwlink/?linkid=14202")]
TypeInformation = 0x01,
MemberAccess = 0x02,
[Obsolete("This permission is no longer used by the CLR.")]
ReflectionEmit = 0x04,
[ComVisible(false)]
RestrictedMemberAccess = 0x08,
[Obsolete("This permission has been deprecated. Use PermissionState.Unrestricted to get full access.")]
AllFlags = 0x07
}
[ComVisible(true)]
[Serializable]
sealed public class ReflectionPermission
: CodeAccessPermission, IUnrestrictedPermission, IBuiltInPermission
{
// ReflectionPermissionFlag.AllFlags doesn't contain the new value RestrictedMemberAccess,
// but we cannot change its value now because that will break apps that have that old value baked in.
// We should use this const that truely contains "all" flags instead of ReflectionPermissionFlag.AllFlags.
#pragma warning disable 618
internal const ReflectionPermissionFlag AllFlagsAndMore = ReflectionPermissionFlag.AllFlags | ReflectionPermissionFlag.RestrictedMemberAccess;
#pragma warning restore 618
private ReflectionPermissionFlag m_flags;
//
// Public Constructors
//
public ReflectionPermission(PermissionState state)
{
if (state == PermissionState.Unrestricted)
{
SetUnrestricted( true );
}
else if (state == PermissionState.None)
{
SetUnrestricted( false );
}
else
{
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPermissionState"));
}
}
// Parameters:
//
public ReflectionPermission(ReflectionPermissionFlag flag)
{
VerifyAccess(flag);
SetUnrestricted(false);
m_flags = flag;
}
//------------------------------------------------------
//
// PRIVATE AND PROTECTED MODIFIERS
//
//------------------------------------------------------
private void SetUnrestricted(bool unrestricted)
{
if (unrestricted)
{
m_flags = ReflectionPermission.AllFlagsAndMore;
}
else
{
Reset();
}
}
private void Reset()
{
m_flags = ReflectionPermissionFlag.NoFlags;
}
public ReflectionPermissionFlag Flags
{
set
{
VerifyAccess(value);
m_flags = value;
}
get
{
return m_flags;
}
}
#if ZERO // Do not remove this code, useful for debugging
public override String ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("ReflectionPermission(");
if (IsUnrestricted())
{
sb.Append("Unrestricted");
}
else
{
if (GetFlag(ReflectionPermissionFlag.TypeInformation))
sb.Append("TypeInformation; ");
if (GetFlag(ReflectionPermissionFlag.MemberAccess))
sb.Append("MemberAccess; ");
#pragma warning disable 618
if (GetFlag(ReflectionPermissionFlag.ReflectionEmit))
sb.Append("ReflectionEmit; ");
#pragma warning restore 618
}
sb.Append(")");
return sb.ToString();
}
#endif
//
// CodeAccessPermission implementation
//
public bool IsUnrestricted()
{
return m_flags == ReflectionPermission.AllFlagsAndMore;
}
//
// IPermission implementation
//
public override IPermission Union(IPermission other)
{
if (other == null)
{
return this.Copy();
}
else if (!VerifyType(other))
{
throw new
ArgumentException(
Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)
);
}
ReflectionPermission operand = (ReflectionPermission)other;
if (this.IsUnrestricted() || operand.IsUnrestricted())
{
return new ReflectionPermission( PermissionState.Unrestricted );
}
else
{
ReflectionPermissionFlag flag_union = (ReflectionPermissionFlag)(m_flags | operand.m_flags);
return(new ReflectionPermission(flag_union));
}
}
public override bool IsSubsetOf(IPermission target)
{
if (target == null)
{
return m_flags == ReflectionPermissionFlag.NoFlags;
}
try
{
ReflectionPermission operand = (ReflectionPermission)target;
if (operand.IsUnrestricted())
return true;
else if (this.IsUnrestricted())
return false;
else
return (((int)this.m_flags) & ~((int)operand.m_flags)) == 0;
}
catch (InvalidCastException)
{
throw new
ArgumentException(
Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)
);
}
}
public override IPermission Intersect(IPermission target)
{
if (target == null)
return null;
else if (!VerifyType(target))
{
throw new
ArgumentException(
Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)
);
}
ReflectionPermission operand = (ReflectionPermission)target;
ReflectionPermissionFlag newFlags = operand.m_flags & this.m_flags;
if (newFlags == ReflectionPermissionFlag.NoFlags)
return null;
else
return new ReflectionPermission( newFlags );
}
public override IPermission Copy()
{
if (this.IsUnrestricted())
{
return new ReflectionPermission(PermissionState.Unrestricted);
}
else
{
return new ReflectionPermission((ReflectionPermissionFlag)m_flags);
}
}
//
// IEncodable Interface
private
void VerifyAccess(ReflectionPermissionFlag type)
{
if ((type & ~ReflectionPermission.AllFlagsAndMore) != 0)
throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)type));
Contract.EndContractBlock();
}
#if FEATURE_CAS_POLICY
//------------------------------------------------------
//
// PUBLIC ENCODING METHODS
//
//------------------------------------------------------
public override SecurityElement ToXml()
{
SecurityElement esd = CodeAccessPermission.CreatePermissionElement( this, "System.Security.Permissions.ReflectionPermission" );
if (!IsUnrestricted())
{
esd.AddAttribute( "Flags", XMLUtil.BitFieldEnumToString( typeof( ReflectionPermissionFlag ), m_flags ) );
}
else
{
esd.AddAttribute( "Unrestricted", "true" );
}
return esd;
}
public override void FromXml(SecurityElement esd)
{
CodeAccessPermission.ValidateElement( esd, this );
if (XMLUtil.IsUnrestricted( esd ))
{
m_flags = ReflectionPermission.AllFlagsAndMore;
return;
}
Reset () ;
SetUnrestricted (false) ;
String flags = esd.Attribute( "Flags" );
if (flags != null)
m_flags = (ReflectionPermissionFlag)Enum.Parse( typeof( ReflectionPermissionFlag ), flags );
}
#endif // FEATURE_CAS_POLICY
/// <internalonly/>
int IBuiltInPermission.GetTokenIndex()
{
return ReflectionPermission.GetTokenIndex();
}
internal static int GetTokenIndex()
{
return BuiltInPermissionIndex.ReflectionPermissionIndex;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,368 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// SecurityPermission.cs
//
// <OWNER>[....]</OWNER>
//
namespace System.Security.Permissions
{
using System;
using System.IO;
using System.Security.Util;
using System.Text;
using System.Threading;
using System.Runtime.Remoting;
using System.Security;
using System.Runtime.Serialization;
using System.Reflection;
using System.Globalization;
using System.Diagnostics.Contracts;
[Serializable]
[Flags]
[System.Runtime.InteropServices.ComVisible(true)]
#if !FEATURE_CAS_POLICY
// The csharp compiler requires these types to be public, but they are not used elsewhere.
[Obsolete("SecurityPermissionFlag is no longer accessible to application code.")]
#endif
public enum SecurityPermissionFlag
{
NoFlags = 0x00,
/* The following enum value is used in the EE (ASSERT_PERMISSION in security.cpp)
* Should this value change, make corresponding changes there
*/
Assertion = 0x01,
UnmanagedCode = 0x02, // Update vm\Security.h if you change this !
SkipVerification = 0x04, // Update vm\Security.h if you change this !
Execution = 0x08,
ControlThread = 0x10,
ControlEvidence = 0x20,
ControlPolicy = 0x40,
SerializationFormatter = 0x80,
ControlDomainPolicy = 0x100,
ControlPrincipal = 0x200,
ControlAppDomain = 0x400,
RemotingConfiguration = 0x800,
Infrastructure = 0x1000,
BindingRedirects = 0x2000,
AllFlags = 0x3fff,
}
[System.Runtime.InteropServices.ComVisible(true)]
[Serializable]
sealed public class SecurityPermission
: CodeAccessPermission, IUnrestrictedPermission, IBuiltInPermission
{
#pragma warning disable 618
private SecurityPermissionFlag m_flags;
#pragma warning restore 618
//
// Public Constructors
//
public SecurityPermission(PermissionState state)
{
if (state == PermissionState.Unrestricted)
{
SetUnrestricted( true );
}
else if (state == PermissionState.None)
{
SetUnrestricted( false );
Reset();
}
else
{
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPermissionState"));
}
}
// SecurityPermission
//
#pragma warning disable 618
public SecurityPermission(SecurityPermissionFlag flag)
#pragma warning restore 618
{
VerifyAccess(flag);
SetUnrestricted(false);
m_flags = flag;
}
//------------------------------------------------------
//
// PRIVATE AND PROTECTED MODIFIERS
//
//------------------------------------------------------
private void SetUnrestricted(bool unrestricted)
{
if (unrestricted)
{
#pragma warning disable 618
m_flags = SecurityPermissionFlag.AllFlags;
#pragma warning restore 618
}
}
private void Reset()
{
#pragma warning disable 618
m_flags = SecurityPermissionFlag.NoFlags;
#pragma warning restore 618
}
#pragma warning disable 618
public SecurityPermissionFlag Flags
#pragma warning restore 618
{
set
{
VerifyAccess(value);
m_flags = value;
}
get
{
return m_flags;
}
}
//
// CodeAccessPermission methods
//
/*
* IPermission interface implementation
*/
public override bool IsSubsetOf(IPermission target)
{
if (target == null)
{
return m_flags == 0;
}
SecurityPermission operand = target as SecurityPermission;
if (operand != null)
{
return (((int)this.m_flags) & ~((int)operand.m_flags)) == 0;
}
else
{
throw new
ArgumentException(
Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)
);
}
}
public override IPermission Union(IPermission target) {
if (target == null) return(this.Copy());
if (!VerifyType(target)) {
throw new
ArgumentException(
Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)
);
}
SecurityPermission sp_target = (SecurityPermission) target;
if (sp_target.IsUnrestricted() || IsUnrestricted()) {
return(new SecurityPermission(PermissionState.Unrestricted));
}
#pragma warning disable 618
SecurityPermissionFlag flag_union = (SecurityPermissionFlag)(m_flags | sp_target.m_flags);
#pragma warning restore 618
return(new SecurityPermission(flag_union));
}
public override IPermission Intersect(IPermission target)
{
if (target == null)
return null;
else if (!VerifyType(target))
{
throw new
ArgumentException(
Environment.GetResourceString("Argument_WrongType", this.GetType().FullName)
);
}
SecurityPermission operand = (SecurityPermission)target;
#pragma warning disable 618
SecurityPermissionFlag isectFlags = SecurityPermissionFlag.NoFlags;
#pragma warning restore 618
if (operand.IsUnrestricted())
{
if (this.IsUnrestricted())
return new SecurityPermission(PermissionState.Unrestricted);
else
#pragma warning disable 618
isectFlags = (SecurityPermissionFlag)this.m_flags;
#pragma warning restore 618
}
else if (this.IsUnrestricted())
{
#pragma warning disable 618
isectFlags = (SecurityPermissionFlag)operand.m_flags;
#pragma warning restore 618
}
else
{
#pragma warning disable 618
isectFlags = (SecurityPermissionFlag)m_flags & (SecurityPermissionFlag)operand.m_flags;
#pragma warning restore 618
}
if (isectFlags == 0)
return null;
else
return new SecurityPermission(isectFlags);
}
public override IPermission Copy()
{
if (IsUnrestricted())
return new SecurityPermission(PermissionState.Unrestricted);
else
#pragma warning disable 618
return new SecurityPermission((SecurityPermissionFlag)m_flags);
#pragma warning restore 618
}
public bool IsUnrestricted()
{
#pragma warning disable 618
return m_flags == SecurityPermissionFlag.AllFlags;
#pragma warning restore 618
}
private
#pragma warning disable 618
void VerifyAccess(SecurityPermissionFlag type)
#pragma warning restore 618
{
#pragma warning disable 618
if ((type & ~SecurityPermissionFlag.AllFlags) != 0)
#pragma warning restore 618
throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)type));
Contract.EndContractBlock();
}
#if FEATURE_CAS_POLICY
//------------------------------------------------------
//
// PUBLIC ENCODING METHODS
//
//------------------------------------------------------
private const String _strHeaderAssertion = "Assertion";
private const String _strHeaderUnmanagedCode = "UnmanagedCode";
private const String _strHeaderExecution = "Execution";
private const String _strHeaderSkipVerification = "SkipVerification";
private const String _strHeaderControlThread = "ControlThread";
private const String _strHeaderControlEvidence = "ControlEvidence";
private const String _strHeaderControlPolicy = "ControlPolicy";
private const String _strHeaderSerializationFormatter = "SerializationFormatter";
private const String _strHeaderControlDomainPolicy = "ControlDomainPolicy";
private const String _strHeaderControlPrincipal = "ControlPrincipal";
private const String _strHeaderControlAppDomain = "ControlAppDomain";
public override SecurityElement ToXml()
{
SecurityElement esd = CodeAccessPermission.CreatePermissionElement( this, "System.Security.Permissions.SecurityPermission" );
if (!IsUnrestricted())
{
esd.AddAttribute( "Flags", XMLUtil.BitFieldEnumToString( typeof( SecurityPermissionFlag ), m_flags ) );
}
else
{
esd.AddAttribute( "Unrestricted", "true" );
}
return esd;
}
public override void FromXml(SecurityElement esd)
{
CodeAccessPermission.ValidateElement( esd, this );
if (XMLUtil.IsUnrestricted( esd ))
{
m_flags = SecurityPermissionFlag.AllFlags;
return;
}
Reset () ;
SetUnrestricted (false) ;
String flags = esd.Attribute( "Flags" );
if (flags != null)
m_flags = (SecurityPermissionFlag)Enum.Parse( typeof( SecurityPermissionFlag ), flags );
}
#endif // FEATURE_CAS_POLICY
//
// Object Overrides
//
#if ZERO // Do not remove this code, usefull for debugging
public override String ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("SecurityPermission(");
if (IsUnrestricted())
{
sb.Append("Unrestricted");
}
else
{
if (GetFlag(SecurityPermissionFlag.Assertion))
sb.Append("Assertion; ");
if (GetFlag(SecurityPermissionFlag.UnmanagedCode))
sb.Append("UnmangedCode; ");
if (GetFlag(SecurityPermissionFlag.SkipVerification))
sb.Append("SkipVerification; ");
if (GetFlag(SecurityPermissionFlag.Execution))
sb.Append("Execution; ");
if (GetFlag(SecurityPermissionFlag.ControlThread))
sb.Append("ControlThread; ");
if (GetFlag(SecurityPermissionFlag.ControlEvidence))
sb.Append("ControlEvidence; ");
if (GetFlag(SecurityPermissionFlag.ControlPolicy))
sb.Append("ControlPolicy; ");
if (GetFlag(SecurityPermissionFlag.SerializationFormatter))
sb.Append("SerializationFormatter; ");
if (GetFlag(SecurityPermissionFlag.ControlDomainPolicy))
sb.Append("ControlDomainPolicy; ");
if (GetFlag(SecurityPermissionFlag.ControlPrincipal))
sb.Append("ControlPrincipal; ");
}
sb.Append(")");
return sb.ToString();
}
#endif
/// <internalonly/>
int IBuiltInPermission.GetTokenIndex()
{
return SecurityPermission.GetTokenIndex();
}
internal static int GetTokenIndex()
{
return BuiltInPermissionIndex.SecurityPermissionIndex;
}
}
}

View File

@@ -0,0 +1,363 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// SiteIdentityPermission.cs
//
// <OWNER>[....]</OWNER>
//
namespace System.Security.Permissions
{
using System;
#if FEATURE_CAS_POLICY
using SecurityElement = System.Security.SecurityElement;
#endif // FEATURE_CAS_POLICY
using SiteString = System.Security.Util.SiteString;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.Serialization;
[System.Runtime.InteropServices.ComVisible(true)]
[Serializable]
sealed public class SiteIdentityPermission : CodeAccessPermission, IBuiltInPermission
{
//------------------------------------------------------
//
// PRIVATE STATE DATA
//
//------------------------------------------------------
[OptionalField(VersionAdded = 2)]
private bool m_unrestricted;
[OptionalField(VersionAdded = 2)]
private SiteString[] m_sites;
#if FEATURE_REMOTING
// This field will be populated only for non X-AD scenarios where we create a XML-ised string of the Permission
[OptionalField(VersionAdded = 2)]
private String m_serializedPermission;
// This field is legacy info from v1.x and is never used in v2.0 and beyond: purely for serialization purposes
private SiteString m_site;
[OnDeserialized]
private void OnDeserialized(StreamingContext ctx)
{
// v2.0 and beyond XML case
if (m_serializedPermission != null)
{
FromXml(SecurityElement.FromString(m_serializedPermission));
m_serializedPermission = null;
}
else if (m_site != null) //v1.x case where we read the m_site value
{
m_unrestricted = false;
m_sites = new SiteString[1];
m_sites[0] = m_site;
m_site = null;
}
}
[OnSerializing]
private void OnSerializing(StreamingContext ctx)
{
if ((ctx.State & ~(StreamingContextStates.Clone|StreamingContextStates.CrossAppDomain)) != 0)
{
m_serializedPermission = ToXml().ToString(); //for the v2 and beyond case
if (m_sites != null && m_sites.Length == 1) // for the v1.x case
m_site = m_sites[0];
}
}
[OnSerialized]
private void OnSerialized(StreamingContext ctx)
{
if ((ctx.State & ~(StreamingContextStates.Clone|StreamingContextStates.CrossAppDomain)) != 0)
{
m_serializedPermission = null;
m_site = null;
}
}
#endif // FEATURE_REMOTING
//------------------------------------------------------
//
// PUBLIC CONSTRUCTORS
//
//------------------------------------------------------
public SiteIdentityPermission(PermissionState state)
{
if (state == PermissionState.Unrestricted)
{
m_unrestricted = true;
}
else if (state == PermissionState.None)
{
m_unrestricted = false;
}
else
{
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPermissionState"));
}
}
public SiteIdentityPermission( String site )
{
Site = site;
}
//------------------------------------------------------
//
// PUBLIC ACCESSOR METHODS
//
//------------------------------------------------------
public String Site
{
set
{
m_unrestricted = false;
m_sites = new SiteString[1];
m_sites[0] = new SiteString( value );
}
get
{
if(m_sites == null)
return "";
if(m_sites.Length == 1)
return m_sites[0].ToString();
throw new NotSupportedException(Environment.GetResourceString("NotSupported_AmbiguousIdentity"));
}
}
//------------------------------------------------------
//
// PRIVATE AND PROTECTED HELPERS FOR ACCESSORS AND CONSTRUCTORS
//
//------------------------------------------------------
//------------------------------------------------------
//
// CODEACCESSPERMISSION IMPLEMENTATION
//
//------------------------------------------------------
//------------------------------------------------------
//
// IPERMISSION IMPLEMENTATION
//
//------------------------------------------------------
public override IPermission Copy()
{
SiteIdentityPermission perm = new SiteIdentityPermission( PermissionState.None );
perm.m_unrestricted = this.m_unrestricted;
if (this.m_sites != null)
{
perm.m_sites = new SiteString[this.m_sites.Length];
int n;
for(n = 0; n < this.m_sites.Length; n++)
perm.m_sites[n] = (SiteString)this.m_sites[n].Copy();
}
return perm;
}
public override bool IsSubsetOf(IPermission target)
{
if (target == null)
{
if(m_unrestricted)
return false;
if(m_sites == null)
return true;
if(m_sites.Length == 0)
return true;
return false;
}
SiteIdentityPermission that = target as SiteIdentityPermission;
if(that == null)
throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
if(that.m_unrestricted)
return true;
if(m_unrestricted)
return false;
if(this.m_sites != null)
{
foreach(SiteString ssThis in this.m_sites)
{
bool bOK = false;
if(that.m_sites != null)
{
foreach(SiteString ssThat in that.m_sites)
{
if(ssThis.IsSubsetOf(ssThat))
{
bOK = true;
break;
}
}
}
if(!bOK)
return false;
}
}
return true;
}
public override IPermission Intersect(IPermission target)
{
if (target == null)
return null;
SiteIdentityPermission that = target as SiteIdentityPermission;
if(that == null)
throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
if(this.m_unrestricted && that.m_unrestricted)
{
SiteIdentityPermission res = new SiteIdentityPermission(PermissionState.None);
res.m_unrestricted = true;
return res;
}
if(this.m_unrestricted)
return that.Copy();
if(that.m_unrestricted)
return this.Copy();
if(this.m_sites == null || that.m_sites == null || this.m_sites.Length == 0 || that.m_sites.Length == 0)
return null;
List<SiteString> alSites = new List<SiteString>();
foreach(SiteString ssThis in this.m_sites)
{
foreach(SiteString ssThat in that.m_sites)
{
SiteString ssInt = (SiteString)ssThis.Intersect(ssThat);
if(ssInt != null)
alSites.Add(ssInt);
}
}
if(alSites.Count == 0)
return null;
SiteIdentityPermission result = new SiteIdentityPermission(PermissionState.None);
result.m_sites = alSites.ToArray();
return result;
}
public override IPermission Union(IPermission target)
{
if (target == null)
{
if((this.m_sites == null || this.m_sites.Length == 0) && !this.m_unrestricted)
return null;
return this.Copy();
}
SiteIdentityPermission that = target as SiteIdentityPermission;
if(that == null)
throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
if(this.m_unrestricted || that.m_unrestricted)
{
SiteIdentityPermission res = new SiteIdentityPermission(PermissionState.None);
res.m_unrestricted = true;
return res;
}
if (this.m_sites == null || this.m_sites.Length == 0)
{
if(that.m_sites == null || that.m_sites.Length == 0)
return null;
return that.Copy();
}
if(that.m_sites == null || that.m_sites.Length == 0)
return this.Copy();
List<SiteString> alSites = new List<SiteString>();
foreach(SiteString ssThis in this.m_sites)
alSites.Add(ssThis);
foreach(SiteString ssThat in that.m_sites)
{
bool bDupe = false;
foreach(SiteString ss in alSites)
{
if(ssThat.Equals(ss))
{
bDupe = true;
break;
}
}
if(!bDupe)
alSites.Add(ssThat);
}
SiteIdentityPermission result = new SiteIdentityPermission(PermissionState.None);
result.m_sites = alSites.ToArray();
return result;
}
#if FEATURE_CAS_POLICY
public override void FromXml(SecurityElement esd)
{
m_unrestricted = false;
m_sites = null;
CodeAccessPermission.ValidateElement( esd, this );
String unr = esd.Attribute( "Unrestricted" );
if(unr != null && String.Compare(unr, "true", StringComparison.OrdinalIgnoreCase) == 0)
{
m_unrestricted = true;
return;
}
String elem = esd.Attribute( "Site" );
List<SiteString> al = new List<SiteString>();
if(elem != null)
al.Add(new SiteString( elem ));
ArrayList alChildren = esd.Children;
if(alChildren != null)
{
foreach(SecurityElement child in alChildren)
{
elem = child.Attribute( "Site" );
if(elem != null)
al.Add(new SiteString( elem ));
}
}
if(al.Count != 0)
m_sites = al.ToArray();
}
public override SecurityElement ToXml()
{
SecurityElement esd = CodeAccessPermission.CreatePermissionElement( this, "System.Security.Permissions.SiteIdentityPermission" );
if (m_unrestricted)
esd.AddAttribute( "Unrestricted", "true" );
else if (m_sites != null)
{
if (m_sites.Length == 1)
esd.AddAttribute( "Site", m_sites[0].ToString() );
else
{
int n;
for(n = 0; n < m_sites.Length; n++)
{
SecurityElement child = new SecurityElement("Site");
child.AddAttribute( "Site", m_sites[n].ToString() );
esd.AddChild(child);
}
}
}
return esd;
}
#endif // FEATURE_CAS_POLICY
/// <internalonly/>
int IBuiltInPermission.GetTokenIndex()
{
return SiteIdentityPermission.GetTokenIndex();
}
internal static int GetTokenIndex()
{
return BuiltInPermissionIndex.SiteIdentityPermissionIndex;
}
}
}

View File

@@ -0,0 +1,494 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// StrongNameIdentityPermission.cs
//
// <OWNER>[....]</OWNER>
//
namespace System.Security.Permissions
{
using System;
#if FEATURE_CAS_POLICY
using SecurityElement = System.Security.SecurityElement;
#endif // FEATURE_CAS_POLICY
using System.Security.Util;
using System.IO;
using String = System.String;
using Version = System.Version;
using System.Security.Policy;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Diagnostics.Contracts;
// The only difference between this class and System.Security.Policy.StrongName is that this one
// allows m_name to be null. We should merge this class with System.Security.Policy.StrongName
[Serializable]
sealed internal class StrongName2
{
public StrongNamePublicKeyBlob m_publicKeyBlob;
public String m_name;
public Version m_version;
public StrongName2(StrongNamePublicKeyBlob publicKeyBlob, String name, Version version)
{
m_publicKeyBlob = publicKeyBlob;
m_name = name;
m_version = version;
}
public StrongName2 Copy()
{
return new StrongName2(m_publicKeyBlob, m_name, m_version);
}
public bool IsSubsetOf(StrongName2 target)
{
// This StrongName2 is a subset of the target if it's public key blob is null no matter what
if (this.m_publicKeyBlob == null)
return true;
// Subsets are always false if the public key blobs do not match
if (!this.m_publicKeyBlob.Equals( target.m_publicKeyBlob ))
return false;
// We use null in strings to represent the "Anything" state.
// Therefore, the logic to detect an individual subset is:
//
// 1. If the this string is null ("Anything" is a subset of any other).
// 2. If the this string and target string are the same (equality is sufficient for a subset).
//
// The logic is reversed here to discover things that are not subsets.
if (this.m_name != null)
{
if (target.m_name == null || !System.Security.Policy.StrongName.CompareNames( target.m_name, this.m_name ))
return false;
}
if ((Object) this.m_version != null)
{
if ((Object) target.m_version == null ||
target.m_version.CompareTo( this.m_version ) != 0)
{
return false;
}
}
return true;
}
public StrongName2 Intersect(StrongName2 target)
{
if (target.IsSubsetOf( this ))
return target.Copy();
else if (this.IsSubsetOf( target ))
return this.Copy();
else
return null;
}
public bool Equals(StrongName2 target)
{
if (!target.IsSubsetOf(this))
return false;
if (!this.IsSubsetOf(target))
return false;
return true;
}
}
[System.Runtime.InteropServices.ComVisible(true)]
[Serializable]
sealed public class StrongNameIdentityPermission : CodeAccessPermission, IBuiltInPermission
{
//------------------------------------------------------
//
// PRIVATE STATE DATA
//
//------------------------------------------------------
private bool m_unrestricted;
private StrongName2[] m_strongNames;
//------------------------------------------------------
//
// PUBLIC CONSTRUCTORS
//
//------------------------------------------------------
public StrongNameIdentityPermission(PermissionState state)
{
if (state == PermissionState.Unrestricted)
{
m_unrestricted = true;
}
else if (state == PermissionState.None)
{
m_unrestricted = false;
}
else
{
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPermissionState"));
}
}
public StrongNameIdentityPermission( StrongNamePublicKeyBlob blob, String name, Version version )
{
if (blob == null)
throw new ArgumentNullException( "blob" );
if (name != null && name.Equals( "" ))
throw new ArgumentException( Environment.GetResourceString( "Argument_EmptyStrongName" ) );
Contract.EndContractBlock();
m_unrestricted = false;
m_strongNames = new StrongName2[1];
m_strongNames[0] = new StrongName2(blob, name, version);
}
//------------------------------------------------------
//
// PUBLIC ACCESSOR METHODS
//
//------------------------------------------------------
public StrongNamePublicKeyBlob PublicKey
{
set
{
if (value == null)
throw new ArgumentNullException( "PublicKey" );
Contract.EndContractBlock();
m_unrestricted = false;
if(m_strongNames != null && m_strongNames.Length == 1)
m_strongNames[0].m_publicKeyBlob = value;
else
{
m_strongNames = new StrongName2[1];
m_strongNames[0] = new StrongName2(value, "", new Version());
}
}
get
{
if(m_strongNames == null || m_strongNames.Length == 0)
return null;
if(m_strongNames.Length > 1)
throw new NotSupportedException(Environment.GetResourceString("NotSupported_AmbiguousIdentity"));
return m_strongNames[0].m_publicKeyBlob;
}
}
public String Name
{
set
{
if (value != null && value.Length == 0)
throw new ArgumentException( Environment.GetResourceString("Argument_EmptyName" ));
Contract.EndContractBlock();
m_unrestricted = false;
if(m_strongNames != null && m_strongNames.Length == 1)
m_strongNames[0].m_name = value;
else
{
m_strongNames = new StrongName2[1];
m_strongNames[0] = new StrongName2(null, value, new Version());
}
}
get
{
if(m_strongNames == null || m_strongNames.Length == 0)
return "";
if(m_strongNames.Length > 1)
throw new NotSupportedException(Environment.GetResourceString("NotSupported_AmbiguousIdentity"));
return m_strongNames[0].m_name;
}
}
public Version Version
{
set
{
m_unrestricted = false;
if(m_strongNames != null && m_strongNames.Length == 1)
m_strongNames[0].m_version = value;
else
{
m_strongNames = new StrongName2[1];
m_strongNames[0] = new StrongName2(null, "", value);
}
}
get
{
if(m_strongNames == null || m_strongNames.Length == 0)
return new Version();
if(m_strongNames.Length > 1)
throw new NotSupportedException(Environment.GetResourceString("NotSupported_AmbiguousIdentity"));
return m_strongNames[0].m_version;
}
}
//------------------------------------------------------
//
// PRIVATE AND PROTECTED HELPERS FOR ACCESSORS AND CONSTRUCTORS
//
//------------------------------------------------------
//------------------------------------------------------
//
// CODEACCESSPERMISSION IMPLEMENTATION
//
//------------------------------------------------------
//------------------------------------------------------
//
// IPERMISSION IMPLEMENTATION
//
//------------------------------------------------------
public override IPermission Copy()
{
StrongNameIdentityPermission perm = new StrongNameIdentityPermission(PermissionState.None);
perm.m_unrestricted = this.m_unrestricted;
if(this.m_strongNames != null)
{
perm.m_strongNames = new StrongName2[this.m_strongNames.Length];
int n;
for(n = 0; n < this.m_strongNames.Length; n++)
perm.m_strongNames[n] = this.m_strongNames[n].Copy();
}
return perm;
}
public override bool IsSubsetOf(IPermission target)
{
if (target == null)
{
if(m_unrestricted)
return false;
if(m_strongNames == null)
return true;
if(m_strongNames.Length == 0)
return true;
return false;
}
StrongNameIdentityPermission that = target as StrongNameIdentityPermission;
if(that == null)
throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
if(that.m_unrestricted)
return true;
if(m_unrestricted)
return false;
if(this.m_strongNames != null)
{
foreach(StrongName2 snThis in m_strongNames)
{
bool bOK = false;
if(that.m_strongNames != null)
{
foreach(StrongName2 snThat in that.m_strongNames)
{
if(snThis.IsSubsetOf(snThat))
{
bOK = true;
break;
}
}
}
if(!bOK)
return false;
}
}
return true;
}
public override IPermission Intersect(IPermission target)
{
if (target == null)
return null;
StrongNameIdentityPermission that = target as StrongNameIdentityPermission;
if(that == null)
throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
if(this.m_unrestricted && that.m_unrestricted)
{
StrongNameIdentityPermission res = new StrongNameIdentityPermission(PermissionState.None);
res.m_unrestricted = true;
return res;
}
if(this.m_unrestricted)
return that.Copy();
if(that.m_unrestricted)
return this.Copy();
if(this.m_strongNames == null || that.m_strongNames == null || this.m_strongNames.Length == 0 || that.m_strongNames.Length == 0)
return null;
List<StrongName2> alStrongNames = new List<StrongName2>();
foreach(StrongName2 snThis in this.m_strongNames)
{
foreach(StrongName2 snThat in that.m_strongNames)
{
StrongName2 snInt = (StrongName2)snThis.Intersect(snThat);
if(snInt != null)
alStrongNames.Add(snInt);
}
}
if(alStrongNames.Count == 0)
return null;
StrongNameIdentityPermission result = new StrongNameIdentityPermission(PermissionState.None);
result.m_strongNames = alStrongNames.ToArray();
return result;
}
public override IPermission Union(IPermission target)
{
if (target == null)
{
if((this.m_strongNames == null || this.m_strongNames.Length == 0) && !this.m_unrestricted)
return null;
return this.Copy();
}
StrongNameIdentityPermission that = target as StrongNameIdentityPermission;
if(that == null)
throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", this.GetType().FullName));
if(this.m_unrestricted || that.m_unrestricted)
{
StrongNameIdentityPermission res = new StrongNameIdentityPermission(PermissionState.None);
res.m_unrestricted = true;
return res;
}
if (this.m_strongNames == null || this.m_strongNames.Length == 0)
{
if(that.m_strongNames == null || that.m_strongNames.Length == 0)
return null;
return that.Copy();
}
if(that.m_strongNames == null || that.m_strongNames.Length == 0)
return this.Copy();
List<StrongName2> alStrongNames = new List<StrongName2>();
foreach(StrongName2 snThis in this.m_strongNames)
alStrongNames.Add(snThis);
foreach(StrongName2 snThat in that.m_strongNames)
{
bool bDupe = false;
foreach(StrongName2 sn in alStrongNames)
{
if(snThat.Equals(sn))
{
bDupe = true;
break;
}
}
if(!bDupe)
alStrongNames.Add(snThat);
}
StrongNameIdentityPermission result = new StrongNameIdentityPermission(PermissionState.None);
result.m_strongNames = alStrongNames.ToArray();
return result;
}
#if FEATURE_CAS_POLICY
public override void FromXml(SecurityElement e)
{
m_unrestricted = false;
m_strongNames = null;
CodeAccessPermission.ValidateElement( e, this );
String unr = e.Attribute( "Unrestricted" );
if(unr != null && String.Compare(unr, "true", StringComparison.OrdinalIgnoreCase) == 0)
{
m_unrestricted = true;
return;
}
String elBlob = e.Attribute("PublicKeyBlob");
String elName = e.Attribute("Name");
String elVersion = e.Attribute("AssemblyVersion");
StrongName2 sn;
List<StrongName2> al = new List<StrongName2>();
if(elBlob != null || elName != null || elVersion != null)
{
sn = new StrongName2(
(elBlob == null ? null : new StrongNamePublicKeyBlob(elBlob)),
elName,
(elVersion == null ? null : new Version(elVersion)));
al.Add(sn);
}
ArrayList alChildren = e.Children;
if(alChildren != null)
{
foreach(SecurityElement child in alChildren)
{
elBlob = child.Attribute("PublicKeyBlob");
elName = child.Attribute("Name");
elVersion = child.Attribute("AssemblyVersion");
if(elBlob != null || elName != null || elVersion != null)
{
sn = new StrongName2(
(elBlob == null ? null : new StrongNamePublicKeyBlob(elBlob)),
elName,
(elVersion == null ? null : new Version(elVersion)));
al.Add(sn);
}
}
}
if(al.Count != 0)
m_strongNames = al.ToArray();
}
public override SecurityElement ToXml()
{
SecurityElement esd = CodeAccessPermission.CreatePermissionElement( this, "System.Security.Permissions.StrongNameIdentityPermission" );
if (m_unrestricted)
esd.AddAttribute( "Unrestricted", "true" );
else if (m_strongNames != null)
{
if (m_strongNames.Length == 1)
{
if (m_strongNames[0].m_publicKeyBlob != null)
esd.AddAttribute("PublicKeyBlob", Hex.EncodeHexString(m_strongNames[0].m_publicKeyBlob.PublicKey));
if (m_strongNames[0].m_name != null)
esd.AddAttribute("Name", m_strongNames[0].m_name);
if ((Object)m_strongNames[0].m_version != null)
esd.AddAttribute("AssemblyVersion", m_strongNames[0].m_version.ToString());
}
else
{
int n;
for(n = 0; n < m_strongNames.Length; n++)
{
SecurityElement child = new SecurityElement("StrongName");
if (m_strongNames[n].m_publicKeyBlob != null)
child.AddAttribute("PublicKeyBlob", Hex.EncodeHexString(m_strongNames[n].m_publicKeyBlob.PublicKey));
if (m_strongNames[n].m_name != null)
child.AddAttribute("Name", m_strongNames[n].m_name);
if ((Object)m_strongNames[n].m_version != null)
child.AddAttribute("AssemblyVersion", m_strongNames[n].m_version.ToString());
esd.AddChild(child);
}
}
}
return esd;
}
#endif // FEATURE_CAS_POLICY
/// <internalonly/>
int IBuiltInPermission.GetTokenIndex()
{
return StrongNameIdentityPermission.GetTokenIndex();
}
internal static int GetTokenIndex()
{
return BuiltInPermissionIndex.StrongNameIdentityPermissionIndex;
}
}
}

View File

@@ -0,0 +1,100 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// StrongNamePublicKeyBlob.cs
//
// <OWNER>[....]</OWNER>
//
namespace System.Security.Permissions
{
using System;
using System.Security.Util;
using System.Diagnostics.Contracts;
[System.Runtime.InteropServices.ComVisible(true)]
[Serializable] sealed public class StrongNamePublicKeyBlob
{
internal byte[] PublicKey;
internal StrongNamePublicKeyBlob()
{
}
public StrongNamePublicKeyBlob( byte[] publicKey )
{
if (publicKey == null)
throw new ArgumentNullException( "PublicKey" );
Contract.EndContractBlock();
this.PublicKey = new byte[publicKey.Length];
Array.Copy( publicKey, 0, this.PublicKey, 0, publicKey.Length );
}
internal StrongNamePublicKeyBlob( String publicKey )
{
this.PublicKey = Hex.DecodeHexString( publicKey );
}
private static bool CompareArrays( byte[] first, byte[] second )
{
if (first.Length != second.Length)
{
return false;
}
int count = first.Length;
for (int i = 0; i < count; ++i)
{
if (first[i] != second[i])
return false;
}
return true;
}
internal bool Equals( StrongNamePublicKeyBlob blob )
{
if (blob == null)
return false;
else
return CompareArrays( this.PublicKey, blob.PublicKey );
}
public override bool Equals( Object obj )
{
if (obj == null || !(obj is StrongNamePublicKeyBlob))
return false;
return this.Equals( (StrongNamePublicKeyBlob)obj );
}
static private int GetByteArrayHashCode( byte[] baData )
{
if (baData == null)
return 0;
int accumulator = 0;
for (int i = 0; i < baData.Length; ++i)
{
accumulator = (accumulator << 8) ^ (int)baData[i] ^ (accumulator >> 24);
}
return accumulator;
}
public override int GetHashCode()
{
return GetByteArrayHashCode( PublicKey );
}
public override String ToString()
{
return Hex.EncodeHexString( PublicKey );
}
}
}

Some files were not shown because too many files have changed in this diff Show More