]> git.sur5r.net Git - openldap/commitdiff
Mirror modrdn special case fix to db2.
authorJuan Gomez <gomez@openldap.org>
Wed, 26 May 1999 12:29:54 +0000 (12:29 +0000)
committerJuan Gomez <gomez@openldap.org>
Wed, 26 May 1999 12:29:54 +0000 (12:29 +0000)
servers/slapd/back-bdb2/modrdn.c

index 9cea47a6824a94412828c35127b52d77c07eeb4e..a8c31693cd153a918a14fcedc43a5bce83e1a08e 100644 (file)
@@ -48,9 +48,11 @@ bdb2i_back_modrdn_internal(
        char            *old_rdn;               /* Old rdn's attr type & val */
        char            *old_rdn_type = NULL;   /* Type of old rdn attr. */
        char            *old_rdn_val = NULL;    /* Old rdn attribute value */
-       struct berval   bv;                     /* Stores new rdn att */
-       struct berval   *bvals[2];              /* Stores new rdn att */
-       LDAPMod         mod;                    /* Used to delete old rdn */
+       struct berval   add_bv;                 /* Stores new rdn att */
+       struct berval   *add_bvals[2];          /* Stores new rdn att */
+       struct berval   del_bv;                 /* Stores old rdn att */
+       struct berval   *del_bvals[2];          /* Stores old rdn att */
+       LDAPMod         mod[2];                 /* Used to delete old rdn */
        /* Added to support newSuperior */ 
        Entry           *np = NULL;     /* newSuperior Entry */
        char            *np_dn = NULL;  /* newSuperior dn */
@@ -284,13 +286,30 @@ bdb2i_back_modrdn_internal(
                Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: DN_X500\n",
                       0, 0, 0 );
 
-               bvals[0] = &bv;         /* Array of bervals */
-               bvals[1] = NULL;
+               /* Add new attribute value to the entry.
+                */
+
+               add_bvals[0] = &add_bv;         /* Array of bervals */
+               add_bvals[1] = NULL;
 
+               add_bv.bv_val = new_rdn_val;
+               add_bv.bv_len = strlen(new_rdn_val);
+               
+               mod[0].mod_type = new_rdn_type; 
+               mod[0].mod_bvalues = add_bvals;
+               mod[0].mod_op = LDAP_MOD_SOFTADD;
+               mod[0].mod_next = NULL;
+               
+               Debug( LDAP_DEBUG_TRACE,
+                      "ldbm_back_modrdn: adding new rdn attr val =%s\n",
+                      new_rdn_val, 0, 0 );
+               
                /* Remove old rdn value if required */
 
                if (deleteoldrdn) {
 
+                       del_bvals[0] = &del_bv;         /* Array of bervals */
+                       del_bvals[1] = NULL;
                        /* Get value of old rdn */
        
                        if ((old_rdn_val = rdn_attr_value( old_rdn ))
@@ -309,60 +328,22 @@ bdb2i_back_modrdn_internal(
 
                        /* Remove old value of rdn as an attribute. */
                    
-                       bv.bv_val = old_rdn_val;
-                       bv.bv_len = strlen(old_rdn_val);
+                       del_bv.bv_val = old_rdn_val;
+                       del_bv.bv_len = strlen(old_rdn_val);
+                       
+                       mod[0].mod_next = &mod[1];
+                       mod[1].mod_type = old_rdn_type; 
+                       mod[1].mod_bvalues = del_bvals;
+                       mod[1].mod_op = LDAP_MOD_DELETE;
+                       mod[1].mod_next = NULL;
 
-                       /* No need to normalize old_rdn_type, delete_values()
-                        * does that for us
-                        */
-                       mod.mod_type = old_rdn_type;    
-                       mod.mod_bvalues = bvals;
-                       mod.mod_op = LDAP_MOD_DELETE;   /* XXX:really needed?*/
-
-                       /* Assembly mod structure */
-
-                       if ( delete_values( e, &mod, op->o_ndn )
-                            != LDAP_SUCCESS ) {
-
-                               /* Could not find old_rdn as an attribute or
-                                * the old value was not present. Return an 
-                                * error.
-                                */
-                               Debug( LDAP_DEBUG_TRACE,
-                                      "ldbm_back_modrdn: old rdn not found or att type doesn't exist\n",
-                                      0, 0, 0);
-                               send_ldap_result( conn, op,
-                                                 LDAP_OPERATIONS_ERROR,
-                                                 "", "");
-                               goto return_results;
-
-                       }
 
                        Debug( LDAP_DEBUG_TRACE,
-                              "ldbm_back_modrdn: removed old_rdn_val=%s\n",
+                              "ldbm_back_modrdn: removing old_rdn_val=%s\n",
                               old_rdn_val, 0, 0 );
                
                }/* if (deleteoldrdn) */
 
-               /* Add new attribute value to the entry.
-                */
-
-               bv.bv_val = new_rdn_val;
-               bv.bv_len = strlen(new_rdn_val);
-               
-               
-               Debug( LDAP_DEBUG_TRACE,
-                      "ldbm_back_modrdn: adding new rdn attr val =%s\n",
-                      new_rdn_val, 0, 0 );
-               
-               /* No need to normalize new_rdn_type, attr_merge does it */
-
-               attr_merge( e, new_rdn_type, bvals );
-       
-               /* Update new_rdn_type if it is an index */
-
-               bdb2i_index_add_values( be, new_rdn_type, bvals, e->e_id );
-       
        } else {
            
 
@@ -375,6 +356,14 @@ bdb2i_back_modrdn_internal(
 
        }
 
+       /* modify memory copy of entry */
+       if ( bdb2i_back_modify_internal( be, conn, op, dn, &mod[0], e )
+            != 0 ) {
+           
+               goto return_results;
+                       
+       }
+       
        (void) bdb2i_cache_update_entry( &li->li_cache, e );
 
        /* NOTE: after this you must not free new_dn or new_ndn!