]> git.sur5r.net Git - openldap/commitdiff
Ported referral patches from back-ldbm. I believe search.c still needs
authorHoward Chu <hyc@openldap.org>
Mon, 5 Nov 2001 06:24:11 +0000 (06:24 +0000)
committerHoward Chu <hyc@openldap.org>
Mon, 5 Nov 2001 06:24:11 +0000 (06:24 +0000)
the patch from ITS#1289 to be ported here.

servers/slapd/back-bdb/add.c
servers/slapd/back-bdb/bind.c
servers/slapd/back-bdb/compare.c
servers/slapd/back-bdb/delete.c
servers/slapd/back-bdb/modify.c
servers/slapd/back-bdb/modrdn.c
servers/slapd/back-bdb/referral.c
servers/slapd/back-bdb/search.c

index 90d4eda61114aac44fc784298309c459782f94b8..a2e55d0180b6c1474d102356864d964117059333 100644 (file)
@@ -113,20 +113,21 @@ retry:    rc = txn_abort( ltid );
                }
 
                if ( p == NULL ) {
-                       char *matched_dn;
+                       char *matched_dn = NULL;
                        struct berval **refs;
 
                        if ( matched != NULL ) {
                                matched_dn = ch_strdup( matched->e_dn );
                                refs = is_entry_referral( matched )
-                                       ? get_entry_referrals( be, conn, op, matched )
+                                       ? get_entry_referrals( be, conn, op,
+                                       matched, e->e_dn, LDAP_SCOPE_DEFAULT )
                                        : NULL;
                                bdb_entry_return( be, matched );
                                matched = NULL;
 
                        } else {
-                               matched_dn = NULL;
-                               refs = default_referral;
+                               refs = referral_rewrite( default_referral,
+                                       NULL, e->e_dn, LDAP_SCOPE_DEFAULT );
                        }
 
                        Debug( LDAP_DEBUG_TRACE, "bdb_add: parent does not exist\n",
@@ -135,10 +136,8 @@ retry:     rc = txn_abort( ltid );
                        send_ldap_result( conn, op, rc = LDAP_REFERRAL,
                                matched_dn, NULL, refs, NULL );
 
-                       if( matched != NULL ) {
-                               ber_bvecfree( refs );
-                               ch_free( matched_dn );
-                       }
+                       ber_bvecfree( refs );
+                       ch_free( matched_dn );
 
                        goto done;
                }
@@ -166,7 +165,8 @@ retry:      rc = txn_abort( ltid );
                        /* parent is a referral, don't allow add */
                        char *matched_dn = ch_strdup( p->e_dn );
                        struct berval **refs = is_entry_referral( p )
-                               ? get_entry_referrals( be, conn, op, p )
+                               ? get_entry_referrals( be, conn, op, p,
+                                       e->e_dn, LDAP_SCOPE_DEFAULT )
                                : NULL;
 
                        Debug( LDAP_DEBUG_TRACE, "bdb_add: parent is referral\n",
index e412216ed1eb93f5971f32684dc1ee5ef6614258..987c3e757dcd14e2f775a3a27e0c972b3508aa2b 100644 (file)
@@ -60,20 +60,22 @@ bdb_bind(
        /* get entry with reader lock */
        if ( e == NULL ) {
                char *matched_dn = NULL;
-               struct berval **refs = NULL;
+               struct berval **refs;
 
                if( matched != NULL ) {
                        matched_dn = ch_strdup( matched->e_dn );
 
                        refs = is_entry_referral( matched )
-                               ? get_entry_referrals( be, conn, op, matched )
+                               ? get_entry_referrals( be, conn, op, matched,
+                                       dn, LDAP_SCOPE_DEFAULT )
                                : NULL;
 
                        bdb_entry_return( be, matched );
                        matched = NULL;
 
                } else {
-                       refs = default_referral;
+                       refs = referral_rewrite( default_referral,
+                               NULL, dn, LDAP_SCOPE_DEFAULT );
                }
 
                /* allow noauth binds */
@@ -101,10 +103,8 @@ bdb_bind(
                                NULL, NULL, NULL, NULL );
                }
 
-               if ( matched != NULL ) {
-                       ber_bvecfree( refs );
-                       free( matched_dn );
-               }
+               ber_bvecfree( refs );
+               free( matched_dn );
 
                return rc;
        }
@@ -127,7 +127,7 @@ bdb_bind(
        if ( is_entry_referral( e ) ) {
                /* entry is a referral, don't allow bind */
                struct berval **refs = get_entry_referrals( be,
-                       conn, op, e );
+                       conn, op, e, dn, LDAP_SCOPE_DEFAULT );
 
                Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
                        0, 0 );
index 0d56a69ef40d64f801a97eab57b1563af748fb8d..d6e30804a82002bd77d90213ac0ef1cbcc092128 100644 (file)
@@ -45,27 +45,27 @@ bdb_compare(
 
        if ( e == NULL ) {
                char *matched_dn = NULL;
-               struct berval **refs = NULL;
+               struct berval **refs;
 
                if ( matched != NULL ) {
                        matched_dn = ch_strdup( matched->e_dn );
                        refs = is_entry_referral( matched )
-                               ? get_entry_referrals( be, conn, op, matched )
+                               ? get_entry_referrals( be, conn, op, matched,
+                                       dn, LDAP_SCOPE_DEFAULT )
                                : NULL;
                        bdb_entry_return( be, matched );
                        matched = NULL;
 
                } else {
-                       refs = default_referral;
+                       refs = referral_rewrite( default_referral,
+                               NULL, dn, LDAP_SCOPE_DEFAULT );
                }
 
                send_ldap_result( conn, op, rc = LDAP_REFERRAL,
                        matched_dn, NULL, refs, NULL );
 
-               if( matched != NULL ) {
-                       ber_bvecfree( refs );
-                       free( matched_dn );
-               }
+               ber_bvecfree( refs );
+               free( matched_dn );
 
                goto done;
        }
@@ -73,7 +73,7 @@ bdb_compare(
        if (!manageDSAit && is_entry_referral( e ) ) {
                /* entry is a referral, don't allow add */
                struct berval **refs = get_entry_referrals( be,
-                       conn, op, e );
+                       conn, op, e, dn, LDAP_SCOPE_DEFAULT );
 
                Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
                        0, 0 );
index 6e5659a43786d45bd8c144afe7fd2ebabce16e8b..550c476b91e48813bf7eb748c0c5d5cc7852c7be 100644 (file)
@@ -83,7 +83,7 @@ retry:        /* transaction retry */
 
        if ( e == NULL ) {
                char *matched_dn = NULL;
-               struct berval **refs = NULL;
+               struct berval **refs;
 
                Debug( LDAP_DEBUG_ARGS,
                        "<=- bdb_delete: no such object %s\n",
@@ -92,22 +92,22 @@ retry:      /* transaction retry */
                if ( matched != NULL ) {
                        matched_dn = ch_strdup( matched->e_dn );
                        refs = is_entry_referral( matched )
-                               ? get_entry_referrals( be, conn, op, matched )
+                               ? get_entry_referrals( be, conn, op, matched,
+                                       dn, LDAP_SCOPE_DEFAULT )
                                : NULL;
                        bdb_entry_return( be, matched );
                        matched = NULL;
 
                } else {
-                       refs = default_referral;
+                       refs = referral_rewrite( default_referral,
+                               NULL, dn, LDAP_SCOPE_DEFAULT );
                }
 
                send_ldap_result( conn, op, LDAP_REFERRAL,
                        matched_dn, NULL, refs, NULL );
 
-               if ( matched != NULL ) {
-                       ber_bvecfree( refs );
-                       free( matched_dn );
-               }
+               ber_bvecfree( refs );
+               free( matched_dn );
 
                rc = -1;
                goto done;
@@ -175,7 +175,7 @@ retry:      /* transaction retry */
                /* parent is a referral, don't allow add */
                /* parent is an alias, don't allow add */
                struct berval **refs = get_entry_referrals( be,
-                       conn, op, e );
+                       conn, op, e, dn, LDAP_SCOPE_DEFAULT );
 
                Debug( LDAP_DEBUG_TRACE,
                        "bdb_delete: entry is referral\n",
index 4e2d19917b26e94910dc2ce61b929f2c429dda48..449c55b0da8e991e0b4ab0892fd9baa77241a8cb 100644 (file)
@@ -227,27 +227,27 @@ retry:    /* transaction retry */
        /* acquire and lock entry */
        if ( e == NULL ) {
                char* matched_dn = NULL;
-               struct berval **refs = NULL;
+               struct berval **refs;
 
                if ( matched != NULL ) {
                        matched_dn = ch_strdup( matched->e_dn );
                        refs = is_entry_referral( matched )
-                               ? get_entry_referrals( be, conn, op, matched )
+                               ? get_entry_referrals( be, conn, op, matched,
+                                       dn, LDAP_SCOPE_DEFAULT )
                                : NULL;
                        bdb_entry_return( be, matched );
                        matched = NULL;
 
                } else {
-                       refs = default_referral;
+                       refs = referral_rewrite( default_referral,
+                               NULL, dn, LDAP_SCOPE_DEFAULT );
                }
 
                send_ldap_result( conn, op, rc = LDAP_REFERRAL,
                        matched_dn, NULL, refs, NULL );
 
-               if ( matched != NULL ) {
-                       ber_bvecfree( refs );
-                       free( matched_dn );
-               }
+               ber_bvecfree( refs );
+               free( matched_dn );
 
                return rc;
        }
@@ -256,7 +256,7 @@ retry:      /* transaction retry */
                /* parent is a referral, don't allow add */
                /* parent is an alias, don't allow add */
                struct berval **refs = get_entry_referrals( be,
-                       conn, op, e );
+                       conn, op, e, dn, LDAP_SCOPE_DEFAULT );
 
                Debug( LDAP_DEBUG_TRACE,
                        "bdb_modify: entry is referral\n",
index aba9cdfaddcff4726e6b9e4196e2ab06809e6a99..1707a54026f149cae97383a63b0b6b344f0d4146 100644 (file)
@@ -114,27 +114,27 @@ retry:    /* transaction retry */
 
        if ( e == NULL ) {
                char* matched_dn = NULL;
-               struct berval** refs = NULL;
+               struct berval** refs;
 
                if( matched != NULL ) {
                        matched_dn = strdup( matched->e_dn );
                        refs = is_entry_referral( matched )
-                               ? get_entry_referrals( be, conn, op, matched )
+                               ? get_entry_referrals( be, conn, op, matched,
+                                       dn, LDAP_SCOPE_DEFAULT )
                                : NULL;
                        bdb_entry_return( be, matched );
                        matched = NULL;
 
                } else {
-                       refs = default_referral;
+                       refs = referral_rewrite( default_referral,
+                               NULL, dn, LDAP_SCOPE_DEFAULT );
                }
 
                send_ldap_result( conn, op, rc = LDAP_REFERRAL,
                        matched_dn, NULL, refs, NULL );
 
-               if ( matched != NULL ) {
-                       ber_bvecfree( refs );
-                       free( matched_dn );
-               }
+               ber_bvecfree( refs );
+               free( matched_dn );
 
                goto done;
        }
@@ -143,10 +143,10 @@ retry:    /* transaction retry */
                /* parent is a referral, don't allow add */
                /* parent is an alias, don't allow add */
                struct berval **refs = get_entry_referrals( be,
-                       conn, op, e );
+                       conn, op, e, dn, LDAP_SCOPE_DEFAULT );
 
-               Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: entry is referral\n",
-                       0, 0, 0 );
+               Debug( LDAP_DEBUG_TRACE, "bdb_modrdn: entry %s is referral\n",
+                       e->e_dn, 0, 0 );
 
                send_ldap_result( conn, op, rc = LDAP_REFERRAL,
                        e->e_dn, NULL, refs, NULL );
index 1064292f186c1aff03d9a923487039f02ce59cf4..c32522d2dc1ec4f180685766204b01c8f438bb11 100644 (file)
@@ -40,6 +40,7 @@ bdb_referrals(
 
        switch(rc) {
        case DB_NOTFOUND:
+               rc = 0;
        case 0:
                break;
        default:
@@ -53,7 +54,7 @@ bdb_referrals(
 
        if ( e == NULL ) {
                char *matched_dn = NULL;
-               struct berval **refs = default_referral;
+               struct berval **refs = NULL;
 
                if ( matched != NULL ) {
                        matched_dn = ch_strdup( matched->e_dn );
@@ -62,42 +63,53 @@ bdb_referrals(
                                "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
                                (long) op->o_tag, dn, matched_dn );
 
-                       refs = is_entry_referral( matched )
-                               ? get_entry_referrals( be, conn, op, matched )
-                               : NULL;
+                       if( is_entry_referral( matched ) ) {
+                               rc = LDAP_OTHER;
+                               refs = get_entry_referrals( be, conn, op,
+                                       matched, dn, LDAP_SCOPE_DEFAULT );
+                       }
 
                        bdb_entry_return( be, matched );
                        matched = NULL;
+               } else if ( default_referral != NULL ) {
+                       rc = LDAP_OTHER;
+                       refs = referral_rewrite( default_referral,
+                               NULL, dn, LDAP_SCOPE_DEFAULT );
                }
 
                if( refs != NULL ) {
                        /* send referrals */
                        send_ldap_result( conn, op, rc = LDAP_REFERRAL,
                                matched_dn, NULL, refs, NULL );
-               } else {
-                       rc = LDAP_SUCCESS;
-               }
-
-               if( matched != NULL ) {
                        ber_bvecfree( refs );
-                       free( matched_dn );
+               } else if ( rc != LDAP_SUCCESS ) {
+                       send_ldap_result( conn, op, rc, matched_dn,
+                               matched_dn ? "bad referral object" : NULL,
+                               NULL, NULL );
                }
 
+               free( matched_dn );
                return rc;
        }
 
        if ( is_entry_referral( e ) ) {
                /* entry is a referral */
                struct berval **refs = get_entry_referrals( be,
-                       conn, op, e );
+                       conn, op, e, dn, LDAP_SCOPE_DEFAULT );
+               struct berval **rrefs = referral_rewrite(
+                       refs, e->e_dn, dn, LDAP_SCOPE_DEFAULT );
 
                Debug( LDAP_DEBUG_TRACE,
                        "bdb_referrals: op=%ld target=\"%s\" matched=\"%s\"\n",
                        (long) op->o_tag, dn, e->e_dn );
 
-               if( refs != NULL ) {
+               if( rrefs != NULL ) {
                        send_ldap_result( conn, op, rc = LDAP_REFERRAL,
-                               e->e_dn, NULL, refs, NULL );
+                               e->e_dn, NULL, rrefs, NULL );
+                       ber_bvecfree( rrefs );
+               } else {
+                       send_ldap_result( conn, op, rc = LDAP_OTHER, e->e_dn,
+                               "bad referral object", NULL, NULL );
                }
 
                ber_bvecfree( refs );
index f6d4db747fbfa33881bccf0ce3279f5d420248e9..e8ac773f354dc67e853dcd0af705cb170cf51a49 100644 (file)
@@ -91,25 +91,33 @@ bdb_search(
                struct berval **refs = NULL;
 
                if ( matched != NULL ) {
+                       struct berval **erefs;
                        matched_dn = ch_strdup( matched->e_dn );
 
-                       refs = is_entry_referral( matched )
-                               ? get_entry_referrals( be, conn, op, matched )
+                       erefs = is_entry_referral( matched )
+                               ? get_entry_referrals( be, conn, op, matched,
+                                       base, scope )
                                : NULL;
 
+                       bdb_entry_return( be, matched );
+                       matched = NULL;
+
+                       if( erefs ) {
+                               refs = referral_rewrite( erefs, matched_dn,
+                                       base, scope );
+                               ber_bvecfree( erefs );
+                       }
+
                } else {
-                       refs = default_referral;
+                       refs = referral_rewrite( default_referral,
+                               NULL, base, scope );
                }
 
                send_ldap_result( conn, op,     rc=LDAP_REFERRAL ,
                        matched_dn, text, refs, NULL );
 
-               if( matched != NULL ) {
-                       ber_bvecfree( refs );
-                       free( matched_dn );
-                       bdb_entry_return( be, matched );
-                       matched = NULL;
-               }
+               ber_bvecfree( refs );
+               free( matched_dn );
 
                return rc;
        }
@@ -117,17 +125,25 @@ bdb_search(
        if (!manageDSAit && is_entry_referral( e ) ) {
                /* entry is a referral, don't allow add */
                char *matched_dn = ch_strdup( e->e_dn );
-               struct berval **refs = get_entry_referrals( be,
-                       conn, op, e );
+               struct berval **erefs = get_entry_referrals( be,
+                       conn, op, e, base, scope );
+               struct berval **refs = NULL;
 
                bdb_entry_return( be, e );
                e = NULL;
 
+               if( erefs ) {
+                       refs = referral_rewrite( erefs, matched_dn,
+                               base, scope );
+                       ber_bvecfree( erefs );
+               }
+
                Debug( LDAP_DEBUG_TRACE, "bdb_search: entry is referral\n",
                        0, 0, 0 );
 
                send_ldap_result( conn, op, LDAP_REFERRAL,
-                       matched_dn, NULL, refs, NULL );
+                       matched_dn, refs ? NULL : "bad referral object",
+                       refs, NULL );
 
                ber_bvecfree( refs );
                free( matched_dn );
@@ -329,10 +345,10 @@ bdb_search(
                        is_entry_referral( e ) )
                {
                        struct berval **refs = get_entry_referrals(
-                               be, conn, op, e );
+                               be, conn, op, e, NULL, scope );
 
                        send_search_reference( be, conn, op,
-                               e, refs, scope, NULL, &v2refs );
+                               e, refs, NULL, &v2refs );
 
                        ber_bvecfree( refs );