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 / .NET SDK / June 2006

Tip: Looking for answers? Try searching our database.

is file rooted from ...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David Thielen - 26 May 2006 05:17 GMT
Hi;

I want to make sure all files pulled from my server app (ASP.NET 2.0) come
from one of 3 directories -
"c:\inetpub\wwwroot\myserver\files;c:\special;\\server\share\dir" Is there a
call in .NET to determine if a file has the same root as say c:\special? Or
even better, I can give it "dir1;dir2;...".

Otherwise it seems to me the best bet is to add a \ at the end of each root
and see if the filename starts with it. And do a ToLowerCase() on both and
hop I don't hit a case where it's a unix share where the case is different.

Any suggestions?

Signature

thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Steven Cheng[MSFT] - 26 May 2006 10:36 GMT
Hi Dave.

Thank you for posting.

As for the

=========
I want to make sure all files pulled from my server app (ASP.NET 2.0) come
from one of 3 directories -
=========

You mentioned, would you please provide some further description on it? So
far I'm still quite confused about the operation you're doing or your
ASP.NET application's code logic. Based on my understanding, as for a file,
if it is existing on the physical disk, we can access it through File class
which will contains full path info. However, when we've loaded file stream
into memory, they'll no longer contain disk file info...  

Regards,

Steven Cheng
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Signature

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

David Thielen - 26 May 2006 17:28 GMT
Hi;

In my app the user can enter a file (an xml data file) that resides on the
server to be used as a datasource. For security reasons I don't want them
able to get any file on the computer (like the ones in c:\windows) but they
may need to get files I put in places like c:\employees\data.

So when they give me a filename (not stream, just the filename) - I want to
check it against c:\employees\data\ and make sure it is in that directory or
a subdirectory of that.

Signature

thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

> Hi Dave.
>
[quoted text clipped - 31 lines]
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
Steven Cheng[MSFT] - 29 May 2006 03:20 GMT
Thanks for your response Dave,

So I've got your point that you want to verify the existence of a certain
file(given the name) within several directories, correct? I suggest you
have a look at the Sytem.IO namespace's classes, and they are specific to
IO operations against physical directory and files. For example, the
Directory class and the File class contains many static methods to do some
generic IO operations.

#System.IO Namespace  
http://msdn2.microsoft.com/en-us/library/system.io.aspx

BTW, when you try accessing UNC share, make sure your ASP.NET's current
security context (process identity or impersonated user) has the permission
to access the share directory.

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Signature

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

David Thielen - 01 Jun 2006 16:36 GMT
Ok, I've implemented this. If anyone else needs it it is at
http://www.davidthielen.info/programming/2006/06/is_directory_ac.html If you
see any problems (ie MFUs) in the code please comment on the blog so others
know too.

Signature

thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

> Thanks for your response Dave,
>
[quoted text clipped - 31 lines]
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
Steven Cheng[MSFT] - 02 Jun 2006 02:37 GMT
Thanks for your followup and share the solution with us.

Regards,

Steven Cheng
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Signature

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Ben Voigt - 29 May 2006 14:40 GMT
> Hi;
>
[quoted text clipped - 9 lines]
> or
> a subdirectory of that.

In this scenario, I don't think giving your users maximum flexibility is a
design goal.  There's no reason they should be entering
\\?\C:\Windows\..\Employees\DaTa and expecting your website to recognize
that it's an authorized directory.  Require them to use the canonical name.
Use a strong regex and be done with it.  If they can't stop using the CAPS
LOCK key when they fill in your form, give them a client-side javascript to
help them get it right.  Let the server be ultra-strict.

i.e. something like

@"c:\\(employees|managers|otherdatadir)\\data\\[-_A-Za-z0-9]{1,50}\.xml"

It's rather desirable to limit filenames to a bounded sequence of
alphanumeric characters as I've done, in order to prevent parent paths (..),
redirection symbols (< > >> |), NTFS hidden streams, and all manner of other
evil such as "c:\employees\data\I_AM_A_BUFFER_OVERFLOW_HAHAHA_<overwrite
your return address here>.xml".

>> Hi Dave.
>>
[quoted text clipped - 37 lines]
>> (This posting is provided "AS IS", with no warranties, and confers no
>> rights.)

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.