遇到未在枚举中定义的FileSystemRights值

时间:2012-03-14 01:47:54

标签: .net security ntfs

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

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

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

运行此功能时,我遇到的FileSystemRights268435456(以十六进制显示0x10000000)。

此值不会出现在枚举中!它实际上高于最高的单一标志值(Synchronize,其值为0x100000)。

有谁知道这是什么?

3 个答案:

答案 0 :(得分:12)

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

从该页面开始:

  

使用.NET,您可能会认为确定哪些权限   分配给目录/文件应该很容易,因为有一个   FileSystemRights枚举定义似乎包含所有可能的   文件/目录可以拥有和调用的权限   AccessRule.FileSystemRights返回这些值的组合。   但是,您很快就会遇到一些权限   此属性与FileSystemRights中的任何值都不匹配   枚举(我希望他们不会将一些具有相同名称的属性命名为   作为一个类型,但嘿)。

     

这样做的最终结果是对于某些文件/目录而言   无法确定为其分配了哪些权限。如果你这样做   然后,您可以看到AccessRule.FileSystemRights.ToString这些值   是一个数字而不是一个描述(例如Modify,Delete,FullControl   等等)。您可能会看到的常见数字是:

     

-1610612736,-536805376和268435456

     

要弄清楚这些权限实际是什么,您需要查看   当您将该数字视为32个单独的位时,将设置哪些位   而不是整数(因为整数是32位长),并进行比较   他们到这个图:   http://msdn.microsoft.com/en-us/library/aa374896(v=vs.85).aspx

     

例如,-1610612736具有第一位和第三位,   这意味着GENERIC_READ与GENERIC_EXECUTE结合使用。所以现在   您可以将这些通用权限转换为特定文件   他们对应的系统权限。

     

您可以在此处查看每个通用权限映射到的权限:   http://msdn.microsoft.com/en-us/library/aa364399.aspx。请注意   那个STANDARD_RIGHTS_READ,STANDARD_RIGHTS_EXECUTE和   STANDARD_RIGHTS_WRITE都是一样的(不知道为什么,似乎   对我来说很奇怪)而且实际上都等于   FileSystemRights.ReadPermissions值。

答案 1 :(得分:4)

答案 2 :(得分:2)

这是我的纠正FileSystemRights的解决方案,因此它们适合枚举。

有几个相关的文件。引用包含在代码中。

function copy(source, destination, stackSource, stackDest) {
  if (isWindow(source) || isScope(source)) {
    throw ngMinErr('cpws',
      "Can't copy! Making copies of Window or Scope instances is not supported.");
  }
  if (isTypedArray(destination)) {
    throw ngMinErr('cpta',
      "Can't copy! TypedArray destination cannot be mutated.");
  }

  if (!destination) {
    destination = source;
    if (isObject(source)) {
      var index;
      if (stackSource && (index = stackSource.indexOf(source)) !== -1) {
        return stackDest[index];
      }

      // TypedArray, Date and RegExp have specific copy functionality and must be
      // pushed onto the stack before returning.
      // Array and other objects create the base object and recurse to copy child
      // objects. The array/object will be pushed onto the stack when recursed.
      if (isArray(source)) {
        return copy(source, [], stackSource, stackDest);
      } else if (isTypedArray(source)) {
        destination = new source.constructor(source);
      } else if (isDate(source)) {
        destination = new Date(source.getTime());
      } else if (isRegExp(source)) {
        destination = new RegExp(source.source, source.toString().match(/[^\/]*$/)[0]);
        destination.lastIndex = source.lastIndex;
      } else if (isFunction(source.cloneNode)) {
          destination = source.cloneNode(true);
      } else {
        var emptyObject = Object.create(getPrototypeOf(source));
        return copy(source, emptyObject, stackSource, stackDest);
      }

      if (stackDest) {
        stackSource.push(source);
        stackDest.push(destination);
      }
    }
  } else {
    if (source === destination) throw ngMinErr('cpi',
      "Can't copy! Source and destination are identical.");

    stackSource = stackSource || [];
    stackDest = stackDest || [];

    if (isObject(source)) {
      stackSource.push(source);
      stackDest.push(destination);
    }

    var result, key;
    if (isArray(source)) {
      destination.length = 0;
      for (var i = 0; i < source.length; i++) {
        destination.push(copy(source[i], null, stackSource, stackDest));
      }
    } else {
      var h = destination.$$hashKey;
      if (isArray(destination)) {
        destination.length = 0;
      } else {
        forEach(destination, function(value, key) {
          delete destination[key];
        });
      }
      if (isBlankObject(source)) {
        // createMap() fast path --- Safe to avoid hasOwnProperty check because prototype chain is empty
        for (key in source) {
          destination[key] = copy(source[key], null, stackSource, stackDest);
        }
      } else if (source && typeof source.hasOwnProperty === 'function') {
        // Slow path, which must rely on hasOwnProperty
        for (key in source) {
          if (source.hasOwnProperty(key)) {
            destination[key] = copy(source[key], null, stackSource, stackDest);
          }
        }
      } else {
        // Slowest path --- hasOwnProperty can't be called as a method
        for (key in source) {
          if (hasOwnProperty.call(source, key)) {
            destination[key] = copy(source[key], null, stackSource, stackDest);
          }
        }
      }
      setHashKey(destination,h);
    }
  }
  return destination;
}