2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2005 The OpenLDAP Foundation.
5 * Portions Copyright 1999 Dmitry Kovalev.
6 * Portions Copyright 2002 Pierangelo Masarati.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by Dmitry Kovalev for inclusion
19 * by OpenLDAP Software. Additional significant contributors include
20 * Pierangelo Masarati.
26 #include <sys/types.h>
27 #include "ac/string.h"
30 #include "proto-sql.h"
33 backsql_modify( Operation *op, SlapReply *rs )
35 backsql_info *bi = (backsql_info*)op->o_bd->be_private;
36 SQLHDBC dbh = SQL_NULL_HDBC;
37 backsql_oc_map_rec *oc = NULL;
38 backsql_srch_info bsi = { 0 };
42 * FIXME: in case part of the operation cannot be performed
43 * (missing mapping, SQL write fails or so) the entire operation
44 * should be rolled-back
46 Debug( LDAP_DEBUG_TRACE, "==>backsql_modify(): modifying entry \"%s\"\n",
47 op->o_req_ndn.bv_val, 0, 0 );
49 rs->sr_err = backsql_get_db_conn( op, &dbh );
50 if ( rs->sr_err != LDAP_SUCCESS ) {
51 Debug( LDAP_DEBUG_TRACE, " backsql_modify(): "
52 "could not get connection handle - exiting\n",
55 * FIXME: we don't want to send back
56 * excessively detailed messages
58 rs->sr_text = ( rs->sr_err == LDAP_OTHER )
59 ? "SQL-backend error" : NULL;
63 /* FIXME: using all attributes because of access control later ... */
64 rs->sr_err = backsql_init_search( &bsi, &op->o_req_ndn,
66 SLAP_NO_LIMIT, SLAP_NO_LIMIT,
67 (time_t)(-1), NULL, dbh, op, rs,
68 slap_anlist_all_attributes,
70 if ( rs->sr_err != LDAP_SUCCESS ) {
71 Debug( LDAP_DEBUG_TRACE, "backsql_modify(): "
72 "could not retrieve modifyDN ID - no such entry\n",
74 rs->sr_err = LDAP_NO_SUCH_OBJECT;
79 rs->sr_err = backsql_id2entry( &bsi, &bsi.bsi_base_id );
80 if ( rs->sr_err != LDAP_SUCCESS ) {
81 Debug( LDAP_DEBUG_TRACE, "backsql_modify(): "
82 "error %d in backsql_id2entry()\n",
87 #ifdef BACKSQL_ARBITRARY_KEY
88 Debug( LDAP_DEBUG_TRACE, " backsql_modify(): "
89 "modifying entry \"%s\" (id=%s)\n",
90 bsi.bsi_base_id.eid_dn.bv_val,
91 bsi.bsi_base_id.eid_id.bv_val, 0 );
92 #else /* ! BACKSQL_ARBITRARY_KEY */
93 Debug( LDAP_DEBUG_TRACE, " backsql_modify(): "
94 "modifying entry \"%s\" (id=%ld)\n",
95 bsi.bsi_base_id.eid_dn.bv_val, bsi.bsi_base_id.eid_id, 0 );
96 #endif /* ! BACKSQL_ARBITRARY_KEY */
98 oc = backsql_id2oc( bi, bsi.bsi_base_id.eid_oc_id );
100 Debug( LDAP_DEBUG_TRACE, " backsql_modify(): "
101 "cannot determine objectclass of entry -- aborting\n",
104 * FIXME: should never occur, since the entry was built!!!
108 * FIXME: we don't want to send back
109 * excessively detailed messages
111 rs->sr_err = LDAP_OTHER;
112 rs->sr_text = "SQL-backend error";
117 e.e_name = op->o_req_dn;
118 e.e_nname = op->o_req_ndn;
119 if ( !acl_check_modlist( op, &e, op->oq_modify.rs_modlist ) ) {
120 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
123 rs->sr_err = backsql_modify_internal( op, rs, dbh, oc,
125 op->oq_modify.rs_modlist );
128 if ( rs->sr_err == LDAP_SUCCESS ) {
130 * Commit only if all operations succeed
132 SQLTransact( SQL_NULL_HENV, dbh,
133 op->o_noop ? SQL_ROLLBACK : SQL_COMMIT );
137 send_ldap_result( op, rs );
139 if ( !BER_BVISNULL( &bsi.bsi_base_id.eid_ndn ) ) {
140 (void)backsql_free_entryID( &bsi.bsi_base_id, 0 );
143 if ( bsi.bsi_e != NULL ) {
144 entry_clean( bsi.bsi_e );
147 Debug( LDAP_DEBUG_TRACE, "<==backsql_modify()\n", 0, 0, 0 );
149 return rs->sr_err != LDAP_SUCCESS ? rs->sr_err : op->o_noop;