2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2004 The OpenLDAP Foundation.
5 * Portions Copyright 1999 Dmitry Kovalev.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was initially developed by Dmitry Kovalev for inclusion
18 * by OpenLDAP Software.
24 #include <sys/types.h>
25 #include "ac/string.h"
28 #include "proto-sql.h"
31 backsql_modify( Operation *op, SlapReply *rs )
33 backsql_info *bi = (backsql_info*)op->o_bd->be_private;
35 backsql_oc_map_rec *oc = NULL;
36 backsql_entryID e_id = BACKSQL_ENTRYID_INIT;
40 * FIXME: in case part of the operation cannot be performed
41 * (missing mapping, SQL write fails or so) the entire operation
42 * should be rolled-back
44 Debug( LDAP_DEBUG_TRACE, "==>backsql_modify(): modifying entry \"%s\"\n",
45 op->o_req_ndn.bv_val, 0, 0 );
47 rs->sr_err = backsql_get_db_conn( op, &dbh );
48 if ( rs->sr_err != LDAP_SUCCESS ) {
49 Debug( LDAP_DEBUG_TRACE, " backsql_modify(): "
50 "could not get connection handle - exiting\n",
53 * FIXME: we don't want to send back
54 * excessively detailed messages
56 rs->sr_text = ( rs->sr_err == LDAP_OTHER )
57 ? "SQL-backend error" : NULL;
58 send_ldap_result( op, rs );
63 rs->sr_err = backsql_dn2id( bi, &e_id, dbh, &op->o_req_ndn );
64 if ( rs->sr_err != LDAP_SUCCESS ) {
65 Debug( LDAP_DEBUG_TRACE, " backsql_modify(): "
66 "could not lookup entry id\n", 0, 0, 0 );
67 rs->sr_text = ( rs->sr_err == LDAP_OTHER )
68 ? "SQL-backend error" : NULL;
69 send_ldap_result( op, rs );
73 #ifdef BACKSQL_ARBITRARY_KEY
74 Debug( LDAP_DEBUG_TRACE, " backsql_modify(): "
75 "modifying entry \"%s\" (id=%s)\n",
76 e_id.eid_dn.bv_val, e_id.eid_id.bv_val, 0 );
77 #else /* ! BACKSQL_ARBITRARY_KEY */
78 Debug( LDAP_DEBUG_TRACE, " backsql_modify(): "
79 "modifying entry \"%s\" (id=%ld)\n",
80 e_id.eid_dn.bv_val, e_id.eid_id, 0 );
81 #endif /* ! BACKSQL_ARBITRARY_KEY */
83 oc = backsql_id2oc( bi, e_id.eid_oc_id );
85 Debug( LDAP_DEBUG_TRACE, " backsql_modify(): "
86 "cannot determine objectclass of entry -- aborting\n",
89 * FIXME: should never occur, since the entry was built!!!
93 * FIXME: we don't want to send back
94 * excessively detailed messages
96 rs->sr_err = LDAP_OTHER;
97 rs->sr_text = "SQL-backend error";
98 send_ldap_result( op, rs );
103 e.e_name = op->o_req_dn;
104 e.e_nname = op->o_req_ndn;
105 if ( !acl_check_modlist( op, &e, op->oq_modify.rs_modlist ) ) {
106 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
109 rs->sr_err = backsql_modify_internal( op, rs, dbh, oc, &e_id,
110 op->oq_modify.rs_modlist );
113 if ( rs->sr_err == LDAP_SUCCESS ) {
115 * Commit only if all operations succeed
117 SQLTransact( SQL_NULL_HENV, dbh,
118 op->o_noop ? SQL_ROLLBACK : SQL_COMMIT );
120 send_ldap_result( op, rs );
121 Debug( LDAP_DEBUG_TRACE, "<==backsql_modify()\n", 0, 0, 0 );