php中的ldap_add返回“已经存在68"错误 [英] ldap_add in php returning "already exists 68" error

查看:583
本文介绍了php中的ldap_add返回“已经存在68"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是无法弄清楚自己在做什么,我已经在网上搜寻了答案,但找不到任何可行的方法.请有人可以看看我的代码,并告诉我我要去哪里了吗?如果我注释掉"objectclass",我得到服务器不愿执行53",如果我将OU更改为一个愚蠢的东西($ dn),则得到命名违规",如果我将键盘混搭并输入随机字母即使我输入的内容不存在,我的用户名仍然会出现已经存在"错误.如果我在同一OU中为另一个CN添加ldap_mod_replace行,则工作正常,因此我知道连接正常.我也尝试过在除对象类之外的所有对象上都没有'[0]'(正如我在所有示例中所看到的).公司和用户信息进行了明显的编辑.

I just cannot figure out what I'm doing wrong, I've scoured the web for answers but cannot find anything that works. Please can someone look at my code and tell me where I'm going wrong? If I comment out "objectclass" I get "server is unwilling to perform 53", if I change the OU to something silly (the $dn) then I get "Naming Violation", if I mash the keyboard and put in random letters for the user's name I still get "already exists" error even though no parts of the things I'm entering exist. If I add an ldap_mod_replace line in for another CN in the same OU it works fine so I know the connection is working. I've tried without the '[0]' on all except objectclass too (as I've seen in all examples). Company and user info edited obviously.

$server = "ldap://ServerName.domain.co.uk";
$dn = "OU=Advertising,OU=EmailDepartmentAccounts,OU=Administration,OU=Central,DC=domain,DC=co,DC=uk";

//domain user to connect to LDAP
$user = "helpdesk.ldap@domain.co.uk";
//user password
$psw = "Password";

$ds = ldap_connect($server);
if ($ds) {
    ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
    ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
    $r = ldap_bind($ds, $user, $psw);

    $proxyaddresses_array = array();
    $proxyaddresses_array[0] = "X400:c=GB;a= ;p=Company Name p;o=PWEXCHANGE;s=Kitbag;g=Digital;";
    $proxyaddresses_array[1] = "SMTP:test.maff@domain.co.uk";
    $proxyaddresses_array[2] = "smtp:test.maff@other.co.uk";

    //$NewUser = array();
    $NewUser["cn"][0] = "Test Maff1";
    $NewUser["userprincipalname"][0] = "Test.Maff1@domain.co.uk";
    $NewUser["samaccountname"][0] = "Test.Maff";
    $NewUser["objectClass"][0] = "top";
    $NewUser["objectClass"][1] = "person";
    $NewUser["objectClass"][2] = "organizationalPerson";
    $NewUser["objectClass"][3] = "user";
    //$NewUser["givenname"][0] = "Test";
    //$NewUser["sn"][0] = "Maff";
    //$NewUser["instancetype"][0] = 4;
    //$NewUser["physicaldeliveryofficename"][0] = "Leeds";
    //$NewUser["displayname"][0] = "Test Maff";
    //$NewUser["proxyaddresses"] = $proxyaddresses_array;
    //$NewUser["department"][0] = "IT";
    //$NewUser["company"][0] = "Company Name";
    //$NewUser["homemta"][0] = "CN=Microsoft MTA,CN=STH-EXC-01B,CN=Servers,CN=BSP,CN=Administrative Groups,CN=Johnston Press plc,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=domain,DC=co,DC=uk";
    //$NewUser["displaynameprintable"][0] = "Test Maff";
    //$NewUser["mailnickname"][0] = "Test.Maff";
    //$NewUser["useraccountcontrol"][0] = "512";
    //$NewUser["primarygroupid"][0] = "513";
    //$NewUser["name"] [0]= "Test Maff";
    $NewUser["objectcategory"][0] = "CN=Person,CN=Schema,CN=Configuration,DC=domain,DC=co,DC=uk";
    //$NewUser["mail"] = "Test.Maff@domain.co.uk";

    if ($NewUserAdded = ldap_add($ds, $dn, $NewUser)) {
        echo "success<br />";
    } else {
        echo ldap_error($ds) . " " . ldap_errno($ds);
    }
    ldap_close($ds);
} else {
    echo "unable to connect to LDAP server";
}

推荐答案

我可能是错的,但是从我在您的代码中看到的内容来看,您有一个条目OU=Advertising,OU=EmailDepartmentAccounts,OU=Administration,OU=Central,DC=domain,DC=co,DC=uk.据我解释您的代码,您想在该条目的下方添加一个条目.但是您必须提供 new 条目的DN作为ldap_add的第二个参数.但是,您需要提供新条目的 baseDN .那已经在那里.否则,您将无法向其中添加某些内容.

I might be wrong, but from what I read in your code you have an entry OU=Advertising,OU=EmailDepartmentAccounts,OU=Administration,OU=Central,DC=domain,DC=co,DC=uk. And as far as I interpret your code you want to add an entry below that entry. But you have to provide the DN of the new entry as second parameter to ldap_add. But you provide the baseDN of the new entry. and that is already there. Otherwise you wouldn't be able to add something into it.

因此,在调用ldap_add之前,应先调用类似以下的内容:

So you should call something like the following before calling the ldap_add:

$dn = 'cn=' . $NewUser['cn'][0] . ',' . $dn;

它使用baseDN并在其前面加上当前用户的cn.

That uses the baseDN and prepends it with the cn of the current user.

希望有帮助

这篇关于php中的ldap_add返回“已经存在68"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆