ldapclient can now be used as benchmark
link or rename the binary to "ldapbench" and pass the number of requests in $NUM in the environment. Also, a slight optimization in ldapclient (it now calls shutdown when it wrote the search request)
This commit is contained in:
11
Makefile
11
Makefile
@@ -1,4 +1,5 @@
|
||||
DEBUG=1
|
||||
#DEBUG=1
|
||||
#COVERAGE=1
|
||||
|
||||
all: t1 t2 parse dumpidx idx2ldif addindex bindrequest tinyldap \
|
||||
tinyldap_standalone tinyldap_debug ldapclient ldapclient_str \
|
||||
@@ -40,6 +41,11 @@ ifneq ($(DEBUG),)
|
||||
DIET=/opt/diet/bin/diet
|
||||
CFLAGS=-pipe -I. -Wall -W -g
|
||||
endif
|
||||
ifeq ($(COVERAGE),1)
|
||||
DIET=
|
||||
CFLAGS=-pipe -I. -g -fprofile-arcs -ftest-coverage
|
||||
endif
|
||||
|
||||
ifneq ($(DIET),)
|
||||
LIBS+=-llatin1
|
||||
else
|
||||
@@ -78,7 +84,8 @@ acl: acl.c ldap.a asn1.a
|
||||
clean:
|
||||
rm -f t t[1-9] *.[ao] bindrequest tinyldap ldapclient data \
|
||||
parse tinyldap_standalone tinyldap_debug ldapclient_str addindex \
|
||||
dumpidx idx2ldif md5password *.da *.bbg *.bb *.gcov gmon.out
|
||||
dumpidx idx2ldif md5password *.da *.bbg *.bb *.gcov gmon.out *.gcda \
|
||||
*.gcno
|
||||
|
||||
tar: clean
|
||||
cd ..; tar cvvf tinyldap.tar.bz2 tinyldap --use=bzip2 --exclude capture --exclude CVS --exclude exp.ldif --exclude polyp* --exclude rfc*
|
||||
|
||||
2
auth.c
2
auth.c
@@ -1,6 +1,4 @@
|
||||
#ifdef __FreeBSD__
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#ifdef __dietlibc__
|
||||
#include <md5.h>
|
||||
#else
|
||||
|
||||
311
ldapclient.c
311
ldapclient.c
@@ -11,6 +11,7 @@
|
||||
#include "str.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#define BUFSIZE 8192
|
||||
|
||||
@@ -40,164 +41,186 @@ int main(int argc,char* argv[]) {
|
||||
int sock;
|
||||
char buf[BUFSIZE];
|
||||
int len=0;
|
||||
char* me;
|
||||
long n,durchlauf;
|
||||
int bench;
|
||||
if ((me=strrchr(argv[0],'/')))
|
||||
++me;
|
||||
else
|
||||
me=argv[0];
|
||||
if ((bench=!strcmp(me,"ldapbench"))) {
|
||||
n=atoi(getenv("NUM"));
|
||||
buffer_putsflush(buffer_2,"benchmark mode\n");
|
||||
}
|
||||
|
||||
if (argc<4) {
|
||||
usage:
|
||||
buffer_putsflush(buffer_2,"usage: ldapclient ip baseObject filter [foo...]\n");
|
||||
return 0;
|
||||
}
|
||||
sock=socket_tcp4();
|
||||
{
|
||||
char ip[4];
|
||||
if (argv[1][scan_ip4(argv[1],ip)]) goto usage;
|
||||
if (socket_connect4(sock,ip,389)) {
|
||||
buffer_putsflush(buffer_2,"could not connect to ldap server!\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (ldapbind(sock)) {
|
||||
struct Filter *f;
|
||||
struct AttributeDescriptionList adl;
|
||||
struct AttributeDescriptionList *next;
|
||||
struct SearchRequest sr;
|
||||
int i;
|
||||
if (!scan_ldapsearchfilterstring(argv[3],&f)) {
|
||||
buffer_putsflush(buffer_2,"could not parse filter!\n");
|
||||
close(sock);
|
||||
return 1;
|
||||
}
|
||||
i=4; /* This should be the first index to an attribute argument in argv[] */
|
||||
if (argc>4) {
|
||||
adl.a.s=argv[i];
|
||||
adl.a.l=str_len(argv[i]);
|
||||
next=&adl;
|
||||
++i;
|
||||
while (i<argc) {
|
||||
struct AttributeDescriptionList *n;
|
||||
n=malloc(sizeof(struct AttributeDescriptionList));
|
||||
n->a.s=argv[i]; n->a.l=str_len(argv[i]);
|
||||
n->next=0;
|
||||
next->next=n;
|
||||
next=n;
|
||||
|
||||
#if 0
|
||||
buffer_puts(buffer_2,"requesting ");
|
||||
buffer_puts(buffer_2,argv[i]);
|
||||
buffer_putnlflush(buffer_2);
|
||||
#endif
|
||||
|
||||
i++;
|
||||
}
|
||||
sr.attributes=&adl;
|
||||
} else {
|
||||
sr.attributes=0;
|
||||
}
|
||||
sr.baseObject.s=argv[2]; sr.baseObject.l=str_len(sr.baseObject.s);
|
||||
sr.scope=wholeSubtree; sr.derefAliases=neverDerefAliases;
|
||||
sr.sizeLimit=sr.timeLimit=sr.typesOnly=0;
|
||||
sr.filter=f;
|
||||
len=fmt_ldapsearchrequest(buf+100,&sr);
|
||||
if (!bench) n=1;
|
||||
for (durchlauf=0; durchlauf<n; ++durchlauf) {
|
||||
sock=socket_tcp4();
|
||||
{
|
||||
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;
|
||||
int matches=0;
|
||||
len=0;
|
||||
for (;;) {
|
||||
long slen,mid,op;
|
||||
int cur=0;
|
||||
|
||||
tmp=read(sock,buf+len,sizeof(buf)-len);
|
||||
|
||||
#if 0
|
||||
buffer_puts(buffer_2,"DEBUG: read ");
|
||||
buffer_putulong(buffer_2,tmp);
|
||||
buffer_putsflush(buffer_2," bytes.\n");
|
||||
#endif
|
||||
|
||||
if (tmp<=0) {
|
||||
buffer_putsflush(buffer_2,"read error.\n");
|
||||
return 0;
|
||||
}
|
||||
// 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 0
|
||||
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);
|
||||
pal=pal->next;
|
||||
}
|
||||
buffer_putsflush(buffer_1,"\n");
|
||||
free_ldapsearchresultentry(&sre);
|
||||
} else {
|
||||
buffer_putsflush(buffer_2,"goto\n");
|
||||
goto copypartialandcontinue;
|
||||
}
|
||||
} else if (op==SearchResultDone) {
|
||||
if (!matches)
|
||||
buffer_putsflush(buffer_2,"no matches.\n");
|
||||
return 0;
|
||||
} else {
|
||||
buffer_putsflush(buffer_2,"unexpected response.\n");
|
||||
return 0;
|
||||
}
|
||||
if (max<buf+len) {
|
||||
cur+=slen+tmp2;
|
||||
goto nextmessage;
|
||||
} else {
|
||||
len=0;
|
||||
}
|
||||
} else {
|
||||
/* copy partial message */
|
||||
copypartialandcontinue:
|
||||
byte_copy(buf,len-cur,buf+cur);
|
||||
len-=cur; cur=0;
|
||||
}
|
||||
char ip[4];
|
||||
if (argv[1][scan_ip4(argv[1],ip)]) goto usage;
|
||||
if (socket_connect4(sock,ip,389)) {
|
||||
buffer_putsflush(buffer_2,"could not connect to ldap server!\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (ldapbind(sock)) {
|
||||
struct Filter *f;
|
||||
struct AttributeDescriptionList adl;
|
||||
struct AttributeDescriptionList *next;
|
||||
struct SearchRequest sr;
|
||||
int i;
|
||||
if (!scan_ldapsearchfilterstring(argv[3],&f)) {
|
||||
buffer_putsflush(buffer_2,"could not parse filter!\n");
|
||||
close(sock);
|
||||
return 1;
|
||||
}
|
||||
i=4; /* This should be the first index to an attribute argument in argv[] */
|
||||
if (argc>4) {
|
||||
adl.a.s=argv[i];
|
||||
adl.a.l=str_len(argv[i]);
|
||||
next=&adl;
|
||||
++i;
|
||||
while (i<argc) {
|
||||
struct AttributeDescriptionList *n;
|
||||
n=malloc(sizeof(struct AttributeDescriptionList));
|
||||
n->a.s=argv[i]; n->a.l=str_len(argv[i]);
|
||||
n->next=0;
|
||||
next->next=n;
|
||||
next=n;
|
||||
|
||||
#if 0
|
||||
buffer_puts(buffer_2,"requesting ");
|
||||
buffer_puts(buffer_2,argv[i]);
|
||||
buffer_putnlflush(buffer_2);
|
||||
#endif
|
||||
|
||||
i++;
|
||||
}
|
||||
sr.attributes=&adl;
|
||||
} else {
|
||||
sr.attributes=0;
|
||||
}
|
||||
sr.baseObject.s=argv[2]; sr.baseObject.l=str_len(sr.baseObject.s);
|
||||
sr.scope=wholeSubtree; sr.derefAliases=neverDerefAliases;
|
||||
sr.sizeLimit=sr.timeLimit=sr.typesOnly=0;
|
||||
sr.filter=f;
|
||||
len=fmt_ldapsearchrequest(buf+100,&sr);
|
||||
{
|
||||
int fd=open("/tmp/searchresultentry",O_WRONLY|O_CREAT,0600);
|
||||
write(fd,buf+tmp2,max-buf+tmp2);
|
||||
close(fd);
|
||||
int tmp=fmt_ldapmessage(0,++messageid,SearchRequest,len);
|
||||
fmt_ldapmessage(buf+100-tmp,messageid,SearchRequest,len);
|
||||
write(sock,buf+100-tmp,len+tmp);
|
||||
}
|
||||
shutdown(sock,SHUT_WR);
|
||||
{
|
||||
char buf[8192]; /* arbitrary limit, bad! */
|
||||
int len=0,tmp,tmp2;
|
||||
char* max;
|
||||
struct SearchResultEntry sre;
|
||||
int matches=0;
|
||||
len=0;
|
||||
for (;;) {
|
||||
long slen,mid,op;
|
||||
int cur=0;
|
||||
|
||||
tmp=read(sock,buf+len,sizeof(buf)-len);
|
||||
|
||||
#if 0
|
||||
buffer_puts(buffer_2,"DEBUG: read ");
|
||||
buffer_putulong(buffer_2,tmp);
|
||||
buffer_putsflush(buffer_2," bytes.\n");
|
||||
#endif
|
||||
|
||||
if (tmp<=0) {
|
||||
buffer_putsflush(buffer_2,"read error.\n");
|
||||
return 0;
|
||||
}
|
||||
// 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 0
|
||||
buffer_puts(buffer_2,"DEBUG: sre size ");
|
||||
buffer_putulong(buffer_2,tmp);
|
||||
buffer_putsflush(buffer_2,".\n");
|
||||
#endif
|
||||
|
||||
if (durchlauf==0) {
|
||||
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);
|
||||
pal=pal->next;
|
||||
}
|
||||
buffer_putsflush(buffer_1,"\n");
|
||||
}
|
||||
free_ldapsearchresultentry(&sre);
|
||||
} else {
|
||||
buffer_putsflush(buffer_2,"goto\n");
|
||||
goto copypartialandcontinue;
|
||||
}
|
||||
} else if (op==SearchResultDone) {
|
||||
if (!matches)
|
||||
buffer_putsflush(buffer_2,"no matches.\n");
|
||||
if (bench && durchlauf!=0)
|
||||
write(1,"+",1);
|
||||
break;
|
||||
// return 0;
|
||||
} else {
|
||||
buffer_putsflush(buffer_2,"unexpected response.\n");
|
||||
return 0;
|
||||
}
|
||||
if (max<buf+len) {
|
||||
cur+=slen+tmp2;
|
||||
goto nextmessage;
|
||||
} else {
|
||||
len=0;
|
||||
}
|
||||
} else {
|
||||
/* copy partial message */
|
||||
copypartialandcontinue:
|
||||
byte_copy(buf,len-cur,buf+cur);
|
||||
len-=cur; cur=0;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
{
|
||||
int fd=open("/tmp/searchresultentry",O_WRONLY|O_CREAT,0600);
|
||||
write(fd,buf+tmp2,max-buf+tmp2);
|
||||
close(fd);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
buffer_putsflush(buffer_2,"ldapbind failed\n");
|
||||
return 2;
|
||||
}
|
||||
} else {
|
||||
buffer_putsflush(buffer_2,"ldapbind failed\n");
|
||||
return 2;
|
||||
close(sock);
|
||||
}
|
||||
if (bench) write(1,"\n",1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
#ifdef __FreeBSD__
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#ifdef __dietlibc__
|
||||
#include <md5.h>
|
||||
#else
|
||||
|
||||
17
tinyldap.c
17
tinyldap.c
@@ -27,6 +27,7 @@
|
||||
#include "acl.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#include <sys/poll.h>
|
||||
#define verbose 1
|
||||
#define debug 1
|
||||
#else
|
||||
@@ -740,7 +741,7 @@ static void answerwith(uint32 ofs,struct SearchRequest* sr,long messageid,int ou
|
||||
adl[i].a.l=strlen(map+j);
|
||||
adl[i].next=adl+i+1;
|
||||
}
|
||||
adl[attribute_count-1].next=0;
|
||||
adl[attribute_count-2].next=0;
|
||||
}
|
||||
while (adl) {
|
||||
const char* val=0;
|
||||
@@ -886,8 +887,12 @@ int handle(int in,int out) {
|
||||
int tmp=read(in,buf+len,BUFSIZE-len);
|
||||
int res;
|
||||
long messageid,op,Len;
|
||||
if (tmp==0)
|
||||
if (BUFSIZE-len) { close(in); if (in!=out) close(out); return 0; }
|
||||
if (tmp==0) {
|
||||
close(in);
|
||||
if (in!=out) close(out);
|
||||
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);
|
||||
@@ -1289,6 +1294,12 @@ again:
|
||||
exit(1);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
{
|
||||
struct pollfd p;
|
||||
p.fd=0;
|
||||
p.events=POLLIN;
|
||||
if (poll(&p,1,1)==1) return;
|
||||
}
|
||||
handle(asock,asock);
|
||||
goto again;
|
||||
// exit(0);
|
||||
|
||||
Reference in New Issue
Block a user