我有这个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);不管用。结果是假的。
这个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,而不受其他两个选项的影响?
我所要做的是:
编辑
所以,我发现了这个
modrdn更改类型不能将条目移动到完全不同的子树。要将条目移动到完全不同的分支,您必须使用旧条目的属性在替代子树中创建一个新条目,然后删除旧条目。
来自Statements.html
我发现其他几页也有类似的陈述。
所以听起来我需要做一个新的条目,复制属性,删除旧的。就像我上面提到的第二个痛苦的选择。
发布于 2013-06-14 19:42:16
最后,我使用了“创建新条目,删除旧条目”的方法。我还以为我以前还有别的办法,但我记不起来是什么了。这是一个基本的移动函数。
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;
}
}希望这能对某人有所帮助。
发布于 2016-10-12 01:37:37
实际上,没有必要在eDir中重新创建。重新创建会在运行IDM的环境中引起问题,因为对象将有一个新的GUID,IDM引擎将不会将事件视为真正的“移动”。
下面的代码可以移动用户(经过测试的eDir 8.8.x和eDir 9.x):
$olduserdn = "cn=userid,ou=container1,o=org";
$newdestdn = "ou=container2,o=org";
if (preg_match('/^(cn=[A-Za-z0-9]+)\,(.+)/i', $olduserdn, $rdnmatches))
{
if (ldap_rename($ldapconn, $olduserdn, $rdnmatches[1], $newdestdn, TRUE))
{
print("Moved $olduserdn to $rdnmatches[1],$newdestdn");
}
else
{
print("Failed move because " . ldap_error($ldapconn));
}
}别忘了给点时间复制.
还要考虑修改/移动对象的约束,这些对象仍然是从以前的移动事件中复制的。
发布于 2018-10-10 19:56:27
试试这个:
ldap_rename($ldapconn, "cn=blah,ou=apples,ou=people,dc=yay,dc=edu", "cn=blah", "ou=oranges,ou=people,dc=yay,dc=edu", true);https://stackoverflow.com/questions/17035037
复制相似问题