X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-bdb%2Freferral.c;h=fb29411ffe9556caf53ca1cd9aaef9ddbbe9609b;hb=ece2a4daa676c85e1d2ae2bdc426a4ade25037a3;hp=2552248bb792870f13f7e1234630f64eefdecd83;hpb=6939c531700652491f4be4688c6a1f35a1ab8a18;p=openldap
diff --git a/servers/slapd/back-bdb/referral.c b/servers/slapd/back-bdb/referral.c
index 2552248bb7..fb29411ffe 100644
--- a/servers/slapd/back-bdb/referral.c
+++ b/servers/slapd/back-bdb/referral.c
@@ -1,8 +1,17 @@
/* referral.c - BDB backend referral handler */
/* $OpenLDAP$ */
-/*
- * Copyright 2000-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* This work is part of OpenLDAP Software .
+ *
+ * Copyright 2000-2008 The OpenLDAP Foundation.
+ * 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
+ * .
*/
#include "portable.h"
@@ -10,23 +19,16 @@
#include
#include "back-bdb.h"
-#include "external.h"
int
-bdb_referrals(
- BackendDB *be,
- Connection *conn,
- Operation *op,
- struct berval *dn,
- struct berval *ndn,
- const char **text )
+bdb_referrals( Operation *op, SlapReply *rs )
{
- struct bdb_info *bdb = (struct bdb_info *) be->be_private;
- int rc = LDAP_SUCCESS;
+ struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
Entry *e = NULL;
- Entry *matched = NULL;
+ EntryInfo *ei;
+ int rc = LDAP_SUCCESS;
- u_int32_t locker;
+ DB_TXN *rtxn;
DB_LOCK lock;
if( op->o_tag == LDAP_REQ_SEARCH ) {
@@ -39,7 +41,7 @@ bdb_referrals(
return rc;
}
- rc = LOCK_ID(bdb->bi_dbenv, &locker);
+ rc = bdb_reader_get(op, bdb->bi_dbenv, &rtxn);
switch(rc) {
case 0:
break;
@@ -49,124 +51,102 @@ bdb_referrals(
dn2entry_retry:
/* get entry */
- rc = bdb_dn2entry_r( be, NULL, ndn, &e, &matched, 0, locker, &lock );
+ rc = bdb_dn2entry( op, rtxn, &op->o_req_ndn, &ei, 1, &lock );
+
+ /* bdb_dn2entry() may legally leave ei == NULL
+ * if rc != 0 and rc != DB_NOTFOUND
+ */
+ if ( ei ) {
+ e = ei->bei_e;
+ }
switch(rc) {
case DB_NOTFOUND:
- rc = 0;
case 0:
break;
case LDAP_BUSY:
- if (e != NULL) {
- bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
- }
- if (matched != NULL) {
- bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, matched, &lock);
- }
- send_ldap_result( conn, op, LDAP_BUSY,
- NULL, "ldap server busy", NULL, NULL );
- LOCK_ID_FREE ( bdb->bi_dbenv, locker );
+ rs->sr_text = "ldap server busy";
return LDAP_BUSY;
case DB_LOCK_DEADLOCK:
case DB_LOCK_NOTGRANTED:
goto dn2entry_retry;
default:
-#ifdef NEW_LOGGING
- LDAP_LOG ( OPERATION, ERR,
- "bdb_referrals: dn2entry failed: %s (%d)\n",
- db_strerror(rc), rc, 0 );
-#else
Debug( LDAP_DEBUG_TRACE,
- "bdb_referrals: dn2entry failed: %s (%d)\n",
+ LDAP_XSTRING(bdb_referrals)
+ ": dn2entry failed: %s (%d)\n",
db_strerror(rc), rc, 0 );
-#endif
- if (e != NULL) {
- bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
- }
- if (matched != NULL) {
- bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, matched, &lock);
- }
- send_ldap_result( conn, op, rc=LDAP_OTHER,
- NULL, "internal error", NULL, NULL );
- LOCK_ID_FREE ( bdb->bi_dbenv, locker );
- return rc;
+ rs->sr_text = "internal error";
+ return LDAP_OTHER;
}
- if ( e == NULL ) {
- char *matched_dn = NULL;
- BerVarray refs = NULL;
-
- if ( matched != NULL ) {
- matched_dn = ch_strdup( matched->e_dn );
-
-#ifdef NEW_LOGGING
- LDAP_LOG ( OPERATION, DETAIL1,
- "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
- (long) op->o_tag, dn->bv_val, matched_dn );
-#else
+ if ( rc == DB_NOTFOUND ) {
+ rc = LDAP_SUCCESS;
+ rs->sr_matched = NULL;
+ if ( e != NULL ) {
Debug( LDAP_DEBUG_TRACE,
- "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
- (long) op->o_tag, dn->bv_val, matched_dn );
-#endif
+ LDAP_XSTRING(bdb_referrals)
+ ": tag=%lu target=\"%s\" matched=\"%s\"\n",
+ (unsigned long)op->o_tag, op->o_req_dn.bv_val, e->e_name.bv_val );
- if( is_entry_referral( matched ) ) {
+ if( is_entry_referral( e ) ) {
+ BerVarray ref = get_entry_referrals( op, e );
rc = LDAP_OTHER;
- refs = get_entry_referrals( be, conn, op, matched );
+ rs->sr_ref = referral_rewrite( ref, &e->e_name,
+ &op->o_req_dn, LDAP_SCOPE_DEFAULT );
+ ber_bvarray_free( ref );
+ if ( rs->sr_ref ) {
+ rs->sr_matched = ber_strdup_x(
+ e->e_name.bv_val, op->o_tmpmemctx );
+ }
}
- bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache, matched, &lock);
- matched = NULL;
- } else if ( default_referral != NULL ) {
- rc = LDAP_OTHER;
- refs = referral_rewrite( default_referral,
- NULL, dn, LDAP_SCOPE_DEFAULT );
+ bdb_cache_return_entry_r (bdb, e, &lock);
+ e = NULL;
}
- if( refs != NULL ) {
+ if( rs->sr_ref != NULL ) {
/* send referrals */
- send_ldap_result( conn, op, rc = LDAP_REFERRAL,
- matched_dn, NULL, refs, NULL );
- ber_bvarray_free( refs );
+ rc = rs->sr_err = LDAP_REFERRAL;
+ send_ldap_result( op, rs );
+ ber_bvarray_free( rs->sr_ref );
+ rs->sr_ref = NULL;
} else if ( rc != LDAP_SUCCESS ) {
- send_ldap_result( conn, op, rc, matched_dn,
- matched_dn ? "bad referral object" : NULL,
- NULL, NULL );
+ rs->sr_text = rs->sr_matched ? "bad referral object" : NULL;
}
- LOCK_ID_FREE ( bdb->bi_dbenv, locker );
- free( matched_dn );
+ if (rs->sr_matched) {
+ op->o_tmpfree( (char *)rs->sr_matched, op->o_tmpmemctx );
+ rs->sr_matched = NULL;
+ }
return rc;
}
if ( is_entry_referral( e ) ) {
/* entry is a referral */
- BerVarray refs = get_entry_referrals( be, conn, op, e );
- BerVarray rrefs = referral_rewrite(
- refs, &e->e_name, dn, LDAP_SCOPE_DEFAULT );
-
-#ifdef NEW_LOGGING
- LDAP_LOG ( OPERATION, DETAIL1,
- "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
- (long) op->o_tag, dn->bv_val, e->e_dn );
-#else
+ BerVarray refs = get_entry_referrals( op, e );
+ rs->sr_ref = referral_rewrite(
+ refs, &e->e_name, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
+
Debug( LDAP_DEBUG_TRACE,
- "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
- (long) op->o_tag, dn->bv_val, e->e_dn );
-#endif
-
- if( rrefs != NULL ) {
- send_ldap_result( conn, op, rc = LDAP_REFERRAL,
- e->e_dn, NULL, rrefs, NULL );
- ber_bvarray_free( rrefs );
+ LDAP_XSTRING(bdb_referrals)
+ ": tag=%lu target=\"%s\" matched=\"%s\"\n",
+ (unsigned long)op->o_tag, op->o_req_dn.bv_val, e->e_name.bv_val );
+
+ rs->sr_matched = e->e_name.bv_val;
+ if( rs->sr_ref != NULL ) {
+ rc = rs->sr_err = LDAP_REFERRAL;
+ send_ldap_result( op, rs );
+ ber_bvarray_free( rs->sr_ref );
+ rs->sr_ref = NULL;
} else {
- send_ldap_result( conn, op, rc = LDAP_OTHER, e->e_dn,
- "bad referral object", NULL, NULL );
+ rc = LDAP_OTHER;
+ rs->sr_text = "bad referral object";
}
+ rs->sr_matched = NULL;
ber_bvarray_free( refs );
}
- bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
- LOCK_ID_FREE ( bdb->bi_dbenv, locker );
+ bdb_cache_return_entry_r(bdb, e, &lock);
return rc;
}