1 /* referral.c - BDB backend referral handler */
4 * Copyright 2000-2003 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 #include <ac/string.h>
16 bdb_referrals( Operation *op, SlapReply *rs )
18 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
21 int rc = LDAP_SUCCESS;
26 if( op->o_tag == LDAP_REQ_SEARCH ) {
27 /* let search take care of itself */
31 if( get_manageDSAit( op ) ) {
32 /* let op take care of DSA management */
36 rc = LOCK_ID(bdb->bi_dbenv, &locker);
46 rc = bdb_dn2entry( op->o_bd, NULL, &op->o_req_ndn, &ei, 1, locker,
47 &lock, op->o_tmpmemctx );
55 send_ldap_error( op, rs, LDAP_BUSY, "ldap server busy" );
56 LOCK_ID_FREE ( bdb->bi_dbenv, locker );
58 case DB_LOCK_DEADLOCK:
59 case DB_LOCK_NOTGRANTED:
63 LDAP_LOG ( OPERATION, ERR,
64 "bdb_referrals: dn2entry failed: %s (%d)\n",
65 db_strerror(rc), rc, 0 );
67 Debug( LDAP_DEBUG_TRACE,
68 "bdb_referrals: dn2entry failed: %s (%d)\n",
69 db_strerror(rc), rc, 0 );
71 send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
72 LOCK_ID_FREE ( bdb->bi_dbenv, locker );
76 if ( rc == DB_NOTFOUND ) {
78 rs->sr_matched = NULL;
81 LDAP_LOG ( OPERATION, DETAIL1,
82 "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
83 (long) op->o_tag, op->o_req_dn.bv_val, rs->sr_matched );
85 Debug( LDAP_DEBUG_TRACE,
86 "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
87 (long) op->o_tag, op->o_req_dn.bv_val, rs->sr_matched );
90 if( is_entry_referral( e ) ) {
92 rs->sr_ref = get_entry_referrals( op, e );
94 rs->sr_matched = ber_strdup_x(
95 e->e_name.bv_val, op->o_tmpmemctx );
99 bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
101 } else if ( default_referral != NULL ) {
103 rs->sr_ref = referral_rewrite( default_referral,
104 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
107 if( rs->sr_ref != NULL ) {
109 rs->sr_err = LDAP_REFERRAL;
110 send_ldap_result( op, rs );
111 ber_bvarray_free( rs->sr_ref );
113 } else if ( rc != LDAP_SUCCESS ) {
115 rs->sr_text = rs->sr_matched ? "bad referral object" : NULL;
116 send_ldap_result( op, rs );
119 LOCK_ID_FREE ( bdb->bi_dbenv, locker );
120 if (rs->sr_matched) {
121 sl_free( (char *)rs->sr_matched, op->o_tmpmemctx );
122 rs->sr_matched = NULL;
127 if ( is_entry_referral( e ) ) {
128 /* entry is a referral */
129 BerVarray refs = get_entry_referrals( op, e );
130 rs->sr_ref = referral_rewrite(
131 refs, &e->e_name, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
134 LDAP_LOG ( OPERATION, DETAIL1,
135 "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
136 (long) op->o_tag, op->o_req_dn.bv_val, e->e_dn );
138 Debug( LDAP_DEBUG_TRACE,
139 "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
140 (long) op->o_tag, op->o_req_dn.bv_val, e->e_dn );
143 rs->sr_matched = e->e_name.bv_val;
144 if( rs->sr_ref != NULL ) {
145 rs->sr_err = LDAP_REFERRAL;
146 send_ldap_result( op, rs );
147 ber_bvarray_free( rs->sr_ref );
150 send_ldap_error( op, rs, LDAP_OTHER, "bad referral object" );
154 rs->sr_matched = NULL;
155 ber_bvarray_free( refs );
158 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
159 LOCK_ID_FREE ( bdb->bi_dbenv, locker );