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 );
48 LDAP_LOG (( "referral", LDAP_LEVEL_ERR,
49 "bdb_referrals: dn2entry failed: %s (%d)\n",
50 db_strerror(rc), rc ));
52 Debug( LDAP_DEBUG_TRACE,
53 "bdb_referrals: dn2entry failed: %s (%d)\n",
54 db_strerror(rc), rc, 0 );
57 bdb_cache_return_entry_r(&bdb->bi_cache, e);
59 if (matched != NULL) {
60 bdb_cache_return_entry_r(&bdb->bi_cache, matched);
62 send_ldap_result( conn, op, rc=LDAP_OTHER,
63 NULL, "internal error", NULL, NULL );
68 char *matched_dn = NULL;
69 BerVarray refs = NULL;
71 if ( matched != NULL ) {
72 matched_dn = ch_strdup( matched->e_dn );
75 LDAP_LOG (( "referral", LDAP_LEVEL_DETAIL1,
76 "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
77 (long) op->o_tag, dn->bv_val, matched_dn ));
79 Debug( LDAP_DEBUG_TRACE,
80 "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
81 (long) op->o_tag, dn->bv_val, matched_dn );
84 if( is_entry_referral( matched ) ) {
86 refs = get_entry_referrals( be, conn, op, matched );
89 bdb_cache_return_entry_r (&bdb->bi_cache, matched);
91 } else if ( default_referral != NULL ) {
93 refs = referral_rewrite( default_referral,
94 NULL, dn, LDAP_SCOPE_DEFAULT );
99 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
100 matched_dn, NULL, refs, NULL );
101 ber_bvarray_free( refs );
102 } else if ( rc != LDAP_SUCCESS ) {
103 send_ldap_result( conn, op, rc, matched_dn,
104 matched_dn ? "bad referral object" : NULL,
112 if ( is_entry_referral( e ) ) {
113 /* entry is a referral */
114 BerVarray refs = get_entry_referrals( be, conn, op, e );
115 BerVarray rrefs = referral_rewrite(
116 refs, &e->e_name, dn, LDAP_SCOPE_DEFAULT );
119 LDAP_LOG (( "referral", LDAP_LEVEL_DETAIL1,
120 "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
121 (long) op->o_tag, dn->bv_val, e->e_dn ));
123 Debug( LDAP_DEBUG_TRACE,
124 "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
125 (long) op->o_tag, dn->bv_val, e->e_dn );
128 if( rrefs != NULL ) {
129 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
130 e->e_dn, NULL, rrefs, NULL );
131 ber_bvarray_free( rrefs );
133 send_ldap_result( conn, op, rc = LDAP_OTHER, e->e_dn,
134 "bad referral object", NULL, NULL );
137 ber_bvarray_free( refs );
140 bdb_cache_return_entry_r(&bdb->bi_cache, e);