Author: spouliot
Date: 2005-03-24 09:12:01 -0500 (Thu, 24 Mar 2005)
New Revision: 42212

Modified:
   trunk/mcs/class/corlib/System.IO/ChangeLog
   trunk/mcs/class/corlib/System.IO/Directory.cs
   trunk/mcs/class/corlib/System.IO/FileStream.cs
   trunk/mcs/class/corlib/System.IO/FileSystemInfo.cs
   trunk/mcs/class/corlib/System.IO/Path.cs
Log:
2005-03-24  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * Directory.cs: Added a Demand for Read/Write when creating a new 
        directory.
        * FileSystemInfo.cs: Added an InheritanceDemand for Unrestricted on 
        the class.
        * Path.cs: Added a Demand for PathDiscovery in GetFullPath method.
        Added an Assert for unrestricted file access to GetTempFilename as
        the method must create the (zero-length) file and can be called from
        partially trusted code. Added a Demand for unrestricted environment
        access to GetTempPath method.
        * FileStream.cs: Added a Demand for UnmanagedCode for all constructors
        accepting a file handle. Added LinkDemand and InheritanceDemand for 
        UnmanagedCode to get Handle and SafeFileHandle (2.0) properties.



Modified: trunk/mcs/class/corlib/System.IO/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System.IO/ChangeLog  2005-03-24 13:55:59 UTC (rev 
42211)
+++ trunk/mcs/class/corlib/System.IO/ChangeLog  2005-03-24 14:12:01 UTC (rev 
42212)
@@ -1,3 +1,18 @@
+2005-03-24  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * Directory.cs: Added a Demand for Read/Write when creating a new 
+       directory.
+       * FileSystemInfo.cs: Added an InheritanceDemand for Unrestricted on 
+       the class.
+       * Path.cs: Added a Demand for PathDiscovery in GetFullPath method.
+       Added an Assert for unrestricted file access to GetTempFilename as
+       the method must create the (zero-length) file and can be called from
+       partially trusted code. Added a Demand for unrestricted environment
+       access to GetTempPath method.
+       * FileStream.cs: Added a Demand for UnmanagedCode for all constructors
+       accepting a file handle. Added LinkDemand and InheritanceDemand for 
+       UnmanagedCode to get Handle and SafeFileHandle (2.0) properties.
+
 2005-03-16  Lluis Sanchez Gual  <[EMAIL PROTECTED]>
 
        * BinaryReader.cs, BinaryWriter.cs: Read/write dobules, floats and

Modified: trunk/mcs/class/corlib/System.IO/Directory.cs
===================================================================
--- trunk/mcs/class/corlib/System.IO/Directory.cs       2005-03-24 13:55:59 UTC 
(rev 42211)
+++ trunk/mcs/class/corlib/System.IO/Directory.cs       2005-03-24 14:12:01 UTC 
(rev 42212)
@@ -38,7 +38,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System;
 using System.Collections;
 using System.Security;
 using System.Security.Permissions;
@@ -83,6 +82,10 @@
 
                static DirectoryInfo CreateDirectoriesInternal (string path)
                {
+                       if (SecurityManager.SecurityEnabled) {
+                               new FileIOPermission 
(FileIOPermissionAccess.Read | FileIOPermissionAccess.Write, path).Demand ();
+                       }
+
                        DirectoryInfo info = new DirectoryInfo (path);
                        if (info.Parent != null && !info.Parent.Exists)
                                 info.Parent.Create ();

Modified: trunk/mcs/class/corlib/System.IO/FileStream.cs
===================================================================
--- trunk/mcs/class/corlib/System.IO/FileStream.cs      2005-03-24 13:55:59 UTC 
(rev 42211)
+++ trunk/mcs/class/corlib/System.IO/FileStream.cs      2005-03-24 14:12:01 UTC 
(rev 42212)
@@ -29,12 +29,12 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System;
 using System.Collections;
 using System.Globalization;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Runtime.Remoting.Messaging;
+using System.Security.Permissions;
 using System.Threading;
 
 #if NET_2_0
@@ -59,6 +59,7 @@
                public FileStream (IntPtr handle, FileAccess access, bool 
ownsHandle, int bufferSize, bool isAsync)
                        : this (handle, access, ownsHandle, bufferSize, 
isAsync, false) {}
 
+               [SecurityPermission (SecurityAction.Demand, UnmanagedCode = 
true)]
                internal FileStream (IntPtr handle, FileAccess access, bool 
ownsHandle, int bufferSize, bool isAsync, bool noBuffering)
                {
                        this.handle = MonoIO.InvalidHandle;
@@ -326,6 +327,8 @@
                }
 
                public virtual IntPtr Handle {
+                       [SecurityPermission (SecurityAction.LinkDemand, 
UnmanagedCode = true)]
+                       [SecurityPermission (SecurityAction.InheritanceDemand, 
UnmanagedCode = true)]
                        get {
                                return handle;
                        }
@@ -333,6 +336,8 @@
 
 #if NET_2_0
                public virtual SafeFileHandle SafeFileHandle {
+                       [SecurityPermission (SecurityAction.LinkDemand, 
UnmanagedCode = true)]
+                       [SecurityPermission (SecurityAction.InheritanceDemand, 
UnmanagedCode = true)]
                        get { throw new NotImplementedException (); }
                }
 #endif

Modified: trunk/mcs/class/corlib/System.IO/FileSystemInfo.cs
===================================================================
--- trunk/mcs/class/corlib/System.IO/FileSystemInfo.cs  2005-03-24 13:55:59 UTC 
(rev 42211)
+++ trunk/mcs/class/corlib/System.IO/FileSystemInfo.cs  2005-03-24 14:12:01 UTC 
(rev 42212)
@@ -11,7 +11,7 @@
 
//------------------------------------------------------------------------------
 
 //
-// Copyright (C) 2004 Novell, Inc (http://www.novell.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
@@ -33,13 +33,14 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System;
 using System.Runtime.InteropServices;
 using System.Runtime.Serialization;
+using System.Security.Permissions;
 
 namespace System.IO {
        
        [Serializable]
+       [FileIOPermission (SecurityAction.InheritanceDemand, Unrestricted = 
true)]
        public abstract class FileSystemInfo : MarshalByRefObject, 
ISerializable {
                #region Implementation of ISerializable
 

Modified: trunk/mcs/class/corlib/System.IO/Path.cs
===================================================================
--- trunk/mcs/class/corlib/System.IO/Path.cs    2005-03-24 13:55:59 UTC (rev 
42211)
+++ trunk/mcs/class/corlib/System.IO/Path.cs    2005-03-24 14:12:01 UTC (rev 
42212)
@@ -15,7 +15,7 @@
 
//------------------------------------------------------------------------------
 
 //
-// Copyright (C) 2004 Novell, Inc (http://www.novell.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
@@ -37,8 +37,9 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System;
 using System.Runtime.CompilerServices;
+using System.Security;
+using System.Security.Permissions;
 
 namespace System.IO
 {
@@ -192,6 +193,16 @@
 
                public static string GetFullPath (string path)
                {
+                       string fullpath = InsecureGetFullPath (path);
+                       if (SecurityManager.SecurityEnabled) {
+                               new FileIOPermission 
(FileIOPermissionAccess.PathDiscovery, fullpath).Demand ();
+                       }
+                       return fullpath;
+               }
+
+               // insecure - do not call directly
+               internal static string InsecureGetFullPath (string path)
+               {
                        if (path == null)
                                throw (new ArgumentNullException (
                                        "path",
@@ -205,11 +216,11 @@
                                IsDsc (path [1])) {
                                if (path.Length == 2 || path.IndexOf (path [0], 
2) < 0)
                                        throw new ArgumentException ("UNC pass 
should be of the form \\\\server\\share.");
-                               else
-                                       if (path [0] == DirectorySeparatorChar)
-                                               return path; // UNC
-                                       else
-                                               return path.Replace 
(AltDirectorySeparatorChar, DirectorySeparatorChar);
+
+                               if (path [0] != DirectorySeparatorChar)
+                                       path = path.Replace 
(AltDirectorySeparatorChar, DirectorySeparatorChar);
+
+                               return path;
                        }
 
                        if (!IsPathRooted (path))
@@ -275,6 +286,8 @@
                        }
                }
 
+               // FIXME: Further limit the assertion when imperative Assert is 
implemented
+               [FileIOPermission (SecurityAction.Assert, Unrestricted = true)]
                public static string GetTempFileName ()
                {
                        FileStream f = null;
@@ -290,17 +303,20 @@
 
                                try {
                                        f = new FileStream (path, 
FileMode.CreateNew);
-                               } catch {
                                }
+                               catch (SecurityException) {
+                                       // avoid an endless loop
+                                       throw;
+                               }
+                               catch {
+                               }
                        } while (f == null);
                        
                        f.Close();
                        return path;
                }
 
-               /// <summary>
-               /// Returns the path of the current systems temp directory
-               /// </summary>
+               [EnvironmentPermission (SecurityAction.Demand, Unrestricted = 
true)]
                public static string GetTempPath ()
                {
                        string p = get_temp_path ();

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to