From bcdfdb968f6436ca450b0ee812d5f84a8430c9ca Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 3 Jan 2002 05:38:26 +0000 Subject: [PATCH] Changed AttributeName back into an array instead of a linked list. Fixed bug in do_search eating up controls. --- servers/slapd/aclparse.c | 9 +++--- servers/slapd/ad.c | 35 +++++++++++++--------- servers/slapd/back-ldap/config.c | 11 ++++--- servers/slapd/back-ldap/search.c | 7 ++--- servers/slapd/back-meta/search.c | 4 +-- servers/slapd/back-shell/search.c | 2 +- servers/slapd/search.c | 48 ++++++++++++------------------- servers/slapd/slap.h | 1 - 8 files changed, 55 insertions(+), 62 deletions(-) diff --git a/servers/slapd/aclparse.c b/servers/slapd/aclparse.c index ea1eef7e14..a5cfb662cf 100644 --- a/servers/slapd/aclparse.c +++ b/servers/slapd/aclparse.c @@ -1275,9 +1275,10 @@ acl_free( AccessControl *a ) filter_free( a->acl_filter ); if ( a->acl_dn_pat.bv_len ) free ( a->acl_dn_pat.bv_val ); - for (; a->acl_attrs; a->acl_attrs = an) { - an = a->acl_attrs->an_next; - free( a->acl_attrs->an_name.bv_val ); + if ( a->acl_attrs ) { + for ( an = a->acl_attrs; an->an_name.bv_val; an++ ) { + free( an->an_name.bv_val ); + } free( a->acl_attrs ); } for (; a->acl_access; a->acl_access = n) { @@ -1489,7 +1490,7 @@ print_acl( Backend *be, AccessControl *a ) to++; fprintf( stderr, " attrs=" ); - for ( an = a->acl_attrs; an; an=an->an_next ) { + for ( an = a->acl_attrs; an && an->an_name.bv_val; an++ ) { if ( ! first ) { fprintf( stderr, "," ); } diff --git a/servers/slapd/ad.c b/servers/slapd/ad.c index 440ecf8a59..ba5e3ddb26 100644 --- a/servers/slapd/ad.c +++ b/servers/slapd/ad.c @@ -284,7 +284,9 @@ int ad_inlist( AttributeDescription *desc, AttributeName *attrs ) { - for( ; attrs; attrs=attrs->an_next ) { + if (! attrs ) return 0; + + for( ; attrs->an_name.bv_val; attrs++ ) { ObjectClass *oc; int rc; @@ -415,7 +417,7 @@ an_find( { if( a == NULL ) return 0; - for ( ; a; a=a->an_next ) { + for ( ; a->an_name.bv_val; a++ ) { if ( a->an_name.bv_len != s->bv_len) continue; if ( strcasecmp( s->bv_val, a->an_name.bv_val ) == 0 ) { return( 1 ); @@ -434,31 +436,36 @@ str2anlist( AttributeName *an, const char *in, const char *brkstr ) char *str; char *s; char *lasts; + int i, j; const char *text; - AttributeName *a, *anew; + AttributeName *anew; + /* find last element in list */ + for (i = 0; an && an[i].an_name.bv_val; i++); + /* protect the input string from strtok */ str = ch_strdup( in ); - /* find last element in list */ - for (a = an; a && a->an_next; a=a->an_next); - + /* Count words in string */ + j=1; + for ( s = str; *s; s++ ) { + if ( strchr( brkstr, *s ) != NULL ) { + j++; + } + } + + an = ch_realloc( an, ( i + j + 1 ) * sizeof( AttributeName ) ); + anew = an + i; for ( s = ldap_pvt_strtok( str, brkstr, &lasts ); s != NULL; s = ldap_pvt_strtok( NULL, brkstr, &lasts ) ) { - anew = ch_malloc( sizeof( AttributeName ) ); - anew->an_next = NULL; anew->an_desc = NULL; ber_str2bv(s, 0, 1, &anew->an_name); slap_bv2ad(&anew->an_name, &anew->an_desc, &text); - if (!an) { - an = anew; - } else { - a->an_next = anew; - } - a = anew; + anew++; } + anew->an_name.bv_val = NULL; free( str ); return( an ); diff --git a/servers/slapd/back-ldap/config.c b/servers/slapd/back-ldap/config.c index c06a7c5d89..6d6890919c 100644 --- a/servers/slapd/back-ldap/config.c +++ b/servers/slapd/back-ldap/config.c @@ -438,19 +438,18 @@ ldap_back_map_filter( char ** ldap_back_map_attrs( struct ldapmap *at_map, - AttributeName *a, + AttributeName *an, int remap ) { int i; char **na; - AttributeName *an; struct berval mapped; - if (a == NULL) + if (an == NULL) return(NULL); - for (i = 0, an=a; an; an=an->an_next, i++) { + for (i = 0; an[i].an_name.bv_val; i++) { /* */ } @@ -458,8 +457,8 @@ ldap_back_map_attrs( if (na == NULL) return(NULL); - for (i = 0, an=a; an; an=an->an_next) { - ldap_back_map(at_map, &an->an_name, &mapped, remap); + for (i = 0; an[i].an_name.bv_val; i++) { + ldap_back_map(at_map, &an[i].an_name, &mapped, remap); if (mapped.bv_val != NULL) { na[i] = mapped.bv_val; i++; diff --git a/servers/slapd/back-ldap/search.c b/servers/slapd/back-ldap/search.c index 6f192f13b8..f05ed507a6 100644 --- a/servers/slapd/back-ldap/search.c +++ b/servers/slapd/back-ldap/search.c @@ -225,11 +225,10 @@ ldap_back_search( mapped_attrs = ldap_back_map_attrs(&li->at_map, attrs, 0); if ( mapped_attrs == NULL && attrs) { - AttributeName *an; - for (count=0, an=attrs; an; an=an->an_next,count++); + for (count=0; attrs[count].an_name.bv_val; count++); mapped_attrs = ch_malloc( (count+1) * sizeof(char *)); - for (count=0, an=attrs; an; an=an->an_next,count++) { - mapped_attrs[count] = an->an_name.bv_val; + for (count=0; attrs[count].an_name.bv_val; count++) { + mapped_attrs[count] = attrs[count].an_name.bv_val; } mapped_attrs[count] = NULL; } diff --git a/servers/slapd/back-meta/search.c b/servers/slapd/back-meta/search.c index f504745cb4..7ec8ae8707 100644 --- a/servers/slapd/back-meta/search.c +++ b/servers/slapd/back-meta/search.c @@ -352,9 +352,9 @@ meta_back_search( attrs, 0 ); if ( mapped_attrs == NULL && attrs) { AttributeName *an; - for ( count=0, an=attrs; an; an=an->an_next, count++ ); + for ( count=0, an=attrs; an->an_name.bv_val; an++, count++ ); mapped_attrs = ch_malloc( ( count + 1 ) * sizeof(char *)); - for ( count=0, an=attrs; an; an=an->an_next, count++ ) { + for ( count=0, an=attrs; an->an_name.bv_val; an++, count++ ) { mapped_attrs[ count ] = an->an_name.bv_val; } mapped_attrs[ count ] = NULL; diff --git a/servers/slapd/back-shell/search.c b/servers/slapd/back-shell/search.c index 9e0d6c3761..e16d8668b4 100644 --- a/servers/slapd/back-shell/search.c +++ b/servers/slapd/back-shell/search.c @@ -62,7 +62,7 @@ shell_back_search( fprintf( wfp, "filter: %s\n", filterstr ); fprintf( wfp, "attrsonly: %d\n", attrsonly ? 1 : 0 ); fprintf( wfp, "attrs:%s", attrs == NULL ? " all" : "" ); - for ( an = attrs; an; an=an->an_next ) { + for ( an = attrs; an && an->an_name.bv_val; an++ ) { fprintf( wfp, " %s", an->an_name.bv_val ); } fprintf( wfp, "\n" ); diff --git a/servers/slapd/search.c b/servers/slapd/search.c index 435417b071..52e22285c5 100644 --- a/servers/slapd/search.c +++ b/servers/slapd/search.c @@ -37,9 +37,11 @@ do_search( struct berval nbase = { 0, NULL }; struct berval fstr = { 0, NULL }; Filter *filter = NULL; - AttributeName an, *al = NULL, *alast, *anew; + AttributeName *an; + ber_len_t siz, off; Backend *be; int rc; + int i; const char *text; int manageDSAit; @@ -156,30 +158,17 @@ do_search( /* attributes */ - if ( ber_scanf( op->o_ber, "{" /*}*/ ) == LBER_ERROR ) { + siz = sizeof(AttributeName); + off = 0; + if ( ber_scanf( op->o_ber, "{w}}", &an, &siz, off ) == LBER_ERROR ) { send_ldap_disconnect( conn, op, LDAP_PROTOCOL_ERROR, "decoding attrs error" ); rc = SLAPD_DISCONNECT; goto return_results; } - while ( ber_scanf( op->o_ber, "o", &an.an_name ) != LBER_ERROR) { - anew = ch_malloc(sizeof(AttributeName)); - anew->an_next = NULL; - anew->an_name = an.an_name; - anew->an_desc = NULL; - slap_bv2ad( &anew->an_name, &anew->an_desc, &text ); - if (!al) { - al = anew; - } else { - alast->an_next = anew; - } - alast = anew; - } - if ( ber_scanf( op->o_ber, /*{{*/ "}}" ) == LBER_ERROR ) { - send_ldap_disconnect( conn, op, - LDAP_PROTOCOL_ERROR, "decoding attrs error" ); - rc = SLAPD_DISCONNECT; - goto return_results; + for ( i=0; ian_next ) { + if ( siz != 0 ) { + for ( i = 0; ian_name.bv_val )); + "do_search: %s", an[i].an_name.bv_val )); #else - Debug( LDAP_DEBUG_ARGS, " %s", anew->an_name.bv_val, 0, 0 ); + Debug( LDAP_DEBUG_ARGS, " %s", an[i].an_name.bv_val, 0, 0 ); #endif } @@ -274,7 +263,7 @@ do_search( if( rc == LDAP_COMPARE_TRUE ) { send_search_entry( NULL, conn, op, - entry, al, attrsonly, NULL ); + entry, an, attrsonly, NULL ); } entry_free( entry ); @@ -330,7 +319,7 @@ do_search( if ( be->be_search ) { (*be->be_search)( be, conn, op, &pbase, &nbase, scope, deref, sizelimit, - timelimit, filter, &fstr, al, attrsonly ); + timelimit, filter, &fstr, an, attrsonly ); } else { send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM, NULL, "operation not supported within namingContext", NULL, NULL ); @@ -343,11 +332,10 @@ return_results:; if( fstr.bv_val != NULL) free( fstr.bv_val ); if( filter != NULL) filter_free( filter ); - for (; al; al=anew ) { - anew = al->an_next; - free(al->an_name.bv_val); - free(al); + for (i = 0; i