.net - 遇到枚举中未定义的 FileSystemRights 值

标签 .net security ntfs

我编写了一个应用程序来检查目录上的所有文件系统权限。

一个目录有许多访问规则(类型为 FileSystemAccessRule )。

每个访问规则都有一个属性 FileSystemRights ,它是一个标志枚举。

运行此程序时,我不断遇到 FileSystemRights268435456 值(以十六进制表示 0x10000000)。

这个值只是没有出现在枚举中!它实际上高于最高的单个标志值( Synchronize ,值为 0x100000 )。

有谁知道这是什么?

最佳答案

http://cjwdev.wordpress.com/2011/06/28/permissions-not-included-in-net-accessrule-filesystemrights-enum/

从该页面:

Using .NET you may think that determining which permissions are assigned to a directory/file should be quite easy, as there is a FileSystemRights Enum defined that seems to contain every possible permission that a file/directory can have and calling AccessRule.FileSystemRights returns a combination of these values. However, you will soon come across some permissions where the value in this property does not match any of the values in the FileSystemRights Enum (I do wish they wouldn’t name some properties with the same name as a Type but hey).

The end result of this is that for some files/directories you simply cannot determine which permissions are assigned to them. If you do AccessRule.FileSystemRights.ToString then for these values all you see is a number rather than a description (e.g Modify, Delete, FullControl etc). Common numbers you might see are:

-1610612736, –536805376, and 268435456

To work out what these permissions actually are, you need to look at which bits are set when you treat that number as 32 separate bits rather than as an Integer (as Integers are 32 bits long), and compare them to this diagram: http://msdn.microsoft.com/en-us/library/aa374896(v=vs.85).aspx

So for example, -1610612736 has the first bit and the third bit set, which means it is GENERIC_READ combined with GENERIC_EXECUTE. So now you can convert these generic permissions into the specific file system permissions that they correspond to.

You can see which permissions each generic permission maps to here: http://msdn.microsoft.com/en-us/library/aa364399.aspx. Just be aware that STANDARD_RIGHTS_READ, STANDARD_RIGHTS_EXECUTE and STANDARD_RIGHTS_WRITE are all the same thing (no idea why, seems strange to me) and actually all equal the FileSystemRights.ReadPermissions value.

关于.net - 遇到枚举中未定义的 FileSystemRights 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9694834/

相关文章:

security - 使用 OWIN/Katana 在 Azure 上进行数据保护操作失败

c# - 以前没有的访问冲突

java - 升级 JRE 1.7 后小程序复制/粘贴不起作用

javascript - 如何防止html/JavaScript代码修改

c++ - GetFullPathNameW 和长 Windows 文件路径

architecture - NTFS 备用数据流 - 好主意还是坏主意?

linux - 如何获取和设置NTFS分区中文件的安全信息?

c# - SQL SMO 执行批处理 TSQL 脚本

.net - 至少包含 1 个字母和 1 个数字的正则表达式

c# - 将图像从 iPhone 发送到 .net 服务器