2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2011 The OpenLDAP Foundation.
5 * Portions Copyright 2001-2003 Pierangelo Masarati.
6 * Portions Copyright 1999-2003 Howard Chu.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by the Howard Chu for inclusion
19 * in OpenLDAP Software and subsequently enhanced by Pierangelo
27 #include <ac/socket.h>
28 #include <ac/string.h>
31 #include "../back-ldap/back-ldap.h"
32 #include "back-meta.h"
35 meta_back_modrdn( Operation *op, SlapReply *rs )
37 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
41 struct berval mdn = BER_BVNULL,
42 mnewSuperior = BER_BVNULL;
45 ldap_back_send_t retrying = LDAP_BACK_RETRYING;
46 LDAPControl **ctrls = NULL;
47 struct berval newrdn = BER_BVNULL;
49 mc = meta_back_getconn( op, rs, &candidate, LDAP_BACK_SENDERR );
50 if ( !mc || !meta_back_dobind( op, rs, mc, LDAP_BACK_SENDERR ) ) {
54 assert( mc->mc_conns[ candidate ].msc_ld != NULL );
56 mt = mi->mi_targets[ candidate ];
61 if ( op->orr_newSup ) {
64 * NOTE: the newParent, if defined, must be on the
65 * same target as the entry to be renamed. This check
66 * has been anticipated in meta_back_getconn()
69 * FIXME: one possibility is to delete the entry
70 * from one target and add it to the other;
71 * unfortunately we'd need write access to both,
72 * which is nearly impossible; for administration
73 * needs, the rootdn of the metadirectory could
74 * be mapped to an administrative account on each
75 * target (the binddn?); we'll see.
78 * NOTE: we need to port the identity assertion
79 * feature from back-ldap
83 switch ( mt->mt_version ) {
88 if ( op->o_protocol == 0 || op->o_protocol == LDAP_VERSION3 ) {
94 /* op->o_protocol cannot be anything but LDAPv3,
95 * otherwise wouldn't be here */
96 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
97 send_ldap_result( op, rs );
102 * Rewrite the new superior, if defined and required
104 dc.ctx = "newSuperiorDN";
105 if ( ldap_back_dn_massage( &dc, op->orr_newSup, &mnewSuperior ) ) {
106 rs->sr_err = LDAP_OTHER;
107 send_ldap_result( op, rs );
113 * Rewrite the modrdn dn, if required
116 if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
117 rs->sr_err = LDAP_OTHER;
118 send_ldap_result( op, rs );
122 /* NOTE: we need to copy the newRDN in case it was formed
123 * from a DN by simply changing the length (ITS#5397) */
124 newrdn = op->orr_newrdn;
125 if ( newrdn.bv_val[ newrdn.bv_len ] != '\0' ) {
126 ber_dupbv_x( &newrdn, &op->orr_newrdn, op->o_tmpmemctx );
131 if ( meta_back_controls_add( op, rs, mc, candidate, &ctrls ) != LDAP_SUCCESS )
133 send_ldap_result( op, rs );
137 rs->sr_err = ldap_rename( mc->mc_conns[ candidate ].msc_ld,
138 mdn.bv_val, newrdn.bv_val,
139 mnewSuperior.bv_val, op->orr_deleteoldrdn,
140 ctrls, NULL, &msgid );
141 rs->sr_err = meta_back_op_result( mc, op, rs, candidate, msgid,
142 mt->mt_timeout[ SLAP_OP_MODRDN ], ( LDAP_BACK_SENDRESULT | retrying ) );
143 if ( rs->sr_err == LDAP_UNAVAILABLE && retrying ) {
144 retrying &= ~LDAP_BACK_RETRYING;
145 if ( meta_back_retry( op, rs, &mc, candidate, LDAP_BACK_SENDERR ) ) {
146 /* if the identity changed, there might be need to re-authz */
147 (void)mi->mi_ldap_extra->controls_free( op, rs, &ctrls );
153 (void)mi->mi_ldap_extra->controls_free( op, rs, &ctrls );
155 if ( mdn.bv_val != op->o_req_dn.bv_val ) {
160 if ( !BER_BVISNULL( &mnewSuperior )
161 && mnewSuperior.bv_val != op->orr_newSup->bv_val )
163 free( mnewSuperior.bv_val );
164 BER_BVZERO( &mnewSuperior );
167 if ( newrdn.bv_val != op->orr_newrdn.bv_val ) {
168 op->o_tmpfree( newrdn.bv_val, op->o_tmpmemctx );
172 meta_back_release_conn( mi, mc );