From 55a217d9ae092510a8e29c3a59c240f9ccd756ec Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sat, 8 Dec 2001 05:15:58 +0000 Subject: [PATCH] Changed be_nsuffix from char ** to struct berval ** to eliminate strlen's --- servers/slapd/back-bdb/dn2id.c | 7 +++---- servers/slapd/back-monitor/init.c | 2 +- servers/slapd/back-passwd/search.c | 2 +- servers/slapd/backend.c | 10 +++++++--- servers/slapd/config.c | 4 ++-- servers/slapd/slap.h | 2 +- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/servers/slapd/back-bdb/dn2id.c b/servers/slapd/back-bdb/dn2id.c index a40663cbae..8bef765bce 100644 --- a/servers/slapd/back-bdb/dn2id.c +++ b/servers/slapd/back-bdb/dn2id.c @@ -579,9 +579,8 @@ int bdb_build_tree( * multiple suffixes for a single backend won't work! */ bdb->bi_sufflen = strlen(be->be_suffix[0]); - bdb->bi_nsufflen = strlen(be->be_nsuffix[0]); - rdns = ldap_explode_dn(be->be_nsuffix[0], 0); + rdns = ldap_explode_dn(be->be_nsuffix[0]->bv_val, 0); for (i=0; rdns[i]; i++); bdb->bi_nrdns = i; charray_free(rdns); @@ -621,7 +620,7 @@ int bdb_fix_dn( ldap_pvt_thread_rdwr_rlock(&bdb->bi_tree_rdwr); o = bdb_find_id_node(id, bdb->bi_tree); rlen = bdb->bi_sufflen + 1; - nrlen = bdb->bi_nsufflen + 1; + nrlen = be->be_nsuffix[0]->bv_len + 1; for (n = o; n; n=n->i_parent) { rlen += n->i_rdn->rdn.bv_len + 1; nrlen += n->i_rdn->nrdn.bv_len + 1; @@ -641,7 +640,7 @@ int bdb_fix_dn( ptr--; nptr--; strcpy(ptr, be->be_suffix[0]); - strcpy(nptr, be->be_nsuffix[0]); + strcpy(nptr, be->be_nsuffix[0]->bv_val); return 0; } diff --git a/servers/slapd/back-monitor/init.c b/servers/slapd/back-monitor/init.c index e787577556..b7b0c51ea6 100644 --- a/servers/slapd/back-monitor/init.c +++ b/servers/slapd/back-monitor/init.c @@ -206,7 +206,7 @@ monitor_back_db_init( monitor_defined++; charray_add( &be->be_suffix, SLAPD_MONITOR_DN ); - charray_add( &be->be_nsuffix, SLAPD_MONITOR_NDN ); + ber_bvecadd( &be->be_nsuffix, ber_bvstr( SLAPD_MONITOR_NDN )); mi = ( struct monitorinfo * )ch_calloc( sizeof( struct monitorinfo ), 1 ); ldap_pvt_thread_mutex_init( &mi->mi_cache_mutex ); diff --git a/servers/slapd/back-passwd/search.c b/servers/slapd/back-passwd/search.c index 1a9bf057eb..1fd6991090 100644 --- a/servers/slapd/back-passwd/search.c +++ b/servers/slapd/back-passwd/search.c @@ -190,7 +190,7 @@ passwd_back_search( if( !be_issuffix( be, parent ) ) { int i; for( i=0; be->be_nsuffix[i] != NULL; i++ ) { - if( dn_issuffix( nbase, be->be_nsuffix[i] ) ) { + if( dn_issuffix( nbase, be->be_nsuffix[i]->bv_val ) ) { matched = ch_strdup( be->be_suffix[i] ); break; } diff --git a/servers/slapd/backend.c b/servers/slapd/backend.c index 688a4ee3e8..08e1062fdb 100644 --- a/servers/slapd/backend.c +++ b/servers/slapd/backend.c @@ -525,7 +525,7 @@ select_backend( for ( j = 0; backends[i].be_nsuffix != NULL && backends[i].be_nsuffix[j] != NULL; j++ ) { - len = strlen( backends[i].be_nsuffix[j] ); + len = backends[i].be_nsuffix[j]->bv_len; if ( len > dnlen ) { /* suffix is longer than DN */ @@ -539,7 +539,7 @@ select_backend( } - if ( strcmp( backends[i].be_nsuffix[j], &dn[dnlen-len] ) == 0 ) { + if ( strcmp( backends[i].be_nsuffix[j]->bv_val, &dn[dnlen-len] ) == 0 ) { if( be == NULL ) { be = &backends[i]; @@ -564,9 +564,13 @@ be_issuffix( ) { int i; + int len = strlen(suffix); for ( i = 0; be->be_nsuffix != NULL && be->be_nsuffix[i] != NULL; i++ ) { - if ( strcmp( be->be_nsuffix[i], suffix ) == 0 ) { + if ( len != be->be_nsuffix[i]->bv_len ) { + continue; + } + if ( strcmp( be->be_nsuffix[i]->bv_val, suffix ) == 0 ) { return( 1 ); } } diff --git a/servers/slapd/config.c b/servers/slapd/config.c index 756a6bb376..1dfef56688 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -899,6 +899,7 @@ read_config( const char *fname ) } else { char *dn = ch_strdup( cargv[1] ); + if ( load_ucdata( NULL ) < 0 ) { return( 1 ); } @@ -947,8 +948,7 @@ read_config( const char *fname ) return 1; } #endif /* USE_LDAP_DN_PARSING */ - charray_add( &be->be_nsuffix, dn ); - free( dn ); + ber_bvecadd( &be->be_nsuffix, ber_bvstr( dn )); } /* set database suffixAlias */ diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 6c35e4735e..c0a6237ce3 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -979,7 +979,7 @@ struct slap_backend_db { /* these should be renamed from be_ to bd_ */ char **be_suffix; /* the DN suffixes of data in this backend */ - char **be_nsuffix; /* the normalized DN suffixes in this backend */ + struct berval **be_nsuffix; /* the normalized DN suffixes in this backend */ char **be_suffixAlias; /* pairs of DN suffix aliases and deref values */ char *be_root_dn; /* the magic "root" dn for this db */ char *be_root_ndn; /* the magic "root" normalized dn for this db */ -- 2.39.5