2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2005 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 struct metainfo *li = ( struct metainfo * )op->o_bd->be_private;
41 struct berval mdn = BER_BVNULL,
42 mnewSuperior = BER_BVNULL;
45 lc = meta_back_getconn( op, rs, &candidate, LDAP_BACK_SENDERR );
50 assert( candidate != META_TARGET_NONE );
52 if ( !meta_back_dobind( lc, op, LDAP_BACK_SENDERR ) ) {
56 if ( !meta_back_is_valid( lc, candidate ) ) {
57 rs->sr_err = LDAP_OTHER;
58 send_ldap_result( op, rs );
65 if ( op->orr_newSup ) {
66 int version = LDAP_VERSION3;
69 * NOTE: the newParent, if defined, must be on the
70 * same target as the entry to be renamed. This check
71 * has been anticipated in meta_back_getconn()
74 * FIXME: one possibility is to delete the entry
75 * from one target and add it to the other;
76 * unfortunately we'd need write access to both,
77 * which is nearly impossible; for administration
78 * needs, the rootdn of the metadirectory could
79 * be mapped to an administrative account on each
80 * target (the binddn?); we'll see.
83 * NOTE: we need to port the identity assertion
84 * feature from back-ldap
87 /* newSuperior needs LDAPv3; if we got here, we can safely
89 ldap_set_option( lc->mc_conns[ candidate ].msc_ld,
90 LDAP_OPT_PROTOCOL_VERSION, &version );
93 * Rewrite the new superior, if defined and required
95 dc.rwmap = &li->mi_targets[ candidate ]->mt_rwmap;
96 dc.ctx = "newSuperiorDN";
97 if ( ldap_back_dn_massage( &dc, op->orr_newSup, &mnewSuperior ) ) {
104 * Rewrite the modrdn dn, if required
106 dc.rwmap = &li->mi_targets[ candidate ]->mt_rwmap;
108 if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
113 rc = ldap_rename_s( lc->mc_conns[ candidate ].msc_ld, mdn.bv_val,
114 op->orr_newrdn.bv_val,
116 op->orr_deleteoldrdn,
117 op->o_ctrls, NULL ) != LDAP_SUCCESS;
120 if ( mdn.bv_val != op->o_req_dn.bv_val ) {
125 if ( !BER_BVISNULL( &mnewSuperior )
126 && mnewSuperior.bv_val != op->orr_newSup->bv_val )
128 free( mnewSuperior.bv_val );
129 BER_BVZERO( &mnewSuperior );
133 return meta_back_op_result( lc, op, rs, candidate ) == LDAP_SUCCESS
137 send_ldap_result( op, rs );