diff --git a/README b/README index ef982e5..a2f6a65 100644 --- a/README +++ b/README @@ -17,3 +17,5 @@ file called "exp.ldif" (I can't give you my test data, sorry). Then use "addindex" to add indexes if you like. Use "dumpidx" to have the contents of data displayed on screen. tinyldap has been modified to use data instead of the in-memory linked list. + +Do _not_ add an index for objectClass! It will not work! diff --git a/mstorage_add.c b/mstorage_add.c index 28d3ba8..ba97d3f 100644 --- a/mstorage_add.c +++ b/mstorage_add.c @@ -1,3 +1,4 @@ +#define _GNU_SOURCE #include #include #include diff --git a/tinyldap.c b/tinyldap.c index de18ee5..82fb5a4 100644 --- a/tinyldap.c +++ b/tinyldap.c @@ -64,6 +64,31 @@ static int indexable(struct Filter* f) { } } +#define MAXINDEXMATCHES 100 +static uint32 matches[MAXINDEXMATCHES]; +static uint32 matchcounter; + +/* find record given a data pointer */ +static uint32 findrec(uint32 dat) { + uint32* records=(uint32*)(map+indices_offset); + uint32 bottom=0; + uint32 top=record_count; + while ((top>=bottom)) { + uint32 mid=(top+bottom)/2; + uint32 k,l; + uint32_unpack(&records[mid],&k); + uint32_unpack(map+k+8,&l); + if (ldat) return k; /* found! */ + bottom=mid+1; + } else + top=mid-1; + } + return 0; +} + static void answerwith(uint32 ofs,struct SearchRequest* sr,long messageid,int out) { uint32 k; struct SearchResultEntry sre; @@ -237,12 +262,12 @@ int handle(int in,int out) { } #endif if ((tmp=scan_ldapsearchrequest(buf+res,buf+res+len,&sr))) { -#if 0 if (indexable(sr.filter)) { buffer_putsflush(buffer_2,"query is indexable!\n"); - } /* else */ -#endif - { + /* Use the index to find matching data. Put the offsets + * of the matches in a table. Use findrec to locate + * the records that point to the data. */ + } /* else */ { char* x=map+5*4+size_of_string_table+attribute_count*8; unsigned long i; for (i=0; idn); - buffer_putsflush(buffer_2,"\"\n"); -#endif - if (ldap_match(r,&sr)) { - struct SearchResultEntry sre; - struct PartialAttributeList** pal=&sre.attributes; - sre.objectName.s=r->dn; sre.objectName.l=strlen(r->dn); - sre.attributes=0; - /* now go through list of requested attributes */ - { - struct AttributeDescriptionList* adl=sr.attributes; - while (adl) { - const char* val=0; - int i=0; -#if 0 - buffer_puts(buffer_2,"looking for attribute \""); - buffer_put(buffer_2,adl->a.s,adl->a.l); - buffer_putsflush(buffer_2,"\"\n"); -#endif - if (!matchstring(&adl->a,"dn")) val=r->dn; else - if (!matchstring(&adl->a,"cn")) val=r->cn; else - if (!matchstring(&adl->a,"mail")) val=r->mail; else - if (!matchstring(&adl->a,"sn")) val=r->sn; else - for (; in; ++i) { -#if 0 - buffer_puts(buffer_2,"comparing with \""); - buffer_puts(buffer_2,r->a[i].name); - buffer_putsflush(buffer_2,"\"\n"); -#endif - if (!matchstring(&adl->a,r->a[i].name)) - val=r->a[i].value; - } - if (val) { - *pal=malloc(sizeof(struct PartialAttributeList)); - if (!*pal) { -nomem: - buffer_putsflush(buffer_2,"out of virtual memory!\n"); - exit(1); - } - (*pal)->type=adl->a; - { - struct AttributeDescriptionList** a=&(*pal)->values; - while (in) { - *a=malloc(sizeof(struct AttributeDescriptionList)); - if (!*a) goto nomem; - (*a)->a.s=val; - (*a)->a.l=strlen(val); - (*a)->next=0; - for (;in; ++i) - if (!matchstring(&adl->a,r->a[i].name)) { - val=r->a[i].value; - break; - } - } - } - (*pal)->next=0; - pal=&(*pal)->next; - } - adl=adl->next; - } - } - { - long l=fmt_ldapsearchresultentry(0,&sre); - char *buf=alloca(l+300); /* you never know ;) */ - long tmp; - if (verbose) { - buffer_puts(buffer_2,"sre len "); - buffer_putulong(buffer_2,l); - buffer_putsflush(buffer_2,".\n"); - } - tmp=fmt_ldapmessage(buf,messageid,SearchResultEntry,l); - fmt_ldapsearchresultentry(buf+tmp,&sre); - write(out,buf,l+tmp); - } - if (verbose) { - buffer_puts(buffer_2,"found: "); - buffer_puts(buffer_2,r->dn); - buffer_putsflush(buffer_2,"\n"); - } - } - r=r->next; - } -#endif } else { buffer_putsflush(buffer_2,"couldn't parse search request!\n"); exit(1);