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 2007

Tip: Looking for answers? Try searching our database.

How to find out file owner?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dmitry Nogin - 25 Jan 2007 16:55 GMT
Hi,
The following code doesn't work for mapped drives:

using System;
using System.Text;
using System.Threading;
using System.Security.AccessControl;
using System.Security.Principal;
using System.IO;

namespace ConsoleApplication1
{
  class Program
  {
       static void Main(string[] args)
       {
           FileInfo fi = new FileInfo(@"c:\boot.ini");
           FileSecurity fs = fi.GetAccessControl();
           IdentityReference ir = fs.GetOwner(typeof(NTAccount));
           Console.WriteLine(ir.Value);
       }
   }
}

What should I do to make it work for mapped drives or UNC (like
\\10.0.61.22\c$\boot.ini)?

(Windows XP network; logged on using domain administrator account)

   Thanks
Joe Kaplan - 26 Jan 2007 23:37 GMT
I'm not sure what the problem is, but can you explain more about what
doesn't work?  Does it crash?  Can you not access the security descriptor?
Can you just not access the owner or does the translation of the SID into an
NTAccount fail?

Joe K.

Signature

Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--

> Hi,
> The following code doesn't work for mapped drives:
[quoted text clipped - 26 lines]
>
>    Thanks
Dmitry Nogin - 29 Jan 2007 10:43 GMT
Yes, the problem is about SID translation. I can acquire SID but translation
into an NTAccount fails.

BTW, I can see actual value in Windows Explorer.

> I'm not sure what the problem is, but can you explain more about what
> doesn't work?  Does it crash?  Can you not access the security descriptor?
[quoted text clipped - 33 lines]
>>
>>    Thanks
Joe Kaplan - 29 Jan 2007 16:24 GMT
If the SID is local to the machine that it is coming from, then that might
explain it.  The current machine may have no way to determine who that user
is.  I can't explain why Windows explorer would be able to do it as they
should be using the same APIs, but sometimes things aren't that obvious.

What is the SID in this case?  Does it belong to a specific local machine
user?

Joe K.

Signature

Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--

> Yes, the problem is about SID translation. I can acquire SID but
> translation into an NTAccount fails.
[quoted text clipped - 38 lines]
>>>
>>>    Thanks
Dmitry Nogin - 31 Jan 2007 10:05 GMT
I checked all the possible situations:
BULTIN\Administrator
MYDOMAIN\Administrator
etc...

Sometimes it works, sometimes - no. I couldn't find any dependancy on the
origin of the account.

> If the SID is local to the machine that it is coming from, then that might
> explain it.  The current machine may have no way to determine who that
[quoted text clipped - 49 lines]
>>>>
>>>>    Thanks
Joe Kaplan - 31 Jan 2007 14:58 GMT
I honestly don't know.  It is a generally good idea to trap the exception
returned when trying to convert between a SID and NTAccount though, as that
can fail unexpected for a variety of reasons.  Sometimes you can only ever
get the original SID.

Joe K.

Signature

Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--

>I checked all the possible situations:
> BULTIN\Administrator
[quoted text clipped - 57 lines]
>>>>>
>>>>>    Thanks

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.