]> git.sur5r.net Git - openldap/blob - servers/slapd/txn.c
e0d46670f07de77561870c6a2cdb24e1c7ff1643
[openldap] / servers / slapd / txn.c
1 /* txn.c - LDAP Transactions */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2006 The OpenLDAP Foundation.
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
17 #include "portable.h"
18
19 #include <stdio.h>
20
21 #include <ac/krb.h>
22 #include <ac/socket.h>
23 #include <ac/string.h>
24 #include <ac/unistd.h>
25
26 #include "slap.h"
27
28 #include <lber_pvt.h>
29 #include <lutil.h>
30
31 #ifdef LDAP_X_TXN
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);
34
35 int txn_start_extop(
36         Operation *op, SlapReply *rs )
37 {
38         struct berval *bv;
39
40         if( op->ore_reqdata != NULL ) {
41                 rs->sr_text = "no request data expected";
42                 return LDAP_PROTOCOL_ERROR;
43         }
44
45         Statslog( LDAP_DEBUG_STATS, "%s TXN START\n",
46                 op->o_log_prefix, 0, 0, 0, 0 );
47
48         op->o_bd = op->o_conn->c_authz_backend;
49         if( backend_check_restrictions( op, rs,
50                 (struct berval *)&slap_EXOP_TXN_START ) != LDAP_SUCCESS )
51         {
52                 return rs->sr_err;
53         }
54
55         bv = (struct berval *) ch_malloc( sizeof (struct berval) );
56         bv->bv_len = 0;
57         bv->bv_val = NULL;
58
59         rs->sr_rspdata = bv;
60         return LDAP_SUCCESS;
61 }
62
63 int txn_spec_ctrl(
64         Operation *op, SlapReply *rs, LDAPControl *ctrl )
65 {
66         if ( !ctrl->ldctl_iscritical ) {
67                 rs->sr_text = "txnSpec control must be marked critical";
68                 return LDAP_PROTOCOL_ERROR;
69         }
70         if( op->o_txnSpec ) {
71                 rs->sr_text = "txnSpec control provided multiple times";
72                 return LDAP_PROTOCOL_ERROR;
73         }
74
75         if ( ctrl->ldctl_value.bv_val == NULL ) {
76                 rs->sr_text = "no transaction identifier provided";
77                 return LDAP_PROTOCOL_ERROR;
78         }
79         if ( ctrl->ldctl_value.bv_len != 0 ) {
80                 rs->sr_text = "invalid transaction identifier";
81                 return LDAP_X_TXN_ID_INVALID;
82         }
83
84         op->o_txnSpec = SLAP_CONTROL_CRITICAL;
85         return LDAP_SUCCESS;
86 }
87
88 int txn_end_extop(
89         Operation *op, SlapReply *rs )
90 {
91         if( op->ore_reqdata == NULL ) {
92                 rs->sr_text = "request data expected";
93                 return LDAP_PROTOCOL_ERROR;
94         }
95
96         Statslog( LDAP_DEBUG_STATS, "%s TXN END\n",
97                 op->o_log_prefix, 0, 0, 0, 0 );
98
99         op->o_bd = op->o_conn->c_authz_backend;
100         if( backend_check_restrictions( op, rs,
101                 (struct berval *)&slap_EXOP_TXN_END ) != LDAP_SUCCESS )
102         {
103                 return rs->sr_err;
104         }
105
106         rs->sr_text = "not yet implemented";
107         return LDAP_UNWILLING_TO_PERFORM;
108 }
109
110 #endif /* LDAP_X_TXN */