drkj41932 2018-02-09 17:45
浏览 132
已采纳

我想检查给定objectGUID的密码

I want to write a function that searchs a ldap user with objectGuid in GoLang.
I am using ldap as "gopkg.in/ldap.v2" for connecting ldap host.

l,_ :=ldap.Dial("tcp", fmt.Sprintf("%s:%d", host, 389))
defer l.Close()
l.Bind(adminuser, adminpass);
searchRequest := ldap.NewSearchRequest(
    "dc="+strings.Join(strings.Split(domain,"."),",dc="),
    ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 
    0,false,
    "(&(objectclass=person)(objectGUID=???SpecialFormat???))",
    []string{"dn"},
    nil,
)
sr, err := l.Search(searchRequest);
if err!=nil {
    log.Printf("Error %s",err);
}

       userdn := sr.Entries[0].DN; // I need UserDN for checking

       err=l.Bind(userdn, string(pass)) //checking password

My Code is like this.
I want to search a person that have a GUID like "445a1532-08aa-4a10-8a9c-d7f10f574afe".
But i guess, "The ldapsearch request" wants a different format for objectGUID.
How can i convert my GUIDString to needed format.

  • 写回答

1条回答 默认 最新

  • 普通网友 2018-02-16 11:55
    关注

    As far as I know object GUID must be passed to LDAP filters in a different format called Octet String.

    The format is simply a mangling of the hexadecimal values contained in the object Guid split as bytes (remember that a byte contains two hex digits).

    Example : "b0ae470c-16bc-4019-b455-8c96ec515f55" -> "\0c\47\ae\b0\bc\16\19\40\b4\55\8c\96\ec\51\5f\55"

    I've created a simple golang function in the Go Playground for you to play with.

    Hope this resolves your issue.

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

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程