473,659 Members | 3,553 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

NTFS ACLs from C# (Whidbey)

I'm using the new System.Security .AccessControl stuff in 2.0.

This is a snippet typical of what I've done (this example sets Read access for Network Service on 'myFolder' and all subfolders and files)

SecurityIdentif ier siNetworkServic e = new SecurityIdentif ier(WellKnownSi dType.NetworkSe rviceSid, null);
NTAccount ntaNetworkServi ce = siNetworkServic e.Translate(typ eof(NTAccount)) as NTAccount;
DirectoryInfo diMyFolder = new DirectoryInfo(m yFolder);
DirectorySecuri ty dsMyFolder = diMyFolder.GetA ccessControl();
FileSystemAcces sRule fsarNetworkServ ice = new FileSystemAcces sRule(ntaNetwor kService, FileSystemRight s.Read, AccessControlTy pe.Allow);
FileSystemAcces sRule fsarNetworkServ ice2 = new FileSystemAcces sRule(ntaNetwor kService, FileSystemRight s.Read, InheritanceFlag s.ContainerInhe rit | InheritanceFlag s.ObjectInherit , PropagationFlag s.InheritOnly, AccessControlTy pe.Allow);

// I can't figure out why I need two ACEs for this, but I can't get the
// behavior for this folder, child folder and files, and propagate all
// to work in one line of code. The InheritanceFlag s and PropagationFlag s
// don't like to be mixed with the line above. Try it without the 2nd line
// and you'll see what I mean. Bug in .NET Fx?

dsMyFolder.AddA ccessRule(fsarN etworkService);
dsMyFolder.AddA ccessRule(fsarN etworkService2) ;
diMyFolder.SetA ccessControl(ds MyFolder);

Any idea why that 2nd ACE is required? Is there a way to set this ACL with fewer lines of code? I have about a dozen rules like this, and it adds up to about 100 lines of code.

- Mark

--
MARK RICHMAN
Jul 21 '05 #1
4 5003
Mark,
I think that using string security descriptors and then translating them to
binary security descriptors is the most efficient way of doing that sort of
things. Here is your sd:

D:(A;;GR;;;NS)( A;CIOIIO;GR;;;N S)

After that you just call ConvertStringSe curityDescripto rToSecurityDesc riptor
API and done with it with just tree lines of code :-).

-Valery.
http://www.harper.no/valery

"Mark A. Richman" <no****@nospam. com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
I'm using the new System.Security .AccessControl stuff in 2.0.

This is a snippet typical of what I've done (this example sets Read access
for Network Service on 'myFolder' and all subfolders and files)

SecurityIdentif ier siNetworkServic e = new
SecurityIdentif ier(WellKnownSi dType.NetworkSe rviceSid, null);
NTAccount ntaNetworkServi ce = siNetworkServic e.Translate(typ eof(NTAccount))
as NTAccount;
DirectoryInfo diMyFolder = new DirectoryInfo(m yFolder);
DirectorySecuri ty dsMyFolder = diMyFolder.GetA ccessControl();
FileSystemAcces sRule fsarNetworkServ ice = new
FileSystemAcces sRule(ntaNetwor kService, FileSystemRight s.Read,
AccessControlTy pe.Allow);
FileSystemAcces sRule fsarNetworkServ ice2 = new
FileSystemAcces sRule(ntaNetwor kService, FileSystemRight s.Read,
InheritanceFlag s.ContainerInhe rit | InheritanceFlag s.ObjectInherit ,
PropagationFlag s.InheritOnly, AccessControlTy pe.Allow);

// I can't figure out why I need two ACEs for this, but I can't get the
// behavior for this folder, child folder and files, and propagate all
// to work in one line of code. The InheritanceFlag s and PropagationFlag s
// don't like to be mixed with the line above. Try it without the 2nd line
// and you'll see what I mean. Bug in .NET Fx?

dsMyFolder.AddA ccessRule(fsarN etworkService);
dsMyFolder.AddA ccessRule(fsarN etworkService2) ;
diMyFolder.SetA ccessControl(ds MyFolder);

Any idea why that 2nd ACE is required? Is there a way to set this ACL with
fewer lines of code? I have about a dozen rules like this, and it adds up to
about 100 lines of code.

- Mark

--
MARK RICHMAN

Jul 21 '05 #2
Mark,

The forums for Beta testing and related

http://forums.microsoft.com/MSDN/default.aspx

I hope this helps a little bit?

Cor
Jul 21 '05 #3
Valery,

Since it's just three lines of code, may I ask for an example? Also, can
you provide a link to that descriptor format?

--
MARK RICHMAN

"Valery Pryamikov" <va****@harper. no> wrote in message
news:%2******** *********@TK2MS FTNGP12.phx.gbl ...
Mark,
I think that using string security descriptors and then translating them
to binary security descriptors is the most efficient way of doing that
sort of things. Here is your sd:

D:(A;;GR;;;NS)( A;CIOIIO;GR;;;N S)

After that you just call
ConvertStringSe curityDescripto rToSecurityDesc riptor API and done with it
with just tree lines of code :-).

-Valery.
http://www.harper.no/valery

"Mark A. Richman" <no****@nospam. com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
I'm using the new System.Security .AccessControl stuff in 2.0.

This is a snippet typical of what I've done (this example sets Read access
for Network Service on 'myFolder' and all subfolders and files)

SecurityIdentif ier siNetworkServic e = new
SecurityIdentif ier(WellKnownSi dType.NetworkSe rviceSid, null);
NTAccount ntaNetworkServi ce =
siNetworkServic e.Translate(typ eof(NTAccount)) as NTAccount;
DirectoryInfo diMyFolder = new DirectoryInfo(m yFolder);
DirectorySecuri ty dsMyFolder = diMyFolder.GetA ccessControl();
FileSystemAcces sRule fsarNetworkServ ice = new
FileSystemAcces sRule(ntaNetwor kService, FileSystemRight s.Read,
AccessControlTy pe.Allow);
FileSystemAcces sRule fsarNetworkServ ice2 = new
FileSystemAcces sRule(ntaNetwor kService, FileSystemRight s.Read,
InheritanceFlag s.ContainerInhe rit | InheritanceFlag s.ObjectInherit ,
PropagationFlag s.InheritOnly, AccessControlTy pe.Allow);

// I can't figure out why I need two ACEs for this, but I can't get the
// behavior for this folder, child folder and files, and propagate all
// to work in one line of code. The InheritanceFlag s and PropagationFlag s
// don't like to be mixed with the line above. Try it without the 2nd line
// and you'll see what I mean. Bug in .NET Fx?

dsMyFolder.AddA ccessRule(fsarN etworkService);
dsMyFolder.AddA ccessRule(fsarN etworkService2) ;
diMyFolder.SetA ccessControl(ds MyFolder);

Any idea why that 2nd ACE is required? Is there a way to set this ACL with
fewer lines of code? I have about a dozen rules like this, and it adds up
to about 100 lines of code.

- Mark

--
MARK RICHMAN

Jul 21 '05 #4
Since you are using Whidbey, you simply could call
SetSecurityDesc riptorSddlForm method of any XXXSecurity based class
ex.

DirectorySecuri ty dirSec = Directory.GetAc cessControl("C: \\TestDirectory ");
dirSec.SetSecur ityDescriptorSd dlForm("D:(A;;G R;;;NS)(A;CIOII O;GR;;;NS)");
Directory.SetAc cessControl("C: \\TestDirectory ", dirSec);

Documentation of SDDL format could be found here:
http://msdn.microsoft.com/library/de...descriptor.asp

(watch for line breaks)

in C++ it it looks like:
if
(!ConvertString SecurityDescrip torToSecurityDe scriptor(_T("D: (A;;GR;;;NS)(A; CIOIIO;GR;;;NS) "),
SDDL_REVISION_1 , (PSECURITY_DESC RIPTOR *)pDescriptor, NULL))
// you can return error here. ex: return GetLastError();

-Valery.
http://www.harper.no/valery

"Mark A. Richman" <no****@nospam. com> wrote in message
news:uw******** ******@TK2MSFTN GP09.phx.gbl...
Valery,

Since it's just three lines of code, may I ask for an example? Also, can
you provide a link to that descriptor format?

--
MARK RICHMAN

"Valery Pryamikov" <va****@harper. no> wrote in message
news:%2******** *********@TK2MS FTNGP12.phx.gbl ...
Mark,
I think that using string security descriptors and then translating them
to binary security descriptors is the most efficient way of doing that
sort of things. Here is your sd:

D:(A;;GR;;;NS)( A;CIOIIO;GR;;;N S)

After that you just call
ConvertStringSe curityDescripto rToSecurityDesc riptor API and done with it
with just tree lines of code :-).

-Valery.
http://www.harper.no/valery

"Mark A. Richman" <no****@nospam. com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
I'm using the new System.Security .AccessControl stuff in 2.0.

This is a snippet typical of what I've done (this example sets Read
access for Network Service on 'myFolder' and all subfolders and files)

SecurityIdentif ier siNetworkServic e = new
SecurityIdentif ier(WellKnownSi dType.NetworkSe rviceSid, null);
NTAccount ntaNetworkServi ce =
siNetworkServic e.Translate(typ eof(NTAccount)) as NTAccount;
DirectoryInfo diMyFolder = new DirectoryInfo(m yFolder);
DirectorySecuri ty dsMyFolder = diMyFolder.GetA ccessControl();
FileSystemAcces sRule fsarNetworkServ ice = new
FileSystemAcces sRule(ntaNetwor kService, FileSystemRight s.Read,
AccessControlTy pe.Allow);
FileSystemAcces sRule fsarNetworkServ ice2 = new
FileSystemAcces sRule(ntaNetwor kService, FileSystemRight s.Read,
InheritanceFlag s.ContainerInhe rit | InheritanceFlag s.ObjectInherit ,
PropagationFlag s.InheritOnly, AccessControlTy pe.Allow);

// I can't figure out why I need two ACEs for this, but I can't get the
// behavior for this folder, child folder and files, and propagate all
// to work in one line of code. The InheritanceFlag s and PropagationFlag s
// don't like to be mixed with the line above. Try it without the 2nd
line
// and you'll see what I mean. Bug in .NET Fx?

dsMyFolder.AddA ccessRule(fsarN etworkService);
dsMyFolder.AddA ccessRule(fsarN etworkService2) ;
diMyFolder.SetA ccessControl(ds MyFolder);

Any idea why that 2nd ACE is required? Is there a way to set this ACL
with fewer lines of code? I have about a dozen rules like this, and it
adds up to about 100 lines of code.

- Mark

--
MARK RICHMAN



Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
453
by: Pål Andreassen | last post by:
Running Windows 2003 Server Framework 1.1 A site is configured to use integrated security (in IIS 6) Windows autentication and user impersonation in web.config <identity impersonate="true" /> <authentication mode="Windows" /> I've got a ASPX page that lists folders and files from a predefined location on the server. These folders and files have access rights set to
2
3224
by: Jim Richards | last post by:
I have been told by a local PC club technician that 98SE cannot read NTFS drives in a network. Is this true? TIA, Jim.
1
2857
by: Morten | last post by:
Hi! I'm trying to figure out how to add a user with full access to an NTFS folder on a Windows 2003 Server using C# (web project). Does anyone have an example of this? I want to keep existing permissions and just add one more user to the list of allowed users. Thanks in advance for your help. Morten
0
1133
by: Sherwood | last post by:
My current scenario is users logging in to our website and being directed to a specific directory based on who they are. The ACLs on the destination result in prompts for credentials (the windows popup dialog). I'm using basic windows authentication with https to protect the username and password. I'd like to have a nicer login UI using Forms authentication against the AD, but would still like to use ACLs to control resource access. ...
0
1212
by: spamfurnace | last post by:
Will Whidbey have the features, of a girl i'd like to meet? Will Whidbey be easy to talk to, and rub my tired feet? Will Whidbey bats it eyes at me, and whisper "Baby, your so sweet". Will Whidbey have a body to die for, and look hot as hell wrapped only in a sheet. Will Whidbey have construction workers whistling at it if i tucked under my arm and walked it down the street. Will Whidbey make me feel like a man, and have all other IDE...
5
2873
by: rogsonl | last post by:
My computer was moved last week, and the company changed the network groups we work on. As a result, one of the main benefits from Whidbey (database connectivity) no longer works. Situation: 1. I open a new project based on a windows form 2. I click on "data" and then "Add New Data Source" then I click on next within the wizard 3. I have 3 choices Database, Local Database, Web service and Object. 4. I choose Database, click next and get...
1
2245
by: Troy | last post by:
Is there a way in Visual Basic to determine when a user has explicit rights to a directory and when they have rights due to inheritance?
4
905
by: Mark A. Richman | last post by:
I'm using the new System.Security.AccessControl stuff in 2.0. This is a snippet typical of what I've done (this example sets Read access for Network Service on 'myFolder' and all subfolders and files) SecurityIdentifier siNetworkService = new SecurityIdentifier(WellKnownSidType.NetworkServiceSid, null); NTAccount ntaNetworkService = siNetworkService.Translate(typeof(NTAccount)) as NTAccount; DirectoryInfo diMyFolder = new...
5
9732
by: dananrg | last post by:
Is there a standard library module in Python 2.4 (Win32) that will return directory permissions / ACLs (e.g. users, groups, and what rights they have)? Otherwise, I'm faced with sending "cacls dirName" commands via os.popen as below, and then parsing and comparing the text output. Basically, I'd like to compare what the ACLs a directory should have against what the actual ACLs are.
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8337
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8748
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7359
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2754
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.