From 73e9cf8902e6e8a552ffe8b0b5b48b2dde492aa7 Mon Sep 17 00:00:00 2001 From: leitner Date: Mon, 1 Sep 2003 15:34:34 +0000 Subject: [PATCH] add code to parse AddRequests (by Andreas Krennmair) --- Makefile | 6 +++--- byte_case_diff.c | 14 -------------- case.h | 3 --- ldap.h | 14 ++++++++++++++ ldap_match_mapped.c | 14 +++++++++----- matchcaseprefix.c | 2 +- matchcasestring.c | 2 +- tinyldap.c | 40 ++++++++++++++++++++++++++++++++++++++-- 8 files changed, 66 insertions(+), 29 deletions(-) delete mode 100644 byte_case_diff.c delete mode 100644 case.h diff --git a/Makefile b/Makefile index c900fed..8400495 100644 --- a/Makefile +++ b/Makefile @@ -18,9 +18,9 @@ freefilter.o freeava.o scan_ldapava.o fmt_ldapsearchresultentry.o \ fmt_ldapstring.o freepal.o scan_ldapsearchresultentry.o \ fmt_ldapresult.o fmt_ldappal.o fmt_ldapadl.o fmt_ldapava.o \ fmt_ldapsearchfilter.o fmt_ldapsearchrequest.o matchstring.o \ -matchprefix.o byte_case_diff.o matchcasestring.o matchcaseprefix.o \ -scan_ldapmodifyrequest.o bstrlen.o bstrfirst.o bstrstart.o \ -free_ldapadl.o free_ldappal.o free_ldapsearchfilter.o \ +matchprefix.o matchcasestring.o matchcaseprefix.o \ +scan_ldapmodifyrequest.o scan_ldapaddrequest.o bstrlen.o bstrfirst.o \ +bstrstart.o free_ldapadl.o free_ldappal.o free_ldapsearchfilter.o \ scan_ldapsearchfilterstring.o ldif.a: ldif_parse.o ldap_match_mapped.o diff --git a/byte_case_diff.c b/byte_case_diff.c deleted file mode 100644 index d596a9c..0000000 --- a/byte_case_diff.c +++ /dev/null @@ -1,14 +0,0 @@ -#include - -int byte_case_diff(const void* a, unsigned int len, const void* b) { - register const char* s=a; - register const char* t=b; - register const char* u=t+len; - register int j; - j=0; - for (;;) { - if (t==u) break; if ((j=(tolower(*s)-tolower(*t)))) break; ++s; ++t; - } - return j; -} - diff --git a/case.h b/case.h deleted file mode 100644 index b0fa6f5..0000000 --- a/case.h +++ /dev/null @@ -1,3 +0,0 @@ - -int byte_case_diff(const void* a, unsigned int len, const void* b); - diff --git a/ldap.h b/ldap.h index 5e4a7b0..696b566 100644 --- a/ldap.h +++ b/ldap.h @@ -74,11 +74,22 @@ struct Modification { struct Modification* next; }; +struct Addition { + struct string AttributeDescription; + struct AttributeDescriptionList vals; + struct Addition* next; +}; + struct ModifyRequest { struct string object; struct Modification m; }; +struct AddRequest { + struct string entry; + struct Addition a; +}; + enum ldapops { BindRequest=0, BindResponse=1, UnbindRequest=2, @@ -115,6 +126,7 @@ int scan_ldapresult(const char* src,const char* max,long* result, struct string* matcheddn,struct string* errormessage, struct string* referral); int scan_ldapmodifyrequest(const char* src,const char* max,struct ModifyRequest* m); +int scan_ldapaddrequest(const char * src, const char * max, struct AddRequest * a); int scan_ldapsearchfilterstring(const char* src,struct Filter** f); int fmt_ldapstring(char* dest,struct string* s); @@ -140,6 +152,8 @@ void free_ldapsearchfilter(struct Filter* f); void free_ldapsearchrequest(struct SearchRequest* s); /* does not free m itself */ void free_ldapmodifyrequest(struct ModifyRequest* m); +/* does not free a itself */ +void free_ldapaddrequest(struct AddRequest * a); #endif diff --git a/ldap_match_mapped.c b/ldap_match_mapped.c index 77651f5..6718360 100644 --- a/ldap_match_mapped.c +++ b/ldap_match_mapped.c @@ -15,13 +15,13 @@ extern uint32 magic,attribute_count,record_count,indices_offset,size_of_string_t extern uint32 dn_ofs,objectClass_ofs; static int substringmatch(struct Substring* x,const char* attr,int ignorecase) { - int (*diff)(const void* a, unsigned int len, const void* b); + int (*diff)(const void* a, unsigned long len, const void* b); if (ignorecase) - diff=byte_case_diff; + diff=case_diffb; else diff=byte_diff; while (x) { - unsigned int i; + unsigned long i; if (x->s.l>strlen(attr)) return 0; switch (x->substrtype) { case prefix: @@ -29,8 +29,12 @@ static int substringmatch(struct Substring* x,const char* attr,int ignorecase) { found: break; case any: - for (i=0; is.l-strlen(attr); ++i) { - if (!diff(x->s.s,x->s.l,attr+i)) goto found; + { + unsigned long len=strlen(attr); + if (lens.l) return 0; + for (i=0; is.l-len; ++i) + if (!diff(x->s.s,x->s.l,attr+i)) + goto found; } return 0; case suffix: diff --git a/matchcaseprefix.c b/matchcaseprefix.c index 440b2de..0d006be 100644 --- a/matchcaseprefix.c +++ b/matchcaseprefix.c @@ -8,7 +8,7 @@ int matchcaseprefix(struct string* s,const char* c) { if (!c) return -1; l1=l=strlen(c); if (s->ll; - i=byte_case_diff(s->s,l1,c); + i=case_diffb(s->s,l1,c); if (i) return i; /* one is a prefix of the other */ if (l==s->l) return 0; diff --git a/matchcasestring.c b/matchcasestring.c index eb5b1ac..242cefc 100644 --- a/matchcasestring.c +++ b/matchcasestring.c @@ -8,7 +8,7 @@ int matchcasestring(struct string* s,const char* c) { if (!c) return -1; l1=l=strlen(c); if (s->ll; - i=byte_case_diff(s->s,l1,c); + i=case_diffb(s->s,l1,c); if (i) return i; /* one is a prefix of the other */ if (l==s->l) return 0; diff --git a/tinyldap.c b/tinyldap.c index faa7f34..d086bcc 100644 --- a/tinyldap.c +++ b/tinyldap.c @@ -1,6 +1,7 @@ #include #include #include +#include "case.h" #include "byte.h" #include "buffer.h" #include "ldap.h" @@ -766,6 +767,41 @@ found: buffer_putsflush(buffer_2,"AbandonRequest!\n"); /* do nothing */ break; + case AddRequest: + { + struct AddRequest ar; +// buffer_putsflush(buffer_2,"AddRequest!\n"); + if ((tmp=scan_ldapaddrequest(buf+res,buf+res+len,&ar))) { + } else { + buffer_putsflush(buffer_2,"couldn't parse add request!\n"); + exit(1); + } + + buffer_put(buffer_1,ar.entry.s,ar.entry.l); + buffer_putsflush(buffer_1,"\n"); + if (verbose) { /* iterate all attributes */ + struct Addition * x; + struct AttributeDescriptionList * y; + for (x = &ar.a;x;x=x->next) { + for (y = &x->vals;y;y=y->next) { + buffer_put(buffer_1,x->AttributeDescription.s,x->AttributeDescription.l); + buffer_puts(buffer_1,": "); + buffer_put(buffer_1,y->a.s,y->a.l); + buffer_putsflush(buffer_1,"\n"); + } + } + } + + { + char outbuf[1024]; + int s=100; + int len=fmt_ldapbindresponse(outbuf+s,0,"","",""); + int hlen=fmt_ldapmessage(0,messageid,AddResponse,len); + fmt_ldapmessage(outbuf+s-hlen,messageid,AddResponse,len); + write(out,outbuf+s-hlen,len+hlen); + } + } + break; default: buffer_puts(buffer_2,"unknown request type "); buffer_putulong(buffer_2,op); @@ -819,9 +855,9 @@ int main() { j=uint32_read(x); if (!strcmp("dn",map+j)) dn_ofs=j; - else if (!strcasecmp("objectClass",map+j)) + else if (case_equals("objectClass",map+j)) objectClass_ofs=j; - else if (!strcasecmp("userPassword",map+j)) + else if (case_equals("userPassword",map+j)) userPassword_ofs=j; x+=4; }