【问题标题】:Windows indexing service - List scopes accessible to the current userWindows 索引服务 - 列出当前用户可访问的范围
【发布时间】:2011-12-02 03:44:02
【问题描述】:

我们的文件服务器上设置了索引服务来索引几十个文件夹(在索引服务术语中称为“范围”),并非所有用户都可以访问所有这些文件夹。我有一个在 IIS 下运行的带有 Windows 集成身份验证的 ASP 搜索脚本,这意味着当用户登录网络使用搜索页面时,他们只会看到他们有权访问的结果。这是一件好事。

但是如何向用户显示他们可以访问的范围列表? (换句话说,将被搜索的文件夹列表)。可以使用 CatAdm 对象以编程方式枚举范围,但这需要我的 ASP 脚本没有的管理员权限,而且无论如何它不会告诉我当前用户是否具有访问权限。

我尝试了启用目录索引的巧妙技巧(FilterDirectories 注册表设置),然后只查询目录(“@Attrib ^a 0x10”,检查文件属性中的目录标志) ,但是当然这也给了我子目录...我可以遍历结果并只获取顶级目录,但这似乎只是为了生成这个简单的列表而在服务器上增加了很多负载。此外,我已经配置了别名,以便索引服务返回网络路径而不是本地路径,但我似乎遇到了索引服务错误,因为别名应用于所有除了顶级目录本身.

谁有更好的建议?

【问题讨论】:

    标签: asp-classic


    【解决方案1】:

    到目前为止,这个问题只有 7 次浏览,并为我赢得了“风滚草”徽章,但我认为我会跟进我的最终解决方案。

    使用 CatAdm 对象确实是最终的唯一选择,因为这是解决索引服务中与别名相关的错误的唯一方法(在我的原始帖子中提到)。

    一种方法(在 ASP.NET 中相对简单,在 ASP Classic 中使用等效的自定义 COM 组件可能)是使用模拟:使用特权帐户从 CatAdm 读取范围列表对象,然后使用授权的 HTTP 请求的帐户对这些范围进行查询。结果将仅包含该帐户有权访问的目录。

    问题在于只有管理员帐户才有权使用 CatAdm 对象,从安全角度来看,使用管理员帐户来处理 HTTP 请求并不是一个好的做法。

    因此,尽管它增加了管理负担,但我决定编写一个单独的 HTA 脚本,无论何时从目录中添加或删除目录,都必须运行该脚本(在服务器机器本身上,而不是通过 HTTP)。该脚本从 CatAdm 对象中读取范围列表并将其写入配置文件:

        Function makeConfig(catalogName)
            Set machine = CreateObject("Shell.LocalMachine")
            Set adm = CreateObject("Microsoft.ISAdm")
            Set cat = adm.GetCatalogByName(catalogName)
    
            Dim config
            config = "<%" & vbCrLf
            config = config & "' Automatically generated by " & document.location.pathname & " at " & Now & vbCrLf
            config = config & "' This file is indended for inclusion by the intranet search script." & vbCrLf
            config = config & "catalogMachine = """ & machine.MachineName & """"  & vbCrLf
            config = config & "catalogName = """ & catalogName & """"  & vbCrLf
    
            scopeFound = cat.FindFirstScope()
            While scopeFound
                Set scope = cat.GetScope()
                If Not scope.ExcludeScope Then
                    ' Must be lowercase because query results are returned in lowercase
                    dir = lcase(scope.Path)
                    If scope.Alias <> "" Then
                        alias = scope.Alias
                    Else
                        alias = scope.Path
                    End If
    
                    config = config & "dirs(""" & dir & """) = """ & alias & """" & vbCrLf
                End If
                scopeFound = cat.FindNextScope()
            Wend
    
            config = config & "%>" & vbCrLf
            makeConfig = config
        End Function
    

    然后搜索脚本本身只是读取配置文件并使用它来查找可访问目录的列表。要解决索引服务错误,需要从物理目录映射到别名:

    Set dirs = CreateObject("Scripting.Dictionary")
    %><!--#include file="search_config.asp"--><%
    catalogURI = "query://" & catalogMachine & "/" & catalogName
    
    queryString = ""
    For Each dir In dirs
      If queryString <> "" Then
        queryString = queryString & " or "
      End If
      queryString = queryString & "@Path = """ & dir & """"
    Next
    
    ' But the @Path attribute is not indexed, and running queryString
    ' as is will return no results. Solution: limit search to only
    ' directories, i.e. items with the 0x10 flag set in @Attrib.
    queryString = "@Attrib ^a 0x10 and (" & queryString & ")"
    
    ' No point asking for sorted query results, because we need
    ' to map the results from real paths to network aliases and
    ' sort again ourselves.
    Set query = Server.CreateObject("ixsso.Query")
    query.Catalog = catalogURI
    query.Query = queryString
    query.Columns = "path"
    query.MaxRecords = dirs.Count
    Set rs = query.CreateRecordSet("sequential")
    
    i = 0
    Do While Not rs.EOF
      ReDim Preserve accessibleAliases(i)
      accessibleAliases(i) = dirs(rs("path").Value)
      i = i + 1
      rs.MoveNext
    Loop
    rs.Close
    
    BubbleSort accessibleAliases
    

    【讨论】:

      猜你喜欢
      • 2013-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-18
      • 1970-01-01
      • 1970-01-01
      • 2017-03-07
      • 2020-09-04
      相关资源
      最近更新 更多