我正在尝试使用 Go 中的 ldap 重置 MS Active Directory 密码属性。AD 不能很好地发挥作用,ldap.PasswordModifyRequest所以我正在使用ldap.NewModifyRequest. (使用 gopkg.in/ldap.v2)
AD 将接受用引号引起来的密码和 utf16le 编码,在 Python 中我可以使用
unicode_pass = unicode("\"secret\"", "iso-8859-1")
password_value = unicode_pass.encode("utf-16-le")
mod_attrs = [(ldap.MOD_REPLACE, "unicodePwd", [password_value])]
l.modify_s(user_dn, mod_attrs)
Run Code Online (Sandbox Code Playgroud)
我怎样才能在 Go 中做到这一点?使用ldap.NewModifyRequest和Replace我可以更改其他属性,但我需要传递Request []string更新的值,这需要是我的编码密码,并且当我玩...时遇到类型不匹配的utf16.Encode问题
modify := ldap.NewModifyRequest(dn)
modify.Replace("unicodePwd", []string{"encodedsecret"})
Run Code Online (Sandbox Code Playgroud)
谢谢。
您可以使用golang.org/x/text/encoding/unicode包将字符串编码为 UTF16。
使用这个包你可以写这样的东西:
utf16 := unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM)
encoded, err := utf16.NewEncoder().String("encodedsecret")
modify := ldap.NewModifyRequest(dn)
modify.Replace("unicodePwd", []string{encoded})
// do something with modify
Run Code Online (Sandbox Code Playgroud)