~ubuntu-branches/ubuntu/maverick/openldap/maverick-proposed

« back to all changes in this revision

Viewing changes to servers/slapd/back-relay/op.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug
  • Date: 2009-09-07 13:41:10 UTC
  • mto: This revision was merged to the branch mainline in revision 19.
  • Revision ID: james.westby@ubuntu.com-20090907134110-jsdrvn0atu1fex4m
Tags: upstream-2.4.18
ImportĀ upstreamĀ versionĀ 2.4.18

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* op.c - relay backend operations */
2
 
/* $OpenLDAP: pkg/ldap/servers/slapd/back-relay/op.c,v 1.15.2.9 2009/06/02 23:08:35 quanah Exp $ */
 
2
/* $OpenLDAP: pkg/ldap/servers/slapd/back-relay/op.c,v 1.15.2.11 2009/08/12 23:58:52 quanah Exp $ */
3
3
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4
4
 *
5
5
 * Copyright 2004-2009 The OpenLDAP Foundation.
26
26
#include "slap.h"
27
27
#include "back-relay.h"
28
28
 
29
 
#define RB_ERR_MASK             (0x0000FFFFU)
30
 
#define RB_ERR                  (0x10000000U)
31
 
#define RB_UNSUPPORTED_FLAG     (0x20000000U)
32
 
#define RB_REFERRAL             (0x40000000U)
33
 
#define RB_SEND                 (0x80000000U)
34
 
#define RB_UNSUPPORTED          (LDAP_UNWILLING_TO_PERFORM|RB_ERR|RB_UNSUPPORTED_FLAG)
35
 
#define RB_UNSUPPORTED_SEND     (RB_UNSUPPORTED|RB_SEND)
36
 
#define RB_REFERRAL_SEND        (RB_REFERRAL|RB_SEND)
37
 
#define RB_ERR_SEND             (RB_ERR|RB_SEND)
38
 
#define RB_ERR_REFERRAL_SEND    (RB_ERR|RB_REFERRAL|RB_SEND)
39
 
 
40
 
static int
41
 
relay_back_swap_bd( Operation *op, SlapReply *rs )
42
 
{
43
 
        slap_callback   *cb = op->o_callback;
44
 
        BackendDB       *be = op->o_bd;
45
 
 
46
 
        op->o_bd = cb->sc_private;
47
 
        cb->sc_private = be;
48
 
 
49
 
        return SLAP_CB_CONTINUE;
50
 
}
51
 
 
52
 
#define relay_back_add_cb( cb, op ) \
53
 
        {                                               \
54
 
                (cb)->sc_next = (op)->o_callback;       \
55
 
                (cb)->sc_response = relay_back_swap_bd; \
56
 
                (cb)->sc_cleanup = relay_back_swap_bd;  \
57
 
                (cb)->sc_private = (op)->o_bd;          \
58
 
                (op)->o_callback = (cb);                \
 
29
/* Results when no real database (.rf_bd) or operation handler (.rf_op) */
 
30
static const struct relay_fail_modes_s {
 
31
        slap_mask_t     rf_bd, rf_op;
 
32
#define RB_ERR_MASK     0x0000FFFFU /* bitmask for default return value */
 
33
#define RB_BDERR        0x80000000U /* use .rf_bd's default return value */
 
34
#define RB_OPERR        0x40000000U /* set rs->sr_err = .rf_op return value */
 
35
#define RB_REF          0x20000000U /* use default_referral if available */
 
36
#define RB_SEND         0x10000000U /* send result; RB_??ERR is also set */
 
37
#define RB_SENDREF      0/*unused*/ /* like RB_SEND when referral found */
 
38
#define RB_NO_BIND      (RB_OPERR | LDAP_INVALID_CREDENTIALS)
 
39
#define RB_NOT_SUPP     (RB_OPERR | LDAP_UNWILLING_TO_PERFORM)
 
40
#define RB_NO_OBJ       (RB_REF | LDAP_NO_SUCH_OBJECT)
 
41
#define RB_CHK_REF      (RB_REF | RB_SENDREF | LDAP_SUCCESS)
 
42
} relay_fail_modes[relay_op_last] = {
 
43
        /* .rf_bd is unused when zero, otherwise both fields have RB_BDERR */
 
44
#       define RB_OP(b, o)      { (b) | RB_BD2ERR(b), (o) | RB_BD2ERR(b) }
 
45
#       define RB_BD2ERR(b)     ((b) ? RB_BDERR : 0)
 
46
        /* indexed by slap_operation_t: */
 
47
        RB_OP(RB_NO_BIND|RB_SEND, RB_NO_BIND  |RB_SEND), /* Bind           */
 
48
        RB_OP(0,                  LDAP_SUCCESS),         /* Unbind: unused */
 
49
        RB_OP(RB_NO_OBJ |RB_SEND, RB_NOT_SUPP |RB_SEND), /* Search         */
 
50
        RB_OP(RB_NO_OBJ |RB_SEND, SLAP_CB_CONTINUE),     /* Compare        */
 
51
        RB_OP(RB_NO_OBJ |RB_SEND, RB_NOT_SUPP |RB_SEND), /* Modify         */
 
52
        RB_OP(RB_NO_OBJ |RB_SEND, RB_NOT_SUPP |RB_SEND), /* Modrdn         */
 
53
        RB_OP(RB_NO_OBJ |RB_SEND, RB_NOT_SUPP |RB_SEND), /* Add            */
 
54
        RB_OP(RB_NO_OBJ |RB_SEND, RB_NOT_SUPP |RB_SEND), /* Delete         */
 
55
        RB_OP(0,                  LDAP_SUCCESS),         /* Abandon:unused */
 
56
        RB_OP(RB_NO_OBJ,          RB_NOT_SUPP),          /* Extended       */
 
57
        RB_OP(0,                  SLAP_CB_CONTINUE),     /* Cancel: unused */
 
58
        RB_OP(0,                  LDAP_SUCCESS),    /* operational         */
 
59
        RB_OP(RB_CHK_REF,         LDAP_SUCCESS),    /* chk_referrals:unused*/
 
60
        RB_OP(0,                  SLAP_CB_CONTINUE),/* chk_controls:unused */
 
61
        /* additional relay_operation_t indexes from back-relay.h: */
 
62
        RB_OP(0,                  0/*unused*/),     /* entry_get = op_last */
 
63
        RB_OP(0,                  0/*unused*/),     /* entry_release       */
 
64
        RB_OP(0,                  0/*unused*/),     /* has_subordinates    */
 
65
};
 
66
 
 
67
/*
 
68
 * Callbacks: Caller changed op->o_bd from Relay to underlying
 
69
 * BackendDB.  sc_response sets it to Relay BackendDB, sc_cleanup puts
 
70
 * back underlying BackendDB.  Caller will restore Relay BackendDB.
 
71
 */
 
72
 
 
73
typedef struct relay_callback {
 
74
        slap_callback rcb_sc;
 
75
        BackendDB *rcb_bd;
 
76
} relay_callback;
 
77
 
 
78
int
 
79
relay_back_cleanup_cb( Operation *op, SlapReply *rs )
 
80
{
 
81
        op->o_bd = ((relay_callback *) op->o_callback)->rcb_bd;
 
82
        return SLAP_CB_CONTINUE;
 
83
}
 
84
 
 
85
int
 
86
relay_back_response_cb( Operation *op, SlapReply *rs )
 
87
{
 
88
        relay_callback  *rcb = (relay_callback *) op->o_callback;
 
89
 
 
90
        rcb->rcb_sc.sc_cleanup = relay_back_cleanup_cb;
 
91
        rcb->rcb_bd = op->o_bd;
 
92
        op->o_bd = op->o_callback->sc_private;
 
93
        return SLAP_CB_CONTINUE;
 
94
}
 
95
 
 
96
#define relay_back_add_cb( rcb, op, bd )                        \
 
97
        {                                                       \
 
98
                (rcb)->rcb_sc.sc_next = (op)->o_callback;       \
 
99
                (rcb)->rcb_sc.sc_response = relay_back_response_cb; \
 
100
                (rcb)->rcb_sc.sc_cleanup = 0;                   \
 
101
                (rcb)->rcb_sc.sc_private = (op)->o_bd;          \
 
102
                (op)->o_callback = (slap_callback *) (rcb);     \
59
103
        }
60
104
 
61
105
/*
62
 
 * selects the backend if not enforced at config;
63
 
 * in case of failure, behaves based on err:
64
 
 *      -1                      don't send result
65
 
 *      LDAP_SUCCESS            don't send result; may send referral if dosend
66
 
 *      any valid error         send as error result if dosend
 
106
 * Select the backend database with the operation's DN.  On failure,
 
107
 * set/send results depending on operation type <which>'s fail_modes.
67
108
 */
68
109
static BackendDB *
69
 
relay_back_select_backend( Operation *op, SlapReply *rs, slap_mask_t fail_mode )
 
110
relay_back_select_backend( Operation *op, SlapReply *rs, int which )
70
111
{
71
 
        relay_back_info         *ri = (relay_back_info *)op->o_bd->be_private;
72
 
        BackendDB               *bd = ri->ri_bd;
73
 
        int                     rc = ( fail_mode & RB_ERR_MASK );
 
112
        OpExtra         *oex;
 
113
        char            *key = (char *) op->o_bd->be_private;
 
114
        BackendDB       *bd  = ((relay_back_info *) key)->ri_bd;
 
115
        slap_mask_t     fail_mode = relay_fail_modes[which].rf_bd;
 
116
        int             useDN = 0, rc = ( fail_mode & RB_ERR_MASK );
74
117
 
75
118
        if ( bd == NULL && !BER_BVISNULL( &op->o_req_ndn ) ) {
 
119
                useDN = 1;
76
120
                bd = select_backend( &op->o_req_ndn, 1 );
77
 
                if ( bd->be_private == op->o_bd->be_private ) {
78
 
                        Debug( LDAP_DEBUG_ANY,
79
 
                                "%s: back-relay for DN=\"%s\" would call self.\n",
80
 
                                op->o_log_prefix, op->o_req_dn.bv_val, 0 );
81
 
                        if ( fail_mode & RB_ERR ) {
82
 
                                rs->sr_err = rc;
83
 
                                if ( fail_mode & RB_SEND ) {
84
 
                                        send_ldap_result( op, rs );
85
 
                                }
86
 
                        }
87
 
 
88
 
                        return NULL;
89
 
                }
90
 
        }
91
 
 
92
 
        if ( bd == NULL ) {
93
 
                if ( ( fail_mode & RB_REFERRAL )
94
 
                        && ( fail_mode & RB_SEND )
95
 
                        && !BER_BVISNULL( &op->o_req_ndn )
96
 
                        && default_referral )
97
 
                {
98
 
                        rs->sr_err = LDAP_REFERRAL;
99
 
 
100
 
                        /* if we set sr_err to LDAP_REFERRAL,
101
 
                         * we must provide one */
102
 
                        rs->sr_ref = referral_rewrite(
103
 
                                default_referral,
104
 
                                NULL, &op->o_req_dn,
105
 
                                LDAP_SCOPE_DEFAULT );
106
 
                        if ( !rs->sr_ref ) {
107
 
                                rs->sr_ref = default_referral;
108
 
                        }
109
 
 
110
 
                        send_ldap_result( op, rs );
111
 
 
112
 
                        if ( rs->sr_ref != default_referral ) {
113
 
                                ber_bvarray_free( rs->sr_ref );
114
 
                        }
115
 
 
116
 
                        return NULL;
117
 
                }
118
 
 
119
 
                /* NOTE: err is LDAP_INVALID_CREDENTIALS for bind,
120
 
                 * LDAP_NO_SUCH_OBJECT for other operations.
121
 
                 * noSuchObject cannot be returned by bind */
 
121
        }
 
122
 
 
123
        if ( bd != NULL ) {
 
124
                key += which; /* <relay, op type> key from RELAY_WRAP_OP() */
 
125
                LDAP_SLIST_FOREACH( oex, &op->o_extra, oe_next ) {
 
126
                        if ( oex->oe_key == key )
 
127
                                break;
 
128
                }
 
129
                if ( oex == NULL ) {
 
130
                        return bd;
 
131
                }
 
132
 
 
133
                Debug( LDAP_DEBUG_ANY,
 
134
                        "%s: back-relay for DN=\"%s\" would call self.\n",
 
135
                        op->o_log_prefix, op->o_req_dn.bv_val, 0 );
 
136
 
 
137
        } else if ( useDN && ( fail_mode & RB_REF ) && default_referral ) {
 
138
                rc = LDAP_REFERRAL;
 
139
 
 
140
                /* if we set sr_err to LDAP_REFERRAL, we must provide one */
 
141
                rs->sr_ref = referral_rewrite(
 
142
                        default_referral, NULL, &op->o_req_dn,
 
143
                        op->o_tag == LDAP_REQ_SEARCH ?
 
144
                        op->ors_scope : LDAP_SCOPE_DEFAULT );
 
145
                if ( rs->sr_ref != NULL ) {
 
146
                        rs->sr_flags |= REP_REF_MUSTBEFREED;
 
147
                } else {
 
148
                        rs->sr_ref = default_referral;
 
149
                }
 
150
 
 
151
                if ( fail_mode & RB_SENDREF )
 
152
                        fail_mode = (RB_BDERR | RB_SEND);
 
153
        }
 
154
 
 
155
        if ( fail_mode & RB_BDERR ) {
122
156
                rs->sr_err = rc;
123
157
                if ( fail_mode & RB_SEND ) {
124
158
                        send_ldap_result( op, rs );
125
159
                }
126
160
        }
127
161
 
128
 
        return bd;
129
 
}
130
 
 
 
162
        return NULL;
 
163
}
 
164
 
 
165
/*
 
166
 * Forward <act> on <op> to database <bd>, with <relay, op type>-specific
 
167
 * key in op->o_extra so relay_back_select_backend() can catch recursion.
 
168
 */
 
169
#define RELAY_WRAP_OP( op, bd, which, act ) { \
 
170
        OpExtraDB wrap_oex; \
 
171
        BackendDB *const wrap_bd = (op)->o_bd; \
 
172
        wrap_oex.oe_db = wrap_bd; \
 
173
        wrap_oex.oe.oe_key = (char *) wrap_bd->be_private + (which); \
 
174
        LDAP_SLIST_INSERT_HEAD( &(op)->o_extra, &wrap_oex.oe, oe_next ); \
 
175
        (op)->o_bd = (bd); \
 
176
        act; \
 
177
        (op)->o_bd = wrap_bd; \
 
178
        LDAP_SLIST_REMOVE( &(op)->o_extra, &wrap_oex.oe, OpExtra, oe_next ); \
 
179
}
 
180
 
 
181
/*
 
182
 * Forward backend function #<which> on <op> to operation DN's database
 
183
 * like RELAY_WRAP_OP, after setting up callbacks. If no database or no
 
184
 * backend function, set/send results depending on <which>'s fail_modes.
 
185
 */
131
186
static int
132
 
relay_back_op(
133
 
        Operation       *op,
134
 
        SlapReply       *rs,
135
 
        BackendDB       *bd,
136
 
        BI_op_func      *func,
137
 
        slap_mask_t     fail_mode )
 
187
relay_back_op( Operation *op, SlapReply *rs, int which )
138
188
{
139
 
        int                     rc = ( fail_mode & RB_ERR_MASK );
140
 
 
141
 
        if ( func ) {
142
 
                BackendDB       *be = op->o_bd;
143
 
                slap_callback   cb;
144
 
 
145
 
                relay_back_add_cb( &cb, op );
146
 
 
147
 
                op->o_bd = bd;
148
 
                rc = func( op, rs );
149
 
                op->o_bd = be;
150
 
 
151
 
                if ( op->o_callback == &cb ) {
 
189
        BackendDB       *bd;
 
190
        BI_op_bind      *func;
 
191
        slap_mask_t     fail_mode = relay_fail_modes[which].rf_op;
 
192
        int             rc = ( fail_mode & RB_ERR_MASK );
 
193
 
 
194
        bd = relay_back_select_backend( op, rs, which );
 
195
        if ( bd == NULL ) {
 
196
                if ( fail_mode & RB_BDERR )
 
197
                        return rs->sr_err;      /* sr_err was set above */
 
198
 
 
199
        } else if ( (func = (&bd->be_bind)[which]) != 0 ) {
 
200
                relay_callback  rcb;
 
201
 
 
202
                relay_back_add_cb( &rcb, op, bd );
 
203
 
 
204
                RELAY_WRAP_OP( op, bd, which, {
 
205
                        rc = func( op, rs );
 
206
                });
 
207
 
 
208
                if ( op->o_callback == (slap_callback *) &rcb ) {
152
209
                        op->o_callback = op->o_callback->sc_next;
153
210
                }
154
211
 
155
 
        } else if ( fail_mode & RB_ERR ) {
 
212
        } else if ( fail_mode & RB_OPERR ) {
156
213
                rs->sr_err = rc;
157
 
                if ( fail_mode & RB_UNSUPPORTED_FLAG ) {
 
214
                if ( rc == LDAP_UNWILLING_TO_PERFORM ) {
158
215
                        rs->sr_text = "operation not supported within naming context";
159
216
                }
160
217
 
166
223
        return rc;
167
224
}
168
225
 
 
226
 
169
227
int
170
228
relay_back_op_bind( Operation *op, SlapReply *rs )
171
229
{
172
 
        BackendDB       *bd;
173
 
 
174
230
        /* allow rootdn as a means to auth without the need to actually
175
231
         * contact the proxied DSA */
176
232
        switch ( be_rootdn_bind( op, rs ) ) {
181
237
                return rs->sr_err;
182
238
        }
183
239
 
184
 
        bd = relay_back_select_backend( op, rs,
185
 
                ( LDAP_INVALID_CREDENTIALS | RB_ERR_SEND ) );
186
 
        if ( bd == NULL ) {
187
 
                return rs->sr_err;
188
 
        }
189
 
 
190
 
        return relay_back_op( op, rs, bd, bd->be_bind,
191
 
                ( LDAP_INVALID_CREDENTIALS | RB_ERR_SEND ) );
192
 
}
193
 
 
194
 
int
195
 
relay_back_op_unbind( Operation *op, SlapReply *rs )
196
 
{
197
 
        BackendDB               *bd;
198
 
 
199
 
        bd = relay_back_select_backend( op, rs, 0 );
200
 
        if ( bd != NULL ) {
201
 
                (void)relay_back_op( op, rs, bd, bd->be_unbind, 0 );
202
 
        }
203
 
 
204
 
        return 0;
205
 
}
206
 
 
207
 
int
208
 
relay_back_op_search( Operation *op, SlapReply *rs )
209
 
{
210
 
        BackendDB               *bd;
211
 
 
212
 
        bd = relay_back_select_backend( op, rs,
213
 
                ( LDAP_NO_SUCH_OBJECT | RB_ERR_REFERRAL_SEND ) );
214
 
        if ( bd == NULL ) {
215
 
                return rs->sr_err;
216
 
        }
217
 
 
218
 
        return relay_back_op( op, rs, bd, bd->be_search,
219
 
                RB_UNSUPPORTED_SEND );
220
 
}
221
 
 
222
 
int
223
 
relay_back_op_compare( Operation *op, SlapReply *rs )
224
 
{
225
 
        BackendDB               *bd;
226
 
 
227
 
        bd = relay_back_select_backend( op, rs,
228
 
                ( LDAP_NO_SUCH_OBJECT | RB_ERR_REFERRAL_SEND ) );
229
 
        if ( bd == NULL ) {
230
 
                return rs->sr_err;
231
 
        }
232
 
 
233
 
        return relay_back_op( op, rs, bd, bd->be_compare,
234
 
                ( SLAP_CB_CONTINUE | RB_ERR ) );
235
 
}
236
 
 
237
 
int
238
 
relay_back_op_modify( Operation *op, SlapReply *rs )
239
 
{
240
 
        BackendDB               *bd;
241
 
 
242
 
        bd = relay_back_select_backend( op, rs,
243
 
                ( LDAP_NO_SUCH_OBJECT | RB_ERR_REFERRAL_SEND ) );
244
 
        if ( bd == NULL ) {
245
 
                return rs->sr_err;
246
 
        }
247
 
 
248
 
        return relay_back_op( op, rs, bd, bd->be_modify,
249
 
                RB_UNSUPPORTED_SEND );
250
 
}
251
 
 
252
 
int
253
 
relay_back_op_modrdn( Operation *op, SlapReply *rs )
254
 
{
255
 
        BackendDB               *bd;
256
 
 
257
 
        bd = relay_back_select_backend( op, rs,
258
 
                ( LDAP_NO_SUCH_OBJECT | RB_ERR_REFERRAL_SEND ) );
259
 
        if ( bd == NULL ) {
260
 
                return rs->sr_err;
261
 
        }
262
 
 
263
 
        return relay_back_op( op, rs, bd, bd->be_modrdn,
264
 
                RB_UNSUPPORTED_SEND );
265
 
}
266
 
 
267
 
int
268
 
relay_back_op_add( Operation *op, SlapReply *rs )
269
 
{
270
 
        BackendDB               *bd;
271
 
 
272
 
        bd = relay_back_select_backend( op, rs,
273
 
                ( LDAP_NO_SUCH_OBJECT | RB_ERR_REFERRAL_SEND ) );
274
 
        if ( bd == NULL ) {
275
 
                return rs->sr_err;
276
 
        }
277
 
 
278
 
        return relay_back_op( op, rs, bd, bd->be_add,
279
 
                RB_UNSUPPORTED_SEND );
280
 
}
281
 
 
282
 
int
283
 
relay_back_op_delete( Operation *op, SlapReply *rs )
284
 
{
285
 
        BackendDB               *bd;
286
 
 
287
 
        bd = relay_back_select_backend( op, rs,
288
 
                ( LDAP_NO_SUCH_OBJECT | RB_ERR_REFERRAL_SEND ) );
289
 
        if ( bd == NULL ) {
290
 
                return rs->sr_err;
291
 
        }
292
 
 
293
 
        return relay_back_op( op, rs, bd, bd->be_delete,
294
 
                RB_UNSUPPORTED_SEND );
295
 
}
296
 
 
297
 
int
298
 
relay_back_op_abandon( Operation *op, SlapReply *rs )
299
 
{
300
 
        BackendDB               *bd;
301
 
 
302
 
        bd = relay_back_select_backend( op, rs, 0 );
303
 
        if ( bd == NULL ) {
304
 
                return rs->sr_err;
305
 
        }
306
 
 
307
 
        return relay_back_op( op, rs, bd, bd->be_abandon, 0 );
308
 
}
309
 
 
310
 
int
311
 
relay_back_op_cancel( Operation *op, SlapReply *rs )
312
 
{
313
 
        BackendDB               *bd;
314
 
        int                     rc;
315
 
 
316
 
        bd = relay_back_select_backend( op, rs,
317
 
                ( LDAP_CANNOT_CANCEL | RB_ERR ) );
318
 
        if ( bd == NULL ) {
319
 
                if ( op->o_cancel == SLAP_CANCEL_REQ ) {
320
 
                        op->o_cancel = LDAP_CANNOT_CANCEL;
321
 
                }
322
 
                return rs->sr_err;
323
 
        }
324
 
 
325
 
        rc = relay_back_op( op, rs, bd, bd->be_cancel,
326
 
                ( LDAP_CANNOT_CANCEL | RB_ERR ) );
327
 
        if ( rc == LDAP_CANNOT_CANCEL && op->o_cancel == SLAP_CANCEL_REQ )
328
 
        {
329
 
                op->o_cancel = LDAP_CANNOT_CANCEL;
330
 
        }
331
 
 
332
 
        return rc;
333
 
}
334
 
 
335
 
int
336
 
relay_back_op_extended( Operation *op, SlapReply *rs )
337
 
{
338
 
        BackendDB               *bd;
339
 
 
340
 
        bd = relay_back_select_backend( op, rs,
341
 
                ( LDAP_NO_SUCH_OBJECT | RB_ERR | RB_REFERRAL ) );
342
 
        if ( bd == NULL ) {
343
 
                return rs->sr_err;
344
 
        }
345
 
 
346
 
        return relay_back_op( op, rs, bd, bd->be_extended,
347
 
                RB_UNSUPPORTED );
348
 
}
 
240
        return relay_back_op( op, rs, op_bind );
 
241
}
 
242
 
 
243
#define RELAY_DEFOP(func, which) \
 
244
        int func( Operation *op, SlapReply *rs ) \
 
245
        { return relay_back_op( op, rs, which ); }
 
246
 
 
247
RELAY_DEFOP( relay_back_op_search,              op_search )
 
248
RELAY_DEFOP( relay_back_op_compare,             op_compare )
 
249
RELAY_DEFOP( relay_back_op_modify,              op_modify )
 
250
RELAY_DEFOP( relay_back_op_modrdn,              op_modrdn )
 
251
RELAY_DEFOP( relay_back_op_add,                 op_add )
 
252
RELAY_DEFOP( relay_back_op_delete,              op_delete )
 
253
RELAY_DEFOP( relay_back_op_extended,    op_extended )
 
254
RELAY_DEFOP( relay_back_operational,    op_aux_operational )
 
255
 
 
256
/* Abandon, Cancel, Unbind and some DN-less calls like be_connection_init
 
257
 * need no extra handling:  slapd already calls them for all databases.
 
258
 */
 
259
 
349
260
 
350
261
int
351
262
relay_back_entry_release_rw( Operation *op, Entry *e, int rw )
352
263
{
353
 
        relay_back_info         *ri = (relay_back_info *)op->o_bd->be_private;
354
264
        BackendDB               *bd;
355
 
        int                     rc = 1;
356
 
 
357
 
        bd = ri->ri_bd;
358
 
        if ( bd == NULL) {
359
 
                bd = select_backend( &op->o_req_ndn, 1 );
360
 
                if ( bd == NULL ) {
361
 
                        return 1;
362
 
                }
363
 
        }
364
 
 
365
 
        if ( bd->be_release ) {
366
 
                BackendDB       *be = op->o_bd;
367
 
 
368
 
                op->o_bd = bd;
369
 
                rc = bd->be_release( op, e, rw );
370
 
                op->o_bd = be;
 
265
        int                     rc = LDAP_UNWILLING_TO_PERFORM;
 
266
 
 
267
        bd = relay_back_select_backend( op, NULL, relay_op_entry_release );
 
268
        if ( bd && bd->be_release ) {
 
269
                RELAY_WRAP_OP( op, bd, relay_op_entry_release, {
 
270
                        rc = bd->be_release( op, e, rw );
 
271
                });
 
272
        } else if ( e->e_private == NULL ) {
 
273
                entry_free( e );
 
274
                rc = LDAP_SUCCESS;
371
275
        }
372
276
 
373
277
        return rc;
374
 
 
375
278
}
376
279
 
377
280
int
378
281
relay_back_entry_get_rw( Operation *op, struct berval *ndn,
379
282
        ObjectClass *oc, AttributeDescription *at, int rw, Entry **e )
380
283
{
381
 
        relay_back_info         *ri = (relay_back_info *)op->o_bd->be_private;
382
284
        BackendDB               *bd;
383
 
        int                     rc = 1;
384
 
 
385
 
        bd = ri->ri_bd;
386
 
        if ( bd == NULL) {
387
 
                bd = select_backend( &op->o_req_ndn, 1 );
388
 
                if ( bd == NULL ) {
389
 
                        return 1;
390
 
                }
391
 
        }
392
 
 
393
 
        if ( bd->be_fetch ) {
394
 
                BackendDB       *be = op->o_bd;
395
 
 
396
 
                op->o_bd = bd;
397
 
                rc = bd->be_fetch( op, ndn, oc, at, rw, e );
398
 
                op->o_bd = be;
 
285
        int                     rc = LDAP_NO_SUCH_OBJECT;
 
286
 
 
287
        bd = relay_back_select_backend( op, NULL, relay_op_entry_get );
 
288
        if ( bd && bd->be_fetch ) {
 
289
                RELAY_WRAP_OP( op, bd, relay_op_entry_get, {
 
290
                        rc = bd->be_fetch( op, ndn, oc, at, rw, e );
 
291
                });
399
292
        }
400
293
 
401
294
        return rc;
402
 
 
403
295
}
404
296
 
 
297
#if 0 /* Give the RB_SENDREF flag a nonzero value if implementing this */
405
298
/*
406
299
 * NOTE: even the existence of this function is questionable: we cannot
407
300
 * pass the bi_chk_referrals() call thru the rwm overlay because there
409
302
 * is passing the target database a DN that likely does not belong to its
410
303
 * naming context... mmmh.
411
304
 */
412
 
int
413
 
relay_back_chk_referrals( Operation *op, SlapReply *rs )
414
 
{
415
 
        BackendDB               *bd;
416
 
 
417
 
        bd = relay_back_select_backend( op, rs,
418
 
                ( LDAP_SUCCESS | RB_ERR_REFERRAL_SEND ) );
419
 
        /* FIXME: this test only works if there are no overlays, so
420
 
         * it is nearly useless; if made stricter, no nested back-relays
421
 
         * can be instantiated... too bad. */
422
 
        if ( bd == NULL || bd == op->o_bd ) {
423
 
                return 0;
424
 
        }
425
 
 
426
 
        /* no nested back-relays... */
427
 
        if ( overlay_is_over( bd ) ) {
428
 
                slap_overinfo   *oi = (slap_overinfo *)bd->bd_info->bi_private;
429
 
 
430
 
                if ( oi->oi_orig == op->o_bd->bd_info ) {
431
 
                        return 0;
432
 
                }
433
 
        }
434
 
 
435
 
        return relay_back_op( op, rs, bd, bd->be_chk_referrals, LDAP_SUCCESS );
436
 
}
437
 
 
438
 
int
439
 
relay_back_operational( Operation *op, SlapReply *rs )
440
 
{
441
 
        BackendDB               *bd;
442
 
 
443
 
        bd = relay_back_select_backend( op, rs,
444
 
                ( LDAP_SUCCESS | RB_ERR ) );
445
 
        /* FIXME: this test only works if there are no overlays, so
446
 
         * it is nearly useless; if made stricter, no nested back-relays
447
 
         * can be instantiated... too bad. */
448
 
        if ( bd == NULL || bd == op->o_bd ) {
449
 
                return 0;
450
 
        }
451
 
 
452
 
        return relay_back_op( op, rs, bd, bd->be_operational, 0 );
453
 
}
 
305
RELAY_DEFOP( relay_back_chk_referrals, op_aux_chk_referrals )
 
306
#endif /*0*/
454
307
 
455
308
int
456
309
relay_back_has_subordinates( Operation *op, Entry *e, int *hasSubs )
457
310
{
458
 
        SlapReply               rs = { 0 };
459
311
        BackendDB               *bd;
460
312
        int                     rc = LDAP_OTHER;
461
313
 
462
 
        bd = relay_back_select_backend( op, &rs, LDAP_OTHER );
463
 
        /* FIXME: this test only works if there are no overlays, so
464
 
         * it is nearly useless; if made stricter, no nested back-relays
465
 
         * can be instantiated... too bad. */
466
 
        if ( bd == NULL || bd == op->o_bd ) {
467
 
                return LDAP_OTHER;
468
 
        }
469
 
 
470
 
        if ( bd->be_has_subordinates ) {
471
 
                BackendDB       *be = op->o_bd;
472
 
 
473
 
                op->o_bd = bd;
474
 
                rc = bd->be_has_subordinates( op, e, hasSubs );
475
 
                op->o_bd = be;
 
314
        bd = relay_back_select_backend( op, NULL, relay_op_has_subordinates );
 
315
        if ( bd && bd->be_has_subordinates ) {
 
316
                RELAY_WRAP_OP( op, bd, relay_op_has_subordinates, {
 
317
                        rc = bd->be_has_subordinates( op, e, hasSubs );
 
318
                });
476
319
        }
477
320
 
478
321
        return rc;
479
322
}
480
323
 
481
 
int
482
 
relay_back_connection_init( BackendDB *bd, Connection *c )
483
 
{
484
 
        relay_back_info         *ri = (relay_back_info *)bd->be_private;
485
 
 
486
 
        bd = ri->ri_bd;
487
 
        if ( bd == NULL ) {
488
 
                return 0;
489
 
        }
490
 
 
491
 
        if ( bd->be_connection_init ) {
492
 
                return bd->be_connection_init( bd, c );
493
 
        }
494
 
 
495
 
        return 0;
496
 
}
497
 
 
498
 
int
499
 
relay_back_connection_destroy( BackendDB *bd, Connection *c )
500
 
{
501
 
        relay_back_info         *ri = (relay_back_info *)bd->be_private;
502
 
 
503
 
        bd = ri->ri_bd;
504
 
        if ( bd == NULL ) {
505
 
                return 0;
506
 
        }
507
 
 
508
 
        if ( bd->be_connection_destroy ) {
509
 
                return bd->be_connection_destroy( bd, c );
510
 
        }
511
 
 
512
 
        return 0;
513
 
 
514
 
}
515
324
 
516
325
/*
517
326
 * FIXME: must implement tools as well