From 7f7fb3c2f9913cf0379f579326fd6a751d6fdd31 Mon Sep 17 00:00:00 2001 From: leitner Date: Mon, 14 Jan 2002 21:50:49 +0000 Subject: [PATCH] parse substring search correctly --- ldap.h | 10 +++++++--- scan_ldapsearchfilter.c | 17 +++++++++++++++-- t2.c | 18 ++++++++++++++++-- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/ldap.h b/ldap.h index c7718a6..57849b2 100644 --- a/ldap.h +++ b/ldap.h @@ -21,15 +21,19 @@ struct PartialAttributeList { struct PartialAttributeList* next; }; +struct Substring { + enum { prefix=0, any=1, suffix=2 } substrtype; + struct string s; + struct Substring* next; +}; + struct Filter { enum { AND=0, OR=1, NOT=2, EQUAL=3, SUBSTRING=4, GREATEQUAL=5, LESSEQUAL=6, PRESENT=7, APPROX=8, EXTENSIBLE=9 } type; struct AttributeValueAssertion ava; + struct Substring* substrings; struct AttributeDescriptionList *a; - enum { - PREFIX=0, ANY=1, SUFFIX=2 - } substrtype; struct Filter* x,*next; }; diff --git a/scan_ldapsearchfilter.c b/scan_ldapsearchfilter.c index cc923f2..e2955a2 100644 --- a/scan_ldapsearchfilter.c +++ b/scan_ldapsearchfilter.c @@ -79,9 +79,22 @@ int scan_ldapsearchfilter(const char* src,const char* max,struct Filter** f) { if (!(tmp=scan_ldapstring(src+res,nmax,&(*f)->ava.desc))) goto error; res+=tmp; if (!(tmp=scan_asn1SEQUENCE(src+res,nmax,&len2))) goto error; - if (src+tmp+len2!=nmax) goto error; res+=tmp; - goto error; /* TODO */ + if (src+res+len2!=nmax) goto error; + while (src+ress.s,&s->s.l))) goto error; + if (x>2) goto error; + s->substrtype=x; + res+=tmp; + s->next=(*f)->substrings; + (*f)->substrings=s; + } + break; } case 7: /* present [7] AttributeDescription, */ goto error; diff --git a/t2.c b/t2.c index 780c8e9..facfd95 100644 --- a/t2.c +++ b/t2.c @@ -36,7 +36,21 @@ mergesub: printava(&f->ava,"=="); break; case SUBSTRING: - printava(&f->ava,"\\in"); + { + struct Substring* s=f->substrings; + int first=1; + printf("%.*s has ",(int)f->ava.desc.l,f->ava.desc.s); + while (s) { + if (!first) printf(" and "); first=0; + switch(s->substrtype) { + case prefix: printf("prefix \""); break; + case any: printf("substr \""); break; + case suffix: printf("suffix \""); break; + } + printf("%.*s\"",(int)s->s.l,s->s.s); + s=s->next; + } + } break; case GREATEQUAL: printava(&f->ava,">="); @@ -64,7 +78,7 @@ int main(int argc,char* argv[]) { #if 1 unsigned long size; // char* ldapsequence=mmap_read("req",&size); - char* ldapsequence=mmap_read(argc>1?argv[1]:"capture/127.000.000.001.32779-127.000.000.001.00389",&size); + char* ldapsequence=mmap_read(argc>1?argv[1]:"capture/127.000.000.001.38433-127.000.000.001.00389",&size); long messageid, op, len; int res,done=0; while (done