From 0b2a282ec0b7e34f201ef936c31412612d6c2867 Mon Sep 17 00:00:00 2001 From: leitner Date: Wed, 3 Apr 2002 13:44:15 +0000 Subject: [PATCH] begin work on modifyrequest parser --- Makefile | 4 +-- TODO | 4 +++ ldap.h | 14 +++++++++ scan_ldapmodifyrequest.c | 68 ++++++++++++++++++++++++++++++++++++++++ tinyldap.c | 30 ++++++++++++++++++ 5 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 TODO create mode 100644 scan_ldapmodifyrequest.c diff --git a/Makefile b/Makefile index ac1ece0..2815524 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ 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 +matchprefix.o scan_ldapmodifyrequest.o ldif.a: ldif_parse.o ldap_match.o ldap_match_mapped.o @@ -59,7 +59,7 @@ parse tinyldap_standalone tinyldap_debug ldapclient_str addindex \ dumpidx *.da *.bbg *.bb *.gcov gmon.out tar: clean - cd ..; tar cvvf ldap.tar.bz2 ldap --use=bzip2 --exclude CVS --exclude exp.ldif --exclude polyp* --exclude rfc* + cd ..; tar cvvf tinyldap.tar.bz2 tinyldap --use=bzip2 --exclude capture --exclude CVS --exclude exp.ldif --exclude polyp* --exclude rfc* fmt_asn1int.o: fmt_asn1int.c fmt_asn1intpayload.o: fmt_asn1intpayload.c diff --git a/TODO b/TODO new file mode 100644 index 0000000..76b6b61 --- /dev/null +++ b/TODO @@ -0,0 +1,4 @@ + + - add support for case insensitive matching + - add real dn parsing + - add write support with an external journal diff --git a/ldap.h b/ldap.h index 7fbec64..6a06bf5 100644 --- a/ldap.h +++ b/ldap.h @@ -59,6 +59,18 @@ struct SearchResultEntry { struct PartialAttributeList* attributes; }; +struct Modification { + enum { Add=0, Delete=1, Replace=2 } operation; + struct string AttributeDescription; /* ? */ + struct AttributeDescriptionList vals; + struct Modification* next; +}; + +struct ModifyRequest { + struct string object; + struct Modification m; +}; + enum ldapops { BindRequest=0, BindResponse=1, UnbindRequest=2, @@ -92,6 +104,7 @@ int scan_ldapsearchresultentry(const char* src,const char* max,struct SearchResu 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 fmt_ldapstring(char* dest,struct string* s); int fmt_ldapmessage(char* dest,long messageid,long op,long len); @@ -104,6 +117,7 @@ int fmt_ldappal(char* dest,struct PartialAttributeList* pal); int fmt_ldapava(char* dest,struct AttributeValueAssertion* a); int fmt_ldapadl(char* dest,struct AttributeDescriptionList* adl); int fmt_ldapavl(char* dest,struct AttributeDescriptionList* adl); +int fmt_ldapmodifyrequest(char* dest,struct ModifyRequest* m); #define fmt_ldapbindresponse(a,b,c,d,e) fmt_ldapresult(a,b,c,d,e) #define fmt_ldapsearchresultdone(a,b,c,d,e) fmt_ldapresult(a,b,c,d,e) diff --git a/scan_ldapmodifyrequest.c b/scan_ldapmodifyrequest.c new file mode 100644 index 0000000..f69b751 --- /dev/null +++ b/scan_ldapmodifyrequest.c @@ -0,0 +1,68 @@ +#include +#include "asn1.h" +#include "ldap.h" + +#if 0 + ModifyRequest ::= [APPLICATION 6] SEQUENCE { + object LDAPDN, + modification SEQUENCE OF SEQUENCE { + operation ENUMERATED { + add (0), + delete (1), + replace (2) }, + modification AttributeTypeAndValues } } + + AttributeTypeAndValues ::= SEQUENCE { + type AttributeDescription, + vals SET OF AttributeValue } +#endif + +int scan_ldapmodifyrequest(const char* src,const char* max,struct ModifyRequest* m) { + int res,tmp; + long oslen; /* outer sequence length */ + struct Modification* last=0; + if (!(res=scan_ldapstring(src,max,&m->object))) goto error; + if (!(tmp=scan_asn1SEQUENCE(src+res,max,&oslen))) goto error; + res+=tmp; + if (src+res+oslen>max) goto error; + max=src+res+oslen; + if (src+res>=max) goto error; /* need at least one record */ + do { + long islen, etmp; + if (last) { + struct Modification* cur; + if (!(cur=malloc(sizeof(struct Modification)))) goto error; + last->next=cur; last=cur; + } else + last=&m->m; + last->next=0; + if (!(tmp=scan_asn1SEQUENCE(src+res,max,&islen))) goto error; + res+=tmp; + if (!(tmp=scan_asn1ENUMERATED(src+res,max,&etmp))) goto error; + if (etmp>2) goto error; last->operation=etmp; res+=tmp; + { + long iislen; /* urgh, _three_ levels of indirection */ + const char* imax; + if (!(tmp=scan_asn1SEQUENCE(src+res,max,&iislen))) goto error; + imax=src+res+iislen; + if (imax>max) goto error; + res+=tmp; + if (!(tmp=scan_ldapstring(src+res,imax,&last->AttributeDescription))) goto error; + res+=tmp; + { + long iiislen; /* urgh, _four_ levels of indirection */ + const char* iimax; + if (!(tmp=scan_asn1SET(src+res,max,&iiislen))) goto error; + iimax=src+res+iiislen; + if (src+res+iiislen!=imax) goto error; res+=tmp; + while (src+res \""); + buffer_put(buffer_1,x->a.s,x->a.l); + buffer_putsflush(buffer_1,"\"\n"); + x=x->next; + } while (x); + } + } else { + buffer_putsflush(buffer_2,"couldn't parse modify request!\n"); + exit(1); + } + } default: buffer_puts(buffer_2,"unknown request type "); buffer_putulong(buffer_2,op);