summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/ldb/Makefile.ldb8
-rw-r--r--source4/lib/ldb/common/util.c51
-rw-r--r--source4/lib/ldb/include/ldb_private.h4
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_index.c51
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_pack.c13
-rwxr-xr-xsource4/lib/ldb/tests/test-generic.sh6
-rw-r--r--source4/lib/ldb/tests/test-index.ldif13
-rw-r--r--source4/lib/ldb/tests/test.ldif2
-rw-r--r--source4/lib/ldb/tools/ldbsearch.c2
9 files changed, 73 insertions, 77 deletions
diff --git a/source4/lib/ldb/Makefile.ldb b/source4/lib/ldb/Makefile.ldb
index a472f949af..75c298241d 100644
--- a/source4/lib/ldb/Makefile.ldb
+++ b/source4/lib/ldb/Makefile.ldb
@@ -15,6 +15,8 @@ TALLOCDIR=../talloc
CFLAGS1=-Wall -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith \
-Wcast-qual -Wcast-align -Wwrite-strings -g -Iinclude -I. -I.. \
-I$(TDBDIR)/include -I$(TALLOCDIR) -DUSE_MMAP=1 $(LDAP_FLAGS)
+
+# enable the following two lines to build with gcov code coverage support
#GCOV_FLAGS = -ftest-coverage -fprofile-arcs
#GCOV_LIBS = -lgcov
@@ -99,6 +101,6 @@ test: test-tdb test-ldap
gcov:
gcov -po ldb_ldap ldb_ldap/*.c 2| tee ldb_ldap.report.gcov
gcov -po ldb_tdb ldb_tdb/*.c 2| tee ldb_tdb.report.gcov
- gcov -po common common/*.c 2| tee ldb_common.report.gcov
- gcov -po modules modules/*.c 2| tee ldb_modules.report.gcov
- gcov -po tools tools/*.c 2| tee ldb_tools.report.gcov
+ gcov -po common common/*.c 2| tee common.report.gcov
+ gcov -po modules modules/*.c 2| tee modules.report.gcov
+ gcov -po tools tools/*.c 2| tee tools.report.gcov
diff --git a/source4/lib/ldb/common/util.c b/source4/lib/ldb/common/util.c
index 0c9cf297c1..c2fd72acd1 100644
--- a/source4/lib/ldb/common/util.c
+++ b/source4/lib/ldb/common/util.c
@@ -38,57 +38,6 @@
/*
- find an element in a list, using the given comparison function and
- assuming that the list is already sorted using comp_fn
-
- return -1 if not found, or the index of the first occurance of needle if found
-*/
-int ldb_list_find(const void *needle,
- const void *base, size_t nmemb, size_t size, comparison_fn_t comp_fn)
-{
- const char *base_p = base;
- size_t min_i, max_i, test_i;
-
- if (nmemb == 0) {
- return -1;
- }
-
- min_i = 0;
- max_i = nmemb-1;
-
- while (min_i < max_i) {
- int r;
-
- test_i = (min_i + max_i) / 2;
- r = comp_fn(needle, *(void * const *)(base_p + (size * test_i)));
- if (r == 0) {
- /* scan back for first element */
- while (test_i > 0 &&
- comp_fn(needle, *(void * const *)(base_p + (size * (test_i-1)))) == 0) {
- test_i--;
- }
- return test_i;
- }
- if (r < 0) {
- if (test_i == 0) {
- return -1;
- }
- max_i = test_i - 1;
- }
- if (r > 0) {
- min_i = test_i + 1;
- }
- }
-
- if (comp_fn(needle, *(void * const *)(base_p + (size * min_i))) == 0) {
- return min_i;
- }
-
- return -1;
-}
-
-
-/*
common code for parsing -o options in ldb tools
*/
const char **ldb_options_parse(const char **options, int *ldbopts, const char *arg)
diff --git a/source4/lib/ldb/include/ldb_private.h b/source4/lib/ldb/include/ldb_private.h
index 3d3b1ec0eb..426da5ccae 100644
--- a/source4/lib/ldb/include/ldb_private.h
+++ b/source4/lib/ldb/include/ldb_private.h
@@ -100,10 +100,6 @@ int ldb_next_named_lock(struct ldb_module *module, const char *lockname);
int ldb_next_named_unlock(struct ldb_module *module, const char *lockname);
const char *ldb_next_errstring(struct ldb_module *module);
-/* The following definitions come from lib/ldb/common/util.c */
-int ldb_list_find(const void *needle,
- const void *base, size_t nmemb, size_t size, comparison_fn_t comp_fn);
-
/* The following definitions come from lib/ldb/common/ldb_debug.c */
void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4);
diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c
index ff0cabb0d6..88ef997a03 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_index.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_index.c
@@ -38,6 +38,57 @@
#include "ldb/ldb_tdb/ldb_tdb.h"
#include "ldb/include/ldb_parse.h"
+/*
+ find an element in a list, using the given comparison function and
+ assuming that the list is already sorted using comp_fn
+
+ return -1 if not found, or the index of the first occurance of needle if found
+*/
+static int ldb_list_find(const void *needle,
+ const void *base, size_t nmemb, size_t size,
+ comparison_fn_t comp_fn)
+{
+ const char *base_p = base;
+ size_t min_i, max_i, test_i;
+
+ if (nmemb == 0) {
+ return -1;
+ }
+
+ min_i = 0;
+ max_i = nmemb-1;
+
+ while (min_i < max_i) {
+ int r;
+
+ test_i = (min_i + max_i) / 2;
+ r = comp_fn(needle, *(void * const *)(base_p + (size * test_i)));
+ if (r == 0) {
+ /* scan back for first element */
+ while (test_i > 0 &&
+ comp_fn(needle, *(void * const *)(base_p + (size * (test_i-1)))) == 0) {
+ test_i--;
+ }
+ return test_i;
+ }
+ if (r < 0) {
+ if (test_i == 0) {
+ return -1;
+ }
+ max_i = test_i - 1;
+ }
+ if (r > 0) {
+ min_i = test_i + 1;
+ }
+ }
+
+ if (comp_fn(needle, *(void * const *)(base_p + (size * min_i))) == 0) {
+ return min_i;
+ }
+
+ return -1;
+}
+
struct dn_list {
unsigned int count;
char **dn;
diff --git a/source4/lib/ldb/ldb_tdb/ldb_pack.c b/source4/lib/ldb/ldb_tdb/ldb_pack.c
index a548a4189b..4c1241d0bd 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_pack.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_pack.c
@@ -139,16 +139,6 @@ int ltdb_pack_data(struct ldb_module *module,
}
/*
- free the memory allocated from a ltdb_unpack_data()
-*/
-void ltdb_unpack_data_free(struct ldb_module *module,
- struct ldb_message *message)
-{
- talloc_free(message->elements);
-}
-
-
-/*
unpack a ldb message from a linear buffer in TDB_DATA
Free with ltdb_unpack_data_free()
@@ -267,7 +257,6 @@ int ltdb_unpack_data(struct ldb_module *module,
return 0;
failed:
- ltdb_unpack_data_free(module, message);
-
+ talloc_free(message->elements);
return -1;
}
diff --git a/source4/lib/ldb/tests/test-generic.sh b/source4/lib/ldb/tests/test-generic.sh
index 4fb54b6c3b..2b2ab2e78a 100755
--- a/source4/lib/ldb/tests/test-generic.sh
+++ b/source4/lib/ldb/tests/test-generic.sh
@@ -27,11 +27,15 @@ $VALGRIND bin/ldbadd tests/test-index.ldif || exit 1
echo "testing indexed search"
$VALGRIND bin/ldbsearch '(uid=uham)' || exit 1
+$VALGRIND bin/ldbsearch '(&(objectclass=person)(objectclass=person)(objectclass=top))' || exit 1
$VALGRIND bin/ldbsearch '(&(uid=uham)(uid=uham))' || exit 1
$VALGRIND bin/ldbsearch '(|(uid=uham)(uid=uham))' || exit 1
$VALGRIND bin/ldbsearch '(|(uid=uham)(uid=uham)(objectclass=OpenLDAPperson))' || exit 1
$VALGRIND bin/ldbsearch '(&(uid=uham)(uid=uham)(!(objectclass=xxx)))' || exit 1
-$VALGRIND bin/ldbsearch '(&(uid=uham)(!(uid=uhamxx)))' || exit 1
+$VALGRIND bin/ldbsearch '(&(objectclass=person)(uid=uham)(!(uid=uhamxx)))' uid \* \+ dn || exit 1
+$VALGRIND bin/ldbsearch '(&(uid=uham)(uid=uha*)(title=*))' uid || exit 1
+$VALGRIND bin/ldbsearch '((' uid && exit 1
+$VALGRIND bin/ldbsearch 'dn=cn=Hampster Ursula,ou=Alumni Association,ou=People,o=University of Michigan,c=US' uid || exit 1
echo "Starting ldbtest indexed"
time $VALGRIND bin/ldbtest -r 1000 -s 5000 || exit 1
diff --git a/source4/lib/ldb/tests/test-index.ldif b/source4/lib/ldb/tests/test-index.ldif
index 6b2e921ebd..24ac408764 100644
--- a/source4/lib/ldb/tests/test-index.ldif
+++ b/source4/lib/ldb/tests/test-index.ldif
@@ -1,6 +1,11 @@
dn: @INDEXLIST
@IDXATTR: uid
-# it is much better not to index on objectclass if nearly
-# all the records are the same class (the index is expensive
-# to maintain, and doesn't really gain anything)
-# @IDXATTR: objectclass
+@IDXATTR: objectclass
+
+dn: @ATTRIBUTES
+uid: CASE_INSENSITIVE WILDCARD
+
+dn: @SUBCLASSES
+top: person
+person: organizationalPerson
+organizationalPerson: OpenLDAPperson
diff --git a/source4/lib/ldb/tests/test.ldif b/source4/lib/ldb/tests/test.ldif
index 8d6c0c750e..7fe3a8ffd7 100644
--- a/source4/lib/ldb/tests/test.ldif
+++ b/source4/lib/ldb/tests/test.ldif
@@ -212,7 +212,7 @@ objectclass: OpenLDAPperson
cn: Barbara Jensen
cn: Babs Jensen
sn:: IEplbnNlbiA=
-uid: bjensen
+uid:: YmplCW5zZW4
title: Mythical Manager, Research Systems
postaladdress: ITD Prod Dev & Deployment $ 535 W. William St. Room 4212 $ Ann
Arbor, MI 48103-4943
diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c
index 9041231faf..5e0246d7a9 100644
--- a/source4/lib/ldb/tools/ldbsearch.c
+++ b/source4/lib/ldb/tools/ldbsearch.c
@@ -153,7 +153,7 @@ static int do_search(struct ldb_context *ldb,
attrs = (const char * const *)(argv+1);
}
- ldb = ldb_connect(ldb_url, 0, options);
+ ldb = ldb_connect(ldb_url, LDB_FLG_RDONLY, options);
if (!ldb) {
perror("ldb_connect");
exit(1);