2000-09-28 07:25:15 +08:00
|
|
|
/* referral.c - BDB backend referral handler */
|
2000-09-26 11:47:56 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/*
|
2003-01-04 04:20:47 +08:00
|
|
|
* Copyright 2000-2003 The OpenLDAP Foundation, All Rights Reserved.
|
2000-09-26 11:47:56 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
|
|
|
#include "back-bdb.h"
|
2000-09-26 13:33:37 +08:00
|
|
|
#include "external.h"
|
2000-09-26 11:47:56 +08:00
|
|
|
|
|
|
|
int
|
2003-03-30 17:03:54 +08:00
|
|
|
bdb_referrals( Operation *op, SlapReply *rs )
|
2000-09-26 11:47:56 +08:00
|
|
|
{
|
2003-03-30 17:03:54 +08:00
|
|
|
struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
|
2002-04-30 00:42:41 +08:00
|
|
|
Entry *e = NULL;
|
|
|
|
Entry *matched = NULL;
|
2003-03-30 17:03:54 +08:00
|
|
|
int rc = LDAP_SUCCESS;
|
2000-09-26 11:47:56 +08:00
|
|
|
|
2002-06-01 04:49:19 +08:00
|
|
|
u_int32_t locker;
|
|
|
|
DB_LOCK lock;
|
|
|
|
|
2000-09-26 11:47:56 +08: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;
|
|
|
|
}
|
|
|
|
|
2002-08-20 11:10:08 +08:00
|
|
|
rc = LOCK_ID(bdb->bi_dbenv, &locker);
|
|
|
|
switch(rc) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return LDAP_OTHER;
|
|
|
|
}
|
2002-06-01 04:49:19 +08:00
|
|
|
|
|
|
|
dn2entry_retry:
|
2000-09-28 06:28:59 +08:00
|
|
|
/* get entry */
|
2003-03-30 17:03:54 +08:00
|
|
|
rc = bdb_dn2entry_r( op->o_bd, NULL, &op->o_req_ndn, &e, &matched, 0, locker, &lock );
|
2000-09-26 11:47:56 +08:00
|
|
|
|
|
|
|
switch(rc) {
|
|
|
|
case DB_NOTFOUND:
|
2001-11-05 14:24:11 +08:00
|
|
|
rc = 0;
|
2000-09-26 11:47:56 +08:00
|
|
|
case 0:
|
|
|
|
break;
|
2002-04-20 05:41:32 +08:00
|
|
|
case LDAP_BUSY:
|
|
|
|
if (e != NULL) {
|
2002-06-01 04:49:19 +08:00
|
|
|
bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
|
2002-04-20 05:41:32 +08:00
|
|
|
}
|
|
|
|
if (matched != NULL) {
|
2002-06-01 04:49:19 +08:00
|
|
|
bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, matched, &lock);
|
2002-04-20 05:41:32 +08:00
|
|
|
}
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_BUSY, "ldap server busy" );
|
2002-06-01 04:49:19 +08:00
|
|
|
LOCK_ID_FREE ( bdb->bi_dbenv, locker );
|
2002-04-20 05:41:32 +08:00
|
|
|
return LDAP_BUSY;
|
2002-06-01 04:49:19 +08:00
|
|
|
case DB_LOCK_DEADLOCK:
|
|
|
|
case DB_LOCK_NOTGRANTED:
|
|
|
|
goto dn2entry_retry;
|
2000-09-26 11:47:56 +08:00
|
|
|
default:
|
2002-03-27 06:17:08 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG ( OPERATION, ERR,
|
|
|
|
"bdb_referrals: dn2entry failed: %s (%d)\n",
|
|
|
|
db_strerror(rc), rc, 0 );
|
2002-03-27 06:17:08 +08:00
|
|
|
#else
|
2000-09-28 07:25:15 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"bdb_referrals: dn2entry failed: %s (%d)\n",
|
|
|
|
db_strerror(rc), rc, 0 );
|
2002-03-27 06:17:08 +08:00
|
|
|
#endif
|
2002-01-25 15:19:01 +08:00
|
|
|
if (e != NULL) {
|
2002-06-01 04:49:19 +08:00
|
|
|
bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
|
2002-01-25 15:19:01 +08:00
|
|
|
}
|
|
|
|
if (matched != NULL) {
|
2002-06-01 04:49:19 +08:00
|
|
|
bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, matched, &lock);
|
2002-01-25 15:19:01 +08:00
|
|
|
}
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
|
2002-06-01 04:49:19 +08:00
|
|
|
LOCK_ID_FREE ( bdb->bi_dbenv, locker );
|
2003-03-30 17:03:54 +08:00
|
|
|
return rs->sr_err;
|
2000-09-26 11:47:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( e == NULL ) {
|
|
|
|
if ( matched != NULL ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_matched = ch_strdup( matched->e_name.bv_val );
|
2000-09-26 11:47:56 +08:00
|
|
|
|
2002-03-27 06:17:08 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG ( OPERATION, DETAIL1,
|
2002-03-27 06:17:08 +08:00
|
|
|
"bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
|
2003-03-30 17:03:54 +08:00
|
|
|
(long) op->o_tag, op->o_req_dn.bv_val, rs->sr_matched );
|
2002-03-27 06:17:08 +08:00
|
|
|
#else
|
2000-09-26 11:47:56 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2000-09-28 07:25:15 +08:00
|
|
|
"bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
|
2003-03-30 17:03:54 +08:00
|
|
|
(long) op->o_tag, op->o_req_dn.bv_val, rs->sr_matched );
|
2002-03-27 06:17:08 +08:00
|
|
|
#endif
|
2000-09-26 11:47:56 +08:00
|
|
|
|
2001-11-05 14:24:11 +08:00
|
|
|
if( is_entry_referral( matched ) ) {
|
|
|
|
rc = LDAP_OTHER;
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_ref = get_entry_referrals( op, matched );
|
2001-11-05 14:24:11 +08:00
|
|
|
}
|
2000-09-26 11:47:56 +08:00
|
|
|
|
2002-06-01 04:49:19 +08:00
|
|
|
bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache, matched, &lock);
|
2000-09-28 10:27:49 +08:00
|
|
|
matched = NULL;
|
2001-11-05 14:24:11 +08:00
|
|
|
} else if ( default_referral != NULL ) {
|
|
|
|
rc = LDAP_OTHER;
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_ref = referral_rewrite( default_referral,
|
|
|
|
NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
|
2000-09-26 11:47:56 +08:00
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
if( rs->sr_ref != NULL ) {
|
2000-09-26 11:47:56 +08:00
|
|
|
/* send referrals */
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = LDAP_REFERRAL;
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
ber_bvarray_free( rs->sr_ref );
|
|
|
|
rs->sr_ref = NULL;
|
2001-11-05 14:24:11 +08:00
|
|
|
} else if ( rc != LDAP_SUCCESS ) {
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_err = rc;
|
|
|
|
rs->sr_text = rs->sr_matched ? "bad referral object" : NULL;
|
|
|
|
send_ldap_result( op, rs );
|
2000-09-26 11:47:56 +08:00
|
|
|
}
|
|
|
|
|
2002-06-01 04:49:19 +08:00
|
|
|
LOCK_ID_FREE ( bdb->bi_dbenv, locker );
|
2003-03-30 17:03:54 +08:00
|
|
|
free( (char *)rs->sr_matched );
|
|
|
|
rs->sr_matched = NULL;
|
2000-09-26 11:47:56 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( is_entry_referral( e ) ) {
|
|
|
|
/* entry is a referral */
|
2003-03-30 17:03:54 +08: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-26 11:47:56 +08:00
|
|
|
|
2002-03-27 06:17:08 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG ( OPERATION, DETAIL1,
|
2002-03-27 06:17:08 +08:00
|
|
|
"bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
|
2003-03-30 17:03:54 +08:00
|
|
|
(long) op->o_tag, op->o_req_dn.bv_val, e->e_dn );
|
2002-03-27 06:17:08 +08:00
|
|
|
#else
|
2000-09-26 11:47:56 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2000-09-28 07:25:15 +08:00
|
|
|
"bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
|
2003-03-30 17:03:54 +08:00
|
|
|
(long) op->o_tag, op->o_req_dn.bv_val, e->e_dn );
|
2002-03-27 06:17:08 +08:00
|
|
|
#endif
|
2000-09-26 11:47:56 +08:00
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_matched = e->e_name.bv_val;
|
|
|
|
if( rs->sr_ref != NULL ) {
|
|
|
|
rs->sr_err = LDAP_REFERRAL;
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
ber_bvarray_free( rs->sr_ref );
|
|
|
|
rs->sr_ref = NULL;
|
2001-11-05 14:24:11 +08:00
|
|
|
} else {
|
2003-03-30 17:03:54 +08:00
|
|
|
send_ldap_error( op, rs, LDAP_OTHER, "bad referral object" );
|
|
|
|
rc = rs->sr_err;
|
2000-09-26 11:47:56 +08:00
|
|
|
}
|
|
|
|
|
2003-03-30 17:03:54 +08:00
|
|
|
rs->sr_matched = NULL;
|
2002-01-14 09:43:17 +08:00
|
|
|
ber_bvarray_free( refs );
|
2000-09-26 11:47:56 +08:00
|
|
|
}
|
|
|
|
|
2002-06-01 04:49:19 +08:00
|
|
|
bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
|
|
|
|
LOCK_ID_FREE ( bdb->bi_dbenv, locker );
|
2000-09-26 11:47:56 +08:00
|
|
|
return rc;
|
|
|
|
}
|