From d00fe773ae5676b819c5fc2e081bfc23f72a5991 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Wed, 26 Dec 2001 09:19:57 +0000 Subject: [PATCH] Fix attrs handling --- servers/slapd/back-ldap/back-ldap.h | 2 +- servers/slapd/back-ldap/config.c | 33 ++++++++++++++++++++--------- servers/slapd/back-ldap/search.c | 13 ++++++++---- servers/slapd/back-tcl/tcl_search.c | 9 +++++--- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/servers/slapd/back-ldap/back-ldap.h b/servers/slapd/back-ldap/back-ldap.h index 45fb33bea6..c9c16ac716 100644 --- a/servers/slapd/back-ldap/back-ldap.h +++ b/servers/slapd/back-ldap/back-ldap.h @@ -112,7 +112,7 @@ ldap_back_map_filter( char ** ldap_back_map_attrs( struct ldapmap *at_map, - char **a, + struct berval **a, int remap ); diff --git a/servers/slapd/back-ldap/config.c b/servers/slapd/back-ldap/config.c index 605a16ab2f..425ef251da 100644 --- a/servers/slapd/back-ldap/config.c +++ b/servers/slapd/back-ldap/config.c @@ -117,6 +117,7 @@ ldap_back_db_config( char *dn, *massaged_dn; #endif /* ENABLE_REWRITE */ BackendDB *tmp_be; + struct berval bdn, *ndn = NULL; /* * syntax: @@ -137,7 +138,16 @@ ldap_back_db_config( return( 1 ); } - tmp_be = select_backend( argv[1], 0, 0 ); + bdn.bv_val = argv[1]; + bdn.bv_len = strlen(bdn.bv_val); + if ( dnNormalize( NULL, &bdn, &ndn ) != LDAP_SUCCESS ) { + fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n", + fname, lineno, bdn.bv_val ); + return( 1 ); + } + tmp_be = select_backend( ndn, 0, 0 ); + ber_bvfree( ndn ); + ndn = NULL; if ( tmp_be != NULL && tmp_be != be ) { fprintf( stderr, "%s: line %d: suffix already in use" " by another backend in" @@ -147,7 +157,15 @@ ldap_back_db_config( return( 1 ); } - tmp_be = select_backend( argv[2], 0, 0 ); + bdn.bv_val = argv[2]; + bdn.bv_len = strlen(bdn.bv_val); + if ( dnNormalize( NULL, &bdn, &ndn ) != LDAP_SUCCESS ) { + fprintf( stderr, "%s: line %d: suffix DN %s is invalid\n", + fname, lineno, bdn.bv_val ); + return( 1 ); + } + tmp_be = select_backend( ndn, 0, 0 ); + ber_bvfree( ndn ); if ( tmp_be != NULL ) { fprintf( stderr, "%s: line %d: massaged suffix" " already in use by another backend in" @@ -413,12 +431,12 @@ ldap_back_map_filter( char ** ldap_back_map_attrs( struct ldapmap *at_map, - char **a, + struct berval **a, int remap ) { int i, j, count; - char **na, *mapped; + char *mapped, **na; if (a == NULL) return(NULL); @@ -432,13 +450,8 @@ ldap_back_map_attrs( return(NULL); for (i = 0, j = 0; i < count; i++) { - mapped = ldap_back_map(at_map, a[i], remap); + mapped = ldap_back_map(at_map, a[i]->bv_val, remap); if (mapped != NULL) { - mapped = ch_strdup(mapped); - if (mapped == NULL) { - charray_free(na); - return(NULL); - } na[j] = mapped; j++; } diff --git a/servers/slapd/back-ldap/search.c b/servers/slapd/back-ldap/search.c index 8ede770591..14dadd3d17 100644 --- a/servers/slapd/back-ldap/search.c +++ b/servers/slapd/back-ldap/search.c @@ -221,8 +221,13 @@ ldap_back_search( } mapped_attrs = ldap_back_map_attrs(&li->at_map, attrs, 0); - if ( mapped_attrs == NULL ) { - mapped_attrs = attrs; + if ( mapped_attrs == NULL && attrs) { + for (count=0; attrs[count]; count++); + mapped_attrs = ch_malloc( (count+1) * sizeof(char *)); + for (count=0; attrs[count]; count++) { + mapped_attrs[count] = attrs[count]->bv_val; + } + mapped_attrs[count] = NULL; } if ((msgid = ldap_search(lc->ld, mbase, scope, mapped_filter, mapped_attrs, @@ -330,8 +335,8 @@ finish:; if ( err ) { free( err ); } - if ( mapped_attrs != attrs ) { - charray_free( mapped_attrs ); + if ( mapped_attrs ) { + free( mapped_attrs ); } #ifdef ENABLE_REWRITE if ( mapped_filter != mfilter ) { diff --git a/servers/slapd/back-tcl/tcl_search.c b/servers/slapd/back-tcl/tcl_search.c index 3f557d4757..6f689da5a7 100644 --- a/servers/slapd/back-tcl/tcl_search.c +++ b/servers/slapd/back-tcl/tcl_search.c @@ -45,11 +45,14 @@ tcl_back_search ( return (-1); } - for (i = 0; attrs != NULL && attrs[i] != NULL; i++) - charray_add(&sattrs, attrs[i]->bv_val); + for (i = 0; attrs != NULL && attrs[i] != NULL; i++); if (i > 0) { + sattrs = ch_malloc( (i+1) * sizeof(char *)); + for (i = 0; attrs[i]; i++) + sattrs[i] = attrs[i]->bv_val; + sattrs[i] = NULL; attrs_tcl = Tcl_Merge (i, sattrs); - charray_free(sattrs); + free(sattrs); } for (i = 0; be->be_suffix[i] != NULL; i++); -- 2.39.5