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