转到LDAP搜索ContextCSN

问题描述 投票:0回答:1

晚上好,我是比较新的去尝试编写一个从openldap目录中导出contextCSN变量的函数(类似于ldapsearch -x -s base contextCSN)从文档of ldap.v2我想出了这个:

searchRequest := ldap.NewSearchRequest(
  baseDN, // The base dn to search
  ldap.ScopeBaseObject, ldap.NeverDerefAliases, 0, 0, false,
  "(contextCSN)", // The filter to apply
  []string{"contextCSN"},     // A list attributes to retrieve
  nil,
)

但它不接受contextCSN作为搜索词

LDAP Result Code 201 "Filter Compile Error": ldap: error parsing filter
exit status 1

有没有办法在不调用ldapsearch的情况下查询此值?

更新:在盯着ldapsearch的输出一段时间后,我想出了这个,这确实解决了问题。数据有点难看,但另外提供了我需要的东西:

l, err := ldap.DialTLS("tcp", ldapHost, conf)
if err != nil {
    log.Fatal(err)
}
defer l.Close()

searchRequest := ldap.NewSearchRequest(
    baseDN, // The base dn to search
    ldap.ScopeBaseObject, ldap.NeverDerefAliases, 0, 0, false,
    "(objectClass=*)",      // The filter to apply
    []string{"contextCSN"}, // A list attributes to retrieve
    nil,
)

sr, err := l.Search(searchRequest)
if err != nil {
    log.Fatal(err)
}

for _, entry := range sr.Entries {
    for _, csn := range entry.GetAttributeValues("contextCSN") {
        ...
    }
}
go ldap openldap
1个回答
0
投票

(contextCSN)不是过滤器,它应该是您想要查询的(sn =%s)

保持空白或更换适合您的过滤器

© www.soinside.com 2019 - 2024. All rights reserved.