]> git.sur5r.net Git - openldap/blob - servers/slapd/back-sql/modify.c
2e43e13c120cd5ddd5f1ed44d465e8323c45596c
[openldap] / servers / slapd / back-sql / modify.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1999-2004 The OpenLDAP Foundation.
5  * Portions Copyright 1999 Dmitry Kovalev.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
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>.
15  */
16 /* ACKNOWLEDGEMENTS:
17  * This work was initially developed by Dmitry Kovalev for inclusion
18  * by OpenLDAP Software.
19  */
20
21 #include "portable.h"
22
23 #ifdef SLAPD_SQL
24
25 #include <stdio.h>
26 #include <sys/types.h>
27 #include "ac/string.h"
28
29 #include "slap.h"
30 #include "proto-sql.h"
31
32 int
33 backsql_modify( Operation *op, SlapReply *rs )
34 {
35         backsql_info            *bi = (backsql_info*)op->o_bd->be_private;
36         SQLHDBC                 dbh;
37         backsql_oc_map_rec      *oc = NULL;
38         backsql_entryID         e_id = BACKSQL_ENTRYID_INIT;
39         Entry                   e;
40
41         /*
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
45          */
46         Debug( LDAP_DEBUG_TRACE, "==>backsql_modify(): modifying entry \"%s\"\n",
47                 op->o_req_ndn.bv_val, 0, 0 );
48
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", 
53                         0, 0, 0 );
54                 /*
55                  * FIXME: we don't want to send back 
56                  * excessively detailed messages
57                  */
58                 rs->sr_text = ( rs->sr_err == LDAP_OTHER )
59                         ? "SQL-backend error" : NULL;
60                 send_ldap_result( op, rs );
61                 return 1;
62         }
63
64         rs->sr_err = backsql_dn2id( bi, &e_id, dbh, &op->o_req_ndn );
65         if ( rs->sr_err != LDAP_SUCCESS ) {
66                 Debug( LDAP_DEBUG_TRACE, "   backsql_modify(): "
67                         "could not lookup entry id\n", 0, 0, 0 );
68                 rs->sr_text = ( rs->sr_err == LDAP_OTHER )
69                         ? "SQL-backend error" : NULL;
70                 send_ldap_result( op, rs );
71                 return 1;
72         }
73
74 #ifdef BACKSQL_ARBITRARY_KEY
75         Debug( LDAP_DEBUG_TRACE, "   backsql_modify(): "
76                 "modifying entry \"%s\" (id=%s)\n", 
77                 e_id.eid_dn.bv_val, e_id.eid_id.bv_val, 0 );
78 #else /* ! BACKSQL_ARBITRARY_KEY */
79         Debug( LDAP_DEBUG_TRACE, "   backsql_modify(): "
80                 "modifying entry \"%s\" (id=%ld)\n", 
81                 e_id.eid_dn.bv_val, e_id.eid_id, 0 );
82 #endif /* ! BACKSQL_ARBITRARY_KEY */
83
84         oc = backsql_id2oc( bi, e_id.eid_oc_id );
85         if ( oc == NULL ) {
86                 Debug( LDAP_DEBUG_TRACE, "   backsql_modify(): "
87                         "cannot determine objectclass of entry -- aborting\n",
88                         0, 0, 0 );
89                 /*
90                  * FIXME: should never occur, since the entry was built!!!
91                  */
92
93                 /*
94                  * FIXME: we don't want to send back 
95                  * excessively detailed messages
96                  */
97                 rs->sr_err = LDAP_OTHER;
98                 rs->sr_text = "SQL-backend error";
99                 send_ldap_result( op, rs );
100                 return 1;
101         }
102
103         e.e_attrs = NULL;
104         e.e_name = op->o_req_dn;
105         e.e_nname = op->o_req_ndn;
106         if ( !acl_check_modlist( op, &e, op->oq_modify.rs_modlist ) ) {
107                 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
108
109         } else {
110                 rs->sr_err = backsql_modify_internal( op, rs, dbh, oc, &e_id,
111                                 op->oq_modify.rs_modlist );
112         }
113
114         if ( rs->sr_err == LDAP_SUCCESS ) {
115                 /*
116                  * Commit only if all operations succeed
117                  */
118                 SQLTransact( SQL_NULL_HENV, dbh, 
119                                 op->o_noop ? SQL_ROLLBACK : SQL_COMMIT );
120         }
121         send_ldap_result( op, rs );
122         Debug( LDAP_DEBUG_TRACE, "<==backsql_modify()\n", 0, 0, 0 );
123
124         return op->o_noop;
125 }
126
127 #endif /* SLAPD_SQL */
128