public static bool HasAccessToDirectory()

in Configurator/Base/Classes/DirectoryServicesWrapper.cs [448:500]


    public static bool HasAccessToDirectory(SecurityIdentifier principalSid, string path, FileSystemRights? fileSystemRights)
    {
      if (principalSid == null)
      {
        throw new ArgumentNullException(string.Format(Resources.MissingParameterGenericError, "principal name"));
      }

      if (string.IsNullOrEmpty(path))
      {
        throw new ArgumentNullException(string.Format(Resources.MissingParameterGenericError, "file path"));
      }

      var directoryInfo = new DirectoryInfo(path);
      if (!directoryInfo.Exists)
      {
        throw new Exception(string.Format(Resources.PathDoesNotExist, path));
      }

      var rules = GetAuthorizationRules(directoryInfo);
      if (rules == null)
      {
        throw new Exception(string.Format(Resources.AuthorizationRulesRetrievalFailed, path));
      }

      foreach (FileSystemAccessRule rule in rules)
      {
        var ruleValue = rule.IdentityReference.Value;
        if (string.IsNullOrEmpty(ruleValue))
        {
          throw new ArgumentNullException(string.Format(Resources.MissingParameterGenericError, "rule"));
        }

        var securityIdentifier = GetSecurityIdentifier(ruleValue.Contains("\\") ? ruleValue.Split('\\')[1] : ruleValue);
        if (securityIdentifier == null
            || securityIdentifier.Value != principalSid.Value)
        {
          continue;
        }

        if (rule.AccessControlType != AccessControlType.Allow)
        {
          return false;
        }

        if (fileSystemRights != null
            && rule.FileSystemRights == fileSystemRights)
        {
          return true;
        }
      }

      return false;
    }