[bcl] Remove the ValueAdd and InetAccess NUnit categories (#2212)
[mono.git] / mcs / class / corlib / System.Security.Permissions / FileIOPermission.cs
index 72f7566cc66c1a241fe54e64399d507aa74f91be..c08313b278fd1ee0bd9a4425621eb3014f573494 100644 (file)
@@ -1,11 +1,11 @@
-// \r
-// System.Security.Permissions.FileIOPermission.cs \r
-//\r
+// 
+// System.Security.Permissions.FileIOPermission.cs 
+//
 // Authors:
-//     Nick Drochak, ndrochak@gol.com\r
+//     Nick Drochak, ndrochak@gol.com
 //     Sebastien Pouliot  <sebastien@ximian.com>
 //
-// Copyright (C) 2001 Nick Drochak, All Rights Reserved\r
+// Copyright (C) 2001 Nick Drochak, All Rights Reserved
 // Copyright (C) 2004-2005 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.Collections;\r
-using System.IO;\r
-using System.Text;\r
 
-#if NET_2_0
+using System.Collections;
+using System.IO;
+using System.Text;
+
 using System.Runtime.InteropServices;
 using System.Security.AccessControl;
-#endif
-\r
-namespace System.Security.Permissions {\r
-\r
-#if NET_2_0
+
+namespace System.Security.Permissions {
+
        [ComVisible (true)]
-#endif
-       [Serializable]\r
-       public sealed class FileIOPermission\r
-                : CodeAccessPermission, IBuiltInPermission, IUnrestrictedPermission {\r
+       [Serializable]
+       public sealed class FileIOPermission
+                : CodeAccessPermission, IBuiltInPermission, IUnrestrictedPermission {
 
                private const int version = 1;
 
-#if NET_2_0
                private static char[] BadPathNameCharacters;
                private static char[] BadFileNameCharacters;
 
@@ -58,54 +53,43 @@ namespace System.Security.Permissions {
                        BadPathNameCharacters = Path.GetInvalidPathChars ();
                        BadFileNameCharacters = Path.GetInvalidFileNameChars ();
                }
-#else
-               private static char[] m_badCharacters;
 
-               static FileIOPermission ()
-               {
-                       // note: deprecated in 2.0 as InvalidPathChars is an array (i.e. items can be
-                       // modified). Anyway we keep our own copy, which should be called by the 
-                       // security manager before anyone has the chance to change it.
-                       m_badCharacters = (char[]) Path.InvalidPathChars.Clone ();
-               }
-#endif\r
-
-               private bool m_Unrestricted = false;\r
-               private FileIOPermissionAccess m_AllFilesAccess = FileIOPermissionAccess.NoAccess;\r
-               private FileIOPermissionAccess m_AllLocalFilesAccess = FileIOPermissionAccess.NoAccess;\r
+               private bool m_Unrestricted = false;
+               private FileIOPermissionAccess m_AllFilesAccess = FileIOPermissionAccess.NoAccess;
+               private FileIOPermissionAccess m_AllLocalFilesAccess = FileIOPermissionAccess.NoAccess;
                private ArrayList readList;
                private ArrayList writeList;
                private ArrayList appendList;
                private ArrayList pathList;
 
                public FileIOPermission (PermissionState state)
-               {\r
+               {
                        if (CheckPermissionState (state, true) == PermissionState.Unrestricted) {
-                               m_Unrestricted = true;\r
-                               m_AllFilesAccess = FileIOPermissionAccess.AllAccess;\r
-                               m_AllLocalFilesAccess = FileIOPermissionAccess.AllAccess;\r
+                               m_Unrestricted = true;
+                               m_AllFilesAccess = FileIOPermissionAccess.AllAccess;
+                               m_AllLocalFilesAccess = FileIOPermissionAccess.AllAccess;
                        }
-                       CreateLists ();\r
-               }\r
-\r
+                       CreateLists ();
+               }
+
                public FileIOPermission (FileIOPermissionAccess access, string path)
                {
                        if (path == null)
                                throw new ArgumentNullException ("path");
 
                        CreateLists ();
-                       // access and path will be validated in AddPathList\r
-                       AddPathList (access, path);\r
-               }\r
-\r
+                       // access and path will be validated in AddPathList
+                       AddPathList (access, path);
+               }
+
                public FileIOPermission (FileIOPermissionAccess access, string[] pathList)
-               {\r
+               {
                        if (pathList == null)
                                throw new ArgumentNullException ("pathList");
 
-                       CreateLists ();\r
-                       // access and path will be validated in AddPathList\r
-                       AddPathList (access, pathList);\r
+                       CreateLists ();
+                       // access and path will be validated in AddPathList
+                       AddPathList (access, pathList);
                }
 
                internal void CreateLists ()
@@ -116,56 +100,58 @@ namespace System.Security.Permissions {
                        pathList = new ArrayList ();
                }
 
-#if NET_2_0
                [MonoTODO ("(2.0) Access Control isn't implemented")]
                public FileIOPermission (FileIOPermissionAccess access, AccessControlActions control, string path)
                {
                        throw new NotImplementedException ();
-               }\r
-\r
+               }
+
                [MonoTODO ("(2.0) Access Control isn't implemented")]
                public FileIOPermission (FileIOPermissionAccess access, AccessControlActions control, string[] pathList)
-               {\r
+               {
                        throw new NotImplementedException ();
                }
-#endif\r
-\r
-               public FileIOPermissionAccess AllFiles {\r
-                       get { return m_AllFilesAccess; } \r
-                       set {\r
-                               // if we are already set to unrestricted, don't change this property\r
-                               if (!m_Unrestricted){\r
-                                       m_AllFilesAccess = value;\r
-                               }\r
-                       }\r
-               }\r
-\r
-               public FileIOPermissionAccess AllLocalFiles {\r
-                       get { return m_AllLocalFilesAccess; } \r
-                       set {\r
-                               // if we are already set to unrestricted, don't change this property\r
-                               if (!m_Unrestricted){\r
-                                       m_AllLocalFilesAccess = value;\r
-                               }\r
-                       }\r
-               }\r
-\r
+
+               internal FileIOPermission (FileIOPermissionAccess access, string[] pathList, bool checkForDuplicates, bool needFullPath)
+               {
+               }
+
+               public FileIOPermissionAccess AllFiles {
+                       get { return m_AllFilesAccess; } 
+                       set {
+                               // if we are already set to unrestricted, don't change this property
+                               if (!m_Unrestricted){
+                                       m_AllFilesAccess = value;
+                               }
+                       }
+               }
+
+               public FileIOPermissionAccess AllLocalFiles {
+                       get { return m_AllLocalFilesAccess; } 
+                       set {
+                               // if we are already set to unrestricted, don't change this property
+                               if (!m_Unrestricted){
+                                       m_AllLocalFilesAccess = value;
+                               }
+                       }
+               }
+
                public void AddPathList (FileIOPermissionAccess access, string path)
                {
                         if ((FileIOPermissionAccess.AllAccess & access) != access)
                                ThrowInvalidFlag (access, true);
-                       ThrowIfInvalidPath (path);\r
-                       AddPathInternal (access, path);\r
-               }\r
-\r
+                       ThrowIfInvalidPath (path);
+                       AddPathInternal (access, path);
+               }
+
                public void AddPathList (FileIOPermissionAccess access, string[] pathList)
-               {\r
+               {
                         if ((FileIOPermissionAccess.AllAccess & access) != access)
                                ThrowInvalidFlag (access, true);
-                       ThrowIfInvalidPath (pathList);\r
+                       ThrowIfInvalidPath (pathList);
                        foreach (string path in pathList) {
-                               AddPathInternal (access, path);\r
-                       }\r
+                               AddPathInternal (access, path);
+                       }
                }
 
                // internal to avoid duplicate checks
@@ -185,9 +171,9 @@ namespace System.Security.Permissions {
                }
 
                public override IPermission Copy ()
-               {\r
-                       if (m_Unrestricted)\r
-                               return new FileIOPermission (PermissionState.Unrestricted);\r
+               {
+                       if (m_Unrestricted)
+                               return new FileIOPermission (PermissionState.Unrestricted);
 
                        FileIOPermission copy = new FileIOPermission (PermissionState.None);
                        copy.readList = (ArrayList) readList.Clone ();
@@ -196,47 +182,47 @@ namespace System.Security.Permissions {
                        copy.pathList = (ArrayList) pathList.Clone ();
                        copy.m_AllFilesAccess = m_AllFilesAccess;
                        copy.m_AllLocalFilesAccess = m_AllLocalFilesAccess;
-                       return copy;\r
-               }\r
-\r
+                       return copy;
+               }
+
                public override void FromXml (SecurityElement esd)
-               {\r
+               {
                        // General validation in CodeAccessPermission
                        CheckSecurityElement (esd, "esd", version, version);
                        // Note: we do not (yet) care about the return value 
                        // as we only accept version 1 (min/max values)
 
-                       if (IsUnrestricted (esd)) {\r
-                               m_Unrestricted = true;\r
-                       }\r
-                       else{\r
-                               m_Unrestricted = false;\r
-                               string fileList = esd.Attribute ("Read");\r
-                               string[] files;\r
-                               if (fileList != null){\r
-                                       files = fileList.Split (';');\r
-                                       AddPathList (FileIOPermissionAccess.Read, files);\r
-                               }\r
-                               fileList = esd.Attribute ("Write");\r
-                               if (fileList != null){\r
-                                       files = fileList.Split (';');\r
-                                       AddPathList (FileIOPermissionAccess.Write, files);\r
-                               }\r
-                               fileList = esd.Attribute ("Append");\r
-                               if (fileList != null){\r
-                                       files = fileList.Split (';');\r
-                                       AddPathList (FileIOPermissionAccess.Append, files);\r
-                               }\r
-                               fileList = esd.Attribute ("PathDiscovery");\r
-                               if (fileList != null){\r
-                                       files = fileList.Split (';');\r
-                                       AddPathList (FileIOPermissionAccess.PathDiscovery, files);\r
-                               }\r
-                       }\r
-               }\r
-\r
+                       if (IsUnrestricted (esd)) {
+                               m_Unrestricted = true;
+                       }
+                       else{
+                               m_Unrestricted = false;
+                               string fileList = esd.Attribute ("Read");
+                               string[] files;
+                               if (fileList != null){
+                                       files = fileList.Split (';');
+                                       AddPathList (FileIOPermissionAccess.Read, files);
+                               }
+                               fileList = esd.Attribute ("Write");
+                               if (fileList != null){
+                                       files = fileList.Split (';');
+                                       AddPathList (FileIOPermissionAccess.Write, files);
+                               }
+                               fileList = esd.Attribute ("Append");
+                               if (fileList != null){
+                                       files = fileList.Split (';');
+                                       AddPathList (FileIOPermissionAccess.Append, files);
+                               }
+                               fileList = esd.Attribute ("PathDiscovery");
+                               if (fileList != null){
+                                       files = fileList.Split (';');
+                                       AddPathList (FileIOPermissionAccess.PathDiscovery, files);
+                               }
+                       }
+               }
+
                public string[] GetPathList (FileIOPermissionAccess access)
-               {\r
+               {
                         if ((FileIOPermissionAccess.AllAccess & access) != access)
                                ThrowInvalidFlag (access, true);
 
@@ -260,9 +246,9 @@ namespace System.Security.Permissions {
                                        ThrowInvalidFlag (access, false);
                                        break;
                        }
-                       return (result.Count > 0) ? (string[]) result.ToArray (typeof (string)) : null;\r
-               }\r
-\r
+                       return (result.Count > 0) ? (string[]) result.ToArray (typeof (string)) : null;
+               }
+
                public override IPermission Intersect (IPermission target)
                {
                        FileIOPermission fiop = Cast (target);
@@ -284,8 +270,8 @@ namespace System.Security.Permissions {
                        IntersectKeys (pathList, fiop.pathList, result.pathList);
 
                        return (result.IsEmpty () ? null : result);
-               }\r
-\r
+               }
+
                public override bool IsSubsetOf (IPermission target)
                {
                        FileIOPermission fiop = Cast (target);
@@ -314,63 +300,63 @@ namespace System.Security.Permissions {
                                return false;
 
                        return true;
-               }\r
+               }
 
                public bool IsUnrestricted ()
-               {\r
-                       return m_Unrestricted;\r
-               }\r
-\r
+               {
+                       return m_Unrestricted;
+               }
+
                public void SetPathList (FileIOPermissionAccess access, string path)
                {
                         if ((FileIOPermissionAccess.AllAccess & access) != access)
                                ThrowInvalidFlag (access, true);
-                       ThrowIfInvalidPath (path);\r
+                       ThrowIfInvalidPath (path);
                        // note: throw before clearing the actual list
-                       Clear (access);\r
-                       AddPathInternal (access, path);\r
-               }\r
-               \r
+                       Clear (access);
+                       AddPathInternal (access, path);
+               }
+               
                public void SetPathList (FileIOPermissionAccess access, string[] pathList)
-               {\r
+               {
                         if ((FileIOPermissionAccess.AllAccess & access) != access)
                                ThrowInvalidFlag (access, true);
-                       ThrowIfInvalidPath (pathList);\r
+                       ThrowIfInvalidPath (pathList);
                        // note: throw before clearing the actual list
                        Clear (access);
-                       foreach (string path in pathList)\r
-                               AddPathInternal (access, path);\r
+                       foreach (string path in pathList)
+                               AddPathInternal (access, path);
                }
 
                public override SecurityElement ToXml ()
-               {\r
+               {
                        SecurityElement se = Element (1);
-                       if (m_Unrestricted) {\r
-                               se.AddAttribute ("Unrestricted", "true");\r
-                       }\r
-                       else {\r
-                               string[] paths = GetPathList (FileIOPermissionAccess.Append);\r
-                               if (null != paths && paths.Length > 0) {\r
-                                       se.AddAttribute ("Append", String.Join (";", paths));\r
-                               }\r
-                               paths = GetPathList (FileIOPermissionAccess.Read);\r
-                               if (null != paths && paths.Length > 0) {\r
-                                       se.AddAttribute ("Read", String.Join (";", paths));\r
-                               }\r
-                               paths = GetPathList (FileIOPermissionAccess.Write);\r
-                               if (null != paths && paths.Length > 0) {\r
-                                       se.AddAttribute ("Write", String.Join  (";", paths));\r
-                               }\r
-                               paths = GetPathList (FileIOPermissionAccess.PathDiscovery);\r
-                               if (null != paths && paths.Length > 0) {\r
-                                       se.AddAttribute ("PathDiscovery", String.Join  (";", paths));\r
-                               }\r
-                       }\r
-                       return se;\r
-               }\r
-\r
+                       if (m_Unrestricted) {
+                               se.AddAttribute ("Unrestricted", "true");
+                       }
+                       else {
+                               string[] paths = GetPathList (FileIOPermissionAccess.Append);
+                               if (null != paths && paths.Length > 0) {
+                                       se.AddAttribute ("Append", String.Join (";", paths));
+                               }
+                               paths = GetPathList (FileIOPermissionAccess.Read);
+                               if (null != paths && paths.Length > 0) {
+                                       se.AddAttribute ("Read", String.Join (";", paths));
+                               }
+                               paths = GetPathList (FileIOPermissionAccess.Write);
+                               if (null != paths && paths.Length > 0) {
+                                       se.AddAttribute ("Write", String.Join  (";", paths));
+                               }
+                               paths = GetPathList (FileIOPermissionAccess.PathDiscovery);
+                               if (null != paths && paths.Length > 0) {
+                                       se.AddAttribute ("PathDiscovery", String.Join  (";", paths));
+                               }
+                       }
+                       return se;
+               }
+
                public override IPermission Union (IPermission other)
-               {\r
+               {
                        FileIOPermission fiop = Cast (other);
                        if (fiop == null)
                                return Copy ();
@@ -402,9 +388,8 @@ namespace System.Security.Permissions {
                                UnionKeys (result.pathList, paths);
                        
                        return result;
-               }\r
-\r
-#if NET_2_0
+               }
+
                [MonoTODO ("(2.0)")]
                [ComVisible (false)]
                public override bool Equals (object obj)
@@ -418,11 +403,10 @@ namespace System.Security.Permissions {
                {
                        return base.GetHashCode ();
                }
-#endif
 
-               // IBuiltInPermission\r
-               int IBuiltInPermission.GetTokenIndex ()\r
-               {\r
+               // IBuiltInPermission
+               int IBuiltInPermission.GetTokenIndex ()
+               {
                        return (int) BuiltInToken.FileIO;
                }
 
@@ -459,31 +443,24 @@ namespace System.Security.Permissions {
 
                internal static void ThrowIfInvalidPath (string path)
                {
-#if NET_2_0
                        string dir = Path.GetDirectoryName (path);
                        if ((dir != null) && (dir.LastIndexOfAny (BadPathNameCharacters) >= 0)) {
-                               string msg = String.Format (Locale.GetText ("Invalid path characters in path: '{0}'"), path);\r
-                               throw new ArgumentException (msg, "path");\r
+                               string msg = String.Format (Locale.GetText ("Invalid path characters in path: '{0}'"), path);
+                               throw new ArgumentException (msg, "path");
                        }
-\r
+
                        string fname = Path.GetFileName (path);
                        if ((fname != null) && (fname.LastIndexOfAny (BadFileNameCharacters) >= 0)) {
-                               string msg = String.Format (Locale.GetText ("Invalid filename characters in path: '{0}'"), path);\r
-                               throw new ArgumentException (msg, "path");\r
-                       }
-#else
-                       if (path.LastIndexOfAny (m_badCharacters) >= 0) {\r
-                               string msg = String.Format (Locale.GetText ("Invalid characters in path: '{0}'"), path);\r
-                               throw new ArgumentException (msg, "path");\r
+                               string msg = String.Format (Locale.GetText ("Invalid filename characters in path: '{0}'"), path);
+                               throw new ArgumentException (msg, "path");
                        }
-#endif\r
-                       // LAMESPEC: docs don't say it must be a rooted path, but the MS implementation enforces it, so we will too.\r
+                       // LAMESPEC: docs don't say it must be a rooted path, but the MS implementation enforces it, so we will too.
                        if (!Path.IsPathRooted (path)) {
                                string msg = Locale.GetText ("Absolute path information is required.");
-                               throw new ArgumentException (msg, "path");\r
+                               throw new ArgumentException (msg, "path");
                        }
                }
-\r
+
                internal static void ThrowIfInvalidPath (string[] paths)
                {
                        foreach (string path in paths)
@@ -501,7 +478,7 @@ namespace System.Security.Permissions {
                                appendList.Clear ();
                        if ((access & FileIOPermissionAccess.PathDiscovery) == FileIOPermissionAccess.PathDiscovery)
                                pathList.Clear ();
-               }\r
+               }
 
                // note: all path in IList are already "full paths"
                internal static bool KeyIsSubsetOf (IList local, IList target)
@@ -563,5 +540,5 @@ namespace System.Security.Permissions {
                                }
                        }
                }
-       }\r
-}\r
+       }
+}