2003-12-08 03:19:18 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2004-01-02 03:15:16 +08:00
|
|
|
* Copyright 1999-2004 The OpenLDAP Foundation.
|
2003-12-08 03:19:18 +08:00
|
|
|
* Portions Copyright 1999 Dmitry Kovalev.
|
|
|
|
* All rights reserved.
|
2000-03-17 03:08:22 +08:00
|
|
|
*
|
2003-12-08 03:19:18 +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>.
|
|
|
|
*/
|
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
* This work was initially developed by Dmitry Kovalev for inclusion
|
|
|
|
* by OpenLDAP Software.
|
2000-03-17 03:08:22 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
2002-11-10 01:03:07 +08:00
|
|
|
#include "ac/string.h"
|
2004-01-20 06:13:15 +08:00
|
|
|
|
2000-03-17 03:08:22 +08:00
|
|
|
#include "slap.h"
|
2004-01-20 06:13:15 +08:00
|
|
|
#include "proto-sql.h"
|
2002-08-17 00:45:24 +08:00
|
|
|
|
|
|
|
int
|
2003-04-03 08:35:16 +08:00
|
|
|
backsql_modify( Operation *op, SlapReply *rs )
|
2002-08-17 00:45:24 +08:00
|
|
|
{
|
2003-04-03 08:35:16 +08:00
|
|
|
backsql_info *bi = (backsql_info*)op->o_bd->be_private;
|
2002-08-17 00:45:24 +08:00
|
|
|
SQLHDBC dbh;
|
|
|
|
backsql_oc_map_rec *oc = NULL;
|
2004-04-10 17:33:55 +08:00
|
|
|
backsql_entryID e_id = BACKSQL_ENTRYID_INIT;
|
2002-08-23 16:54:08 +08:00
|
|
|
Entry e;
|
2002-08-17 00:45:24 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: in case part of the operation cannot be performed
|
|
|
|
* (missing mapping, SQL write fails or so) the entire operation
|
|
|
|
* should be rolled-back
|
|
|
|
*/
|
2004-01-20 06:13:15 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>backsql_modify(): modifying entry \"%s\"\n",
|
2003-04-03 08:35:16 +08:00
|
|
|
op->o_req_ndn.bv_val, 0, 0 );
|
|
|
|
|
|
|
|
rs->sr_err = backsql_get_db_conn( op, &dbh );
|
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
2004-01-20 06:13:15 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modify(): "
|
2002-08-17 00:45:24 +08:00
|
|
|
"could not get connection handle - exiting\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
/*
|
|
|
|
* FIXME: we don't want to send back
|
|
|
|
* excessively detailed messages
|
|
|
|
*/
|
2003-04-03 08:35:16 +08:00
|
|
|
rs->sr_text = ( rs->sr_err == LDAP_OTHER )
|
|
|
|
? "SQL-backend error" : NULL;
|
|
|
|
send_ldap_result( op, rs );
|
2002-08-17 00:45:24 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-10-04 05:08:54 +08:00
|
|
|
/* FIXME: API... */
|
2003-04-03 08:35:16 +08:00
|
|
|
rs->sr_err = backsql_dn2id( bi, &e_id, dbh, &op->o_req_ndn );
|
|
|
|
if ( rs->sr_err != LDAP_SUCCESS ) {
|
2004-01-20 06:13:15 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modify(): "
|
2002-08-17 00:45:24 +08:00
|
|
|
"could not lookup entry id\n", 0, 0, 0 );
|
2003-04-03 08:35:16 +08:00
|
|
|
rs->sr_text = ( rs->sr_err == LDAP_OTHER )
|
|
|
|
? "SQL-backend error" : NULL;
|
|
|
|
send_ldap_result( op, rs );
|
2002-08-17 00:45:24 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-04-08 17:08:28 +08:00
|
|
|
#ifdef BACKSQL_ARBITRARY_KEY
|
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modify(): "
|
|
|
|
"modifying entry \"%s\" (id=%s)\n",
|
|
|
|
e_id.eid_dn.bv_val, e_id.eid_id.bv_val, 0 );
|
|
|
|
#else /* ! BACKSQL_ARBITRARY_KEY */
|
2004-01-20 06:13:15 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modify(): "
|
|
|
|
"modifying entry \"%s\" (id=%ld)\n",
|
2004-04-08 17:08:28 +08:00
|
|
|
e_id.eid_dn.bv_val, e_id.eid_id, 0 );
|
|
|
|
#endif /* ! BACKSQL_ARBITRARY_KEY */
|
2002-08-17 00:45:24 +08:00
|
|
|
|
2004-04-08 17:08:28 +08:00
|
|
|
oc = backsql_id2oc( bi, e_id.eid_oc_id );
|
2002-08-17 00:45:24 +08:00
|
|
|
if ( oc == NULL ) {
|
2004-01-20 06:13:15 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, " backsql_modify(): "
|
2002-08-17 00:45:24 +08:00
|
|
|
"cannot determine objectclass of entry -- aborting\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
/*
|
|
|
|
* FIXME: should never occur, since the entry was built!!!
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: we don't want to send back
|
|
|
|
* excessively detailed messages
|
|
|
|
*/
|
2003-04-03 08:35:16 +08:00
|
|
|
rs->sr_err = LDAP_OTHER;
|
|
|
|
rs->sr_text = "SQL-backend error";
|
|
|
|
send_ldap_result( op, rs );
|
2002-08-17 00:45:24 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
e.e_attrs = NULL;
|
2003-04-03 08:35:16 +08:00
|
|
|
e.e_name = op->o_req_dn;
|
|
|
|
e.e_nname = op->o_req_ndn;
|
|
|
|
if ( !acl_check_modlist( op, &e, op->oq_modify.rs_modlist ) ) {
|
|
|
|
rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
|
2002-08-23 16:54:08 +08:00
|
|
|
|
|
|
|
} else {
|
2003-04-03 08:35:16 +08:00
|
|
|
rs->sr_err = backsql_modify_internal( op, rs, dbh, oc, &e_id,
|
|
|
|
op->oq_modify.rs_modlist );
|
2002-08-23 16:54:08 +08:00
|
|
|
}
|
|
|
|
|
2003-04-03 08:35:16 +08:00
|
|
|
if ( rs->sr_err == LDAP_SUCCESS ) {
|
2002-08-17 00:45:24 +08:00
|
|
|
/*
|
|
|
|
* Commit only if all operations succeed
|
|
|
|
*/
|
2002-08-29 18:55:48 +08:00
|
|
|
SQLTransact( SQL_NULL_HENV, dbh,
|
|
|
|
op->o_noop ? SQL_ROLLBACK : SQL_COMMIT );
|
2002-08-17 00:45:24 +08:00
|
|
|
}
|
2003-04-03 08:35:16 +08:00
|
|
|
send_ldap_result( op, rs );
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==backsql_modify()\n", 0, 0, 0 );
|
|
|
|
|
2002-09-03 03:39:31 +08:00
|
|
|
return op->o_noop;
|
2000-03-17 03:08:22 +08:00
|
|
|
}
|
|
|
|
|