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;
27 Entry *matched = NULL;
29 if( op->o_tag == LDAP_REQ_SEARCH ) {
30 /* let search take care of itself */
34 if( get_manageDSAit( op ) ) {
35 /* let op take care of DSA management */
40 rc = bdb_dn2entry_r( be, NULL, ndn, &e, &matched, 0 );
49 bdb_cache_return_entry_r(&bdb->bi_cache, e);
51 if (matched != NULL) {
52 bdb_cache_return_entry_r(&bdb->bi_cache, matched);
54 send_ldap_result( conn, op, LDAP_BUSY,
55 NULL, "ldap server busy", NULL, NULL );
59 LDAP_LOG (( "referral", LDAP_LEVEL_ERR,
60 "bdb_referrals: dn2entry failed: %s (%d)\n",
61 db_strerror(rc), rc ));
63 Debug( LDAP_DEBUG_TRACE,
64 "bdb_referrals: dn2entry failed: %s (%d)\n",
65 db_strerror(rc), rc, 0 );
68 bdb_cache_return_entry_r(&bdb->bi_cache, e);
70 if (matched != NULL) {
71 bdb_cache_return_entry_r(&bdb->bi_cache, matched);
73 send_ldap_result( conn, op, rc=LDAP_OTHER,
74 NULL, "internal error", NULL, NULL );
79 char *matched_dn = NULL;
80 BerVarray refs = NULL;
82 if ( matched != NULL ) {
83 matched_dn = ch_strdup( matched->e_dn );
86 LDAP_LOG (( "referral", LDAP_LEVEL_DETAIL1,
87 "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
88 (long) op->o_tag, dn->bv_val, matched_dn ));
90 Debug( LDAP_DEBUG_TRACE,
91 "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
92 (long) op->o_tag, dn->bv_val, matched_dn );
95 if( is_entry_referral( matched ) ) {
97 refs = get_entry_referrals( be, conn, op, matched );
100 bdb_cache_return_entry_r (&bdb->bi_cache, matched);
102 } else if ( default_referral != NULL ) {
104 refs = referral_rewrite( default_referral,
105 NULL, dn, LDAP_SCOPE_DEFAULT );
110 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
111 matched_dn, NULL, refs, NULL );
112 ber_bvarray_free( refs );
113 } else if ( rc != LDAP_SUCCESS ) {
114 send_ldap_result( conn, op, rc, matched_dn,
115 matched_dn ? "bad referral object" : NULL,
123 if ( is_entry_referral( e ) ) {
124 /* entry is a referral */
125 BerVarray refs = get_entry_referrals( be, conn, op, e );
126 BerVarray rrefs = referral_rewrite(
127 refs, &e->e_name, dn, LDAP_SCOPE_DEFAULT );
130 LDAP_LOG (( "referral", LDAP_LEVEL_DETAIL1,
131 "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
132 (long) op->o_tag, dn->bv_val, e->e_dn ));
134 Debug( LDAP_DEBUG_TRACE,
135 "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
136 (long) op->o_tag, dn->bv_val, e->e_dn );
139 if( rrefs != NULL ) {
140 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
141 e->e_dn, NULL, rrefs, NULL );
142 ber_bvarray_free( rrefs );
144 send_ldap_result( conn, op, rc = LDAP_OTHER, e->e_dn,
145 "bad referral object", NULL, NULL );
148 ber_bvarray_free( refs );
151 bdb_cache_return_entry_r(&bdb->bi_cache, e);