/* referral.c - LDBM backend referral handler */
/* $OpenLDAP$ */
-/*
- * Copyright 2000 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2005 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
*/
#include "portable.h"
int
ldbm_back_referrals(
- Backend *be,
- Connection *conn,
Operation *op,
- const char *dn,
- const char *ndn,
- const char **text )
+ SlapReply *rs )
{
- struct ldbminfo *li = (struct ldbminfo *) be->be_private;
- int rc = LDAP_SUCCESS;
- Entry *e, *matched;
+ struct ldbminfo *li = (struct ldbminfo *) op->o_bd->be_private;
+ Entry *e, *matched;
+ int rc = LDAP_SUCCESS;
if( op->o_tag == LDAP_REQ_SEARCH ) {
/* let search take care of itself */
- return rc;
+ return LDAP_SUCCESS;
}
if( get_manageDSAit( op ) ) {
/* let op take care of DSA management */
- return rc;
+ return LDAP_SUCCESS;
}
+ /* grab giant lock for reading */
+ ldap_pvt_thread_rdwr_rlock(&li->li_giant_rwlock);
+
/* get entry with reader lock */
- e = dn2entry_r( be, ndn, &matched );
+ e = dn2entry_r( op->o_bd, &op->o_req_ndn, &matched );
if ( e == NULL ) {
- char *matched_dn = NULL;
- struct berval **refs = default_referral;
-
if ( matched != NULL ) {
- matched_dn = ch_strdup( matched->e_dn );
+ rs->sr_matched = ch_strdup( matched->e_dn );
Debug( LDAP_DEBUG_TRACE,
"ldbm_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
- op->o_tag, dn, matched_dn );
+ op->o_tag, op->o_req_dn.bv_val, rs->sr_matched );
- refs = is_entry_referral( matched )
- ? get_entry_referrals( be, conn, op, matched )
- : NULL;
+ if ( is_entry_referral( matched ) ) {
+ rc = rs->sr_err = LDAP_OTHER;
+ rs->sr_ref = get_entry_referrals( op, matched );
+ }
cache_return_entry_r( &li->li_cache, matched );
+
+ } else if ( default_referral != NULL ) {
+ rs->sr_ref = referral_rewrite( default_referral,
+ NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
}
- if( refs != NULL ) {
+ ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);
+
+ if ( rs->sr_ref != NULL ) {
/* send referrals */
- send_ldap_result( conn, op, rc = LDAP_REFERRAL,
- matched_dn, NULL, refs, NULL );
- }
+ rc = rs->sr_err = LDAP_REFERRAL;
- if( matched != NULL ) {
- ber_bvecfree( refs );
- free( matched_dn );
+ } else {
+ rs->sr_text = rs->sr_matched ? "bad referral object" : "bad default referral";
}
+ send_ldap_result( op, rs );
+
+ if ( rs->sr_matched ) free( (char *)rs->sr_matched );
+ if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
+ rs->sr_text = NULL;
+ rs->sr_ref = NULL;
+ rs->sr_matched = NULL;
+
return rc;
}
if ( is_entry_referral( e ) ) {
/* entry is a referral */
- struct berval **refs = get_entry_referrals( be,
- conn, op, e );
+ BerVarray refs = get_entry_referrals( op, e );
+ rs->sr_ref = referral_rewrite(
+ refs, &e->e_name, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
Debug( LDAP_DEBUG_TRACE,
"ldbm_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
- op->o_tag, dn, e->e_dn );
+ op->o_tag, op->o_req_dn.bv_val, e->e_dn );
- if( refs != NULL ) {
- send_ldap_result( conn, op, rc = LDAP_REFERRAL,
- e->e_dn, NULL, refs, NULL );
+ rs->sr_matched = e->e_name.bv_val;
+ if( rs->sr_ref != NULL ) {
+ rc = rs->sr_err = LDAP_REFERRAL;
+ rs->sr_text = NULL;
+
+ } else {
+ rc = rs->sr_err = LDAP_OTHER;
+ rs->sr_text = "bad referral object";
}
+ send_ldap_result( op, rs );
- ber_bvecfree( refs );
+ if ( refs != NULL ) ber_bvarray_free( refs );
+ rs->sr_err = rc;
+ rs->sr_ref = NULL;
+ rs->sr_text = NULL;
+ rs->sr_matched = NULL;
}
cache_return_entry_r( &li->li_cache, e );
+ ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);
+
return rc;
}