1998-08-09 08:43:13 +08:00
|
|
|
/* modrdn.c - ldbm backend modrdn routine */
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include "slap.h"
|
|
|
|
#include "back-ldbm.h"
|
1998-09-21 04:22:46 +08:00
|
|
|
#include "proto-back-ldbm.h"
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
ldbm_back_modrdn(
|
|
|
|
Backend *be,
|
|
|
|
Connection *conn,
|
|
|
|
Operation *op,
|
|
|
|
char *dn,
|
|
|
|
char *newrdn,
|
|
|
|
int deleteoldrdn
|
|
|
|
)
|
|
|
|
{
|
|
|
|
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
|
|
|
|
char *matched;
|
|
|
|
char *pdn, *newdn, *p;
|
|
|
|
char sep[2];
|
1998-09-21 04:22:46 +08:00
|
|
|
Entry *e;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
matched = NULL;
|
1998-09-21 04:22:46 +08:00
|
|
|
|
|
|
|
/* get entry with writer lock */
|
|
|
|
if ( (e = dn2entry_w( be, dn, &matched )) == NULL ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched, "" );
|
|
|
|
if ( matched != NULL ) {
|
|
|
|
free( matched );
|
|
|
|
}
|
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (pdn = dn_parent( be, dn )) != NULL ) {
|
|
|
|
/* parent + rdn + separator(s) + null */
|
|
|
|
newdn = (char *) ch_malloc( strlen( pdn ) + strlen( newrdn )
|
|
|
|
+ 3 );
|
|
|
|
if ( dn_type( dn ) == DN_X500 ) {
|
|
|
|
strcpy( newdn, newrdn );
|
|
|
|
strcat( newdn, ", " );
|
|
|
|
strcat( newdn, pdn );
|
|
|
|
} else {
|
|
|
|
strcpy( newdn, newrdn );
|
|
|
|
p = strchr( newrdn, '\0' );
|
|
|
|
p--;
|
|
|
|
if ( *p != '.' && *p != '@' ) {
|
|
|
|
if ( (p = strpbrk( dn, ".@" )) != NULL ) {
|
|
|
|
sep[0] = *p;
|
|
|
|
sep[1] = '\0';
|
|
|
|
strcat( newdn, sep );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
strcat( newdn, pdn );
|
|
|
|
}
|
|
|
|
} else {
|
1998-11-28 04:21:54 +08:00
|
|
|
newdn = ch_strdup( newrdn );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
(void) dn_normalize( newdn );
|
|
|
|
|
1998-09-21 04:22:46 +08:00
|
|
|
/* get entry with writer lock */
|
|
|
|
if ( (dn2id ( be, newdn ) ) != NOID ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
free( newdn );
|
|
|
|
free( pdn );
|
|
|
|
send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, NULL, NULL );
|
1998-09-21 04:22:46 +08:00
|
|
|
goto error_return;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check for abandon */
|
|
|
|
pthread_mutex_lock( &op->o_abandonmutex );
|
|
|
|
if ( op->o_abandon ) {
|
|
|
|
pthread_mutex_unlock( &op->o_abandonmutex );
|
|
|
|
free( newdn );
|
|
|
|
free( pdn );
|
1998-09-21 04:22:46 +08:00
|
|
|
goto error_return;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
pthread_mutex_unlock( &op->o_abandonmutex );
|
|
|
|
|
|
|
|
/* add new one */
|
|
|
|
if ( dn2id_add( be, newdn, e->e_id ) != 0 ) {
|
|
|
|
free( newdn );
|
|
|
|
free( pdn );
|
|
|
|
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
|
1998-09-21 04:22:46 +08:00
|
|
|
goto error_return;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* delete old one */
|
|
|
|
if ( dn2id_delete( be, dn ) != 0 ) {
|
|
|
|
free( newdn );
|
|
|
|
free( pdn );
|
|
|
|
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL, NULL );
|
1998-09-21 04:22:46 +08:00
|
|
|
goto error_return;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
(void) cache_delete_entry( &li->li_cache, e );
|
|
|
|
free( e->e_dn );
|
|
|
|
e->e_dn = newdn;
|
|
|
|
|
|
|
|
/* XXX
|
|
|
|
* At some point here we need to update the attribute values in
|
|
|
|
* the entry itself that were effected by this RDN change
|
|
|
|
* (respecting the value of the deleteoldrdn parameter).
|
|
|
|
*
|
|
|
|
* Since the code to do this has not yet been written, treat this
|
|
|
|
* omission as a (documented) bug.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* id2entry index */
|
|
|
|
if ( id2entry_add( be, e ) != 0 ) {
|
|
|
|
entry_free( e );
|
|
|
|
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
|
1998-09-21 04:22:46 +08:00
|
|
|
goto error_return;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
free( pdn );
|
1998-09-21 04:22:46 +08:00
|
|
|
|
|
|
|
/* free entry and writer lock */
|
|
|
|
cache_return_entry_w( &li->li_cache, e );
|
1998-08-09 08:43:13 +08:00
|
|
|
send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
|
|
|
|
|
|
|
|
return( 0 );
|
1998-09-21 04:22:46 +08:00
|
|
|
|
|
|
|
error_return:
|
|
|
|
/* free entry and writer lock */
|
|
|
|
cache_return_entry_w( &li->li_cache, e );
|
|
|
|
return( -1 );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|