2004-01-20 06:13:15 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
|
|
|
* Copyright 1999-2004 The OpenLDAP Foundation.
|
|
|
|
* Portions Copyright 1999 Dmitry Kovalev.
|
|
|
|
* 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>.
|
|
|
|
*/
|
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
* This work was initially developed by Dmitry Kovalev for inclusion
|
|
|
|
* by OpenLDAP Software.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#ifdef SLAPD_SQL
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include "ac/string.h"
|
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
#include "ldap_pvt.h"
|
|
|
|
#include "proto-sql.h"
|
|
|
|
|
|
|
|
int
|
|
|
|
backsql_modrdn( Operation *op, SlapReply *rs )
|
|
|
|
{
|
|
|
|
backsql_info *bi = (backsql_info*)op->o_bd->be_private;
|
|
|
|
SQLHDBC dbh;
|
|
|
|
SQLHSTMT sth;
|
|
|
|
RETCODE rc;
|
2004-04-10 17:33:55 +08:00
|
|
|
backsql_entryID e_id = BACKSQL_ENTRYID_INIT,
|
|
|
|
pe_id = BACKSQL_ENTRYID_INIT,
|
2004-08-25 18:41:13 +08:00
|
|
|
new_pe_id = BACKSQL_ENTRYID_INIT;
|
2004-01-20 06:13:15 +08:00
|
|
|
backsql_oc_map_rec *oc = NULL;
|
2004-08-25 18:41:13 +08:00
|
|
|
struct berval p_dn = BER_BVNULL, p_ndn = BER_BVNULL,
|
2004-01-20 06:13:15 +08:00
|
|
|
*new_pdn = NULL, *new_npdn = NULL,
|
2004-08-25 18:41:13 +08:00
|
|
|
new_dn = BER_BVNULL, new_ndn = BER_BVNULL;
|
2004-01-20 06:13:15 +08:00
|
|
|
LDAPRDN new_rdn = NULL;
|
|
|
|
LDAPRDN old_rdn = NULL;
|
|
|
|
Entry e;
|
2004-08-25 18:41:13 +08:00
|
|
|
Modifications *mod = NULL;
|
2004-01-20 06:13:15 +08:00
|
|
|
struct berval *newSuperior = op->oq_modrdn.rs_newSup;
|
2004-08-25 18:41:13 +08:00
|
|
|
char *next;
|
2004-01-20 06:13:15 +08:00
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>backsql_modrdn() renaming entry \"%s\", "
|
|
|
|
"newrdn=\"%s\", newSuperior=\"%s\"\n",
|
|
|
|
op->o_req_dn.bv_val, op->oq_modrdn.rs_newrdn.bv_val,
|
|
|
|
newSuperior ? newSuperior->bv_val : "(NULL)" );
|
|
|
|
rs->sr_err = backsql_get_db_conn( op, &dbh );
|
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
|
|
|
|
"could not get connection handle - exiting\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
rs->sr_text = ( rs->sr_err == LDAP_OTHER )
|
|
|
|
? "SQL-backend error" : NULL;
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rs->sr_err = backsql_dn2id( bi, &e_id, dbh, &op->o_req_ndn );
|
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
|
|
|
|
"could not lookup entry id\n", 0, 0, 0 );
|
|
|
|
rs->sr_text = ( rs->sr_err == LDAP_OTHER )
|
|
|
|
? "SQL-backend error" : NULL;
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-04-08 17:08:28 +08:00
|
|
|
#ifdef BACKSQL_ARBITRARY_KEY
|
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): entry id=%s\n",
|
|
|
|
e_id.eid_id.bv_val, 0, 0 );
|
|
|
|
#else /* ! BACKSQL_ARBITRARY_KEY */
|
2004-01-20 06:13:15 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): entry id=%ld\n",
|
2004-04-08 17:08:28 +08:00
|
|
|
e_id.eid_id, 0, 0 );
|
|
|
|
#endif /* ! BACKSQL_ARBITRARY_KEY */
|
2004-01-20 06:13:15 +08:00
|
|
|
|
|
|
|
if ( backsql_has_children( bi, dbh, &op->o_req_ndn ) == LDAP_COMPARE_TRUE ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
|
|
|
|
"entry \"%s\" has children\n",
|
|
|
|
op->o_req_dn.bv_val, 0, 0 );
|
|
|
|
rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
|
|
|
|
rs->sr_text = "subtree rename not supported";
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
dnParent( &op->o_req_dn, &p_dn );
|
|
|
|
dnParent( &op->o_req_ndn, &p_ndn );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* namingContext "" is not supported
|
|
|
|
*/
|
|
|
|
if ( p_dn.bv_len == 0 ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
|
|
|
|
"parent is \"\" - aborting\n", 0, 0, 0 );
|
|
|
|
rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
rs->sr_text = "not allowed within namingContext";
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
goto modrdn_return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for children access to parent
|
|
|
|
*/
|
|
|
|
e.e_attrs = NULL;
|
|
|
|
e.e_name = p_dn;
|
|
|
|
e.e_nname = p_ndn;
|
|
|
|
if ( !access_allowed( op, &e, slap_schema.si_ad_children,
|
|
|
|
NULL, ACL_WRITE, NULL ) ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, " no access to parent\n", 0, 0, 0 );
|
|
|
|
rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
|
|
|
|
goto modrdn_return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( newSuperior ) {
|
|
|
|
/*
|
|
|
|
* namingContext "" is not supported
|
|
|
|
*/
|
|
|
|
if ( newSuperior->bv_len == 0 ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
|
|
|
|
"newSuperior is \"\" - aborting\n", 0, 0, 0 );
|
|
|
|
rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
rs->sr_text = "not allowed within namingContext";
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
goto modrdn_return;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_pdn = newSuperior;
|
|
|
|
new_npdn = op->oq_modrdn.rs_nnewSup;
|
|
|
|
|
|
|
|
e.e_name = *new_pdn;
|
|
|
|
e.e_nname = *new_npdn;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for children access to new parent
|
|
|
|
*/
|
|
|
|
if ( !access_allowed( op, &e, slap_schema.si_ad_children,
|
|
|
|
NULL, ACL_WRITE, NULL ) ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
|
|
|
|
"no access to new parent \"%s\"\n",
|
|
|
|
new_pdn->bv_val, 0, 0 );
|
|
|
|
rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
|
|
|
|
goto modrdn_return;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
new_pdn = &p_dn;
|
|
|
|
new_npdn = &p_ndn;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( newSuperior && dn_match( &p_ndn, new_npdn ) ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
|
|
|
|
"newSuperior is equal to old parent - ignored\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
newSuperior = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( newSuperior && dn_match( &op->o_req_ndn, new_npdn ) ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
|
|
|
|
"newSuperior is equal to entry being moved "
|
|
|
|
"- aborting\n", 0, 0, 0 );
|
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
rs->sr_text = "newSuperior is equal to old DN";
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
goto modrdn_return;
|
|
|
|
}
|
|
|
|
|
2004-08-25 18:41:13 +08:00
|
|
|
build_new_dn( &new_dn, new_pdn, &op->oq_modrdn.rs_newrdn,
|
|
|
|
op->o_tmpmemctx );
|
2004-01-20 06:13:15 +08:00
|
|
|
rs->sr_err = dnNormalize( 0, NULL, NULL, &new_dn, &new_ndn,
|
2004-08-25 18:41:13 +08:00
|
|
|
op->o_tmpmemctx );
|
2004-01-20 06:13:15 +08:00
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
|
|
|
|
"new dn is invalid (\"%s\") - aborting\n",
|
|
|
|
new_dn.bv_val, 0, 0 );
|
|
|
|
rs->sr_text = "unable to build new DN";
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
goto modrdn_return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): new entry dn is \"%s\"\n",
|
|
|
|
new_dn.bv_val, 0, 0 );
|
|
|
|
|
|
|
|
rs->sr_err = backsql_dn2id( bi, &pe_id, dbh, &p_ndn );
|
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
|
|
|
|
"could not lookup old parent entry id\n", 0, 0, 0 );
|
|
|
|
rs->sr_text = ( rs->sr_err == LDAP_OTHER )
|
|
|
|
? "SQL-backend error" : NULL;
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
goto modrdn_return;
|
|
|
|
}
|
|
|
|
|
2004-04-08 17:08:28 +08:00
|
|
|
#ifdef BACKSQL_ARBITRARY_KEY
|
2004-01-20 06:13:15 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
|
2004-04-08 17:08:28 +08:00
|
|
|
"old parent entry id is %s\n", pe_id.eid_id.bv_val, 0, 0 );
|
|
|
|
#else /* ! BACKSQL_ARBITRARY_KEY */
|
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
|
|
|
|
"old parent entry id is %ld\n", pe_id.eid_id, 0, 0 );
|
|
|
|
#endif /* ! BACKSQL_ARBITRARY_KEY */
|
2004-01-20 06:13:15 +08:00
|
|
|
|
2004-04-10 17:33:55 +08:00
|
|
|
backsql_free_entryID( &pe_id, 0 );
|
|
|
|
|
2004-08-25 18:41:13 +08:00
|
|
|
rs->sr_err = backsql_dn2id( bi, &new_pe_id, dbh, new_npdn );
|
2004-01-20 06:13:15 +08:00
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
|
|
|
|
"could not lookup new parent entry id\n", 0, 0, 0 );
|
|
|
|
rs->sr_text = ( rs->sr_err == LDAP_OTHER )
|
|
|
|
? "SQL-backend error" : NULL;
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
goto modrdn_return;
|
|
|
|
}
|
2004-04-08 17:08:28 +08:00
|
|
|
|
|
|
|
#ifdef BACKSQL_ARBITRARY_KEY
|
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
|
2004-08-25 18:41:13 +08:00
|
|
|
"new parent entry id=%s\n", new_pe_id.eid_id.bv_val, 0, 0 );
|
2004-04-08 17:08:28 +08:00
|
|
|
#else /* ! BACKSQL_ARBITRARY_KEY */
|
2004-01-20 06:13:15 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
|
2004-08-25 18:41:13 +08:00
|
|
|
"new parent entry id=%ld\n", new_pe_id.eid_id, 0, 0 );
|
2004-04-08 17:08:28 +08:00
|
|
|
#endif /* ! BACKSQL_ARBITRARY_KEY */
|
2004-01-20 06:13:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
|
|
|
|
"executing delentry_query\n", 0, 0, 0 );
|
2004-08-25 18:41:13 +08:00
|
|
|
|
|
|
|
rc = backsql_Prepare( dbh, &sth, bi->delentry_query, 0 );
|
|
|
|
if ( rc != SQL_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
" backsql_modrdn(): "
|
|
|
|
"error preparing delentry_query\n", 0, 0, 0 );
|
|
|
|
backsql_PrintErrors( bi->db_env, dbh,
|
|
|
|
sth, rc );
|
|
|
|
|
|
|
|
rs->sr_text = "SQL-backend error";
|
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2004-04-08 17:08:28 +08:00
|
|
|
#ifdef BACKSQL_ARBITRARY_KEY
|
|
|
|
SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
|
|
|
|
0, 0, e_id.eid_id.bv_val, 0, 0 );
|
|
|
|
#else /* ! BACKSQL_ARBITRARY_KEY */
|
2004-01-20 06:13:15 +08:00
|
|
|
SQLBindParameter( sth, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER,
|
2004-04-08 17:08:28 +08:00
|
|
|
0, 0, &e_id.eid_id, 0, 0 );
|
|
|
|
#endif /* ! BACKSQL_ARBITRARY_KEY */
|
2004-08-25 18:41:13 +08:00
|
|
|
rc = SQLExecute( sth );
|
2004-01-20 06:13:15 +08:00
|
|
|
if ( rc != SQL_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
|
|
|
|
"failed to delete record from ldap_entries\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
backsql_PrintErrors( bi->db_env, dbh, sth, rc );
|
2004-08-25 18:41:13 +08:00
|
|
|
SQLFreeStmt( sth, SQL_DROP );
|
2004-01-20 06:13:15 +08:00
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
rs->sr_text = "SQL-backend error";
|
|
|
|
send_ldap_result( op, rs );
|
2004-08-25 18:41:13 +08:00
|
|
|
goto done;
|
2004-01-20 06:13:15 +08:00
|
|
|
}
|
|
|
|
|
2004-08-25 18:41:13 +08:00
|
|
|
SQLFreeStmt( sth, SQL_DROP );
|
2004-01-20 06:13:15 +08:00
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
|
|
|
|
"executing insentry_query\n", 0, 0, 0 );
|
2004-08-25 18:41:13 +08:00
|
|
|
|
|
|
|
rc = backsql_Prepare( dbh, &sth, bi->insentry_query, 0 );
|
|
|
|
if ( rc != SQL_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
" backsql_modrdn(): "
|
|
|
|
"error preparing insentry_query\n", 0, 0, 0 );
|
|
|
|
backsql_PrintErrors( bi->db_env, dbh,
|
|
|
|
sth, rc );
|
|
|
|
|
|
|
|
rs->sr_text = "SQL-backend error";
|
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2004-01-20 06:13:15 +08:00
|
|
|
backsql_BindParamStr( sth, 1, new_dn.bv_val, BACKSQL_MAX_DN_LEN );
|
|
|
|
SQLBindParameter( sth, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
|
2004-04-08 17:08:28 +08:00
|
|
|
0, 0, &e_id.eid_oc_id, 0, 0 );
|
|
|
|
#ifdef BACKSQL_ARBITRARY_KEY
|
|
|
|
SQLBindParameter( sth, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
|
2004-08-25 18:41:13 +08:00
|
|
|
0, 0, new_pe_id.eid_id.bv_val, 0, 0 );
|
2004-04-08 17:08:28 +08:00
|
|
|
SQLBindParameter( sth, 4, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR,
|
|
|
|
0, 0, e_id.eid_keyval.bv_val, 0, 0 );
|
|
|
|
#else /* ! BACKSQL_ARBITRARY_KEY */
|
2004-01-20 06:13:15 +08:00
|
|
|
SQLBindParameter( sth, 3, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
|
2004-08-25 18:41:13 +08:00
|
|
|
0, 0, &new_pe_id.eid_id, 0, 0 );
|
2004-01-20 06:13:15 +08:00
|
|
|
SQLBindParameter( sth, 4, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
|
2004-04-08 17:08:28 +08:00
|
|
|
0, 0, &e_id.eid_keyval, 0, 0 );
|
|
|
|
#endif /* ! BACKSQL_ARBITRARY_KEY */
|
2004-08-25 18:41:13 +08:00
|
|
|
rc = SQLExecute( sth );
|
2004-01-20 06:13:15 +08:00
|
|
|
if ( rc != SQL_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
|
|
|
|
"could not insert ldap_entries record\n", 0, 0, 0 );
|
|
|
|
backsql_PrintErrors( bi->db_env, dbh, sth, rc );
|
2004-08-25 18:41:13 +08:00
|
|
|
SQLFreeStmt( sth, SQL_DROP );
|
2004-01-20 06:13:15 +08:00
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
rs->sr_text = "SQL-backend error";
|
|
|
|
send_ldap_result( op, rs );
|
2004-08-25 18:41:13 +08:00
|
|
|
goto done;
|
2004-01-20 06:13:15 +08:00
|
|
|
}
|
2004-08-25 18:41:13 +08:00
|
|
|
SQLFreeStmt( sth, SQL_DROP );
|
2004-01-20 06:13:15 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get attribute type and attribute value of our new rdn,
|
|
|
|
* we will need to add that to our new entry
|
|
|
|
*/
|
2004-08-25 18:41:13 +08:00
|
|
|
if ( ldap_bv2rdn( &op->oq_modrdn.rs_newrdn, &new_rdn, &next,
|
|
|
|
LDAP_DN_FORMAT_LDAP ) )
|
|
|
|
{
|
2004-01-20 06:13:15 +08:00
|
|
|
#ifdef NEW_LOGGING
|
|
|
|
LDAP_LOG ( OPERATION, ERR,
|
|
|
|
" backsql_modrdn: can't figure out "
|
|
|
|
"type(s)/values(s) of newrdn\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
#else
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
" backsql_modrdn: can't figure out "
|
|
|
|
"type(s)/values(s) of newrdn\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
#endif
|
|
|
|
rs->sr_err = LDAP_INVALID_DN_SYNTAX;
|
2004-08-25 18:41:13 +08:00
|
|
|
goto done;
|
2004-01-20 06:13:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NEW_LOGGING
|
|
|
|
LDAP_LOG ( OPERATION, RESULTS,
|
|
|
|
" backsql_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 );
|
|
|
|
#else
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
" backsql_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 );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ( op->oq_modrdn.rs_deleteoldrdn ) {
|
2004-08-25 18:41:13 +08:00
|
|
|
if ( ldap_bv2rdn( &op->o_req_dn, &old_rdn, &next,
|
|
|
|
LDAP_DN_FORMAT_LDAP ) )
|
|
|
|
{
|
2004-01-20 06:13:15 +08:00
|
|
|
#ifdef NEW_LOGGING
|
|
|
|
LDAP_LOG ( OPERATION, ERR,
|
|
|
|
" backsql_modrdn: can't figure out "
|
|
|
|
"type(s)/values(s) of old_rdn\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
#else
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
" backsql_modrdn: can't figure out "
|
|
|
|
"the old_rdn type(s)/value(s)\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
#endif
|
|
|
|
rs->sr_err = LDAP_OTHER;
|
2004-08-25 18:41:13 +08:00
|
|
|
goto done;
|
2004-01-20 06:13:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
e.e_name = new_dn;
|
|
|
|
e.e_nname = new_ndn;
|
|
|
|
rs->sr_err = slap_modrdn2mods( op, rs, &e, old_rdn, new_rdn, &mod );
|
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
|
|
|
goto modrdn_return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !acl_check_modlist( op, &e, mod )) {
|
|
|
|
rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
|
|
|
|
goto modrdn_return;
|
|
|
|
}
|
|
|
|
|
2004-04-08 17:08:28 +08:00
|
|
|
oc = backsql_id2oc( bi, e_id.eid_oc_id );
|
2004-01-20 06:13:15 +08:00
|
|
|
rs->sr_err = backsql_modify_internal( op, rs, dbh, oc, &e_id, mod );
|
|
|
|
|
2004-08-25 18:41:13 +08:00
|
|
|
done:;
|
|
|
|
/*
|
|
|
|
* Commit only if all operations succeed
|
|
|
|
*/
|
|
|
|
if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop ) {
|
|
|
|
SQLTransact( SQL_NULL_HENV, dbh, SQL_COMMIT );
|
2004-01-20 06:13:15 +08:00
|
|
|
|
2004-08-25 18:41:13 +08:00
|
|
|
} else {
|
|
|
|
SQLTransact( SQL_NULL_HENV, dbh, SQL_ROLLBACK );
|
2004-01-20 06:13:15 +08:00
|
|
|
}
|
|
|
|
|
2004-08-25 18:41:13 +08:00
|
|
|
modrdn_return:;
|
|
|
|
if ( !BER_BVISNULL( &new_dn ) ) {
|
|
|
|
slap_sl_free( new_dn.bv_val, op->o_tmpmemctx );
|
2004-01-20 06:13:15 +08:00
|
|
|
}
|
|
|
|
|
2004-08-25 18:41:13 +08:00
|
|
|
if ( !BER_BVISNULL( &new_ndn ) ) {
|
|
|
|
slap_sl_free( new_ndn.bv_val, op->o_tmpmemctx );
|
2004-01-20 06:13:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* LDAP v2 supporting correct attribute handling. */
|
|
|
|
if ( new_rdn != NULL ) {
|
|
|
|
ldap_rdnfree( new_rdn );
|
|
|
|
}
|
|
|
|
if ( old_rdn != NULL ) {
|
|
|
|
ldap_rdnfree( old_rdn );
|
|
|
|
}
|
2004-04-10 17:33:55 +08:00
|
|
|
if ( mod != NULL ) {
|
2004-01-20 06:13:15 +08:00
|
|
|
Modifications *tmp;
|
2004-08-25 18:41:13 +08:00
|
|
|
for (; mod; mod = tmp ) {
|
2004-01-20 06:13:15 +08:00
|
|
|
tmp = mod->sml_next;
|
|
|
|
free( mod );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-25 18:41:13 +08:00
|
|
|
if ( new_pe_id.eid_dn.bv_val ) {
|
|
|
|
backsql_free_entryID( &new_pe_id, 0 );
|
2004-04-10 17:33:55 +08:00
|
|
|
}
|
|
|
|
|
2004-01-20 06:13:15 +08:00
|
|
|
send_ldap_result( op, rs );
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==backsql_modrdn()\n", 0, 0, 0 );
|
|
|
|
return op->o_noop;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* SLAPD_SQL */
|
|
|
|
|