如何通过php移动eDirectory条目?

时间:2013-06-11 00:56:05

标签: 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上

修改

所以,我发现了这个:

  

modrdn更改类型无法将条目移动到完全不同的子树。要将条目移动到完全不同的分支,必须使用旧条目的属性在备用子树中创建新条目,然后删除旧条目。

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

我发现了其他一些有类似陈述的网页。

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

3 个答案:

答案 0 :(得分:2)

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

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; 
    }
}

希望有时可以帮到某人。

答案 1 :(得分:0)

实际上不需要在eDir中重新创建。执行重新创建会导致运行IDM的环境出现问题,因为对象将具有新的GUID,并且IDM引擎不会将该事件视为真正的“移动”。

以下代码可以很好地移动用户(测试eDir 8.8.x和eDir 9.x):

  @media (min-width: 1076px) and (min-width: 979px) {
    .row-fluid .span2 {
      margin-left: 5.5%;
    }
  }

  @media (max-width: 979px) and (min-width: 768px) {
    .row-fluid .span2 {
      margin-left: 5.5%;
    }
  }

  .center {
    float: none !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }

不要忘记给复制一些时间......

还要考虑修改/移动仍在从先前移动事件复制的对象的约束。

答案 2 :(得分:0)

尝试一下:

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