2004-07-14 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Wed, 14 Jul 2004 12:06:25 +0000 (12:06 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Wed, 14 Jul 2004 12:06:25 +0000 (12:06 -0000)
* CodeAccessPermission.cs: Added CheckAssert, CheckDemand, CheckDeny,
CheckPermitOnly, Equals and GetHashCode to NET_2_0 profile. Actualized
TODOs. Removed duplicate license.
* NamedPermissionSet.cs: Added Equals/GetHashCode to NET_2_0 profile.
Removed duplicate license.
* PermissionSet.cs: Added Equals/GetHashCode to NET_2_0 profile.
Removed duplicate license.
* SecurityElement.cs: Added Copy and FromString methods to NET_2_0
profile. Removed duplicate license.
* SecurityException.cs: Added new constructors and properties to
NET_2_0 profile. Removed duplicate license.
* SecurityManager.cs: Added GetZoneAndOrigin and ResolvePolicy to
NET_2_0 profile. Removed duplicate license.
* VerificationException.cs: Implements _Exception for NET_2_0 profile.
Removed duplicate license.
* XmlSyntaxException.cs: Implements _Exception for NET_2_0 profile.
Removed duplicate license.

svn path=/trunk/mcs/; revision=31128

mcs/class/corlib/System.Security/ChangeLog
mcs/class/corlib/System.Security/CodeAccessPermission.cs
mcs/class/corlib/System.Security/NamedPermissionSet.cs
mcs/class/corlib/System.Security/PermissionSet.cs
mcs/class/corlib/System.Security/SecurityElement.cs
mcs/class/corlib/System.Security/SecurityException.cs
mcs/class/corlib/System.Security/SecurityManager.cs
mcs/class/corlib/System.Security/VerificationException.cs
mcs/class/corlib/System.Security/XmlSyntaxException.cs

index ada593d64e48bcc489b09a21a22e1628b6eb527a..ea228aaaaed6c634d6515078bf2b46329a520b7f 100755 (executable)
@@ -1,3 +1,23 @@
+2004-07-14  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * CodeAccessPermission.cs: Added CheckAssert, CheckDemand, CheckDeny,
+       CheckPermitOnly, Equals and GetHashCode to NET_2_0 profile. Actualized
+       TODOs. Removed duplicate license.
+       * NamedPermissionSet.cs: Added Equals/GetHashCode to NET_2_0 profile.
+       Removed duplicate license.
+       * PermissionSet.cs: Added Equals/GetHashCode to NET_2_0 profile. 
+       Removed duplicate license.
+       * SecurityElement.cs: Added Copy and FromString methods to NET_2_0 
+       profile. Removed duplicate license.
+       * SecurityException.cs: Added new constructors and properties to 
+       NET_2_0 profile. Removed duplicate license.
+       * SecurityManager.cs: Added GetZoneAndOrigin and ResolvePolicy to 
+       NET_2_0 profile. Removed duplicate license.
+       * VerificationException.cs: Implements _Exception for NET_2_0 profile.
+       Removed duplicate license.
+       * XmlSyntaxException.cs: Implements _Exception for NET_2_0 profile. 
+       Removed duplicate license.
+
 2004-07-14  Sebastien Pouliot  <sebastien@ximian.com>
 
        * HostProtectionException.cs: New class in Fx 2.0.
index 5a8efd408d910512c7e444e22063269c6f8b0037..273109384503334b2cd47f4144a8ca0417f22284 100755 (executable)
@@ -4,37 +4,11 @@
 // Authors:
 //     Miguel de Icaza (miguel@ximian.com)
 //     Nick Drochak, ndrochak@gol.com
-//     Sebastien Pouliot (spouliot@motus.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 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.
-//
-
-//
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
@@ -66,28 +40,94 @@ namespace System.Security {
        [Serializable]
        public abstract class CodeAccessPermission : IPermission, ISecurityEncodable, IStackWalk {
 
-               protected CodeAccessPermission () {}
+               protected CodeAccessPermission ()
+               {
+               }
 
                // LAMESPEC: Documented as virtual
-               [MonoTODO("SecurityStackFrame not ready")]
+               [MonoTODO]
                public void Assert ()
                {
-                       // throw a SecurityException if Assertion is denied
+                       // Not everyone can assert freely so we must check for
+                       // System.Security.Permissions.SecurityPermissionFlag.Assertion
                        new SecurityPermission (SecurityPermissionFlag.Assertion).Demand ();
-//                     SecurityStackFrame.Current.Assert = this;
+
+                       // TODO: Only one Assert can be active in a stack frame
+                       // throw new SecurityException (Locale.GetText (
+                       //      "Only one Assert can be active in a stack frame"));
+               }
+
+#if NET_2_0
+               public 
+#else
+               internal
+#endif
+               virtual bool CheckAssert (CodeAccessPermission asserted)
+               {
+                       if (asserted == null)
+                               return false;
+                       if (asserted.GetType() != this.GetType ())
+                               return false;
+                       return IsSubsetOf (asserted);
+               }
+
+#if NET_2_0
+               public 
+#else
+               internal
+#endif
+               virtual bool CheckDemand (CodeAccessPermission target)
+               {
+                       if (target == null)
+                               return false;
+                       if (target.GetType () != this.GetType ())
+                               return false;
+                       return IsSubsetOf (target);
+               }
+
+#if NET_2_0
+               public 
+#else
+               internal
+#endif
+               virtual bool CheckDeny (CodeAccessPermission denied)
+               {
+                       if (denied == null)
+                               return true;
+                       if (denied.GetType () != this.GetType ())
+                               return true;
+                       return (Intersect (denied) == null);
+               }
+
+#if NET_2_0
+               public 
+#else
+               internal
+#endif
+               virtual bool CheckPermitOnly (CodeAccessPermission target)
+               {
+                       if (target == null)
+                               return false;
+                       if (target.GetType () != this.GetType ())
+                               return false;
+                       return IsSubsetOf (target);
                }
 
                public abstract IPermission Copy ();
 
                // LAMESPEC: Documented as virtual
-               [MonoTODO("MS contralize demands, but I think we should branch back into indivual permission classes.")]
+               [MonoTODO ("MS centralize demands for IBuiltInPermission, but I think we should branch back into indivual permission classes.")]
                public void Demand ()
                {
                        IBuiltInPermission perm = (this as IBuiltInPermission);
                        if (perm == null)
                                return; // not sure about this :(
 
+                       bool result = false;
+
                        // TODO : Loop the stack
+                       // TODO : Loop all permission on the current frame
+                       result = CheckDemand (this);
                        switch (perm.GetTokenIndex ()) {
                                case 0: // EnvironmentPermission
                                        // TODO
@@ -135,17 +175,40 @@ namespace System.Security {
                                        string message = String.Format (Locale.GetText ("Unknown IBuiltInPermission #{0}"), perm.GetTokenIndex ());
                                        throw new SecurityException (message);
                        }
+
+                       if (!result) {
+                               throw new SecurityException (Locale.GetText (
+                                       "Demand failed."));
+                       }
                }
 
                // LAMESPEC: Documented as virtual
-               [MonoTODO("SecurityStackFrame not ready")]
+               [MonoTODO]
                public void Deny ()
                {
-//                     SecurityStackFrame.Current.Deny = this;
                }
 
+#if NET_2_0
+               public override bool Equals (object obj)
+               {
+                       if (obj == null)
+                               return false;
+                       if (obj.GetType () != this.GetType ())
+                               return false;
+                       // TODO: compare
+                       return true;
+               }
+#endif
+
                public abstract void FromXml (SecurityElement elem);
 
+#if NET_2_0
+               public override int GetHashCode ()
+               {
+                       return base.GetHashCode ();
+               }
+#endif
+
                public abstract IPermission Intersect (IPermission target);
 
                public abstract bool IsSubsetOf (IPermission target);
@@ -166,34 +229,29 @@ namespace System.Security {
                }
 
                // LAMESPEC: Documented as virtual
-               [MonoTODO("SecurityStackFrame not ready")]
+               [MonoTODO]
                public void PermitOnly ()
                {
-//                     SecurityStackFrame.Current.PermitOnly = this;
                }
 
-               [MonoTODO("SecurityStackFrame not ready")]
+               [MonoTODO]
                public static void RevertAll ()
                {
-//                     SecurityStackFrame.Current.RevertAll ();
                }
 
-               [MonoTODO("SecurityStackFrame not ready")]
-               public static void RevertAssert () 
+               [MonoTODO]
+               public static void RevertAssert ()
                {
-//                     SecurityStackFrame.Current.RevertAssert ();
                }
 
-               [MonoTODO("SecurityStackFrame not ready")]
+               [MonoTODO]
                public static void RevertDeny ()
                {
-//                     SecurityStackFrame.Current.RevertDeny ();
                }
 
-               [MonoTODO("SecurityStackFrame not ready")]
-               public static void RevertPermitOnly () 
+               [MonoTODO]
+               public static void RevertPermitOnly ()
                {
-//                     SecurityStackFrame.Current.RevertPermitOnly ();
                }
 
                // snippet moved from FileIOPermission (nickd) to be reused in all derived classes
index 6c2a163ccb1b2b8e20284ca826ef7f2ad0e2a946..c88d4227362481896b5936b5af44bb632a41f3f9 100644 (file)
@@ -3,36 +3,10 @@
 //
 // Authors:
 //     Dan Lewis (dihlewis@yahoo.co.uk)
-//     Sebastien Pouliot (spouliot@motus.com)
+//     Sebastien Pouliot  <sebastien@ximian.com>
 //
 // (C) 2002
 // Portions (C) 2003, 2004 Motus Technologies Inc. (http://www.motus.com)
-//
-
-//
-// 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.
-//
-
-//
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
@@ -63,22 +37,35 @@ namespace System.Security {
        [Serializable]
        public sealed class NamedPermissionSet : PermissionSet {
 
+               private string name;
+               private string description;
+
                // for PolicyLevel (to avoid validation duplication)
-               internal NamedPermissionSet () : base () {}
+               internal NamedPermissionSet () : base ()
+               {
+               }
 
-               public NamedPermissionSet (string name, PermissionSet set) : base (set) 
+               public NamedPermissionSet (string name, PermissionSet set) 
+                       : base (set) 
                {
                        Name = name;
                }
 
-               public NamedPermissionSet (string name, PermissionState state) : base (state) 
+               public NamedPermissionSet (string name, PermissionState state) 
+                       : base (state) 
                {
                        Name = name;
                }
 
-               public NamedPermissionSet (NamedPermissionSet set) : this (set.name, set) {}
+               public NamedPermissionSet (NamedPermissionSet set) 
+                       : this (set.name, set)
+               {
+               }
 
-               public NamedPermissionSet (string name) : this (name, PermissionState.None) {}
+               public NamedPermissionSet (string name) 
+                       : this (name, PermissionState.None)
+               {
+               }
 
                // properties
 
@@ -127,9 +114,25 @@ namespace System.Security {
                        return se;
                }
 
-               // private
+#if NET_2_0
+               public override bool Equals (object obj)
+               {
+                       if (obj == null)
+                               return false;
+                       NamedPermissionSet nps = (obj as NamedPermissionSet);
+                       if (nps == null)
+                               return false;
 
-               private string name;
-               private string description;
+                       return ((name == nps.Name) && (description == nps.Description) && base.Equals (obj));
+               }
+
+               public override int GetHashCode ()
+               {
+                       int hashcode = base.GetHashCode () ^ name.GetHashCode ();
+                       if (description != null)
+                               hashcode ^= description.GetHashCode ();
+                       return hashcode;
+               }
+#endif
        }
 }
index b21bbe59b39e76c298256d4cab40a72457cbb90b..1583d421ec18fe816196854b1733f70f80963fd6 100644 (file)
@@ -3,36 +3,10 @@
 //
 // Authors:
 //     Nick Drochak(ndrochak@gol.com)
-//     Sebastien Pouliot (spouliot@motus.com)
+//     Sebastien Pouliot  <sebastien@ximian.com>
 //
 // (C) Nick Drochak
 // Portions (C) 2003, 2004 Motus Technologies Inc. (http://www.motus.com)
-//
-
-//
-// 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.
-//
-
-//
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
@@ -68,6 +42,7 @@ namespace System.Security {
 
                private PermissionState state;
                private ArrayList list;
+               private int _hashcode;
 
                // constructors
 
@@ -118,6 +93,11 @@ namespace System.Security {
                {
                }
 
+               internal void Clear () 
+               {
+                       list.Clear ();
+               }
+
                public virtual PermissionSet Copy ()
                {
                        return new PermissionSet (this);
@@ -343,5 +323,47 @@ namespace System.Security {
                void IDeserializationCallback.OnDeserialization (object sender) 
                {
                }
+
+#if NET_2_0
+               public override bool Equals (object obj)
+               {
+                       if (obj == null)
+                               return false;
+                       PermissionSet ps = (obj as PermissionSet);
+                       if (ps == null)
+                               return false;
+                       if (list.Count != ps.Count)
+                               return false;
+
+                       for (int i=0; i < list.Count; i++) {
+                               bool found = false;
+                               for (int j=0; i < ps.list.Count; j++) {
+                                       if (list [i].Equals (ps.list [j])) {
+                                               found = true;
+                                               break;
+                                       }
+                               }
+                               if (!found)
+                                       return false;
+                       }
+                       return true;
+               }
+
+               public override int GetHashCode ()
+               {
+                       if (_hashcode == 0) {
+                               _hashcode = state.GetHashCode ();
+                               foreach (IPermission p in list) {
+                                       _hashcode ^= p.GetHashCode ();
+                               }
+                       }
+                       return _hashcode;
+               }
+
+               [MonoTODO ("what's it doing here?")]
+               static public void RevertAssert ()
+               {
+               }
+#endif
        }
 }
index 08d7828513261790cec857ff59ab8de88b5a144c..39798039d8df324664319ecb91e9bcaa1c95fab2 100755 (executable)
@@ -2,36 +2,11 @@
 // System.Security.SecurityElement.cs
 //
 // Authors:
-//   Miguel de Icaza (miguel@ximian.com)
-//   Lawrence Pit (loz@cable.a2000.nl)
-//   Sebastien Pouliot  <spouliot@videotron.ca>
+//     Miguel de Icaza (miguel@ximian.com)
+//     Lawrence Pit (loz@cable.a2000.nl)
+//     Sebastien Pouliot  <sebastien@ximian.com>
 //
 // (C) Ximian, Inc. http://www.ximian.com
-
-//
-// 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.
-//
-
-//
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
@@ -58,6 +33,8 @@ using System.Globalization;
 using System.Collections;
 using System.Text;
 
+using Mono.Xml;
+
 namespace System.Security 
 {
        [Serializable]
@@ -117,6 +94,24 @@ namespace System.Security
                        this.Tag = tag;
                        this.Text = text;
                }
+
+               // deep copy
+               internal SecurityElement (SecurityElement se)
+               {
+                       this.Tag = se.Tag;
+                       this.Text = se.Text;
+
+                       if (se.attributes != null) {
+                               foreach (SecurityAttribute sa in se.attributes) {
+                                       this.AddAttribute (sa.Name, sa.Value);
+                               }
+                       }
+                       if (se.children != null) {
+                               foreach (SecurityElement child in se.children) {
+                                       this.AddChild (new SecurityElement (child));
+                               }
+                       }
+               }
                
                public Hashtable Attributes {
                        get {
@@ -225,6 +220,13 @@ namespace System.Security
                        return ((sa == null) ? null : sa.Value);
                }
 
+#if NET_2_0
+               public SecurityElement Copy ()
+               {
+                       return new SecurityElement (this);
+               }
+#endif
+
                public bool Equal (SecurityElement other)
                {
                        if (other == null)
@@ -298,6 +300,15 @@ namespace System.Security
                        return sb.ToString ();
                }
 
+#if NET_2_0
+               static public SecurityElement FromString (string xml)
+               {
+                       SecurityParser sp = new SecurityParser ();
+                       sp.LoadXml (xml);
+                       return sp.ToXml ();
+               }
+#endif
+
                public static bool IsValidAttributeName (string name)
                {
                        return name != null && name.IndexOfAny (invalid_attr_name_chars) == -1;
index be1f5c2b476567594c6898393c3c3f4933856ad0..b389066d1a46feb11b34c02c67397f3556a36aac 100644 (file)
@@ -3,36 +3,10 @@
 //
 // Authors:
 //     Nick Drochak(ndrochak@gol.com)
-//     Sebastien Pouliot (spouliot@motus.com)
+//     Sebastien Pouliot  <sebastien@ximian.com>
 //
 // (C) Nick Drochak
 // (C) 2004 Motus Technologies Inc. (http://www.motus.com)
-//
-
-//
-// 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.
-//
-
-//
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System.Runtime.Serialization;
 using System.Globalization;
+using System.Reflection;
+using System.Runtime.InteropServices;
+using System.Runtime.Serialization;
+using System.Security.Permissions;
+using System.Security.Policy;
 using System.Text;
 
 namespace System.Security {
 
        [Serializable]
+#if NET_2_0
+       public class SecurityException : SystemException, _Exception {
+#else
        public class SecurityException : SystemException {
-
+#endif
                // Fields
                string permissionState;
                Type permissionType;
                private string _granted;
                private string _refused;
+#if NET_2_0
+               private SecurityAction _action;
+               private object _demanded;
+               private object _denyset;
+               private object _permitset;
+               private AssemblyName _assembly;
+               private IPermission _firstperm;
+               private IPermission _permfailed;
+               private MethodInfo _method;
+               private string _url;
+               private SecurityZone _zone;
+#endif
 
                // Properties
-               public string PermissionState
-               {
+
+#if NET_2_0
+               public SecurityAction Action {
+                       get { return _action; }
+                       set { _action = value; }
+               }
+
+               public object Demanded {
+                       get { return _demanded; }
+                       set { _demanded = value; }
+               }
+
+               public object DenySetInstance {
+                       get { return _denyset; }
+                       set { _denyset = value; }
+               }
+
+               public AssemblyName FailedAssemblyInfo {
+                       get { return _assembly; }
+                       set { _assembly = value; }
+               }
+
+               public IPermission FirstPermissionThatFailed {
+                       get { return _firstperm; }
+                       set { _firstperm = value; }
+               }
+
+               public MethodInfo Method {
+                       get { return _method; }
+                       set { _method = value; }
+               }
+
+               [Obsolete]
+               public IPermission PermissionThatFailed {
+                       get { return _permfailed; }
+                       set { _permfailed = value; }
+               }
+
+               public object PermitOnlySetInstance {
+                       get { return _permitset; }
+                       set { _permitset = value; }
+               }
+
+               public string Url {
+                       get { return _url; }
+                       set { _url = value; }
+               }
+
+               public SecurityZone Zone {
+                       get { return _zone; }
+                       set { _zone = value; }
+               }
+#endif
+
+               public string PermissionState {
                        get { return permissionState; }
+#if NET_2_0
+                       set { permissionState = value; }
+#endif
                }
 
-               public Type PermissionType
-               {
+               public Type PermissionType {
                        get { return permissionType; }
+#if NET_2_0
+                       set { permissionType = value; }
+#endif
                }
-#if ! NET_1_0
+
+#if NET_1_1
                public string GrantedSet {
                        get { return _granted; }
+#if NET_2_0
+                       set { _granted = value; }
+#endif
                }
 
                public string RefusedSet {
                        get { return _refused; }
+#if NET_2_0
+                       set { _refused = value; }
+#endif
                }
 #endif
                // Constructors
+
                public SecurityException ()
                        : base (Locale.GetText ("A security error has been detected."))
                {
@@ -138,6 +197,34 @@ namespace System.Security {
                        _refused = refused.ToString ();
                }
 
+#if NET_2_0
+               public SecurityException (string message, object deny, object permitOnly, MethodInfo method, 
+                       object demanded, IPermission permThatFailed)
+                       : base (message)
+               {
+                       _denyset = deny;
+                       _permitset = permitOnly;
+                       _method = method;
+                       _demanded = demanded;
+                       _permfailed = permThatFailed;
+               }
+
+               public SecurityException (string message, AssemblyName assemblyName, PermissionSet grant, 
+                       PermissionSet refused, MethodInfo method, SecurityAction action, object demanded, 
+                       IPermission permThatFailed, Evidence evidence)
+                       : base (message)
+               {
+                       _assembly = assemblyName;
+                       _granted = grant.ToString ();
+                       _refused = refused.ToString ();
+                       _method = method;
+                       _action = action;
+                       _demanded = demanded;
+                       _permfailed = permThatFailed;
+                       // FIXME ? evidence ?
+               }
+#endif
+
                // Methods
                public override void GetObjectData (SerializationInfo info, StreamingContext context)
                {
@@ -158,7 +245,7 @@ namespace System.Security {
                                sb.Append ("Type: ");
                                sb.Append (permissionType.ToString ());
                        }
-#if ! NET_1_0
+#if NET_1_1
                        if (_granted != null) {
                                sb.Append (Environment.NewLine);
                                sb.Append ("Granted: ");
index dfd4977a784e7c5f717222196ec11b8537ba22a2..ffd780a8df911c6b6e2dfa479889e64b0149136e 100644 (file)
@@ -3,36 +3,10 @@
 //
 // Authors:
 //     Nick Drochak(ndrochak@gol.com)
-//     Sebastien Pouliot (spouliot@motus.com)
+//     Sebastien Pouliot  <sebastien@ximian.com>
 //
 // (C) Nick Drochak
 // Portions (C) 2004 Motus Technologies Inc. (http://www.motus.com)
-//
-
-//
-// 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.
-//
-
-//
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
@@ -82,13 +56,15 @@ namespace System.Security {
                        _lockObject = new object ();
                }
 
-               private SecurityManager () {}
+               private SecurityManager ()
+               {
+               }
 
                // properties
 
                public static bool CheckExecutionRights {
                        get { return checkExecutionRights; }
-                       set { 
+                       set {
                                // throw a SecurityException if we don't have ControlPolicy permission
                                new SecurityPermission (SecurityPermissionFlag.ControlPolicy).Demand ();
                                checkExecutionRights = value; 
@@ -97,7 +73,7 @@ namespace System.Security {
 
                public static bool SecurityEnabled {
                        get { return securityEnabled; }
-                       set { 
+                       set {
                                // throw a SecurityException if we don't have ControlPolicy permission
                                new SecurityPermission (SecurityPermissionFlag.ControlPolicy).Demand ();
                                securityEnabled = value; 
@@ -106,6 +82,16 @@ namespace System.Security {
 
                // methods
 
+#if NET_2_0
+               [MonoTODO]
+//             [StrongNameIdentityPermission (LinkDemand, PublicKey = "0x00000000000000000400000000000000")]
+               public static void GetZoneAndOrigin (out ArrayList zone, out ArrayList origin) 
+               {
+                       zone = null;
+                       origin = null;
+               }
+#endif
+
                [MonoTODO("Incomplete")]
                public static bool IsGranted (IPermission perm)
                {
@@ -169,6 +155,14 @@ namespace System.Security {
                        return null;
                }
 
+#if NET_2_0
+               [MonoTODO ()]
+               public static PermissionSet ResolvePolicy (Evidence[] evidences)
+               {
+                       return null;
+               }
+#endif
+
                [MonoTODO()]
                public static PermissionSet ResolvePolicy (Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, out PermissionSet denied)
                {
@@ -225,12 +219,15 @@ namespace System.Security {
                [MonoTODO ("Incomplete")]
                internal static void InitializePolicyHierarchy ()
                {
+                       string machinePolicyPath = "";
+                       string userPolicyPath = "";
+
                        ArrayList al = new ArrayList ();
                        // minimum: Machine, Enterprise and User
                        // FIXME: Incomplete
-                       al.Add (new PolicyLevel ("Enterprise"));
-                       al.Add (new PolicyLevel ("Machine"));
-                       al.Add (new PolicyLevel ("User"));
+                       al.Add (new PolicyLevel ("Enterprise", Path.Combine (machinePolicyPath, "enterprisesec.config")));
+                       al.Add (new PolicyLevel ("Machine", Path.Combine (machinePolicyPath, "security.config")));
+                       al.Add (new PolicyLevel ("User", Path.Combine (userPolicyPath, "security.config")));
                        _hierarchy = ArrayList.Synchronized (al);
                }
        }
index 65eb68fc7117104f311012fafbf0446fd2b919e3..1a2bc1afa3d2390930d0af0efb9a6634e6d463d8 100644 (file)
@@ -1,36 +1,10 @@
-//\r
-// System.Security.VerificationException.cs\r
-//\r
-// Author:\r
-//   Nick Drochak(ndrochak@gol.com)\r
-//\r
-// (C) Nick Drochak\r
-//\r
-
-//
-// 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.
+// System.Security.VerificationException.cs
 //
-
+// Author:
+//   Nick Drochak(ndrochak@gol.com)
 //
+// (C) Nick Drochak
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-\r
-using System.Runtime.Serialization;\r
-using System.Globalization;\r
-\r
-namespace System.Security {\r
-       [Serializable]\r
-       public class VerificationException : SystemException {\r
-       \r
-               // Constructors\r
-               public VerificationException(){}\r
-               public VerificationException(string message) \r
-                       : base (message){}\r
-               protected VerificationException(SerializationInfo info, StreamingContext context) \r
-                       : base (info, context) {}\r
-               public VerificationException(string message, Exception inner) \r
-                       : base (message, inner) {}\r
-       }\r
-}\r
+
+using System.Globalization;
+using System.Runtime.InteropServices;
+using System.Runtime.Serialization;
+
+namespace System.Security {
+
+       [Serializable]
+#if NET_2_0
+       public class VerificationException : SystemException, _Exception {
+#else
+       public class VerificationException : SystemException {
+#endif
+       
+               // Constructors
+               public VerificationException ()
+               {
+               }
+
+               public VerificationException (string message) 
+                       : base (message)
+               {
+               }
+
+               protected VerificationException (SerializationInfo info, StreamingContext context) 
+                       : base (info, context)
+               {
+               }
+
+               public VerificationException (string message, Exception inner) 
+                       : base (message, inner)
+               {
+               }
+       }
+}
index 3fb5ccd86b1450e12447cc893525175674940763..bac141c5ab4e46cf629c11d2ea9af52fe47b8e34 100644 (file)
@@ -1,36 +1,10 @@
-//\r
-// System.Security.XmlSyntaxException.cs\r
-//\r
-// Author:\r
-//   Nick Drochak(ndrochak@gol.com)\r
-//\r
-// (C) Nick Drochak\r
-//\r
-
-//
-// 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.
+// System.Security.XmlSyntaxException.cs
 //
-
+// Author:
+//   Nick Drochak(ndrochak@gol.com)
 //
+// (C) Nick Drochak
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-\r
-using System.Globalization;\r
+
+using System.Globalization;
+using System.Runtime.InteropServices;
 using System.Runtime.Serialization;
-\r
-namespace System.Security {\r
-       [Serializable]\r
-       public sealed class XmlSyntaxException : SystemException {\r
-       \r
-               // Constructors\r
-               public XmlSyntaxException(){}\r
-               public XmlSyntaxException(int lineNumber)\r
-                       : base (Locale.GetText("Invalid syntax on line ") + lineNumber.ToString() + "."){}\r
-               public XmlSyntaxException(int lineNumber, string message)\r
-                       : base (Locale.GetText("Invalid syntax on line ") + lineNumber.ToString() + " - " + message ){}\r
-               public XmlSyntaxException(string message) \r
-                       : base (message){}\r
-               public XmlSyntaxException(string message, Exception inner) \r
-                       : base (message, inner) {}\r
-               internal XmlSyntaxException(SerializationInfo info, StreamingContext context)
-                       : base(info, context) {}
-       }\r
-}\r
+
+namespace System.Security {
+
+       [Serializable]
+#if NET_2_0
+       public sealed class XmlSyntaxException : SystemException, _Exception {
+#else
+       public sealed class XmlSyntaxException : SystemException {
+#endif
+               // Constructors
+               public XmlSyntaxException ()
+               {
+               }
+
+               public XmlSyntaxException (int lineNumber)
+                       : base (String.Format (Locale.GetText ("Invalid syntax on line {0}."), lineNumber))
+               {
+               }
+
+               public XmlSyntaxException (int lineNumber, string message)
+                       : base (String.Format (Locale.GetText ("Invalid syntax on line {0} - {1}."), lineNumber, message))
+               {
+               }
+
+               public XmlSyntaxException (string message) 
+                       : base (message)
+               {
+               }
+
+               public XmlSyntaxException (string message, Exception inner) 
+                       : base (message, inner) 
+               {
+               }
+
+               internal XmlSyntaxException (SerializationInfo info, StreamingContext context)
+                       : base (info, context)
+               {
+               }
+       }
+}