1 /* referral.c - MDB backend referral handler */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2011 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>
24 mdb_referrals( Operation *op, SlapReply *rs )
26 struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
28 int rc = LDAP_SUCCESS;
31 mdb_op_info opinfo = {0}, *moi = &opinfo;
33 if( op->o_tag == LDAP_REQ_SEARCH ) {
34 /* let search take care of itself */
38 if( get_manageDSAit( op ) ) {
39 /* let op take care of DSA management */
43 rc = mdb_opinfo_get(op, mdb, 1, &moi);
54 rc = mdb_dn2entry( op, rtxn, &op->o_req_ndn, &e, 1 );
61 rs->sr_text = "ldap server busy";
64 Debug( LDAP_DEBUG_TRACE,
65 LDAP_XSTRING(mdb_referrals)
66 ": dn2entry failed: %s (%d)\n",
67 mdb_strerror(rc), rc, 0 );
68 rs->sr_text = "internal error";
73 if ( rc == MDB_NOTFOUND ) {
75 rs->sr_matched = NULL;
77 Debug( LDAP_DEBUG_TRACE,
78 LDAP_XSTRING(mdb_referrals)
79 ": tag=%lu target=\"%s\" matched=\"%s\"\n",
80 (unsigned long)op->o_tag, op->o_req_dn.bv_val, e->e_name.bv_val );
82 if( is_entry_referral( e ) ) {
83 BerVarray ref = get_entry_referrals( op, e );
85 rs->sr_ref = referral_rewrite( ref, &e->e_name,
86 &op->o_req_dn, LDAP_SCOPE_DEFAULT );
87 ber_bvarray_free( ref );
89 rs->sr_matched = ber_strdup_x(
90 e->e_name.bv_val, op->o_tmpmemctx );
94 mdb_entry_return( op, e );
98 if( rs->sr_ref != NULL ) {
100 rc = rs->sr_err = LDAP_REFERRAL;
101 send_ldap_result( op, rs );
102 ber_bvarray_free( rs->sr_ref );
104 } else if ( rc != LDAP_SUCCESS ) {
105 rs->sr_text = rs->sr_matched ? "bad referral object" : NULL;
108 if (rs->sr_matched) {
109 op->o_tmpfree( (char *)rs->sr_matched, op->o_tmpmemctx );
110 rs->sr_matched = NULL;
115 if ( is_entry_referral( e ) ) {
116 /* entry is a referral */
117 BerVarray refs = get_entry_referrals( op, e );
118 rs->sr_ref = referral_rewrite(
119 refs, &e->e_name, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
121 Debug( LDAP_DEBUG_TRACE,
122 LDAP_XSTRING(mdb_referrals)
123 ": tag=%lu target=\"%s\" matched=\"%s\"\n",
124 (unsigned long)op->o_tag, op->o_req_dn.bv_val, e->e_name.bv_val );
126 rs->sr_matched = e->e_name.bv_val;
127 if( rs->sr_ref != NULL ) {
128 rc = rs->sr_err = LDAP_REFERRAL;
129 send_ldap_result( op, rs );
130 ber_bvarray_free( rs->sr_ref );
134 rs->sr_text = "bad referral object";
137 rs->sr_matched = NULL;
138 ber_bvarray_free( refs );
142 if ( moi == &opinfo ) {
143 mdb_txn_reset( moi->moi_txn );
144 LDAP_SLIST_REMOVE( &op->o_extra, &moi->moi_oe, OpExtra, oe_next );
147 mdb_entry_return( op, e );