add code to parse AddRequests (by Andreas Krennmair)
This commit is contained in:
6
Makefile
6
Makefile
@@ -18,9 +18,9 @@ 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 byte_case_diff.o matchcasestring.o matchcaseprefix.o \
|
||||
scan_ldapmodifyrequest.o bstrlen.o bstrfirst.o bstrstart.o \
|
||||
free_ldapadl.o free_ldappal.o free_ldapsearchfilter.o \
|
||||
matchprefix.o matchcasestring.o matchcaseprefix.o \
|
||||
scan_ldapmodifyrequest.o scan_ldapaddrequest.o bstrlen.o bstrfirst.o \
|
||||
bstrstart.o free_ldapadl.o free_ldappal.o free_ldapsearchfilter.o \
|
||||
scan_ldapsearchfilterstring.o
|
||||
|
||||
ldif.a: ldif_parse.o ldap_match_mapped.o
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
#include <ctype.h>
|
||||
|
||||
int byte_case_diff(const void* a, unsigned int len, const void* b) {
|
||||
register const char* s=a;
|
||||
register const char* t=b;
|
||||
register const char* u=t+len;
|
||||
register int j;
|
||||
j=0;
|
||||
for (;;) {
|
||||
if (t==u) break; if ((j=(tolower(*s)-tolower(*t)))) break; ++s; ++t;
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
3
case.h
3
case.h
@@ -1,3 +0,0 @@
|
||||
|
||||
int byte_case_diff(const void* a, unsigned int len, const void* b);
|
||||
|
||||
14
ldap.h
14
ldap.h
@@ -74,11 +74,22 @@ struct Modification {
|
||||
struct Modification* next;
|
||||
};
|
||||
|
||||
struct Addition {
|
||||
struct string AttributeDescription;
|
||||
struct AttributeDescriptionList vals;
|
||||
struct Addition* next;
|
||||
};
|
||||
|
||||
struct ModifyRequest {
|
||||
struct string object;
|
||||
struct Modification m;
|
||||
};
|
||||
|
||||
struct AddRequest {
|
||||
struct string entry;
|
||||
struct Addition a;
|
||||
};
|
||||
|
||||
enum ldapops {
|
||||
BindRequest=0, BindResponse=1,
|
||||
UnbindRequest=2,
|
||||
@@ -115,6 +126,7 @@ 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 scan_ldapaddrequest(const char * src, const char * max, struct AddRequest * a);
|
||||
int scan_ldapsearchfilterstring(const char* src,struct Filter** f);
|
||||
|
||||
int fmt_ldapstring(char* dest,struct string* s);
|
||||
@@ -140,6 +152,8 @@ void free_ldapsearchfilter(struct Filter* f);
|
||||
void free_ldapsearchrequest(struct SearchRequest* s);
|
||||
/* does not free m itself */
|
||||
void free_ldapmodifyrequest(struct ModifyRequest* m);
|
||||
/* does not free a itself */
|
||||
void free_ldapaddrequest(struct AddRequest * a);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -15,13 +15,13 @@ extern uint32 magic,attribute_count,record_count,indices_offset,size_of_string_t
|
||||
extern uint32 dn_ofs,objectClass_ofs;
|
||||
|
||||
static int substringmatch(struct Substring* x,const char* attr,int ignorecase) {
|
||||
int (*diff)(const void* a, unsigned int len, const void* b);
|
||||
int (*diff)(const void* a, unsigned long len, const void* b);
|
||||
if (ignorecase)
|
||||
diff=byte_case_diff;
|
||||
diff=case_diffb;
|
||||
else
|
||||
diff=byte_diff;
|
||||
while (x) {
|
||||
unsigned int i;
|
||||
unsigned long i;
|
||||
if (x->s.l>strlen(attr)) return 0;
|
||||
switch (x->substrtype) {
|
||||
case prefix:
|
||||
@@ -29,8 +29,12 @@ static int substringmatch(struct Substring* x,const char* attr,int ignorecase) {
|
||||
found:
|
||||
break;
|
||||
case any:
|
||||
for (i=0; i<x->s.l-strlen(attr); ++i) {
|
||||
if (!diff(x->s.s,x->s.l,attr+i)) goto found;
|
||||
{
|
||||
unsigned long len=strlen(attr);
|
||||
if (len<x->s.l) return 0;
|
||||
for (i=0; i<x->s.l-len; ++i)
|
||||
if (!diff(x->s.s,x->s.l,attr+i))
|
||||
goto found;
|
||||
}
|
||||
return 0;
|
||||
case suffix:
|
||||
|
||||
@@ -8,7 +8,7 @@ int matchcaseprefix(struct string* s,const char* c) {
|
||||
if (!c) return -1;
|
||||
l1=l=strlen(c);
|
||||
if (s->l<l1) l1=s->l;
|
||||
i=byte_case_diff(s->s,l1,c);
|
||||
i=case_diffb(s->s,l1,c);
|
||||
if (i) return i;
|
||||
/* one is a prefix of the other */
|
||||
if (l==s->l) return 0;
|
||||
|
||||
@@ -8,7 +8,7 @@ int matchcasestring(struct string* s,const char* c) {
|
||||
if (!c) return -1;
|
||||
l1=l=strlen(c);
|
||||
if (s->l<l1) l1=s->l;
|
||||
i=byte_case_diff(s->s,l1,c);
|
||||
i=case_diffb(s->s,l1,c);
|
||||
if (i) return i;
|
||||
/* one is a prefix of the other */
|
||||
if (l==s->l) return 0;
|
||||
|
||||
40
tinyldap.c
40
tinyldap.c
@@ -1,6 +1,7 @@
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "case.h"
|
||||
#include "byte.h"
|
||||
#include "buffer.h"
|
||||
#include "ldap.h"
|
||||
@@ -766,6 +767,41 @@ found:
|
||||
buffer_putsflush(buffer_2,"AbandonRequest!\n");
|
||||
/* do nothing */
|
||||
break;
|
||||
case AddRequest:
|
||||
{
|
||||
struct AddRequest ar;
|
||||
// buffer_putsflush(buffer_2,"AddRequest!\n");
|
||||
if ((tmp=scan_ldapaddrequest(buf+res,buf+res+len,&ar))) {
|
||||
} else {
|
||||
buffer_putsflush(buffer_2,"couldn't parse add request!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
buffer_put(buffer_1,ar.entry.s,ar.entry.l);
|
||||
buffer_putsflush(buffer_1,"\n");
|
||||
if (verbose) { /* iterate all attributes */
|
||||
struct Addition * x;
|
||||
struct AttributeDescriptionList * y;
|
||||
for (x = &ar.a;x;x=x->next) {
|
||||
for (y = &x->vals;y;y=y->next) {
|
||||
buffer_put(buffer_1,x->AttributeDescription.s,x->AttributeDescription.l);
|
||||
buffer_puts(buffer_1,": ");
|
||||
buffer_put(buffer_1,y->a.s,y->a.l);
|
||||
buffer_putsflush(buffer_1,"\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
char outbuf[1024];
|
||||
int s=100;
|
||||
int len=fmt_ldapbindresponse(outbuf+s,0,"","","");
|
||||
int hlen=fmt_ldapmessage(0,messageid,AddResponse,len);
|
||||
fmt_ldapmessage(outbuf+s-hlen,messageid,AddResponse,len);
|
||||
write(out,outbuf+s-hlen,len+hlen);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
buffer_puts(buffer_2,"unknown request type ");
|
||||
buffer_putulong(buffer_2,op);
|
||||
@@ -819,9 +855,9 @@ int main() {
|
||||
j=uint32_read(x);
|
||||
if (!strcmp("dn",map+j))
|
||||
dn_ofs=j;
|
||||
else if (!strcasecmp("objectClass",map+j))
|
||||
else if (case_equals("objectClass",map+j))
|
||||
objectClass_ofs=j;
|
||||
else if (!strcasecmp("userPassword",map+j))
|
||||
else if (case_equals("userPassword",map+j))
|
||||
userPassword_ofs=j;
|
||||
x+=4;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user