php - 如何通过 php 移动 eDirectory 条目?

标签 php ldap edirectory

我有这个 ldap 条目:

cn=blah,ou=apples,ou=people,dc=yay,dc=edu

我需要将该条目移动到:

cn=blah,ou=oranges,ou=people,dc=yay,dc=edu

我的脚本都是 PHP,所以我一直在尝试使用 php.net/ldap_rename

ldap_rename($connection, "cn=blah,ou=apples,ou=people,dc=yay,dc=edu", "cn=blah", "ou=oranges,ou=people,dc=yay,dc=edu", true);

不起作用。它返回 false。

http://us2.php.net/manual/en/function.ldap-rename.php#82393注释提到 eDirectory 想要将父项保留为 NULL。喜欢:

ldap_rename($connection, "cn=blah,ou=apples,ou=people,dc=yay,dc=edu", "cn=blah", NULL, true);

返回 TRUE 但实际上并不移动条目。不足为奇,因为它没有改变父...我确定它可以将 cn=blah 更改为其他内容...

我想删除条目并重新创建它。但这是一种痛苦的方式。写出并运行 LDIF 文件也会很痛苦。

那么,如何在 php 中将一个条目从一个 OU 移动到另一个 OU,而不用担心其他两个选项?

我在运行什么:

  • Ubuntu 12.04 LTS
  • PHP 5.3.10
  • eDirectory 8.8 在 SLES 11 上

编辑

所以,我发现了这个:

The modrdn change type cannot move an entry to a completely different subtree. To move an entry to a completely different branch, you must create a new entry in the alternative subtree using the old entry's attributes, and then delete the old entry.

来自 http://www.centos.org/docs/5/html/CDS/ag/8.0/Creating_Directory_Entries-LDIF_Update_Statements.html

我发现其他几个页面也有类似的陈述。

所以听起来我必须创建一个新条目,复制属性,然后删除旧条目。就像我上面提到的第二个痛苦的选择。

最佳答案

好吧,我最终使用了“创建新条目,删除旧条目”的方法。我仍然认为我之前有另一种工作方式,但我不记得是什么了。所以这是一个基本的移动功能。

function move($connection, $ldapEntryReference, $new_dn){        
    //First, get the values of the current attributes.
    $attributes = array(); //start attributes array
    $firstattr = ldap_first_attribute($connection, $ldapEntryReference);
    $value = ldap_get_values($connection, $ldapEntryReference, $firstattr);
    $attributes[$firstattr] = $value;
    while($attr = ldap_next_attribute($connection, $ldapEntryReference)) {
        if (strcasecmp($attr, 'ACL') !== 0) { //We don't want ACL attributes since 
                                              //eDir/ldap should deal with them for us.
            if (strcasecmp($attr, 'jpegPhoto') === 0) {
                //binary values need to use the ldap_get_values_len function.
                $value = ldap_get_values_len($this->connection, $ldapEntryReference, $attr);
            } else {
                $value = ldap_get_values($this->connection, $ldapEntryReference, $attr);
            }
            $attributes[$attr] = $value;
        }
    }
    //Create a new entry array with the values.
    $entry = array(); //start entry array.
    foreach($attributes as $key => $value) {
        foreach($value as $key2 => $value2) {
            if (strcasecmp($key2, 'count') !== 0) {//get rid of 'count' indexes
                                                   //ldap_add chokes on them.
                $entry[$key][$key2] = $value2;
            }
        }
    }
    //Add the new entry.
    if (ldap_add($connection, $new_dn, $entry)) {
        //Delete the old entry.
        if (ldap_delete($connection, ldap_get_dn($connection, $ldapEntryReference)) {
            return true;
        } else {
            return false;
        }
    } else {
        return false; 
    }
}

希望这有时能对某人有所帮助。

关于php - 如何通过 php 移动 eDirectory 条目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17035037/

相关文章:

php - 传递消息时出错 我自己的 PHP Chat

ruby - 进入域后如何配置静默登录Redmine?

java - eDirectory 查询返回不愿意执行 LDAPSearchException

php - 查找两个接近相同的值mysql

php - 在 PHP 动态创建时缓存 HTTP 响应

objective-c - LDAP 身份验证,ldap_sasl_bind_s 不工作但 ldap_simple_bind_s 工作

mysql - 使用 LDAP (AD) 进行 MySQL 身份验证

ssl - 如何从 OpenSSL 保存 LDAP SSL 证书

php - Drupal 7 错误导致 php 最大超时