Author: spouliot
Date: 2005-03-15 16:07:29 -0500 (Tue, 15 Mar 2005)
New Revision: 41856
Modified:
trunk/mcs/class/corlib/System.IO.IsolatedStorage/ChangeLog
trunk/mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorageFile.cs
trunk/mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorageFileStream.cs
Log:
2005-03-15 Sebastien Pouliot <[EMAIL PROTECTED]>
* IsolatedStorageFile.cs: Added CAS demands (imperative when possible)
for IsolatedStoragePermission. The security attributes for NET_2_0 are
commented until #73046 is fixed.
* IsolatedStorageFileStream.cs: Now use StackFrame(2) to find which
assembly is really calling the IsolatedStorageFileStream when no
default is supplied. Throw DirectoryNotFoundException when a directory
inside the isolated storage is missing.
Modified: trunk/mcs/class/corlib/System.IO.IsolatedStorage/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System.IO.IsolatedStorage/ChangeLog 2005-03-15
21:07:07 UTC (rev 41855)
+++ trunk/mcs/class/corlib/System.IO.IsolatedStorage/ChangeLog 2005-03-15
21:07:29 UTC (rev 41856)
@@ -1,3 +1,13 @@
+2005-03-15 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * IsolatedStorageFile.cs: Added CAS demands (imperative when possible)
+ for IsolatedStoragePermission. The security attributes for NET_2_0 are
+ commented until #73046 is fixed.
+ * IsolatedStorageFileStream.cs: Now use StackFrame(2) to find which
+ assembly is really calling the IsolatedStorageFileStream when no
+ default is supplied. Throw DirectoryNotFoundException when a directory
+ inside the isolated storage is missing.
+
2005-01-31 Sebastien Pouliot <[EMAIL PROTECTED]>
* IsolatedStorage.cs: Added checks to get identities.
Modified:
trunk/mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorageFile.cs
===================================================================
--- trunk/mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorageFile.cs
2005-03-15 21:07:07 UTC (rev 41855)
+++ trunk/mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorageFile.cs
2005-03-15 21:07:29 UTC (rev 41856)
@@ -47,6 +47,8 @@
public static IEnumerator GetEnumerator (IsolatedStorageScope
scope)
{
+ Demand (scope);
+
switch (scope) {
case IsolatedStorageScope.User:
case IsolatedStorageScope.User |
IsolatedStorageScope.Roaming:
@@ -66,6 +68,8 @@
Evidence domainEvidence, Type domainEvidenceType,
Evidence assemblyEvidence, Type assemblyEvidenceType)
{
+ Demand (scope);
+
bool domain = ((scope & IsolatedStorageScope.Domain) !=
0);
if (domain && (domainEvidence == null))
throw new ArgumentNullException
("domainEvidence");
@@ -103,6 +107,8 @@
public static IsolatedStorageFile GetStore
(IsolatedStorageScope scope, object domainIdentity, object assemblyIdentity)
{
+ Demand (scope);
+
if (((scope & IsolatedStorageScope.Domain) != 0) &&
(domainIdentity == null))
throw new ArgumentNullException
("domainIdentity");
@@ -118,6 +124,7 @@
public static IsolatedStorageFile GetStore
(IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType)
{
+ Demand (scope);
IsolatedStorageFile storageFile = new
IsolatedStorageFile (scope);
if ((scope & IsolatedStorageScope.Domain) != 0) {
storageFile._domainIdentity =
GetTypeFromEvidence (AppDomain.CurrentDomain.Evidence, domainEvidenceType);
@@ -131,6 +138,7 @@
#if NET_2_0
public static IsolatedStorageFile GetStore
(IsolatedStorageScope scope, object applicationIdentity)
{
+ Demand (scope);
if (applicationIdentity == null)
throw new ArgumentNullException
("applicationIdentity");
@@ -142,12 +150,15 @@
public static IsolatedStorageFile GetStore
(IsolatedStorageScope scope, Type applicationEvidenceType)
{
+ Demand (scope);
IsolatedStorageFile storageFile = new
IsolatedStorageFile (scope);
storageFile.InitStore (scope, applicationEvidenceType);
storageFile.PostInit ();
return storageFile;
}
+// waiting for fix to http://bugzilla.ximian.com/show_bug.cgi?id=73046
+// [IsolatedStorageFilePermission (SecurityAction.Demand,
UsageAllowed = IsolatedStorageContainment.ApplicationIsolationByMachine)]
public static IsolatedStorageFile GetMachineStoreForApplication
()
{
IsolatedStorageScope scope =
IsolatedStorageScope.Machine | IsolatedStorageScope.Application;
@@ -157,6 +168,8 @@
return storageFile;
}
+// waiting for fix to http://bugzilla.ximian.com/show_bug.cgi?id=73046
+// [IsolatedStorageFilePermission (SecurityAction.Demand,
UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByMachine)]
public static IsolatedStorageFile GetMachineStoreForAssembly ()
{
IsolatedStorageScope scope =
IsolatedStorageScope.Machine | IsolatedStorageScope.Assembly;
@@ -166,6 +179,8 @@
return storageFile;
}
+// waiting for fix to http://bugzilla.ximian.com/show_bug.cgi?id=73046
+// [IsolatedStorageFilePermission (SecurityAction.Demand,
UsageAllowed = IsolatedStorageContainment.DomainIsolationByMachine)]
public static IsolatedStorageFile GetMachineStoreForDomain ()
{
IsolatedStorageScope scope =
IsolatedStorageScope.Machine | IsolatedStorageScope.Domain |
IsolatedStorageScope.Assembly;
@@ -176,6 +191,8 @@
return storageFile;
}
+// waiting for fix to http://bugzilla.ximian.com/show_bug.cgi?id=73046
+// [IsolatedStorageFilePermission (SecurityAction.Demand,
UsageAllowed = IsolatedStorageContainment.ApplicationIsolationByUser)]
public static IsolatedStorageFile GetUserStoreForApplication ()
{
IsolatedStorageScope scope = IsolatedStorageScope.User
| IsolatedStorageScope.Application;
@@ -185,6 +202,7 @@
return storageFile;
}
#endif
+ [IsolatedStorageFilePermission (SecurityAction.Demand,
UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByUser)]
public static IsolatedStorageFile GetUserStoreForAssembly ()
{
IsolatedStorageScope scope = IsolatedStorageScope.User
| IsolatedStorageScope.Assembly;
@@ -194,6 +212,7 @@
return storageFile;
}
+ [IsolatedStorageFilePermission (SecurityAction.Demand,
UsageAllowed = IsolatedStorageContainment.DomainIsolationByUser)]
public static IsolatedStorageFile GetUserStoreForDomain ()
{
IsolatedStorageScope scope = IsolatedStorageScope.User
| IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly;
@@ -242,6 +261,45 @@
return Path.Combine (root, ".isolated-storage");
}
+ private static void Demand (IsolatedStorageScope scope)
+ {
+ if (SecurityManager.SecurityEnabled) {
+ IsolatedStorageFilePermission isfp = new
IsolatedStorageFilePermission (PermissionState.None);
+ isfp.UsageAllowed = ScopeToContainment (scope);
+ // TODO: quota
+ isfp.Demand ();
+ }
+ }
+
+ private static IsolatedStorageContainment ScopeToContainment
(IsolatedStorageScope scope)
+ {
+ switch (scope) {
+ case IsolatedStorageScope.Domain |
IsolatedStorageScope.Assembly | IsolatedStorageScope.User:
+ return
IsolatedStorageContainment.DomainIsolationByUser;
+ case IsolatedStorageScope.Assembly |
IsolatedStorageScope.User:
+ return
IsolatedStorageContainment.AssemblyIsolationByUser;
+ case IsolatedStorageScope.Domain |
IsolatedStorageScope.Assembly | IsolatedStorageScope.User |
IsolatedStorageScope.Roaming:
+ return
IsolatedStorageContainment.DomainIsolationByRoamingUser;
+ case IsolatedStorageScope.Assembly |
IsolatedStorageScope.User | IsolatedStorageScope.Roaming:
+ return
IsolatedStorageContainment.AssemblyIsolationByRoamingUser;
+#if NET_2_0
+ case IsolatedStorageScope.Application |
IsolatedStorageScope.User:
+ return
IsolatedStorageContainment.ApplicationIsolationByUser;
+ case IsolatedStorageScope.Domain |
IsolatedStorageScope.Assembly | IsolatedStorageScope.Machine:
+ return
IsolatedStorageContainment.DomainIsolationByMachine;
+ case IsolatedStorageScope.Assembly |
IsolatedStorageScope.Machine:
+ return
IsolatedStorageContainment.AssemblyIsolationByMachine;
+ case IsolatedStorageScope.Application |
IsolatedStorageScope.Machine:
+ return
IsolatedStorageContainment.ApplicationIsolationByMachine;
+ case IsolatedStorageScope.Application |
IsolatedStorageScope.User | IsolatedStorageScope.Roaming:
+ return
IsolatedStorageContainment.ApplicationIsolationByRoamingUser;
+#endif
+ default:
+ // unknown ?!?! then ask for maximum
(unrestricted)
+ return
IsolatedStorageContainment.UnrestrictedIsolatedStorage;
+ }
+ }
+
internal static ulong GetDirectorySize (DirectoryInfo di)
{
ulong size = 0;
@@ -331,7 +389,7 @@
public void CreateDirectory (string dir)
{
- directory.CreateSubdirectory (dir);
+ directory.CreateSubdirectory (dir);
}
public void DeleteDirectory (string dir)
@@ -405,7 +463,7 @@
return null;
}
- private static object GetAssemblyIdentityFromEvidence (Evidence
e)
+ internal static object GetAssemblyIdentityFromEvidence
(Evidence e)
{
// we prefer...
// a. a Publisher evidence
@@ -420,7 +478,7 @@
return GetTypeFromEvidence (e, typeof (Url));
}
- private static object GetDomainIdentityFromEvidence (Evidence e)
+ internal static object GetDomainIdentityFromEvidence (Evidence
e)
{
// we prefer...
// a. a ApplicationDirectory evidence
Modified:
trunk/mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorageFileStream.cs
===================================================================
---
trunk/mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorageFileStream.cs
2005-03-15 21:07:07 UTC (rev 41855)
+++
trunk/mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorageFileStream.cs
2005-03-15 21:07:29 UTC (rev 41856)
@@ -28,8 +28,11 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
+using System.Diagnostics;
using System.Globalization;
using System.Reflection;
+using System.Security;
+using System.Security.Permissions;
#if NET_2_0
using Microsoft.Win32.SafeHandles;
@@ -39,21 +42,38 @@
public class IsolatedStorageFileStream : FileStream {
+ [ReflectionPermission (SecurityAction.Assert, TypeInformation =
true)]
private static string CreateIsolatedPath (IsolatedStorageFile
isf, string path)
{
if (path == null)
throw new ArgumentNullException ("path");
- if (isf == null)
- isf = IsolatedStorageFile.GetUserStoreForDomain
();
+ if (isf == null) {
+ // we can't call GetUserStoreForDomain here
because it depends on
+ // Assembly.GetCallingAssembly (), which would
be our constructor,
+ // 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
- string file = Path.Combine (isf.Root, path);
+ StackFrame sf = new StackFrame (2); // 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));
+ }
- // Ensure that the file can be created.
- FileInfo fi = new FileInfo (file);
+ // ensure that the _root_ isolated storage can be (and
is) created.
+ FileInfo fi = new FileInfo (isf.Root);
if (!fi.Directory.Exists)
fi.Directory.Create ();
+ // other directories (provided by 'path') must already
exists
+ string file = Path.Combine (isf.Root, path);
+ fi = new FileInfo (file);
+ if (!fi.Directory.Exists) {
+ // don't leak the path information for isolated
storage
+ string msg = Locale.GetText ("Could not find a
part of the path \"{0}\".");
+ throw new DirectoryNotFoundException
(String.Format (msg, path));
+ }
+
// FIXME: this is probably a good place to Assert our
security
// needs (once Mono supports imperative security stack
modifiers)
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches