summaryrefslogtreecommitdiffstats
path: root/scan_ldapsearchrequest.c
blob: f8a366b9cca421bbf61a65d892428f222de992af (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdlib.h>
#include <string.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;
  size_t stmp;
  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,&stmp))) goto error;
  res+=tmp;
  {
    const char* nmax=src+res+stmp;
//#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=calloc(1,sizeof(struct AttributeDescriptionList));
      if (!*a) goto error;
      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);
  free_ldapsearchfilter(s->filter);
  memset(s,0,sizeof(*s));
}