G
Guest
Hi,
I've written a very quick console app to recursive through a directory tree
and display directories that have explicit file permissions (code below). It
works, but GetAccessControl() fails on some folders (always the same) with
the error:
The binary form of an ACE object is invalid.
Parameter name: binaryForm
I've had a look at the folder properties, security tab for a couple of the
affected folders and everything seems to look ok.
Anyone have any ideas?
Thanks,
Ryan
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Principal;
using System.Security.AccessControl;
namespace CheckACLs {
class Program {
static void Main(string[] args) {
DirectoryInfo di = new DirectoryInfo(@"c:\");
DisplayRights(di, 0);
Console.ReadKey();
}
static void DisplayRights(DirectoryInfo di, int recurseLevel) {
if (recurseLevel <= 2) {
recurseLevel++;
foreach (DirectoryInfo d in di.GetDirectories()) {
DisplayRights(d, recurseLevel);
}
}
bool firstRun = true;
DirectorySecurity ds = di.GetAccessControl();
foreach (FileSystemAccessRule fsa in ds.GetAccessRules(true,
false, typeof(NTAccount))) {
if (firstRun) {
Console.WriteLine(di.FullName);
firstRun = false;
}
Console.WriteLine("\t" + fsa.IdentityReference.ToString() +
" " +
fsa.FileSystemRights.ToString() + " " +
fsa.AccessControlType.ToString());
}
}
}
}
I've written a very quick console app to recursive through a directory tree
and display directories that have explicit file permissions (code below). It
works, but GetAccessControl() fails on some folders (always the same) with
the error:
The binary form of an ACE object is invalid.
Parameter name: binaryForm
I've had a look at the folder properties, security tab for a couple of the
affected folders and everything seems to look ok.
Anyone have any ideas?
Thanks,
Ryan
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Principal;
using System.Security.AccessControl;
namespace CheckACLs {
class Program {
static void Main(string[] args) {
DirectoryInfo di = new DirectoryInfo(@"c:\");
DisplayRights(di, 0);
Console.ReadKey();
}
static void DisplayRights(DirectoryInfo di, int recurseLevel) {
if (recurseLevel <= 2) {
recurseLevel++;
foreach (DirectoryInfo d in di.GetDirectories()) {
DisplayRights(d, recurseLevel);
}
}
bool firstRun = true;
DirectorySecurity ds = di.GetAccessControl();
foreach (FileSystemAccessRule fsa in ds.GetAccessRules(true,
false, typeof(NTAccount))) {
if (firstRun) {
Console.WriteLine(di.FullName);
firstRun = false;
}
Console.WriteLine("\t" + fsa.IdentityReference.ToString() +
" " +
fsa.FileSystemRights.ToString() + " " +
fsa.AccessControlType.ToString());
}
}
}
}