Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Security / January 2006

Tip: Looking for answers? Try searching our database.

Limiting File IO

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Spike - 04 Jan 2006 19:10 GMT
How can i limit the access to file IO?
Im using C#, the code is executing on the local machine

i can enable access to file IO with:
PermissionSet ssc = new PermissionSet(null);
ssc.AddPermission(new
SecurityPermission(SecurityPermissionFlag.Execution));
ssc.AddPermission(new FileIOPermission(PermissionState.Unrestricted));

i can disable it by not setting it or setting it to:
ssc.AddPermission(new FileIOPermission(PermissionState.None));

but i would prefer a middleground, alow it only to read for example and
perhaps limit it to a certin directory.

i have found that FileIOPermission has the overload:
FileIOPermission(System.Security.Permissions.FileIOPermissionAccess
access, string path)

this would apear to be what im looking for, as the
FileIOPermissionAccess value can be read and i would assume the string
would be the path its allowed to read from...

however when i try to set this i get:
Request for the permission of type
'System.Security.Permissions.FileIOPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed.

this is using:
ssc.AddPermission(new FileIOPermission( FileIOPermissionAccess.Read,
Application.StartupPath + "\\Data\\"));

i dnt see why this request is being refused as if i set it to
Unrestricted it gets granted...
unless im misunderstanding the purpose of this method?

any ideas?
Nicole Calinoiu - 05 Jan 2006 12:34 GMT
How are you using the generated permission set, and what is the code
attempting to do when the security exception is thrown?  (A relevant code
extract would probably be helpful here.)

> How can i limit the access to file IO?
> Im using C#, the code is executing on the local machine
[quoted text clipped - 34 lines]
>
> any ideas?
Spike - 05 Jan 2006 15:17 GMT
Im using the security permissions to construct an appdomain

AppDomainSetup domaininfo = new AppDomainSetup();
domaininfo.ApplicationBase = Application.StartupPath;

sandDom = AppDomain.CreateDomain("SandboxDomain", new
System.Security.Policy.Evidence(), domaininfo, ssc, null);

i then go on to create a class factory

SandboxFactory factory =
(SandboxFactory)sandDom.CreateInstance("myAssembly",
"Sandbox.SandboxFactory").Unwrap();

and then to create an instance of the class

object[] constructArgs = null;
mySandbox = factory.Create("SandAssembly.dll", "plugin.Test",
constructArgs);

it fails on this line... however the constructor for the Test class
does not use FileIO
Nicole Calinoiu - 05 Jan 2006 15:20 GMT
Could you please provide the full exception details (including call stack
listing) as returned by the exception's ToString method?

> Im using the security permissions to construct an appdomain
>
[quoted text clipped - 18 lines]
> it fails on this line... however the constructor for the Test class
> does not use FileIO
Spike - 05 Jan 2006 15:50 GMT
wow i never knew the ToString method method returned sooo much extra
information
using the information i found it wanted PathDiscovery... i had just
assumed that alowing it access to file contents allowed it access to
pathdiscovery as well.

added path discovery and all is well, thanks for your help

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.