2000-06-17 15:45:40 +08:00
|
|
|
/* referral.c - LDBM backend referral handler */
|
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/*
|
2002-01-05 05:17:25 +08:00
|
|
|
* Copyright 2000-2002 The OpenLDAP Foundation, All Rights Reserved.
|
2000-06-17 15:45:40 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
#include "back-ldbm.h"
|
|
|
|
|
|
|
|
int
|
|
|
|
ldbm_back_referrals(
|
|
|
|
Backend *be,
|
|
|
|
Connection *conn,
|
|
|
|
Operation *op,
|
2001-12-27 01:40:34 +08:00
|
|
|
struct berval *dn,
|
|
|
|
struct berval *ndn,
|
2000-06-17 15:45:40 +08:00
|
|
|
const char **text )
|
|
|
|
{
|
|
|
|
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
|
|
|
|
int rc = LDAP_SUCCESS;
|
|
|
|
Entry *e, *matched;
|
|
|
|
|
|
|
|
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-01-30 01:58:36 +08:00
|
|
|
/* grab giant lock for reading */
|
|
|
|
ldap_pvt_thread_rdwr_rlock(&li->li_giant_rwlock);
|
|
|
|
|
2000-06-17 15:45:40 +08:00
|
|
|
/* get entry with reader lock */
|
2002-01-01 21:31:20 +08:00
|
|
|
e = dn2entry_r( be, ndn, &matched );
|
2000-06-17 15:45:40 +08:00
|
|
|
if ( e == NULL ) {
|
|
|
|
char *matched_dn = NULL;
|
2002-01-14 09:43:17 +08:00
|
|
|
BerVarray refs = NULL;
|
2000-06-17 15:45:40 +08:00
|
|
|
|
|
|
|
if ( matched != NULL ) {
|
|
|
|
matched_dn = ch_strdup( matched->e_dn );
|
|
|
|
|
2001-01-18 01:01:19 +08:00
|
|
|
#ifdef NEW_LOGGING
|
|
|
|
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
|
2001-10-26 10:05:14 +08:00
|
|
|
"ldbm_back_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
|
2001-12-27 01:40:34 +08:00
|
|
|
op->o_tag, dn->bv_val, matched_dn ));
|
2001-01-18 01:01:19 +08:00
|
|
|
#else
|
2000-06-17 15:45:40 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"ldbm_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
|
2001-12-27 01:40:34 +08:00
|
|
|
op->o_tag, dn->bv_val, matched_dn );
|
2001-01-18 01:01:19 +08:00
|
|
|
#endif
|
|
|
|
|
2001-10-26 10:05:14 +08:00
|
|
|
if( is_entry_referral( matched ) ) {
|
|
|
|
rc = LDAP_OTHER;
|
2001-12-27 04:59:24 +08:00
|
|
|
refs = get_entry_referrals( be, conn, op, matched );
|
2001-10-26 10:05:14 +08:00
|
|
|
}
|
2000-06-17 15:45:40 +08:00
|
|
|
|
|
|
|
cache_return_entry_r( &li->li_cache, matched );
|
2001-10-26 10:05:14 +08:00
|
|
|
|
|
|
|
} else if ( default_referral != NULL ) {
|
|
|
|
rc = LDAP_OTHER;
|
|
|
|
refs = referral_rewrite( default_referral,
|
2001-12-27 04:59:24 +08:00
|
|
|
NULL, dn, LDAP_SCOPE_DEFAULT );
|
2000-06-17 15:45:40 +08:00
|
|
|
}
|
|
|
|
|
2002-01-30 01:58:36 +08:00
|
|
|
ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);
|
|
|
|
|
2000-06-17 15:45:40 +08:00
|
|
|
if( refs != NULL ) {
|
|
|
|
/* send referrals */
|
|
|
|
send_ldap_result( conn, op, rc = LDAP_REFERRAL,
|
|
|
|
matched_dn, NULL, refs, NULL );
|
2002-01-14 09:43:17 +08:00
|
|
|
ber_bvarray_free( refs );
|
2001-10-26 10:05:14 +08:00
|
|
|
|
|
|
|
} else if ( rc != LDAP_SUCCESS ) {
|
|
|
|
send_ldap_result( conn, op, rc, matched_dn,
|
|
|
|
matched_dn ? "bad referral object" : "bad default referral",
|
|
|
|
NULL, NULL );
|
2000-06-17 15:45:40 +08:00
|
|
|
}
|
|
|
|
|
2001-12-31 14:44:36 +08:00
|
|
|
if ( matched_dn ) free( matched_dn );
|
2000-06-17 15:45:40 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( is_entry_referral( e ) ) {
|
|
|
|
/* entry is a referral */
|
2002-01-14 09:43:17 +08:00
|
|
|
BerVarray refs = get_entry_referrals( be, conn, op, e );
|
|
|
|
BerVarray rrefs = referral_rewrite(
|
2001-12-27 04:59:24 +08:00
|
|
|
refs, &e->e_name, dn, LDAP_SCOPE_DEFAULT );
|
2000-06-17 15:45:40 +08:00
|
|
|
|
2001-01-18 01:01:19 +08:00
|
|
|
#ifdef NEW_LOGGING
|
|
|
|
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
|
2001-10-26 10:05:14 +08:00
|
|
|
"ldbm_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
|
2001-12-27 01:40:34 +08:00
|
|
|
op->o_tag, dn->bv_val, e->e_dn ));
|
2001-01-18 01:01:19 +08:00
|
|
|
#else
|
2000-06-17 15:45:40 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"ldbm_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
|
2001-12-27 01:40:34 +08:00
|
|
|
op->o_tag, dn->bv_val, e->e_dn );
|
2001-01-18 01:01:19 +08:00
|
|
|
#endif
|
|
|
|
|
2001-10-26 10:05:14 +08:00
|
|
|
if( rrefs != NULL ) {
|
2000-06-17 15:45:40 +08:00
|
|
|
send_ldap_result( conn, op, rc = LDAP_REFERRAL,
|
2001-10-26 10:05:14 +08:00
|
|
|
e->e_dn, NULL, rrefs, NULL );
|
|
|
|
|
2002-01-14 09:43:17 +08:00
|
|
|
ber_bvarray_free( rrefs );
|
2001-10-26 10:05:14 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
send_ldap_result( conn, op, rc = LDAP_OTHER, e->e_dn,
|
|
|
|
"bad referral object", NULL, NULL );
|
2000-06-17 15:45:40 +08:00
|
|
|
}
|
|
|
|
|
2002-01-14 09:43:17 +08:00
|
|
|
if( refs != NULL ) ber_bvarray_free( refs );
|
2000-06-17 15:45:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cache_return_entry_r( &li->li_cache, e );
|
2002-01-30 01:58:36 +08:00
|
|
|
ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);
|
|
|
|
|
2000-06-17 15:45:40 +08:00
|
|
|
return rc;
|
|
|
|
}
|