From 748a1ef357321b3f9153f06efb03d0a1091816ea Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Wed, 14 Jul 2004 11:53:49 +0000 Subject: [PATCH] 2004-07-14 Sebastien Pouliot * HostProtectionException.cs: New class in Fx 2.0. * HostSecurityManager.cs: New class in Fx 2.0. * HostSecurityManagerFlags.cs: New enum in Fx 2.0. * SecurityContext.cs: New class in Fx 2.0. * SecurityContextSwitcher.cs: New structure in Fx 2.0. svn path=/trunk/mcs/; revision=31127 --- mcs/class/corlib/System.Security/ChangeLog | 8 + .../HostProtectionException.cs | 86 +++++++++++ .../System.Security/HostSecurityManager.cs | 70 +++++++++ .../HostSecurityManagerFlags.cs | 47 ++++++ .../corlib/System.Security/SecurityContext.cs | 142 ++++++++++++++++++ .../SecurityContextSwitcher.cs | 78 ++++++++++ 6 files changed, 431 insertions(+) create mode 100644 mcs/class/corlib/System.Security/HostProtectionException.cs create mode 100644 mcs/class/corlib/System.Security/HostSecurityManager.cs create mode 100644 mcs/class/corlib/System.Security/HostSecurityManagerFlags.cs create mode 100644 mcs/class/corlib/System.Security/SecurityContext.cs create mode 100644 mcs/class/corlib/System.Security/SecurityContextSwitcher.cs diff --git a/mcs/class/corlib/System.Security/ChangeLog b/mcs/class/corlib/System.Security/ChangeLog index f79d22c649b..ada593d64e4 100755 --- a/mcs/class/corlib/System.Security/ChangeLog +++ b/mcs/class/corlib/System.Security/ChangeLog @@ -1,3 +1,11 @@ +2004-07-14 Sebastien Pouliot + + * HostProtectionException.cs: New class in Fx 2.0. + * HostSecurityManager.cs: New class in Fx 2.0. + * HostSecurityManagerFlags.cs: New enum in Fx 2.0. + * SecurityContext.cs: New class in Fx 2.0. + * SecurityContextSwitcher.cs: New structure in Fx 2.0. + 2004-06-15 Gert Driesen * XmlSyntaxException.cs: added missing serialization ctor diff --git a/mcs/class/corlib/System.Security/HostProtectionException.cs b/mcs/class/corlib/System.Security/HostProtectionException.cs new file mode 100644 index 00000000000..c209ede23e6 --- /dev/null +++ b/mcs/class/corlib/System.Security/HostProtectionException.cs @@ -0,0 +1,86 @@ +// +// System.Security.HostProtectionException class +// +// Author: +// Sebastien Pouliot +// +// Copyright (C) 2004 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_2_0 + +using System; +using System.Runtime.InteropServices; +using System.Runtime.Serialization; +using System.Security.Permissions; + +namespace System.Security { + + [Serializable] + public class HostProtectionException : SystemException, _Exception { + + private HostProtectionResource _inaccessible; + private HostProtectionResource _protected; + private HostProtectionResource _demanded; + + public HostProtectionException (string message, HostProtectionResource inaccessibleResources, + HostProtectionResource protectedResources, HostProtectionResource demandedRessources) + : base (message) + { + } + + protected HostProtectionException (SerializationInfo info, StreamingContext context) + { + GetObjectData (info, context); + } + + public HostProtectionResource DemandedResources { + get { return _demanded; } + set { _demanded = value; } + } + + public HostProtectionResource InaccessibleResources { + get { return _inaccessible; } + set { _inaccessible = value; } + } + + public HostProtectionResource ProtectedResources { + get { return _protected; } + set { _protected = value; } + } + + [MonoTODO] + public override void GetObjectData (SerializationInfo info, StreamingContext context) + { + if (info == null) + throw new ArgumentNullException ("info"); + } + + [MonoTODO] + public override string ToString () + { + return base.ToString (); + } + } +} + +#endif diff --git a/mcs/class/corlib/System.Security/HostSecurityManager.cs b/mcs/class/corlib/System.Security/HostSecurityManager.cs new file mode 100644 index 00000000000..8987ccbfa30 --- /dev/null +++ b/mcs/class/corlib/System.Security/HostSecurityManager.cs @@ -0,0 +1,70 @@ +// +// System.Security.HostSecurityManager class +// +// Author: +// Sebastien Pouliot +// +// Copyright (C) 2004 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_2_0 + +using System; +using System.Reflection; +using System.Security.Policy; + +namespace System.Security { + + [Serializable] + public class HostSecurityManager { + + public HostSecurityManager () + { + } + + public virtual PolicyLevel DomainPolicy { + get { return null; } + } + + public virtual HostSecurityManagerFlags Flags { + get { return HostSecurityManagerFlags.AllFlags; } + } + + public virtual PermissionSet RefusedSet { + get { return null; } + } + + public virtual bool DetermineApplicationTrust (ActivationContext activationContext, TrustManagerContext context) + { + if (activationContext == null) + throw new ArgumentNullException ("activationContext"); + return true; + } + + public virtual Evidence ProvideAssemblyEvidence (Assembly loadedAssembly, Evidence evidence) + { + return evidence; + } + } +} + +#endif diff --git a/mcs/class/corlib/System.Security/HostSecurityManagerFlags.cs b/mcs/class/corlib/System.Security/HostSecurityManagerFlags.cs new file mode 100644 index 00000000000..e23a6795882 --- /dev/null +++ b/mcs/class/corlib/System.Security/HostSecurityManagerFlags.cs @@ -0,0 +1,47 @@ +// +// System.Security.HostSecurityManagerFlags enumeration +// +// Author: +// Sebastien Pouliot +// +// Copyright (C) 2004 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_2_0 + +using System; + +namespace System.Security { + + [Flags] + [Serializable] + public enum HostSecurityManagerFlags { + None = 0, + HostRefusedSet = 1, + HostPolicyLevel = 2, + HostAssemblyEvidence = 4, + HostDetermineApplicationTrust = 8, + AllFlags = HostAssemblyEvidence | HostDetermineApplicationTrust | HostPolicyLevel | HostRefusedSet + } +} + +#endif diff --git a/mcs/class/corlib/System.Security/SecurityContext.cs b/mcs/class/corlib/System.Security/SecurityContext.cs new file mode 100644 index 00000000000..8edb1f56730 --- /dev/null +++ b/mcs/class/corlib/System.Security/SecurityContext.cs @@ -0,0 +1,142 @@ +// +// System.Security.SecurityContext class +// +// Author: +// Sebastien Pouliot +// +// Copyright (C) 2004 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_2_0 + +using System; +using System.Runtime.InteropServices; +using System.Security.Principal; +using System.Threading; + +namespace System.Security { + + [MonoTODO ("need to determine internals")] + [ComVisible (false)] + public sealed class SecurityContext { + + static private bool _flowSuppressed; + static private bool _windowsIdentityFlowSuppressed; + + private bool _usedForSetSecurityContext; + private WindowsIdentity _winid; + private CompressedStack _stack; + + internal SecurityContext () + { + _usedForSetSecurityContext = false; + } + + // copy constructor + internal SecurityContext (SecurityContext sc) + { + _usedForSetSecurityContext = sc._usedForSetSecurityContext; + _winid = sc._winid; + _stack = sc._stack.CreateCopy (); + } + + public SecurityContext CreateCopy () + { + if (_usedForSetSecurityContext) { + throw new InvalidOperationException (Locale.GetText ( + "SecurityContext used for SetSecurityContext")); + } + return new SecurityContext (this); + } + +// LAMESPEC: documented but not implemented (not shown by corcompare) +#if false + public override bool Equals (object obj) + { + return false; + } + + public override int GetHashCode () + { + return 0; + } + + public void Undo () + { + } +#endif + // static methods + + static public SecurityContext Capture () + { + return new SecurityContext (); + } + + static public bool IsFlowSuppressed () + { + return _flowSuppressed; + } + + static public bool IsWindowsIdentityFlowSuppressed () + { + return _windowsIdentityFlowSuppressed; + } + + static public void RestoreFlow () + { + _flowSuppressed = false; + } + + static public void Run (SecurityContext securityContext, ContextCallback callBack, object state) + { + if (securityContext == null) { + throw new InvalidOperationException (Locale.GetText ( + "Null SecurityContext")); + } + } + + static public SecurityContextSwitcher SetSecurityContext (SecurityContext securityContext) + { + if (securityContext == null) { + throw new InvalidOperationException (Locale.GetText ( + "Null SecurityContext")); + } + + securityContext._usedForSetSecurityContext = true; + return new SecurityContextSwitcher (); + } + + static public AsyncFlowControl SuppressFlow () + { + _flowSuppressed = true; + return new AsyncFlowControl (); + } + + static public AsyncFlowControl SuppressFlowWindowsIdentity () + { + _windowsIdentityFlowSuppressed = true; + return new AsyncFlowControl (); + } + } +} + +#endif diff --git a/mcs/class/corlib/System.Security/SecurityContextSwitcher.cs b/mcs/class/corlib/System.Security/SecurityContextSwitcher.cs new file mode 100644 index 00000000000..6b2457391b1 --- /dev/null +++ b/mcs/class/corlib/System.Security/SecurityContextSwitcher.cs @@ -0,0 +1,78 @@ +// +// System.Security.SecurityContextSwitcher structure +// +// Author: +// Sebastien Pouliot +// +// Copyright (C) 2004 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_2_0 + +using System; +using System.Runtime.InteropServices; + +namespace System.Security { + + [MonoTODO ("need to determine internals")] + [ComVisibleAttribute (false)] + public struct SecurityContextSwitcher : IDisposable { + + private bool _undo; + + public override bool Equals (object obj) + { + return false; + } + + public override int GetHashCode () + { + return 0; + } + + public void Undo () + { + _undo = true; + } + + void IDisposable.Dispose () + { + if (!_undo) + Undo (); + } + +// LAMESPEC: documented but not implemented (not shown by corcompare) +#if false + public static bool op_Equality (SecurityContextSwitcher c1, SecurityContextSwitcher c2) + { + return false; + } + + public static bool op_Inequality (SecurityContextSwitcher c1, SecurityContextSwitcher c2) + { + return false; + } +#endif + } +} + +#endif -- 2.25.1