1 /* referral.c - BDB backend referral handler */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2004 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
19 #include <ac/string.h>
25 bdb_referrals( Operation *op, SlapReply *rs )
27 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
30 int rc = LDAP_SUCCESS;
35 if( op->o_tag == LDAP_REQ_SEARCH ) {
36 /* let search take care of itself */
40 if( get_manageDSAit( op ) ) {
41 /* let op take care of DSA management */
45 rc = LOCK_ID(bdb->bi_dbenv, &locker);
55 rc = bdb_dn2entry( op, NULL, &op->o_req_ndn, &ei, 1, locker, &lock );
63 send_ldap_error( op, rs, LDAP_BUSY, "ldap server busy" );
64 LOCK_ID_FREE ( bdb->bi_dbenv, locker );
66 case DB_LOCK_DEADLOCK:
67 case DB_LOCK_NOTGRANTED:
70 Debug( LDAP_DEBUG_TRACE,
71 "bdb_referrals: dn2entry failed: %s (%d)\n",
72 db_strerror(rc), rc, 0 );
73 send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
74 LOCK_ID_FREE ( bdb->bi_dbenv, locker );
78 if ( rc == DB_NOTFOUND ) {
80 rs->sr_matched = NULL;
82 Debug( LDAP_DEBUG_TRACE,
83 "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
84 (long) op->o_tag, op->o_req_dn.bv_val, e->e_name.bv_val );
86 if( is_entry_referral( e ) ) {
88 rs->sr_ref = get_entry_referrals( op, e );
90 rs->sr_matched = ber_strdup_x(
91 e->e_name.bv_val, op->o_tmpmemctx );
95 bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
97 } else if ( default_referral != NULL ) {
99 rs->sr_ref = referral_rewrite( default_referral,
100 NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
103 if( rs->sr_ref != NULL ) {
105 rs->sr_err = LDAP_REFERRAL;
106 send_ldap_result( op, rs );
107 ber_bvarray_free( rs->sr_ref );
109 } else if ( rc != LDAP_SUCCESS ) {
111 rs->sr_text = rs->sr_matched ? "bad referral object" : NULL;
112 send_ldap_result( op, rs );
115 LOCK_ID_FREE ( bdb->bi_dbenv, locker );
116 if (rs->sr_matched) {
117 op->o_tmpfree( (char *)rs->sr_matched, op->o_tmpmemctx );
118 rs->sr_matched = NULL;
123 if ( is_entry_referral( e ) ) {
124 /* entry is a referral */
125 BerVarray refs = get_entry_referrals( op, e );
126 rs->sr_ref = referral_rewrite(
127 refs, &e->e_name, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
129 Debug( LDAP_DEBUG_TRACE,
130 "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
131 (long) op->o_tag, op->o_req_dn.bv_val, e->e_name.bv_val );
133 rs->sr_matched = e->e_name.bv_val;
134 if( rs->sr_ref != NULL ) {
135 rc = rs->sr_err = LDAP_REFERRAL;
136 send_ldap_result( op, rs );
137 ber_bvarray_free( rs->sr_ref );
140 send_ldap_error( op, rs, LDAP_OTHER, "bad referral object" );
144 rs->sr_matched = NULL;
145 ber_bvarray_free( refs );
148 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
149 LOCK_ID_FREE ( bdb->bi_dbenv, locker );