diff options
author | Simon Rettberg | 2014-03-15 01:49:50 +0100 |
---|---|---|
committer | Simon Rettberg | 2014-03-15 01:49:50 +0100 |
commit | bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad (patch) | |
tree | c7d1995a09f6ed0c4e6873252e957d72f5d07d07 /scan_ldapaddrequest.c | |
download | ldadp-bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad.tar.gz ldadp-bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad.tar.xz ldadp-bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad.zip |
Lean and mean initial commit
Not much functionality yet
Diffstat (limited to 'scan_ldapaddrequest.c')
-rw-r--r-- | scan_ldapaddrequest.c | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/scan_ldapaddrequest.c b/scan_ldapaddrequest.c new file mode 100644 index 0000000..9fb4b1d --- /dev/null +++ b/scan_ldapaddrequest.c @@ -0,0 +1,95 @@ +#include <stdlib.h> +#include "ldap.h" +#include "buffer.h" +#include "byte.h" + +#if 0 + AddRequest ::= [APPLICATION 8] SEQUENCE { + entry LDAPDN, + attributes SEQUENCE OF SEQUENCE { + type AttributeDescription, + vals SET OF AttributeValue } } + + AttributeList ::= SEQUENCE OF SEQUENCE { + type AttributeDescription, + vals SET OF AttributeValue } +#endif + +size_t scan_ldapaddrequest(const char* src,const char* max,struct AddRequest* a) { + size_t res,tmp,oslen; + struct Addition* last=0; + byte_zero(a,sizeof(*a)); + if (!(res=scan_ldapstring(src,max,&a->entry))) 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 { + size_t islen; + if (last) { + struct Addition* cur; + if (!(cur=malloc(sizeof(struct Addition)))) + goto error; + last->next=cur; + last=cur; + } else { + last=&a->a; + } + last->next=0; + if (!(tmp=scan_asn1SEQUENCE(src+res,max,&islen))) + goto error; + res+=tmp; + /* scan AttributeDescription: */ + if (!(tmp=scan_ldapstring(src+res,max,&last->AttributeDescription))) + goto error; + res+=tmp; + + /* scan set of AttributeValue: */ + { + size_t set_len; + const char* set_max; + struct AttributeDescriptionList* ilast=0; + if (!(tmp=scan_asn1SET(src+res,max,&set_len))) { + goto error; + } + res+=tmp; + set_max=src+res+set_len; + if (src+res+set_len!=set_max) { + goto error; + } + while (src+res<set_max) { + if (ilast) { + struct AttributeDescriptionList* x; + if (!(x=malloc(sizeof(struct AttributeDescriptionList)))) goto error; + ilast->next=x; + ilast = ilast->next; + } else { + ilast=&last->vals; + } + ilast->next=0; + if (!(tmp=scan_ldapstring(src+res,max,&ilast->a))) + goto error; + res+=tmp; + } + } + } while (src+res<max); +// buffer_putsflush(buffer_2,"done with scan_ldapaddrequest!\n"); + return res; +error: + free_ldapaddrequest(a); + return 0; +} + +static void free_add(struct Addition * a) { + while (a) { + struct Addition * tmp = a->next; + free(a); + a = tmp; + } +} + +void free_ldapaddrequest(struct AddRequest * a) { + free_ldapadl(a->a.vals.next); + free_add(a->a.next); +} |