]> git.sur5r.net Git - openldap/commitdiff
honors '+' rdn separator in adding/deleting attributes; needs -DMULTIATTRVAL_RDN...
authorPierangelo Masarati <ando@openldap.org>
Fri, 6 Jul 2001 12:24:34 +0000 (12:24 +0000)
committerPierangelo Masarati <ando@openldap.org>
Fri, 6 Jul 2001 12:24:34 +0000 (12:24 +0000)
servers/slapd/back-ldbm/modrdn.c

index 19b0da05a2f26814ed8eae40e872fa08c28f7db5..090444c7a73d53ba7ae9b59b84f84b91833ef95e 100644 (file)
@@ -57,22 +57,37 @@ ldbm_back_modrdn(
        char textbuf[SLAP_TEXT_BUFLEN];
        size_t textlen = sizeof textbuf;
        /* Added to support LDAP v2 correctly (deleteoldrdn thing) */
+#ifndef MULTIATTRVAL_RDN
        char            *new_rdn_val = NULL;    /* Val of new rdn */
        char            *new_rdn_type = NULL;   /* Type of new rdn */
+#else /* MULTIATTRVAL_RDN */
+       char            **new_rdn_vals = NULL;  /* Vals of new rdn */
+       char            **new_rdn_types = NULL; /* Types of new rdn */
+       int             a_cnt, d_cnt;
+#endif /* MULTIATTRVAL_RDN */
        char            *old_rdn = NULL;        /* Old rdn's attr type & val */
+#ifndef MULTIATTRVAL_RDN
        char            *old_rdn_type = NULL;   /* Type of old rdn attr. */
        char            *old_rdn_val = NULL;    /* Old rdn attribute value */
+#else /* MULTIATTRVAL_RDN */
+       char            **old_rdn_types = NULL; /* Types of old rdn attrs. */
+       char            **old_rdn_vals = NULL;  /* Old rdn attribute values */
+#endif /* MULTIATTRVAL_RDN */
        /* Added to support newSuperior */ 
        Entry           *np = NULL;     /* newSuperior Entry */
        char            *np_dn = NULL;  /* newSuperior dn */
        char            *np_ndn = NULL; /* newSuperior ndn */
        char            *new_parent_dn = NULL;  /* np_dn, p_dn, or NULL */
        /* Used to interface with ldbm_modify_internal() */
+#ifndef MULTIATTRVAL_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 */
        Modifications   mod[2];                 /* Used to delete old rdn */
+#else /* MULTIATTRVAL_RDN */
+       Modifications   *mod = NULL;            /* Used to delete old/add new rdn */
+#endif /* MULTIATTRVAL_RDN */
        int             manageDSAit = get_manageDSAit( op );
 
 #ifdef NEW_LOGGING
@@ -137,7 +152,7 @@ ldbm_back_modrdn(
                LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
                           "ldbm_back_modrdn: entry %s has children\n", e->e_dn ));
 #else
-               Debug( LDAP_DEBUG_TRACE, "entry %s referral\n", 0,
+               Debug( LDAP_DEBUG_TRACE, "entry %s referral\n", e->e_dn,
                    0, 0 );
 #endif
 
@@ -398,6 +413,8 @@ ldbm_back_modrdn(
               new_ndn, 0, 0 );
 #endif
 
+#ifndef MULTIATTRVAL_RDN /* Ando 2001/07/06 */
+
        /* Get attribute type and attribute value of our new rdn, we will
         * need to add that to our new entry
         */
@@ -469,7 +486,7 @@ ldbm_back_modrdn(
 #endif
 
                send_ldap_result( conn, op, LDAP_OTHER,
-                       NULL, "count parse RDN from old DN", NULL, NULL );
+                       NULL, "could not parse RDN from old DN", NULL, NULL );
                goto return_results;            
        }
        
@@ -596,6 +613,194 @@ ldbm_back_modrdn(
                               old_rdn_val, 0, 0 );
 #endif
                }
+
+#else /* MULTIATTRVAL_RDN */
+
+       /* Get attribute types and values of our new rdn, we will
+        * need to add that to our new entry
+        */
+       if ( !rdn_attrs( newrdn, &new_rdn_types, &new_rdn_vals ) ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
+                          "ldbm_back_modrdn: can't figure out type(s)/value(s) of newrdn\n" ));
+#else
+               Debug( LDAP_DEBUG_TRACE,
+                      "ldbm_back_modrdn: can't figure out type(s)/value(s) of newrdn\n",
+                      0, 0, 0 );
+#endif
+
+               send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
+                       NULL, "unable to parse type(s)/value(s) used in RDN", NULL, NULL );
+               goto return_results;            
+       }
+
+#ifdef NEW_LOGGING
+       LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
+                  "ldbm_back_modrdn: new_rdn_val=\"%s\", new_rdn_type=\"%s\"\n",
+                  new_rdn_vals[0], new_rdn_types[0] ));
+#else
+       Debug( LDAP_DEBUG_TRACE,
+              "ldbm_back_modrdn: new_rdn_val=\"%s\", new_rdn_type=\"%s\"\n",
+              new_rdn_vals[0], new_rdn_types[0], 0 );
+#endif
+
+       /* Retrieve the old rdn from the entry's dn */
+       if ( (old_rdn = dn_rdn( be, dn )) == NULL ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
+                          "ldbm_back_modrdn: can't figure out old_rdn from dn (%s)\n",
+                          dn ));
+#else
+               Debug( LDAP_DEBUG_TRACE,
+                      "ldbm_back_modrdn: can't figure out old_rdn from dn\n",
+                      0, 0, 0 );
+#endif
+
+               send_ldap_result( conn, op, LDAP_OTHER,
+                       NULL, "could not parse old DN", NULL, NULL );
+               goto return_results;            
+       }
+
+       if ( !rdn_attrs( old_rdn, &old_rdn_types, &old_rdn_vals ) ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
+                          "ldbm_back_modrdn: can't figure out the old_rdn type(s)/value(s).\n" ));
+#else
+               Debug( LDAP_DEBUG_TRACE,
+                      "ldbm_back_modrdn: can't figure out the old_rdn type(s)/value(s)\n",
+                      0, 0, 0 );
+#endif
+
+               send_ldap_result( conn, op, LDAP_OTHER,
+                       NULL, "unable to parse type(s)/value(s) used in RDN from old DN", NULL, NULL );
+               goto return_results;            
+       }
+       
+       if ( newSuperior == NULL
+               && charray_strcasecmp( (const char **)old_rdn_types, (const char **)new_rdn_types ) != 0 )
+       {
+           /* Not a big deal but we may say something */
+#ifdef NEW_LOGGING
+           LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
+                      "ldbm_back_modrdn: old_rdn_type=%s new_rdn_type=%s\n",
+                      old_rdn_types[0], new_rdn_types[0] ));
+#else
+           Debug( LDAP_DEBUG_TRACE,
+                  "ldbm_back_modrdn: old_rdn_type=%s, new_rdn_type=%s!\n",
+                  old_rdn_types[0], new_rdn_types[0], 0 );
+#endif
+       }               
+
+#ifdef NEW_LOGGING
+       LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
+                  "ldbm_back_modrdn:  DN_X500\n" ));
+#else
+       Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: DN_X500\n",
+              0, 0, 0 );
+#endif
+
+       mod = NULL;
+       for ( a_cnt = 0; new_rdn_types[a_cnt]; a_cnt++ ) {
+               int rc;
+               Modifications *mod_tmp;
+
+               mod_tmp = (Modifications *)ch_malloc( sizeof( Modifications ) );
+
+               mod_tmp->sml_desc = NULL;
+               rc = slap_str2ad( new_rdn_types[a_cnt], 
+                               &mod_tmp->sml_desc, &text );
+
+               if ( rc != LDAP_SUCCESS ) {
+#ifdef NEW_LOGGING
+                       LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
+                                  "ldbm_back_modrdn: slap_str2ad error: %s (%s)\n",
+                                  text, new_rdn_types[a_cnt] ));
+#else
+                       Debug( LDAP_DEBUG_TRACE,
+                               "ldbm_back_modrdn: %s: %s (new)\n",
+                               text, new_rdn_types[a_cnt], 0 );
+#endif
+
+                       send_ldap_result( conn, op, rc,
+                               NULL, text, NULL, NULL );
+
+                       goto return_results;            
+               }
+
+               mod_tmp->sml_bvalues = (struct berval **)ch_malloc( 2 * sizeof(struct berval *) );
+               mod_tmp->sml_bvalues[0] = ber_bvstrdup( new_rdn_vals[a_cnt] );
+               mod_tmp->sml_bvalues[1] = NULL;
+               mod_tmp->sml_op = SLAP_MOD_SOFTADD;
+               mod_tmp->sml_next = mod;
+               mod = mod_tmp;
+       }
+
+       /* Remove old rdn value if required */
+       if ( deleteoldrdn ) {
+               /* Get value of old rdn */
+               if ( old_rdn_vals == NULL ) {
+#ifdef NEW_LOGGING
+                       LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
+                                  "ldbm_back_modrdn: can't figure out old RDN value(s) from old RDN\n" ));
+#else
+                       Debug( LDAP_DEBUG_TRACE,
+                              "ldbm_back_modrdn: can't figure out oldRDN value(s) from old RDN\n",
+                              0, 0, 0 );
+#endif
+
+                       send_ldap_result( conn, op, LDAP_OTHER,
+                               NULL, "could not parse value(s) from old RDN", NULL, NULL );
+                       goto return_results;            
+               }
+
+               for ( d_cnt = 0; old_rdn_types[d_cnt]; d_cnt++ ) {    
+                       int rc;
+                       Modifications *mod_tmp;
+
+                       mod_tmp = (Modifications *)ch_malloc( sizeof( Modifications ) );
+
+
+                       mod_tmp->sml_desc = NULL;
+                       rc = slap_str2ad( old_rdn_types[d_cnt], 
+                                       &mod_tmp->sml_desc, &text );
+
+                       if ( rc != LDAP_SUCCESS ) {
+#ifdef NEW_LOGGING
+                               LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
+                                          "ldbm_back_modrdn: %s: %s (old)\n",
+                                          text, old_rdn_types[d_cnt] ));
+#else
+                               Debug( LDAP_DEBUG_TRACE,
+                                       "ldbm_back_modrdn: %s: %s (old)\n",
+                                       text, old_rdn_types[d_cnt], 0 );
+#endif
+
+                               send_ldap_result( conn, op, rc,
+                                       NULL, text, NULL, NULL );
+
+                               goto return_results;
+                       }
+
+                       /* Remove old value of rdn as an attribute. */
+                       mod_tmp->sml_bvalues = (struct berval **)ch_malloc( 2 * sizeof(struct berval *) );
+                       mod_tmp->sml_bvalues[0] = ber_bvstrdup( old_rdn_vals[d_cnt] );
+                       mod_tmp->sml_bvalues[1] = NULL;
+                       mod_tmp->sml_op = LDAP_MOD_DELETE;
+                       mod_tmp->sml_next = mod;
+                       mod = mod_tmp;
+
+#ifdef NEW_LOGGING
+                       LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
+                                  "ldbm_back_modrdn: removing old_rdn_val=%s\n", old_rdn_vals[0] ));
+#else
+                       Debug( LDAP_DEBUG_TRACE,
+                              "ldbm_back_modrdn: removing old_rdn_val=%s\n",
+                              old_rdn_vals[0], 0, 0 );
+#endif
+               }
+       }
+
+#endif /* MULTIATTRVAL_RDN */
        
        /* check for abandon */
        ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
@@ -669,11 +874,27 @@ return_results:
        if( p_ndn != NULL ) free( p_ndn );
 
        /* LDAP v2 supporting correct attribute handling. */
+#ifndef MULTIATTRVAL_RDN
        if( new_rdn_type != NULL ) free(new_rdn_type);
        if( new_rdn_val != NULL ) free(new_rdn_val);
+#else /* MULTIATTRVAL_RDN */
+       if( new_rdn_types != NULL ) charray_free( new_rdn_types );
+       if( new_rdn_vals != NULL ) charray_free( new_rdn_vals );
+#endif /* MULTIATTRVAL_RDN */
        if( old_rdn != NULL ) free(old_rdn);
+#ifndef MULTIATTRVAL_RDN
        if( old_rdn_type != NULL ) free(old_rdn_type);
        if( old_rdn_val != NULL ) free(old_rdn_val);
+#else /* MULTIATTRVAL_RDN */
+       if( old_rdn_types != NULL ) charray_free( old_rdn_types );
+       if( old_rdn_vals != NULL ) charray_free( old_rdn_vals );
+#endif /* MULTIATTRVAL_RDN */
+
+#ifdef MULTIATTRVAL_RDN
+       if ( mod != NULL ) {
+               slap_mods_free( mod );
+       }
+#endif /* MULTIATTRVAL_RDN */
 
        /* LDAP v3 Support */
        if ( np_dn != NULL ) free( np_dn );