1 /* txn.c - LDAP Transactions */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2006 The OpenLDAP Foundation.
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>.
22 #include <ac/socket.h>
23 #include <ac/string.h>
24 #include <ac/unistd.h>
32 const struct berval slap_EXOP_TXN_START = BER_BVC(LDAP_EXOP_X_TXN_START);
33 const struct berval slap_EXOP_TXN_END = BER_BVC(LDAP_EXOP_X_TXN_END);
36 Operation *op, SlapReply *rs )
41 Statslog( LDAP_DEBUG_STATS, "%s TXN START\n",
42 op->o_log_prefix, 0, 0, 0, 0 );
44 if( op->ore_reqdata != NULL ) {
45 rs->sr_text = "no request data expected";
46 return LDAP_PROTOCOL_ERROR;
49 op->o_bd = op->o_conn->c_authz_backend;
50 if( backend_check_restrictions( op, rs,
51 (struct berval *)&slap_EXOP_TXN_START ) != LDAP_SUCCESS )
56 /* acquire connection lock */
57 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
59 if( op->o_conn->c_txn ) {
60 rs->sr_text = "Too many transactions";
67 bv = (struct berval *) ch_malloc( sizeof (struct berval) );
75 /* release connection lock */
76 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
81 Operation *op, SlapReply *rs, LDAPControl *ctrl )
83 if ( !ctrl->ldctl_iscritical ) {
84 rs->sr_text = "txnSpec control must be marked critical";
85 return LDAP_PROTOCOL_ERROR;
88 rs->sr_text = "txnSpec control provided multiple times";
89 return LDAP_PROTOCOL_ERROR;
92 if ( ctrl->ldctl_value.bv_val == NULL ) {
93 rs->sr_text = "no transaction identifier provided";
94 return LDAP_PROTOCOL_ERROR;
96 if ( ctrl->ldctl_value.bv_len != 0 ) {
97 rs->sr_text = "invalid transaction identifier";
98 return LDAP_X_TXN_ID_INVALID;
101 op->o_txnSpec = SLAP_CONTROL_CRITICAL;
106 Operation *op, SlapReply *rs )
109 BerElementBuffer berbuf;
110 BerElement *ber = (BerElement *)&berbuf;
116 Statslog( LDAP_DEBUG_STATS, "%s TXN END\n",
117 op->o_log_prefix, 0, 0, 0, 0 );
119 if( op->ore_reqdata == NULL ) {
120 rs->sr_text = "request data expected";
121 return LDAP_PROTOCOL_ERROR;
123 if( op->ore_reqdata->bv_len == 0 ) {
124 rs->sr_text = "empty request data";
125 return LDAP_PROTOCOL_ERROR;
128 op->o_bd = op->o_conn->c_authz_backend;
129 if( backend_check_restrictions( op, rs,
130 (struct berval *)&slap_EXOP_TXN_END ) != LDAP_SUCCESS )
135 ber_init2( ber, op->ore_reqdata, 0 );
137 tag = ber_scanf( ber, "{" /*}*/ );
138 if( tag == LBER_ERROR ) {
139 rs->sr_text = "request data decoding error";
140 return LDAP_PROTOCOL_ERROR;
143 tag = ber_peek_tag( ber, &len );
144 assert( tag == LBER_BOOLEAN );
145 if( tag == LBER_BOOLEAN ) {
146 tag = ber_scanf( ber, "b", &commit );
147 if( tag == LBER_ERROR ) {
148 rs->sr_text = "request data decoding error";
149 return LDAP_PROTOCOL_ERROR;
153 tag = ber_scanf( ber, /*{*/ "m}", &txnid );
154 if( tag == LBER_ERROR ) {
155 rs->sr_text = "request data decoding error";
156 return LDAP_PROTOCOL_ERROR;
160 rs->sr_text = "invalid transaction identifier";
161 return LDAP_X_TXN_ID_INVALID;
164 /* acquire connection lock */
165 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
167 if( op->o_conn->c_txn == 0 ) {
168 rs->sr_text = "invalid transaction identifier";
169 rc = LDAP_X_TXN_ID_INVALID;
174 rs->sr_text = "not yet implemented";
175 rc = LDAP_UNWILLING_TO_PERFORM;
178 rs->sr_text = "transaction aborted";
182 op->o_conn->c_txn = 0;
185 /* release connection lock */
186 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
191 #endif /* LDAP_X_TXN */