]> git.sur5r.net Git - openldap/commitdiff
Use dnIsSuffix
authorHoward Chu <hyc@openldap.org>
Sun, 30 Dec 2001 10:47:28 +0000 (10:47 +0000)
committerHoward Chu <hyc@openldap.org>
Sun, 30 Dec 2001 10:47:28 +0000 (10:47 +0000)
servers/slapd/back-bdb/search.c
servers/slapd/back-ldbm/search.c

index 9192753e2286ae86b10ab4405007f34b17d73744..c6d11b1f97a7cecdb399206f023903fff356eeb8 100644 (file)
@@ -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;
 }
index 4f97aa6c1a26406c6c74b78fc0b2573ec794a5f1..52a28dddd65f48deddacf67f4f5915fc00f475ae 100644 (file)
@@ -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;
 }