1 /* op.c - relay backend operations */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 2003-2004 The OpenLDAP Foundation.
5 * Portions Copyright 2004 Pierangelo Masarati.
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>.
17 * This work was initially developed by Pierangelo Masarati for inclusion
18 * in OpenLDAP Software.
25 #include <ac/string.h>
26 #include <ac/socket.h>
29 #include "back-relay.h"
32 relay_back_select_backend( struct slap_op *op, struct slap_rep *rs, int err )
34 relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
35 BackendDB *bd = ri->ri_bd;
38 bd = select_backend( &op->o_req_ndn, 0, 1 );
39 if ( bd == op->o_bd ) {
40 if ( err != LDAP_SUCCESS ) {
41 send_ldap_error( op, rs,
42 LDAP_UNWILLING_TO_PERFORM,
50 if ( default_referral ) {
51 rs->sr_ref = referral_rewrite( default_referral,
52 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
54 rs->sr_ref = default_referral;
57 rs->sr_err = LDAP_REFERRAL;
58 send_ldap_result( op, rs );
60 if ( rs->sr_ref != default_referral ) {
61 ber_bvarray_free( rs->sr_ref );
65 /* NOTE: err is LDAP_INVALID_CREDENTIALS for bind,
66 * LDAP_NO_SUCH_OBJECT for other operations.
67 * noSuchObject is not allowed to be returned by bind */
69 send_ldap_result( op, rs );
77 relay_back_op_bind( struct slap_op *op, struct slap_rep *rs )
82 bd = relay_back_select_backend( op, rs, LDAP_INVALID_CREDENTIALS );
88 BackendDB *be = op->o_bd;
91 rc = ( bd->be_bind )( op, rs );
95 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
96 "operation not supported "
97 "within naming context" );
104 relay_back_op_unbind( struct slap_op *op, struct slap_rep *rs )
109 bd = relay_back_select_backend( op, rs, LDAP_NO_SUCH_OBJECT );
114 if ( bd->be_unbind ) {
115 BackendDB *be = op->o_bd;
118 rc = ( bd->be_unbind )( op, rs );
122 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
123 "operation not supported "
124 "within naming context" );
132 relay_back_op_search( struct slap_op *op, struct slap_rep *rs )
137 bd = relay_back_select_backend( op, rs, LDAP_NO_SUCH_OBJECT );
142 if ( bd->be_search ) {
143 BackendDB *be = op->o_bd;
146 rc = ( bd->be_search )( op, rs );
150 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
151 "operation not supported "
152 "within naming context" );
160 relay_back_op_compare( struct slap_op *op, struct slap_rep *rs )
165 bd = relay_back_select_backend( op, rs, LDAP_NO_SUCH_OBJECT );
170 if ( bd->be_compare ) {
171 BackendDB *be = op->o_bd;
174 rc = ( bd->be_compare )( op, rs );
178 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
179 "operation not supported "
180 "within naming context" );
188 relay_back_op_modify( struct slap_op *op, struct slap_rep *rs )
193 bd = relay_back_select_backend( op, rs, LDAP_NO_SUCH_OBJECT );
198 if ( bd->be_modify ) {
199 BackendDB *be = op->o_bd;
202 rc = ( bd->be_modify )( op, rs );
206 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
207 "operation not supported "
208 "within naming context" );
216 relay_back_op_modrdn( struct slap_op *op, struct slap_rep *rs )
221 bd = relay_back_select_backend( op, rs, LDAP_NO_SUCH_OBJECT );
226 if ( bd->be_modrdn ) {
227 BackendDB *be = op->o_bd;
230 rc = ( bd->be_modrdn )( op, rs );
234 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
235 "operation not supported "
236 "within naming context" );
244 relay_back_op_add( struct slap_op *op, struct slap_rep *rs )
249 bd = relay_back_select_backend( op, rs, LDAP_NO_SUCH_OBJECT );
255 BackendDB *be = op->o_bd;
258 rc = ( bd->be_add )( op, rs );
262 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
263 "operation not supported "
264 "within naming context" );
272 relay_back_op_delete( struct slap_op *op, struct slap_rep *rs )
277 bd = relay_back_select_backend( op, rs, LDAP_NO_SUCH_OBJECT );
282 if ( bd->be_delete ) {
283 BackendDB *be = op->o_bd;
286 rc = ( bd->be_delete )( op, rs );
295 relay_back_op_abandon( struct slap_op *op, struct slap_rep *rs )
300 bd = relay_back_select_backend( op, rs, LDAP_NO_SUCH_OBJECT );
305 if ( bd->be_abandon ) {
306 BackendDB *be = op->o_bd;
309 rc = ( bd->be_abandon )( op, rs );
313 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
314 "operation not supported "
315 "within naming context" );
323 relay_back_op_cancel( struct slap_op *op, struct slap_rep *rs )
328 bd = relay_back_select_backend( op, rs, LDAP_NO_SUCH_OBJECT );
333 if ( bd->be_cancel ) {
334 BackendDB *be = op->o_bd;
337 rc = ( bd->be_cancel )( op, rs );
341 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
342 "operation not supported "
343 "within naming context" );
351 relay_back_op_extended( struct slap_op *op, struct slap_rep *rs )
356 bd = relay_back_select_backend( op, rs, LDAP_NO_SUCH_OBJECT );
361 if ( bd->be_extended ) {
362 BackendDB *be = op->o_bd;
365 rc = ( bd->be_extended )( op, rs );
369 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
370 "operation not supported "
371 "within naming context" );
379 relay_back_entry_release_rw( struct slap_op *op, Entry *e, int rw )
381 relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
387 bd = select_backend( &op->o_req_ndn, 0, 1 );
393 if ( bd->be_release ) {
394 BackendDB *be = op->o_bd;
397 rc = ( bd->be_release )( op, e, rw );
406 relay_back_entry_get_rw( struct slap_op *op, struct berval *ndn,
407 ObjectClass *oc, AttributeDescription *at, int rw, Entry **e )
409 relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
415 bd = select_backend( &op->o_req_ndn, 0, 1 );
421 if ( bd->be_fetch ) {
422 BackendDB *be = op->o_bd;
425 rc = ( bd->be_fetch )( op, ndn, oc, at, rw, e );
434 relay_back_chk_referrals( struct slap_op *op, struct slap_rep *rs )
439 bd = relay_back_select_backend( op, rs, LDAP_SUCCESS );
444 if ( bd->be_chk_referrals ) {
445 BackendDB *be = op->o_bd;
448 rc = ( bd->be_chk_referrals )( op, rs );
457 relay_back_operational( struct slap_op *op, struct slap_rep *rs,
458 int opattrs, Attribute **ap )
460 relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
466 bd = select_backend( &op->o_req_ndn, 0, 1 );
472 if ( bd->be_operational ) {
473 BackendDB *be = op->o_bd;
476 rc = ( bd->be_operational )( op, rs, opattrs, ap );
485 relay_back_has_subordinates( struct slap_op *op, Entry *e, int *hasSubs )
487 relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
493 bd = select_backend( &op->o_req_ndn, 0, 1 );
499 if ( bd->be_has_subordinates ) {
500 BackendDB *be = op->o_bd;
503 rc = ( bd->be_has_subordinates )( op, e, hasSubs );
512 relay_back_connection_init( BackendDB *bd, struct slap_conn *c )
514 relay_back_info *ri = (relay_back_info *)bd->be_private;
521 if ( bd->be_connection_init ) {
522 return ( bd->be_connection_init )( bd, c );
529 relay_back_connection_destroy( BackendDB *bd, struct slap_conn *c )
531 relay_back_info *ri = (relay_back_info *)bd->be_private;
538 if ( bd->be_connection_destroy ) {
539 return ( bd->be_connection_destroy )( bd, c );
547 * FIXME: must implement tools as well