diff --git a/fmt_ldapbindrequest.c b/fmt_ldapbindrequest.c index 6f56a97..d883838 100644 --- a/fmt_ldapbindrequest.c +++ b/fmt_ldapbindrequest.c @@ -3,12 +3,12 @@ #include "ldap.h" int fmt_ldapbindrequest(char* dest,long version,char* name,char* simple) { - int l,sum=0; + int l,sum; int nlen=strlen(name); sum=l=fmt_asn1INTEGER(dest,version); if (dest) dest+=l; l=fmt_asn1OCTETSTRING(dest,name,nlen); - sum+=l+nlen; if (dest) dest+=l+nlen; + sum+=l; if (dest) dest+=l; nlen=strlen(simple); l=fmt_asn1string(dest,PRIVATE,PRIMITIVE,0,simple,nlen); if (dest) dest+=l+nlen; diff --git a/ldapclient.c b/ldapclient.c index af3ee00..7977449 100644 --- a/ldapclient.c +++ b/ldapclient.c @@ -96,8 +96,10 @@ usage: int len=0,tmp,tmp2; char* max; struct SearchResultEntry sre; + int matches=0; for (;;) { long slen,mid,op; + len=0; tmp=read(sock,buf+len,sizeof(buf)-len); if (tmp<=0) { buffer_putsflush(buffer_2,"read error.\n"); @@ -106,9 +108,31 @@ usage: len+=tmp; if ((tmp2=scan_ldapmessage(buf,buf+len,&mid,&op,&slen))) { max=buf+slen+tmp2; - if (op==SearchResultEntry) break; - if (op==SearchResultDone) { - buffer_putsflush(buffer_2,"no matches.\n"); + if (op==SearchResultEntry) { + ++matches; + if ((tmp=scan_ldapsearchresultentry(buf+tmp2,max,&sre))) { + struct PartialAttributeList* pal=sre.attributes; + buffer_puts(buffer_1,"objectName \""); + buffer_put(buffer_1,sre.objectName.s,sre.objectName.l); + buffer_puts(buffer_1,"\"\n"); + while (pal) { + struct AttributeDescriptionList* adl=pal->values; + buffer_puts(buffer_1," "); + buffer_put(buffer_1,pal->type.s,pal->type.l); + buffer_puts(buffer_1,":"); + while (adl) { + buffer_put(buffer_1,adl->a.s,adl->a.l); + if (adl->next) buffer_puts(buffer_1,", "); + adl=adl->next; + } + buffer_putsflush(buffer_1,"\n"); + pal=pal->next; + } + } else + buffer_putsflush(buffer_1,"punt!\n"); + } else if (op==SearchResultDone) { + if (!matches) + buffer_putsflush(buffer_2,"no matches.\n"); return 0; } else { buffer_putsflush(buffer_2,"unexpected response.\n"); @@ -124,26 +148,6 @@ usage: close(fd); } #endif - if ((tmp=scan_ldapsearchresultentry(buf+tmp2,max,&sre))) { - struct PartialAttributeList* pal=sre.attributes; - buffer_puts(buffer_1,"objectName \""); - buffer_put(buffer_1,sre.objectName.s,sre.objectName.l); - buffer_puts(buffer_1,"\"\n"); - while (pal) { - struct AttributeDescriptionList* adl=pal->values; - buffer_puts(buffer_1," "); - buffer_put(buffer_1,pal->type.s,pal->type.l); - buffer_puts(buffer_1,":"); - while (adl) { - buffer_put(buffer_1,adl->a.s,adl->a.l); - if (adl->next) buffer_puts(buffer_1,", "); - adl=adl->next; - } - buffer_putsflush(buffer_1,"\n"); - pal=pal->next; - } - } else - buffer_putsflush(buffer_1,"punt!\n"); } } else { buffer_putsflush(buffer_2,"ldapbind failed\n"); diff --git a/tinyldap.c b/tinyldap.c index 3e0aa46..cdfaef9 100644 --- a/tinyldap.c +++ b/tinyldap.c @@ -15,6 +15,7 @@ #include "ip6.h" #include #endif +#include #define verbose 1 #define debug 1 @@ -523,7 +524,7 @@ int handle(int in,int out) { int res; long messageid,op,Len; if (tmp==0) - if (!len) { return 0; } + if (BUFSIZE-len) { return 0; } if (tmp<0) { write(2,"error!\n",7); return 1; } len+=tmp; res=scan_ldapmessage(buf,buf+len,&messageid,&op,&Len); @@ -772,6 +773,8 @@ int main() { int sock; #endif + signal(SIGPIPE,SIG_IGN); + map=mmap_read("data",&filelen); if (!map) { buffer_putsflush(buffer_2,"could not open data!\n");