代码之家  ›  专栏  ›  技术社区  ›  lesscode

如何让DirectorySearch尊重我指定的搜索范围?

  •  1
  • lesscode  · 技术社区  · 14 年前

    我在一个项目中有以下C代码:

        DirectoryEntry root = new DirectoryEntry(@"LDAP://ad.mydomain.com");
        DirectorySearcher ds = new DirectorySearcher(root);
        ds.DerefAlias = DereferenceAlias.Always;
        ds.SearchScope = SearchScope.Subtree;
        ds.Filter = "(|(name=John_Smith)(cn=John_Smith))";
        SearchResultCollection src = ds.FindAll();
    

    我正在用MS Network Monitor监视到AD服务器的LDAP流量,搜索发生时会看到:

      Frame: Number = 1417, Captured Frame Length = 404, MediaType = ETHERNET 
    + Ethernet: Etype = Internet IP (IPv4),DestinationAddress:[XXX],SourceAddress:[XXX]
    + Ipv4: Src = XXX, Dest = XXX, Next Protocol = TCP, Packet ID = 9696, Total IP Length = 390
    + Tcp: Flags=...AP..., SrcPort=1521, DstPort=LDAP(389), PayloadLen=350, Seq=3825204841 - 3825205191, Ack=1241404727, Win=16425 (scale factor 0x2) = 65700
    - Ldap: Search Request, MessageID: 1, BaseObject: NULL, SearchScope: base Object, SearchAlias: neverDerefAliases
      - Parser: Search Request, MessageID: 1
       + ParserHeader: 
       + MessageID: 1
       + OperationHeader: Search Request, 3(0x3)
       - SearchRequest: BaseDN: NULL, SearchScope: base Object, SearchAlias: neverDerefAliases
        + BaseObject: NULL
        + Scope: base Object
        + Alias: neverDerefAliases
        + SizeLimit: No Limit
        + TimeLimit: 120 seconds
        + TypesOnly: False
        - Filter: (objectclass Present)
         + Operator: Present, 7(0x07)
         - Length: 11
            Length: 11 bytes, LengthOfLength = 0
         + PresentFilter: objectclass Present
        - Attributes: ( subschemaSubentry )( dsServiceName )( namingContexts )( defaultNamingContext )( schemaNamingContext )( configurationNamingContext )( rootDomainNamingContext )( supportedControl )( supportedLDAPVersion )( supportedLDAPPolicies )( supportedSASLMec
         + AttributeSelectionHeader: 
         + Attribute: subschemaSubentry
         + Attribute: dsServiceName
         + Attribute: namingContexts
         + Attribute: defaultNamingContext
         + Attribute: schemaNamingContext
         + Attribute: configurationNamingContext
         + Attribute: rootDomainNamingContext
         + Attribute: supportedControl
         + Attribute: supportedLDAPVersion
         + Attribute: supportedLDAPPolicies
         + Attribute: supportedSASLMechanisms
         + Attribute: dnsHostName
         + Attribute: ldapServiceName
         + Attribute: serverName
         + Attribute: supportedCapabilities
    

    我请求的搜索范围或筛选器似乎都未在查询中使用。我尝试使用Softerra LDAP Administrator在“John_Smith”上执行根搜索,网络监视器显示了一个完美的LDAP查询,过滤器和搜索范围保持不变。

    我错过了什么?

    2 回复  |  直到 11 年前
        1
  •  2
  •   Aaron    14 年前

    我就是这样做的:

    searcher.Filter = "(&(objectClass=user)(|(cn=John_Smith)(sAMAccountName=John_Smith)))";
    

    一个很棒的广告网站就是我用的这个。

    http://www.codeproject.com/KB/system/everythingInAD.aspx

        2
  •  0
  •   Daeron Lockett    11 年前

    因此,发送的请求是对LDAP服务器功能(模式的位置、支持的LDAP版本等)的查询。LDAP/AD服务器可以使用请求的信息进行响应,也可以要求进行身份验证。在绑定到根条目时,您可以通过提供凭证来处理该步骤(绑定)。在为功能查询接收到searchresultsdone消息后,目录搜索者(实际上是底层LDAP类)将发送一个搜索请求,请求您所请求的信息。

    推荐文章