1998-08-09 08:43:13 +08:00
|
|
|
/* modrdn.c - ldbm backend modrdn routine */
|
1999-09-09 03:06:24 +08:00
|
|
|
/* $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 1998-2005 The OpenLDAP Foundation.
|
2003-11-29 05:08:20 +08:00
|
|
|
* All rights reserved.
|
1999-03-05 11:38:12 +08:00
|
|
|
*
|
2003-11-29 05:08:20 +08:00
|
|
|
* 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>.
|
|
|
|
*/
|
|
|
|
/* Portions Copyright 1999, Juan C. Gomez, All rights reserved.
|
1999-03-05 11:38:12 +08:00
|
|
|
* This software is not subject to any license of Silicon Graphics
|
|
|
|
* Inc. or Purdue University.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* without restriction or fee of any kind as long as this notice
|
|
|
|
* is preserved.
|
|
|
|
*/
|
|
|
|
|
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(
|
|
|
|
Operation *op,
|
2003-03-30 17:03:54 +08:00
|
|
|
SlapReply *rs )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
2000-05-28 09:36:03 +08:00
|
|
|
AttributeDescription *children = slap_schema.si_ad_children;
|
2002-10-08 03:19:29 +08:00
|
|
|
AttributeDescription *entry = slap_schema.si_ad_entry;
|
2003-03-30 17:03:54 +08:00
|
|
|
struct ldbminfo *li = (struct ldbminfo *) op->o_bd->be_private;
|
2001-12-27 09:10:52 +08:00
|
|
|
struct berval p_dn, p_ndn;
|
2004-04-07 12:11:43 +08:00
|
|
|
struct berval new_dn = BER_BVNULL, new_ndn = BER_BVNULL;
|
|
|
|
struct berval old_ndn = BER_BVNULL;
|
1999-01-07 10:51:08 +08:00
|
|
|
Entry *e, *p = NULL;
|
1999-09-04 04:25:58 +08:00
|
|
|
Entry *matched;
|
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-11-16 22:04:54 +08:00
|
|
|
int isroot = -1;
|
2001-07-30 22:54:02 +08:00
|
|
|
int rc_id = 0;
|
2001-07-03 19:23:18 +08:00
|
|
|
ID id = NOID;
|
2002-12-28 01:53:53 +08:00
|
|
|
char textbuf[SLAP_TEXT_BUFLEN];
|
|
|
|
size_t textlen = sizeof textbuf;
|
1999-03-25 05:45:15 +08:00
|
|
|
/* Added to support newSuperior */
|
|
|
|
Entry *np = NULL; /* newSuperior Entry */
|
2001-12-27 09:10:52 +08:00
|
|
|
struct berval *np_ndn = NULL; /* newSuperior ndn */
|
|
|
|
struct berval *new_parent_dn = NULL; /* np_dn, p_dn, or NULL */
|
1999-05-20 02:27:25 +08:00
|
|
|
/* Used to interface with ldbm_modify_internal() */
|
2001-07-06 20:24:34 +08:00
|
|
|
Modifications *mod = NULL; /* Used to delete old/add new rdn */
|
1999-07-16 10:45:46 +08:00
|
|
|
int manageDSAit = get_manageDSAit( op );
|
1999-03-25 05:45:15 +08:00
|
|
|
|
2001-12-27 03:50:40 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"==>ldbm_back_modrdn: dn: %s newSuperior=%s\n",
|
2003-03-30 17:03:54 +08:00
|
|
|
op->o_req_dn.bv_len ? op->o_req_dn.bv_val : "NULL",
|
|
|
|
( op->oq_modrdn.rs_newSup && op->oq_modrdn.rs_newSup->bv_len )
|
|
|
|
? op->oq_modrdn.rs_newSup->bv_val : "NULL", 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
|
2002-01-30 01:58:36 +08:00
|
|
|
/* grab giant lock for writing */
|
|
|
|
ldap_pvt_thread_rdwr_wlock(&li->li_giant_rwlock);
|
|
|
|
|
2003-07-15 08:55:58 +08:00
|
|
|
e = dn2entry_w( op->o_bd, &op->o_req_ndn, &matched );
|
|
|
|
|
1998-09-21 04:22:46 +08:00
|
|
|
/* get entry with writer lock */
|
2003-08-28 06:16:04 +08:00
|
|
|
/* FIXME: dn2entry() should return non-glue entry */
|
2003-07-15 08:55:58 +08:00
|
|
|
if (( e == NULL ) || ( !manageDSAit && e && is_entry_glue( e ))) {
|
|
|
|
if ( matched != NULL ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_matched = strdup( matched->e_dn );
|
|
|
|
rs->sr_ref = is_entry_referral( matched )
|
|
|
|
? get_entry_referrals( op, matched )
|
1999-07-16 10:45:46 +08:00
|
|
|
: NULL;
|
|
|
|
cache_return_entry_r( &li->li_cache, matched );
|
|
|
|
} else {
|
2005-01-15 18:39:23 +08:00
|
|
|
rs->sr_ref = referral_rewrite( default_referral, NULL,
|
|
|
|
&op->o_req_dn, LDAP_SCOPE_DEFAULT );
|
1999-07-16 10:45:46 +08:00
|
|
|
}
|
|
|
|
|
2002-01-30 01:58:36 +08:00
|
|
|
ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_REFERRAL;
|
|
|
|
send_ldap_result( op, rs );
|
1999-07-16 10:45:46 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
|
|
|
|
free( (char *)rs->sr_matched );
|
2003-09-27 15:36:20 +08:00
|
|
|
rs->sr_ref = NULL;
|
|
|
|
rs->sr_matched = NULL;
|
2003-07-15 08:55:58 +08:00
|
|
|
return rs->sr_err;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
2002-10-08 03:19:29 +08:00
|
|
|
/* check entry for "entry" acl */
|
2005-04-08 08:18:24 +08:00
|
|
|
if ( ! access_allowed( op, e, entry, NULL, ACL_WRITE, NULL ) )
|
2002-10-08 03:19:29 +08:00
|
|
|
{
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"<=- ldbm_back_modrdn: no write access to entry\n", 0,
|
|
|
|
0, 0 );
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
|
|
|
|
"no write access to entry" );
|
2002-10-08 03:19:29 +08:00
|
|
|
|
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
1999-07-16 10:45:46 +08:00
|
|
|
if (!manageDSAit && is_entry_referral( e ) ) {
|
|
|
|
/* parent is a referral, don't allow add */
|
|
|
|
/* parent is an alias, don't allow add */
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_ref = get_entry_referrals( op, e );
|
1999-07-16 10:45:46 +08:00
|
|
|
|
2001-10-26 10:05:14 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "entry %s is referral\n", e->e_dn,
|
1999-07-16 10:45:46 +08:00
|
|
|
0, 0 );
|
2001-01-18 01:01:19 +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 );
|
1999-07-16 10:45:46 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
|
2003-09-27 15:36:20 +08:00
|
|
|
rs->sr_ref = NULL;
|
|
|
|
rs->sr_matched = NULL;
|
1999-07-16 10:45:46 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( has_children( op->o_bd, e ) ) {
|
2001-10-26 10:05:14 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "entry %s has children\n", e->e_dn,
|
2001-06-07 08:19:23 +08:00
|
|
|
0, 0 );
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_NOT_ALLOWED_ON_NONLEAF,
|
|
|
|
"subtree rename not supported" );
|
2001-06-07 08:19:23 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( be_issuffix( op->o_bd, &e->e_nname ) ) {
|
2002-01-26 14:52:59 +08:00
|
|
|
p_ndn = slap_empty_bv ;
|
|
|
|
} else {
|
|
|
|
dnParent( &e->e_nname, &p_ndn );
|
|
|
|
}
|
2001-12-27 09:10:52 +08:00
|
|
|
|
|
|
|
if ( p_ndn.bv_len != 0 ) {
|
1999-07-16 10:45:46 +08:00
|
|
|
/* Make sure parent entry exist and we can write its
|
1999-03-25 05:45:15 +08:00
|
|
|
* children.
|
|
|
|
*/
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if( (p = dn2entry_w( op->o_bd, &p_ndn, NULL )) == NULL) {
|
1999-01-07 10:51:08 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "parent does not exist\n",
|
|
|
|
0, 0, 0);
|
2001-01-18 01:01:19 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_OTHER,
|
|
|
|
"parent entry does not exist" );
|
2001-05-19 01:10:03 +08:00
|
|
|
|
1999-01-07 10:51:08 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check parent for "children" acl */
|
2005-04-08 08:18:24 +08:00
|
|
|
if ( ! access_allowed( op, p, children, NULL,
|
|
|
|
op->oq_modrdn.rs_newSup != NULL ?
|
|
|
|
ACL_WDEL : ACL_WRITE,
|
|
|
|
NULL ) )
|
1999-01-07 10:51:08 +08:00
|
|
|
{
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
|
|
|
|
0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS,
|
|
|
|
NULL );
|
1999-01-07 10:51:08 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
1999-03-25 05:45:15 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"ldbm_back_modrdn: wr to children of entry %s OK\n",
|
2001-12-27 09:10:52 +08:00
|
|
|
p_ndn.bv_val, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
|
2002-01-26 14:52:59 +08:00
|
|
|
if ( p_ndn.bv_val == slap_empty_bv.bv_val ) {
|
|
|
|
p_dn = slap_empty_bv;
|
|
|
|
} else {
|
|
|
|
dnParent( &e->e_name, &p_dn );
|
|
|
|
}
|
1999-03-25 05:45:15 +08:00
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: parent dn=%s\n",
|
2001-12-27 09:10:52 +08:00
|
|
|
p_dn.bv_val, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
} else {
|
2001-11-16 20:24:22 +08:00
|
|
|
/* no parent, must be root to modify rdn */
|
2004-04-06 09:06:20 +08:00
|
|
|
isroot = be_isroot( op );
|
2001-12-26 03:48:26 +08:00
|
|
|
if ( ! isroot ) {
|
2004-04-08 01:32:37 +08:00
|
|
|
if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv )
|
2004-04-10 18:00:58 +08:00
|
|
|
|| be_shadow_update( op ) ) {
|
2002-12-28 01:53:53 +08:00
|
|
|
int can_access;
|
2001-11-17 01:05:32 +08:00
|
|
|
p = (Entry *)&slap_entry_root;
|
2001-11-16 20:24:22 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
can_access = access_allowed( op, p,
|
2005-04-08 08:18:24 +08:00
|
|
|
children, NULL,
|
|
|
|
op->oq_modrdn.rs_newSup ?
|
|
|
|
ACL_WDEL : ACL_WRITE,
|
|
|
|
NULL );
|
2001-11-16 20:24:22 +08:00
|
|
|
p = NULL;
|
|
|
|
|
|
|
|
/* check parent for "children" acl */
|
2002-12-28 01:53:53 +08:00
|
|
|
if ( ! can_access ) {
|
2001-11-16 20:24:22 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"<=- ldbm_back_modrdn: no "
|
|
|
|
"access to parent\n", 0, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs,
|
2001-11-16 20:24:22 +08:00
|
|
|
LDAP_INSUFFICIENT_ACCESS,
|
2003-03-30 17:03:54 +08:00
|
|
|
NULL );
|
2001-11-16 20:24:22 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"<=- ldbm_back_modrdn: no parent & "
|
|
|
|
"not root\n", 0, 0, 0);
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs,
|
2001-11-16 20:24:22 +08:00
|
|
|
LDAP_INSUFFICIENT_ACCESS,
|
2003-03-30 17:03:54 +08:00
|
|
|
NULL );
|
2001-11-16 20:24:22 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
1999-01-07 10:51:08 +08:00
|
|
|
}
|
|
|
|
|
1999-03-25 05:45:15 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"ldbm_back_modrdn: no parent, locked root\n",
|
|
|
|
0, 0, 0 );
|
1999-07-22 11:42:02 +08:00
|
|
|
}
|
1999-03-25 05:45:15 +08:00
|
|
|
|
2001-12-27 09:10:52 +08:00
|
|
|
new_parent_dn = &p_dn; /* New Parent unless newSuperior given */
|
1999-03-25 05:45:15 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( op->oq_modrdn.rs_newSup != NULL ) {
|
1999-03-25 05:45:15 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2000-05-22 11:46:57 +08:00
|
|
|
"ldbm_back_modrdn: new parent \"%s\" requested...\n",
|
2003-03-30 17:03:54 +08:00
|
|
|
op->oq_modrdn.rs_newSup->bv_val, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
np_ndn = op->oq_modrdn.rs_nnewSup;
|
1999-03-25 05:45:15 +08:00
|
|
|
|
2001-01-09 23:49:44 +08:00
|
|
|
/* newSuperior == oldParent? */
|
2002-01-13 02:17:13 +08:00
|
|
|
if ( dn_match( &p_ndn, np_ndn ) ) {
|
2001-12-27 07:03:36 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: "
|
|
|
|
"new parent\"%s\" seems to be the 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 );
|
2001-01-18 01:01:19 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
op->oq_modrdn.rs_newSup = NULL; /* ignore newSuperior */
|
2001-01-09 23:49:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( op->oq_modrdn.rs_newSup != NULL ) {
|
1999-03-25 05:45:15 +08:00
|
|
|
/* newSuperior == entry being moved?, if so ==> ERROR */
|
|
|
|
/* Get Entry with dn=newSuperior. Does newSuperior exist? */
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( op->oq_modrdn.rs_nnewSup->bv_len ) {
|
|
|
|
if( (np = dn2entry_w( op->o_bd, np_ndn, NULL )) == NULL) {
|
2001-11-16 22:04:54 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2001-12-27 07:03:36 +08:00
|
|
|
"ldbm_back_modrdn: newSup(ndn=%s) not here!\n",
|
2001-12-27 09:10:52 +08:00
|
|
|
np_ndn->bv_val, 0, 0);
|
2001-01-18 01:01:19 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_OTHER,
|
|
|
|
"newSuperior not found" );
|
2001-11-16 22:04:54 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
1999-03-25 05:45:15 +08:00
|
|
|
|
2001-11-16 22:04:54 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2001-12-27 07:03:36 +08:00
|
|
|
"ldbm_back_modrdn: wr to new parent OK np=%p, id=%ld\n",
|
2003-05-02 21:08:47 +08:00
|
|
|
(void *) np, np->e_id, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
|
2001-11-16 22:04:54 +08:00
|
|
|
/* check newSuperior for "children" acl */
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( !access_allowed( op, np, children, NULL,
|
2005-04-08 08:18:24 +08:00
|
|
|
ACL_WADD, NULL ) )
|
2001-11-16 22:04:54 +08:00
|
|
|
{
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"ldbm_back_modrdn: no wr to newSup children\n",
|
|
|
|
0, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
|
2001-11-16 22:04:54 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
1999-07-16 10:45:46 +08:00
|
|
|
|
2001-11-16 22:04:54 +08:00
|
|
|
if ( is_entry_alias( np ) ) {
|
|
|
|
/* parent is an alias, don't allow add */
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "entry is alias\n", 0, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
|
1999-07-16 10:45:46 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_ALIAS_PROBLEM,
|
|
|
|
"newSuperior is an alias" );
|
1999-07-16 10:45:46 +08:00
|
|
|
|
2001-11-16 22:04:54 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
1999-07-16 10:45:46 +08:00
|
|
|
|
2001-11-16 22:04:54 +08:00
|
|
|
if ( is_entry_referral( np ) ) {
|
|
|
|
/* parent is a referral, don't allow add */
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "entry (%s) is referral\n",
|
|
|
|
np->e_dn, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_OTHER,
|
|
|
|
"newSuperior is a referral" );
|
1999-07-16 10:45:46 +08:00
|
|
|
|
2001-11-16 22:04:54 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* no parent, must be root to modify newSuperior */
|
|
|
|
if ( isroot == -1 ) {
|
2004-04-06 09:06:20 +08:00
|
|
|
isroot = be_isroot( op );
|
2001-11-16 22:04:54 +08:00
|
|
|
}
|
|
|
|
|
2001-12-26 03:48:26 +08:00
|
|
|
if ( ! isroot ) {
|
2004-04-08 01:32:37 +08:00
|
|
|
if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv )
|
2004-04-10 18:00:58 +08:00
|
|
|
|| be_shadow_update( op ) ) {
|
2002-12-28 01:53:53 +08:00
|
|
|
int can_access;
|
2001-11-17 01:05:32 +08:00
|
|
|
np = (Entry *)&slap_entry_root;
|
2001-11-16 22:04:54 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
can_access = access_allowed( op, np,
|
2005-04-08 08:18:24 +08:00
|
|
|
children, NULL, ACL_WADD, NULL );
|
2001-11-16 22:04:54 +08:00
|
|
|
np = NULL;
|
|
|
|
|
|
|
|
/* check parent for "children" acl */
|
2002-12-28 01:53:53 +08:00
|
|
|
if ( ! can_access ) {
|
2001-11-16 22:04:54 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"<=- ldbm_back_modrdn: no "
|
|
|
|
"access to new superior\n", 0, 0, 0 );
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs,
|
2001-11-16 22:04:54 +08:00
|
|
|
LDAP_INSUFFICIENT_ACCESS,
|
2003-03-30 17:03:54 +08:00
|
|
|
NULL );
|
2001-11-16 22:04:54 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"<=- ldbm_back_modrdn: \"\" "
|
|
|
|
"not allowed as new superior\n",
|
|
|
|
0, 0, 0);
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs,
|
2001-11-16 22:04:54 +08:00
|
|
|
LDAP_INSUFFICIENT_ACCESS,
|
2003-03-30 17:03:54 +08:00
|
|
|
NULL );
|
2001-11-16 22:04:54 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
}
|
1999-03-25 05:45:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2001-10-26 10:05:14 +08:00
|
|
|
"ldbm_back_modrdn: wr to new parent's children OK\n",
|
|
|
|
0, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
new_parent_dn = op->oq_modrdn.rs_newSup;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1999-03-25 05:45:15 +08:00
|
|
|
|
|
|
|
/* Build target dn and make sure target entry doesn't exist already. */
|
2003-09-24 12:30:41 +08:00
|
|
|
build_new_dn( &new_dn, new_parent_dn, &op->oq_modrdn.rs_newrdn, NULL );
|
2003-04-30 02:28:14 +08:00
|
|
|
dnNormalize( 0, NULL, NULL, &new_dn, &new_ndn, NULL );
|
1999-03-25 05:45:15 +08:00
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: new ndn=%s\n",
|
2001-12-29 12:48:00 +08:00
|
|
|
new_ndn.bv_val, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
|
1999-08-27 05:00:22 +08:00
|
|
|
/* check for abandon */
|
|
|
|
if ( op->o_abandon ) {
|
2005-02-18 08:50:17 +08:00
|
|
|
rs->sr_err = SLAPD_ABANDON;
|
1999-08-27 05:00:22 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( ( rc_id = dn2id ( op->o_bd, &new_ndn, &id ) ) || id != NOID ) {
|
2001-07-03 03:42:27 +08:00
|
|
|
/* if (rc_id) something bad happened to ldbm cache */
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = rc_id ? LDAP_OTHER : LDAP_ALREADY_EXISTS;
|
|
|
|
send_ldap_result( op, rs );
|
1999-01-07 10:51:08 +08:00
|
|
|
goto return_results;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
1999-03-25 05:45:15 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2001-12-27 03:50:40 +08:00
|
|
|
"ldbm_back_modrdn: new ndn=%s does not exist\n",
|
2001-12-29 12:48:00 +08:00
|
|
|
new_ndn.bv_val, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
|
2002-08-17 00:35:16 +08:00
|
|
|
/* Get attribute type and attribute value of our new rdn, we will
|
2001-07-06 20:24:34 +08:00
|
|
|
* need to add that to our new entry
|
|
|
|
*/
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( ldap_bv2rdn( &op->oq_modrdn.rs_newrdn, &new_rdn, (char **)&rs->sr_text,
|
2002-01-09 14:30:23 +08:00
|
|
|
LDAP_DN_FORMAT_LDAP ) )
|
|
|
|
{
|
2001-07-06 20:24:34 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2002-08-17 00:35:16 +08:00
|
|
|
"ldbm_back_modrdn: can't figure out "
|
|
|
|
"type(s)/values(s) of newrdn\n",
|
|
|
|
0, 0, 0 );
|
2003-12-03 19:06:00 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX,
|
|
|
|
"unknown type(s) used in RDN" );
|
2001-07-06 20:24:34 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2002-08-17 00:35:16 +08:00
|
|
|
"ldbm_back_modrdn: new_rdn_type=\"%s\", "
|
|
|
|
"new_rdn_val=\"%s\"\n",
|
2003-04-11 09:29:28 +08:00
|
|
|
new_rdn[ 0 ]->la_attr.bv_val,
|
|
|
|
new_rdn[ 0 ]->la_value.bv_val, 0 );
|
2001-07-06 20:24:34 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( op->oq_modrdn.rs_deleteoldrdn ) {
|
|
|
|
if ( ldap_bv2rdn( &op->o_req_dn, &old_rdn, (char **)&rs->sr_text,
|
2002-08-17 00:35:16 +08:00
|
|
|
LDAP_DN_FORMAT_LDAP ) )
|
|
|
|
{
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"ldbm_back_modrdn: can't figure out "
|
|
|
|
"the old_rdn type(s)/value(s)\n",
|
|
|
|
0, 0, 0 );
|
2003-12-03 19:06:00 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_OTHER,
|
|
|
|
"cannot parse RDN from old DN" );
|
2002-08-17 00:35:16 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
2001-07-06 20:24:34 +08:00
|
|
|
}
|
2002-01-01 17:18:34 +08:00
|
|
|
|
2001-07-06 20:24:34 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldbm_back_modrdn: DN_X500\n",
|
|
|
|
0, 0, 0 );
|
2002-08-17 00:35:16 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( slap_modrdn2mods( op, rs, e, old_rdn, new_rdn, &mod ) != LDAP_SUCCESS ) {
|
2003-12-03 19:06:00 +08:00
|
|
|
send_ldap_result( op, rs );
|
2002-08-17 00:35:16 +08:00
|
|
|
goto return_results;
|
2001-07-06 20:24:34 +08:00
|
|
|
}
|
|
|
|
|
1999-08-27 03:12:15 +08:00
|
|
|
/* check for abandon */
|
|
|
|
if ( op->o_abandon ) {
|
2005-02-18 08:50:17 +08:00
|
|
|
rs->sr_err = SLAPD_ABANDON;
|
1999-08-27 03:12:15 +08:00
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
1999-08-26 09:33:57 +08:00
|
|
|
(void) cache_delete_entry( &li->li_cache, e );
|
1999-08-27 03:12:15 +08:00
|
|
|
|
1999-08-26 09:33:57 +08:00
|
|
|
free( e->e_dn );
|
2003-12-03 19:31:43 +08:00
|
|
|
old_ndn = e->e_nname;
|
2001-12-27 09:10:52 +08:00
|
|
|
e->e_name = new_dn;
|
2001-12-29 12:48:00 +08:00
|
|
|
e->e_nname = new_ndn;
|
2001-12-27 09:10:52 +08:00
|
|
|
new_dn.bv_val = NULL;
|
2001-12-29 12:48:00 +08:00
|
|
|
new_ndn.bv_val = NULL;
|
1999-08-26 09:33:57 +08:00
|
|
|
|
2002-12-28 01:53:53 +08:00
|
|
|
/* NOTE: after this you must not free new_dn or new_ndn!
|
|
|
|
* They are used by cache.
|
|
|
|
*/
|
|
|
|
|
1999-05-20 02:27:25 +08:00
|
|
|
/* modify memory copy of entry */
|
2003-12-03 19:06:00 +08:00
|
|
|
rs->sr_err = ldbm_modify_internal( op, &mod[0], e,
|
2003-03-30 17:03:54 +08:00
|
|
|
&rs->sr_text, textbuf, textlen );
|
2003-12-03 19:06:00 +08:00
|
|
|
switch ( rs->sr_err ) {
|
2002-12-28 01:53:53 +08:00
|
|
|
case LDAP_SUCCESS:
|
|
|
|
break;
|
1999-12-08 12:37:59 +08:00
|
|
|
|
2002-12-28 01:53:53 +08:00
|
|
|
default:
|
2003-12-03 19:06:00 +08:00
|
|
|
send_ldap_result( op, rs );
|
2003-12-03 20:30:28 +08:00
|
|
|
/* FALLTHRU */
|
|
|
|
case SLAPD_ABANDON:
|
2001-07-31 18:54:39 +08:00
|
|
|
goto return_results;
|
1999-05-20 02:27:25 +08:00
|
|
|
}
|
|
|
|
|
2004-04-07 05:06:35 +08:00
|
|
|
/*
|
|
|
|
* NOTE: the backend MUST delete then add the entry,
|
|
|
|
* otherwise indexing may get hosed
|
|
|
|
* FIXME: if a new ID was used, the add could be done first.
|
|
|
|
* that would be safer.
|
|
|
|
*/
|
|
|
|
|
2003-12-03 20:30:28 +08:00
|
|
|
/* delete old one */
|
|
|
|
if ( dn2id_delete( op->o_bd, &old_ndn, e->e_id ) != 0 ) {
|
|
|
|
send_ldap_error( op, rs, LDAP_OTHER,
|
|
|
|
"DN index delete fail" );
|
|
|
|
goto return_results;
|
|
|
|
}
|
1999-03-07 17:31:54 +08:00
|
|
|
|
2004-04-07 05:06:35 +08:00
|
|
|
/* add new one */
|
|
|
|
if ( dn2id_add( op->o_bd, &e->e_nname, e->e_id ) != 0 ) {
|
|
|
|
/* try to repair old entry - probably hopeless */
|
|
|
|
if( dn2id_add( op->o_bd, &old_ndn, e->e_id) != 0 ) {
|
|
|
|
send_ldap_error( op, rs, LDAP_OTHER,
|
|
|
|
"DN index add and repair failed" );
|
|
|
|
} else {
|
|
|
|
send_ldap_error( op, rs, LDAP_OTHER,
|
|
|
|
"DN index add failed" );
|
|
|
|
}
|
|
|
|
goto return_results;
|
|
|
|
}
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
/* id2entry index */
|
2003-03-30 17:03:54 +08:00
|
|
|
if ( id2entry_add( op->o_bd, e ) != 0 ) {
|
2003-12-03 20:30:28 +08:00
|
|
|
/* Try to undo */
|
2004-04-07 05:06:35 +08:00
|
|
|
int rc;
|
|
|
|
rc = dn2id_delete( op->o_bd, &e->e_nname, e->e_id );
|
|
|
|
rc |= dn2id_add( op->o_bd, &old_ndn, e->e_id );
|
|
|
|
if( rc ) {
|
|
|
|
send_ldap_error( op, rs, LDAP_OTHER,
|
|
|
|
"entry update and repair failed" );
|
|
|
|
} else {
|
|
|
|
send_ldap_error( op, rs, LDAP_OTHER,
|
|
|
|
"entry update failed" );
|
|
|
|
}
|
1999-08-27 03:12:15 +08:00
|
|
|
goto return_results;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1998-09-21 04:22:46 +08:00
|
|
|
|
2003-12-03 20:30:28 +08:00
|
|
|
(void) cache_update_entry( &li->li_cache, e );
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_SUCCESS;
|
2003-09-27 15:36:20 +08:00
|
|
|
rs->sr_text = NULL;
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_result( op, rs );
|
2001-07-21 18:53:06 +08:00
|
|
|
cache_entry_commit( e );
|
1999-01-07 10:51:08 +08:00
|
|
|
|
|
|
|
return_results:
|
2001-12-27 09:10:52 +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 );
|
2003-12-03 19:31:43 +08:00
|
|
|
if( old_ndn.bv_val != NULL ) free( old_ndn.bv_val );
|
1999-07-22 11:42:02 +08:00
|
|
|
|
1999-03-07 17:31:54 +08:00
|
|
|
/* LDAP v2 supporting correct attribute handling. */
|
2002-08-17 00:35:16 +08:00
|
|
|
if ( new_rdn != NULL ) {
|
|
|
|
ldap_rdnfree( new_rdn );
|
|
|
|
}
|
|
|
|
if ( old_rdn != NULL ) {
|
|
|
|
ldap_rdnfree( old_rdn );
|
|
|
|
}
|
2001-07-06 20:24:34 +08:00
|
|
|
if ( mod != NULL ) {
|
2002-01-01 17:18:34 +08:00
|
|
|
Modifications *tmp;
|
|
|
|
for (; mod; mod = tmp ) {
|
2003-09-27 15:52:20 +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
|
|
|
tmp = mod->sml_next;
|
|
|
|
free( mod );
|
|
|
|
}
|
2005-08-01 10:16:02 +08:00
|
|
|
slap_mods_free( mod, 1 );
|
2001-07-06 20:24:34 +08:00
|
|
|
}
|
1999-03-07 17:31:54 +08:00
|
|
|
|
1999-03-25 05:45:15 +08:00
|
|
|
/* LDAP v3 Support */
|
1999-07-22 11:42:02 +08:00
|
|
|
if( np != NULL ) {
|
|
|
|
/* free new parent and writer lock */
|
|
|
|
cache_return_entry_w( &li->li_cache, np );
|
|
|
|
}
|
|
|
|
|
1999-01-07 10:51:08 +08:00
|
|
|
if( p != NULL ) {
|
|
|
|
/* free parent and writer lock */
|
|
|
|
cache_return_entry_w( &li->li_cache, p );
|
1999-01-22 06:20:03 +08:00
|
|
|
}
|
1999-01-07 10:51:08 +08:00
|
|
|
|
1998-09-21 04:22:46 +08:00
|
|
|
/* free entry and writer lock */
|
|
|
|
cache_return_entry_w( &li->li_cache, e );
|
2002-01-30 01:58:36 +08:00
|
|
|
ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
|
2003-09-27 15:36:20 +08:00
|
|
|
rs->sr_text = NULL;
|
2003-12-03 19:31:43 +08:00
|
|
|
return( rs->sr_err );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|