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 );
42 if ( default_referral ) {
43 rs->sr_ref = referral_rewrite( default_referral,
44 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
46 rs->sr_ref = default_referral;
49 rs->sr_err = LDAP_REFERRAL;
50 send_ldap_result( op, rs );
52 if (rs->sr_ref != default_referral) {
53 ber_bvarray_free( rs->sr_ref );
57 /* NOTE: err is LDAP_INVALID_CREDENTIALS for bind,
58 * LDAP_NO_SUCH_OBJECT for other operations.
59 * noSuchObject is not allowed to be returned by bind */
61 send_ldap_result( op, rs );
69 relay_back_op_bind( struct slap_op *op, struct slap_rep *rs )
74 bd = relay_back_select_backend( op, rs, LDAP_INVALID_CREDENTIALS );
80 BackendDB *be = op->o_bd;
83 rc = ( bd->be_bind )( op, rs );
87 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
88 "operation not supported "
89 "within naming context" );
96 relay_back_op_unbind( struct slap_op *op, struct slap_rep *rs )
101 bd = relay_back_select_backend( op, rs, LDAP_NO_SUCH_OBJECT );
106 if ( bd->be_unbind ) {
107 BackendDB *be = op->o_bd;
110 rc = ( bd->be_unbind )( op, rs );
114 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
115 "operation not supported "
116 "within naming context" );
124 relay_back_op_search( struct slap_op *op, struct slap_rep *rs )
129 bd = relay_back_select_backend( op, rs, LDAP_NO_SUCH_OBJECT );
134 if ( bd->be_search ) {
135 BackendDB *be = op->o_bd;
138 rc = ( bd->be_search )( op, rs );
142 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
143 "operation not supported "
144 "within naming context" );
152 relay_back_op_compare( struct slap_op *op, struct slap_rep *rs )
157 bd = relay_back_select_backend( op, rs, LDAP_NO_SUCH_OBJECT );
162 if ( bd->be_compare ) {
163 BackendDB *be = op->o_bd;
166 rc = ( bd->be_compare )( op, rs );
170 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
171 "operation not supported "
172 "within naming context" );
180 relay_back_op_modify( struct slap_op *op, struct slap_rep *rs )
185 bd = relay_back_select_backend( op, rs, LDAP_NO_SUCH_OBJECT );
190 if ( bd->be_modify ) {
191 BackendDB *be = op->o_bd;
194 rc = ( bd->be_modify )( op, rs );
198 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
199 "operation not supported "
200 "within naming context" );
208 relay_back_op_modrdn( struct slap_op *op, struct slap_rep *rs )
213 bd = relay_back_select_backend( op, rs, LDAP_NO_SUCH_OBJECT );
218 if ( bd->be_modrdn ) {
219 BackendDB *be = op->o_bd;
222 rc = ( bd->be_modrdn )( op, rs );
226 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
227 "operation not supported "
228 "within naming context" );
236 relay_back_op_add( struct slap_op *op, struct slap_rep *rs )
241 bd = relay_back_select_backend( op, rs, LDAP_NO_SUCH_OBJECT );
247 BackendDB *be = op->o_bd;
250 rc = ( bd->be_add )( op, rs );
254 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
255 "operation not supported "
256 "within naming context" );
264 relay_back_op_delete( struct slap_op *op, struct slap_rep *rs )
269 bd = relay_back_select_backend( op, rs, LDAP_NO_SUCH_OBJECT );
274 if ( bd->be_delete ) {
275 BackendDB *be = op->o_bd;
278 rc = ( bd->be_delete )( op, rs );
287 relay_back_op_abandon( struct slap_op *op, struct slap_rep *rs )
292 bd = relay_back_select_backend( op, rs, LDAP_NO_SUCH_OBJECT );
297 if ( bd->be_abandon ) {
298 BackendDB *be = op->o_bd;
301 rc = ( bd->be_abandon )( op, rs );
305 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
306 "operation not supported "
307 "within naming context" );
315 relay_back_op_cancel( struct slap_op *op, struct slap_rep *rs )
320 bd = relay_back_select_backend( op, rs, LDAP_NO_SUCH_OBJECT );
325 if ( bd->be_cancel ) {
326 BackendDB *be = op->o_bd;
329 rc = ( bd->be_cancel )( op, rs );
333 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
334 "operation not supported "
335 "within naming context" );
343 relay_back_op_extended( struct slap_op *op, struct slap_rep *rs )
348 bd = relay_back_select_backend( op, rs, LDAP_NO_SUCH_OBJECT );
353 if ( bd->be_extended ) {
354 BackendDB *be = op->o_bd;
357 rc = ( bd->be_extended )( op, rs );
361 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
362 "operation not supported "
363 "within naming context" );
371 relay_back_entry_release_rw( struct slap_op *op, Entry *e, int rw )
373 relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
379 bd = select_backend( &op->o_req_ndn, 0, 1 );
385 if ( bd->be_release ) {
386 BackendDB *be = op->o_bd;
389 rc = ( bd->be_release )( op, e, rw );
398 relay_back_entry_get_rw( struct slap_op *op, struct berval *ndn,
399 ObjectClass *oc, AttributeDescription *at, int rw, Entry **e )
401 relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
407 bd = select_backend( &op->o_req_ndn, 0, 1 );
413 if ( bd->be_fetch ) {
414 BackendDB *be = op->o_bd;
417 rc = ( bd->be_fetch )( op, ndn, oc, at, rw, e );
426 relay_back_chk_referrals( struct slap_op *op, struct slap_rep *rs )
428 relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
434 bd = select_backend( &op->o_req_ndn, 0, 1 );
440 if ( bd->be_chk_referrals ) {
441 BackendDB *be = op->o_bd;
444 rc = ( bd->be_chk_referrals )( op, rs );
453 relay_back_operational( struct slap_op *op, struct slap_rep *rs,
454 int opattrs, Attribute **ap )
456 relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
462 bd = select_backend( &op->o_req_ndn, 0, 1 );
468 if ( bd->be_operational ) {
469 BackendDB *be = op->o_bd;
472 rc = ( bd->be_operational )( op, rs, opattrs, ap );
481 relay_back_has_subordinates( struct slap_op *op, Entry *e, int *hasSubs )
483 relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
489 bd = select_backend( &op->o_req_ndn, 0, 1 );
495 if ( bd->be_has_subordinates ) {
496 BackendDB *be = op->o_bd;
499 rc = ( bd->be_has_subordinates )( op, e, hasSubs );
508 relay_back_connection_init( BackendDB *bd, struct slap_conn *c )
510 relay_back_info *ri = (relay_back_info *)bd->be_private;
512 if ( ri->ri_bd->be_connection_init ) {
513 return ( ri->ri_bd->be_connection_init )( ri->ri_bd, c );
521 relay_back_connection_destroy( BackendDB *bd, struct slap_conn *c )
523 relay_back_info *ri = (relay_back_info *)bd->be_private;
525 if ( ri->ri_bd->be_connection_destroy ) {
526 return ( ri->ri_bd->be_connection_destroy )( ri->ri_bd, c );
534 * FIXME: must implement tools as well