X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-ldbm%2Fmodrdn.c;h=d4209177c4ed2af0aabd1af134516321b50ecd15;hb=80ce3b5cb27549e4e0ac8614546fad682a88db80;hp=fcd9fcc35a6f6c14ca2444386ed6f2eb48d093fb;hpb=42e0d83cb3a1a1c5b25183f1ab74ce7edbe25de7;p=openldap diff --git a/servers/slapd/back-ldbm/modrdn.c b/servers/slapd/back-ldbm/modrdn.c index fcd9fcc35a..d4209177c4 100644 --- a/servers/slapd/back-ldbm/modrdn.c +++ b/servers/slapd/back-ldbm/modrdn.c @@ -1,14 +1,15 @@ /* modrdn.c - ldbm backend modrdn routine */ +#include "portable.h" + #include -#include -#include -#include + +#include +#include + #include "slap.h" #include "back-ldbm.h" - -extern Entry *dn2entry(); -extern char *dn_parent(); +#include "proto-back-ldbm.h" int ldbm_back_modrdn( @@ -24,10 +25,12 @@ ldbm_back_modrdn( char *matched; char *pdn, *newdn, *p; char sep[2]; - Entry *e, *e2; + Entry *e; matched = NULL; - if ( (e = dn2entry( be, dn, &matched )) == NULL ) { + + /* get entry with writer lock */ + if ( (e = dn2entry_w( be, dn, &matched )) == NULL ) { send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched, "" ); if ( matched != NULL ) { free( matched ); @@ -57,21 +60,16 @@ ldbm_back_modrdn( strcat( newdn, pdn ); } } else { - newdn = strdup( newrdn ); + newdn = ch_strdup( newrdn ); } (void) dn_normalize( newdn ); - matched = NULL; - if ( (e2 = dn2entry( be, newdn, &matched )) != NULL ) { + /* get entry with writer lock */ + if ( (dn2id ( be, newdn ) ) != NOID ) { free( newdn ); free( pdn ); send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, NULL, NULL ); - cache_return_entry( &li->li_cache, e2 ); - cache_return_entry( &li->li_cache, e ); - return( -1 ); - } - if ( matched != NULL ) { - free( matched ); + goto error_return; } /* check for abandon */ @@ -80,9 +78,7 @@ ldbm_back_modrdn( pthread_mutex_unlock( &op->o_abandonmutex ); free( newdn ); free( pdn ); - cache_return_entry( &li->li_cache, e2 ); - cache_return_entry( &li->li_cache, e ); - return( -1 ); + goto error_return; } pthread_mutex_unlock( &op->o_abandonmutex ); @@ -91,8 +87,7 @@ ldbm_back_modrdn( free( newdn ); free( pdn ); send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL ); - cache_return_entry( &li->li_cache, e ); - return( -1 ); + goto error_return; } /* delete old one */ @@ -100,8 +95,7 @@ ldbm_back_modrdn( free( newdn ); free( pdn ); send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL ); - cache_return_entry( &li->li_cache, e ); - return( -1 ); + goto error_return; } (void) cache_delete_entry( &li->li_cache, e ); @@ -120,13 +114,19 @@ ldbm_back_modrdn( /* id2entry index */ if ( id2entry_add( be, e ) != 0 ) { entry_free( e ); - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" ); - return( -1 ); + goto error_return; } free( pdn ); - cache_return_entry( &li->li_cache, e ); + + /* free entry and writer lock */ + cache_return_entry_w( &li->li_cache, e ); send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL ); return( 0 ); + +error_return: + /* free entry and writer lock */ + cache_return_entry_w( &li->li_cache, e ); + return( -1 ); }