1 /* modrdn.c - ldap backend modrdn function */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1999-2004 The OpenLDAP Foundation.
6 * Portions Copyright 1999-2003 Howard Chu.
7 * Portions Copyright 2000-2003 Pierangelo Masarati.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
14 * A copy of this license is available in the file LICENSE in the
15 * top-level directory of the distribution or, alternatively, at
16 * <http://www.OpenLDAP.org/license.html>.
19 * This work was initially developed by the Howard Chu for inclusion
20 * in OpenLDAP Software and subsequently enhanced by Pierangelo
28 #include <ac/socket.h>
29 #include <ac/string.h>
32 #include "back-ldap.h"
39 struct ldapinfo *li = (struct ldapinfo *) op->o_bd->be_private;
43 LDAPControl **ctrls = NULL;
45 int rc = LDAP_SUCCESS;
47 struct berval mdn = BER_BVNULL, mnewSuperior = BER_BVNULL;
49 lc = ldap_back_getconn( op, rs );
50 if ( !lc || !ldap_back_dobind(lc, op, rs) ) {
54 dc.rwmap = &li->rwmap;
63 int version = LDAP_VERSION3;
64 ldap_set_option( lc->ld, LDAP_OPT_PROTOCOL_VERSION, &version);
67 * Rewrite the new superior, if defined and required
70 dc.ctx = "newSuperiorDN";
72 if ( ldap_back_dn_massage( &dc, op->orr_newSup,
74 send_ldap_result( op, rs );
80 * Rewrite the modrdn dn, if required
85 if ( ldap_back_dn_massage( &dc, &op->o_req_ndn, &mdn ) ) {
86 send_ldap_result( op, rs );
91 #ifdef LDAP_BACK_PROXY_AUTHZ
92 rc = ldap_back_proxy_authz_ctrl( lc, op, rs, &ctrls );
93 if ( rc != LDAP_SUCCESS ) {
94 send_ldap_result( op, rs );
98 #endif /* LDAP_BACK_PROXY_AUTHZ */
101 rs->sr_err = ldap_rename( lc->ld, mdn.bv_val,
102 op->orr_newrdn.bv_val, mnewSuperior.bv_val,
103 op->orr_deleteoldrdn,
106 rc = ldap_back_op_result( lc, op, rs, msgid, 1 );
107 if ( rs->sr_err == LDAP_SERVER_DOWN && do_retry ) {
109 if ( ldap_back_retry (lc, op, rs )) goto retry;
112 #ifdef LDAP_BACK_PROXY_AUTHZ
114 if ( ctrls && ctrls != op->o_ctrls ) {
118 #endif /* LDAP_BACK_PROXY_AUTHZ */
120 if ( mdn.bv_val != op->o_req_ndn.bv_val ) {
123 if ( mnewSuperior.bv_val != NULL
124 && mnewSuperior.bv_val != op->oq_modrdn.rs_newSup->bv_val ) {
125 free( mnewSuperior.bv_val );