]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/referral.c
Fix ITS#3255, boi_bdb comparisons
[openldap] / servers / slapd / back-bdb / referral.c
index 73b441d67c3c858e01873c57123fad91de5b4f15..d69c35a7d9eab4ff75e2ade0926d6119c2a2d807 100644 (file)
@@ -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 <http://www.openldap.org/>.
+ *
+ * Copyright 2000-2004 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
+ * <http://www.OpenLDAP.org/license.html>.
  */
 
 #include "portable.h"
@@ -17,7 +26,7 @@ bdb_referrals( Operation *op, SlapReply *rs )
 {
        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;
@@ -43,20 +52,14 @@ bdb_referrals( Operation *op, SlapReply *rs )
 
 dn2entry_retry:
        /* get entry */
-       rc = bdb_dn2entry_r( op->o_bd, NULL, &op->o_req_ndn, &e, &matched, 0, locker, &lock );
+       rc = bdb_dn2entry( op, NULL, &op->o_req_ndn, &ei, 1, locker, &lock );
 
+       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_error( op, rs, LDAP_BUSY, "ldap server busy" );
                LOCK_ID_FREE ( bdb->bi_dbenv, locker );
                return LDAP_BUSY;
@@ -73,38 +76,36 @@ dn2entry_retry:
                        "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_error( op, rs, LDAP_OTHER, "internal error" );
                LOCK_ID_FREE ( bdb->bi_dbenv, locker );
                return rs->sr_err;
        }
 
-       if ( e == NULL ) {
-               if ( matched != NULL ) {
-                       rs->sr_matched = ch_strdup( matched->e_name.bv_val );
-
+       if ( rc == DB_NOTFOUND ) {
+               rc = 0;
+               rs->sr_matched = NULL;
+               if ( e != NULL ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG ( OPERATION, DETAIL1, 
+                       LDAP_LOG ( OPERATION, DETAIL1, 
                        "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
-                       (long) op->o_tag, op->o_req_dn.bv_val, rs->sr_matched );
+                       (long) op->o_tag, op->o_req_dn.bv_val, e->e_name.bv_val );
 #else
                        Debug( LDAP_DEBUG_TRACE,
                                "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
-                               (long) op->o_tag, op->o_req_dn.bv_val, rs->sr_matched );
+                               (long) op->o_tag, op->o_req_dn.bv_val, e->e_name.bv_val );
 #endif
 
-                       if( is_entry_referral( matched ) ) {
+                       if( is_entry_referral( e ) ) {
                                rc = LDAP_OTHER;
-                               rs->sr_ref = get_entry_referrals( op, matched );
+                               rs->sr_ref = get_entry_referrals( op, e );
+                               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;
+                       bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
+                       e = NULL;
                } else if ( default_referral != NULL ) {
                        rc = LDAP_OTHER;
                        rs->sr_ref = referral_rewrite( default_referral,
@@ -124,8 +125,10 @@ dn2entry_retry:
                }
 
                LOCK_ID_FREE ( bdb->bi_dbenv, locker );
-               free( (char *)rs->sr_matched );
-               rs->sr_matched = NULL;
+               if (rs->sr_matched) {
+                       op->o_tmpfree( (char *)rs->sr_matched, op->o_tmpmemctx );
+                       rs->sr_matched = NULL;
+               }
                return rc;
        }
 
@@ -138,16 +141,16 @@ dn2entry_retry:
 #ifdef NEW_LOGGING
                LDAP_LOG ( OPERATION, DETAIL1, 
                        "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
-                       (long) op->o_tag, op->o_req_dn.bv_val, e->e_dn );
+                       (long) op->o_tag, op->o_req_dn.bv_val, e->e_name.bv_val );
 #else
                Debug( LDAP_DEBUG_TRACE,
                        "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
-                       (long) op->o_tag, op->o_req_dn.bv_val, e->e_dn );
+                       (long) op->o_tag, op->o_req_dn.bv_val, e->e_name.bv_val );
 #endif
 
                rs->sr_matched = e->e_name.bv_val;
                if( rs->sr_ref != NULL ) {
-                       rs->sr_err = LDAP_REFERRAL;
+                       rc = rs->sr_err = LDAP_REFERRAL;
                        send_ldap_result( op, rs );
                        ber_bvarray_free( rs->sr_ref );
                        rs->sr_ref = NULL;