Forráskód Böngészése

2005-03-24 Sebastien Pouliot <[email protected]>

	* IsolatedStorageFile.cs: Added an assert for unrestricted file access
	to the class. This is "ok" as the user cannot control the base path 
	for isolated storage but will be updated to be more "precise" when
	imperative assert are supported in the runtime.
	* IsolatedStorageFileStream.cs: Changed constructors so the assert
	for unrestricted file access is limited to constructors (not the whole
	class). Added LinkDemand for UnmanagedCode to get Handle and 
	SafeFileHandle (2.0) properties.


svn path=/trunk/mcs/; revision=42215
Sebastien Pouliot 21 éve
szülő
commit
028952d395

+ 11 - 0
mcs/class/corlib/System.IO.IsolatedStorage/ChangeLog

@@ -1,3 +1,14 @@
+2005-03-24  Sebastien Pouliot  <[email protected]>
+
+	* IsolatedStorageFile.cs: Added an assert for unrestricted file access
+	to the class. This is "ok" as the user cannot control the base path 
+	for isolated storage but will be updated to be more "precise" when
+	imperative assert are supported in the runtime.
+	* IsolatedStorageFileStream.cs: Changed constructors so the assert
+	for unrestricted file access is limited to constructors (not the whole
+	class). Added LinkDemand for UnmanagedCode to get Handle and 
+	SafeFileHandle (2.0) properties.
+
 2005-03-17  Sebastien Pouliot  <[email protected]>
 
 	* IsolatedStorageScope.cs: Add missing BOOTSTRAP_NET_2_0 to new enum 

+ 4 - 0
mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorageFile.cs

@@ -43,6 +43,10 @@ namespace System.IO.IsolatedStorage {
 
 	// This is a terribly named class.  It doesn't actually represent a file as
 	// much as a directory
+
+
+	// FIXME: Further limit the assertion when imperative Assert is implemented
+	[FileIOPermission (SecurityAction.Assert, Unrestricted = true)]
 	public sealed class IsolatedStorageFile : IsolatedStorage, IDisposable {
 
 		public static IEnumerator GetEnumerator (IsolatedStorageScope scope)

+ 12 - 8
mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorageFileStream.cs

@@ -54,7 +54,7 @@ namespace System.IO.IsolatedStorage {
 				// i.e. the result would always be mscorlib.dll. So we need to do 
 				// a small stack walk to find who's calling the constructor
 
-				StackFrame sf = new StackFrame (2); // skip self and constructor
+				StackFrame sf = new StackFrame (3); // skip self and constructor
 				isf = IsolatedStorageFile.GetStore (IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly,
 					IsolatedStorageFile.GetDomainIdentityFromEvidence (AppDomain.CurrentDomain.Evidence), 
 					IsolatedStorageFile.GetAssemblyIdentityFromEvidence (sf.GetMethod ().ReflectedType.Assembly.Evidence));
@@ -81,42 +81,44 @@ namespace System.IO.IsolatedStorage {
 		}
 
 		public IsolatedStorageFileStream (string path, FileMode mode)
-			: base (CreateIsolatedPath (null, path), mode, (mode == FileMode.Append ? FileAccess.Write : FileAccess.ReadWrite), FileShare.Read, DefaultBufferSize, false, true)
+			: this (path, mode, (mode == FileMode.Append ? FileAccess.Write : FileAccess.ReadWrite), FileShare.Read, DefaultBufferSize, null)
 		{
 		}	
 
 		public IsolatedStorageFileStream (string path, FileMode mode, FileAccess access)
-			: base (CreateIsolatedPath (null, path), mode, access, access == FileAccess.Write ? FileShare.None : FileShare.Read, DefaultBufferSize, false, true)
+			: this (path, mode, access, access == FileAccess.Write ? FileShare.None : FileShare.Read, DefaultBufferSize, null)
 		{
 		}
 
 		public IsolatedStorageFileStream (string path, FileMode mode, FileAccess access, FileShare share)
-			: base (CreateIsolatedPath (null, path), mode, access, share, DefaultBufferSize, false, true)
+			: this (path, mode, access, share, DefaultBufferSize, null)
 		{
 		}
 
 		public IsolatedStorageFileStream (string path, FileMode mode, FileAccess access, FileShare share, int bufferSize)
-			: base (CreateIsolatedPath (null, path), mode, access, share, bufferSize, false, true)
+			: this (path, mode, access, share, bufferSize, null)
 		{
 		}
 
+		// FIXME: Further limit the assertion when imperative Assert is implemented
+		[FileIOPermission (SecurityAction.Assert, Unrestricted = true)]
 		public IsolatedStorageFileStream (string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, IsolatedStorageFile isf)
 			: base (CreateIsolatedPath (isf, path), mode, access, share, bufferSize, false, true)
 		{
 		}
 
 		public IsolatedStorageFileStream (string path, FileMode mode, FileAccess access, FileShare share, IsolatedStorageFile isf)
-			: base (CreateIsolatedPath (isf, path), mode, access, share, DefaultBufferSize, false, true)
+			: this (path, mode, access, share, DefaultBufferSize, isf)
 		{
 		}
 
 		public IsolatedStorageFileStream (string path, FileMode mode, FileAccess access, IsolatedStorageFile isf)
-			: base (CreateIsolatedPath (isf, path), mode, access, access == FileAccess.Write ? FileShare.None : FileShare.Read, DefaultBufferSize, false, true)
+			: this (path, mode, access, access == FileAccess.Write ? FileShare.None : FileShare.Read, DefaultBufferSize, isf)
 		{
 		}
 
 		public IsolatedStorageFileStream (string path, FileMode mode, IsolatedStorageFile isf)
-			: base (CreateIsolatedPath (isf, path), mode, (mode == FileMode.Append ? FileAccess.Write : FileAccess.ReadWrite), FileShare.Read, DefaultBufferSize, false, true)
+			: this (path, mode, (mode == FileMode.Append ? FileAccess.Write : FileAccess.ReadWrite), FileShare.Read, DefaultBufferSize, isf)
 		{
 		}
 
@@ -134,6 +136,7 @@ namespace System.IO.IsolatedStorage {
 
 #if NET_2_0
 		public override SafeFileHandle SafeFileHandle {
+			[SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
 			get {
 				throw new IsolatedStorageException (
 					Locale.GetText ("Information is restricted"));
@@ -143,6 +146,7 @@ namespace System.IO.IsolatedStorage {
 		[Obsolete ("Use SafeFileHandle - once available")]
 #endif
 		public override IntPtr Handle {
+			[SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
 			get {
 				throw new IsolatedStorageException (
 					Locale.GetText ("Information is restricted"));