add md5password (convert argv to md5 password string with base64 for ldif)
fix ldapclient to use all the arguments and cope with fused packets (one read() returning the search result entry and the end marker). Make ldif_parse() use strallocs (remove 8k limit on payloads)
This commit is contained in:
4
Makefile
4
Makefile
@@ -1,6 +1,8 @@
|
||||
DEBUG=1
|
||||
|
||||
all: t1 t2 parse dumpidx idx2ldif addindex bindrequest tinyldap tinyldap_standalone tinyldap_debug ldapclient ldapclient_str # t
|
||||
all: t1 t2 parse dumpidx idx2ldif addindex bindrequest tinyldap \
|
||||
tinyldap_standalone tinyldap_debug ldapclient ldapclient_str \
|
||||
md5password # t
|
||||
|
||||
asn1.a: fmt_asn1intpayload.o fmt_asn1length.o fmt_asn1tag.o \
|
||||
fmt_asn1int.o fmt_asn1string.o fmt_asn1transparent.o scan_asn1tag.o \
|
||||
|
||||
15
ldapclient.c
15
ldapclient.c
@@ -76,8 +76,14 @@ usage:
|
||||
struct AttributeDescriptionList *n;
|
||||
n=malloc(sizeof(struct AttributeDescriptionList));
|
||||
n->a.s=argv[i]; n->a.l=strlen(argv[i]);
|
||||
n->next=next;
|
||||
n->next=0;
|
||||
next->next=n;
|
||||
next=n;
|
||||
|
||||
buffer_puts(buffer_2,"requesting ");
|
||||
buffer_puts(buffer_2,argv[i]);
|
||||
buffer_putnlflush(buffer_2);
|
||||
|
||||
i++;
|
||||
}
|
||||
sr.baseObject.s=argv[2]; sr.baseObject.l=strlen(sr.baseObject.s);
|
||||
@@ -106,6 +112,7 @@ usage:
|
||||
return 0;
|
||||
}
|
||||
len+=tmp;
|
||||
nextmessage:
|
||||
if ((tmp2=scan_ldapmessage(buf,buf+len,&mid,&op,&slen))) {
|
||||
max=buf+slen+tmp2;
|
||||
if (op==SearchResultEntry) {
|
||||
@@ -138,6 +145,12 @@ usage:
|
||||
buffer_putsflush(buffer_2,"unexpected response.\n");
|
||||
return 0;
|
||||
}
|
||||
if (max<buf+len) {
|
||||
byte_copy(buf,buf+len-max,max);
|
||||
tmp-=(max-(buf+len));
|
||||
len-=(max-(buf+len));
|
||||
goto nextmessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
72
ldif_parse.c
72
ldif_parse.c
@@ -10,6 +10,7 @@
|
||||
#include "ldif.h"
|
||||
#include "byte.h"
|
||||
#include "textcode.h"
|
||||
#include "stralloc.h"
|
||||
|
||||
mduptab_t attributes,classes;
|
||||
mstorage_t stringtable;
|
||||
@@ -67,6 +68,8 @@ static int parserec(buffer* b, struct ldaprec** l) {
|
||||
char buf[8192];
|
||||
int n,i,eof=0,ofs=0;
|
||||
int len,base64;
|
||||
stralloc payload={0,0,0};
|
||||
|
||||
if (!(*l=malloc(sizeof(struct ldaprec)))) return 2;
|
||||
(*l)->dn=-1;
|
||||
(*l)->next=0; (*l)->n=0;
|
||||
@@ -75,12 +78,7 @@ static int parserec(buffer* b, struct ldaprec** l) {
|
||||
long tmp, val;
|
||||
base64=0;
|
||||
n=ofs+buffer_get_token(b,buf+ofs,8192-ofs,":",1);
|
||||
buffer_feed(b);
|
||||
if (*buffer_peek(b)==':') {
|
||||
char dummy;
|
||||
base64=1;
|
||||
buffer_getc(b,&dummy);
|
||||
}
|
||||
if (n==0) break;
|
||||
i=scan_whitenskip(buf,n);
|
||||
buf[n]=0;
|
||||
if ((tmp=mduptab_adds(&attributes,buf+i))<0) {
|
||||
@@ -88,10 +86,20 @@ nomem:
|
||||
buffer_putsflush(buffer_2,"out of memory!\n");
|
||||
return 1;
|
||||
}
|
||||
n=buffer_get_token(b,buf,8192,"\n",1);
|
||||
if (n==0) break;
|
||||
i=scan_whitenskip(buf,n);
|
||||
buf[n]=0;
|
||||
if (!stralloc_copys(&payload,"")) return 2;
|
||||
{
|
||||
char dummy;
|
||||
int res;
|
||||
/* read line, skipping initial whitespace */
|
||||
for (n=0; (res=buffer_getc(b,&dummy))==1; ) {
|
||||
if (dummy=='\n') break;
|
||||
if (!n && dummy==':' && base64==0) { base64=1; continue; }
|
||||
if (!n && (dummy==' ' || dummy=='\t')) continue;
|
||||
if (!stralloc_append(&payload,&dummy)) return 2;
|
||||
++n;
|
||||
}
|
||||
if (res==-1) return 1;
|
||||
}
|
||||
|
||||
lookagain:
|
||||
{
|
||||
@@ -102,34 +110,36 @@ lookagain:
|
||||
}
|
||||
if (c==' ') { /* continuation */
|
||||
// puts("continuation!");
|
||||
n+=buffer_get_token(b,buf+n,8192-n,"\n",1);
|
||||
buf[n]=0;
|
||||
n=buffer_get_token(b,buf,8192,"\n",1);
|
||||
if (n==-1) return 1;
|
||||
stralloc_catb(&payload,buf,n);
|
||||
goto lookagain;
|
||||
} else if (c=='\n') {
|
||||
struct ldaprec* m=malloc(sizeof(struct ldaprec));
|
||||
if (!m) return 2;
|
||||
|
||||
stralloc_0(&payload);
|
||||
if (base64) {
|
||||
len=unbase64(buf+i);
|
||||
buf[i+len]=0; ++len;
|
||||
len=unbase64(payload.s);
|
||||
payload.s[len]=0; ++len;
|
||||
} else
|
||||
len=n-i+1;
|
||||
len=n+1;
|
||||
|
||||
#if 0
|
||||
buffer_puts(buffer_2,"feld \"");
|
||||
buffer_puts(buffer_2,attributes.strings.root+tmp);
|
||||
buffer_puts(buffer_2,"\", wert \"");
|
||||
buffer_put(buffer_2,buf+i,len);
|
||||
buffer_put(buffer_2,payload.s,len);
|
||||
buffer_putsflush(buffer_2,"\".\n");
|
||||
#endif
|
||||
|
||||
if (tmp==objectClass) {
|
||||
if ((val=mduptab_add(&classes,buf+i,len-1))<0) goto nomem;
|
||||
if ((val=mduptab_add(&classes,payload.s,len-1))<0) goto nomem;
|
||||
} else if (tmp==dn) {
|
||||
char* newdn=alloca(len);
|
||||
if ((val=mstorage_add(&stringtable,newdn,normalize_dn(newdn,buf+i,len)))<0) goto nomem;
|
||||
if ((val=mstorage_add(&stringtable,newdn,normalize_dn(newdn,payload.s,len)))<0) goto nomem;
|
||||
} else
|
||||
if ((val=mstorage_add(&stringtable,buf+i,len))<0) goto nomem;
|
||||
if ((val=mstorage_add(&stringtable,payload.s,len))<0) goto nomem;
|
||||
addattribute(l,tmp,val);
|
||||
|
||||
(*l)->next=m;
|
||||
@@ -147,26 +157,28 @@ lookagain:
|
||||
// buf[n]=0;
|
||||
#if 1
|
||||
|
||||
stralloc_0(&payload);
|
||||
if (base64) {
|
||||
len=unbase64(buf+i);
|
||||
buf[len+i]=0; ++len;
|
||||
len=unbase64(payload.s);
|
||||
payload.s[len]=0; ++len;
|
||||
} else
|
||||
len=n-i+1;
|
||||
len=n+1;
|
||||
|
||||
#if 0
|
||||
buffer_puts(buffer_2,"feld \"");
|
||||
buffer_puts(buffer_2,attributes.strings.root+tmp);
|
||||
buffer_puts(buffer_2,"\", wert \"");
|
||||
buffer_put(buffer_2,buf+i,len);
|
||||
buffer_putsflush(buffer_2,"\".\n");
|
||||
buffer_puts(buffer_2,"feld \"");
|
||||
buffer_puts(buffer_2,attributes.strings.root+tmp);
|
||||
buffer_puts(buffer_2,"\", wert \"");
|
||||
buffer_put(buffer_2,payload.s,len);
|
||||
buffer_putsflush(buffer_2,"\".\n");
|
||||
#endif
|
||||
|
||||
if (tmp==objectClass) {
|
||||
if ((val=mduptab_add(&classes,buf+i,len-1))<0) goto nomem;
|
||||
if ((val=mduptab_add(&classes,payload.s,len-1))<0) goto nomem;
|
||||
} else if (tmp==dn) {
|
||||
char* newdn=alloca(n-i+1);
|
||||
if ((val=mstorage_add(&stringtable,newdn,normalize_dn(newdn,buf+i,len)))<0) goto nomem;
|
||||
if ((val=mstorage_add(&stringtable,newdn,normalize_dn(newdn,payload.s,len)))<0) goto nomem;
|
||||
} else
|
||||
if ((val=mstorage_add(&stringtable,buf+i,len))<0) goto nomem;
|
||||
if ((val=mstorage_add(&stringtable,payload.s,len))<0) goto nomem;
|
||||
addattribute(l,tmp,val);
|
||||
#endif
|
||||
} while (!eof);
|
||||
|
||||
23
md5password.c
Normal file
23
md5password.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <md5.h>
|
||||
#include "buffer.h"
|
||||
#include "str.h"
|
||||
#include "textcode.h"
|
||||
|
||||
int main(int argc,char* argv[]) {
|
||||
char digest[17];
|
||||
char md5[40];
|
||||
int i;
|
||||
for (i=1; i<argc; ++i) {
|
||||
MD5_CTX c;
|
||||
MD5Init(&c);
|
||||
MD5Update(&c,argv[i],strlen(argv[i]));
|
||||
MD5Final(digest,&c);
|
||||
digest[16]=0;
|
||||
md5[fmt_base64(md5,digest,16)]=0;
|
||||
buffer_puts(buffer_1,argv[i]);
|
||||
buffer_puts(buffer_1," -> {MD5}");
|
||||
buffer_puts(buffer_1,md5);
|
||||
buffer_putnlflush(buffer_1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
1
parse.c
1
parse.c
@@ -71,6 +71,7 @@ int main() {
|
||||
/* we add 8 for the <length-in-uint32_t,0> pair and we substract 8
|
||||
* for the two saved pointers ("dn" and "objectClass") */
|
||||
if (x->dn>=0) len+=8; else {
|
||||
if (x->n==0 && x->next==0) break;
|
||||
buffer_putsflush(buffer_2,"record without dn?!\n");
|
||||
dumprec(x);
|
||||
return 1;
|
||||
|
||||
@@ -605,12 +605,15 @@ authfailure:
|
||||
buffer_put(buffer_2,f.ava.value.s,f.ava.value.l);
|
||||
buffer_putsflush(buffer_2,".\n");
|
||||
#endif
|
||||
if (check_password(c,&password))
|
||||
if (check_password(c,&password)) {
|
||||
done=1;
|
||||
goto found;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!done) goto authfailure;
|
||||
found:
|
||||
}
|
||||
}
|
||||
{
|
||||
@@ -742,6 +745,7 @@ authfailure:
|
||||
}
|
||||
}
|
||||
case AbandonRequest:
|
||||
buffer_putsflush(buffer_2,"AbandonRequest!\n");
|
||||
/* do nothing */
|
||||
break;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user