dqs66973 2015-09-18 06:46
浏览 253
已采纳

php中的ldap_add返回“已存在68”错误

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";
}
  • 写回答

1条回答 默认 最新

  • duanlang1196 2015-09-19 16:52
    关注

    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.

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

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

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

    Hope that helps

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

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵