From 60ee9f82b188eebd437cd22fda3f10ca9b830cff Mon Sep 17 00:00:00 2001 From: leitner Date: Wed, 16 Jan 2002 16:05:38 +0000 Subject: [PATCH] make ldapclient print the search result --- ldapclient.c | 41 ++++++++++++++++++++++++++++++++++++++++- t2.c | 4 ++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/ldapclient.c b/ldapclient.c index 685140c..55af04a 100644 --- a/ldapclient.c +++ b/ldapclient.c @@ -1,9 +1,15 @@ #include +#include #include "byte.h" #include "buffer.h" +#include "asn1.h" #include "ldap.h" #include "socket.h" #include "ip4.h" +#include "str.h" + +#define INCLUDE +#include "t2.c" #define BUFSIZE 8192 @@ -67,12 +73,45 @@ usage: sr.attributes=&adl; len=fmt_ldapsearchrequest(buf+100,&sr); { - int tmp=fmt_ldapmessage(buf,++messageid,SearchRequest,len); + int tmp=fmt_ldapmessage(0,++messageid,SearchRequest,len); fmt_ldapmessage(buf+100-tmp,messageid,SearchRequest,len); write(sock,buf+100-tmp,len+tmp); } + { + char buf[8192]; /* arbitrary limit, bad! */ + int len=0,tmp,tmp2; + char* max; + struct SearchResultEntry sre; + for (;;) { + long slen,mid,op; + tmp=read(sock,buf+len,sizeof(buf)-len); + len+=tmp; + if ((tmp2=scan_ldapmessage(buf,buf+len,&mid,&op,&slen))) + if (op==SearchResultEntry) { + max=buf+slen+tmp2; + break; + } + } + if ((tmp=scan_ldapsearchresultentry(buf+tmp2,max,&sre))) { + struct PartialAttributeList* pal=sre.attributes; + printf("objectName \"%.*s\"\n",(int)sre.objectName.l,sre.objectName.s); + while (pal) { + struct AttributeDescriptionList* adl=pal->values; + printf(" %.*s:",(int)pal->type.l,pal->type.s); + while (adl) { + printf("%.*s",(int)adl->a.l,adl->a.s); + if (adl->next) printf(", "); + adl=adl->next; + } + printf("\n"); + pal=pal->next; + } + } else + puts("punt!"); + } } else { buffer_putsflush(buffer_2,"ldapbind failed\n"); return 2; } + return 0; } diff --git a/t2.c b/t2.c index cdbfdc0..6fd8e12 100644 --- a/t2.c +++ b/t2.c @@ -1,8 +1,10 @@ +#ifndef INCLUDE #include #include #include "mmap.h" #include "asn1.h" #include "ldap.h" +#endif /* this is some sort of protocol analyzer. You give it a file name with * a network dump of an LDAP correspondence, and it will try to parse it @@ -78,6 +80,7 @@ mergesub: } } +#ifndef INCLUDE int main(int argc,char* argv[]) { #if 1 unsigned long size; @@ -225,3 +228,4 @@ int main(int argc,char* argv[]) { #endif return 0; } +#endif