如何通过php移动eDirectory条目?
我有以下ldap条目:如何通过php移动eDirectory条目?,php,ldap,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\u重命名 ldap_rename($connection, "cn=blah,ou=apples,ou=people,dc=yay,dc=edu", "cn=blah", "ou=oranges,ou=people,
cn=blah,ou=apples,ou=people,dc=yay,dc=edu
我需要将该条目移动到:
cn=blah,ou=oranges,ou=people,dc=yay,dc=edu
我的脚本都是PHP,所以我一直在尝试使用PHP.net/ldap\u重命名
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
此注释提到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上
因此,听起来我必须创建一个新条目,复制属性,删除旧条目。就像我上面提到的第二个痛苦的选择 我最后使用了“创建新条目,删除旧条目”的方法。我仍然认为我有另一种工作方式,但我不记得是什么。这是一个基本的移动函数
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;
}
}
希望这有助于某些人 实际上不需要在eDir中重新创建。在运行IDM的环境中执行重新创建会导致问题,因为对象将具有新的GUID,并且IDM引擎不会将事件视为真正的“移动” 以下代码可以很好地移动用户(已测试的eDir 8.8.x和eDir 9.x): 别忘了给复制一点时间
还考虑修改或移动对象的约束,这些对象仍在从先前的移动事件中复制。
尝试:
ldap_rename($ldapconn, "cn=blah,ou=apples,ou=people,dc=yay,dc=edu", "cn=blah", "ou=oranges,ou=people,dc=yay,dc=edu", true);
您能告诉我您正在运行的LDAP的版本吗?声明中的注释明确提到了重命名和不移动条目。所以它不适用于这里。您是否尝试在第三个参数中给它一个完整的dn?您确定绑定到LDAP的用户具有足够的权限吗?LDAP v3。在前面的代码中,我明确地设置了协议。我正在测试的用户是目录的主要管理员。所以它有正确的perms。只是尝试将完整的新dn传递给第三个参数。ldap_rename返回true,但eDirectory未移动条目。请注意,函数的第5行到最后一行缺少右括号。它应该是(ldap\u delete($connection,ldap\u get\u dn($connection,$ldapEntryReference))){
ldap_rename($ldapconn, "cn=blah,ou=apples,ou=people,dc=yay,dc=edu", "cn=blah", "ou=oranges,ou=people,dc=yay,dc=edu", true);