Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@ -0,0 +1,43 @@
//
// System.Security.AllowPartiallyTrustedCallersAttribute implementation
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2003, 2004 Motus Technologies Inc. (http://www.motus.com)
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
namespace System.Security {
[ComVisible (true)]
[AttributeUsage (AttributeTargets.Assembly, AllowMultiple=false, Inherited=false)]
public sealed class AllowPartiallyTrustedCallersAttribute : Attribute {
public AllowPartiallyTrustedCallersAttribute ()
: base ()
{
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,392 @@
//
// System.Security.CodeAccessPermission.cs
//
// Authors:
// Miguel de Icaza (miguel@ximian.com)
// Nick Drochak, ndrochak@gol.com
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) Ximian, Inc. http://www.ximian.com
// Copyright (C) 2001 Nick Drochak, All Rights Reserved
// Portions (C) 2004 Motus Technologies Inc. (http://www.motus.com)
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Threading;
namespace System.Security {
[Serializable]
[SecurityPermission (SecurityAction.InheritanceDemand, ControlEvidence = true, ControlPolicy = true)]
[ComVisible (true)]
[MonoTODO ("CAS support is experimental (and unsupported).")]
public abstract class CodeAccessPermission : IPermission, ISecurityEncodable, IStackWalk {
protected CodeAccessPermission ()
{
}
[MonoTODO ("CAS support is experimental (and unsupported). Imperative mode is not implemented.")]
public void Assert ()
{
new PermissionSet (this).Assert ();
}
internal bool CheckAssert (CodeAccessPermission asserted)
{
if (asserted == null)
return false;
if (asserted.GetType () != this.GetType ())
return false;
return IsSubsetOf (asserted);
}
internal bool CheckDemand (CodeAccessPermission target)
{
if (target == null)
return false;
if (target.GetType () != this.GetType ())
return false;
return IsSubsetOf (target);
}
internal bool CheckDeny (CodeAccessPermission denied)
{
if (denied == null)
return true;
Type t = denied.GetType ();
if (t != this.GetType ())
return true;
IPermission inter = Intersect (denied);
if (inter == null)
return true;
// sadly that's not enough :( at this stage we must also check
// if an empty (PermissionState.None) is a subset of the denied
// (which is like a empty intersection looks like for flag based
// permissions, e.g. AspNetHostingPermission).
return denied.IsSubsetOf (PermissionBuilder.Create (t));
}
internal bool CheckPermitOnly (CodeAccessPermission target)
{
if (target == null)
return false;
if (target.GetType () != this.GetType ())
return false;
return IsSubsetOf (target);
}
public abstract IPermission Copy ();
public void Demand ()
{
// note: here we're sure it's a CAS demand
if (!SecurityManager.SecurityEnabled)
return;
// skip frames until we get the caller (of our caller)
new PermissionSet (this).CasOnlyDemand (3);
}
[MonoTODO ("CAS support is experimental (and unsupported). Imperative mode is not implemented.")]
public void Deny ()
{
new PermissionSet (this).Deny ();
}
[ComVisible (false)]
public override bool Equals (object obj)
{
if (obj == null)
return false;
if (obj.GetType () != this.GetType ())
return false;
CodeAccessPermission cap = (obj as CodeAccessPermission);
return (IsSubsetOf (cap) && cap.IsSubsetOf (this));
}
public abstract void FromXml (SecurityElement elem);
[ComVisible (false)]
public override int GetHashCode ()
{
return base.GetHashCode ();
}
public abstract IPermission Intersect (IPermission target);
public abstract bool IsSubsetOf (IPermission target);
public override string ToString ()
{
SecurityElement elem = ToXml ();
return elem.ToString ();
}
public abstract SecurityElement ToXml ();
public virtual IPermission Union (IPermission other)
{
if (null != other)
throw new System.NotSupportedException (); // other is not null.
return null;
}
[MonoTODO ("CAS support is experimental (and unsupported). Imperative mode is not implemented.")]
public void PermitOnly ()
{
new PermissionSet (this).PermitOnly ();
}
[MonoTODO ("CAS support is experimental (and unsupported). Imperative mode is not implemented.")]
public static void RevertAll ()
{
if (!SecurityManager.SecurityEnabled)
return;
SecurityFrame sf = new SecurityFrame (1);
bool revert = false;
if ((sf.Assert != null) && !sf.Assert.DeclarativeSecurity) {
revert = true;
throw new NotSupportedException ("Currently only declarative Assert are supported.");
}
if ((sf.Deny != null) && !sf.Deny.DeclarativeSecurity) {
revert = true;
throw new NotSupportedException ("Currently only declarative Deny are supported.");
}
if ((sf.PermitOnly != null) && !sf.PermitOnly.DeclarativeSecurity) {
revert = true;
throw new NotSupportedException ("Currently only declarative PermitOnly are supported.");
}
if (!revert) {
string msg = Locale.GetText ("No stack modifiers are present on the current stack frame.");
// FIXME: we don't (yet) support imperative stack modifiers
msg += Environment.NewLine + "Currently only declarative stack modifiers are supported.";
throw new ExecutionEngineException (msg);
}
}
[MonoTODO ("CAS support is experimental (and unsupported). Imperative mode is not implemented.")]
public static void RevertAssert ()
{
if (!SecurityManager.SecurityEnabled)
return;
SecurityFrame sf = new SecurityFrame (1);
if ((sf.Assert != null) && !sf.Assert.DeclarativeSecurity) {
throw new NotSupportedException ("Currently only declarative Assert are supported.");
} else {
// we can't revert declarative security (or an empty frame) imperatively
ThrowExecutionEngineException (SecurityAction.Assert);
}
}
[MonoTODO ("CAS support is experimental (and unsupported). Imperative mode is not implemented.")]
public static void RevertDeny ()
{
if (!SecurityManager.SecurityEnabled)
return;
SecurityFrame sf = new SecurityFrame (1);
if ((sf.Deny != null) && !sf.Deny.DeclarativeSecurity) {
throw new NotSupportedException ("Currently only declarative Deny are supported.");
} else {
// we can't revert declarative security (or an empty frame) imperatively
ThrowExecutionEngineException (SecurityAction.Deny);
}
}
[MonoTODO ("CAS support is experimental (and unsupported). Imperative mode is not implemented.")]
public static void RevertPermitOnly ()
{
if (!SecurityManager.SecurityEnabled)
return;
SecurityFrame sf = new SecurityFrame (1);
if ((sf.PermitOnly != null) && sf.PermitOnly.DeclarativeSecurity) {
throw new NotSupportedException ("Currently only declarative PermitOnly are supported.");
} else {
// we can't revert declarative security (or an empty frame) imperatively
ThrowExecutionEngineException (SecurityAction.PermitOnly);
}
}
// Internal helpers methods
// snippet moved from FileIOPermission (nickd) to be reused in all derived classes
internal SecurityElement Element (int version)
{
SecurityElement se = new SecurityElement ("IPermission");
Type type = this.GetType ();
se.AddAttribute ("class", type.FullName + ", " + type.Assembly.ToString ().Replace ('\"', '\''));
se.AddAttribute ("version", version.ToString ());
return se;
}
internal static PermissionState CheckPermissionState (PermissionState state, bool allowUnrestricted)
{
string msg;
switch (state) {
case PermissionState.None:
break;
case PermissionState.Unrestricted:
// unrestricted permissions are possible for identiy permissions
break;
default:
msg = String.Format (Locale.GetText ("Invalid enum {0}"), state);
throw new ArgumentException (msg, "state");
}
return state;
}
internal static int CheckSecurityElement (SecurityElement se, string parameterName, int minimumVersion, int maximumVersion)
{
if (se == null)
throw new ArgumentNullException (parameterName);
// Tag is case-sensitive
if (se.Tag != "IPermission") {
string msg = String.Format (Locale.GetText ("Invalid tag {0}"), se.Tag);
throw new ArgumentException (msg, parameterName);
}
// Note: we do not care about the class attribute at
// this stage (in fact we don't even if the class
// attribute is present or not). Anyway the object has
// already be created, with success, if we're loading it
// we assume minimum version if no version number is supplied
int version = minimumVersion;
string v = se.Attribute ("version");
if (v != null) {
try {
version = Int32.Parse (v);
}
catch (Exception e) {
string msg = Locale.GetText ("Couldn't parse version from '{0}'.");
msg = String.Format (msg, v);
throw new ArgumentException (msg, parameterName, e);
}
}
if ((version < minimumVersion) || (version > maximumVersion)) {
string msg = Locale.GetText ("Unknown version '{0}', expected versions between ['{1}','{2}'].");
msg = String.Format (msg, version, minimumVersion, maximumVersion);
throw new ArgumentException (msg, parameterName);
}
return version;
}
// must be called after CheckSecurityElement (i.e. se != null)
internal static bool IsUnrestricted (SecurityElement se)
{
string value = se.Attribute ("Unrestricted");
if (value == null)
return false;
return (String.Compare (value, Boolean.TrueString, true, CultureInfo.InvariantCulture) == 0);
}
internal bool ProcessFrame (SecurityFrame frame)
{
// 1. CheckPermitOnly
if (frame.PermitOnly != null) {
// the demanded permission must be in one of the permitted...
bool permit = frame.PermitOnly.IsUnrestricted ();
if (!permit) {
// check individual permissions
foreach (IPermission p in frame.PermitOnly) {
if (CheckPermitOnly (p as CodeAccessPermission)) {
permit = true;
break;
}
}
}
if (!permit) {
// ...or else we throw
ThrowSecurityException (this, "PermitOnly", frame, SecurityAction.Demand, null);
}
}
// 2. CheckDeny
if (frame.Deny != null) {
// special case where everything is denied (i.e. no child to be processed)
if (frame.Deny.IsUnrestricted ())
ThrowSecurityException (this, "Deny", frame, SecurityAction.Demand, null);
foreach (IPermission p in frame.Deny) {
if (!CheckDeny (p as CodeAccessPermission))
ThrowSecurityException (this, "Deny", frame, SecurityAction.Demand, p);
}
}
// 3. CheckAssert
if (frame.Assert != null) {
if (frame.Assert.IsUnrestricted ())
return true; // remove permission and continue stack walk
foreach (IPermission p in frame.Assert) {
if (CheckAssert (p as CodeAccessPermission)) {
return true; // remove permission and continue stack walk
}
}
}
// continue the stack walk
return false;
}
internal static void ThrowInvalidPermission (IPermission target, Type expected)
{
string msg = Locale.GetText ("Invalid permission type '{0}', expected type '{1}'.");
msg = String.Format (msg, target.GetType (), expected);
throw new ArgumentException (msg, "target");
}
internal static void ThrowExecutionEngineException (SecurityAction stackmod)
{
string msg = Locale.GetText ("No {0} modifier is present on the current stack frame.");
// FIXME: we don't (yet) support imperative stack modifiers
msg += Environment.NewLine + "Currently only declarative stack modifiers are supported.";
throw new ExecutionEngineException (String.Format (msg, stackmod));
}
internal static void ThrowSecurityException (object demanded, string message, SecurityFrame frame,
SecurityAction action, IPermission failed)
{
#if NET_2_1
throw new SecurityException (message);
#else
Assembly a = frame.Assembly;
throw new SecurityException (Locale.GetText (message),
a.UnprotectedGetName (), a.GrantedPermissionSet,
a.DeniedPermissionSet, frame.Method, action, demanded,
failed, a.UnprotectedGetEvidence ());
#endif
}
}
}

View File

@ -0,0 +1,91 @@
//
// System.Security.HostProtectionException class
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Permissions;
namespace System.Security {
[Serializable]
[ComVisible (true)]
[MonoTODO ("Not supported in the runtime")]
public class HostProtectionException : SystemException {
private HostProtectionResource _protected;
private HostProtectionResource _demanded;
public HostProtectionException ()
{
}
public HostProtectionException (string message)
: base (message)
{
}
public HostProtectionException (string message, Exception e)
: base (message, e)
{
}
public HostProtectionException (string message, HostProtectionResource protectedResources, HostProtectionResource demandedResources)
: base (message)
{
this._protected = protectedResources;
this._demanded = demandedResources;
}
protected HostProtectionException (SerializationInfo info, StreamingContext context)
{
GetObjectData (info, context);
}
public HostProtectionResource DemandedResources {
get { return _demanded; }
}
public HostProtectionResource ProtectedResources {
get { return _protected; }
}
[MonoTODO]
public override void GetObjectData (SerializationInfo info, StreamingContext context)
{
if (info == null)
throw new ArgumentNullException ("info");
}
[MonoTODO]
public override string ToString ()
{
return base.ToString ();
}
}
}

View File

@ -0,0 +1,103 @@
//
// System.Security.HostSecurityManager class
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Reflection;
using System.Runtime.Hosting;
using System.Runtime.InteropServices;
using System.Security.Policy;
namespace System.Security {
[Serializable]
[ComVisible (true)]
public class HostSecurityManager {
public HostSecurityManager ()
{
}
public virtual PolicyLevel DomainPolicy {
// always return null - may be overriden
get { return null; }
}
public virtual HostSecurityManagerOptions Flags {
get { return HostSecurityManagerOptions.AllFlags; }
}
public virtual ApplicationTrust DetermineApplicationTrust (Evidence applicationEvidence, Evidence activatorEvidence, TrustManagerContext context)
{
if (applicationEvidence == null)
throw new ArgumentNullException ("applicationEvidence");
ActivationArguments aa = null;
foreach (object o in applicationEvidence) {
aa = (o as ActivationArguments);
if (aa != null)
break;
}
if (aa == null) {
string msg = Locale.GetText ("No {0} found in {1}.");
throw new ArgumentException (string.Format (msg, "ActivationArguments", "Evidence"), "applicationEvidence");
}
if (aa.ActivationContext == null) {
string msg = Locale.GetText ("No {0} found in {1}.");
throw new ArgumentException (string.Format (msg, "ActivationContext", "ActivationArguments"), "applicationEvidence");
}
// FIXME: this part is still untested (requires manifest support)
if (ApplicationSecurityManager.DetermineApplicationTrust (aa.ActivationContext, context)) {
if (aa.ApplicationIdentity == null)
return new ApplicationTrust ();
else
return new ApplicationTrust (aa.ApplicationIdentity);
}
return null;
}
public virtual Evidence ProvideAppDomainEvidence (Evidence inputEvidence)
{
// no changes - may be overriden
return inputEvidence;
}
public virtual Evidence ProvideAssemblyEvidence (Assembly loadedAssembly, Evidence inputEvidence)
{
// no changes - may be overriden
return inputEvidence;
}
public virtual PermissionSet ResolvePolicy (Evidence evidence)
{
if (evidence == null)
throw new NullReferenceException ("evidence");
return SecurityManager.ResolvePolicy (evidence);
}
}
}

View File

@ -0,0 +1,45 @@
//
// System.Security.HostSecurityManagerOptions enumeration
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
namespace System.Security {
[Flags]
[ComVisible (true)]
[Serializable]
public enum HostSecurityManagerOptions {
None = 0,
HostAppDomainEvidence = 1,
HostPolicyLevel = 2,
HostAssemblyEvidence = 4,
HostDetermineApplicationTrust = 8,
HostResolvePolicy = 16,
AllFlags = HostAppDomainEvidence | HostPolicyLevel | HostAssemblyEvidence | HostDetermineApplicationTrust | HostResolvePolicy
}
}

View File

@ -0,0 +1,37 @@
// System.Security.IEvidenceFactory
//
// Sean MacIsaac (macisaac@ximian.com)
//
// (C) Ximian, Inc. 2001
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
using System.Security.Policy;
namespace System.Security {
[ComVisible (true)]
public interface IEvidenceFactory {
Evidence Evidence { get; }
}
}

View File

@ -0,0 +1,46 @@
//
// System.Security.IPermission.cs
//
// Author:
// Miguel de Icaza (miguel@ximian.com)
//
// (C) Ximian, Inc. http://www.ximian.com
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
namespace System.Security {
[ComVisible (true)]
public interface IPermission : ISecurityEncodable {
IPermission Copy ();
void Demand ();
IPermission Intersect (IPermission target);
bool IsSubsetOf (IPermission target);
IPermission Union (IPermission target);
}
}

View File

@ -0,0 +1,41 @@
//
// System.Security.ISecurityEncodable.cs
//
// Author:
// Miguel de Icaza (miguel@ximian.com)
//
// (C) Ximian, Inc. http://www.ximian.com
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
namespace System.Security {
[ComVisible (true)]
public interface ISecurityEncodable {
void FromXml (SecurityElement e);
SecurityElement ToXml ();
}
}

View File

@ -0,0 +1,42 @@
//
// System.Security.ISecurityPolicyEncodable.cs
//
// Author:
// Nick Drochak(ndrochak@gol.com)
//
// (C) Nick Drochak
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
using System.Security.Policy;
namespace System.Security {
[ComVisible (true)]
public interface ISecurityPolicyEncodable {
void FromXml (SecurityElement e, PolicyLevel level);
SecurityElement ToXml (PolicyLevel level);
}
}

View File

@ -0,0 +1,45 @@
//
// System.Security.IStackWalk.cs
//
// Author:
// Miguel de Icaza (miguel@ximian.com)
//
// (C) Ximian, Inc. http://www.ximian.com
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
namespace System.Security {
[ComVisible (true)]
public interface IStackWalk {
void Assert ();
void Demand ();
void Deny ();
void PermitOnly ();
}
}

View File

@ -0,0 +1,148 @@
//
// System.Security.NamedPermissionSet
//
// Authors:
// Dan Lewis (dihlewis@yahoo.co.uk)
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2002
// Portions (C) 2003, 2004 Motus Technologies Inc. (http://www.motus.com)
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
using System.Security.Permissions;
namespace System.Security {
[ComVisible (true)]
[Serializable]
public sealed class NamedPermissionSet : PermissionSet {
private string name;
private string description;
// for PolicyLevel (to avoid validation duplication)
internal NamedPermissionSet ()
: base ()
{
}
public NamedPermissionSet (string name, PermissionSet permSet)
: base (permSet)
{
Name = name;
}
public NamedPermissionSet (string name, PermissionState state)
: base (state)
{
Name = name;
}
public NamedPermissionSet (NamedPermissionSet permSet)
: base (permSet)
{
name = permSet.name; // name can be null here
description = permSet.description;
}
public NamedPermissionSet (string name)
: this (name, PermissionState.Unrestricted)
{
}
// properties
public string Description {
get { return description; }
set { description = value; }
}
public string Name {
get { return name; }
set {
if ((value == null) || (value == String.Empty)) {
throw new ArgumentException (Locale.GetText ("invalid name"));
}
name = value;
}
}
// methods
public override PermissionSet Copy ()
{
return new NamedPermissionSet (this);
}
public NamedPermissionSet Copy (string name)
{
NamedPermissionSet nps = new NamedPermissionSet (this);
nps.Name = name; // get the new name
return nps;
}
public override void FromXml (SecurityElement et)
{
base.FromXml (et);
// strangely it can import a null Name (bypassing property setter)
name = et.Attribute ("Name");
description = et.Attribute ("Description");
if (description == null)
description = String.Empty;
}
public override SecurityElement ToXml ()
{
SecurityElement se = base.ToXml ();
if (name != null)
se.AddAttribute ("Name", name);
if (description != null)
se.AddAttribute ("Description", description);
return se;
}
[ComVisible (false)]
public override bool Equals (object obj)
{
if (obj == null)
return false;
NamedPermissionSet nps = (obj as NamedPermissionSet);
if (nps == null)
return false;
// description isn't part of the comparaison
return ((name == nps.Name) && base.Equals (obj));
}
[ComVisible (false)]
public override int GetHashCode ()
{
int hc = base.GetHashCode ();
// name is part of the hash code (except when null)
if (name != null)
hc ^= name.GetHashCode ();
// description is never part of the hash code
return hc;
}
}
}

View File

@ -0,0 +1,95 @@
//
// System.Security.PermissionBuilder.cs
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Security.Permissions;
namespace System.Security {
internal static class PermissionBuilder {
private static object[] psNone = new object [1] { PermissionState.None };
// can be used to create an empty or an unrestricted permission from any valid type
static public IPermission Create (string fullname, PermissionState state)
{
if (fullname == null)
throw new ArgumentNullException ("fullname");
SecurityElement se = new SecurityElement ("IPermission");
se.AddAttribute ("class", fullname);
se.AddAttribute ("version", "1");
if (state == PermissionState.Unrestricted)
se.AddAttribute ("Unrestricted", "true");
return CreatePermission (fullname, se);
}
static public IPermission Create (SecurityElement se)
{
if (se == null)
throw new ArgumentNullException ("se");
string className = se.Attribute ("class");
if ((className == null) || (className.Length == 0))
throw new ArgumentException ("class");
return CreatePermission (className, se);
}
// to use in case where the "class" attribute isn't a fully qualified class name
static public IPermission Create (string fullname, SecurityElement se)
{
if (fullname == null)
throw new ArgumentNullException ("fullname");
if (se == null)
throw new ArgumentNullException ("se");
return CreatePermission (fullname, se);
}
static public IPermission Create (Type type)
{
// note: unification is handled in lower levels
// http://blogs.msdn.com/shawnfa/archive/2004/08/05/209320.aspx
return (IPermission) Activator.CreateInstance (type, psNone);
}
// internal stuff
internal static IPermission CreatePermission (string fullname, SecurityElement se)
{
Type classType = Type.GetType (fullname);
if (classType == null) {
string msg = Locale.GetText ("Can't create an instance of permission class {0}.");
throw new TypeLoadException (String.Format (msg, fullname));
}
IPermission p = Create (classType);
p.FromXml (se);
return p;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,42 @@
//
// System.Security.PolicyLevelType.cs
//
// Author:
// Nick Drochak(ndrochak@gol.com)
//
// (C) Nick Drochak
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
namespace System.Security {
[Serializable]
[ComVisible (true)]
public enum PolicyLevelType {
User = 0x0,
Machine,
Enterprise,
AppDomain,
}
}

View File

@ -0,0 +1,319 @@
//
// System.Security.SecureString class
//
// Authors
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.ConstrainedExecution;
using System.Security.Cryptography;
using System.Security.Permissions;
#if NET_4_0
using System.Runtime.ExceptionServices;
#endif
namespace System.Security {
[MonoTODO ("work in progress - encryption is missing")]
public sealed class SecureString : IDisposable {
private const int BlockSize = 16;
private const int MaxSize = 65536;
private int length;
private bool disposed;
private bool read_only;
private byte[] data;
static SecureString ()
{
// ProtectedMemory has been moved to System.Security.dll
// we use reflection to call it (if available) or we'll
// throw an exception
}
public SecureString ()
{
Alloc (BlockSize >> 1, false);
}
[CLSCompliant (false)]
public unsafe SecureString (char* value, int length)
{
if (value == null)
throw new ArgumentNullException ("value");
if ((length < 0) || (length > MaxSize))
throw new ArgumentOutOfRangeException ("length", "< 0 || > 65536");
this.length = length; // real length
Alloc (length, false);
int n = 0;
for (int i = 0; i < length; i++) {
char c = *value++;
data[n++] = (byte) (c >> 8);
data[n++] = (byte) c;
}
Encrypt ();
}
// properties
public int Length {
get {
if (disposed)
throw new ObjectDisposedException ("SecureString");
return length;
}
}
#if NET_4_0
[HandleProcessCorruptedStateExceptions]
#endif
public void AppendChar (char c)
{
if (disposed)
throw new ObjectDisposedException ("SecureString");
if (read_only) {
throw new InvalidOperationException (Locale.GetText (
"SecureString is read-only."));
}
if (length == MaxSize)
throw new ArgumentOutOfRangeException ("length", "> 65536");
try {
Decrypt ();
int n = length * 2;
Alloc (++length, true);
data[n++] = (byte) (c >> 8);
data[n++] = (byte) c;
}
finally {
Encrypt ();
}
}
public void Clear ()
{
if (disposed)
throw new ObjectDisposedException ("SecureString");
if (read_only) {
throw new InvalidOperationException (Locale.GetText (
"SecureString is read-only."));
}
Array.Clear (data, 0, data.Length);
length = 0;
}
public SecureString Copy ()
{
SecureString ss = new SecureString ();
ss.data = (byte[]) data.Clone ();
ss.length = length;
return ss;
}
public void Dispose ()
{
disposed = true;
// don't call clear because we could be either in read-only
// or already disposed - but DO CLEAR the data
if (data != null) {
Array.Clear (data, 0, data.Length);
data = null;
}
length = 0;
}
#if NET_4_0
[HandleProcessCorruptedStateExceptions]
#endif
public void InsertAt (int index, char c)
{
if (disposed)
throw new ObjectDisposedException ("SecureString");
if (read_only) {
throw new InvalidOperationException (Locale.GetText (
"SecureString is read-only."));
}
if ((index < 0) || (index > length))
throw new ArgumentOutOfRangeException ("index", "< 0 || > length");
// insert increments length
if (length >= MaxSize) {
string msg = Locale.GetText ("Maximum string size is '{0}'.", MaxSize);
throw new ArgumentOutOfRangeException ("index", msg);
}
try {
Decrypt ();
Alloc (++length, true);
int n = index * 2;
Buffer.BlockCopy (data, n, data, n + 2, data.Length - n - 2);
data[n++] = (byte) (c >> 8);
data[n] = (byte) c;
}
finally {
Encrypt ();
}
}
public bool IsReadOnly ()
{
if (disposed)
throw new ObjectDisposedException ("SecureString");
return read_only;
}
public void MakeReadOnly ()
{
read_only = true;
}
#if NET_4_0
[HandleProcessCorruptedStateExceptions]
#endif
public void RemoveAt (int index)
{
if (disposed)
throw new ObjectDisposedException ("SecureString");
if (read_only) {
throw new InvalidOperationException (Locale.GetText (
"SecureString is read-only."));
}
if ((index < 0) || (index >= length))
throw new ArgumentOutOfRangeException ("index", "< 0 || > length");
try {
Decrypt ();
Buffer.BlockCopy (data, index * 2 + 2, data, index * 2, data.Length - index * 2 - 2);
Alloc (--length, true);
}
finally {
Encrypt ();
}
}
#if NET_4_0
[HandleProcessCorruptedStateExceptions]
#endif
public void SetAt (int index, char c)
{
if (disposed)
throw new ObjectDisposedException ("SecureString");
if (read_only) {
throw new InvalidOperationException (Locale.GetText (
"SecureString is read-only."));
}
if ((index < 0) || (index >= length))
throw new ArgumentOutOfRangeException ("index", "< 0 || > length");
try {
Decrypt ();
int n = index * 2;
data[n++] = (byte) (c >> 8);
data[n] = (byte) c;
}
finally {
Encrypt ();
}
}
// internal/private stuff
// [MethodImplAttribute(MethodImplOptions.InternalCall)]
// extern static void EncryptInternal (byte [] data, object scope);
// [MethodImplAttribute(MethodImplOptions.InternalCall)]
// extern static void DecryptInternal (byte [] data, object scope);
// static readonly object scope = Enum.Parse (
// Assembly.Load (Consts.AssemblySystem_Security)
// .GetType ("System.Security.Cryptography.MemoryProtectionScope"), "SameProcess");
// Note that ProtectedMemory is not supported on non-Windows environment right now.
private void Encrypt ()
{
if ((data != null) && (data.Length > 0)) {
// It somehow causes nunit test breakage
// EncryptInternal (data, scope);
}
}
// Note that ProtectedMemory is not supported on non-Windows environment right now.
private void Decrypt ()
{
if ((data != null) && (data.Length > 0)) {
// It somehow causes nunit test breakage
// DecryptInternal (data, scope);
}
}
// note: realloc only work for bigger buffers. Clear will
// reset buffers to default (and small) size.
private void Alloc (int length, bool realloc)
{
if ((length < 0) || (length > MaxSize))
throw new ArgumentOutOfRangeException ("length", "< 0 || > 65536");
// (size / blocksize) + 1 * blocksize
// where size = length * 2 (unicode) and blocksize == 16 (ProtectedMemory)
// length * 2 (unicode) / 16 (blocksize)
int size = (length >> 3) + (((length & 0x7) == 0) ? 0 : 1) << 4;
// is re-allocation necessary ? (i.e. grow or shrink
// but do not re-allocate the same amount of memory)
if (realloc && (data != null) && (size == data.Length))
return;
if (realloc) {
// copy, then clear
byte[] newdata = new byte[size];
Array.Copy (data, 0, newdata, 0, Math.Min (data.Length, newdata.Length));
Array.Clear (data, 0, data.Length);
data = newdata;
} else {
data = new byte[size];
}
}
// dangerous method (put a LinkDemand on it)
internal byte[] GetBuffer ()
{
byte[] secret = new byte[length << 1];
try {
Decrypt ();
Buffer.BlockCopy (data, 0, secret, 0, secret.Length);
}
finally {
Encrypt ();
}
// NOTE: CALLER IS RESPONSIBLE TO ZEROIZE THE DATA
return secret;
}
}
}

View File

@ -0,0 +1,213 @@
//
// System.Security.SecurityContext class
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Security.Principal;
using System.Threading;
namespace System.Security {
public sealed class SecurityContext
#if NET_4_0
: IDisposable
#endif
{
private bool _capture;
private IntPtr _winid;
#if !MOBILE
private CompressedStack _stack;
#endif
private bool _suppressFlowWindowsIdentity;
private bool _suppressFlow;
internal SecurityContext ()
{
}
// copy constructor
internal SecurityContext (SecurityContext sc)
{
_capture = true;
#if !MOBILE
_winid = sc._winid;
if (sc._stack != null)
_stack = sc._stack.CreateCopy ();
#endif
}
public SecurityContext CreateCopy ()
{
if (!_capture)
throw new InvalidOperationException ();
return new SecurityContext (this);
}
// static methods
static public SecurityContext Capture ()
{
#if !MOBILE
SecurityContext sc = Thread.CurrentThread.ExecutionContext.SecurityContext;
if (sc.FlowSuppressed)
return null;
#endif
SecurityContext capture = new SecurityContext ();
capture._capture = true;
#if !MOBILE
capture._winid = WindowsIdentity.GetCurrentToken ();
capture._stack = CompressedStack.Capture ();
#endif
return capture;
}
#if NET_4_0
public void Dispose ()
{
}
#endif
// internal stuff
internal bool FlowSuppressed {
get { return _suppressFlow; }
set { _suppressFlow = value; }
}
internal bool WindowsIdentityFlowSuppressed {
get { return _suppressFlowWindowsIdentity; }
set { _suppressFlowWindowsIdentity = value; }
}
#if !MOBILE
internal CompressedStack CompressedStack {
get { return _stack; }
set { _stack = value; }
}
#endif
internal IntPtr IdentityToken {
get { return _winid; }
set { _winid = value; }
}
// Suppressing the SecurityContext flow wasn't required before 2.0
static public bool IsFlowSuppressed ()
{
#if MOBILE
return false;
#else
return Thread.CurrentThread.ExecutionContext.SecurityContext.FlowSuppressed;
#endif
}
static public bool IsWindowsIdentityFlowSuppressed ()
{
#if MOBILE
return false;
#else
return Thread.CurrentThread.ExecutionContext.SecurityContext.WindowsIdentityFlowSuppressed;
#endif
}
static public void RestoreFlow ()
{
#if !MOBILE
SecurityContext sc = Thread.CurrentThread.ExecutionContext.SecurityContext;
// if nothing is suppressed then throw
if (!sc.FlowSuppressed && !sc.WindowsIdentityFlowSuppressed)
throw new InvalidOperationException ();
sc.FlowSuppressed = false;
sc.WindowsIdentityFlowSuppressed = false;
#endif
}
// if you got the context then you can use it
[SecurityPermission (SecurityAction.Assert, ControlPrincipal = true)]
[SecurityPermission (SecurityAction.LinkDemand, Infrastructure = true)]
static public void Run (SecurityContext securityContext, ContextCallback callback, object state)
{
if (securityContext == null) {
throw new InvalidOperationException (Locale.GetText (
"Null SecurityContext"));
}
#if MOBILE
callback (state);
#else
SecurityContext sc = Thread.CurrentThread.ExecutionContext.SecurityContext;
IPrincipal original = Thread.CurrentPrincipal;
try {
if (sc.IdentityToken != IntPtr.Zero) {
Thread.CurrentPrincipal = new WindowsPrincipal (new WindowsIdentity (sc.IdentityToken));
}
// FIXME: is the security manager isn't active then we may not have
// a compressed stack (bug #78652)
if (securityContext.CompressedStack != null)
CompressedStack.Run (securityContext.CompressedStack, callback, state);
else
callback (state);
}
finally {
if ((original != null) && (sc.IdentityToken != IntPtr.Zero))
Thread.CurrentPrincipal = original;
}
#endif
}
[SecurityPermission (SecurityAction.LinkDemand, Infrastructure = true)]
static public AsyncFlowControl SuppressFlow ()
{
#if MOBILE
throw new NotSupportedException ();
#else
Thread t = Thread.CurrentThread;
// suppress both flows
t.ExecutionContext.SecurityContext.FlowSuppressed = true;
t.ExecutionContext.SecurityContext.WindowsIdentityFlowSuppressed = true;
return new AsyncFlowControl (t, AsyncFlowControlType.Security);
#endif
}
static public AsyncFlowControl SuppressFlowWindowsIdentity ()
{
#if MOBILE
throw new NotSupportedException ();
#else
Thread t = Thread.CurrentThread;
t.ExecutionContext.SecurityContext.WindowsIdentityFlowSuppressed = true;
return new AsyncFlowControl (t, AsyncFlowControlType.Security);
#endif
}
}
}

View File

@ -0,0 +1,39 @@
//
// System.Security.SecurityContextSource
//
// Author:
// Jb Evain <jbevain@novell.com>
//
// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_4_0
namespace System.Security {
public enum SecurityContextSource {
CurrentAppDomain,
CurrentAssembly,
}
}
#endif

View File

@ -0,0 +1,89 @@
//
// System.Security.SecurityCriticalAttribute implementation
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005, 2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace System.Security {
#if NET_2_1
[AttributeUsage (AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct |
AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property |
AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate,
AllowMultiple=false, Inherited=false)]
public sealed class SecurityCriticalAttribute : Attribute {
public SecurityCriticalAttribute ()
{
}
}
#else
[MonoTODO ("Only supported by the runtime when CoreCLR is enabled")]
#if NET_4_0
[AttributeUsage (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct |
AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method |
AttributeTargets.Field | AttributeTargets.Interface | AttributeTargets.Delegate,
AllowMultiple=false, Inherited=false)]
#else
[AttributeUsage (AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct |
AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event |
AttributeTargets.Field | AttributeTargets.Interface | AttributeTargets.Delegate,
AllowMultiple=false, Inherited=false)]
#endif
public sealed class SecurityCriticalAttribute : Attribute {
private SecurityCriticalScope _scope;
public SecurityCriticalAttribute ()
: base ()
{
_scope = SecurityCriticalScope.Explicit;
}
public SecurityCriticalAttribute (SecurityCriticalScope scope)
: base ()
{
switch (scope) {
case SecurityCriticalScope.Everything:
_scope = SecurityCriticalScope.Everything;
break;
default:
// that includes all bad enums values
_scope = SecurityCriticalScope.Explicit;
break;
}
}
#if NET_4_0
[Obsolete]
#endif
public SecurityCriticalScope Scope {
get { return _scope; }
}
}
#endif
}

View File

@ -0,0 +1,39 @@
//
// System.Security.SecurityCriticalScope enum
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace System.Security {
#if NET_4_0
[Obsolete]
#endif
public enum SecurityCriticalScope {
Explicit,
Everything
}
}

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