]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/modrdn.c
Fix typo
[openldap] / servers / slapd / back-ldbm / modrdn.c
1 /* modrdn.c - ldbm backend modrdn routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 /*
9  * LDAP v3 newSuperior support. Add new rdn as an attribute.
10  * (Full support for v2 also used software/ideas contributed
11  * by Roy Hooper rhooper@cyberus.ca, thanks to him for his
12  * submission!.)
13  *
14  * Copyright 1999, Juan C. Gomez, All rights reserved.
15  * This software is not subject to any license of Silicon Graphics 
16  * Inc. or Purdue University.
17  *
18  * Redistribution and use in source and binary forms are permitted
19  * without restriction or fee of any kind as long as this notice
20  * is preserved.
21  *
22  */
23
24 #include "portable.h"
25
26 #include <stdio.h>
27
28 #include <ac/string.h>
29 #include <ac/socket.h>
30
31 #include "slap.h"
32 #include "back-ldbm.h"
33 #include "proto-back-ldbm.h"
34
35 int
36 ldbm_back_modrdn(
37     Backend     *be,
38     Connection  *conn,
39     Operation   *op,
40     const char  *dn,
41     const char  *ndn,
42     const char  *newrdn,
43     int         deleteoldrdn,
44     const char  *newSuperior
45 )
46 {
47         AttributeDescription *children = slap_schema.si_ad_children;
48         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
49         char            *p_dn = NULL, *p_ndn = NULL;
50         char            *new_dn = NULL, *new_ndn = NULL;
51         Entry           *e, *p = NULL;
52         Entry           *matched;
53         int                     rootlock = 0;
54         int                     rc = -1;
55         const char *text = NULL;
56         /* Added to support LDAP v2 correctly (deleteoldrdn thing) */
57         char            *new_rdn_val = NULL;    /* Val of new rdn */
58         char            *new_rdn_type = NULL;   /* Type of new rdn */
59         char            *old_rdn = NULL;        /* Old rdn's attr type & val */
60         char            *old_rdn_type = NULL;   /* Type of old rdn attr. */
61         char            *old_rdn_val = NULL;    /* Old rdn attribute value */
62         /* Added to support newSuperior */ 
63         Entry           *np = NULL;     /* newSuperior Entry */
64         char            *np_dn = NULL;  /* newSuperior dn */
65         char            *np_ndn = NULL; /* newSuperior ndn */
66         char            *new_parent_dn = NULL;  /* np_dn, p_dn, or NULL */
67         /* Used to interface with ldbm_modify_internal() */
68         struct berval   add_bv;                 /* Stores new rdn att */
69         struct berval   *add_bvals[2];          /* Stores new rdn att */
70         struct berval   del_bv;                 /* Stores old rdn att */
71         struct berval   *del_bvals[2];          /* Stores old rdn att */
72         Modifications   mod[2];                 /* Used to delete old rdn */
73         int             manageDSAit = get_manageDSAit( op );
74
75 #ifdef NEW_LOGGING
76         LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
77                    "ldbm_back_modrdn: dn: %s newSuperior=%s\n", 
78                    dn ? dn : "NULL", newSuperior ? newSuperior : "NULL" ));
79 #else
80         Debug( LDAP_DEBUG_TRACE, "==>ldbm_back_modrdn(newSuperior=%s)\n",
81                (newSuperior ? newSuperior : "NULL"),
82                0, 0 );
83 #endif
84
85
86         /* get entry with writer lock */
87         if ( (e = dn2entry_w( be, ndn, &matched )) == NULL ) {
88                 char* matched_dn = NULL;
89                 struct berval** refs = NULL;
90
91                 if( matched != NULL ) {
92                         matched_dn = strdup( matched->e_dn );
93                         refs = is_entry_referral( matched )
94                                 ? get_entry_referrals( be, conn, op, matched )
95                                 : NULL;
96                         cache_return_entry_r( &li->li_cache, matched );
97                 } else {
98                         refs = default_referral;
99                 }
100
101                 send_ldap_result( conn, op, LDAP_REFERRAL,
102                         matched_dn, NULL, refs, NULL );
103
104                 if ( matched != NULL ) {
105                         ber_bvecfree( refs );
106                         free( matched_dn );
107                 }
108
109                 return( -1 );
110         }
111
112         if (!manageDSAit && is_entry_referral( e ) ) {
113                 /* parent is a referral, don't allow add */
114                 /* parent is an alias, don't allow add */
115                 struct berval **refs = get_entry_referrals( be,
116                         conn, op, e );
117
118 #ifdef NEW_LOGGING
119                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
120                            "ldbm_back_modrdn: entry %s is a referral\n", e->e_dn ));
121 #else
122                 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
123                     0, 0 );
124 #endif
125
126
127                 send_ldap_result( conn, op, LDAP_REFERRAL,
128                     e->e_dn, NULL, refs, NULL );
129
130                 ber_bvecfree( refs );
131
132                 goto return_results;
133         }
134
135         if ( (p_ndn = dn_parent( be, e->e_ndn )) != NULL ) {
136
137                 /* Make sure parent entry exist and we can write its 
138                  * children.
139                  */
140
141                 if( (p = dn2entry_w( be, p_ndn, NULL )) == NULL) {
142 #ifdef NEW_LOGGING
143                         LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
144                                    "ldbm_back_modrdn: parent of %s does not exist\n", e->e_ndn ));
145 #else
146                         Debug( LDAP_DEBUG_TRACE, "parent does not exist\n",
147                                 0, 0, 0);
148 #endif
149
150                         send_ldap_result( conn, op, LDAP_OTHER,
151                                 NULL, NULL, NULL, NULL );
152                         goto return_results;
153                 }
154
155                 /* check parent for "children" acl */
156                 if ( ! access_allowed( be, conn, op, p,
157                         children, NULL, ACL_WRITE ) )
158                 {
159 #ifdef NEW_LOGGING
160                         LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
161                                    "ldbm_back_modrdn: no access to parent of (%s)\n", e->e_dn ));
162 #else
163                         Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
164                                 0, 0 );
165 #endif
166
167                         send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
168                                 NULL, NULL, NULL, NULL );
169                         goto return_results;
170                 }
171
172 #ifdef NEW_LOGGING
173                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
174                            "ldbm_back_modrdn: wr to children of entry %s OK\n",
175                            p_ndn ));
176 #else
177                 Debug( LDAP_DEBUG_TRACE,
178                        "ldbm_back_modrdn: wr to children of entry %s OK\n",
179                        p_ndn, 0, 0 );
180 #endif
181
182                 
183                 p_dn = dn_parent( be, e->e_dn );
184         
185
186 #ifdef NEW_LOGGING
187                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
188                            "ldbm_back_modrdn: parent dn=%s\n", p_dn ));
189 #else
190                 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: parent dn=%s\n",
191                        p_dn, 0, 0 );
192 #endif
193
194
195         } else {
196                 /* no parent, modrdn entry directly under root */
197                 if( ! be_isroot( be, op->o_ndn ) ) {
198 #ifdef NEW_LOGGING
199                         LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
200                                    "ldbm_back_modrdn: (%s) no parent & not a root.\n",
201                                    e->e_dn ));
202 #else
203                         Debug( LDAP_DEBUG_TRACE, "no parent & not root\n",
204                                 0, 0, 0);
205 #endif
206
207                         send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
208                                 NULL, NULL, NULL, NULL );
209                         goto return_results;
210                 }
211
212                 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
213                 rootlock = 1;
214                 
215 #ifdef NEW_LOGGING
216                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
217                            "ldbm_back_modrdn: (%s) no parent, locked root.\n", e->e_dn ));
218 #else
219                 Debug( LDAP_DEBUG_TRACE,
220                        "ldbm_back_modrdn: no parent, locked root\n",
221                        0, 0, 0 );
222 #endif
223
224
225         }
226
227         new_parent_dn = p_dn;   /* New Parent unless newSuperior given */
228
229         if ( newSuperior != NULL ) {
230 #ifdef NEW_LOGGING
231                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
232                            "ldbm_back_modrdn: new parent \"%s\" requested\n", newSuperior ));
233 #else
234                 Debug( LDAP_DEBUG_TRACE, 
235                         "ldbm_back_modrdn: new parent \"%s\" requested...\n",
236                         newSuperior, 0, 0 );
237 #endif
238
239
240                 np_dn = ch_strdup( newSuperior );
241                 np_ndn = ch_strdup( np_dn );
242                 (void) dn_normalize( np_ndn );
243
244                 /* newSuperior == oldParent? */
245                 if ( strcmp( p_ndn, np_ndn ) == 0 ) {
246 #ifdef NEW_LOGGING
247                         LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
248                                    "ldbm_back_modrdn: new parent\"%s\" seems to be the same as the old parent \"%s\"\n",
249                                    newSuperior, p_dn ));
250 #else
251                         Debug( LDAP_DEBUG_TRACE, 
252                                "ldbm_back_modrdn: new parent \"%s\" seems to be the same as old parent \"%s\"...\n",
253                                newSuperior, p_dn, 0 );
254 #endif
255
256                         newSuperior = NULL; /* ignore newSuperior */
257                 }
258         }
259
260         if ( newSuperior != NULL ) {
261
262                 /* newSuperior == entry being moved?, if so ==> ERROR */
263                 /* Get Entry with dn=newSuperior. Does newSuperior exist? */
264
265                 if( (np = dn2entry_w( be, np_ndn, NULL )) == NULL) {
266 #ifdef NEW_LOGGING
267                         LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
268                                    "ldbm_back_modrdn: newSup(ndn=%s) not found.\n", np_ndn ));
269 #else
270                         Debug( LDAP_DEBUG_TRACE,
271                                "ldbm_back_modrdn: newSup(ndn=%s) not here!\n",
272                                np_ndn, 0, 0);
273 #endif
274
275                         send_ldap_result( conn, op, LDAP_OTHER,
276                                 NULL, NULL, NULL, NULL );
277                         goto return_results;
278                 }
279
280 #ifdef NEW_LOGGING
281                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
282                            "ldbm_back_modrdn: wr to new parent OK np=%p, id=%ld\n",
283                            np, np->e_id ));
284 #else
285                 Debug( LDAP_DEBUG_TRACE,
286                        "ldbm_back_modrdn: wr to new parent OK np=%p, id=%ld\n",
287                        np, np->e_id, 0 );
288 #endif
289
290             
291                 /* check newSuperior for "children" acl */
292                 if ( !access_allowed( be, conn, op, np, children, NULL,
293                                       ACL_WRITE ) )
294                 {
295 #ifdef NEW_LOGGING
296                         LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
297                                    "ldbm_back_modrdn: no wr to newSup children.\n" ));
298 #else
299                         Debug( LDAP_DEBUG_TRACE,
300                                "ldbm_back_modrdn: no wr to newSup children\n",
301                                0, 0, 0 );
302 #endif
303
304                         send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
305                                 NULL, NULL, NULL, NULL );
306                         goto return_results;
307                 }
308
309                 if ( is_entry_alias( np ) ) {
310                         /* entry is an alias, don't allow bind */
311 #ifdef NEW_LOGGING
312                         LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
313                                    "ldbm_back_modrdn: entry (%s) is an alias.\n", np->e_dn ));
314 #else
315                         Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0,
316                             0, 0 );
317 #endif
318
319
320                         send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM,
321                             NULL, NULL, NULL, NULL );
322
323                         goto return_results;
324                 }
325
326                 if ( is_entry_referral( np ) ) {
327                         /* parent is a referral, don't allow add */
328                         /* parent is an alias, don't allow add */
329 #ifdef NEW_LOGGING
330                         LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
331                                    "ldbm_back_modrdn: entry (%s) is a referral\n",
332                                    np->e_dn ));
333 #else
334                         Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
335                                 0, 0 );
336 #endif
337
338
339                         send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
340                             NULL, NULL, NULL, NULL );
341
342                         goto return_results;
343                 }
344
345 #ifdef NEW_LOGGING
346                 LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
347                            "ldbm_back_modrdn: wr to new parent's children OK.\n" ));
348 #else
349                 Debug( LDAP_DEBUG_TRACE,
350                        "ldbm_back_modrdn: wr to new parent's children OK\n",
351                        0, 0 , 0 );
352 #endif
353
354
355                 new_parent_dn = np_dn;
356         }
357         
358         /* Build target dn and make sure target entry doesn't exist already. */
359
360         build_new_dn( &new_dn, e->e_dn, new_parent_dn, newrdn ); 
361
362
363         new_ndn = ch_strdup(new_dn);
364         (void) dn_normalize( new_ndn );
365
366 #ifdef NEW_LOGGING
367         LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
368                    "ldbm_back_modrdn: new ndn=%s\n", new_ndn ));
369 #else
370         Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: new ndn=%s\n",
371                new_ndn, 0, 0 );
372 #endif
373
374
375         /* check for abandon */
376         ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
377         if ( op->o_abandon ) {
378                 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
379                 goto return_results;
380         }
381
382         ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
383         if (dn2id ( be, new_ndn ) != NOID) {
384                 send_ldap_result( conn, op, LDAP_ALREADY_EXISTS,
385                         NULL, NULL, NULL, NULL );
386                 goto return_results;
387         }
388
389 #ifdef NEW_LOGGING
390         LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
391                    "ldbm_back_modrdn: new ndn (%s) does not exist\n", new_ndn ));
392 #else
393         Debug( LDAP_DEBUG_TRACE,
394                "ldbm_back_modrdn: new ndn=%s does not exist\n",
395                new_ndn, 0, 0 );
396 #endif
397
398
399         /* Get attribute type and attribute value of our new rdn, we will
400          * need to add that to our new entry
401          */
402
403         if ( (new_rdn_type = rdn_attr_type( newrdn )) == NULL ) {
404             
405 #ifdef NEW_LOGGING
406                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
407                            "ldbm_back_modrdn: can't figure out type of newrdn\n" ));
408 #else
409                 Debug( LDAP_DEBUG_TRACE,
410                        "ldbm_back_modrdn: can't figure out type of newrdn\n",
411                        0, 0, 0 );
412 #endif
413
414                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
415                         NULL, "unknown type used in RDN", NULL, NULL );
416                 goto return_results;            
417
418         }
419
420         if ( (new_rdn_val = rdn_attr_value( newrdn )) == NULL ) {
421             
422 #ifdef NEW_LOGGING
423                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
424                            "ldbm_back_modrdn: can't figure out val of newrdn\n"));
425 #else
426                 Debug( LDAP_DEBUG_TRACE,
427                        "ldbm_back_modrdn: can't figure out val of newrdn\n",
428                        0, 0, 0 );
429 #endif
430
431                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
432                         NULL, "could not parse RDN value", NULL, NULL );
433                 goto return_results;            
434
435         }
436
437 #ifdef NEW_LOGGING
438         LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
439                    "ldbm_back_modrdn: new_rdn_val=\"%s\", new_rdn_type=\"%s\"\n",
440                    new_rdn_val, new_rdn_type ));
441 #else
442         Debug( LDAP_DEBUG_TRACE,
443                "ldbm_back_modrdn: new_rdn_val=\"%s\", new_rdn_type=\"%s\"\n",
444                new_rdn_val, new_rdn_type, 0 );
445 #endif
446
447
448         /* Retrieve the old rdn from the entry's dn */
449
450         if ( (old_rdn = dn_rdn( be, dn )) == NULL ) {
451 #ifdef NEW_LOGGING
452                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
453                            "ldbm_back_modrdn: can't figure out old_rdn from dn (%s)\n",
454                            dn ));
455 #else
456                 Debug( LDAP_DEBUG_TRACE,
457                        "ldbm_back_modrdn: can't figure out old_rdn from dn\n",
458                        0, 0, 0 );
459 #endif
460
461                 send_ldap_result( conn, op, LDAP_OTHER,
462                         NULL, "could not parse old DN", NULL, NULL );
463                 goto return_results;            
464         }
465
466         if ( (old_rdn_type = rdn_attr_type( old_rdn )) == NULL ) {
467 #ifdef NEW_LOGGING
468                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
469                            "ldbm_back_modrdn: can't figure out the old_rdn type.\n" ));
470 #else
471                 Debug( LDAP_DEBUG_TRACE,
472                        "ldbm_back_modrdn: can't figure out the old_rdn type\n",
473                        0, 0, 0 );
474 #endif
475
476                 send_ldap_result( conn, op, LDAP_OTHER,
477                         NULL, "count parse RDN from old DN", NULL, NULL );
478                 goto return_results;            
479         }
480         
481         if ( strcasecmp( old_rdn_type, new_rdn_type ) != 0 ) {
482             /* Not a big deal but we may say something */
483 #ifdef NEW_LOGGING
484             LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
485                        "ldbm_back_modrdn: old_rdn_type=%s new_rdn_type-%s\n",
486                        old_rdn_type, new_rdn_type ));
487 #else
488             Debug( LDAP_DEBUG_TRACE,
489                    "ldbm_back_modrdn: old_rdn_type=%s, new_rdn_type=%s!\n",
490                    old_rdn_type, new_rdn_type, 0 );
491 #endif
492
493         }               
494
495 #ifdef NEW_LOGGING
496         LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
497                    "ldbm_back_modrdn:  DN_X500\n" ));
498 #else
499                 Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: DN_X500\n",
500                        0, 0, 0 );
501 #endif
502
503                 
504                 /* Add new attribute value to the entry.
505                  */
506
507                 add_bvals[0] = &add_bv;         /* Array of bervals */
508                 add_bvals[1] = NULL;
509
510                 add_bv.bv_val = new_rdn_val;
511                 add_bv.bv_len = strlen(new_rdn_val);
512                 
513                 {
514                         int rc;
515
516                         mod[0].sml_desc = NULL;
517                         rc = slap_str2ad( new_rdn_type, &mod[0].sml_desc, &text );
518
519                         if( rc != LDAP_SUCCESS ) {
520 #ifdef NEW_LOGGING
521                                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
522                                            "ldbm_back_modrdn: slap_str2ad error: %s (%s)\n",
523                                            text, new_rdn_type ));
524 #else
525                                 Debug( LDAP_DEBUG_TRACE,
526                                         "ldbm_back_modrdn: %s: %s (new)\n",
527                                         text, new_rdn_type, 0 );
528 #endif
529
530                                 send_ldap_result( conn, op, rc,
531                                         NULL, text, NULL, NULL );
532                                 goto return_results;            
533                         }
534                 }
535                 mod[0].sml_bvalues = add_bvals;
536                 mod[0].sml_op = SLAP_MOD_SOFTADD;
537                 mod[0].sml_next = NULL;
538
539                 /* Remove old rdn value if required */
540
541                 if (deleteoldrdn) {
542                         /* Get value of old rdn */
543         
544                         if ((old_rdn_val = rdn_attr_value( old_rdn ))
545                             == NULL) {
546                             
547 #ifdef NEW_LOGGING
548                                 LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
549                                            "ldbm_back_modrdn: can't figure out old_rdn_val from old_rdn\n" ));
550 #else
551                                 Debug( LDAP_DEBUG_TRACE,
552                                        "ldbm_back_modrdn: can't figure out old_rdn_val from old_rdn\n",
553                                        0, 0, 0 );
554 #endif
555
556                                 send_ldap_result( conn, op, LDAP_OTHER,
557                                         NULL, "could not parse value from old RDN", NULL, NULL );
558                                 goto return_results;            
559                         }
560
561                         del_bvals[0] = &del_bv;         /* Array of bervals */
562                         del_bvals[1] = NULL;
563
564                         /* Remove old value of rdn as an attribute. */
565                     
566                         del_bv.bv_val = old_rdn_val;
567                         del_bv.bv_len = strlen(old_rdn_val);
568
569                         {
570                                 int rc;
571
572                                 mod[1].sml_desc = NULL;
573                                 rc = slap_str2ad( old_rdn_type, &mod[1].sml_desc, &text );
574
575                                 if( rc != LDAP_SUCCESS ) {
576 #ifdef NEW_LOGGING
577                                         LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
578                                                    "ldbm_back_modrdn: %s: %s (old)\n",
579                                                    text, old_rdn_type ));
580 #else
581                                         Debug( LDAP_DEBUG_TRACE,
582                                                 "ldbm_back_modrdn: %s: %s (old)\n",
583                                                 text, old_rdn_type, 0 );
584 #endif
585
586                                         send_ldap_result( conn, op, rc,
587                                                 NULL, text, NULL, NULL );
588                                         goto return_results;            
589                                 }
590                         }
591                         mod[0].sml_next = &mod[1];
592                         mod[1].sml_bvalues = del_bvals;
593                         mod[1].sml_op = LDAP_MOD_DELETE;
594                         mod[1].sml_next = NULL;
595
596 #ifdef NEW_LOGGING
597                         LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
598                                    "ldbm_back_modrdn: removing old_rdn_val=%s\n", old_rdn_val ));
599 #else
600                         Debug( LDAP_DEBUG_TRACE,
601                                "ldbm_back_modrdn: removing old_rdn_val=%s\n",
602                                old_rdn_val, 0, 0 );
603 #endif
604
605                 }
606         
607         /* check for abandon */
608         ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
609         if ( op->o_abandon ) {
610                 ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
611                 goto return_results;
612         }
613         ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
614
615         /* delete old one */
616         if ( dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) {
617                 send_ldap_result( conn, op, LDAP_OTHER,
618                         NULL, "DN index delete fail", NULL, NULL );
619                 goto return_results;
620         }
621
622         (void) cache_delete_entry( &li->li_cache, e );
623
624         /* XXX: there is no going back! */
625
626         free( e->e_dn );
627         free( e->e_ndn );
628         e->e_dn = new_dn;
629         e->e_ndn = new_ndn;
630         new_dn = NULL;
631         new_ndn = NULL;
632
633         /* add new one */
634         if ( dn2id_add( be, e->e_ndn, e->e_id ) != 0 ) {
635                 send_ldap_result( conn, op, LDAP_OTHER,
636                         NULL, "DN index add failed", NULL, NULL );
637                 goto return_results;
638         }
639
640         /* modify memory copy of entry */
641         rc = ldbm_modify_internal( be, conn, op, dn, &mod[0], e, &text );
642
643         if( rc != LDAP_SUCCESS ) {
644                 if( rc != SLAPD_ABANDON ) {
645                         send_ldap_result( conn, op, rc,
646                                 NULL, text, NULL, NULL );
647                 }
648             
649             goto return_results;
650         }
651         
652         (void) cache_update_entry( &li->li_cache, e );
653
654         /* NOTE: after this you must not free new_dn or new_ndn!
655          * They are used by cache.
656          */
657
658         /* id2entry index */
659         if ( id2entry_add( be, e ) != 0 ) {
660                 entry_free( e );
661                 send_ldap_result( conn, op, LDAP_OTHER,
662                         NULL, "entry update failed", NULL, NULL );
663                 goto return_results;
664         }
665
666         send_ldap_result( conn, op, LDAP_SUCCESS,
667                 NULL, NULL, NULL, NULL );
668         rc = 0;
669
670 return_results:
671         if( new_dn != NULL ) free( new_dn );
672         if( new_ndn != NULL ) free( new_ndn );
673
674         if( p_dn != NULL ) free( p_dn );
675         if( p_ndn != NULL ) free( p_ndn );
676
677         /* LDAP v2 supporting correct attribute handling. */
678         if( new_rdn_type != NULL ) free(new_rdn_type);
679         if( new_rdn_val != NULL ) free(new_rdn_val);
680         if( old_rdn != NULL ) free(old_rdn);
681         if( old_rdn_type != NULL ) free(old_rdn_type);
682         if( old_rdn_val != NULL ) free(old_rdn_val);
683
684
685         /* LDAP v3 Support */
686         if ( np_dn != NULL ) free( np_dn );
687         if ( np_ndn != NULL ) free( np_ndn );
688
689         if( np != NULL ) {
690                 /* free new parent and writer lock */
691                 cache_return_entry_w( &li->li_cache, np );
692         }
693
694         if( p != NULL ) {
695                 /* free parent and writer lock */
696                 cache_return_entry_w( &li->li_cache, p );
697         }
698
699         if ( rootlock ) {
700                 /* release root writer lock */
701                 ldap_pvt_thread_mutex_unlock(&li->li_root_mutex);
702         }
703
704         /* free entry and writer lock */
705         cache_return_entry_w( &li->li_cache, e );
706         return( rc );
707 }