From 09cddf9188d3e6b10e8a835c1227e4767407b569 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Mon, 5 Nov 2001 06:24:11 +0000 Subject: [PATCH] Ported referral patches from back-ldbm. I believe search.c still needs the patch from ITS#1289 to be ported here. --- servers/slapd/back-bdb/add.c | 18 ++++++------- servers/slapd/back-bdb/bind.c | 16 +++++------ servers/slapd/back-bdb/compare.c | 16 +++++------ servers/slapd/back-bdb/delete.c | 16 +++++------ servers/slapd/back-bdb/modify.c | 16 +++++------ servers/slapd/back-bdb/modrdn.c | 20 +++++++------- servers/slapd/back-bdb/referral.c | 38 +++++++++++++++++--------- servers/slapd/back-bdb/search.c | 44 +++++++++++++++++++++---------- 8 files changed, 106 insertions(+), 78 deletions(-) diff --git a/servers/slapd/back-bdb/add.c b/servers/slapd/back-bdb/add.c index 90d4eda611..a2e55d0180 100644 --- a/servers/slapd/back-bdb/add.c +++ b/servers/slapd/back-bdb/add.c @@ -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", diff --git a/servers/slapd/back-bdb/bind.c b/servers/slapd/back-bdb/bind.c index e412216ed1..987c3e757d 100644 --- a/servers/slapd/back-bdb/bind.c +++ b/servers/slapd/back-bdb/bind.c @@ -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 ); diff --git a/servers/slapd/back-bdb/compare.c b/servers/slapd/back-bdb/compare.c index 0d56a69ef4..d6e30804a8 100644 --- a/servers/slapd/back-bdb/compare.c +++ b/servers/slapd/back-bdb/compare.c @@ -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 ); diff --git a/servers/slapd/back-bdb/delete.c b/servers/slapd/back-bdb/delete.c index 6e5659a437..550c476b91 100644 --- a/servers/slapd/back-bdb/delete.c +++ b/servers/slapd/back-bdb/delete.c @@ -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", diff --git a/servers/slapd/back-bdb/modify.c b/servers/slapd/back-bdb/modify.c index 4e2d19917b..449c55b0da 100644 --- a/servers/slapd/back-bdb/modify.c +++ b/servers/slapd/back-bdb/modify.c @@ -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", diff --git a/servers/slapd/back-bdb/modrdn.c b/servers/slapd/back-bdb/modrdn.c index aba9cdfadd..1707a54026 100644 --- a/servers/slapd/back-bdb/modrdn.c +++ b/servers/slapd/back-bdb/modrdn.c @@ -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 ); diff --git a/servers/slapd/back-bdb/referral.c b/servers/slapd/back-bdb/referral.c index 1064292f18..c32522d2dc 100644 --- a/servers/slapd/back-bdb/referral.c +++ b/servers/slapd/back-bdb/referral.c @@ -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 ); diff --git a/servers/slapd/back-bdb/search.c b/servers/slapd/back-bdb/search.c index f6d4db747f..e8ac773f35 100644 --- a/servers/slapd/back-bdb/search.c +++ b/servers/slapd/back-bdb/search.c @@ -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 ); -- 2.39.5