From c405143a0af708b6f5ba76ae909643de5d3071e8 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Tue, 7 Sep 2010 02:03:23 +0000 Subject: [PATCH] ignore undefined attrs (ITS#6600, based on patch by Jonathan CLARKE) --- servers/slapd/overlays/pcache.c | 23 +++++++++++++---- tests/data/proxycache.out | 20 ++++++++++----- tests/scripts/test020-proxycache | 42 ++++++++++++++++++++++++++------ 3 files changed, 67 insertions(+), 18 deletions(-) diff --git a/servers/slapd/overlays/pcache.c b/servers/slapd/overlays/pcache.c index 88b90c3a32..26e28e7de9 100644 --- a/servers/slapd/overlays/pcache.c +++ b/servers/slapd/overlays/pcache.c @@ -3122,19 +3122,30 @@ get_attr_set( query_manager* qm, int num ) { - int i; + int i = 0; int count = 0; if ( attrs ) { - for ( ; attrs[count].an_name.bv_val; count++ ); + for ( ; attrs[i].an_name.bv_val; i++ ) { + /* only count valid attribute names + * (searches ignore others, this overlay does the same) */ + if ( attrs[i].an_desc ) { + count++; + } + } } - /* recognize a single "*" or a "1.1" */ - if ( count == 0 ) { + /* recognize default or explicit single "*" */ + if ( ! attrs || + ( i == 1 && bvmatch( &attrs[0].an_name, slap_bv_all_user_attrs ) ) ) + { count = 1; attrs = slap_anlist_all_user_attributes; - } else if ( count == 1 && bvmatch( &attrs[0].an_name, slap_bv_no_attrs ) ) { + /* recognize implicit (no valid attributes) or explicit single "1.1" */ + } else if ( count == 0 || + ( i == 1 && bvmatch( &attrs[0].an_name, slap_bv_no_attrs ) ) ) + { count = 0; attrs = NULL; } @@ -3155,6 +3166,8 @@ get_attr_set( } for ( a2 = attrs; a2->an_name.bv_val; a2++ ) { + if ( !a2->an_desc && !bvmatch( &a2->an_name, slap_bv_all_user_attrs ) ) continue; + if ( !an_find( qm->attr_sets[i].attrs, &a2->an_name ) ) { found = 0; break; diff --git a/tests/data/proxycache.out b/tests/data/proxycache.out index dfffc88aad..d879fd806c 100644 --- a/tests/data/proxycache.out +++ b/tests/data/proxycache.out @@ -189,7 +189,11 @@ dn: cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example, dc=com mail: bjensen@mailgw.example.com -# Query 10: filter:(|(cn=*Jones)(sn=Jones)) attrs:cn sn title uid +# Query 10: filter:(|(cn=All Staff)(sn=All Staff)) attrs:sn cn title uid undefinedAttr +dn: cn=All Staff,ou=Groups,dc=example,dc=com +cn: All Staff + +# Query 11: filter:(|(cn=*Jones)(sn=Jones)) attrs:cn sn title uid dn: cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com cn: James A Jones 1 cn: James Jones @@ -207,7 +211,7 @@ sn: Doe uid: jjones title: Senior Manager, Information Technology Division -# Query 11: filter:(sn=Smith) attrs:cn sn title uid +# Query 12: filter:(sn=Smith) attrs:cn sn title uid dn: cn=Jennifer Smith,ou=Alumni Association,ou=People,dc=example,dc=com cn: Jennifer Smith cn: Jen Smith @@ -215,7 +219,7 @@ sn: Smith uid: jen title: Telemarketer, UM Alumni Association -# Query 12: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid +# Query 13: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid dn: cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc =com cn: Bjorn Jensen @@ -225,7 +229,7 @@ postalAddress: Info Tech Division $ 535 W. William St. $ Anytown, MI 48103 mail: bjorn@mailgw.example.com telephoneNumber: +1 313 555 0355 -# Query 13: filter:(mail=jaj@mail.alumni.example.com) attrs:cn sn title uid +# Query 14: filter:(mail=jaj@mail.alumni.example.com) attrs:cn sn title uid dn: cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com cn: James A Jones 1 cn: James Jones @@ -234,7 +238,7 @@ sn: Jones uid: jaj title: Mad Cow Researcher, UM Alumni Association -# Query 14: filter:(mail=*example.com) attrs:cn sn title uid +# Query 15: filter:(mail=*example.com) attrs:cn sn title uid dn: cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example, dc=com cn: Barbara Jensen @@ -243,8 +247,12 @@ sn:: IEplbnNlbiA= uid: bjensen title: Mythical Manager, Research Systems -# Query 15: filter:(uid=b*) attrs:mail +# Query 16: filter:(uid=b*) attrs:mail dn: cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example, dc=com mail: bjensen@mailgw.example.com +# Query 17: filter:(|(cn=All Staff)(sn=All Staff)) attrs:sn cn title uid undefinedAttr +dn: cn=All Staff,ou=Groups,dc=example,dc=com +cn: All Staff + diff --git a/tests/scripts/test020-proxycache b/tests/scripts/test020-proxycache index a0b0e25e31..02cbd0323f 100755 --- a/tests/scripts/test020-proxycache +++ b/tests/scripts/test020-proxycache @@ -295,10 +295,24 @@ case $RC in ;; esac +CNT=`expr $CNT + 1` +FILTER="(|(cn=All Staff)(sn=All Staff))" +ATTRS="sn cn title uid undefinedAttr" +echo "Query $CNT: filter:$FILTER attrs:$ATTRS" +echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT +$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \ + "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT +RC=$? +if test $RC != 0 ; then + echo "ldapsearch failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + FIRST=$CNT -# queries 2-6,8-9 are cacheable -CACHEABILITY=011111011 +# queries 2-6,8-10 are cacheable +CACHEABILITY=0111110111 grep CACHEABLE $LOG2 | awk '{ if ($2 == "NOT") printf "Query %d not cacheable\n",NR @@ -431,11 +445,25 @@ case $RC in ;; esac -#queries 10-12,15 are answerable, 13-14 are not -#actually, 12 would be answerable, but since 8 made mail=*example.com +CNT=`expr $CNT + 1` +FILTER="(|(cn=All Staff)(sn=All Staff))" +ATTRS="sn cn title uid undefinedAttr" +echo "Query $CNT: filter:$FILTER attrs:$ATTRS" +echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT +$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \ + "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT +RC=$? +if test $RC != 0 ; then + echo "ldapsearch failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + +#queries 11-13,16-17 are answerable, 14-15 are not +#actually, 14 would be answerable, but since 8 made mail=*example.com #not answerable because of sizelimit, queries contained in it are no longer #answerable as well -ANSWERABILITY=111001 +ANSWERABILITY=1110011 grep ANSWERABLE $LOG2 | awk "BEGIN {FIRST=$FIRST}"'{ if (NR > FIRST) { if ($2 == "NOT") @@ -462,9 +490,9 @@ else fi echo "Filtering ldapsearch results..." -$LDIFFILTER < $SEARCHOUT > $SEARCHFLT +$LDIFFILTER -s ldif=a < $SEARCHOUT > $SEARCHFLT echo "Filtering original ldif..." -$LDIFFILTER < $PROXYCACHEOUT > $LDIFFLT +$LDIFFILTER -s ldif=a < $PROXYCACHEOUT > $LDIFFLT echo "Comparing filter output..." $CMP $SEARCHFLT $LDIFFLT > $CMPOUT -- 2.39.5