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 ) {
79 rs->sr_matched = ch_strdup( e->e_name.bv_val );
82 LDAP_LOG ( OPERATION, DETAIL1,
83 "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
84 (long) op->o_tag, op->o_req_dn.bv_val, rs->sr_matched );
86 Debug( LDAP_DEBUG_TRACE,
87 "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
88 (long) op->o_tag, op->o_req_dn.bv_val, rs->sr_matched );
91 if( is_entry_referral( e ) ) {
93 rs->sr_ref = get_entry_referrals( op, e );
96 bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
98 } else if ( default_referral != NULL ) {
100 rs->sr_ref = referral_rewrite( default_referral,
101 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
104 if( rs->sr_ref != NULL ) {
106 rs->sr_err = LDAP_REFERRAL;
107 send_ldap_result( op, rs );
108 ber_bvarray_free( rs->sr_ref );
110 } else if ( rc != LDAP_SUCCESS ) {
112 rs->sr_text = rs->sr_matched ? "bad referral object" : NULL;
113 send_ldap_result( op, rs );
116 LOCK_ID_FREE ( bdb->bi_dbenv, locker );
117 free( (char *)rs->sr_matched );
118 rs->sr_matched = NULL;
122 if ( is_entry_referral( e ) ) {
123 /* entry is a referral */
124 BerVarray refs = get_entry_referrals( op, e );
125 rs->sr_ref = referral_rewrite(
126 refs, &e->e_name, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
129 LDAP_LOG ( OPERATION, DETAIL1,
130 "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
131 (long) op->o_tag, op->o_req_dn.bv_val, e->e_dn );
133 Debug( LDAP_DEBUG_TRACE,
134 "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
135 (long) op->o_tag, op->o_req_dn.bv_val, e->e_dn );
138 rs->sr_matched = e->e_name.bv_val;
139 if( rs->sr_ref != NULL ) {
140 rs->sr_err = LDAP_REFERRAL;
141 send_ldap_result( op, rs );
142 ber_bvarray_free( rs->sr_ref );
145 send_ldap_error( op, rs, LDAP_OTHER, "bad referral object" );
149 rs->sr_matched = NULL;
150 ber_bvarray_free( refs );
153 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
154 LOCK_ID_FREE ( bdb->bi_dbenv, locker );