gpt4 book ai didi

c - C/Go 中的 LDAP : Error code 53 "Server is unwilling to perfom" when trying to set unicodePwd

转载 作者:数据小太阳 更新时间:2023-10-29 03:16:27 31 4
gpt4 key购买 nike

所以我正在用 Go 编写一个程序,由于 CGo,我使用 C 绑定(bind),并且我正在使用 ldap 来执行搜索、添加和修改操作。我可以设法做到所有这些,但现在我试图在 unicodePwd mod_type 中设置密码,但我似乎无法解决错误 53:服务器不愿意执行。

我知道很多东西会导致这个错误,所以:我与 ldaps 连接。为了测试目的,我硬编码了一个由 10 个字符组成的密码,开头和结尾都带有双引号,并以 UTF-16LE、Base64 格式获得了该密码。密码有小写字母、大写字母和标点符号。

这是我的一些代码示例,我现在只是在测试一些东西,所以编码真的很糟糕:

设置选项:C.ldap_set_option(l, LDAP_OPT_PROTOCOL_VERSION, unsafe.Pointer(&version))
C.ldap_set_option(l, LDAP_OPT_REFERRALS, unsafe.Pointer(&v))

初始化:C.ldap_initialize(&l, C.CString("ldaps://**.**.**.**:636"))

绑定(bind):rc := C.ldap_simple_bind_s(l, C.CString("CN=Administrator,CN=Users,DC=intra,DC=localdomain,DC=com"), C.CString("* *********"))

现在是重要的部分,添加一个带密码的用户:

add_user(l, "ldaps://**.**.**.**", "636", "CN=Administrator,CN=Users,DC=intra,DC=localdomain,DC=com", "OU=*******,DC=intra,DC=localdomain,DC=com")

func add_user(l *C.LDAP, host string, port string, login string, container string) {

var mods [5]*C.LDAPModStr
var modClass, modCN, modSN, modPass C.LDAPModStr
var vclass [5]*C.char
var vcn [4]*C.char
var vsn [2]*C.char
var vpass [2]*C.char
modClass.mod_op = 0
modClass.mod_type = C.CString("objectclass")
vclass[0] = C.CString("top")
vclass[1] = C.CString("person")
vclass[2] = C.CString("organizationalPerson")
vclass[3] = C.CString("User")
vclass[4] = nil
modClass.mod_vals = &vclass[0]

modCN.mod_op = 0
modCN.mod_type = C.CString("cn")
vcn[0] = C.CString("john")
vcn[1] = nil
modCN.mod_vals = &vcn[0]

modSN.mod_op = 0
modSN.mod_type = C.CString("sn")
vsn[0] = C.CString("mclane")
vsn[1] = nil
modSN.mod_vals = &vsn[0]

modPass.mod_op = 0
modPass.mod_type = C.CString("unicodePwd")
vpass[0] = C.CString("IgBTAHcAZQBlAHQATgBlAHcAUAB3AGQAMQAyADMAIQAiAA==")
vpass[1] = nil
modPass.mod_vals = &vpass[0]

mods[0] = &modClass
mods[1] = &modCN
mods[2] = &modSN
mods[3] = &modPass
mods[4] = nil

dn := "cn=john,OU=*********,DC=intra,DC=localdomain,DC=com"

rc := C._ldap_add(l, C.CString(dn), &mods[0])

if rc != LDAP_SUCCESS {
er := C.ldap_err2string(rc)
fmt.Println("ADD ERROR")
fmt.Println(rc)
fmt.Println(C.GoString(er))
}

哦,这里是 LDAPModStr 类型的定义:

typedef struct ldapmod_str {
int mod_op;
char *mod_type;
char **mod_vals;} LDAPModStr;

和 _ldap_add :

int _ldap_add(LDAP *ld, char* dn, LDAPModStr **attrs){

return ldap_add_ext_s(ld, dn, (LDAPMod **)attrs, NULL, NULL);
}

我可能在这里遗漏了一些明显的东西,因为我对 GO 和 LDAP 有点陌生,但如果你能帮助我解决这个问题,我将非常感激。我不知道这是否相关,但程序连接到 Windows Server 2012 R2 的 Active Directory,它在虚拟机中的同一台计算机上运行。我也是新来的,如果对您来说更容易的话,我可以在这里发布我的所有代码,但我认为只发布重要步骤可能更好。

最佳答案

我不知道是否有人会感兴趣,但我在@kostix 的帮助下找到了一个解决方案,我想我会分享:C 中的扩展修改操作(使用 CGO)不起作用,但是一个简单的使用正确编码的 go-ldap 修改操作允许我在 Windows AD 上更改用户密码。

关于c - C/Go 中的 LDAP : Error code 53 "Server is unwilling to perfom" when trying to set unicodePwd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33098380/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com