]> git.sur5r.net Git - openldap/blob - servers/slapd/back-sql/modify.c
minor naming cleanup; improvements to DN mapping layer; major docs update
[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-2005 The OpenLDAP Foundation.
5  * Portions Copyright 1999 Dmitry Kovalev.
6  * Portions Copyright 2002 Pierangelo Masarati.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
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>.
16  */
17 /* ACKNOWLEDGEMENTS:
18  * This work was initially developed by Dmitry Kovalev for inclusion
19  * by OpenLDAP Software.  Additional significant contributors include
20  * Pierangelo Masarati.
21  */
22
23 #include "portable.h"
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 = SQL_NULL_HDBC;
37         backsql_oc_map_rec      *oc = NULL;
38         backsql_srch_info       bsi = { 0 };
39         Entry                   e = { 0 };
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                 goto done;
61         }
62
63         /* FIXME: using all attributes because of access control later ... */
64         rs->sr_err = backsql_init_search( &bsi, &op->o_req_ndn,
65                         LDAP_SCOPE_BASE, 
66                         SLAP_NO_LIMIT, SLAP_NO_LIMIT,
67                         (time_t)(-1), NULL, dbh, op, rs,
68                         slap_anlist_all_attributes,
69                         BACKSQL_ISF_GET_ID );
70         if ( rs->sr_err != LDAP_SUCCESS ) {
71                 Debug( LDAP_DEBUG_TRACE, "backsql_modify(): "
72                         "could not retrieve modifyDN ID - no such entry\n", 
73                         0, 0, 0 );
74                 rs->sr_err = LDAP_NO_SUCH_OBJECT;
75                 goto done;
76         }
77
78         bsi.bsi_e = &e;
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",
83                         rs->sr_err, 0, 0 );
84                 goto done;
85         }
86
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 */
97
98         oc = backsql_id2oc( bi, bsi.bsi_base_id.eid_oc_id );
99         if ( oc == NULL ) {
100                 Debug( LDAP_DEBUG_TRACE, "   backsql_modify(): "
101                         "cannot determine objectclass of entry -- aborting\n",
102                         0, 0, 0 );
103                 /*
104                  * FIXME: should never occur, since the entry was built!!!
105                  */
106
107                 /*
108                  * FIXME: we don't want to send back 
109                  * excessively detailed messages
110                  */
111                 rs->sr_err = LDAP_OTHER;
112                 rs->sr_text = "SQL-backend error";
113                 goto done;
114         }
115
116         e.e_attrs = NULL;
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;
121
122         } else {
123                 rs->sr_err = backsql_modify_internal( op, rs, dbh, oc,
124                                 &bsi.bsi_base_id,
125                                 op->oq_modify.rs_modlist );
126         }
127
128         if ( rs->sr_err == LDAP_SUCCESS ) {
129                 /*
130                  * Commit only if all operations succeed
131                  */
132                 SQLTransact( SQL_NULL_HENV, dbh, 
133                                 op->o_noop ? SQL_ROLLBACK : SQL_COMMIT );
134         }
135
136 done:;
137         send_ldap_result( op, rs );
138
139         if ( !BER_BVISNULL( &bsi.bsi_base_id.eid_ndn ) ) {
140                 (void)backsql_free_entryID( &bsi.bsi_base_id, 0 );
141         }
142
143         if ( bsi.bsi_e != NULL ) {
144                 entry_clean( bsi.bsi_e );
145         }
146
147         Debug( LDAP_DEBUG_TRACE, "<==backsql_modify()\n", 0, 0, 0 );
148
149         return rs->sr_err != LDAP_SUCCESS ? rs->sr_err : op->o_noop;
150 }
151