From 07b4ad7fa251620a3d44d2681bfd2e0e40512a2a Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sun, 30 Dec 2001 10:47:28 +0000 Subject: [PATCH] Use dnIsSuffix --- servers/slapd/back-bdb/search.c | 20 +++++++++---------- servers/slapd/back-ldbm/search.c | 33 ++++++++++++++------------------ 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/servers/slapd/back-bdb/search.c b/servers/slapd/back-bdb/search.c index 9192753e22..c6d11b1f97 100644 --- a/servers/slapd/back-bdb/search.c +++ b/servers/slapd/back-bdb/search.c @@ -53,7 +53,7 @@ bdb_search( Entry *e = NULL; struct berval **v2refs = NULL; Entry *matched = NULL; - char *realbase = NULL; + struct berval realbase = { 0, NULL }; int nentries = 0; int manageDSAit; @@ -235,7 +235,7 @@ bdb_search( } /* need normalized dn below */ - realbase = ch_strdup( e->e_ndn ); + ber_dupbv( &realbase, &e->e_nname ); /* start cursor at base entry's id * FIXME: hack to make "" base work */ @@ -328,12 +328,12 @@ bdb_search( if( scope & LDAP_SCOPE_ONELEVEL ) { char *pdn = dn_parent( NULL, e->e_ndn ); if ( pdn != NULL ) { - if( strcmp( pdn, realbase ) ) { + if( strcmp( pdn, realbase.bv_val ) ) { goto loop_continue; } } - } else if ( dn_issuffix( e->e_ndn, realbase ) ) { + } else if ( dnIsSuffix( &e->e_nname, &realbase ) ) { /* alias is within scope */ Debug( LDAP_DEBUG_TRACE, "bdb_search: \"%s\" in subtree\n", @@ -377,17 +377,15 @@ bdb_search( /* check scope */ if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) { if ( (dn = dn_parent( be, e->e_ndn )) != NULL ) { - scopeok = (dn == realbase) + scopeok = (dn == realbase.bv_val) ? 1 - : (strcmp( dn, realbase ) ? 0 : 1 ); + : (strcmp( dn, realbase.bv_val ) ? 0 : 1 ); } else { - scopeok = (realbase == NULL || *realbase == '\0'); + scopeok = (realbase.bv_len == 0); } } else if ( !scopeok && scope == LDAP_SCOPE_SUBTREE ) { - dn = ch_strdup( e->e_ndn ); - scopeok = dn_issuffix( dn, realbase ); - free( dn ); + scopeok = dnIsSuffix( &e->e_nname, &realbase ); } else { scopeok = 1; @@ -448,7 +446,7 @@ loop_continue: done: ber_bvecfree( v2refs ); - if( realbase ) ch_free( realbase ); + if( realbase.bv_val ) ch_free( realbase.bv_val ); return rc; } diff --git a/servers/slapd/back-ldbm/search.c b/servers/slapd/back-ldbm/search.c index 4f97aa6c1a..52a28dddd6 100644 --- a/servers/slapd/back-ldbm/search.c +++ b/servers/slapd/back-ldbm/search.c @@ -49,7 +49,7 @@ ldbm_back_search( Entry *e; struct berval **v2refs = NULL; Entry *matched = NULL; - char *realbase = NULL; + struct berval realbase = { 0, NULL }; int nentries = 0; int manageDSAit = get_manageDSAit( op ); int cscope = LDAP_SCOPE_DEFAULT; @@ -70,7 +70,7 @@ ldbm_back_search( e = (Entry *) &slap_entry_root; /* need normalized dn below */ - realbase = ch_strdup( e->e_ndn ); + ber_dupbv( &realbase, &e->e_nname ); candidates = search_candidates( be, e, filter, scope, deref, manageDSAit ); @@ -183,7 +183,7 @@ ldbm_back_search( } /* need normalized dn below */ - realbase = ch_strdup( e->e_ndn ); + ber_dupbv( &realbase, &e->e_nname ); cache_return_entry_r( &li->li_cache, e ); @@ -343,13 +343,12 @@ searchit: if( scope & LDAP_SCOPE_ONELEVEL ) { char *pdn = dn_parent( NULL, e->e_ndn ); if ( pdn != NULL ) { - if( strcmp( pdn, realbase ) ) { - free( pdn ); + if( strcmp( pdn, realbase.bv_val ) ) { goto loop_continue; } } - } else if ( dn_issuffix( e->e_ndn, realbase ) ) { + } else if ( dnIsSuffix( &e->e_nname, &realbase ) ) { /* alias is within scope */ #ifdef NEW_LOGGING LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1, @@ -379,17 +378,15 @@ searchit: /* check scope */ if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) { if ( (dn = dn_parent( be, e->e_ndn )) != NULL ) { - scopeok = (dn == realbase) + scopeok = (dn == realbase.bv_val) ? 1 - : (strcmp( dn, realbase ) ? 0 : 1 ); + : (strcmp( dn, realbase.bv_val ) ? 0 : 1 ); } else { - scopeok = (realbase == NULL || *realbase == '\0'); + scopeok = (realbase.bv_len == 0); } } else if ( !scopeok && scope == LDAP_SCOPE_SUBTREE ) { - dn = ch_strdup( e->e_ndn ); - scopeok = dn_issuffix( dn, realbase ); - free( dn ); + scopeok = dnIsSuffix( &e->e_nname, &realbase ); } else { scopeok = 1; @@ -431,17 +428,15 @@ searchit: /* check scope */ if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) { if ( (dn = dn_parent( be, e->e_ndn )) != NULL ) { - scopeok = (dn == realbase) + scopeok = (dn == realbase.bv_val) ? 1 - : (strcmp( dn, realbase ) ? 0 : 1 ); + : (strcmp( dn, realbase.bv_val ) ? 0 : 1 ); } else { - scopeok = (realbase == NULL || *realbase == '\0'); + scopeok = (realbase.bv_len == 0); } } else if ( !scopeok && scope == LDAP_SCOPE_SUBTREE ) { - dn = ch_strdup( e->e_ndn ); - scopeok = dn_issuffix( dn, realbase ); - free( dn ); + scopeok = dnIsSuffix( &e->e_nname, &realbase ); } else { scopeok = 1; @@ -516,7 +511,7 @@ done: idl_free( candidates ); ber_bvecfree( v2refs ); - if( realbase ) free( realbase ); + if( realbase.bv_val ) free( realbase.bv_val ); return rc; } -- 2.39.5