1 /* referral.c - BDB backend referral handler */
4 * Copyright 2000-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 #include <ac/string.h>
24 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
25 int rc = LDAP_SUCCESS;
26 Entry *e = NULL, *matched;
28 if( op->o_tag == LDAP_REQ_SEARCH ) {
29 /* let search take care of itself */
33 if( get_manageDSAit( op ) ) {
34 /* let op take care of DSA management */
39 rc = bdb_dn2entry_r( be, NULL, ndn, &e, &matched, 0 );
47 Debug( LDAP_DEBUG_TRACE,
48 "bdb_referrals: dn2entry failed: %s (%d)\n",
49 db_strerror(rc), rc, 0 );
51 bdb_cache_return_entry_r(&bdb->bi_cache, e);
53 if (matched != NULL) {
54 bdb_cache_return_entry_r(&bdb->bi_cache, matched);
56 send_ldap_result( conn, op, rc=LDAP_OTHER,
57 NULL, "internal error", NULL, NULL );
62 char *matched_dn = NULL;
63 BerVarray refs = NULL;
65 if ( matched != NULL ) {
66 matched_dn = ch_strdup( matched->e_dn );
68 Debug( LDAP_DEBUG_TRACE,
69 "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
70 (long) op->o_tag, dn->bv_val, matched_dn );
72 if( is_entry_referral( matched ) ) {
74 refs = get_entry_referrals( be, conn, op, matched );
77 bdb_cache_return_entry_r (&bdb->bi_cache, matched);
79 } else if ( default_referral != NULL ) {
81 refs = referral_rewrite( default_referral,
82 NULL, dn, LDAP_SCOPE_DEFAULT );
87 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
88 matched_dn, NULL, refs, NULL );
89 ber_bvarray_free( refs );
90 } else if ( rc != LDAP_SUCCESS ) {
91 send_ldap_result( conn, op, rc, matched_dn,
92 matched_dn ? "bad referral object" : NULL,
100 if ( is_entry_referral( e ) ) {
101 /* entry is a referral */
102 BerVarray refs = get_entry_referrals( be, conn, op, e );
103 BerVarray rrefs = referral_rewrite(
104 refs, &e->e_name, dn, LDAP_SCOPE_DEFAULT );
106 Debug( LDAP_DEBUG_TRACE,
107 "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
108 (long) 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 );
113 ber_bvarray_free( rrefs );
115 send_ldap_result( conn, op, rc = LDAP_OTHER, e->e_dn,
116 "bad referral object", NULL, NULL );
119 ber_bvarray_free( refs );
122 bdb_cache_return_entry_r(&bdb->bi_cache, e);