More struct berval fixes for modrdn

This commit is contained in:
Howard Chu 2001-12-27 01:10:52 +00:00
parent 02700a4f14
commit 0e5e2a95fd

View File

@ -48,8 +48,8 @@ ldbm_back_modrdn(
{ {
AttributeDescription *children = slap_schema.si_ad_children; AttributeDescription *children = slap_schema.si_ad_children;
struct ldbminfo *li = (struct ldbminfo *) be->be_private; struct ldbminfo *li = (struct ldbminfo *) be->be_private;
char *p_dn = NULL, *p_ndn = NULL; struct berval p_dn, p_ndn;
char *new_dn = NULL, *new_ndn = NULL; struct berval new_dn = { 0, NULL}, *new_ndn = NULL;
Entry *e, *p = NULL; Entry *e, *p = NULL;
Entry *matched; Entry *matched;
int isroot = -1; int isroot = -1;
@ -71,9 +71,9 @@ ldbm_back_modrdn(
char **old_rdn_vals = NULL; /* Old rdn attribute values */ char **old_rdn_vals = NULL; /* Old rdn attribute values */
/* Added to support newSuperior */ /* Added to support newSuperior */
Entry *np = NULL; /* newSuperior Entry */ Entry *np = NULL; /* newSuperior Entry */
char *np_dn = NULL; /* newSuperior dn */ struct berval *np_dn = NULL; /* newSuperior dn */
char *np_ndn = NULL; /* newSuperior ndn */ struct berval *np_ndn = NULL; /* newSuperior ndn */
char *new_parent_dn = NULL; /* np_dn, p_dn, or NULL */ struct berval *new_parent_dn = NULL; /* np_dn, p_dn, or NULL */
/* Used to interface with ldbm_modify_internal() */ /* Used to interface with ldbm_modify_internal() */
Modifications *mod = NULL; /* Used to delete old/add new rdn */ Modifications *mod = NULL; /* Used to delete old/add new rdn */
int manageDSAit = get_manageDSAit( op ); int manageDSAit = get_manageDSAit( op );
@ -152,12 +152,15 @@ ldbm_back_modrdn(
goto return_results; goto return_results;
} }
if ( (p_ndn = dn_parent( be, e->e_ndn )) != NULL && p_ndn[0] != '\0' ) { p_ndn.bv_val = dn_parent( be, e->e_ndn );
p_ndn.bv_len = e->e_nname.bv_len - (p_ndn.bv_val - e->e_ndn);
if ( p_ndn.bv_len != 0 ) {
/* Make sure parent entry exist and we can write its /* Make sure parent entry exist and we can write its
* children. * children.
*/ */
if( (p = dn2entry_w( be, p_ndn, NULL )) == NULL) { if( (p = dn2entry_w( be, p_ndn.bv_val, NULL )) == NULL) {
#ifdef NEW_LOGGING #ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_INFO, LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
"ldbm_back_modrdn: parent of %s does not exist\n", e->e_ndn )); "ldbm_back_modrdn: parent of %s does not exist\n", e->e_ndn ));
@ -192,21 +195,22 @@ ldbm_back_modrdn(
#ifdef NEW_LOGGING #ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1, LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
"ldbm_back_modrdn: wr to children of entry %s OK\n", "ldbm_back_modrdn: wr to children of entry %s OK\n",
p_ndn )); p_ndn.bv_val ));
#else #else
Debug( LDAP_DEBUG_TRACE, Debug( LDAP_DEBUG_TRACE,
"ldbm_back_modrdn: wr to children of entry %s OK\n", "ldbm_back_modrdn: wr to children of entry %s OK\n",
p_ndn, 0, 0 ); p_ndn.bv_val, 0, 0 );
#endif #endif
p_dn = dn_parent( be, e->e_dn ); p_dn.bv_val = dn_parent( be, e->e_dn );
p_dn.bv_len = e->e_name.bv_len - (p_dn.bv_val - e->e_dn);
#ifdef NEW_LOGGING #ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1, LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
"ldbm_back_modrdn: parent dn=%s\n", p_dn )); "ldbm_back_modrdn: parent dn=%s\n", p_dn.bv_val ));
#else #else
Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: parent dn=%s\n", Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: parent dn=%s\n",
p_dn, 0, 0 ); p_dn.bv_val, 0, 0 );
#endif #endif
} else { } else {
@ -269,7 +273,7 @@ ldbm_back_modrdn(
#endif #endif
} }
new_parent_dn = p_dn; /* New Parent unless newSuperior given */ new_parent_dn = &p_dn; /* New Parent unless newSuperior given */
if ( newSuperior != NULL ) { if ( newSuperior != NULL ) {
#ifdef NEW_LOGGING #ifdef NEW_LOGGING
@ -282,22 +286,22 @@ ldbm_back_modrdn(
newSuperior->bv_val, 0, 0 ); newSuperior->bv_val, 0, 0 );
#endif #endif
np_dn = ch_strdup( newSuperior->bv_val ); np_dn = newSuperior;
np_ndn = ch_strdup( np_dn ); np_ndn = nnewSuperior;
(void) dn_normalize( np_ndn );
/* newSuperior == oldParent? */ /* newSuperior == oldParent? */
if ( strcmp( p_ndn, np_ndn ) == 0 ) { if ( p_ndn.bv_len == np_ndn->bv_len &&
strcmp( p_ndn.bv_val, np_ndn->bv_val ) == 0 ) {
#ifdef NEW_LOGGING #ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_INFO, "ldbm_back_modrdn: " LDAP_LOG(( "backend", LDAP_LEVEL_INFO, "ldbm_back_modrdn: "
"new parent\"%s\" seems to be the same as the " "new parent\"%s\" seems to be the same as the "
"old parent \"%s\"\n", "old parent \"%s\"\n",
newSuperior->bv_val, p_dn )); newSuperior->bv_val, p_dn.bv_val ));
#else #else
Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: " Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: "
"new parent\"%s\" seems to be the same as the " "new parent\"%s\" seems to be the same as the "
"old parent \"%s\"\n", "old parent \"%s\"\n",
newSuperior->bv_val, p_dn, 0 ); newSuperior->bv_val, p_dn.bv_val, 0 );
#endif #endif
newSuperior = NULL; /* ignore newSuperior */ newSuperior = NULL; /* ignore newSuperior */
@ -309,14 +313,14 @@ ldbm_back_modrdn(
/* Get Entry with dn=newSuperior. Does newSuperior exist? */ /* Get Entry with dn=newSuperior. Does newSuperior exist? */
if ( nnewSuperior->bv_len ) { if ( nnewSuperior->bv_len ) {
if( (np = dn2entry_w( be, np_ndn, NULL )) == NULL) { if( (np = dn2entry_w( be, np_ndn->bv_val, NULL )) == NULL) {
#ifdef NEW_LOGGING #ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_ERR, LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
"ldbm_back_modrdn: newSup(ndn=%s) not found.\n", np_ndn )); "ldbm_back_modrdn: newSup(ndn=%s) not found.\n", np_ndn->bv_val ));
#else #else
Debug( LDAP_DEBUG_TRACE, Debug( LDAP_DEBUG_TRACE,
"ldbm_back_modrdn: newSup(ndn=%s) not here!\n", "ldbm_back_modrdn: newSup(ndn=%s) not here!\n",
np_ndn, 0, 0); np_ndn->bv_val, 0, 0);
#endif #endif
send_ldap_result( conn, op, LDAP_OTHER, send_ldap_result( conn, op, LDAP_OTHER,
@ -451,17 +455,15 @@ ldbm_back_modrdn(
} }
/* Build target dn and make sure target entry doesn't exist already. */ /* Build target dn and make sure target entry doesn't exist already. */
build_new_dn( &new_dn, e->e_dn, new_parent_dn, newrdn->bv_val ); build_new_dn( &new_dn, new_parent_dn, newrdn );
dnNormalize( NULL, &new_dn, &new_ndn );
new_ndn = ch_strdup( new_dn );
(void) dn_normalize( new_ndn );
#ifdef NEW_LOGGING #ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1, LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
"ldbm_back_modrdn: new ndn=%s\n", new_ndn )); "ldbm_back_modrdn: new ndn=%s\n", new_ndn->bv_val ));
#else #else
Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: new ndn=%s\n", Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: new ndn=%s\n",
new_ndn, 0, 0 ); new_ndn->bv_val, 0, 0 );
#endif #endif
/* check for abandon */ /* check for abandon */
@ -472,7 +474,7 @@ ldbm_back_modrdn(
} }
ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex ); ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
if ( ( rc_id = dn2id ( be, new_ndn, &id ) ) || id != NOID ) { if ( ( rc_id = dn2id ( be, new_ndn->bv_val, &id ) ) || id != NOID ) {
/* if (rc_id) something bad happened to ldbm cache */ /* if (rc_id) something bad happened to ldbm cache */
send_ldap_result( conn, op, send_ldap_result( conn, op,
rc_id ? LDAP_OPERATIONS_ERROR : LDAP_ALREADY_EXISTS, rc_id ? LDAP_OPERATIONS_ERROR : LDAP_ALREADY_EXISTS,
@ -742,11 +744,9 @@ ldbm_back_modrdn(
free( e->e_dn ); free( e->e_dn );
free( e->e_ndn ); free( e->e_ndn );
e->e_dn = new_dn; e->e_name = new_dn;
e->e_name.bv_len = strlen( new_dn ); e->e_nname = *new_ndn;
e->e_ndn = new_ndn; new_dn.bv_val = NULL;
e->e_nname.bv_len = strlen( new_ndn );
new_dn = NULL;
new_ndn = NULL; new_ndn = NULL;
/* add new one */ /* add new one */
@ -794,8 +794,8 @@ ldbm_back_modrdn(
cache_entry_commit( e ); cache_entry_commit( e );
return_results: return_results:
if( new_dn != NULL ) free( new_dn ); if( new_dn.bv_val != NULL ) free( new_dn.bv_val );
if( new_ndn != NULL ) free( new_ndn ); if( new_ndn != NULL ) ber_bvfree( new_ndn );
/* LDAP v2 supporting correct attribute handling. */ /* LDAP v2 supporting correct attribute handling. */
if( new_rdn_types != NULL ) charray_free( new_rdn_types ); if( new_rdn_types != NULL ) charray_free( new_rdn_types );
@ -809,9 +809,6 @@ return_results:
} }
/* LDAP v3 Support */ /* LDAP v3 Support */
if ( np_dn != NULL ) free( np_dn );
if ( np_ndn != NULL ) free( np_ndn );
if( np != NULL ) { if( np != NULL ) {
/* free new parent and writer lock */ /* free new parent and writer lock */
cache_return_entry_w( &li->li_cache, np ); cache_return_entry_w( &li->li_cache, np );