if ( strcasecmp( argv[0], "relay" ) == 0 ) {
struct berval dn, ndn, pdn;
int rc;
+ char *cargv[ 4 ];
if (argc != 2) {
fprintf( stderr,
rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
if ( rc != LDAP_SUCCESS ) {
fprintf( stderr, "%s: line %d: "
- "relay dn '%s' is invalid\n",
+ "relay dn \"%s\" is invalid\n",
fname, lineno, argv[ 1 ] );
return 1;
}
if ( ri->ri_bd == NULL ) {
fprintf( stderr, "%s: line %d: "
"cannot find database "
- "of relay dn '%s'\n",
+ "of relay dn \"%s\"\n",
fname, lineno, argv[ 1 ] );
return 1;
- }
-
+
+ } else if ( ri->ri_bd == be ) {
+ fprintf( stderr, "%s: line %d: "
+ "relay dn \"%s\" would call self\n",
+ fname, lineno, pdn.bv_val );
+ return 1;
+ }
+
if ( overlay_config( be, "rewrite-remap" ) ) {
fprintf( stderr, "unable to install "
"rewrite-remap overlay "
be->be_suffix[0].bv_val,
ri->ri_bd->be_suffix[0].bv_val ?
ri->ri_bd->be_suffix[0].bv_val : "<unknown>" );
+ return 1;
+ }
+
+ cargv[ 0 ] = "suffixmassage";
+ cargv[ 1 ] = be->be_suffix[0].bv_val;
+ cargv[ 2 ] = ri->ri_bd->be_suffix[0].bv_val;
+ cargv[ 3 ] = NULL;
+
+ if ( be->be_config( be, "back-relay", 1, 3, cargv ) ) {
+ return 1;
}
/* anything else */
if ( bd == NULL ) {
bd = select_backend( &op->o_req_ndn, 0, 1 );
+ if ( bd == op->o_bd ) {
+ if ( err != LDAP_SUCCESS ) {
+ send_ldap_error( op, rs,
+ LDAP_UNWILLING_TO_PERFORM,
+ "would call self" );
+ }
+ return NULL;
+ }
}
if ( bd == NULL ) {
if ( default_referral ) {
rs->sr_ref = referral_rewrite( default_referral,
NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
- if (!rs->sr_ref) {
+ if ( !rs->sr_ref ) {
rs->sr_ref = default_referral;
}
rs->sr_err = LDAP_REFERRAL;
send_ldap_result( op, rs );
- if (rs->sr_ref != default_referral) {
+ if ( rs->sr_ref != default_referral ) {
ber_bvarray_free( rs->sr_ref );
}
int
relay_back_chk_referrals( struct slap_op *op, struct slap_rep *rs )
{
- relay_back_info *ri = (relay_back_info *)op->o_bd->be_private;
BackendDB *bd;
- int rc = 1;
+ int rc = 0;
- bd = ri->ri_bd;
- if ( bd == NULL) {
- bd = select_backend( &op->o_req_ndn, 0, 1 );
- if ( bd == NULL ) {
- return 1;
- }
+ bd = relay_back_select_backend( op, rs, LDAP_SUCCESS );
+ if ( bd == NULL ) {
+ return 0;
}
if ( bd->be_chk_referrals ) {
{
relay_back_info *ri = (relay_back_info *)bd->be_private;
- if ( ri->ri_bd->be_connection_init ) {
- return ( ri->ri_bd->be_connection_init )( ri->ri_bd, c );
+ bd = ri->ri_bd;
+ if ( bd == NULL ) {
+ return 0;
}
- return 1;
+ if ( bd->be_connection_init ) {
+ return ( bd->be_connection_init )( bd, c );
+ }
+ return 0;
}
int
{
relay_back_info *ri = (relay_back_info *)bd->be_private;
- if ( ri->ri_bd->be_connection_destroy ) {
- return ( ri->ri_bd->be_connection_destroy )( ri->ri_bd, c );
+ bd = ri->ri_bd;
+ if ( bd == NULL) {
+ return 0;
+ }
+
+ if ( bd->be_connection_destroy ) {
+ return ( bd->be_connection_destroy )( bd, c );
}
- return 1;
+ return 0;
}