I've got a very strange Problem. When im adding a new ACE entry to a UNC Direcotry the inherented ACL's will be lost. When I'm adding a new ACE to a directory / file in this UNC path the inherented ACE are still available.
What's wrong ? I don't understand the difference between \\server\share and \\server\share\directory while adding a ACE
AndyL
Sample:
\\myserver\myshare
Inherited ACE: Administrators, Network Service
After adding a ACE:
\\myserver\myshare
Inherited ACE: <empty>
ACE: myUser
Sample II:
\\myserver\myshare
Inherited ACE: Administrators, Network Service
After adding a ACE:
\\myserver\myshare
Inherited ACE: Administrators, Network Service
ACE: myUser
here is my code:
Expand|Select|Wrap|Line Numbers
- class programm
- {
- static void Main(string[] args)
- {
- String dir1 = @"\\myserver\myshare";
- String dir2 = @"\\myserver\myshare\test";
- String usr = "myuser";
- AddDirectorySecurity(dir1, usr , System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Allow);
- Console.ReadKey();
- AddDirectorySecurity(dir2, usr , System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Allow);
- Console.ReadKey();
- }
- public static void AddDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
- {
- // Create a new DirectoryInfo object.
- DirectoryInfo dInfo = new DirectoryInfo(FileName);
- // Get a DirectorySecurity object that represents the
- // current security settings.
- DirectorySecurity dSecurity = dInfo.GetAccessControl();
- // Add the FileSystemAccessRule to the security settings.
- dSecurity.AddAccessRule(new FileSystemAccessRule(Account,
- Rights,
- ControlType));
- // Set the new access settings.
- dInfo.SetAccessControl(dSecurity);
- }
- }