summaryrefslogtreecommitdiffstats
path: root/scan_ldapsearchrequest.c
diff options
context:
space:
mode:
authorSimon Rettberg2014-03-15 01:49:50 +0100
committerSimon Rettberg2014-03-15 01:49:50 +0100
commitbedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad (patch)
treec7d1995a09f6ed0c4e6873252e957d72f5d07d07 /scan_ldapsearchrequest.c
downloadldadp-bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad.tar.gz
ldadp-bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad.tar.xz
ldadp-bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad.zip
Lean and mean initial commit
Not much functionality yet
Diffstat (limited to 'scan_ldapsearchrequest.c')
-rw-r--r--scan_ldapsearchrequest.c55
1 files changed, 55 insertions, 0 deletions
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 <stdlib.h>
+#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,&ltmp)) || ltmp<0) goto error;
+ s->sizeLimit=(unsigned long)ltmp;
+ res+=tmp;
+ if (!(tmp=scan_asn1INTEGER(src+res,max,&ltmp)) || 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);
+}