1 /* referral.c - LDBM backend referral handler */
4 * Copyright 2000-2003 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/string.h>
13 #include <ac/socket.h>
16 #include "back-ldbm.h"
27 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
28 int rc = LDAP_SUCCESS;
31 if( op->o_tag == LDAP_REQ_SEARCH ) {
32 /* let search take care of itself */
36 if( get_manageDSAit( op ) ) {
37 /* let op take care of DSA management */
41 /* grab giant lock for reading */
42 ldap_pvt_thread_rdwr_rlock(&li->li_giant_rwlock);
44 /* get entry with reader lock */
45 e = dn2entry_r( be, ndn, &matched );
47 char *matched_dn = NULL;
48 BerVarray refs = NULL;
50 if ( matched != NULL ) {
51 matched_dn = ch_strdup( matched->e_dn );
54 LDAP_LOG( BACK_LDBM, DETAIL1,
55 "ldbm_back_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
56 op->o_tag, dn->bv_val, matched_dn );
58 Debug( LDAP_DEBUG_TRACE,
59 "ldbm_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
60 op->o_tag, dn->bv_val, matched_dn );
63 if( is_entry_referral( matched ) ) {
65 refs = get_entry_referrals( be, conn, op, matched );
68 cache_return_entry_r( &li->li_cache, matched );
70 } else if ( default_referral != NULL ) {
72 refs = referral_rewrite( default_referral,
73 NULL, dn, LDAP_SCOPE_DEFAULT );
76 ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);
80 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
81 matched_dn, NULL, refs, NULL );
82 ber_bvarray_free( refs );
84 } else if ( rc != LDAP_SUCCESS ) {
85 send_ldap_result( conn, op, rc, matched_dn,
86 matched_dn ? "bad referral object" : "bad default referral",
90 if ( matched_dn ) free( matched_dn );
94 if ( is_entry_referral( e ) ) {
95 /* entry is a referral */
96 BerVarray refs = get_entry_referrals( be, conn, op, e );
97 BerVarray rrefs = referral_rewrite(
98 refs, &e->e_name, dn, LDAP_SCOPE_DEFAULT );
101 LDAP_LOG( BACK_LDBM, DETAIL1,
102 "ldbm_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
103 op->o_tag, dn->bv_val, e->e_dn );
105 Debug( LDAP_DEBUG_TRACE,
106 "ldbm_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
107 op->o_tag, dn->bv_val, e->e_dn );
110 if( rrefs != NULL ) {
111 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
112 e->e_dn, NULL, rrefs, NULL );
114 ber_bvarray_free( rrefs );
117 send_ldap_result( conn, op, rc = LDAP_OTHER, e->e_dn,
118 "bad referral object", NULL, NULL );
121 if( refs != NULL ) ber_bvarray_free( refs );
124 cache_return_entry_r( &li->li_cache, e );
125 ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);