douao8353 2018-02-28 01:17
浏览 176
已采纳

LDAP搜索ContextCSN

Good evening, I'm relatively new to go and try to write a function exporting the contextCSN variable from an openldap directory (analogous to ldapsearch -x -s base contextCSN) From the documentation of ldap.v2 I came up with this:

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,
)

But it doesn't accept contextCSN as search term

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

Is there a way to query for this value without invoking ldapsearch?

Update: After staring at the output of ldapsearch for a while I came up with this, which did solve the problem. The data is a bit ugly structured but otherwise provides what I needed:

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") {
        ...
    }
}
  • 写回答

1条回答 默认 最新

  • doudi8298 2018-02-28 07:47
    关注

    (contextCSN) is not a filter, it should be something like (sn=%s) which you want to query

    Leave it empty or change your filter as it suits you

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥15 关于communitytoolkit.mvvm的生成器得到的代码看起来没有被使用的问题
    • ¥15 matlab中此类型的变量不支持使用点进行索引
    • ¥15 咨询第六届工业互联网数据创新大赛原始数据
    • ¥15 Pycharm无法自动补全,识别第三方库函数接收的参数!
    • ¥15 STM32U575 pwm和DMA输出的波形少一段
    • ¥30 android百度地图SDK海量点显示标题
    • ¥15 windows导入environment.yml运行conda env create -f environment_win.yml命令报错
    • ¥15 这段代码可以正常运行,打包后无法执行,在执行for内容之前一直不断弹窗,请修改调整
    • ¥15 C语言判断有向图是否存在环路
    • ¥15 请问4.11到4.18以及4.27和4.29公式的具体推导过程是怎样的呢