modrdn.c revision 1.3 1 1.3 christos /* $NetBSD: modrdn.c,v 1.3 2021/08/14 16:15:00 christos Exp $ */
2 1.1 tron
3 1.1 tron /* modrdn.c - mdb backend modrdn routine */
4 1.1 tron /* $OpenLDAP$ */
5 1.1 tron /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6 1.1 tron *
7 1.3 christos * Copyright 2000-2021 The OpenLDAP Foundation.
8 1.1 tron * All rights reserved.
9 1.1 tron *
10 1.1 tron * Redistribution and use in source and binary forms, with or without
11 1.1 tron * modification, are permitted only as authorized by the OpenLDAP
12 1.1 tron * Public License.
13 1.1 tron *
14 1.1 tron * A copy of this license is available in the file LICENSE in the
15 1.1 tron * top-level directory of the distribution or, alternatively, at
16 1.1 tron * <http://www.OpenLDAP.org/license.html>.
17 1.1 tron */
18 1.1 tron
19 1.2 christos #include <sys/cdefs.h>
20 1.3 christos __RCSID("$NetBSD: modrdn.c,v 1.3 2021/08/14 16:15:00 christos Exp $");
21 1.2 christos
22 1.1 tron #include "portable.h"
23 1.1 tron
24 1.1 tron #include <stdio.h>
25 1.1 tron #include <ac/string.h>
26 1.1 tron
27 1.1 tron #include "back-mdb.h"
28 1.1 tron
29 1.1 tron int
30 1.1 tron mdb_modrdn( Operation *op, SlapReply *rs )
31 1.1 tron {
32 1.1 tron struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
33 1.1 tron AttributeDescription *children = slap_schema.si_ad_children;
34 1.1 tron AttributeDescription *entry = slap_schema.si_ad_entry;
35 1.1 tron struct berval p_dn, p_ndn;
36 1.1 tron struct berval new_dn = {0, NULL}, new_ndn = {0, NULL};
37 1.1 tron Entry *e = NULL;
38 1.1 tron Entry *p = NULL;
39 1.1 tron /* LDAP v2 supporting correct attribute handling. */
40 1.1 tron char textbuf[SLAP_TEXT_BUFLEN];
41 1.1 tron size_t textlen = sizeof textbuf;
42 1.1 tron MDB_txn *txn = NULL;
43 1.1 tron MDB_cursor *mc;
44 1.1 tron struct mdb_op_info opinfo = {{{ 0 }}}, *moi = &opinfo;
45 1.1 tron Entry dummy = {0};
46 1.1 tron
47 1.1 tron Entry *np = NULL; /* newSuperior Entry */
48 1.1 tron struct berval *np_dn = NULL; /* newSuperior dn */
49 1.1 tron struct berval *np_ndn = NULL; /* newSuperior ndn */
50 1.1 tron struct berval *new_parent_dn = NULL; /* np_dn, p_dn, or NULL */
51 1.1 tron
52 1.1 tron int manageDSAit = get_manageDSAit( op );
53 1.1 tron
54 1.1 tron ID nid, nsubs;
55 1.1 tron LDAPControl **preread_ctrl = NULL;
56 1.1 tron LDAPControl **postread_ctrl = NULL;
57 1.1 tron LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
58 1.1 tron int num_ctrls = 0;
59 1.1 tron
60 1.1 tron int parent_is_glue = 0;
61 1.1 tron int parent_is_leaf = 0;
62 1.1 tron
63 1.1 tron Debug( LDAP_DEBUG_TRACE, "==>" LDAP_XSTRING(mdb_modrdn) "(%s,%s,%s)\n",
64 1.1 tron op->o_req_dn.bv_val,op->oq_modrdn.rs_newrdn.bv_val,
65 1.1 tron op->oq_modrdn.rs_newSup ? op->oq_modrdn.rs_newSup->bv_val : "NULL" );
66 1.1 tron
67 1.1 tron ctrls[num_ctrls] = NULL;
68 1.1 tron
69 1.1 tron /* begin transaction */
70 1.1 tron rs->sr_err = mdb_opinfo_get( op, mdb, 0, &moi );
71 1.1 tron rs->sr_text = NULL;
72 1.1 tron if( rs->sr_err != 0 ) {
73 1.1 tron Debug( LDAP_DEBUG_TRACE,
74 1.1 tron LDAP_XSTRING(mdb_modrdn) ": txn_begin failed: "
75 1.3 christos "%s (%d)\n", mdb_strerror(rs->sr_err), rs->sr_err );
76 1.1 tron rs->sr_err = LDAP_OTHER;
77 1.1 tron rs->sr_text = "internal error";
78 1.1 tron goto return_results;
79 1.1 tron }
80 1.1 tron txn = moi->moi_txn;
81 1.1 tron
82 1.1 tron slap_mods_opattrs( op, &op->orr_modlist, 1 );
83 1.1 tron
84 1.1 tron if ( be_issuffix( op->o_bd, &op->o_req_ndn ) ) {
85 1.1 tron #ifdef MDB_MULTIPLE_SUFFIXES
86 1.1 tron /* Allow renaming one suffix entry to another */
87 1.1 tron p_ndn = slap_empty_bv;
88 1.1 tron #else
89 1.1 tron /* There can only be one suffix entry */
90 1.1 tron rs->sr_err = LDAP_NAMING_VIOLATION;
91 1.1 tron rs->sr_text = "cannot rename suffix entry";
92 1.1 tron goto return_results;
93 1.1 tron #endif
94 1.1 tron } else {
95 1.1 tron dnParent( &op->o_req_ndn, &p_ndn );
96 1.1 tron }
97 1.1 tron np_ndn = &p_ndn;
98 1.1 tron /* Make sure parent entry exist and we can write its
99 1.1 tron * children.
100 1.1 tron */
101 1.1 tron rs->sr_err = mdb_cursor_open( txn, mdb->mi_dn2id, &mc );
102 1.1 tron if ( rs->sr_err != 0 ) {
103 1.1 tron Debug(LDAP_DEBUG_TRACE,
104 1.1 tron "<=- " LDAP_XSTRING(mdb_modrdn)
105 1.1 tron ": cursor_open failed: %s (%d)\n",
106 1.3 christos mdb_strerror(rs->sr_err), rs->sr_err );
107 1.1 tron rs->sr_err = LDAP_OTHER;
108 1.1 tron rs->sr_text = "DN cursor_open failed";
109 1.1 tron goto return_results;
110 1.1 tron }
111 1.1 tron rs->sr_err = mdb_dn2entry( op, txn, mc, &p_ndn, &p, NULL, 0 );
112 1.1 tron switch( rs->sr_err ) {
113 1.1 tron case MDB_NOTFOUND:
114 1.1 tron Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(mdb_modrdn)
115 1.3 christos ": parent does not exist\n" );
116 1.1 tron rs->sr_ref = referral_rewrite( default_referral, NULL,
117 1.1 tron &op->o_req_dn, LDAP_SCOPE_DEFAULT );
118 1.1 tron rs->sr_err = LDAP_REFERRAL;
119 1.1 tron
120 1.1 tron send_ldap_result( op, rs );
121 1.1 tron
122 1.1 tron ber_bvarray_free( rs->sr_ref );
123 1.1 tron goto done;
124 1.1 tron case 0:
125 1.1 tron break;
126 1.1 tron case LDAP_BUSY:
127 1.1 tron rs->sr_text = "ldap server busy";
128 1.1 tron goto return_results;
129 1.1 tron default:
130 1.1 tron rs->sr_err = LDAP_OTHER;
131 1.1 tron rs->sr_text = "internal error";
132 1.1 tron goto return_results;
133 1.1 tron }
134 1.1 tron
135 1.1 tron /* check parent for "children" acl */
136 1.1 tron rs->sr_err = access_allowed( op, p,
137 1.1 tron children, NULL,
138 1.1 tron op->oq_modrdn.rs_newSup == NULL ?
139 1.1 tron ACL_WRITE : ACL_WDEL,
140 1.1 tron NULL );
141 1.1 tron
142 1.1 tron if ( ! rs->sr_err ) {
143 1.1 tron rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
144 1.3 christos Debug( LDAP_DEBUG_TRACE, "no access to parent\n" );
145 1.1 tron rs->sr_text = "no write access to parent's children";
146 1.1 tron goto return_results;
147 1.1 tron }
148 1.1 tron
149 1.1 tron Debug( LDAP_DEBUG_TRACE,
150 1.1 tron LDAP_XSTRING(mdb_modrdn) ": wr to children "
151 1.3 christos "of entry %s OK\n", p_ndn.bv_val );
152 1.1 tron
153 1.1 tron if ( p_ndn.bv_val == slap_empty_bv.bv_val ) {
154 1.1 tron p_dn = slap_empty_bv;
155 1.1 tron } else {
156 1.1 tron dnParent( &op->o_req_dn, &p_dn );
157 1.1 tron }
158 1.1 tron
159 1.1 tron Debug( LDAP_DEBUG_TRACE,
160 1.1 tron LDAP_XSTRING(mdb_modrdn) ": parent dn=%s\n",
161 1.3 christos p_dn.bv_val );
162 1.1 tron
163 1.1 tron /* get entry */
164 1.1 tron rs->sr_err = mdb_dn2entry( op, txn, mc, &op->o_req_ndn, &e, &nsubs, 0 );
165 1.1 tron switch( rs->sr_err ) {
166 1.1 tron case MDB_NOTFOUND:
167 1.1 tron e = p;
168 1.1 tron p = NULL;
169 1.1 tron case 0:
170 1.1 tron break;
171 1.1 tron case LDAP_BUSY:
172 1.1 tron rs->sr_text = "ldap server busy";
173 1.1 tron goto return_results;
174 1.1 tron default:
175 1.1 tron rs->sr_err = LDAP_OTHER;
176 1.1 tron rs->sr_text = "internal error";
177 1.1 tron goto return_results;
178 1.1 tron }
179 1.1 tron
180 1.1 tron /* FIXME: dn2entry() should return non-glue entry */
181 1.1 tron if (( rs->sr_err == MDB_NOTFOUND ) ||
182 1.1 tron ( !manageDSAit && e && is_entry_glue( e )))
183 1.1 tron {
184 1.1 tron if( e != NULL ) {
185 1.1 tron rs->sr_matched = ch_strdup( e->e_dn );
186 1.1 tron if ( is_entry_referral( e )) {
187 1.1 tron BerVarray ref = get_entry_referrals( op, e );
188 1.1 tron rs->sr_ref = referral_rewrite( ref, &e->e_name,
189 1.1 tron &op->o_req_dn, LDAP_SCOPE_DEFAULT );
190 1.1 tron ber_bvarray_free( ref );
191 1.1 tron } else {
192 1.1 tron rs->sr_ref = NULL;
193 1.1 tron }
194 1.1 tron mdb_entry_return( op, e );
195 1.1 tron e = NULL;
196 1.1 tron
197 1.1 tron } else {
198 1.1 tron rs->sr_ref = referral_rewrite( default_referral, NULL,
199 1.1 tron &op->o_req_dn, LDAP_SCOPE_DEFAULT );
200 1.1 tron }
201 1.1 tron
202 1.1 tron rs->sr_err = LDAP_REFERRAL;
203 1.1 tron send_ldap_result( op, rs );
204 1.1 tron
205 1.1 tron ber_bvarray_free( rs->sr_ref );
206 1.1 tron free( (char *)rs->sr_matched );
207 1.1 tron rs->sr_ref = NULL;
208 1.1 tron rs->sr_matched = NULL;
209 1.1 tron
210 1.1 tron goto done;
211 1.1 tron }
212 1.1 tron
213 1.1 tron if ( get_assert( op ) &&
214 1.1 tron ( test_filter( op, e, get_assertion( op )) != LDAP_COMPARE_TRUE ))
215 1.1 tron {
216 1.1 tron rs->sr_err = LDAP_ASSERTION_FAILED;
217 1.1 tron goto return_results;
218 1.1 tron }
219 1.1 tron
220 1.1 tron /* check write on old entry */
221 1.1 tron rs->sr_err = access_allowed( op, e, entry, NULL, ACL_WRITE, NULL );
222 1.1 tron if ( ! rs->sr_err ) {
223 1.3 christos Debug( LDAP_DEBUG_TRACE, "no access to entry\n" );
224 1.1 tron rs->sr_text = "no write access to old entry";
225 1.1 tron rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
226 1.1 tron goto return_results;
227 1.1 tron }
228 1.1 tron
229 1.1 tron if (!manageDSAit && is_entry_referral( e ) ) {
230 1.1 tron /* entry is a referral, don't allow rename */
231 1.1 tron rs->sr_ref = get_entry_referrals( op, e );
232 1.1 tron
233 1.1 tron Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(mdb_modrdn)
234 1.3 christos ": entry %s is referral\n", e->e_dn );
235 1.1 tron
236 1.1 tron rs->sr_err = LDAP_REFERRAL,
237 1.1 tron rs->sr_matched = e->e_name.bv_val;
238 1.1 tron send_ldap_result( op, rs );
239 1.1 tron
240 1.1 tron ber_bvarray_free( rs->sr_ref );
241 1.1 tron rs->sr_ref = NULL;
242 1.1 tron rs->sr_matched = NULL;
243 1.1 tron goto done;
244 1.1 tron }
245 1.1 tron
246 1.1 tron new_parent_dn = &p_dn; /* New Parent unless newSuperior given */
247 1.1 tron
248 1.1 tron if ( op->oq_modrdn.rs_newSup != NULL ) {
249 1.1 tron Debug( LDAP_DEBUG_TRACE,
250 1.1 tron LDAP_XSTRING(mdb_modrdn)
251 1.1 tron ": new parent \"%s\" requested...\n",
252 1.3 christos op->oq_modrdn.rs_newSup->bv_val );
253 1.1 tron
254 1.1 tron /* newSuperior == oldParent? */
255 1.1 tron if( dn_match( &p_ndn, op->oq_modrdn.rs_nnewSup ) ) {
256 1.1 tron Debug( LDAP_DEBUG_TRACE, "mdb_back_modrdn: "
257 1.1 tron "new parent \"%s\" same as the old parent \"%s\"\n",
258 1.3 christos op->oq_modrdn.rs_newSup->bv_val, p_dn.bv_val );
259 1.1 tron op->oq_modrdn.rs_newSup = NULL; /* ignore newSuperior */
260 1.1 tron }
261 1.1 tron }
262 1.1 tron
263 1.1 tron /* There's a MDB_MULTIPLE_SUFFIXES case here that this code doesn't
264 1.1 tron * support. E.g., two suffixes dc=foo,dc=com and dc=bar,dc=net.
265 1.1 tron * We do not allow modDN
266 1.1 tron * dc=foo,dc=com
267 1.1 tron * newrdn dc=bar
268 1.1 tron * newsup dc=net
269 1.1 tron * and we probably should. But since MULTIPLE_SUFFIXES is deprecated
270 1.1 tron * I'm ignoring this problem for now.
271 1.1 tron */
272 1.1 tron if ( op->oq_modrdn.rs_newSup != NULL ) {
273 1.1 tron if ( op->oq_modrdn.rs_newSup->bv_len ) {
274 1.1 tron np_dn = op->oq_modrdn.rs_newSup;
275 1.1 tron np_ndn = op->oq_modrdn.rs_nnewSup;
276 1.1 tron
277 1.1 tron /* newSuperior == oldParent? - checked above */
278 1.1 tron /* newSuperior == entry being moved?, if so ==> ERROR */
279 1.1 tron if ( dnIsSuffix( np_ndn, &e->e_nname )) {
280 1.1 tron rs->sr_err = LDAP_NO_SUCH_OBJECT;
281 1.1 tron rs->sr_text = "new superior not found";
282 1.1 tron goto return_results;
283 1.1 tron }
284 1.1 tron /* Get Entry with dn=newSuperior. Does newSuperior exist? */
285 1.1 tron rs->sr_err = mdb_dn2entry( op, txn, NULL, np_ndn, &np, NULL, 0 );
286 1.1 tron
287 1.1 tron switch( rs->sr_err ) {
288 1.1 tron case 0:
289 1.1 tron break;
290 1.1 tron case MDB_NOTFOUND:
291 1.1 tron Debug( LDAP_DEBUG_TRACE,
292 1.1 tron LDAP_XSTRING(mdb_modrdn)
293 1.1 tron ": newSup(ndn=%s) not here!\n",
294 1.3 christos np_ndn->bv_val );
295 1.1 tron rs->sr_text = "new superior not found";
296 1.1 tron rs->sr_err = LDAP_NO_SUCH_OBJECT;
297 1.1 tron goto return_results;
298 1.1 tron case LDAP_BUSY:
299 1.1 tron rs->sr_text = "ldap server busy";
300 1.1 tron goto return_results;
301 1.1 tron default:
302 1.1 tron rs->sr_err = LDAP_OTHER;
303 1.1 tron rs->sr_text = "internal error";
304 1.1 tron goto return_results;
305 1.1 tron }
306 1.1 tron
307 1.1 tron /* check newSuperior for "children" acl */
308 1.1 tron rs->sr_err = access_allowed( op, np, children,
309 1.1 tron NULL, ACL_WADD, NULL );
310 1.1 tron
311 1.1 tron if( ! rs->sr_err ) {
312 1.1 tron Debug( LDAP_DEBUG_TRACE,
313 1.1 tron LDAP_XSTRING(mdb_modrdn)
314 1.3 christos ": no wr to newSup children\n" );
315 1.1 tron rs->sr_text = "no write access to new superior's children";
316 1.1 tron rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
317 1.1 tron goto return_results;
318 1.1 tron }
319 1.1 tron
320 1.1 tron Debug( LDAP_DEBUG_TRACE,
321 1.1 tron LDAP_XSTRING(mdb_modrdn)
322 1.1 tron ": wr to new parent OK np=%p, id=%ld\n",
323 1.3 christos (void *) np, (long) np->e_id );
324 1.1 tron
325 1.1 tron if ( is_entry_alias( np ) ) {
326 1.1 tron /* parent is an alias, don't allow add */
327 1.1 tron Debug( LDAP_DEBUG_TRACE,
328 1.1 tron LDAP_XSTRING(mdb_modrdn)
329 1.3 christos ": entry is alias\n" );
330 1.1 tron rs->sr_text = "new superior is an alias";
331 1.1 tron rs->sr_err = LDAP_ALIAS_PROBLEM;
332 1.1 tron goto return_results;
333 1.1 tron }
334 1.1 tron
335 1.1 tron if ( is_entry_referral( np ) ) {
336 1.1 tron /* parent is a referral, don't allow add */
337 1.1 tron Debug( LDAP_DEBUG_TRACE,
338 1.1 tron LDAP_XSTRING(mdb_modrdn)
339 1.3 christos ": entry is referral\n" );
340 1.1 tron rs->sr_text = "new superior is a referral";
341 1.1 tron rs->sr_err = LDAP_OTHER;
342 1.1 tron goto return_results;
343 1.1 tron }
344 1.2 christos np_dn = &np->e_name;
345 1.1 tron
346 1.1 tron } else {
347 1.1 tron np_dn = NULL;
348 1.1 tron
349 1.1 tron /* no parent, modrdn entry directly under root */
350 1.1 tron if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv )
351 1.1 tron || be_isupdate( op ) ) {
352 1.1 tron np = (Entry *)&slap_entry_root;
353 1.1 tron
354 1.1 tron /* check parent for "children" acl */
355 1.1 tron rs->sr_err = access_allowed( op, np,
356 1.1 tron children, NULL, ACL_WADD, NULL );
357 1.1 tron
358 1.1 tron np = NULL;
359 1.1 tron
360 1.1 tron if ( ! rs->sr_err ) {
361 1.1 tron rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
362 1.1 tron Debug( LDAP_DEBUG_TRACE,
363 1.3 christos "no access to new superior\n" );
364 1.1 tron rs->sr_text =
365 1.1 tron "no write access to new superior's children";
366 1.1 tron goto return_results;
367 1.1 tron }
368 1.1 tron }
369 1.1 tron }
370 1.1 tron
371 1.1 tron Debug( LDAP_DEBUG_TRACE,
372 1.1 tron LDAP_XSTRING(mdb_modrdn)
373 1.3 christos ": wr to new parent's children OK\n" );
374 1.1 tron
375 1.1 tron new_parent_dn = np_dn;
376 1.1 tron }
377 1.1 tron
378 1.1 tron /* Build target dn and make sure target entry doesn't exist already. */
379 1.1 tron if (!new_dn.bv_val) {
380 1.1 tron build_new_dn( &new_dn, new_parent_dn, &op->oq_modrdn.rs_newrdn, op->o_tmpmemctx );
381 1.1 tron }
382 1.1 tron
383 1.1 tron if (!new_ndn.bv_val) {
384 1.1 tron dnNormalize( 0, NULL, NULL, &new_dn, &new_ndn, op->o_tmpmemctx );
385 1.1 tron }
386 1.1 tron
387 1.1 tron Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(mdb_modrdn) ": new ndn=%s\n",
388 1.3 christos new_ndn.bv_val );
389 1.1 tron
390 1.1 tron /* Shortcut the search */
391 1.1 tron rs->sr_err = mdb_dn2id ( op, txn, NULL, &new_ndn, &nid, NULL, NULL, NULL );
392 1.1 tron switch( rs->sr_err ) {
393 1.1 tron case MDB_NOTFOUND:
394 1.1 tron break;
395 1.1 tron case 0:
396 1.1 tron /* Allow rename to same DN */
397 1.1 tron if ( nid == e->e_id )
398 1.1 tron break;
399 1.1 tron rs->sr_err = LDAP_ALREADY_EXISTS;
400 1.1 tron goto return_results;
401 1.1 tron default:
402 1.1 tron rs->sr_err = LDAP_OTHER;
403 1.1 tron rs->sr_text = "internal error";
404 1.1 tron goto return_results;
405 1.1 tron }
406 1.1 tron
407 1.1 tron if( op->o_preread ) {
408 1.1 tron if( preread_ctrl == NULL ) {
409 1.1 tron preread_ctrl = &ctrls[num_ctrls++];
410 1.1 tron ctrls[num_ctrls] = NULL;
411 1.1 tron }
412 1.1 tron if( slap_read_controls( op, rs, e,
413 1.1 tron &slap_pre_read_bv, preread_ctrl ) )
414 1.1 tron {
415 1.1 tron Debug( LDAP_DEBUG_TRACE,
416 1.1 tron "<=- " LDAP_XSTRING(mdb_modrdn)
417 1.3 christos ": pre-read failed!\n" );
418 1.1 tron if ( op->o_preread & SLAP_CONTROL_CRITICAL ) {
419 1.1 tron /* FIXME: is it correct to abort
420 1.1 tron * operation if control fails? */
421 1.1 tron goto return_results;
422 1.1 tron }
423 1.1 tron }
424 1.1 tron }
425 1.1 tron
426 1.1 tron /* delete old DN
427 1.1 tron * If moving to a new parent, must delete current subtree count,
428 1.1 tron * otherwise leave it unchanged since we'll be adding it right back.
429 1.1 tron */
430 1.1 tron rs->sr_err = mdb_dn2id_delete( op, mc, e->e_id, np ? nsubs : 0 );
431 1.1 tron if ( rs->sr_err != 0 ) {
432 1.1 tron Debug(LDAP_DEBUG_TRACE,
433 1.1 tron "<=- " LDAP_XSTRING(mdb_modrdn)
434 1.1 tron ": dn2id del failed: %s (%d)\n",
435 1.3 christos mdb_strerror(rs->sr_err), rs->sr_err );
436 1.1 tron rs->sr_err = LDAP_OTHER;
437 1.1 tron rs->sr_text = "DN index delete fail";
438 1.1 tron goto return_results;
439 1.1 tron }
440 1.1 tron
441 1.1 tron /* copy the entry, then override some fields */
442 1.1 tron dummy = *e;
443 1.1 tron dummy.e_name = new_dn;
444 1.1 tron dummy.e_nname = new_ndn;
445 1.1 tron dummy.e_attrs = NULL;
446 1.1 tron
447 1.1 tron /* add new DN */
448 1.1 tron rs->sr_err = mdb_dn2id_add( op, mc, mc, np ? np->e_id : p->e_id,
449 1.1 tron nsubs, np != NULL, &dummy );
450 1.1 tron if ( rs->sr_err != 0 ) {
451 1.1 tron Debug(LDAP_DEBUG_TRACE,
452 1.1 tron "<=- " LDAP_XSTRING(mdb_modrdn)
453 1.1 tron ": dn2id add failed: %s (%d)\n",
454 1.3 christos mdb_strerror(rs->sr_err), rs->sr_err );
455 1.1 tron rs->sr_err = LDAP_OTHER;
456 1.1 tron rs->sr_text = "DN index add failed";
457 1.1 tron goto return_results;
458 1.1 tron }
459 1.1 tron
460 1.1 tron dummy.e_attrs = e->e_attrs;
461 1.1 tron
462 1.3 christos if ( op->orr_modlist != NULL ) {
463 1.3 christos /* modify entry */
464 1.3 christos rs->sr_err = mdb_modify_internal( op, txn, op->orr_modlist, &dummy,
465 1.3 christos &rs->sr_text, textbuf, textlen );
466 1.3 christos if( rs->sr_err != LDAP_SUCCESS ) {
467 1.3 christos Debug(LDAP_DEBUG_TRACE,
468 1.3 christos "<=- " LDAP_XSTRING(mdb_modrdn)
469 1.3 christos ": modify failed: %s (%d)\n",
470 1.3 christos mdb_strerror(rs->sr_err), rs->sr_err );
471 1.3 christos goto return_results;
472 1.3 christos }
473 1.1 tron }
474 1.1 tron
475 1.1 tron /* id2entry index */
476 1.1 tron rs->sr_err = mdb_id2entry_update( op, txn, NULL, &dummy );
477 1.1 tron if ( rs->sr_err != 0 ) {
478 1.1 tron Debug(LDAP_DEBUG_TRACE,
479 1.1 tron "<=- " LDAP_XSTRING(mdb_modrdn)
480 1.1 tron ": id2entry failed: %s (%d)\n",
481 1.3 christos mdb_strerror(rs->sr_err), rs->sr_err );
482 1.3 christos if ( rs->sr_err == LDAP_ADMINLIMIT_EXCEEDED ) {
483 1.3 christos rs->sr_text = "entry too big";
484 1.3 christos } else {
485 1.3 christos rs->sr_err = LDAP_OTHER;
486 1.3 christos rs->sr_text = "entry update failed";
487 1.3 christos }
488 1.1 tron goto return_results;
489 1.1 tron }
490 1.1 tron
491 1.1 tron if ( p_ndn.bv_len != 0 ) {
492 1.1 tron if ((parent_is_glue = is_entry_glue(p))) {
493 1.1 tron rs->sr_err = mdb_dn2id_children( op, txn, p );
494 1.1 tron if ( rs->sr_err != MDB_NOTFOUND ) {
495 1.1 tron switch( rs->sr_err ) {
496 1.1 tron case 0:
497 1.1 tron break;
498 1.1 tron default:
499 1.1 tron Debug(LDAP_DEBUG_ARGS,
500 1.1 tron "<=- " LDAP_XSTRING(mdb_modrdn)
501 1.1 tron ": has_children failed: %s (%d)\n",
502 1.3 christos mdb_strerror(rs->sr_err), rs->sr_err );
503 1.1 tron rs->sr_err = LDAP_OTHER;
504 1.1 tron rs->sr_text = "internal error";
505 1.1 tron goto return_results;
506 1.1 tron }
507 1.1 tron } else {
508 1.1 tron parent_is_leaf = 1;
509 1.1 tron }
510 1.1 tron }
511 1.1 tron mdb_entry_return( op, p );
512 1.1 tron p = NULL;
513 1.1 tron }
514 1.1 tron
515 1.1 tron if( op->o_postread ) {
516 1.1 tron if( postread_ctrl == NULL ) {
517 1.1 tron postread_ctrl = &ctrls[num_ctrls++];
518 1.1 tron ctrls[num_ctrls] = NULL;
519 1.1 tron }
520 1.1 tron if( slap_read_controls( op, rs, &dummy,
521 1.1 tron &slap_post_read_bv, postread_ctrl ) )
522 1.1 tron {
523 1.1 tron Debug( LDAP_DEBUG_TRACE,
524 1.1 tron "<=- " LDAP_XSTRING(mdb_modrdn)
525 1.3 christos ": post-read failed!\n" );
526 1.1 tron if ( op->o_postread & SLAP_CONTROL_CRITICAL ) {
527 1.1 tron /* FIXME: is it correct to abort
528 1.1 tron * operation if control fails? */
529 1.1 tron goto return_results;
530 1.1 tron }
531 1.1 tron }
532 1.1 tron }
533 1.1 tron
534 1.1 tron if( moi == &opinfo ) {
535 1.1 tron LDAP_SLIST_REMOVE( &op->o_extra, &opinfo.moi_oe, OpExtra, oe_next );
536 1.1 tron opinfo.moi_oe.oe_key = NULL;
537 1.1 tron if( op->o_noop ) {
538 1.1 tron mdb_txn_abort( txn );
539 1.1 tron rs->sr_err = LDAP_X_NO_OPERATION;
540 1.1 tron txn = NULL;
541 1.1 tron goto return_results;
542 1.1 tron
543 1.1 tron } else {
544 1.1 tron if(( rs->sr_err=mdb_txn_commit( txn )) != 0 ) {
545 1.1 tron rs->sr_text = "txn_commit failed";
546 1.1 tron } else {
547 1.1 tron rs->sr_err = LDAP_SUCCESS;
548 1.1 tron }
549 1.1 tron txn = NULL;
550 1.1 tron }
551 1.1 tron }
552 1.1 tron
553 1.1 tron if( rs->sr_err != LDAP_SUCCESS ) {
554 1.1 tron Debug( LDAP_DEBUG_ANY,
555 1.1 tron LDAP_XSTRING(mdb_modrdn) ": %s : %s (%d)\n",
556 1.1 tron rs->sr_text, mdb_strerror(rs->sr_err), rs->sr_err );
557 1.1 tron rs->sr_err = LDAP_OTHER;
558 1.1 tron
559 1.1 tron goto return_results;
560 1.1 tron }
561 1.1 tron
562 1.1 tron Debug(LDAP_DEBUG_TRACE,
563 1.1 tron LDAP_XSTRING(mdb_modrdn)
564 1.1 tron ": rdn modified%s id=%08lx dn=\"%s\"\n",
565 1.1 tron op->o_noop ? " (no-op)" : "",
566 1.1 tron dummy.e_id, op->o_req_dn.bv_val );
567 1.1 tron rs->sr_text = NULL;
568 1.1 tron if( num_ctrls ) rs->sr_ctrls = ctrls;
569 1.1 tron
570 1.1 tron return_results:
571 1.3 christos if ( e != NULL && dummy.e_attrs != e->e_attrs ) {
572 1.1 tron attrs_free( dummy.e_attrs );
573 1.1 tron }
574 1.1 tron send_ldap_result( op, rs );
575 1.1 tron
576 1.1 tron #if 0
577 1.1 tron if( rs->sr_err == LDAP_SUCCESS && mdb->bi_txn_cp_kbyte ) {
578 1.1 tron TXN_CHECKPOINT( mdb->bi_dbenv,
579 1.1 tron mdb->bi_txn_cp_kbyte, mdb->bi_txn_cp_min, 0 );
580 1.1 tron }
581 1.1 tron #endif
582 1.1 tron
583 1.1 tron if ( rs->sr_err == LDAP_SUCCESS && parent_is_glue && parent_is_leaf ) {
584 1.1 tron op->o_delete_glue_parent = 1;
585 1.1 tron }
586 1.1 tron
587 1.1 tron done:
588 1.1 tron slap_graduate_commit_csn( op );
589 1.1 tron
590 1.1 tron if( new_ndn.bv_val != NULL ) op->o_tmpfree( new_ndn.bv_val, op->o_tmpmemctx );
591 1.1 tron if( new_dn.bv_val != NULL ) op->o_tmpfree( new_dn.bv_val, op->o_tmpmemctx );
592 1.1 tron
593 1.1 tron /* LDAP v3 Support */
594 1.1 tron if( np != NULL ) {
595 1.1 tron /* free new parent */
596 1.1 tron mdb_entry_return( op, np );
597 1.1 tron }
598 1.1 tron
599 1.1 tron if( p != NULL ) {
600 1.1 tron /* free parent */
601 1.1 tron mdb_entry_return( op, p );
602 1.1 tron }
603 1.1 tron
604 1.1 tron /* free entry */
605 1.1 tron if( e != NULL ) {
606 1.1 tron mdb_entry_return( op, e );
607 1.1 tron }
608 1.1 tron
609 1.1 tron if( moi == &opinfo ) {
610 1.1 tron if( txn != NULL ) {
611 1.1 tron mdb_txn_abort( txn );
612 1.1 tron }
613 1.1 tron if ( opinfo.moi_oe.oe_key ) {
614 1.1 tron LDAP_SLIST_REMOVE( &op->o_extra, &opinfo.moi_oe, OpExtra, oe_next );
615 1.1 tron }
616 1.1 tron } else {
617 1.1 tron moi->moi_ref--;
618 1.1 tron }
619 1.1 tron
620 1.1 tron if( preread_ctrl != NULL && (*preread_ctrl) != NULL ) {
621 1.1 tron slap_sl_free( (*preread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
622 1.1 tron slap_sl_free( *preread_ctrl, op->o_tmpmemctx );
623 1.1 tron }
624 1.1 tron if( postread_ctrl != NULL && (*postread_ctrl) != NULL ) {
625 1.1 tron slap_sl_free( (*postread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
626 1.1 tron slap_sl_free( *postread_ctrl, op->o_tmpmemctx );
627 1.1 tron }
628 1.1 tron return rs->sr_err;
629 1.1 tron }
630