From 071b9466c444da7df70491fdca4c53f9f98daa31 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Fri, 9 Apr 2004 21:30:55 +0000 Subject: [PATCH] Fix approx matching when there is an equality index but no approx index. Add better approx test --- servers/slapd/back-bdb/attr.c | 7 ++----- servers/slapd/back-bdb/index.c | 9 +++++++-- servers/slapd/back-ldbm/attr.c | 7 ++----- servers/slapd/back-ldbm/index.c | 9 +++++++-- servers/slapd/filterentry.c | 3 +-- servers/slapd/matchedValues.c | 7 ++----- tests/data/search.out.master | 14 ++++++++++++++ tests/scripts/test003-search | 10 ++++++++++ tests/scripts/test009-referral | 10 ++++++++++ 9 files changed, 55 insertions(+), 21 deletions(-) diff --git a/servers/slapd/back-bdb/attr.c b/servers/slapd/back-bdb/attr.c index 5540aef86d..dd545d2602 100644 --- a/servers/slapd/back-bdb/attr.c +++ b/servers/slapd/back-bdb/attr.c @@ -156,12 +156,9 @@ bdb_attr_index_config( } if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) && !( - ( ad->ad_type->sat_approx + ad->ad_type->sat_approx && ad->ad_type->sat_approx->smr_indexer - && ad->ad_type->sat_approx->smr_filter ) - && ( ad->ad_type->sat_equality - && ad->ad_type->sat_equality->smr_indexer - && ad->ad_type->sat_equality->smr_filter ) ) ) + && ad->ad_type->sat_approx->smr_filter ) ) { fprintf( stderr, "%s: line %d: " "approx index of attribute \"%s\" disallowed\n", diff --git a/servers/slapd/back-bdb/index.c b/servers/slapd/back-bdb/index.c index f2d807eb52..e1f09f6fdc 100644 --- a/servers/slapd/back-bdb/index.c +++ b/servers/slapd/back-bdb/index.c @@ -121,9 +121,14 @@ int bdb_index_param( break; case LDAP_FILTER_APPROX: - if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) ) { - goto done; + if ( desc->ad_type->sat_approx ) { + if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) ) { + goto done; + } + break; } + + /* Use EQUALITY rule and index for approximate match */ /* fall thru */ case LDAP_FILTER_EQUALITY: diff --git a/servers/slapd/back-ldbm/attr.c b/servers/slapd/back-ldbm/attr.c index 1ce058b966..bb49d279c2 100644 --- a/servers/slapd/back-ldbm/attr.c +++ b/servers/slapd/back-ldbm/attr.c @@ -156,12 +156,9 @@ attr_index_config( } if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) && !( - ( ad->ad_type->sat_approx + ad->ad_type->sat_approx && ad->ad_type->sat_approx->smr_indexer - && ad->ad_type->sat_approx->smr_filter ) - && ( ad->ad_type->sat_equality - && ad->ad_type->sat_equality->smr_indexer - && ad->ad_type->sat_equality->smr_filter ) ) ) + && ad->ad_type->sat_approx->smr_filter ) ) { fprintf( stderr, "%s: line %d: " "approx index of attribute \"%s\" disallowed\n", diff --git a/servers/slapd/back-ldbm/index.c b/servers/slapd/back-ldbm/index.c index 13956bbc1e..90911d36ad 100644 --- a/servers/slapd/back-ldbm/index.c +++ b/servers/slapd/back-ldbm/index.c @@ -115,9 +115,14 @@ int index_param( break; case LDAP_FILTER_APPROX: - if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) ) { - goto done; + if ( desc->ad_type->sat_approx ) { + if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) ) { + goto done; + } + break; } + + /* Use EQUALITY rule and index for approximate match */ /* fall thru */ case LDAP_FILTER_EQUALITY: diff --git a/servers/slapd/filterentry.c b/servers/slapd/filterentry.c index 86a2db459d..681c66c5c1 100644 --- a/servers/slapd/filterentry.c +++ b/servers/slapd/filterentry.c @@ -437,8 +437,7 @@ test_ava_filter( continue; } - for ( bv = a->a_nvals; bv->bv_val != NULL; bv++ ) - { + for ( bv = a->a_nvals; bv->bv_val != NULL; bv++ ) { int ret; int rc; const char *text; diff --git a/servers/slapd/matchedValues.c b/servers/slapd/matchedValues.c index ef7b39638d..b8a8e61c45 100644 --- a/servers/slapd/matchedValues.c +++ b/servers/slapd/matchedValues.c @@ -206,8 +206,8 @@ test_ava_vrFilter( case LDAP_FILTER_APPROX: mr = a->a_desc->ad_type->sat_approx; if( mr != NULL ) break; + /* use EQUALITY matching rule if no APPROX rule */ - /* use EQUALITY matching rule if no APPROX rule */ case LDAP_FILTER_EQUALITY: mr = a->a_desc->ad_type->sat_equality; break; @@ -221,10 +221,7 @@ test_ava_vrFilter( mr = NULL; } - if( mr == NULL ) { - continue; - - } + if( mr == NULL ) continue; bv = a->a_nvals; for ( j=0; bv->bv_val != NULL; bv++, j++ ) { diff --git a/tests/data/search.out.master b/tests/data/search.out.master index 6545de94a0..79ab08ab85 100644 --- a/tests/data/search.out.master +++ b/tests/data/search.out.master @@ -39,6 +39,20 @@ pager: +1 313 555 4474 facsimiletelephonenumber: +1 313 555 2177 telephonenumber: +1 313 555 0355 +dn: cn=Barbara Jensen,ou=Information Technology Division,ou=People,o=Universit + y of Michigan,c=US +cn: Barbara Jensen +cn: Babs Jensen +sn:: IEplbnNlbiA= +title: Mythical Manager, Research Systems + +dn: cn=Bjorn Jensen,ou=Information Technology Division,ou=People,o=University + of Michigan,c=US +cn: Bjorn Jensen +cn: Biiff Jensen +sn: Jensen +title: Director, Embedded Systems + dn: cn=All Staff,ou=Groups,o=University of Michigan,c=US member: cn=Manager,o=University of Michigan,c=US member: cn=Barbara Jensen,ou=Information Technology Division,ou=People,o=Unive diff --git a/tests/scripts/test003-search b/tests/scripts/test003-search index f473680b31..4adf693f0a 100755 --- a/tests/scripts/test003-search +++ b/tests/scripts/test003-search @@ -75,6 +75,16 @@ if test $RC != 0 ; then exit $RC fi +echo "Testing approximate searching..." +$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ + '(sn~=jENSEN)' name >> $SEARCHOUT 2>&1 +RC=$? +if test $RC != 0 ; then + echo "ldapsearch failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + echo "Testing OR searching..." $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ '(|(givenname=Xx*yY*Z)(cn=)(undef=*)(objectclass=groupofnames)(sn~=jones)(member=cn=Manager,o=University of Michigan,c=US)(uniqueMember=cn=Manager,o=University of Michigan,c=US))' >> $SEARCHOUT 2>&1 diff --git a/tests/scripts/test009-referral b/tests/scripts/test009-referral index d20edc21d2..00a3523935 100755 --- a/tests/scripts/test009-referral +++ b/tests/scripts/test009-referral @@ -92,6 +92,16 @@ if test $RC != 0 ; then exit $RC fi +echo "Testing approximate searching..." +$LDAPSEARCH -C -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \ + '(sn=jENSEN)' name >> $SEARCHOUT 2>&1 +RC=$? +if test $RC != 0 ; then + echo "ldapsearch failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + echo "Testing OR searching..." $LDAPSEARCH -C -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \ '(|(objectclass=groupofnames)(objectClass=groupofuniquenames)(sn=jones))' >> $SEARCHOUT 2>&1 -- 2.39.5