2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2004 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, META_OP_REQUIRE_SINGLE,
46 &op->o_req_ndn, &candidate );
52 if ( !meta_back_dobind( lc, op )
53 || !meta_back_is_valid( lc, candidate ) ) {
54 rs->sr_err = LDAP_OTHER;
62 if ( op->oq_modrdn.rs_newSup ) {
63 int nsCandidate, version = LDAP_VERSION3;
65 nsCandidate = meta_back_select_unique_candidate( li,
66 op->oq_modrdn.rs_nnewSup );
68 if ( nsCandidate != candidate ) {
70 * FIXME: one possibility is to delete the entry
71 * from one target and add it to the other;
72 * unfortunately we'd need write access to both,
73 * which is nearly impossible; for administration
74 * needs, the rootdn of the metadirectory could
75 * be mapped to an administrative account on each
76 * target (the binddn?); we'll see.
79 * FIXME: is this the correct return code?
81 rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
86 ldap_set_option( lc->conns[ nsCandidate ].ld,
87 LDAP_OPT_PROTOCOL_VERSION, &version );
90 * Rewrite the new superior, if defined and required
92 dc.rwmap = &li->targets[ nsCandidate ]->rwmap;
93 dc.ctx = "newSuperiorDN";
94 if ( ldap_back_dn_massage( &dc, op->oq_modrdn.rs_newSup, &mnewSuperior ) ) {
101 * Rewrite the modrdn dn, if required
103 dc.rwmap = &li->targets[ candidate ]->rwmap;
105 if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
110 ldap_rename2_s( lc->conns[ candidate ].ld, mdn.bv_val,
111 op->oq_modrdn.rs_newrdn.bv_val,
113 op->oq_modrdn.rs_deleteoldrdn );
116 if ( mdn.bv_val != op->o_req_dn.bv_val ) {
120 if ( mnewSuperior.bv_val != NULL
121 && mnewSuperior.bv_val != op->oq_modrdn.rs_newSup->bv_val ) {
122 free( mnewSuperior.bv_val );
126 return meta_back_op_result( lc, op, rs ) == LDAP_SUCCESS
130 send_ldap_result( op, rs );