diff --git a/Makefile b/Makefile index 6d1f196..39eff70 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ fmt_ldapsearchfilter.o fmt_ldapsearchrequest.o matchstring.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 +scan_ldapsearchfilterstring.o free_ldapsearchresultentry.o ldif.a: ldif_parse.o ldap_match_mapped.o @@ -42,7 +42,7 @@ endif ifneq ($(DIET),) LIBS+=-llatin1 else -LIBS+=-lcrypto +LIBS+=-lcrypto -lcrypt endif %.o: %.c diff --git a/ldap.h b/ldap.h index 696b566..6ef0324 100644 --- a/ldap.h +++ b/ldap.h @@ -154,6 +154,8 @@ void free_ldapsearchrequest(struct SearchRequest* s); void free_ldapmodifyrequest(struct ModifyRequest* m); /* does not free a itself */ void free_ldapaddrequest(struct AddRequest * a); +/* does not free e itself */ +void free_ldapsearchresultentry(struct SearchResultEntry* e); #endif diff --git a/ldapclient.c b/ldapclient.c index 13b2c5b..c378899 100644 --- a/ldapclient.c +++ b/ldapclient.c @@ -105,7 +105,7 @@ usage: len=0; for (;;) { long slen,mid,op; - int cur; + int cur=0; tmp=read(sock,buf+len,sizeof(buf)-len); @@ -119,43 +119,44 @@ usage: buffer_putsflush(buffer_2,"read error.\n"); return 0; } - cur=len; +// cur=len; len+=tmp; nextmessage: if ((tmp2=scan_ldapmessage(buf+cur,buf+len,&mid,&op,&slen))) { max=buf+cur+slen+tmp2; if (op==SearchResultEntry) { ++matches; - if ((tmp=scan_ldapsearchresultentry(buf+cur+tmp2,max,&sre))) { - struct PartialAttributeList* pal=sre.attributes; + if ((tmp=scan_ldapsearchresultentry(buf+cur+tmp2,max,&sre))) { + struct PartialAttributeList* pal=sre.attributes; #if 0 - buffer_puts(buffer_2,"DEBUG: sre size "); - buffer_putulong(buffer_2,tmp); - buffer_putsflush(buffer_2,".\n"); + buffer_puts(buffer_2,"DEBUG: sre size "); + buffer_putulong(buffer_2,tmp); + buffer_putsflush(buffer_2,".\n"); #endif - buffer_puts(buffer_1,"dn: "); - buffer_put(buffer_1,sre.objectName.s,sre.objectName.l); - buffer_puts(buffer_1,"\n"); - while (pal) { - struct AttributeDescriptionList* adl=pal->values; - do { - buffer_puts(buffer_1," "); - buffer_put(buffer_1,pal->type.s,pal->type.l); - buffer_puts(buffer_1,": "); - if (adl) { - buffer_put(buffer_1,adl->a.s,adl->a.l); - buffer_puts(buffer_1,"\n"); - adl=adl->next; - if (!adl) break; - } - } while (adl); - buffer_putsflush(buffer_1,"\n"); - pal=pal->next; - } - } else - goto copypartialandcontinue; + buffer_puts(buffer_1,"dn: "); + buffer_put(buffer_1,sre.objectName.s,sre.objectName.l); + buffer_puts(buffer_1,"\n"); + while (pal) { + struct AttributeDescriptionList* adl=pal->values; + do { + buffer_puts(buffer_1," "); + buffer_put(buffer_1,pal->type.s,pal->type.l); + buffer_puts(buffer_1,": "); + if (adl) { + buffer_put(buffer_1,adl->a.s,adl->a.l); + buffer_puts(buffer_1,"\n"); + adl=adl->next; + if (!adl) break; + } + } while (adl); + buffer_putsflush(buffer_1,"\n"); + pal=pal->next; + } + free_ldapsearchresultentry(&sre); + } else + goto copypartialandcontinue; } else if (op==SearchResultDone) { if (!matches) buffer_putsflush(buffer_2,"no matches.\n"); @@ -169,6 +170,10 @@ nextmessage: goto nextmessage; } } else { + if (len-cur>200) { + buffer_putsflush(buffer_2,"nanu?!\n"); + tmp2=scan_ldapmessage(buf+cur,buf+len,&mid,&op,&slen); + } /* copy partial message */ copypartialandcontinue: byte_copy(buf,len-cur,buf+cur); diff --git a/scan_ldapsearchfilterstring.c b/scan_ldapsearchfilterstring.c index e89e5a6..7adf2e2 100644 --- a/scan_ldapsearchfilterstring.c +++ b/scan_ldapsearchfilterstring.c @@ -4,7 +4,7 @@ int scan_ldapsearchfilterstring(const char* src,struct Filter** f) { char* s=(char*)src; - if (!(*f=malloc(sizeof(struct Filter)))) goto error; + if (!(*f=calloc(sizeof(struct Filter),1))) goto error; if (*s!='(') goto error; switch (*(++s)) { case '&': ++s; (*f)->type=AND; @@ -47,6 +47,7 @@ substring: while (*s!=')') { int i,j; struct Substring* substring=malloc(sizeof(struct Substring)); + if (!substring) goto error; substring->s.s=s; i=str_chr(s,')'); j=str_chr(s,'*'); @@ -67,6 +68,7 @@ substring: j=str_chr(s,'*'); if (i>j) { struct Substring* substring=malloc(sizeof(struct Substring)); + if (!substring) goto error; (*f)->type=SUBSTRING; substring->substrtype=prefix; substring->s.s=s;