2000-09-28 06:28:59 +08:00
|
|
|
/* modrdn.c - bdb backend modrdn routine */
|
|
|
|
/* $OpenLDAP$ */
|
2003-11-29 05:08:20 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2005-01-02 04:49:32 +08:00
|
|
|
* Copyright 2000-2005 The OpenLDAP Foundation.
|
2003-11-29 05:08:20 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
2000-09-28 06:28:59 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
|
|
|
#include "back-bdb.h"
|
|
|
|
|
|
|
|
int
|
2003-03-30 17:03:54 +08:00
|
|
|
bdb_modrdn( Operation *op, SlapReply *rs )
|
2000-09-28 06:28:59 +08:00
|
|
|
{
|
2003-03-30 17:03:54 +08:00
|
|
|
struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
|
2000-09-28 06:28:59 +08:00
|
|
|
AttributeDescription *children = slap_schema.si_ad_children;
|
2002-10-05 07:26:28 +08:00
|
|
|
AttributeDescription *entry = slap_schema.si_ad_entry;
|
2001-12-27 08:58:14 +08:00
|
|
|
struct berval p_dn, p_ndn;
|
2001-12-29 12:48:00 +08:00
|
|
|
struct berval new_dn = {0, NULL}, new_ndn = {0, NULL};
|
2002-04-30 00:42:41 +08:00
|
|
|
Entry *e = NULL;
|
|
|
|
Entry *p = NULL;
|
2003-04-17 00:23:36 +08:00
|
|
|
EntryInfo *ei = NULL, *eip = NULL, *nei = NULL, *neip = NULL;
|
2002-08-17 00:35:16 +08:00
|
|
|
/* LDAP v2 supporting correct attribute handling. */
|
2003-04-11 09:29:28 +08:00
|
|
|
LDAPRDN new_rdn = NULL;
|
|
|
|
LDAPRDN old_rdn = NULL;
|
2001-06-15 15:08:37 +08:00
|
|
|
char textbuf[SLAP_TEXT_BUFLEN];
|
|
|
|
size_t textlen = sizeof textbuf;
|
2003-04-17 00:23:36 +08:00
|
|
|
DB_TXN *ltid = NULL, *lt2;
|
2004-12-05 10:00:19 +08:00
|
|
|
struct bdb_op_info opinfo = {0};
|
2004-07-06 04:08:20 +08:00
|
|
|
Entry dummy = {0};
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2002-01-25 15:19:01 +08:00
|
|
|
Entry *np = NULL; /* newSuperior Entry */
|
2001-12-27 08:58:14 +08:00
|
|
|
struct berval *np_dn = NULL; /* newSuperior dn */
|
|
|
|
struct berval *np_ndn = NULL; /* newSuperior ndn */
|
|
|
|
struct berval *new_parent_dn = NULL; /* np_dn, p_dn, or NULL */
|
2000-09-28 06:28:59 +08:00
|
|
|
|
|
|
|
/* Used to interface with bdb_modify_internal() */
|
2001-10-02 18:39:04 +08:00
|
|
|
Modifications *mod = NULL; /* Used to delete old rdn */
|
2000-09-28 06:28:59 +08:00
|
|
|
|
|
|
|
int manageDSAit = get_manageDSAit( op );
|
|
|
|
|
2003-02-07 23:47:32 +08:00
|
|
|
u_int32_t locker = 0;
|
2003-04-17 00:23:36 +08:00
|
|
|
DB_LOCK lock, plock, nplock;
|
2002-06-01 04:49:19 +08:00
|
|
|
|
2003-07-01 19:55:18 +08:00
|
|
|
int num_retries = 0;
|
|
|
|
|
2004-06-23 14:56:23 +08:00
|
|
|
LDAPControl **preread_ctrl = NULL;
|
|
|
|
LDAPControl **postread_ctrl = NULL;
|
2003-09-17 02:56:04 +08:00
|
|
|
LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
|
|
|
|
int num_ctrls = 0;
|
|
|
|
|
2003-08-26 06:23:49 +08:00
|
|
|
int rc;
|
2002-10-26 01:51:30 +08:00
|
|
|
|
2004-02-24 06:48:46 +08:00
|
|
|
int parent_is_glue = 0;
|
|
|
|
int parent_is_leaf = 0;
|
|
|
|
|
2004-06-23 14:56:23 +08:00
|
|
|
ctrls[num_ctrls] = NULL;
|
|
|
|
|
2004-11-17 22:53:03 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>" LDAP_XSTRING(bdb_modrdn) "(%s,%s,%s)\n",
|
2003-03-30 17:03:54 +08:00
|
|
|
op->o_req_dn.bv_val,op->oq_modrdn.rs_newrdn.bv_val,
|
|
|
|
op->oq_modrdn.rs_newSup ? op->oq_modrdn.rs_newSup->bv_val : "NULL" );
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2001-11-28 05:59:56 +08:00
|
|
|
if( 0 ) {
|
2000-09-29 02:29:50 +08:00
|
|
|
retry: /* transaction retry */
|
2004-07-06 04:08:20 +08:00
|
|
|
if ( dummy.e_attrs ) {
|
|
|
|
attrs_free( dummy.e_attrs );
|
|
|
|
dummy.e_attrs = NULL;
|
|
|
|
}
|
2002-01-25 15:19:01 +08:00
|
|
|
if (e != NULL) {
|
2002-06-06 18:14:14 +08:00
|
|
|
bdb_unlocked_cache_return_entry_w(&bdb->bi_cache, e);
|
2003-03-12 23:20:51 +08:00
|
|
|
e = NULL;
|
2002-01-25 15:19:01 +08:00
|
|
|
}
|
|
|
|
if (p != NULL) {
|
2002-06-06 18:14:14 +08:00
|
|
|
bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, p);
|
2003-03-12 23:20:51 +08:00
|
|
|
p = NULL;
|
2002-01-25 15:19:01 +08:00
|
|
|
}
|
|
|
|
if (np != NULL) {
|
2002-06-06 18:14:14 +08:00
|
|
|
bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, np);
|
2003-03-12 23:20:51 +08:00
|
|
|
np = NULL;
|
2002-01-25 15:19:01 +08:00
|
|
|
}
|
2004-11-17 22:53:03 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>" LDAP_XSTRING(bdb_modrdn)
|
|
|
|
": retrying...\n", 0, 0, 0 );
|
2002-10-26 01:51:30 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = TXN_ABORT( ltid );
|
2000-09-28 06:28:59 +08:00
|
|
|
ltid = NULL;
|
|
|
|
op->o_private = NULL;
|
2003-02-26 20:09:10 +08:00
|
|
|
op->o_do_not_cache = opinfo.boi_acl_cache;
|
2003-03-30 17:03:54 +08:00
|
|
|
if( rs->sr_err != 0 ) {
|
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
rs->sr_text = "internal error";
|
2000-09-28 06:28:59 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
2005-04-29 02:45:31 +08:00
|
|
|
if ( op->o_abandon ) {
|
|
|
|
rs->sr_err = SLAPD_ABANDON;
|
2005-04-29 02:50:24 +08:00
|
|
|
goto return_results;
|
2005-04-29 02:45:31 +08:00
|
|
|
}
|
2004-02-24 06:48:46 +08:00
|
|
|
parent_is_glue = 0;
|
|
|
|
parent_is_leaf = 0;
|
2002-01-18 21:34:50 +08:00
|
|
|
ldap_pvt_thread_yield();
|
2003-09-27 11:16:38 +08:00
|
|
|
bdb_trans_backoff( ++num_retries );
|
2000-09-28 06:28:59 +08:00
|
|
|
}
|
|
|
|
|
2002-01-29 06:57:50 +08:00
|
|
|
/* begin transaction */
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = TXN_BEGIN( bdb->bi_dbenv, NULL, <id,
|
2002-01-29 06:57:50 +08:00
|
|
|
bdb->bi_db_opflags );
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = NULL;
|
|
|
|
if( rs->sr_err != 0 ) {
|
2002-01-29 06:57:50 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2004-11-17 22:53:03 +08:00
|
|
|
LDAP_XSTRING(bdb_modrdn) ": txn_begin failed: "
|
|
|
|
"%s (%d)\n", db_strerror(rs->sr_err), rs->sr_err, 0 );
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
rs->sr_text = "internal error";
|
2002-01-29 06:57:50 +08:00
|
|
|
goto return_results;
|
2000-09-28 06:28:59 +08:00
|
|
|
}
|
|
|
|
|
2002-06-01 04:49:19 +08:00
|
|
|
locker = TXN_ID ( ltid );
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
opinfo.boi_bdb = op->o_bd;
|
2000-09-28 06:28:59 +08:00
|
|
|
opinfo.boi_txn = ltid;
|
2003-02-07 23:47:32 +08:00
|
|
|
opinfo.boi_locker = locker;
|
2000-09-28 06:28:59 +08:00
|
|
|
opinfo.boi_err = 0;
|
2003-02-26 20:09:10 +08:00
|
|
|
opinfo.boi_acl_cache = op->o_do_not_cache;
|
2000-09-28 06:28:59 +08:00
|
|
|
op->o_private = &opinfo;
|
|
|
|
|
|
|
|
/* get entry */
|
2003-05-25 08:53:08 +08:00
|
|
|
rs->sr_err = bdb_dn2entry( op, ltid, &op->o_req_ndn, &ei, 1,
|
|
|
|
locker, &lock );
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
switch( rs->sr_err ) {
|
2000-09-28 06:28:59 +08:00
|
|
|
case 0:
|
|
|
|
case DB_NOTFOUND:
|
|
|
|
break;
|
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
goto retry;
|
2002-04-20 05:41:32 +08:00
|
|
|
case LDAP_BUSY:
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "ldap server busy";
|
2002-04-20 05:41:32 +08:00
|
|
|
goto return_results;
|
2000-09-28 06:28:59 +08:00
|
|
|
default:
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
rs->sr_text = "internal error";
|
2000-09-28 06:28:59 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
2003-04-17 00:23:36 +08:00
|
|
|
e = ei->bei_e;
|
2003-08-28 06:16:04 +08:00
|
|
|
/* FIXME: dn2entry() should return non-glue entry */
|
2004-04-07 03:42:37 +08:00
|
|
|
if (( rs->sr_err == DB_NOTFOUND ) ||
|
|
|
|
( !manageDSAit && e && is_entry_glue( e )))
|
|
|
|
{
|
2003-07-15 08:43:39 +08:00
|
|
|
if( e != NULL ) {
|
2003-04-17 00:23:36 +08:00
|
|
|
rs->sr_matched = ch_strdup( e->e_dn );
|
|
|
|
rs->sr_ref = is_entry_referral( e )
|
|
|
|
? get_entry_referrals( op, e )
|
2000-09-28 06:28:59 +08:00
|
|
|
: NULL;
|
2003-04-17 00:23:36 +08:00
|
|
|
bdb_unlocked_cache_return_entry_r( &bdb->bi_cache, e);
|
|
|
|
e = NULL;
|
2000-09-28 10:27:49 +08:00
|
|
|
|
2000-09-28 06:28:59 +08:00
|
|
|
} else {
|
2005-01-15 18:39:23 +08:00
|
|
|
rs->sr_ref = referral_rewrite( default_referral, NULL,
|
|
|
|
&op->o_req_dn, LDAP_SCOPE_DEFAULT );
|
2000-09-28 06:28:59 +08:00
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_REFERRAL;
|
|
|
|
send_ldap_result( op, rs );
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
ber_bvarray_free( rs->sr_ref );
|
|
|
|
free( (char *)rs->sr_matched );
|
|
|
|
rs->sr_ref = NULL;
|
|
|
|
rs->sr_matched = NULL;
|
2000-09-28 06:28:59 +08:00
|
|
|
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2003-06-10 12:44:41 +08:00
|
|
|
if ( get_assert( op ) &&
|
|
|
|
( test_filter( op, e, get_assertion( op )) != LDAP_COMPARE_TRUE ))
|
|
|
|
{
|
|
|
|
rs->sr_err = LDAP_ASSERTION_FAILED;
|
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
2002-12-30 09:02:31 +08:00
|
|
|
/* check write on old entry */
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = access_allowed( op, e, entry, NULL, ACL_WRITE, NULL );
|
|
|
|
if ( ! rs->sr_err ) {
|
2003-02-26 20:49:21 +08:00
|
|
|
switch( opinfo.boi_err ) {
|
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
2002-10-05 07:42:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "no access to entry\n", 0,
|
|
|
|
0, 0 );
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "no write access to old entry";
|
|
|
|
rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
|
2002-10-05 07:42:27 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
2003-02-28 13:18:29 +08:00
|
|
|
#ifndef BDB_HIER
|
2003-04-22 12:06:09 +08:00
|
|
|
rs->sr_err = bdb_cache_children( op, ltid, e );
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( rs->sr_err != DB_NOTFOUND ) {
|
|
|
|
switch( rs->sr_err ) {
|
2003-02-28 13:18:29 +08:00
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
goto retry;
|
|
|
|
case 0:
|
|
|
|
Debug(LDAP_DEBUG_ARGS,
|
2004-11-17 22:53:03 +08:00
|
|
|
"<=- " LDAP_XSTRING(bdb_modrdn)
|
|
|
|
": non-leaf %s\n",
|
2003-03-30 17:03:54 +08:00
|
|
|
op->o_req_dn.bv_val, 0, 0);
|
|
|
|
rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
|
|
|
|
rs->sr_text = "subtree rename not supported";
|
2003-02-28 13:18:29 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Debug(LDAP_DEBUG_ARGS,
|
2004-11-17 22:53:03 +08:00
|
|
|
"<=- " LDAP_XSTRING(bdb_modrdn)
|
|
|
|
": has_children failed: %s (%d)\n",
|
2003-03-30 17:03:54 +08:00
|
|
|
db_strerror(rs->sr_err), rs->sr_err, 0 );
|
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
rs->sr_text = "internal error";
|
2003-02-28 13:18:29 +08:00
|
|
|
}
|
|
|
|
goto return_results;
|
|
|
|
}
|
2003-04-17 08:52:31 +08:00
|
|
|
ei->bei_state |= CACHE_ENTRY_NO_KIDS;
|
2003-02-28 13:18:29 +08:00
|
|
|
#endif
|
2004-04-07 03:42:37 +08:00
|
|
|
|
2000-09-28 06:28:59 +08:00
|
|
|
if (!manageDSAit && is_entry_referral( e ) ) {
|
|
|
|
/* parent is a referral, don't allow add */
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_ref = get_entry_referrals( op, e );
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2004-11-17 22:53:03 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(bdb_modrdn)
|
|
|
|
": entry %s is referral\n", e->e_dn, 0, 0 );
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_REFERRAL,
|
|
|
|
rs->sr_matched = e->e_name.bv_val;
|
|
|
|
send_ldap_result( op, rs );
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
ber_bvarray_free( rs->sr_ref );
|
|
|
|
rs->sr_ref = NULL;
|
|
|
|
rs->sr_matched = NULL;
|
2000-09-28 06:28:59 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( be_issuffix( op->o_bd, &e->e_nname ) ) {
|
2005-09-10 09:16:55 +08:00
|
|
|
#ifdef BDB_MULTIPLE_SUFFIXES
|
|
|
|
/* Allow renaming one suffix entry to another */
|
2002-01-26 14:40:56 +08:00
|
|
|
p_ndn = slap_empty_bv;
|
2005-09-10 09:16:55 +08:00
|
|
|
#else
|
|
|
|
/* There can only be one suffix entry */
|
|
|
|
rs->sr_err = LDAP_NAMING_VIOLATION;
|
|
|
|
rs->sr_text = "cannot rename suffix entry";
|
|
|
|
goto return_results;
|
|
|
|
#endif
|
2002-01-18 06:47:55 +08:00
|
|
|
} else {
|
2002-01-26 16:44:59 +08:00
|
|
|
dnParent( &e->e_nname, &p_ndn );
|
2002-01-18 06:47:55 +08:00
|
|
|
}
|
2001-12-27 08:58:14 +08:00
|
|
|
np_ndn = &p_ndn;
|
|
|
|
if ( p_ndn.bv_len != 0 ) {
|
2000-09-28 06:28:59 +08:00
|
|
|
/* Make sure parent entry exist and we can write its
|
|
|
|
* children.
|
|
|
|
*/
|
2003-04-17 00:23:36 +08:00
|
|
|
eip = ei->bei_parent;
|
2003-05-25 08:53:08 +08:00
|
|
|
rs->sr_err = bdb_cache_find_id( op, ltid,
|
|
|
|
eip->bei_id, &eip, 0, locker, &plock );
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
switch( rs->sr_err ) {
|
2000-09-28 06:28:59 +08:00
|
|
|
case 0:
|
|
|
|
case DB_NOTFOUND:
|
|
|
|
break;
|
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
goto retry;
|
2002-04-20 05:41:32 +08:00
|
|
|
case LDAP_BUSY:
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "ldap server busy";
|
2002-04-20 05:41:32 +08:00
|
|
|
goto return_results;
|
2000-09-28 06:28:59 +08:00
|
|
|
default:
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
rs->sr_text = "internal error";
|
2000-09-28 06:28:59 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
2003-04-17 00:23:36 +08:00
|
|
|
p = eip->bei_e;
|
2000-09-28 06:28:59 +08:00
|
|
|
if( p == NULL) {
|
2004-11-17 22:53:03 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(bdb_modrdn)
|
|
|
|
": parent does not exist\n", 0, 0, 0);
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
rs->sr_text = "old entry's parent does not exist";
|
2000-09-28 06:28:59 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
2005-09-10 09:16:55 +08:00
|
|
|
} else {
|
|
|
|
p = (Entry *)&slap_entry_root;
|
|
|
|
}
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2005-09-10 09:16:55 +08:00
|
|
|
/* check parent for "children" acl */
|
|
|
|
rs->sr_err = access_allowed( op, p,
|
|
|
|
children, NULL,
|
|
|
|
op->oq_modrdn.rs_newSup == NULL ?
|
|
|
|
ACL_WRITE : ACL_WDEL,
|
|
|
|
NULL );
|
2002-12-30 09:12:10 +08:00
|
|
|
|
2005-09-10 09:16:55 +08:00
|
|
|
if ( !p_ndn.bv_len )
|
|
|
|
p = NULL;
|
2003-02-26 20:49:21 +08:00
|
|
|
|
2005-09-10 09:16:55 +08:00
|
|
|
if ( ! rs->sr_err ) {
|
|
|
|
switch( opinfo.boi_err ) {
|
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
goto retry;
|
2002-01-18 06:47:55 +08:00
|
|
|
}
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2005-09-10 09:16:55 +08:00
|
|
|
rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
|
|
|
|
0, 0 );
|
|
|
|
rs->sr_text = "no write access to old parent's children";
|
|
|
|
goto return_results;
|
|
|
|
}
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2005-09-10 09:16:55 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
LDAP_XSTRING(bdb_modrdn) ": wr to children "
|
|
|
|
"of entry %s OK\n", p_ndn.bv_val, 0, 0 );
|
|
|
|
|
|
|
|
if ( p_ndn.bv_val == slap_empty_bv.bv_val ) {
|
|
|
|
p_dn = slap_empty_bv;
|
2000-09-28 06:28:59 +08:00
|
|
|
} else {
|
2005-09-10 09:16:55 +08:00
|
|
|
dnParent( &e->e_name, &p_dn );
|
2000-09-28 06:28:59 +08:00
|
|
|
}
|
|
|
|
|
2005-09-10 09:16:55 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
LDAP_XSTRING(bdb_modrdn) ": parent dn=%s\n",
|
|
|
|
p_dn.bv_val, 0, 0 );
|
|
|
|
|
2001-12-27 08:58:14 +08:00
|
|
|
new_parent_dn = &p_dn; /* New Parent unless newSuperior given */
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( op->oq_modrdn.rs_newSup != NULL ) {
|
2000-09-28 06:28:59 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2004-11-17 22:53:03 +08:00
|
|
|
LDAP_XSTRING(bdb_modrdn)
|
|
|
|
": new parent \"%s\" requested...\n",
|
2003-03-30 17:03:54 +08:00
|
|
|
op->oq_modrdn.rs_newSup->bv_val, 0, 0 );
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2002-10-25 09:09:50 +08:00
|
|
|
/* newSuperior == oldParent? */
|
2003-03-30 17:03:54 +08:00
|
|
|
if( dn_match( &p_ndn, op->oq_modrdn.rs_nnewSup ) ) {
|
2002-10-25 09:09:50 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "bdb_back_modrdn: "
|
|
|
|
"new parent \"%s\" same as the old parent \"%s\"\n",
|
2003-03-30 17:03:54 +08:00
|
|
|
op->oq_modrdn.rs_newSup->bv_val, p_dn.bv_val, 0 );
|
|
|
|
op->oq_modrdn.rs_newSup = NULL; /* ignore newSuperior */
|
2002-10-25 09:09:50 +08:00
|
|
|
}
|
|
|
|
}
|
2002-12-30 09:12:10 +08:00
|
|
|
|
2005-09-10 09:16:55 +08:00
|
|
|
/* There's a BDB_MULTIPLE_SUFFIXES case here that this code doesn't
|
|
|
|
* support. E.g., two suffixes dc=foo,dc=com and dc=bar,dc=net.
|
|
|
|
* We do not allow modDN
|
|
|
|
* dc=foo,dc=com
|
|
|
|
* newrdn dc=bar
|
|
|
|
* newsup dc=net
|
|
|
|
* and we probably should. But since MULTIPLE_SUFFIXES is deprecated
|
|
|
|
* I'm ignoring this problem for now.
|
|
|
|
*/
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( op->oq_modrdn.rs_newSup != NULL ) {
|
|
|
|
if ( op->oq_modrdn.rs_newSup->bv_len ) {
|
|
|
|
np_dn = op->oq_modrdn.rs_newSup;
|
|
|
|
np_ndn = op->oq_modrdn.rs_nnewSup;
|
2001-11-16 23:00:03 +08:00
|
|
|
|
2005-04-15 11:57:57 +08:00
|
|
|
/* newSuperior == oldParent? - checked above */
|
2001-11-16 23:00:03 +08:00
|
|
|
/* newSuperior == entry being moved?, if so ==> ERROR */
|
2005-04-15 11:57:57 +08:00
|
|
|
if ( dnIsSuffix( np_ndn, &e->e_nname )) {
|
|
|
|
rs->sr_err = LDAP_NAMING_VIOLATION;
|
|
|
|
rs->sr_text = "new superior is invalid";
|
|
|
|
goto return_results;
|
|
|
|
}
|
2001-11-16 23:00:03 +08:00
|
|
|
/* Get Entry with dn=newSuperior. Does newSuperior exist? */
|
|
|
|
|
2003-05-25 08:53:08 +08:00
|
|
|
rs->sr_err = bdb_dn2entry( op, ltid, np_ndn,
|
|
|
|
&neip, 0, locker, &nplock );
|
2001-11-16 23:00:03 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
switch( rs->sr_err ) {
|
2003-04-17 00:23:36 +08:00
|
|
|
case 0: np = neip->bei_e;
|
2001-11-16 23:00:03 +08:00
|
|
|
case DB_NOTFOUND:
|
|
|
|
break;
|
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
goto retry;
|
2002-04-20 05:41:32 +08:00
|
|
|
case LDAP_BUSY:
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "ldap server busy";
|
2002-04-20 05:41:32 +08:00
|
|
|
goto return_results;
|
2001-11-16 23:00:03 +08:00
|
|
|
default:
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
rs->sr_text = "internal error";
|
2001-11-16 23:00:03 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( np == NULL) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2004-11-17 22:53:03 +08:00
|
|
|
LDAP_XSTRING(bdb_modrdn)
|
|
|
|
": newSup(ndn=%s) not here!\n",
|
2001-12-27 08:58:14 +08:00
|
|
|
np_ndn->bv_val, 0, 0);
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "new superior not found";
|
|
|
|
rs->sr_err = LDAP_OTHER;
|
2001-11-16 23:00:03 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
2000-09-28 06:28:59 +08:00
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2004-11-17 22:53:03 +08:00
|
|
|
LDAP_XSTRING(bdb_modrdn)
|
|
|
|
": wr to new parent OK np=%p, id=%ld\n",
|
2003-05-02 21:08:47 +08:00
|
|
|
(void *) np, (long) np->e_id, 0 );
|
2001-11-16 23:00:03 +08:00
|
|
|
|
|
|
|
/* check newSuperior for "children" acl */
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = access_allowed( op, np, children,
|
2005-04-08 08:18:24 +08:00
|
|
|
NULL, ACL_WADD, NULL );
|
2002-12-30 09:12:10 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if( ! rs->sr_err ) {
|
2003-02-26 20:49:21 +08:00
|
|
|
switch( opinfo.boi_err ) {
|
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
2001-11-16 23:00:03 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2004-11-17 22:53:03 +08:00
|
|
|
LDAP_XSTRING(bdb_modrdn)
|
|
|
|
": no wr to newSup children\n",
|
2001-11-16 23:00:03 +08:00
|
|
|
0, 0, 0 );
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "no write access to new superior's children";
|
|
|
|
rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
|
2001-11-16 23:00:03 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( is_entry_alias( np ) ) {
|
|
|
|
/* parent is an alias, don't allow add */
|
2004-11-17 22:53:03 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
LDAP_XSTRING(bdb_modrdn)
|
|
|
|
": entry is alias\n",
|
2001-11-16 23:00:03 +08:00
|
|
|
0, 0, 0 );
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "new superior is an alias";
|
|
|
|
rs->sr_err = LDAP_ALIAS_PROBLEM;
|
2001-11-16 23:00:03 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( is_entry_referral( np ) ) {
|
|
|
|
/* parent is a referral, don't allow add */
|
2004-11-17 22:53:03 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
LDAP_XSTRING(bdb_modrdn)
|
|
|
|
": entry is referral\n",
|
2001-11-16 23:00:03 +08:00
|
|
|
0, 0, 0 );
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text = "new superior is a referral";
|
|
|
|
rs->sr_err = LDAP_OTHER;
|
2001-11-16 23:00:03 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2001-11-16 23:00:03 +08:00
|
|
|
} else {
|
2001-12-27 08:58:14 +08:00
|
|
|
np_dn = NULL;
|
2001-11-16 23:00:03 +08:00
|
|
|
|
|
|
|
/* no parent, modrdn entry directly under root */
|
2005-09-10 09:16:55 +08:00
|
|
|
if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv )
|
|
|
|
|| be_isupdate( op ) ) {
|
|
|
|
np = (Entry *)&slap_entry_root;
|
|
|
|
|
|
|
|
/* check parent for "children" acl */
|
|
|
|
rs->sr_err = access_allowed( op, np,
|
|
|
|
children, NULL, ACL_WADD, NULL );
|
|
|
|
|
|
|
|
np = NULL;
|
|
|
|
|
|
|
|
if ( ! rs->sr_err ) {
|
|
|
|
switch( opinfo.boi_err ) {
|
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
goto retry;
|
2001-11-16 23:00:03 +08:00
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
|
2005-09-10 09:16:55 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"no access to new superior\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
rs->sr_text =
|
|
|
|
"no write access to new superior's children";
|
2001-11-16 23:00:03 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
}
|
2000-09-28 06:28:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2004-11-17 22:53:03 +08:00
|
|
|
LDAP_XSTRING(bdb_modrdn)
|
|
|
|
": wr to new parent's children OK\n",
|
2000-09-28 06:28:59 +08:00
|
|
|
0, 0, 0 );
|
|
|
|
|
|
|
|
new_parent_dn = np_dn;
|
|
|
|
}
|
2002-10-05 07:26:28 +08:00
|
|
|
|
2000-09-28 06:28:59 +08:00
|
|
|
/* Build target dn and make sure target entry doesn't exist already. */
|
2004-04-07 03:42:37 +08:00
|
|
|
if (!new_dn.bv_val) {
|
|
|
|
build_new_dn( &new_dn, new_parent_dn, &op->oq_modrdn.rs_newrdn, NULL );
|
|
|
|
}
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2003-04-12 18:47:11 +08:00
|
|
|
if (!new_ndn.bv_val) {
|
|
|
|
struct berval bv = {0, NULL};
|
2003-04-30 02:28:14 +08:00
|
|
|
dnNormalize( 0, NULL, NULL, &new_dn, &bv, op->o_tmpmemctx );
|
2003-04-12 18:47:11 +08:00
|
|
|
ber_dupbv( &new_ndn, &bv );
|
|
|
|
}
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2004-11-17 22:53:03 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, LDAP_XSTRING(bdb_modrdn) ": new ndn=%s\n",
|
2001-12-29 12:48:00 +08:00
|
|
|
new_ndn.bv_val, 0, 0 );
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2003-04-17 00:23:36 +08:00
|
|
|
/* Shortcut the search */
|
|
|
|
nei = neip ? neip : eip;
|
2003-09-22 16:37:32 +08:00
|
|
|
rs->sr_err = bdb_cache_find_ndn ( op, ltid, &new_ndn, &nei );
|
2003-04-17 00:23:36 +08:00
|
|
|
if ( nei ) bdb_cache_entryinfo_unlock( nei );
|
2003-03-30 17:03:54 +08:00
|
|
|
switch( rs->sr_err ) {
|
2000-09-28 10:42:20 +08:00
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
goto retry;
|
|
|
|
case DB_NOTFOUND:
|
|
|
|
break;
|
|
|
|
case 0:
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_ALREADY_EXISTS;
|
2000-09-28 10:42:20 +08:00
|
|
|
goto return_results;
|
|
|
|
default:
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
rs->sr_text = "internal error";
|
2000-09-28 06:28:59 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get attribute type and attribute value of our new rdn, we will
|
|
|
|
* need to add that to our new entry
|
|
|
|
*/
|
2004-04-07 03:42:37 +08:00
|
|
|
if ( !new_rdn && ldap_bv2rdn_x( &op->oq_modrdn.rs_newrdn, &new_rdn,
|
|
|
|
(char **)&rs->sr_text, LDAP_DN_FORMAT_LDAP, op->o_tmpmemctx ) )
|
2002-01-09 14:30:23 +08:00
|
|
|
{
|
2000-09-28 06:28:59 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2004-11-17 22:53:03 +08:00
|
|
|
LDAP_XSTRING(bdb_modrdn) ": can't figure out "
|
2002-08-17 00:35:16 +08:00
|
|
|
"type(s)/values(s) of newrdn\n",
|
|
|
|
0, 0, 0 );
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_INVALID_DN_SYNTAX;
|
|
|
|
rs->sr_text = "unknown type(s) used in RDN";
|
2002-08-17 00:35:16 +08:00
|
|
|
goto return_results;
|
2000-09-28 06:28:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2004-11-17 22:53:03 +08:00
|
|
|
LDAP_XSTRING(bdb_modrdn)
|
|
|
|
": new_rdn_type=\"%s\", new_rdn_val=\"%s\"\n",
|
|
|
|
new_rdn[ 0 ]->la_attr.bv_val,
|
|
|
|
new_rdn[ 0 ]->la_value.bv_val, 0 );
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( op->oq_modrdn.rs_deleteoldrdn ) {
|
2004-04-07 03:42:37 +08:00
|
|
|
if ( !old_rdn && ldap_bv2rdn_x( &op->o_req_dn, &old_rdn,
|
|
|
|
(char **)&rs->sr_text, LDAP_DN_FORMAT_LDAP, op->o_tmpmemctx ) )
|
2002-08-17 00:35:16 +08:00
|
|
|
{
|
2000-09-28 06:28:59 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2004-11-17 22:53:03 +08:00
|
|
|
LDAP_XSTRING(bdb_modrdn) ": can't figure out "
|
2002-08-17 00:35:16 +08:00
|
|
|
"the old_rdn type(s)/value(s)\n",
|
|
|
|
0, 0, 0 );
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
rs->sr_text = "cannot parse RDN from old DN";
|
2000-09-28 06:28:59 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
2002-08-17 00:35:16 +08:00
|
|
|
}
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2002-08-17 00:35:16 +08:00
|
|
|
/* prepare modlist of modifications from old/new rdn */
|
2003-03-12 21:04:23 +08:00
|
|
|
if (!mod) {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = slap_modrdn2mods( op, rs, e, old_rdn, new_rdn, &mod );
|
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
2003-03-12 21:04:23 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
2000-09-28 06:28:59 +08:00
|
|
|
}
|
2003-04-17 00:23:36 +08:00
|
|
|
|
2003-09-17 02:56:04 +08:00
|
|
|
if( op->o_preread ) {
|
2004-06-23 14:56:23 +08:00
|
|
|
if( preread_ctrl == NULL ) {
|
|
|
|
preread_ctrl = &ctrls[num_ctrls++];
|
|
|
|
ctrls[num_ctrls] = NULL;
|
|
|
|
}
|
2003-09-17 02:56:04 +08:00
|
|
|
if( slap_read_controls( op, rs, e,
|
2004-06-23 14:56:23 +08:00
|
|
|
&slap_pre_read_bv, preread_ctrl ) )
|
2003-09-17 02:56:04 +08:00
|
|
|
{
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2004-11-17 22:53:03 +08:00
|
|
|
"<=- " LDAP_XSTRING(bdb_modrdn)
|
|
|
|
": post-read failed!\n", 0, 0, 0 );
|
2003-09-17 02:56:04 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-17 00:23:36 +08:00
|
|
|
/* nested transaction */
|
2004-04-07 03:42:37 +08:00
|
|
|
rs->sr_err = TXN_BEGIN( bdb->bi_dbenv, ltid, <2, bdb->bi_db_opflags );
|
2003-04-17 00:23:36 +08:00
|
|
|
rs->sr_text = NULL;
|
|
|
|
if( rs->sr_err != 0 ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2004-11-17 22:53:03 +08:00
|
|
|
LDAP_XSTRING(bdb_modrdn)
|
|
|
|
": txn_begin(2) failed: %s (%d)\n",
|
2003-04-17 00:23:36 +08:00
|
|
|
db_strerror(rs->sr_err), rs->sr_err, 0 );
|
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
rs->sr_text = "internal error";
|
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
2004-07-06 04:08:20 +08:00
|
|
|
/* delete old DN */
|
2003-05-25 08:53:08 +08:00
|
|
|
rs->sr_err = bdb_dn2id_delete( op, lt2, eip, e );
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( rs->sr_err != 0 ) {
|
2003-04-30 15:47:24 +08:00
|
|
|
Debug(LDAP_DEBUG_TRACE,
|
2004-11-17 22:53:03 +08:00
|
|
|
"<=- " LDAP_XSTRING(bdb_modrdn)
|
|
|
|
": dn2id del failed: %s (%d)\n",
|
2003-04-30 15:47:24 +08:00
|
|
|
db_strerror(rs->sr_err), rs->sr_err, 0 );
|
2003-03-30 17:03:54 +08:00
|
|
|
switch( rs->sr_err ) {
|
2000-09-28 10:27:49 +08:00
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
goto retry;
|
|
|
|
}
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
rs->sr_text = "DN index delete fail";
|
2000-09-28 06:28:59 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
2004-07-06 04:08:20 +08:00
|
|
|
/* copy the entry, then override some fields */
|
|
|
|
dummy = *e;
|
|
|
|
dummy.e_name = new_dn;
|
|
|
|
dummy.e_nname = new_ndn;
|
|
|
|
dummy.e_attrs = NULL;
|
2003-05-24 09:54:03 +08:00
|
|
|
|
2004-07-06 04:08:20 +08:00
|
|
|
/* add new DN */
|
|
|
|
rs->sr_err = bdb_dn2id_add( op, lt2, neip ? neip : eip, &dummy );
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( rs->sr_err != 0 ) {
|
2003-04-30 15:47:24 +08:00
|
|
|
Debug(LDAP_DEBUG_TRACE,
|
2004-11-17 22:53:03 +08:00
|
|
|
"<=- " LDAP_XSTRING(bdb_modrdn)
|
|
|
|
": dn2id add failed: %s (%d)\n",
|
2003-04-30 15:47:24 +08:00
|
|
|
db_strerror(rs->sr_err), rs->sr_err, 0 );
|
2003-03-30 17:03:54 +08:00
|
|
|
switch( rs->sr_err ) {
|
2000-09-28 10:27:49 +08:00
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
goto retry;
|
|
|
|
}
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
rs->sr_text = "DN index add failed";
|
2000-09-28 06:28:59 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
2004-07-06 04:08:20 +08:00
|
|
|
dummy.e_attrs = e->e_attrs;
|
|
|
|
|
2000-09-28 06:28:59 +08:00
|
|
|
/* modify entry */
|
2004-07-06 04:08:20 +08:00
|
|
|
rs->sr_err = bdb_modify_internal( op, lt2, &mod[0], &dummy,
|
2003-03-30 17:03:54 +08:00
|
|
|
&rs->sr_text, textbuf, textlen );
|
|
|
|
if( rs->sr_err != LDAP_SUCCESS ) {
|
2003-04-30 15:47:24 +08:00
|
|
|
Debug(LDAP_DEBUG_TRACE,
|
2004-11-17 22:53:03 +08:00
|
|
|
"<=- " LDAP_XSTRING(bdb_modrdn)
|
|
|
|
": modify failed: %s (%d)\n",
|
2003-04-30 15:47:24 +08:00
|
|
|
db_strerror(rs->sr_err), rs->sr_err, 0 );
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( ( rs->sr_err == LDAP_INSUFFICIENT_ACCESS ) && opinfo.boi_err ) {
|
|
|
|
rs->sr_err = opinfo.boi_err;
|
2003-02-26 20:49:21 +08:00
|
|
|
}
|
2004-07-06 04:08:20 +08:00
|
|
|
if ( dummy.e_attrs == e->e_attrs ) dummy.e_attrs = NULL;
|
2003-03-30 17:03:54 +08:00
|
|
|
switch( rs->sr_err ) {
|
2000-09-28 10:27:49 +08:00
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
goto retry;
|
|
|
|
}
|
2000-09-28 06:28:59 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
2003-09-17 02:56:04 +08:00
|
|
|
|
2000-09-28 06:28:59 +08:00
|
|
|
/* id2entry index */
|
2004-07-06 04:08:20 +08:00
|
|
|
rs->sr_err = bdb_id2entry_update( op->o_bd, lt2, &dummy );
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( rs->sr_err != 0 ) {
|
2003-04-30 15:47:24 +08:00
|
|
|
Debug(LDAP_DEBUG_TRACE,
|
2004-11-17 22:53:03 +08:00
|
|
|
"<=- " LDAP_XSTRING(bdb_modrdn)
|
|
|
|
": id2entry failed: %s (%d)\n",
|
2003-04-30 15:47:24 +08:00
|
|
|
db_strerror(rs->sr_err), rs->sr_err, 0 );
|
2003-03-30 17:03:54 +08:00
|
|
|
switch( rs->sr_err ) {
|
2000-09-28 10:27:49 +08:00
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
goto retry;
|
|
|
|
}
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
rs->sr_text = "entry update failed";
|
2000-09-28 06:28:59 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
2004-02-24 06:48:46 +08:00
|
|
|
|
2004-06-25 13:29:33 +08:00
|
|
|
if ( p_ndn.bv_len != 0 ) {
|
|
|
|
parent_is_glue = is_entry_glue(p);
|
|
|
|
rs->sr_err = bdb_cache_children( op, lt2, p );
|
|
|
|
if ( rs->sr_err != DB_NOTFOUND ) {
|
|
|
|
switch( rs->sr_err ) {
|
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
goto retry;
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Debug(LDAP_DEBUG_ARGS,
|
2004-11-17 22:53:03 +08:00
|
|
|
"<=- " LDAP_XSTRING(bdb_modrdn)
|
|
|
|
": has_children failed: %s (%d)\n",
|
2004-06-25 13:29:33 +08:00
|
|
|
db_strerror(rs->sr_err), rs->sr_err, 0 );
|
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
rs->sr_text = "internal error";
|
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
parent_is_leaf = 1;
|
|
|
|
}
|
|
|
|
bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, p);
|
|
|
|
p = NULL;
|
|
|
|
}
|
2004-02-24 06:48:46 +08:00
|
|
|
|
2003-04-17 00:23:36 +08:00
|
|
|
if ( TXN_COMMIT( lt2, 0 ) != 0 ) {
|
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
rs->sr_text = "txn_commit(2) failed";
|
|
|
|
goto return_results;
|
|
|
|
}
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2004-06-23 14:02:49 +08:00
|
|
|
if( op->o_postread ) {
|
2004-06-23 14:56:23 +08:00
|
|
|
if( postread_ctrl == NULL ) {
|
|
|
|
postread_ctrl = &ctrls[num_ctrls++];
|
|
|
|
ctrls[num_ctrls] = NULL;
|
|
|
|
}
|
2004-07-06 04:08:20 +08:00
|
|
|
if( slap_read_controls( op, rs, &dummy,
|
2004-06-23 14:56:23 +08:00
|
|
|
&slap_post_read_bv, postread_ctrl ) )
|
2004-06-23 14:02:49 +08:00
|
|
|
{
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2004-11-17 22:53:03 +08:00
|
|
|
"<=- " LDAP_XSTRING(bdb_modrdn)
|
|
|
|
": post-read failed!\n", 0, 0, 0 );
|
2004-06-23 14:02:49 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-29 08:02:27 +08:00
|
|
|
if( op->o_noop ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
if(( rs->sr_err=TXN_ABORT( ltid )) != 0 ) {
|
|
|
|
rs->sr_text = "txn_abort (no-op) failed";
|
2002-02-02 11:28:32 +08:00
|
|
|
} else {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_SUCCESS;
|
2003-12-30 07:31:39 +08:00
|
|
|
goto return_results;
|
2002-02-02 11:28:32 +08:00
|
|
|
}
|
|
|
|
|
2002-01-29 08:02:27 +08:00
|
|
|
} else {
|
2005-07-12 21:17:56 +08:00
|
|
|
rc = bdb_cache_modrdn( bdb, e, &op->orr_nnewrdn, &dummy, neip,
|
|
|
|
locker, &lock );
|
2004-06-16 11:29:02 +08:00
|
|
|
switch( rc ) {
|
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
goto retry;
|
|
|
|
}
|
2004-07-06 04:08:20 +08:00
|
|
|
dummy.e_attrs = NULL;
|
|
|
|
new_dn.bv_val = NULL;
|
|
|
|
new_ndn.bv_val = NULL;
|
2002-02-12 01:45:39 +08:00
|
|
|
|
2003-12-24 21:27:03 +08:00
|
|
|
if(( rs->sr_err=TXN_COMMIT( ltid, 0 )) != 0 ) {
|
|
|
|
rs->sr_text = "txn_commit failed";
|
|
|
|
} else {
|
|
|
|
rs->sr_err = LDAP_SUCCESS;
|
|
|
|
}
|
2002-01-29 08:02:27 +08:00
|
|
|
}
|
2002-02-02 11:28:32 +08:00
|
|
|
|
2000-09-28 06:28:59 +08:00
|
|
|
ltid = NULL;
|
|
|
|
op->o_private = NULL;
|
2002-02-02 11:28:32 +08:00
|
|
|
|
2003-09-17 02:56:04 +08:00
|
|
|
if( rs->sr_err != LDAP_SUCCESS ) {
|
2004-11-17 22:53:03 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
LDAP_XSTRING(bdb_modrdn) ": %s : %s (%d)\n",
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_text, db_strerror(rs->sr_err), rs->sr_err );
|
|
|
|
rs->sr_err = LDAP_OTHER;
|
2003-09-17 02:56:04 +08:00
|
|
|
|
|
|
|
goto return_results;
|
2000-09-28 06:28:59 +08:00
|
|
|
}
|
|
|
|
|
2003-09-17 02:56:04 +08:00
|
|
|
Debug(LDAP_DEBUG_TRACE,
|
2004-11-17 22:53:03 +08:00
|
|
|
LDAP_XSTRING(bdb_modrdn)
|
|
|
|
": rdn modified%s id=%08lx dn=\"%s\"\n",
|
2003-12-30 07:31:39 +08:00
|
|
|
op->o_noop ? " (no-op)" : "",
|
2004-10-31 07:48:26 +08:00
|
|
|
dummy.e_id, op->o_req_dn.bv_val );
|
2003-09-17 02:56:04 +08:00
|
|
|
rs->sr_text = NULL;
|
|
|
|
if( num_ctrls ) rs->sr_ctrls = ctrls;
|
|
|
|
|
2000-09-28 06:28:59 +08:00
|
|
|
return_results:
|
2004-07-06 04:08:20 +08:00
|
|
|
if ( dummy.e_attrs ) {
|
|
|
|
attrs_free( dummy.e_attrs );
|
|
|
|
}
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_result( op, rs );
|
2000-09-28 06:28:59 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if( rs->sr_err == LDAP_SUCCESS && bdb->bi_txn_cp ) {
|
2000-09-28 12:09:13 +08:00
|
|
|
ldap_pvt_thread_yield();
|
2001-12-07 13:05:00 +08:00
|
|
|
TXN_CHECKPOINT( bdb->bi_dbenv,
|
2000-09-28 12:09:13 +08:00
|
|
|
bdb->bi_txn_cp_kbyte, bdb->bi_txn_cp_min, 0 );
|
|
|
|
}
|
2004-02-24 06:48:46 +08:00
|
|
|
|
|
|
|
if ( rs->sr_err == LDAP_SUCCESS && parent_is_glue && parent_is_leaf ) {
|
|
|
|
op->o_delete_glue_parent = 1;
|
|
|
|
}
|
2000-09-28 12:09:13 +08:00
|
|
|
|
2000-09-28 06:28:59 +08:00
|
|
|
done:
|
2001-12-27 08:58:14 +08:00
|
|
|
if( new_dn.bv_val != NULL ) free( new_dn.bv_val );
|
2001-12-29 12:48:00 +08:00
|
|
|
if( new_ndn.bv_val != NULL ) free( new_ndn.bv_val );
|
2000-09-28 06:28:59 +08:00
|
|
|
|
|
|
|
/* LDAP v2 supporting correct attribute handling. */
|
2002-08-17 00:35:16 +08:00
|
|
|
if ( new_rdn != NULL ) {
|
2003-04-12 18:47:11 +08:00
|
|
|
ldap_rdnfree_x( new_rdn, op->o_tmpmemctx );
|
2002-08-17 00:35:16 +08:00
|
|
|
}
|
|
|
|
if ( old_rdn != NULL ) {
|
2003-04-12 18:47:11 +08:00
|
|
|
ldap_rdnfree_x( old_rdn, op->o_tmpmemctx );
|
2002-08-17 00:35:16 +08:00
|
|
|
}
|
2002-01-01 17:18:34 +08:00
|
|
|
if( mod != NULL ) {
|
|
|
|
Modifications *tmp;
|
|
|
|
for (; mod; mod=tmp ) {
|
|
|
|
tmp = mod->sml_next;
|
2003-09-24 01:14:01 +08:00
|
|
|
/* slap_modrdn2mods does things one way,
|
|
|
|
* slap_mods_opattrs does it differently
|
|
|
|
*/
|
|
|
|
if ( mod->sml_op != SLAP_MOD_SOFTADD &&
|
|
|
|
mod->sml_op != LDAP_MOD_DELETE ) break;
|
2003-03-24 09:56:56 +08:00
|
|
|
if ( mod->sml_nvalues ) free( mod->sml_nvalues[0].bv_val );
|
2002-01-01 17:18:34 +08:00
|
|
|
free( mod );
|
|
|
|
}
|
2005-08-01 10:16:02 +08:00
|
|
|
slap_mods_free( mod, 1 );
|
2002-01-01 17:18:34 +08:00
|
|
|
}
|
2000-09-28 06:28:59 +08:00
|
|
|
|
|
|
|
/* LDAP v3 Support */
|
|
|
|
if( np != NULL ) {
|
2002-01-25 15:19:01 +08:00
|
|
|
/* free new parent and reader lock */
|
2002-06-06 18:14:14 +08:00
|
|
|
bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, np);
|
2000-09-28 06:28:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if( p != NULL ) {
|
2002-01-25 15:19:01 +08:00
|
|
|
/* free parent and reader lock */
|
2002-06-06 18:14:14 +08:00
|
|
|
bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, p);
|
2000-09-28 06:28:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* free entry */
|
|
|
|
if( e != NULL ) {
|
2002-06-06 18:14:14 +08:00
|
|
|
bdb_unlocked_cache_return_entry_w( &bdb->bi_cache, e);
|
2000-09-28 06:28:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if( ltid != NULL ) {
|
2002-02-02 11:28:32 +08:00
|
|
|
TXN_ABORT( ltid );
|
2000-09-28 06:28:59 +08:00
|
|
|
op->o_private = NULL;
|
|
|
|
}
|
|
|
|
|
2004-06-23 14:56:23 +08:00
|
|
|
if( preread_ctrl != NULL ) {
|
2004-11-11 05:38:41 +08:00
|
|
|
slap_sl_free( (*preread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
|
|
|
|
slap_sl_free( *preread_ctrl, op->o_tmpmemctx );
|
2004-06-23 14:56:23 +08:00
|
|
|
}
|
|
|
|
if( postread_ctrl != NULL ) {
|
2004-11-11 05:38:41 +08:00
|
|
|
slap_sl_free( (*postread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
|
|
|
|
slap_sl_free( *postread_ctrl, op->o_tmpmemctx );
|
2004-06-23 14:56:23 +08:00
|
|
|
}
|
2003-12-30 07:31:39 +08:00
|
|
|
return rs->sr_err;
|
2000-09-28 06:28:59 +08:00
|
|
|
}
|