From bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Sat, 15 Mar 2014 01:49:50 +0100 Subject: Lean and mean initial commit Not much functionality yet --- scan_ldapsearchrequest.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 scan_ldapsearchrequest.c (limited to 'scan_ldapsearchrequest.c') diff --git a/scan_ldapsearchrequest.c b/scan_ldapsearchrequest.c new file mode 100644 index 0000000..8b685bf --- /dev/null +++ b/scan_ldapsearchrequest.c @@ -0,0 +1,55 @@ +#include +#include "ldap.h" + +size_t scan_ldapsearchrequest(const char* src,const char* max, + struct SearchRequest* s) { + size_t res,tmp; + unsigned long etmp; + signed long ltmp; + s->attributes=0; + s->filter=0; + if (!(res=scan_ldapstring(src,max,&s->baseObject))) goto error; + if (!(tmp=scan_asn1ENUMERATED(src+res,max,&etmp))) goto error; + if (etmp>2) goto error; s->scope=etmp; res+=tmp; + if (!(tmp=scan_asn1ENUMERATED(src+res,max,&etmp))) goto error; + if (etmp>3) goto error; s->derefAliases=etmp; res+=tmp; + if (!(tmp=scan_asn1INTEGER(src+res,max,<mp)) || ltmp<0) goto error; + s->sizeLimit=(unsigned long)ltmp; + res+=tmp; + if (!(tmp=scan_asn1INTEGER(src+res,max,<mp)) || ltmp<0) goto error; + s->timeLimit=(unsigned long)ltmp; + res+=tmp; + if (!(tmp=scan_asn1BOOLEAN(src+res,max,&s->typesOnly))) goto error; + res+=tmp; + if (!(tmp=scan_ldapsearchfilter(src+res,max,&s->filter))) goto error; + res+=tmp; + /* now for the attributelist */ + if (!(tmp=scan_asn1SEQUENCE(src+res,max,&etmp))) goto error; + res+=tmp; + { + const char* nmax=src+res+etmp; +//#define nmax max + struct AttributeDescriptionList** a=&s->attributes; + if (nmax>max) goto error; + for (;;) { + if (src+res>nmax) goto error; + if (src+res==nmax) break; + if (!*a) *a=malloc(sizeof(struct AttributeDescriptionList)); + if (!*a) goto error; + (*a)->next=0; + if (!(tmp=scan_ldapstring(src+res,nmax,&(*a)->a))) goto error; + res+=tmp; + a=&(*a)->next; + } + return res; + } +error: + free_ldapsearchrequest(s); + return 0; +} + +void free_ldapsearchrequest(struct SearchRequest* s) { + if (s->attributes) + free_ldapadl(s->attributes); // ->next !? + free_ldapsearchfilter(s->filter); +} -- cgit v1.2.3-55-g7522