2000-09-27 19:25:15 -04:00
|
|
|
/* referral.c - BDB backend referral handler */
|
2000-09-25 23:47:56 -04:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-28 16:08:20 -05:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
|
*
|
2009-01-21 19:40:04 -05:00
|
|
|
* Copyright 2000-2009 The OpenLDAP Foundation.
|
2003-11-28 16:08:20 -05:00
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
|
* Public License.
|
|
|
|
|
*
|
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
2000-09-25 23:47:56 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
|
|
|
|
|
#include "back-bdb.h"
|
|
|
|
|
|
|
|
|
|
int
|
2003-03-30 04:03:54 -05:00
|
|
|
bdb_referrals( Operation *op, SlapReply *rs )
|
2000-09-25 23:47:56 -04:00
|
|
|
{
|
2003-03-30 04:03:54 -05:00
|
|
|
struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
|
2002-04-29 12:42:41 -04:00
|
|
|
Entry *e = NULL;
|
2003-04-16 12:23:36 -04:00
|
|
|
EntryInfo *ei;
|
2003-03-30 04:03:54 -05:00
|
|
|
int rc = LDAP_SUCCESS;
|
2000-09-25 23:47:56 -04:00
|
|
|
|
2008-08-26 21:45:35 -04:00
|
|
|
DB_TXN *rtxn;
|
2002-05-31 16:49:19 -04:00
|
|
|
DB_LOCK lock;
|
|
|
|
|
|
2000-09-25 23:47:56 -04:00
|
|
|
if( op->o_tag == LDAP_REQ_SEARCH ) {
|
|
|
|
|
/* let search take care of itself */
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( get_manageDSAit( op ) ) {
|
|
|
|
|
/* let op take care of DSA management */
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-26 21:45:35 -04:00
|
|
|
rc = bdb_reader_get(op, bdb->bi_dbenv, &rtxn);
|
2002-08-19 23:10:08 -04:00
|
|
|
switch(rc) {
|
|
|
|
|
case 0:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return LDAP_OTHER;
|
|
|
|
|
}
|
2002-05-31 16:49:19 -04:00
|
|
|
|
|
|
|
|
dn2entry_retry:
|
2000-09-27 18:28:59 -04:00
|
|
|
/* get entry */
|
2008-08-26 21:45:35 -04:00
|
|
|
rc = bdb_dn2entry( op, rtxn, &op->o_req_ndn, &ei, 1, &lock );
|
2000-09-25 23:47:56 -04:00
|
|
|
|
2005-03-15 18:01:06 -05:00
|
|
|
/* bdb_dn2entry() may legally leave ei == NULL
|
|
|
|
|
* if rc != 0 and rc != DB_NOTFOUND
|
|
|
|
|
*/
|
|
|
|
|
if ( ei ) {
|
|
|
|
|
e = ei->bei_e;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-25 23:47:56 -04:00
|
|
|
switch(rc) {
|
|
|
|
|
case DB_NOTFOUND:
|
|
|
|
|
case 0:
|
|
|
|
|
break;
|
2002-04-19 17:41:32 -04:00
|
|
|
case LDAP_BUSY:
|
2008-02-11 15:59:40 -05:00
|
|
|
rs->sr_text = "ldap server busy";
|
2002-04-19 17:41:32 -04:00
|
|
|
return LDAP_BUSY;
|
2002-05-31 16:49:19 -04:00
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
|
goto dn2entry_retry;
|
2000-09-25 23:47:56 -04:00
|
|
|
default:
|
2000-09-27 19:25:15 -04:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2004-11-17 09:53:03 -05:00
|
|
|
LDAP_XSTRING(bdb_referrals)
|
|
|
|
|
": dn2entry failed: %s (%d)\n",
|
2000-09-27 19:25:15 -04:00
|
|
|
db_strerror(rc), rc, 0 );
|
2008-02-11 15:59:40 -05:00
|
|
|
rs->sr_text = "internal error";
|
|
|
|
|
return LDAP_OTHER;
|
2000-09-25 23:47:56 -04:00
|
|
|
}
|
|
|
|
|
|
2003-04-16 12:23:36 -04:00
|
|
|
if ( rc == DB_NOTFOUND ) {
|
2008-02-11 15:59:40 -05:00
|
|
|
rc = LDAP_SUCCESS;
|
2003-04-21 14:28:38 -04:00
|
|
|
rs->sr_matched = NULL;
|
2003-04-16 12:23:36 -04:00
|
|
|
if ( e != NULL ) {
|
2000-09-25 23:47:56 -04:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2004-11-17 09:53:03 -05:00
|
|
|
LDAP_XSTRING(bdb_referrals)
|
2007-08-24 20:10:52 -04:00
|
|
|
": tag=%lu target=\"%s\" matched=\"%s\"\n",
|
|
|
|
|
(unsigned long)op->o_tag, op->o_req_dn.bv_val, e->e_name.bv_val );
|
2000-09-25 23:47:56 -04:00
|
|
|
|
2003-04-16 12:23:36 -04:00
|
|
|
if( is_entry_referral( e ) ) {
|
2006-05-15 20:57:46 -04:00
|
|
|
BerVarray ref = get_entry_referrals( op, e );
|
2001-11-05 01:24:11 -05:00
|
|
|
rc = LDAP_OTHER;
|
2008-03-10 15:28:40 -04:00
|
|
|
rs->sr_ref = referral_rewrite( ref, &e->e_name,
|
2006-05-15 20:57:46 -04:00
|
|
|
&op->o_req_dn, LDAP_SCOPE_DEFAULT );
|
|
|
|
|
ber_bvarray_free( ref );
|
2003-04-21 14:28:38 -04:00
|
|
|
if ( rs->sr_ref ) {
|
|
|
|
|
rs->sr_matched = ber_strdup_x(
|
|
|
|
|
e->e_name.bv_val, op->o_tmpmemctx );
|
|
|
|
|
}
|
2001-11-05 01:24:11 -05:00
|
|
|
}
|
2000-09-25 23:47:56 -04:00
|
|
|
|
2006-12-31 18:37:06 -05:00
|
|
|
bdb_cache_return_entry_r (bdb, e, &lock);
|
2003-04-16 12:23:36 -04:00
|
|
|
e = NULL;
|
2000-09-25 23:47:56 -04:00
|
|
|
}
|
|
|
|
|
|
2003-03-30 04:03:54 -05:00
|
|
|
if( rs->sr_ref != NULL ) {
|
2000-09-25 23:47:56 -04:00
|
|
|
/* send referrals */
|
2005-01-10 19:38:04 -05:00
|
|
|
rc = rs->sr_err = LDAP_REFERRAL;
|
2003-03-30 04:03:54 -05:00
|
|
|
send_ldap_result( op, rs );
|
|
|
|
|
ber_bvarray_free( rs->sr_ref );
|
|
|
|
|
rs->sr_ref = NULL;
|
2001-11-05 01:24:11 -05:00
|
|
|
} else if ( rc != LDAP_SUCCESS ) {
|
2003-03-30 04:03:54 -05:00
|
|
|
rs->sr_text = rs->sr_matched ? "bad referral object" : NULL;
|
2000-09-25 23:47:56 -04:00
|
|
|
}
|
|
|
|
|
|
2003-04-21 14:28:38 -04:00
|
|
|
if (rs->sr_matched) {
|
2003-05-24 20:53:08 -04:00
|
|
|
op->o_tmpfree( (char *)rs->sr_matched, op->o_tmpmemctx );
|
2003-04-21 14:28:38 -04:00
|
|
|
rs->sr_matched = NULL;
|
|
|
|
|
}
|
2000-09-25 23:47:56 -04:00
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( is_entry_referral( e ) ) {
|
|
|
|
|
/* entry is a referral */
|
2003-03-30 04:03:54 -05:00
|
|
|
BerVarray refs = get_entry_referrals( op, e );
|
|
|
|
|
rs->sr_ref = referral_rewrite(
|
|
|
|
|
refs, &e->e_name, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
|
2000-09-25 23:47:56 -04:00
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2004-11-17 09:53:03 -05:00
|
|
|
LDAP_XSTRING(bdb_referrals)
|
2007-08-24 20:10:52 -04:00
|
|
|
": tag=%lu target=\"%s\" matched=\"%s\"\n",
|
|
|
|
|
(unsigned long)op->o_tag, op->o_req_dn.bv_val, e->e_name.bv_val );
|
2000-09-25 23:47:56 -04:00
|
|
|
|
2003-03-30 04:03:54 -05:00
|
|
|
rs->sr_matched = e->e_name.bv_val;
|
|
|
|
|
if( rs->sr_ref != NULL ) {
|
2004-04-05 13:31:27 -04:00
|
|
|
rc = rs->sr_err = LDAP_REFERRAL;
|
2003-03-30 04:03:54 -05:00
|
|
|
send_ldap_result( op, rs );
|
|
|
|
|
ber_bvarray_free( rs->sr_ref );
|
|
|
|
|
rs->sr_ref = NULL;
|
2001-11-05 01:24:11 -05:00
|
|
|
} else {
|
2008-02-11 15:59:40 -05:00
|
|
|
rc = LDAP_OTHER;
|
|
|
|
|
rs->sr_text = "bad referral object";
|
2000-09-25 23:47:56 -04:00
|
|
|
}
|
|
|
|
|
|
2003-03-30 04:03:54 -05:00
|
|
|
rs->sr_matched = NULL;
|
2002-01-13 20:43:17 -05:00
|
|
|
ber_bvarray_free( refs );
|
2000-09-25 23:47:56 -04:00
|
|
|
}
|
|
|
|
|
|
2006-12-31 18:37:06 -05:00
|
|
|
bdb_cache_return_entry_r(bdb, e, &lock);
|
2000-09-25 23:47:56 -04:00
|
|
|
return rc;
|
|
|
|
|
}
|