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 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同