fix binary attributes based on code from Thomas Walpuski
fix ldapclient buffering fix potential segfault in server error handling
This commit is contained in:
4
Makefile
4
Makefile
@@ -25,7 +25,7 @@ free_ldapadl.o free_ldappal.o free_ldapsearchfilter.o
|
||||
ldif.a: ldif_parse.o ldap_match.o ldap_match_mapped.o
|
||||
|
||||
storage.a: strstorage.o strduptab.o mstorage_add.o mduptab_add.o \
|
||||
bstr_diff.o mduptab_adds.o bstr_diff2.o
|
||||
bstr_diff.o mduptab_adds.o bstr_diff2.o mstorage_add_bin.o
|
||||
|
||||
auth.a: auth.o
|
||||
|
||||
@@ -63,7 +63,7 @@ tinyldap_debug: tinyldap.c
|
||||
clean:
|
||||
rm -f t t[1-9] *.[ao] bindrequest tinyldap ldapclient data \
|
||||
parse tinyldap_standalone tinyldap_debug ldapclient_str addindex \
|
||||
dumpidx idx2ldif *.da *.bbg *.bb *.gcov gmon.out
|
||||
dumpidx idx2ldif md5password *.da *.bbg *.bb *.gcov gmon.out
|
||||
|
||||
tar: clean
|
||||
cd ..; tar cvvf tinyldap.tar.bz2 tinyldap --use=bzip2 --exclude capture --exclude CVS --exclude exp.ldif --exclude polyp* --exclude rfc*
|
||||
|
||||
1
TODO
1
TODO
@@ -2,3 +2,4 @@
|
||||
- add auth method (openldap md5: base64, 4 bytes salt, direct hash)
|
||||
- add write support with an external journal
|
||||
- add ACLs
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ static void dumpbstr(const char* c) {
|
||||
l=bstrlen(c);
|
||||
d=bstrfirst(c);
|
||||
for (i=0; i<l; ++i)
|
||||
if (!isprint(d[i])) printable=0;
|
||||
if (!isprint(d[i])) { printable=0; break; }
|
||||
if (printable) {
|
||||
buffer_puts(buffer_1," ");
|
||||
if (*c)
|
||||
|
||||
@@ -29,7 +29,6 @@ static int substringmatch(struct Substring* x,const char* attr,int ignorecase) {
|
||||
found:
|
||||
break;
|
||||
case any:
|
||||
if (x->s.l>strlen(attr)) return 0;
|
||||
for (i=0; i<x->s.l-strlen(attr); ++i) {
|
||||
if (!diff(x->s.s,x->s.l,attr+i)) goto found;
|
||||
}
|
||||
|
||||
39
ldapclient.c
39
ldapclient.c
@@ -104,22 +104,39 @@ usage:
|
||||
char* max;
|
||||
struct SearchResultEntry sre;
|
||||
int matches=0;
|
||||
len=0;
|
||||
for (;;) {
|
||||
long slen,mid,op;
|
||||
len=0;
|
||||
int cur;
|
||||
|
||||
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;
|
||||
}
|
||||
len+=tmp;
|
||||
cur=0;
|
||||
nextmessage:
|
||||
if ((tmp2=scan_ldapmessage(buf,buf+len,&mid,&op,&slen))) {
|
||||
max=buf+slen+tmp2;
|
||||
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+tmp2,max,&sre))) {
|
||||
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,"objectName \"");
|
||||
buffer_put(buffer_1,sre.objectName.s,sre.objectName.l);
|
||||
buffer_puts(buffer_1,"\"\n");
|
||||
@@ -137,7 +154,7 @@ nextmessage:
|
||||
pal=pal->next;
|
||||
}
|
||||
} else
|
||||
buffer_putsflush(buffer_1,"punt!\n");
|
||||
goto copypartialandcontinue;
|
||||
} else if (op==SearchResultDone) {
|
||||
if (!matches)
|
||||
buffer_putsflush(buffer_2,"no matches.\n");
|
||||
@@ -147,11 +164,17 @@ nextmessage:
|
||||
return 0;
|
||||
}
|
||||
if (max<buf+len) {
|
||||
byte_copy(buf,buf+len-max,max);
|
||||
tmp-=(max-(buf+len));
|
||||
len-=(max-(buf+len));
|
||||
cur+=slen+tmp2;
|
||||
goto nextmessage;
|
||||
}
|
||||
} else {
|
||||
/* copy partial message */
|
||||
copypartialandcontinue:
|
||||
byte_copy(buf,len-cur,buf+cur);
|
||||
len-=cur; cur=0;
|
||||
#if 0
|
||||
buffer_putsflush(buffer_2,"scan_ldapmessage failed!\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ lookagain:
|
||||
char* newdn=alloca(len);
|
||||
if ((val=mstorage_add(&stringtable,newdn,normalize_dn(newdn,payload.s,len)))<0) goto nomem;
|
||||
} else
|
||||
if ((val=mstorage_add(&stringtable,payload.s,len))<0) goto nomem;
|
||||
if ((val=mstorage_add_bin(&stringtable,payload.s,len))<0) goto nomem;
|
||||
addattribute(l,tmp,val);
|
||||
|
||||
(*l)->next=m;
|
||||
@@ -178,7 +178,7 @@ lookagain:
|
||||
char* newdn=alloca(n-i+1);
|
||||
if ((val=mstorage_add(&stringtable,newdn,normalize_dn(newdn,payload.s,len)))<0) goto nomem;
|
||||
} else
|
||||
if ((val=mstorage_add(&stringtable,payload.s,len))<0) goto nomem;
|
||||
if ((val=mstorage_add_bin(&stringtable,payload.s,len))<0) goto nomem;
|
||||
addattribute(l,tmp,val);
|
||||
#endif
|
||||
} while (!eof);
|
||||
|
||||
@@ -9,29 +9,15 @@
|
||||
long mduptab_add(mduptab_t* t,const char* s,unsigned int len) {
|
||||
unsigned int i;
|
||||
unsigned long* l=(unsigned long*)t->table.root;
|
||||
static char zero;
|
||||
int binary=0;
|
||||
long x,bak;
|
||||
for (i=0; i<t->strings.used/sizeof(unsigned long); ++i)
|
||||
if (bstr_equal2(t->strings.root+l[i],s,len))
|
||||
return l[i];
|
||||
for (i=0; i<len; ++i)
|
||||
if (!s[i]) binary=1;
|
||||
{
|
||||
long x;
|
||||
char intbuf[4];
|
||||
if (binary) {
|
||||
x=mstorage_add(&t->strings,&zero,1);
|
||||
uint32_pack(intbuf,len);
|
||||
mstorage_add(&t->strings,intbuf,4);
|
||||
mstorage_add(&t->strings,s,len);
|
||||
} else {
|
||||
x=mstorage_add(&t->strings,s,len);
|
||||
mstorage_add(&t->strings,&zero,1);
|
||||
}
|
||||
if (mstorage_add(&t->table,(const char*)&x,sizeof(x))<0) {
|
||||
t->strings.used-=strlen(s)+1;
|
||||
return -1;
|
||||
}
|
||||
return x;
|
||||
bak=t->strings.used;
|
||||
if ((x=mstorage_add_bin(&t->strings,s,len))<0) return -1;
|
||||
if (mstorage_add(&t->table,(const char*)&x,sizeof(x))<0) {
|
||||
t->strings.used=bak;
|
||||
return -1;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
@@ -18,4 +18,11 @@ long mstorage_add(mstorage_t* p,const char* s,unsigned long n);
|
||||
/* undo mapping */
|
||||
void mstorage_unmap(mstorage_t* p);
|
||||
|
||||
/* this is tinyldap specific. If the data contains at least one 0-byte,
|
||||
* it is stored in a tinyldap specific encoding:
|
||||
* char 0;
|
||||
* uint32 len;
|
||||
* char data[len] */
|
||||
long mstorage_add_bin(mstorage_t* p,const char* s,unsigned long n);
|
||||
|
||||
#endif
|
||||
|
||||
5
parse.c
5
parse.c
@@ -40,13 +40,13 @@ void dumprec(struct ldaprec* l) {
|
||||
buffer_putsflush(buffer_1,"\n");
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main(int argc,char* argv[]) {
|
||||
int fd;
|
||||
long len;
|
||||
unsigned long size_of_string_table,indices_offset,record_count;
|
||||
long offset_stringtable,offset_classes,offset_attributes;
|
||||
char* map,* dest;
|
||||
ldif_parse("exp.ldif");
|
||||
ldif_parse(argc<2?"exp.ldif":argv[1]);
|
||||
if (!first) {
|
||||
buffer_putsflush(buffer_2,"no data?!");
|
||||
return 1;
|
||||
@@ -84,6 +84,7 @@ int main() {
|
||||
buffer_puts(buffer_2,"record \"");
|
||||
buffer_puts(buffer_2,x->dn+stringtable.root);
|
||||
buffer_putsflush(buffer_2,"\" has no objectClass?!\n");
|
||||
dumprec(x);
|
||||
return 1;
|
||||
}
|
||||
++record_count;
|
||||
|
||||
@@ -47,6 +47,7 @@ error:
|
||||
}
|
||||
|
||||
void free_ldapsearchrequest(struct SearchRequest* s) {
|
||||
free_ldapadl(s->attributes->next);
|
||||
if (s->attributes)
|
||||
free_ldapadl(s->attributes->next);
|
||||
free_ldapsearchfilter(s->filter);
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
#endif
|
||||
#include <signal.h>
|
||||
|
||||
#define verbose 1
|
||||
#define debug 1
|
||||
#define verbose 0
|
||||
#define debug 0
|
||||
|
||||
char* map;
|
||||
long filelen;
|
||||
|
||||
Reference in New Issue
Block a user