2000-09-28 07:25:15 +08:00
|
|
|
/* referral.c - BDB backend referral handler */
|
2000-09-26 11:47:56 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/*
|
|
|
|
* Copyright 2000 The OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
* 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
|
|
|
|
bdb_referrals(
|
2000-09-28 06:28:59 +08:00
|
|
|
BackendDB *be,
|
|
|
|
Connection *conn,
|
|
|
|
Operation *op,
|
|
|
|
const char *dn,
|
|
|
|
const char *ndn,
|
2000-09-26 11:47:56 +08:00
|
|
|
const char **text )
|
|
|
|
{
|
|
|
|
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
|
|
|
|
int rc = LDAP_SUCCESS;
|
2000-09-28 07:25:15 +08:00
|
|
|
Entry *e = NULL, *matched;
|
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;
|
|
|
|
}
|
|
|
|
|
2000-09-28 06:28:59 +08:00
|
|
|
/* get entry */
|
|
|
|
rc = bdb_dn2entry( be, NULL, ndn, &e, &matched, 0 );
|
2000-09-26 11:47:56 +08:00
|
|
|
|
|
|
|
switch(rc) {
|
|
|
|
case DB_NOTFOUND:
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
2000-09-28 07:25:15 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"bdb_referrals: dn2entry failed: %s (%d)\n",
|
|
|
|
db_strerror(rc), rc, 0 );
|
2000-09-26 11:47:56 +08:00
|
|
|
send_ldap_result( conn, op, rc=LDAP_OTHER,
|
2000-09-28 06:28:59 +08:00
|
|
|
NULL, "internal error", NULL, NULL );
|
2000-09-26 11:47:56 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( e == NULL ) {
|
|
|
|
char *matched_dn = NULL;
|
|
|
|
struct berval **refs = default_referral;
|
|
|
|
|
|
|
|
if ( matched != NULL ) {
|
|
|
|
matched_dn = ch_strdup( matched->e_dn );
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2000-09-28 07:25:15 +08:00
|
|
|
"bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
|
2001-10-14 00:55:54 +08:00
|
|
|
(long) op->o_tag, dn, matched_dn );
|
2000-09-26 11:47:56 +08:00
|
|
|
|
|
|
|
refs = is_entry_referral( matched )
|
|
|
|
? get_entry_referrals( be, conn, op, matched )
|
|
|
|
: NULL;
|
|
|
|
|
|
|
|
bdb_entry_return( be, matched );
|
2000-09-28 10:27:49 +08:00
|
|
|
matched = NULL;
|
2000-09-26 11:47:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if( refs != NULL ) {
|
|
|
|
/* send referrals */
|
|
|
|
send_ldap_result( conn, op, rc = LDAP_REFERRAL,
|
|
|
|
matched_dn, NULL, refs, NULL );
|
2000-09-28 07:25:15 +08:00
|
|
|
} else {
|
|
|
|
rc = LDAP_SUCCESS;
|
2000-09-26 11:47:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if( matched != NULL ) {
|
|
|
|
ber_bvecfree( refs );
|
|
|
|
free( matched_dn );
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( is_entry_referral( e ) ) {
|
|
|
|
/* entry is a referral */
|
|
|
|
struct berval **refs = get_entry_referrals( be,
|
|
|
|
conn, op, e );
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2000-09-28 07:25:15 +08:00
|
|
|
"bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
|
2001-10-14 00:55:54 +08:00
|
|
|
(long) op->o_tag, dn, e->e_dn );
|
2000-09-26 11:47:56 +08:00
|
|
|
|
|
|
|
if( refs != NULL ) {
|
|
|
|
send_ldap_result( conn, op, rc = LDAP_REFERRAL,
|
2000-09-28 06:28:59 +08:00
|
|
|
e->e_dn, NULL, refs, NULL );
|
2000-09-26 11:47:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ber_bvecfree( refs );
|
|
|
|
}
|
|
|
|
|
|
|
|
bdb_entry_return( be, e );
|
|
|
|
return rc;
|
|
|
|
}
|