diff --git a/Makefile b/Makefile index 88e2996..be81401 100644 --- a/Makefile +++ b/Makefile @@ -82,7 +82,7 @@ acl: acl.c ldap.a asn1.a .PHONY: clean tar clean: - rm -f t t[1-9] *.[ao] bindrequest tinyldap ldapclient data \ + rm -f t t[1-9] *.[ao] bindrequest tinyldap ldapclient \ parse tinyldap_standalone tinyldap_debug ldapclient_str addindex \ dumpidx idx2ldif md5password *.da *.bbg *.bb *.gcov gmon.out *.gcda \ *.gcno @@ -90,34 +90,6 @@ dumpidx idx2ldif md5password *.da *.bbg *.bb *.gcov gmon.out *.gcda \ tar: clean cd ..; tar cvvf tinyldap.tar.bz2 tinyldap --use=bzip2 --exclude capture --exclude CVS --exclude exp.ldif --exclude polyp* --exclude rfc* -fmt_asn1int.o: fmt_asn1int.c -fmt_asn1intpayload.o: fmt_asn1intpayload.c -fmt_asn1length.o: fmt_asn1length.c asn1.h -fmt_asn1string.o: fmt_asn1string.c asn1.h -fmt_asn1tag.o: fmt_asn1tag.c asn1.h -fmt_asn1transparent.o: fmt_asn1transparent.c asn1.h -fmt_ldapbindrequest.o: fmt_ldapbindrequest.c asn1.h ldap.h -fmt_ldapbindresponse.o: fmt_ldapbindresponse.c asn1.h ldap.h -fmt_ldapmessage.o: fmt_ldapmessage.c asn1.h ldap.h - -scan_asn1BOOLEAN.o: scan_asn1BOOLEAN.c asn1.h -scan_asn1ENUMERATED.o: scan_asn1ENUMERATED.c asn1.h -scan_asn1INTEGER.o: scan_asn1INTEGER.c asn1.h -scan_asn1SEQUENCE.o: scan_asn1SEQUENCE.c asn1.h -scan_asn1STRING.o: scan_asn1STRING.c asn1.h -scan_asn1int.o: scan_asn1int.c asn1.h -scan_asn1length.o: scan_asn1length.c asn1.h -scan_asn1string.o: scan_asn1string.c asn1.h -scan_asn1tag.o: scan_asn1tag.c asn1.h -scan_ldapava.o: scan_ldapava.c asn1.h ldap.h -scan_ldapbindrequest.o: scan_ldapbindrequest.c asn1.h ldap.h -scan_ldapbindresponse.o: scan_ldapbindresponse.c asn1.h ldap.h -scan_ldapmessage.o: scan_ldapmessage.c asn1.h ldap.h -scan_ldapsearchfilter.o: scan_ldapsearchfilter.c asn1.h ldap.h -scan_ldapsearchrequest.o: scan_ldapsearchrequest.c asn1.h ldap.h -scan_ldapstring.o: scan_ldapstring.c asn1.h ldap.h -scan_ldapresult.o: scan_ldapresult.c asn1.h ldap.h - ldif_parse.o: ldif_parse.c strduptab.h strstorage.h ldif.h tinyldap.o: tinyldap.c ldap.h ldif.h @@ -129,3 +101,48 @@ strduptab.o: strduptab.c strduptab.h strstorage.h strstorage.o: strstorage.c strstorage.h freeava.o: freeava.c ldap.h freefilter.o: freefilter.c ldap.h + +fmt_asn1int.o: fmt_asn1int.c asn1.h +fmt_asn1intpayload.o: fmt_asn1intpayload.c asn1.h +fmt_asn1length.o: fmt_asn1length.c asn1.h +fmt_asn1sint.o: fmt_asn1sint.c asn1.h +fmt_asn1sintpayload.o: fmt_asn1sintpayload.c asn1.h +fmt_asn1string.o: fmt_asn1string.c asn1.h +fmt_asn1tag.o: fmt_asn1tag.c asn1.h +fmt_asn1transparent.o: fmt_asn1transparent.c asn1.h +fmt_ldapadl.o: fmt_ldapadl.c asn1.h ldap.h +fmt_ldapava.o: fmt_ldapava.c asn1.h ldap.h +fmt_ldapbindrequest.o: fmt_ldapbindrequest.c asn1.h ldap.h +fmt_ldapmessage.o: fmt_ldapmessage.c asn1.h ldap.h +fmt_ldappal.o: fmt_ldappal.c asn1.h ldap.h +fmt_ldapresult.o: fmt_ldapresult.c asn1.h ldap.h +fmt_ldapsearchfilter.o: fmt_ldapsearchfilter.c asn1.h ldap.h +fmt_ldapsearchfilterstring.o: fmt_ldapsearchfilterstring.c ldap.h +fmt_ldapsearchrequest.o: fmt_ldapsearchrequest.c asn1.h ldap.h +fmt_ldapsearchresultentry.o: fmt_ldapsearchresultentry.c asn1.h ldap.h +fmt_ldapstring.o: fmt_ldapstring.c asn1.h ldap.h + +scan_asn1BOOLEAN.o: scan_asn1BOOLEAN.c asn1.h +scan_asn1ENUMERATED.o: scan_asn1ENUMERATED.c asn1.h +scan_asn1INTEGER.o: scan_asn1INTEGER.c asn1.h +scan_asn1SEQUENCE.o: scan_asn1SEQUENCE.c asn1.h +scan_asn1SET.o: scan_asn1SET.c asn1.h +scan_asn1STRING.o: scan_asn1STRING.c asn1.h +scan_asn1int.o: scan_asn1int.c asn1.h +scan_asn1length.o: scan_asn1length.c asn1.h +scan_asn1oid.o: scan_asn1oid.c asn1.h +scan_asn1rawint.o: scan_asn1rawint.c asn1.h +scan_asn1string.o: scan_asn1string.c asn1.h +scan_asn1tag.o: scan_asn1tag.c asn1.h +scan_ldapaddrequest.o: scan_ldapaddrequest.c asn1.h ldap.h +scan_ldapava.o: scan_ldapava.c asn1.h ldap.h +scan_ldapbindrequest.o: scan_ldapbindrequest.c asn1.h ldap.h +scan_ldapbindresponse.o: scan_ldapbindresponse.c asn1.h ldap.h +scan_ldapmessage.o: scan_ldapmessage.c asn1.h ldap.h +scan_ldapmodifyrequest.o: scan_ldapmodifyrequest.c asn1.h ldap.h +scan_ldapresult.o: scan_ldapresult.c asn1.h ldap.h +scan_ldapsearchfilter.o: scan_ldapsearchfilter.c asn1.h ldap.h +scan_ldapsearchfilterstring.o: scan_ldapsearchfilterstring.c ldap.h +scan_ldapsearchrequest.o: scan_ldapsearchrequest.c asn1.h ldap.h +scan_ldapsearchresultentry.o: scan_ldapsearchresultentry.c asn1.h ldap.h +scan_ldapstring.o: scan_ldapstring.c asn1.h ldap.h diff --git a/auth.c b/auth.c index 42c6ca9..84aaebb 100644 --- a/auth.c +++ b/auth.c @@ -19,14 +19,14 @@ int check_password(const char* fromdb,struct string* plaintext) { if (str_start(fromdb,"{MD5}")) { - char digest[17]; + unsigned char digest[17]; char md5[40]; MD5_CTX c; MD5Init(&c); - MD5Update(&c,plaintext->s,plaintext->l); + MD5Update(&c,(unsigned char*)plaintext->s,plaintext->l); MD5Final(digest,&c); digest[16]=0; - md5[fmt_base64(md5,digest,16)]=0; + md5[fmt_base64(md5,(char*)digest,16)]=0; if (str_equal(md5,fromdb+5)) return 1; } diff --git a/dumpacls.c b/dumpacls.c index bcbe93a..f44eabb 100644 --- a/dumpacls.c +++ b/dumpacls.c @@ -8,7 +8,6 @@ #include "byte.h" int main(int argc,char* argv[]) { - int verbose=0; unsigned long filelen; char* fn=argc<2?"data":argv[1]; char* map=mmap_read(fn,&filelen); @@ -31,7 +30,7 @@ int main(int argc,char* argv[]) { uint32 ofs,next; acl_ofs=0; for (ofs=indices_offset+record_count*4; ofs<(unsigned long)filelen;) { - uint32 index_type,next,indexed_attribute; + uint32 index_type; uint32_unpack(map+ofs,&index_type); uint32_unpack(map+ofs+4,&next); if (index_type==2) { acl_ofs=ofs; break; } diff --git a/ldap.h b/ldap.h index 9479ac5..2ca2b39 100644 --- a/ldap.h +++ b/ldap.h @@ -19,6 +19,7 @@ struct AttributeValueAssertion { struct AttributeDescriptionList { struct string a; + uint32 attrofs; struct AttributeDescriptionList *next; }; @@ -124,7 +125,7 @@ unsigned int scan_ldapava(const char* src,const char* max,struct AttributeValueA unsigned int scan_ldapsearchfilter(const char* src,const char* max,struct Filter** f); unsigned int scan_ldapsearchrequest(const char* src,const char* max,struct SearchRequest* s); unsigned int scan_ldapsearchresultentry(const char* src,const char* max,struct SearchResultEntry* sre); -unsigned int scan_ldapresult(const char* src,const char* max,long* result, +unsigned int scan_ldapresult(const char* src,const char* max,unsigned long* result, struct string* matcheddn,struct string* errormessage, struct string* referral); unsigned int scan_ldapmodifyrequest(const char* src,const char* max,struct ModifyRequest* m); diff --git a/ldapclient.c b/ldapclient.c index 40b72dd..d03b345 100644 --- a/ldapclient.c +++ b/ldapclient.c @@ -15,7 +15,7 @@ #define BUFSIZE 8192 -static long messageid=1; +static unsigned long messageid=1; static int ldapbind(int sock) { char outbuf[1024]; @@ -23,7 +23,7 @@ static int ldapbind(int sock) { int len=fmt_ldapbindrequest(outbuf+s,3,"",""); int hlen=fmt_ldapmessage(0,messageid,BindRequest,len); int res; - long op,Len,result; + unsigned long op,Len,result; struct string matcheddn,errormessage,referral; fmt_ldapmessage(outbuf+s-hlen,messageid,BindRequest,len); if (write(sock,outbuf+s-hlen,len+hlen)!=len+hlen) return 0;; @@ -48,6 +48,7 @@ int main(int argc,char* argv[]) { ++me; else me=argv[0]; + n=1; if ((bench=!strcmp(me,"ldapbench"))) { n=atoi(getenv("NUM")); buffer_putsflush(buffer_2,"benchmark mode\n"); @@ -58,7 +59,6 @@ usage: buffer_putsflush(buffer_2,"usage: ldapclient ip baseObject filter [foo...]\n"); return 0; } - if (!bench) n=1; for (durchlauf=0; durchlauf {MD5}"); buffer_puts(buffer_1,md5); diff --git a/parse.c b/parse.c index 1719b9e..d120594 100644 --- a/parse.c +++ b/parse.c @@ -161,7 +161,7 @@ int main(int argc,char* argv[]) { goto derrout2; } - buffer_init(&rbuf,write,rfd,recbuf,sizeof recbuf); + buffer_init(&rbuf,(void*)write,rfd,recbuf,sizeof recbuf); ldif_parse_callback=ldif_callback; @@ -175,7 +175,7 @@ derrout2: return 1; } - buffer_init(&outbuf,write,fd,buf,sizeof buf); + buffer_init(&outbuf,(void*)write,fd,buf,sizeof buf); mduptab_init(&attributes); mduptab_init(&classes); @@ -249,7 +249,7 @@ writeerror: buffer_flush(&rbuf); if (lseek(rfd,0,SEEK_SET)!=0) diesys(1,"lseek failed"); - buffer_init(&rbuf,read,rfd,recbuf,sizeof recbuf); + buffer_init(&rbuf,(void*)read,rfd,recbuf,sizeof recbuf); for (i=0; imax) return 0; + *l=(unsigned long)ltmp; return tmp; + } return 0; } diff --git a/scan_asn1ENUMERATED.c b/scan_asn1ENUMERATED.c index 36d4fc5..09bd5ff 100644 --- a/scan_asn1ENUMERATED.c +++ b/scan_asn1ENUMERATED.c @@ -2,11 +2,15 @@ unsigned int scan_asn1ENUMERATED(const char* src,const char* max,unsigned long* l) { unsigned int tmp; - long tag; + unsigned long tag; enum asn1_tagclass tc; enum asn1_tagtype tt; - if ((tmp=scan_asn1int(src,max,&tc,&tt,&tag,l))) - if (tc==UNIVERSAL && tt==PRIMITIVE && tag==ENUMERATED) + long ltmp; + if ((tmp=scan_asn1int(src,max,&tc,&tt,&tag,<mp))) + if (tc==UNIVERSAL && tt==PRIMITIVE && tag==ENUMERATED) { + if (ltmp<0 || src+tmp+ltmp>max) return 0; + *l=(unsigned long)ltmp; return tmp; + } return 0; } diff --git a/scan_asn1INTEGER.c b/scan_asn1INTEGER.c index dde897d..041493b 100644 --- a/scan_asn1INTEGER.c +++ b/scan_asn1INTEGER.c @@ -2,7 +2,7 @@ unsigned int scan_asn1INTEGER(const char* src,const char* max,signed long* l) { unsigned int tmp; - long tag; + unsigned long tag; enum asn1_tagclass tc; enum asn1_tagtype tt; if ((tmp=scan_asn1int(src,max,&tc,&tt,&tag,l))) diff --git a/scan_asn1SEQUENCE.c b/scan_asn1SEQUENCE.c index 763b40b..b14a2ea 100644 --- a/scan_asn1SEQUENCE.c +++ b/scan_asn1SEQUENCE.c @@ -2,7 +2,7 @@ unsigned int scan_asn1SEQUENCE(const char* src,const char* max,unsigned long* len) { unsigned int res,tmp; - long tag; + unsigned long tag; enum asn1_tagclass tc; enum asn1_tagtype tt; if (!(res=scan_asn1tag(src,max,&tc,&tt,&tag))) return 0; diff --git a/scan_asn1SET.c b/scan_asn1SET.c index 6e9e9ce..238e494 100644 --- a/scan_asn1SET.c +++ b/scan_asn1SET.c @@ -2,7 +2,7 @@ unsigned int scan_asn1SET(const char* src,const char* max,unsigned long* len) { unsigned int res,tmp; - long tag; + unsigned long tag; enum asn1_tagclass tc; enum asn1_tagtype tt; if (!(res=scan_asn1tag(src,max,&tc,&tt,&tag))) return 0; diff --git a/scan_asn1STRING.c b/scan_asn1STRING.c index 89cee80..ac88844 100644 --- a/scan_asn1STRING.c +++ b/scan_asn1STRING.c @@ -2,7 +2,7 @@ unsigned int scan_asn1STRING(const char* src,const char* max,const char** s,unsigned long* l) { unsigned int tmp; - long tag; + unsigned long tag; enum asn1_tagclass tc; enum asn1_tagtype tt; if ((tmp=scan_asn1string(src,max,&tc,&tt,&tag,s,l))) diff --git a/scan_asn1int.c b/scan_asn1int.c index 17bc290..61db7ae 100644 --- a/scan_asn1int.c +++ b/scan_asn1int.c @@ -2,7 +2,7 @@ unsigned int scan_asn1int(const char* src,const char* max,enum asn1_tagclass* tc,enum asn1_tagtype* tt,unsigned long* tag,signed long* l) { unsigned int len,tmp; - long tlen; + unsigned long tlen; if (!(len=scan_asn1tag(src,max,tc,tt,tag))) return 0; if (!(tmp=scan_asn1length(src+len,max,&tlen))) return 0; len+=tmp; diff --git a/scan_ldapaddrequest.c b/scan_ldapaddrequest.c index 3e6d2bf..8271e79 100644 --- a/scan_ldapaddrequest.c +++ b/scan_ldapaddrequest.c @@ -17,7 +17,7 @@ unsigned int scan_ldapaddrequest(const char* src,const char* max,struct AddRequest* a) { unsigned int res,tmp; - long oslen; /* outer sequence length */ + unsigned long oslen; /* outer sequence length */ struct Addition* last=0; a->a.next=0; if (!(res=scan_ldapstring(src,max,&a->entry))) goto error; @@ -27,7 +27,7 @@ unsigned int scan_ldapaddrequest(const char* src,const char* max,struct AddReque max=src+res+oslen; if (src+res>=max) goto error; /* need at least one record */ do { - long islen; + unsigned long islen; if (last) { struct Addition* cur; if (!(cur=malloc(sizeof(struct Addition)))) @@ -48,7 +48,7 @@ unsigned int scan_ldapaddrequest(const char* src,const char* max,struct AddReque /* scan set of AttributeValue: */ { - long set_len; + unsigned long set_len; const char* set_max; struct AttributeDescriptionList* ilast=0; if (!(tmp=scan_asn1SET(src+res,max,&set_len))) { diff --git a/scan_ldapmodifyrequest.c b/scan_ldapmodifyrequest.c index ec17527..d024497 100644 --- a/scan_ldapmodifyrequest.c +++ b/scan_ldapmodifyrequest.c @@ -19,7 +19,7 @@ unsigned int scan_ldapmodifyrequest(const char* src,const char* max,struct ModifyRequest* m) { unsigned int res,tmp; - long oslen; /* outer sequence length */ + unsigned long oslen; /* outer sequence length */ struct Modification* last=0; m->m.next=0; if (!(res=scan_ldapstring(src,max,&m->object))) goto error; @@ -29,7 +29,7 @@ unsigned int scan_ldapmodifyrequest(const char* src,const char* max,struct Modif max=src+res+oslen; if (src+res>=max) goto error; /* need at least one record */ do { - long islen, etmp; + unsigned long islen, etmp; if (last) { struct Modification* cur; if (!(cur=malloc(sizeof(struct Modification)))) goto error; @@ -42,7 +42,7 @@ unsigned int scan_ldapmodifyrequest(const char* src,const char* max,struct Modif if (!(tmp=scan_asn1ENUMERATED(src+res,max,&etmp))) goto error; if (etmp>2) goto error; last->operation=etmp; res+=tmp; { - long iislen; /* urgh, _three_ levels of indirection */ + unsigned long iislen; /* urgh, _three_ levels of indirection */ const char* imax; if (!(tmp=scan_asn1SEQUENCE(src+res,max,&iislen))) goto error; res+=tmp; @@ -51,7 +51,7 @@ unsigned int scan_ldapmodifyrequest(const char* src,const char* max,struct Modif if (!(tmp=scan_ldapstring(src+res,imax,&last->AttributeDescription))) goto error; res+=tmp; { - long iiislen; /* waah, _four_ levels of indirection! It doesn't get more inefficient than this */ + unsigned long iiislen; /* waah, _four_ levels of indirection! It doesn't get more inefficient than this */ const char* iimax; struct AttributeDescriptionList* ilast=0; if (!(tmp=scan_asn1SET(src+res,max,&iiislen))) goto error; diff --git a/scan_ldapresult.c b/scan_ldapresult.c index b703654..f8ac914 100644 --- a/scan_ldapresult.c +++ b/scan_ldapresult.c @@ -1,7 +1,7 @@ #include "asn1.h" #include "ldap.h" -unsigned int scan_ldapresult(const char* src,const char* max,long* result, +unsigned int scan_ldapresult(const char* src,const char* max,unsigned long* result, struct string* matcheddn,struct string* errormessage, struct string* referral) { unsigned int res,tmp; diff --git a/scan_ldapsearchfilter.c b/scan_ldapsearchfilter.c index 0395b9b..1689964 100644 --- a/scan_ldapsearchfilter.c +++ b/scan_ldapsearchfilter.c @@ -80,7 +80,7 @@ unsigned int scan_ldapsearchfilter(const char* src,const char* max,struct Filter break; case 4: /* substrings [4] SubstringFilter, */ { - long len2; + unsigned long len2; if (!(tmp=scan_ldapstring(src+res,nmax,&(*f)->ava.desc))) goto error; res+=tmp; if (!(tmp=scan_asn1SEQUENCE(src+res,nmax,&len2))) goto error; diff --git a/scan_ldapsearchrequest.c b/scan_ldapsearchrequest.c index 89d9757..2517c19 100644 --- a/scan_ldapsearchrequest.c +++ b/scan_ldapsearchrequest.c @@ -6,6 +6,7 @@ unsigned int scan_ldapsearchrequest(const char* src,const char* max, struct SearchRequest* s) { unsigned int res,tmp; unsigned long etmp; + signed long ltmp; s->attributes=0; s->filter=0; if (!(res=scan_ldapstring(src,max,&s->baseObject))) goto error; @@ -13,9 +14,11 @@ unsigned int scan_ldapsearchrequest(const char* src,const char* max, if (etmp>2) goto error; s->scope=etmp; res+=tmp; if (!(tmp=scan_asn1ENUMERATED(src+res,max,&etmp))) goto error; if (etmp>3) goto error; s->derefAliases=etmp; res+=tmp; - if (!(tmp=scan_asn1INTEGER(src+res,max,&s->sizeLimit))) goto error; + if (!(tmp=scan_asn1INTEGER(src+res,max,<mp)) || ltmp<0) goto error; + s->sizeLimit=(unsigned long)ltmp; res+=tmp; - if (!(tmp=scan_asn1INTEGER(src+res,max,&s->timeLimit))) goto error; + if (!(tmp=scan_asn1INTEGER(src+res,max,<mp)) || ltmp<0) goto error; + s->timeLimit=(unsigned long)ltmp; res+=tmp; if (!(tmp=scan_asn1BOOLEAN(src+res,max,&s->typesOnly))) goto error; res+=tmp; diff --git a/scan_ldapsearchresultentry.c b/scan_ldapsearchresultentry.c index c15c44a..5b81833 100644 --- a/scan_ldapsearchresultentry.c +++ b/scan_ldapsearchresultentry.c @@ -4,7 +4,7 @@ unsigned int scan_ldapsearchresultentry(const char* src,const char* max,struct SearchResultEntry* sre) { unsigned int res,tmp; - long oslen; /* outer sequence length */ + unsigned long oslen; /* outer sequence length */ struct PartialAttributeList** a=&sre->attributes; *a=0; if (!(res=scan_ldapstring(src,max,&sre->objectName))) goto error; @@ -15,7 +15,7 @@ unsigned int scan_ldapsearchresultentry(const char* src,const char* max,struct S while (src+resmax) goto error; diff --git a/t1.c b/t1.c index 0491c49..2bec4ab 100644 --- a/t1.c +++ b/t1.c @@ -117,7 +117,7 @@ int parse_ldif(const char* filename) { int fd=open_read(filename); buffer in; if (fd<0) return 1; - buffer_init(&in,read,fd,buf,sizeof buf); + buffer_init(&in,(void*)read,fd,buf,sizeof buf); dn=strduptab_add(&tags,"dn"); mail=strduptab_add(&tags,"mail"); sn=strduptab_add(&tags,"sn"); diff --git a/t2.c b/t2.c index ff6d66c..18dcfc1 100644 --- a/t2.c +++ b/t2.c @@ -86,7 +86,7 @@ int main(int argc,char* argv[]) { unsigned long size; // char* ldapsequence=mmap_read("req",&size); char* ldapsequence=mmap_read(argc>1?argv[1]:"/tmp/ldap/127.000.000.001.00389-127.000.000.001.38433",&size); - long messageid, op, len; + unsigned long messageid, op, len; int res; unsigned long done=0; while (done> BindRequest <<"); { - long version,method; + unsigned long version,method; struct string name; int tmp; printf("scan_ldapbindrequest: %d\n",tmp=scan_ldapbindrequest(ldapsequence+done+res,ldapsequence+done+res+len,&version,&name,&method)); @@ -105,7 +105,7 @@ int main(int argc,char* argv[]) { if (method==0) { enum asn1_tagclass tc; enum asn1_tagtype tt; - long tag; + unsigned long tag; if (scan_asn1string(ldapsequence+done+res+tmp,ldapsequence+size,&tc,&tt,&tag,&name.s,&name.l) && tc==PRIVATE && tt==PRIMITIVE && tag==0) printf("simple \"%.*s\"\n",(int)name.l,name.s); @@ -182,7 +182,7 @@ int main(int argc,char* argv[]) { case SearchResultDone: puts(" >> SearchResultDone <<"); { - long result; + unsigned long result; struct string matcheddn,errormessage,referral; printf("scan_ldapresult: %d\n", scan_ldapresult(ldapsequence+done+res,ldapsequence+done+res+len, diff --git a/tinyldap.c b/tinyldap.c index ea6ee3a..d4df59f 100644 --- a/tinyldap.c +++ b/tinyldap.c @@ -25,6 +25,7 @@ #include #include "uint16.h" #include "acl.h" +#include #ifdef DEBUG #include @@ -37,7 +38,7 @@ /* basic operation: the whole data file is mmapped read-only at the beginning and stays there. */ char* map; /* where the file is mapped */ -long filelen; /* how many bytes are mapped (the whole file) */ +unsigned long filelen; /* how many bytes are mapped (the whole file) */ uint32 magic,attribute_count,record_count,indices_offset,size_of_string_table; /* these are the first values from the file, see the file "FORMAT" * basic counts and offsets needed to calculate the positions of @@ -106,6 +107,28 @@ static void fixup(struct Filter* f) { if (f->next) fixup(f->next); } +static void fixupadl(struct AttributeDescriptionList* a) { + while (a) { + char* x=map+5*4+size_of_string_table; + unsigned int i; + a->attrofs=0; + for (i=0; ia,map+j)) { + a->attrofs=j; + break; + } + x+=4; + } + if (!a->attrofs) { + buffer_puts(buffer_2,"cannot find attribute \""); + buffer_put(buffer_2,a->a.s,a->a.l); + buffer_putsflush(buffer_2,"\"!\n"); + } + a=a->next; + } +} + @@ -145,7 +168,7 @@ static void load_acls() { uint32 ofs; uint32 acl_ofs; acl_ofs=0; - for (ofs=indices_offset+record_count*4; ofs<(unsigned long)filelen;) { + for (ofs=indices_offset+record_count*4; ofstype==EQUAL) { /* prefer a hash index if there is one */ uint32 ofs; - for (ofs=indices_offset+record_count*4; ofs<(unsigned long)filelen;) { + for (ofs=indices_offset+record_count*4; ofsava.desc,map+indexed_attribute)) { uint32 hashtabsize=uint32_read(map+ofs+12); uint32 hashtab=ofs+16; - uint32 hashval=f->attrflag&1?hash_tolower(f->ava.value.s,f->ava.value.l):hash(f->ava.value.s,f->ava.value.l); + uint32 hashval=f->attrflag&1?hash_tolower((unsigned char*)f->ava.value.s,f->ava.value.l):hash((unsigned char*)f->ava.value.s,f->ava.value.l); uint32 hashofs=uint32_read(map+hashtab+(hashval%hashtabsize)*4); if (hashofs==0) return 1; if (hashofssubstrings->substrtype!=prefix) return 0; { uint32 ofs; - for (ofs=indices_offset+record_count*4; ofs<(unsigned long)filelen;) { + for (ofs=indices_offset+record_count*4; ofsattrs; ++k) { - if (Acls[j]->Attrs[k]==any_ofs || !matchstring(&adl->a,map+Acls[j]->Attrs[k])) { +/* if (Acls[j]->Attrs[k]==any_ofs || !matchstring(&adl->a,map+Acls[j]->Attrs[k])) { */ + if (Acls[j]->Attrs[k]==any_ofs || adl->attrofs==Acls[j]->Attrs[k]) { if (Acls[j]->may&acl_read) { #if 0 printf("acl %u allowed serving attribute \"%.*s\"\n",j,(int)adl->a.l,adl->a.s); @@ -845,8 +870,8 @@ static void answerwith(uint32 ofs,struct SearchRequest* sr,long messageid,int ou } if (ok) break; } - if (ok==1) { + if (ok==1) { uint32_unpack(map+ofs,&j); #if 0 buffer_puts(buffer_2,"looking for attribute \""); @@ -858,7 +883,8 @@ static void answerwith(uint32 ofs,struct SearchRequest* sr,long messageid,int ou val=map+uint32_read(map+ofs+12); else { for (; ia,map+uint32_read(map+ofs+i*8))) { +/* if (!matchstring(&adl->a,map+uint32_read(map+ofs+i*8))) { */ + if (adl->attrofs == uint32_read(map+ofs+i*8)) { val=map+uint32_read(map+ofs+i*8+4); ++i; break; @@ -867,20 +893,22 @@ static void answerwith(uint32 ofs,struct SearchRequest* sr,long messageid,int ou if (val) { *pal=malloc(sizeof(struct PartialAttributeList)); if (!*pal) { - nomem: +nomem: buffer_putsflush(buffer_2,"out of virtual memory!\n"); exit(1); } (*pal)->type=adl->a; { - struct AttributeDescriptionList** a=&(*pal)->values; - add_attribute: + struct AttributeDescriptionList** a; + a=&(*pal)->values; +add_attribute: *a=malloc(sizeof(struct AttributeDescriptionList)); if (!*a) goto nomem; (*a)->a.s=bstrfirst(val); (*a)->a.l=bstrlen(val); for (;ia,map+uint32_read(map+ofs+i*8))) { +/* if (!matchstring(&adl->a,map+uint32_read(map+ofs+i*8))) { */ + if (adl->attrofs == uint32_read(map+ofs+i*8)) { val=map+uint32_read(map+ofs+i*8+4); ++i; a=&(*a)->next; @@ -937,12 +965,12 @@ static void answerwith(uint32 ofs,struct SearchRequest* sr,long messageid,int ou * tinyldap does not complain if you don't unbind before hanging up. */ int handle(int in,int out) { - int len; + unsigned int len; char buf[BUFSIZE]; for (len=0;;) { int tmp=read(in,buf+len,BUFSIZE-len); int res; - long messageid,op,Len; + unsigned long messageid,op,Len; if (tmp==0) { close(in); if (in!=out) close(out); @@ -965,7 +993,7 @@ int handle(int in,int out) { switch (op) { case BindRequest: { - long version,method; + unsigned long version,method; struct string name; int tmp; tmp=scan_ldapbindrequest(buf+res,buf+res+len,&version,&name,&method); @@ -1100,6 +1128,7 @@ found: } #endif fixup(sr.filter); + fixupadl(sr.attributes); if (indexable(sr.filter)) { unsigned long* result; unsigned long i;