PHP Doku:: Verändert den Namen eines Eintrags - function.ldap-rename.html

Verlauf / Chronik / History: (22) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzSonstige DiensteLightweight Directory Access ProtocolLDAP Funktionenldap_rename

Ein Service von Reinhard Neidl - Webprogrammierung.

LDAP Funktionen

<<ldap_read

ldap_sasl_bind>>

ldap_rename

(PHP 4 >= 4.0.5, PHP 5)

ldap_rename Verändert den Namen eines Eintrags

Beschreibung

bool ldap_rename ( resource $Verbindungs-Kennung , string $dn , string $neuerrdn , string $neueeltern , bool $löschealtenrdn )

Der Eintrag, der durch dn gegeben ist, wird umbenannt/gelöscht. Der neue RDN wird durch neuerrdn bestimmt, der neue Eltern-/übergeordnete Eintrag wird durch neueeltern bestimmt. Wenn das Argument löschealtenrdn TRUE ist, wird der alte Wert/die alten Werte von RDN enfernt, andernfalls wird der alte Wert/die alten Werte als nicht-eindeutige(r) (non- distinguished) Werte des Eintrags beibehalten. Gibt bei Erfolg TRUE zurück. Im Fehlerfall wird FALSE zurückgegeben.

Hinweis:

Diese Funktion arbeitet zum gegenwärtigen Zeitpunkt nur mit LDAPv3. Sie müssen ldap_set_option() vorher benutzen um für eine Bindung LDAPv3 nutzen zu können. Diese Funktion steht nur zur Verfügung, wenn Sie OpenLDAP 2.x.x ODER Netscape Directory SDK x.x benutzen. Wurde in PHP 4.0.5 hinzugefügt.


9 BenutzerBeiträge:
- Beiträge aktualisieren...
Peter Kehl
9.04.2008 11:51
Here's some clarification about the parameters when renaming a container in Novell eDirectory:
- $new_rdn is in format "ou=new container name"
- newparent parameter is NULL - because we're renaming and not moving
- deleteoldrdn parameter if TRUE then old value of OU attribute is stored as a secondary/further value of LDAP OU attribute. Novell ConsoleOne shows it as 'Other Name' attribute.

$full_old_dn= "ou=Cuckoo,ou=London,ou=UK,ou=Europe,o=Happy";
$new_rdn= "ou=Cuckoo Group";
   
ldap_rename( $conn, $full_old_dn, $new_rdn, NULL, TRUE);
backports at gmail dot com
15.06.2007 16:26
Though clearly mentioned, the following had me in spin for a good 10 minutes.

Ensure:

if (!ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3)) {
   // do something horrible
}

has been set _before_ you actually bind :)
hyc at openldap dot org
6.10.2005 13:49
Contrary to Richard Esplin's statement, this *is* the correct function to use for renaming subtrees and moving entries from one place in the tree to another. Just that most LDAP server implementations don't support moving non-leaf entries.

E.g. In OpenLDAP, moving a non-leaf entry is only supported when using the back-hdb database backend. SunOne only has one database backend, and it apparently doesn't handle this type of operation.
venakis at ccf dot auth dot gr
18.10.2004 11:52
If you are using Sun Directory Server 5.2, please note that you can't use ldap_rename to move an entry. According to Sun's own documentation: "[...] At this point in time, Directory Server does not support the ability to use the modify DN operation to move an entry from one location in the directory tree to another location." (http://docs.sun.com/source/817-6707/resultcodes.html)
The problem is that php does not return any error and the operation seems to complete succesfully, except for the fact that nothing really happens. If you check the server logs, there will be an "error 53" entry (server is unwilling to perform).
hope this saves someone's couple of hours nasty searching...
cory at shopwithafriend dot net
13.08.2004 0:21
When setting a new Rdn value be sure to escape any commas that are not path designators.  I spent several hours trying to move user nodes in AD since their cn was set wrong.  We wanted the cn to be set to: lastname, firstname.

<?php
//In this example we are renaming a node with cn of "jsmith" to "Smith, John"

/*
Setting some variables to values for display purposes.
In a real script the values would probably come from some outside source (file, ldap query, etc...)
*/
$dn = 'cn=jsmith,ou=mygroup,dc=mydomain';
$name = "Smith, John";

// Now replace those pesky commas
$newRdn = "cn=" . str_replace(",", "\\,", $name);

ldap_rename($link, $dn, $newRdn, $newParent, true);
?>
Viper_SB at NOSPAMyahoo dot com
30.06.2004 11:41
Since this function isn't documented to well I thought I'd help out those trying to get this to work.

<?php
// $dn is the full DN of the entry you wish to move
$dn = 'cn=user1,ou=group1,dc=mydomain';
/*
    note that $newRdn IS NOT a full DN, it is only the start
    I've NOT gotten it to change attributes for the RDN
    but that could just be my schema
*/
$newRdn = 'cn=user2';
// $newparent IS the full DN to the NEW parent DN that you want to move/rename to
$newParent = 'ou=group2,dc=mydomain';
ldap_rename($link, $dn, $newRdn, $newParent, true);
?>

Like I said above I haven't been able to get it to rename to a DIFFERENT attribute so deleteoldrdn has no affect on it.
Richard Esplin
16.11.2003 3:37
ldap_rename can only move leaf nodes of the directory tree. If your ldap entry has any child entries, then ldap_rename is not the tool that you need. We needed to change usernames, but that alters the dn. ldap_rename wouldn't work because each of our user ldap entries has a couple associated child entries. We had to write a function to recursively copy the subtree to the new location, and then delete the original version. Here is the basic algorithm:

function recursive_move($old_username, $new_username)
    ldap_search on the old username to get the correct entry
    ldap_get_attributes to get an array of values from the ldap entry
    foreach attribute in array, replace occurences of $old_username with $new_username
    ldap_add the attribute array into the new location
    ldap_modify any additional attributes
    ldap_list each child entry
    call function recursive_move on each child
    ldap_delete current entry
    return
alex at netflex dot nl
16.10.2002 17:29
Works also with eDirectory 8 (NW6).

If you are moving a user, remember that you also change the uid!

4.04.2002 13:10
To get this function working make sure that the value for $newrdn is relative.



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)