remove obsolete ldap_match (superseded by ldap_match_mapped a long time ago)
make mstorage_add compile on non-Linux
This commit is contained in:
2
Makefile
2
Makefile
@@ -22,7 +22,7 @@ matchprefix.o byte_case_diff.o matchcasestring.o matchcaseprefix.o \
|
||||
scan_ldapmodifyrequest.o bstrlen.o bstrfirst.o bstrstart.o \
|
||||
free_ldapadl.o free_ldappal.o free_ldapsearchfilter.o
|
||||
|
||||
ldif.a: ldif_parse.o ldap_match.o ldap_match_mapped.o
|
||||
ldif.a: ldif_parse.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 mstorage_add_bin.o
|
||||
|
||||
99
ldap_match.c
99
ldap_match.c
@@ -1,99 +0,0 @@
|
||||
#include "ldap.h"
|
||||
#include "ldif.h"
|
||||
#include "byte.h"
|
||||
#include "str.h"
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* look up value of an attribute for an LDIF record.
|
||||
* Return NULL if not found */
|
||||
static const char* findattr(struct ldaprec* f,struct string* name) {
|
||||
int i;
|
||||
if (!matchstring(name,"dn")) return f->dn;
|
||||
for (i=0; i<ATTRIBS; ++i)
|
||||
if (!matchstring(name,f->a[i].name))
|
||||
return f->a[i].value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* return non-zero if the record matches the search filter */
|
||||
int ldap_matchfilter(struct ldaprec* s,struct Filter* f) {
|
||||
struct Filter* y=f->x;
|
||||
if (!f) return 1;
|
||||
switch (f->type) {
|
||||
case AND:
|
||||
while (y) {
|
||||
if (!ldap_matchfilter(s,y)) return 0;
|
||||
y=y->next;
|
||||
}
|
||||
return 1;
|
||||
case OR:
|
||||
while (y) {
|
||||
if (ldap_matchfilter(s,y)) return 1;
|
||||
y=y->next;
|
||||
}
|
||||
return 0;
|
||||
case NOT:
|
||||
return !ldap_matchfilter(s,y);
|
||||
case EQUAL:
|
||||
// printf(" -> \"%s\" vs. \"%.*s\"\n",findattr(s,&f->ava.desc),f->ava.value.l,f->ava.value.s);
|
||||
if (matchstring(&f->ava.value,findattr(s,&f->ava.desc))) return 0;
|
||||
// puts("yes!!!");
|
||||
break;
|
||||
case SUBSTRING:
|
||||
{
|
||||
struct Substring* x=f->substrings;
|
||||
const char* attr=findattr(s,&f->ava.desc);
|
||||
if (!attr) return 0;
|
||||
while (x) {
|
||||
unsigned int i;
|
||||
if (x->s.l>strlen(attr)) return 0;
|
||||
switch (x->substrtype) {
|
||||
case prefix:
|
||||
if (byte_diff(x->s.s,x->s.l,attr)) return 0;
|
||||
found:
|
||||
break;
|
||||
case any:
|
||||
for (i=0; i<x->s.l-strlen(attr); ++i)
|
||||
if (byte_equal(x->s.s+i,x->s.l,attr)) goto found;
|
||||
return 0;
|
||||
case suffix:
|
||||
if (byte_diff(x->s.s+x->s.l-strlen(attr),x->s.l,attr)) return 0;
|
||||
}
|
||||
x=x->next;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
if (f->substrings->substrtype!=prefix) return 0;
|
||||
default:
|
||||
write(2,"foo\n",4);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* return non-zero if the record matches the search request */
|
||||
int ldap_match(struct ldaprec* r,struct SearchRequest* sr) {
|
||||
unsigned int l=strlen(r->dn);
|
||||
unsigned int i;
|
||||
// printf("comparing \"%s\" and \"%.*s\"\n",r->dn,(int)sr->baseObject.l,sr->baseObject.s);
|
||||
/* first see if baseObject is a suffix of dn */
|
||||
if (sr->baseObject.l>l) {
|
||||
// puts("fail: baseObject longer than dn");
|
||||
return 0;
|
||||
}
|
||||
if (!byte_equal(sr->baseObject.s,sr->baseObject.l,r->dn+l-sr->baseObject.l)) {
|
||||
// puts("fail: not suffix");
|
||||
return 0;
|
||||
}
|
||||
/* it is. If scope==wholeSubtree, the scope check is also done */
|
||||
switch (sr->scope) {
|
||||
case wholeSubtree: break;
|
||||
case baseObject: if (l==sr->baseObject.l) break; return 0;
|
||||
default:
|
||||
i=str_chr(r->dn,',');
|
||||
if (i+2>=sr->baseObject.l-l) break;
|
||||
return 0;
|
||||
}
|
||||
return ldap_matchfilter(r,sr->filter);
|
||||
}
|
||||
@@ -14,32 +14,43 @@
|
||||
|
||||
#define PAGEMASK ((PAGE_SIZE)-1)
|
||||
|
||||
/* Sadly, mremap is only available on Linux */
|
||||
/* Please petition your congressman^Woperating system vendor to include it! */
|
||||
|
||||
long mstorage_add(mstorage_t* p,const char* s,unsigned long n) {
|
||||
if (p->mapped-p->used<n) {
|
||||
if (!p->root) {
|
||||
/* nothing allocated. mmap /dev/zero */
|
||||
#ifndef MAP_ANONYMOUS
|
||||
int fd=open("/dev/zero",O_RDWR);
|
||||
#endif
|
||||
char* tmp;
|
||||
long need=(n|PAGEMASK)+1;
|
||||
#ifdef MREMAP_MAYMOVE
|
||||
#ifdef MAP_ANONYMOUS
|
||||
if ((tmp=mmap(0,need,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0))==MAP_FAILED)
|
||||
#else
|
||||
if (fd<0) return -1;
|
||||
if ((tmp=mmap(0,need,PROT_READ|PROT_WRITE,MAP_PRIVATE,fd,0))==MAP_FAILED)
|
||||
#endif
|
||||
return -1;
|
||||
#else
|
||||
int fd=open("/dev/zero",O_RDWR);
|
||||
if (fd<0) return -1;
|
||||
tmp=mmap(0,need,PROT_READ|PROT_WRITE,MAP_PRIVATE,fd,0);
|
||||
close(fd);
|
||||
if (tmp==MAP_FAILED)
|
||||
return -1;
|
||||
#endif
|
||||
#else
|
||||
if (!(tmp=malloc(need)))
|
||||
return -1;
|
||||
#endif
|
||||
p->root=tmp;
|
||||
p->mapped=need;
|
||||
p->used=0;
|
||||
#ifndef MAP_ANONYMOUS
|
||||
close(fd);
|
||||
#endif
|
||||
} else {
|
||||
long need=((p->used+n)|PAGEMASK)+1;
|
||||
#ifdef MREMAP_MAYMOVE
|
||||
char* tmp=mremap(p->root,p->mapped,need,MREMAP_MAYMOVE);
|
||||
if (tmp==MAP_FAILED) return -1;
|
||||
#else
|
||||
char* tmp=realloc(p->root,need);
|
||||
if (!tmp) return -1;
|
||||
#endif
|
||||
p->mapped=need; p->root=tmp;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user