diff options
author | Andrew Bartlett <abartlet@samba.org> | 2008-02-21 09:55:13 +1100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2008-02-21 09:55:13 +1100 |
commit | 774fa12ac1695600710ce9fac18024edd38161ee (patch) | |
tree | 5440d8c0f00d28656e0d8f65f3b771eb11a01842 /source4/lib/ldb | |
parent | 49b3a4829325967df9d1e616ad32e5379ce6cf5d (diff) | |
parent | 910a1cafdf253255510d3aff7cc2385da43331dd (diff) | |
download | samba-774fa12ac1695600710ce9fac18024edd38161ee.tar.gz samba-774fa12ac1695600710ce9fac18024edd38161ee.tar.bz2 samba-774fa12ac1695600710ce9fac18024edd38161ee.zip |
Merge branch 'v4-0-test' of git://git.samba.org/samba into 4-0-local
(This used to be commit 5cd3310b78a85243eb436d05db3228c3495f9162)
Diffstat (limited to 'source4/lib/ldb')
38 files changed, 1041 insertions, 1124 deletions
diff --git a/source4/lib/ldb/Makefile.in b/source4/lib/ldb/Makefile.in index 7bd719cdd9..d88f82b726 100644 --- a/source4/lib/ldb/Makefile.in +++ b/source4/lib/ldb/Makefile.in @@ -19,6 +19,11 @@ SWIG = swig EXTRA_OBJ=@EXTRA_OBJ@ TESTS=test-tdb.sh @TESTS@ PACKAGE_VERSION = @PACKAGE_VERSION@ +PYTHON = @PYTHON@ +PYTHON_CONFIG = @PYTHON_CONFIG@ +tdbdir = @tdbdir@ +ldbdir = $(srcdir) +tallocdir = @tallocdir@ TALLOC_LIBS = @TALLOC_LIBS@ TALLOC_CFLAGS = @TALLOC_CFLAGS@ @@ -53,35 +58,6 @@ CFLAGS=-g -I$(srcdir)/include -Iinclude -I$(srcdir) -I$(srcdir)/.. \ MDLD = @MDLD@ MDLD_FLAGS = @MDLD_FLAGS@ -LDB_LIB = $(STATICLIB) - -LIB_FLAGS=$(LDFLAGS) -Llib $(LDB_LIB) $(LIBS) $(POPT_LIBS) $(TALLOC_LIBS) \ - $(TDB_LIBS) $(LDAP_LIBS) $(LIBDL) - -LDB_TDB_DIR=ldb_tdb -LDB_TDB_OBJ=$(LDB_TDB_DIR)/ldb_tdb.o \ - $(LDB_TDB_DIR)/ldb_pack.o $(LDB_TDB_DIR)/ldb_search.o $(LDB_TDB_DIR)/ldb_index.o \ - $(LDB_TDB_DIR)/ldb_cache.o $(LDB_TDB_DIR)/ldb_tdb_wrap.o - -LDB_MAP_DIR=ldb_map -LDB_MAP_OBJ=$(LDB_MAP_DIR)/ldb_map.o $(LDB_MAP_DIR)/ldb_map_inbound.o \ - $(LDB_MAP_DIR)/ldb_map_outbound.o - -COMDIR=common -COMMON_OBJ=$(COMDIR)/ldb.o $(COMDIR)/ldb_ldif.o \ - $(COMDIR)/ldb_parse.o $(COMDIR)/ldb_msg.o $(COMDIR)/ldb_utf8.o \ - $(COMDIR)/ldb_debug.o $(COMDIR)/ldb_modules.o \ - $(COMDIR)/ldb_dn.o $(COMDIR)/ldb_match.o $(COMDIR)/ldb_attributes.o \ - $(COMDIR)/attrib_handlers.o $(COMDIR)/ldb_controls.o $(COMDIR)/qsort.o - -MODDIR=modules -MODULES_OBJ=$(MODDIR)/operational.o $(MODDIR)/rdn_name.o \ - $(MODDIR)/paged_results.o $(MODDIR)/sort.o $(MODDIR)/asq.o - -NSSDIR=nssldb -NSS_OBJ= $(NSSDIR)/ldb-nss.o $(NSSDIR)/ldb-pwd.o $(NSSDIR)/ldb-grp.o -NSS_LIB = lib/libnss_ldb.$(SHLIBEXT).2 - OBJS = $(MODULES_OBJ) $(COMMON_OBJ) $(LDB_TDB_OBJ) $(TDB_OBJ) $(TALLOC_OBJ) $(POPT_OBJ) $(LDB_MAP_OBJ) @LIBREPLACEOBJ@ $(EXTRA_OBJ) headers = $(srcdir)/include/ldb.h $(srcdir)/include/ldb_errors.h $(srcdir)/include/ldb_handlers.h @@ -94,6 +70,8 @@ DIRS = lib bin common ldb_tdb ldb_ldap ldb_sqlite3 modules tools examples default: all +include $(ldbdir)/rules.mk + nss: nssdir all $(NSS_LIB) nssdir: @@ -109,76 +87,22 @@ lib/$(SONAME): $(SOLIB) lib/libldb.$(SHLIBEXT): $(SOLIB) ln -fs libldb.$(SHLIBEXT).$(PACKAGE_VERSION) $@ +lib/libnss_ldb.$(SHLIBEXT).2: $(NSS_OBJ) $(SOLIB) + $(SHLD) $(SHLD_FLAGS) -o $@ $(NSS_OBJ) $(LDFLAGS) $(SOLIB) @SONAMEFLAG@libnss_ldb.$(SHLIBEXT).2 + $(SOLIB): $(OBJS) $(SHLD) $(SHLD_FLAGS) -o $@ $(OBJS) $(LDFLAGS) $(LIBS) $(TALLOC_LIBS) $(TDB_LIBS) $(LIBDL) $(LDAP_LIBS) @SONAMEFLAG@$(SONAME) all: showflags dirs $(OBJS) $(STATICLIB) $(SOLIB) $(BINS) $(EXAMPLES) manpages \ @PYTHON_BUILD_TARGET@ -showflags: - @echo 'ldb will be compiled with flags:' - @echo ' CFLAGS = $(CFLAGS)' - @echo ' LIBS = $(LIBS)' - -.c.o: - @echo Compiling $*.c - @mkdir -p `dirname $@` - @$(CC) $(CFLAGS) $(PICFLAG) -c $< -o $@ - -.c.po: - @echo Compiling $*.c - @mkdir -p `dirname $@` - @$(CC) -fPIC $(CFLAGS) -c $< -o $@ - dirs: @mkdir -p $(DIRS) -lib/libldb.a: $(OBJS) - ar -rv $@ $(OBJS) - @-ranlib $@ - -lib/libnss_ldb.$(SHLIBEXT).2: $(NSS_OBJ) $(SOLIB) - $(SHLD) $(SHLD_FLAGS) -o $@ $(NSS_OBJ) $(LDFLAGS) $(SOLIB) @SONAMEFLAG@libnss_ldb.$(SHLIBEXT).2 - -sample_module.$(SHLIBEXT): tests/sample_module.o - $(MDLD) $(MDLD_FLAGS) -o $@ tests/sample_module.o - -bin/ldbadd: tools/ldbadd.o tools/cmdline.o $(LIBS) - $(CC) -o bin/ldbadd tools/ldbadd.o tools/cmdline.o $(LIB_FLAGS) $(LD_EXPORT_DYNAMIC) - -bin/ldbsearch: tools/ldbsearch.o tools/cmdline.o $(LIBS) - $(CC) -o bin/ldbsearch tools/ldbsearch.o tools/cmdline.o $(LIB_FLAGS) $(LD_EXPORT_DYNAMIC) - -bin/ldbdel: tools/ldbdel.o tools/cmdline.o $(LIBS) - $(CC) -o bin/ldbdel tools/ldbdel.o tools/cmdline.o $(LIB_FLAGS) $(LD_EXPORT_DYNAMIC) - -bin/ldbmodify: tools/ldbmodify.o tools/cmdline.o $(LIBS) - $(CC) -o bin/ldbmodify tools/ldbmodify.o tools/cmdline.o $(LIB_FLAGS) $(LD_EXPORT_DYNAMIC) - -bin/ldbedit: tools/ldbedit.o tools/cmdline.o $(LIBS) - $(CC) -o bin/ldbedit tools/ldbedit.o tools/cmdline.o $(LIB_FLAGS) $(LD_EXPORT_DYNAMIC) - -bin/ldbrename: tools/ldbrename.o tools/cmdline.o $(LIBS) - $(CC) -o bin/ldbrename tools/ldbrename.o tools/cmdline.o $(LIB_FLAGS) $(LD_EXPORT_DYNAMIC) - -bin/ldbtest: tools/ldbtest.o tools/cmdline.o $(LIBS) - $(CC) -o bin/ldbtest tools/ldbtest.o tools/cmdline.o $(LIB_FLAGS) $(LD_EXPORT_DYNAMIC) - -bin/oLschema2ldif: tools/oLschema2ldif.o tools/cmdline.o tools/convert.o $(LIBS) - $(CC) -o bin/oLschema2ldif tools/oLschema2ldif.o tools/cmdline.o tools/convert.o $(LIB_FLAGS) - -examples/ldbreader: examples/ldbreader.o $(LIBS) - $(CC) -o examples/ldbreader examples/ldbreader.o $(LIB_FLAGS) - -examples/ldifreader: examples/ldifreader.o $(LIBS) - $(CC) -o examples/ldifreader examples/ldifreader.o $(LIB_FLAGS) - -.SUFFIXES: .1 .1.xml .3 .3.xml .xml .html .c .o - -manpages: +manpages:: @$(srcdir)/docs/builddocs.sh "$(XSLTPROC)" "$(srcdir)" -doxygen: +doxygen:: test -z "$(DOXYGEN)" || (cd $(srcdir) && "$(DOXYGEN)") clean:: @@ -191,7 +115,6 @@ clean:: rm -rf tests/schema/ distclean:: clean - rm -f *~ */*~ rm -rf bin lib rm -f config.log config.status config.cache include/config.h rm -f ldb.pc @@ -200,39 +123,39 @@ distclean:: clean realdistclean:: distclean rm -f configure.in include/config.h.in -check:: test check-soloading +check:: test @PYTHON_CHECK_TARGET@ -check-soloading: sample_module.$(SHLIBEXT) +check-soloading: sample.$(SHLIBEXT) LDB_MODULES_PATH=$(builddir) $(srcdir)/tests/test-soloading.sh -test: all check-soloading +test:: all check-soloading for t in $(TESTS); do echo STARTING $${t}; $(srcdir)/tests/$${t} || exit 1; done -valgrindtest: all +valgrindtest:: all for t in $(TESTS); do echo STARTING $${t}; VALGRIND="valgrind -q --db-attach=yes --num-callers=30" $(srcdir)/tests/$${t} || exit 1; done -installcheck: install test +installcheck:: install test install:: all installdirs installheaders installlibs installbin installdocs \ @PYTHON_INSTALL_TARGET@ -installdirs: +installdirs:: mkdir -p $(DESTDIR)$(includedir) $(DESTDIR)$(libdir) $(DESTDIR)$(bindir) $(DESTDIR)$(libdir)/pkgconfig -installheaders: installdirs +installheaders:: installdirs cp $(headers) $(DESTDIR)$(includedir) -installlibs: installdirs +installlibs:: installdirs cp $(STATICLIB) $(SOLIB) $(DESTDIR)$(libdir) cp ldb.pc $(DESTDIR)$(libdir)/pkgconfig -installbin: installdirs +installbin:: installdirs cp $(BINS) $(DESTDIR)$(bindir) -installdocs: installdirs +installdocs:: installdirs $(srcdir)/docs/installdocs.sh $(DESTDIR)$(mandir) -gcov: +gcov:: $(GCOV) -po ldb_sqlite3 $(srcdir)/ldb_sqlite3/*.c 2| tee ldb_sqlite3.report.gcov $(GCOV) -po ldb_ldap $(srcdir)/ldb_ldap/*.c 2| tee ldb_ldap.report.gcov $(GCOV) -po ldb_tdb $(srcdir)/ldb_tdb/*.c 2| tee ldb_tdb.report.gcov @@ -240,30 +163,4 @@ gcov: $(GCOV) -po modules $(srcdir)/modules/*.c 2| tee modules.report.gcov $(GCOV) -po tools $(srcdir)/tools/*.c 2| tee tools.report.gcov -etags: - etags `find $(srcdir) -name "*.[ch]"` - -ctags: - ctags `find $(srcdir) -name "*.[ch]"` - -.SUFFIXES: _wrap.c .i - -.i_wrap.c: - [ "$(SWIG)" == "no" ] || $(SWIG) -O -Wall -python -keyword $< - -# Python bindings -build-python: lib/libldb.$(SHLIBEXT) ldb_wrap.c - ./setup.py build - -install-python: build-python - ./setup.py install --prefix=$(DESTDIR)$(prefix) - -install-swig: - cp ldb.i `$(SWIG) -swiglib` - -check-python: build-python - # FIXME: This isn't portable - LD_LIBRARY_PATH=lib PYTHONPATH=.:build/lib.linux-i686-2.4/ trial tests/python/api.py - -clean-python: - ./setup.py clean +include $(ldbdir)/ldb.mk diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c index 5601a33191..3c9ef3ff69 100644 --- a/source4/lib/ldb/common/ldb.c +++ b/source4/lib/ldb/common/ldb.c @@ -56,20 +56,51 @@ struct ldb_context *ldb_init(void *mem_ctx) return ldb; } -struct ldb_backend { - const char *name; - ldb_connect_fn connect_fn; - struct ldb_backend *prev, *next; +static struct backends_list_entry { + struct ldb_backend_ops *ops; + struct backends_list_entry *prev, *next; } *ldb_backends = NULL; +#ifndef STATIC_LIBLDB_BACKENDS + +#ifdef HAVE_LDB_LDAP +#define LDAP_INIT &ldb_ldap_backend_ops, \ + &ldb_ildap_backend_ops, \ + &ldb_ldaps_backend_ops, +#else +#define LDAP_INIT +#endif + +#ifdef HAVE_LDB_SQLITE3 +#define SQLITE3_INIT &ldb_sqlite3_backend_ops, +#else +#define SQLITE3_INIT +#endif + +#define STATIC_LIBLDB_BACKENDS \ + LDAP_INIT \ + SQLITE3_INIT \ + &ldb_tdb_backend_ops, \ + NULL +#endif + +const static struct ldb_backend_ops *builtin_backends[] = { + STATIC_LIBLDB_BACKENDS +}; static ldb_connect_fn ldb_find_backend(const char *url) { - struct ldb_backend *backend; + struct backends_list_entry *backend; + int i; + + for (i = 0; builtin_backends[i]; i++) { + if (strncmp(builtin_backends[i]->name, url, strlen(builtin_backends[i]->name)) == 0) + return builtin_backends[i]->connect_fn; + } for (backend = ldb_backends; backend; backend = backend->next) { - if (strncmp(backend->name, url, strlen(backend->name)) == 0) { - return backend->connect_fn; + if (strncmp(backend->ops->name, url, strlen(backend->ops->name)) == 0) { + return backend->ops->connect_fn; } } @@ -81,7 +112,8 @@ static ldb_connect_fn ldb_find_backend(const char *url) */ int ldb_register_backend(const char *url_prefix, ldb_connect_fn connectfn) { - struct ldb_backend *backend = talloc(talloc_autofree_context(), struct ldb_backend); + struct ldb_backend_ops *backend = talloc(talloc_autofree_context(), struct ldb_backend_ops); + struct backends_list_entry *entry = talloc(talloc_autofree_context(), struct backends_list_entry); if (ldb_find_backend(url_prefix)) { return LDB_SUCCESS; @@ -91,7 +123,8 @@ int ldb_register_backend(const char *url_prefix, ldb_connect_fn connectfn) backend->name = talloc_strdup(backend, url_prefix); backend->connect_fn = connectfn; - DLIST_ADD(ldb_backends, backend); + entry->ops = backend; + DLIST_ADD(ldb_backends, entry); return LDB_SUCCESS; } @@ -135,6 +168,19 @@ int ldb_connect_backend(struct ldb_context *ldb, const char *url, const char *op } } + if (fn == NULL) { + struct ldb_backend_ops *ops; + char *symbol_name = talloc_asprintf(ldb, "ldb_%s_backend_ops", backend); + if (symbol_name == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + ops = ldb_dso_load_symbol(ldb, backend, symbol_name); + if (ops != NULL) { + fn = ops->connect_fn; + } + talloc_free(symbol_name); + } + talloc_free(backend); if (fn == NULL) { @@ -236,7 +282,6 @@ int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, co int ret; const char *url2; /* We seem to need to do this here, or else some utilities don't get ldb backends */ - ldb_global_init(); ldb->flags = flags; diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c index 18070bdb86..7da7b9ba34 100644 --- a/source4/lib/ldb/common/ldb_modules.c +++ b/source4/lib/ldb/common/ldb_modules.c @@ -126,9 +126,30 @@ static struct ops_list_entry { struct ops_list_entry *next; } *registered_modules = NULL; +#ifndef STATIC_LIBLDB_MODULES + +#define STATIC_LIBLDB_MODULES \ + ldb_operational_module_ops, \ + ldb_rdn_name_module_ops, \ + ldb_paged_results_module_ops, \ + ldb_sort_module_ops, \ + ldb_asq_module_ops, \ + NULL +#endif + +const static struct ldb_module_ops *builtin_modules[] = { + STATIC_LIBLDB_MODULES +}; + static const struct ldb_module_ops *ldb_find_module_ops(const char *name) { struct ops_list_entry *e; + int i; + + for (i = 0; builtin_modules[i]; i++) { + if (strcmp(builtin_modules[i]->name, name) == 0) + return builtin_modules[i]; + } for (e = registered_modules; e; e = e->next) { if (strcmp(e->ops->name, name) == 0) @@ -138,51 +159,6 @@ static const struct ldb_module_ops *ldb_find_module_ops(const char *name) return NULL; } -#ifndef STATIC_LIBLDB_MODULES - -#ifdef HAVE_LDB_LDAP -#define LDAP_INIT ldb_ldap_init, -#else -#define LDAP_INIT -#endif - -#ifdef HAVE_LDB_SQLITE3 -#define SQLITE3_INIT ldb_sqlite3_init, -#else -#define SQLITE3_INIT -#endif - -#define STATIC_LIBLDB_MODULES \ - LDAP_INIT \ - SQLITE3_INIT \ - ldb_tdb_init, \ - ldb_operational_init, \ - ldb_rdn_name_init, \ - ldb_paged_results_init, \ - ldb_sort_init, \ - ldb_asq_init, \ - NULL -#endif - -int ldb_global_init(void) -{ - int (*static_init_fns[])(void) = { STATIC_LIBLDB_MODULES }; - - static int initialized = 0; - int ret = 0, i; - - if (initialized) - return 0; - - initialized = 1; - - for (i = 0; static_init_fns[i]; i++) { - if (static_init_fns[i]() == -1) - ret = -1; - } - - return ret; -} int ldb_register_module(const struct ldb_module_ops *ops) { @@ -257,8 +233,13 @@ int ldb_load_modules_list(struct ldb_context *ldb, const char **module_list, str } if (ops == NULL) { - ops = ldb_dso_load_symbol(ldb, module_list[i], - "ldb_module_ops"); + char *symbol_name = talloc_asprintf(ldb, "ldb_%s_module_ops", + module_list[i]); + if (symbol_name == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + ops = ldb_dso_load_symbol(ldb, module_list[i], symbol_name); + talloc_free(symbol_name); } if (ops == NULL) { diff --git a/source4/lib/ldb/config.mk b/source4/lib/ldb/config.mk index 75ce89d6cf..6027acd0c7 100644 --- a/source4/lib/ldb/config.mk +++ b/source4/lib/ldb/config.mk @@ -3,7 +3,7 @@ [MODULE::ldb_asq] PRIVATE_DEPENDENCIES = LIBTALLOC CFLAGS = -Ilib/ldb/include -INIT_FUNCTION = ldb_asq_init +INIT_FUNCTION = &ldb_asq_module_ops SUBSYSTEM = LIBLDB OBJ_FILES = \ modules/asq.o @@ -15,7 +15,7 @@ OBJ_FILES = \ [MODULE::ldb_server_sort] PRIVATE_DEPENDENCIES = LIBTALLOC CFLAGS = -Ilib/ldb/include -INIT_FUNCTION = ldb_sort_init +INIT_FUNCTION = &ldb_server_sort_module_ops SUBSYSTEM = LIBLDB OBJ_FILES = \ modules/sort.o @@ -25,7 +25,7 @@ OBJ_FILES = \ ################################################ # Start MODULE ldb_paged_results [MODULE::ldb_paged_results] -INIT_FUNCTION = ldb_paged_results_init +INIT_FUNCTION = &ldb_paged_results_module_ops CFLAGS = -Ilib/ldb/include PRIVATE_DEPENDENCIES = LIBTALLOC SUBSYSTEM = LIBLDB @@ -37,7 +37,7 @@ OBJ_FILES = \ ################################################ # Start MODULE ldb_paged_results [MODULE::ldb_paged_searches] -INIT_FUNCTION = ldb_paged_searches_init +INIT_FUNCTION = &ldb_paged_searches_module_ops CFLAGS = -Ilib/ldb/include PRIVATE_DEPENDENCIES = LIBTALLOC SUBSYSTEM = LIBLDB @@ -52,7 +52,7 @@ OBJ_FILES = \ SUBSYSTEM = LIBLDB CFLAGS = -Ilib/ldb/include PRIVATE_DEPENDENCIES = LIBTALLOC -INIT_FUNCTION = ldb_operational_init +INIT_FUNCTION = &ldb_operational_module_ops OBJ_FILES = \ modules/operational.o # End MODULE ldb_operational @@ -64,7 +64,7 @@ OBJ_FILES = \ SUBSYSTEM = LIBLDB CFLAGS = -Ilib/ldb/include PRIVATE_DEPENDENCIES = LIBTALLOC -INIT_FUNCTION = ldb_rdn_name_init +INIT_FUNCTION = &ldb_rdn_name_module_ops OBJ_FILES = \ modules/rdn_name.o # End MODULE ldb_rdn_name @@ -88,7 +88,7 @@ OBJ_FILES = \ SUBSYSTEM = LIBLDB CFLAGS = -Ilib/ldb/include PRIVATE_DEPENDENCIES = LIBTALLOC -INIT_FUNCTION = ldb_skel_init +INIT_FUNCTION = &ldb_skel_module_ops OBJ_FILES = modules/skel.o # End MODULE ldb_skel ################################################ @@ -99,7 +99,7 @@ OBJ_FILES = modules/skel.o SUBSYSTEM = LIBLDB CFLAGS = -Ilib/ldb/include PRIVATE_DEPENDENCIES = LIBTALLOC SQLITE3 LIBTALLOC -INIT_FUNCTION = ldb_sqlite3_init +INIT_FUNCTION = &ldb_sqlite3_module_ops OBJ_FILES = \ ldb_sqlite3/ldb_sqlite3.o # End MODULE ldb_sqlite3 @@ -110,7 +110,6 @@ OBJ_FILES = \ [MODULE::ldb_tdb] SUBSYSTEM = LIBLDB CFLAGS = -Ilib/ldb/include -Ilib/ldb/ldb_tdb -INIT_FUNCTION = ldb_tdb_init OBJ_FILES = \ ldb_tdb/ldb_tdb.o \ ldb_tdb/ldb_search.o \ @@ -128,10 +127,9 @@ PRIVATE_DEPENDENCIES = \ [LIBRARY::LIBLDB] VERSION = 0.0.1 SO_VERSION = 0 -OUTPUT_TYPE = SHARED_LIBRARY CFLAGS = -Ilib/ldb/include PC_FILE = ldb.pc -INIT_FUNCTION_TYPE = int (*) (void) +INIT_FUNCTION_TYPE = extern const struct ldb_module_ops OBJ_FILES = \ common/ldb.o \ common/ldb_ldif.o \ @@ -193,5 +191,5 @@ PRIVATE_DEPENDENCIES = \ ################################################ -include tools/config.mk -include ldb_ildap/config.mk +mkinclude tools/config.mk +mkinclude ldb_ildap/config.mk diff --git a/source4/lib/ldb/configure.ac b/source4/lib/ldb/configure.ac index 176cef0f3e..4d9444ad10 100644 --- a/source4/lib/ldb/configure.ac +++ b/source4/lib/ldb/configure.ac @@ -78,14 +78,18 @@ AC_LIBREPLACE_MDLD_FLAGS AC_LIBREPLACE_RUNTIME_LIB_PATH_VAR AC_PATH_PROGS([PYTHON_CONFIG], [python2.6-config python2.5-config python2.4-config python-config]) +AC_PATH_PROGS([PYTHON], [python2.6 python2.5 python2.4 python]) PYTHON_BUILD_TARGET="build-python" PYTHON_INSTALL_TARGET="install-python" +PYTHON_CHECK_TARGET="check-python" AC_SUBST(PYTHON_BUILD_TARGET) AC_SUBST(PYTHON_INSTALL_TARGET) +AC_SUBST(PYTHON_CHECK_TARGET) if test -z "$PYTHON_CONFIG"; then PYTHON_BUILD_TARGET="" + PYTHON_CHECK_TARGET="" PYTHON_INSTALL_TARGET="" fi diff --git a/source4/lib/ldb/include/ldb_private.h b/source4/lib/ldb/include/ldb_private.h index d9f2defdc9..d2dcc675a5 100644 --- a/source4/lib/ldb/include/ldb_private.h +++ b/source4/lib/ldb/include/ldb_private.h @@ -41,6 +41,8 @@ struct ldb_context; struct ldb_module_ops; +struct ldb_backend_ops; + /* basic module structure */ struct ldb_module { struct ldb_module *prev, *next; @@ -70,9 +72,16 @@ struct ldb_module_ops { int (*sequence_number)(struct ldb_module *, struct ldb_request *); }; + typedef int (*ldb_connect_fn) (struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[], struct ldb_module **module); + +struct ldb_backend_ops { + const char *name; + ldb_connect_fn connect_fn; +}; + const char *ldb_default_modules_dir(void); /* @@ -170,17 +179,23 @@ void ldb_debug_set(struct ldb_context *ldb, enum ldb_debug_level level, /* The following definitions come from lib/ldb/common/ldb_ldif.c */ int ldb_should_b64_encode(const struct ldb_val *val); -int ldb_objectclass_init(void); -int ldb_operational_init(void); -int ldb_paged_results_init(void); -int ldb_rdn_name_init(void); -int ldb_schema_init(void); -int ldb_asq_init(void); -int ldb_sort_init(void); -int ldb_ldap_init(void); -int ldb_ildap_init(void); -int ldb_tdb_init(void); -int ldb_sqlite3_init(void); +extern const struct ldb_module_ops ldb_objectclass_module_ops; +extern const struct ldb_module_ops ldb_operational_module_ops; +extern const struct ldb_module_ops ldb_paged_results_module_ops; +extern const struct ldb_module_ops ldb_rdn_name_module_ops; +extern const struct ldb_module_ops ldb_schema_module_ops; +extern const struct ldb_module_ops ldb_asq_module_ops; +extern const struct ldb_module_ops ldb_sort_module_ops; +extern const struct ldb_module_ops ldb_ldap_module_ops; +extern const struct ldb_module_ops ldb_ildap_module_ops; +extern const struct ldb_module_ops ldb_tdb_module_ops; +extern const struct ldb_module_ops ldb_sqlite3_module_ops; + +extern const struct ldb_backend_ops ldb_tdb_backend_ops; +extern const struct ldb_backend_ops ldb_sqlite3_backend_ops; +extern const struct ldb_backend_ops ldb_ldap_backend_ops; +extern const struct ldb_backend_ops ldb_ildap_backend_ops; +extern const struct ldb_backend_ops ldb_ldaps_backend_ops; int ldb_match_msg(struct ldb_context *ldb, const struct ldb_message *msg, diff --git a/source4/lib/ldb/ldb.mk b/source4/lib/ldb/ldb.mk new file mode 100644 index 0000000000..cc920178bc --- /dev/null +++ b/source4/lib/ldb/ldb.mk @@ -0,0 +1,89 @@ +LDB_LIB = $(STATICLIB) + +LIB_FLAGS=$(LDFLAGS) -Llib $(LDB_LIB) $(LIBS) $(POPT_LIBS) $(TALLOC_LIBS) \ + $(TDB_LIBS) $(LDAP_LIBS) $(LIBDL) + +LDB_TDB_DIR=ldb_tdb +LDB_TDB_OBJ=$(LDB_TDB_DIR)/ldb_tdb.o \ + $(LDB_TDB_DIR)/ldb_pack.o $(LDB_TDB_DIR)/ldb_search.o $(LDB_TDB_DIR)/ldb_index.o \ + $(LDB_TDB_DIR)/ldb_cache.o $(LDB_TDB_DIR)/ldb_tdb_wrap.o + +LDB_MAP_DIR=ldb_map +LDB_MAP_OBJ=$(LDB_MAP_DIR)/ldb_map.o $(LDB_MAP_DIR)/ldb_map_inbound.o \ + $(LDB_MAP_DIR)/ldb_map_outbound.o + +COMDIR=common +COMMON_OBJ=$(COMDIR)/ldb.o $(COMDIR)/ldb_ldif.o \ + $(COMDIR)/ldb_parse.o $(COMDIR)/ldb_msg.o $(COMDIR)/ldb_utf8.o \ + $(COMDIR)/ldb_debug.o $(COMDIR)/ldb_modules.o \ + $(COMDIR)/ldb_dn.o $(COMDIR)/ldb_match.o $(COMDIR)/ldb_attributes.o \ + $(COMDIR)/attrib_handlers.o $(COMDIR)/ldb_controls.o $(COMDIR)/qsort.o + +MODDIR=modules +MODULES_OBJ=$(MODDIR)/operational.o $(MODDIR)/rdn_name.o \ + $(MODDIR)/paged_results.o $(MODDIR)/sort.o $(MODDIR)/asq.o + +NSSDIR=nssldb +NSS_OBJ= $(NSSDIR)/ldb-nss.o $(NSSDIR)/ldb-pwd.o $(NSSDIR)/ldb-grp.o +NSS_LIB = lib/libnss_ldb.$(SHLIBEXT).2 + +lib/libldb.a: $(OBJS) + ar -rv $@ $(OBJS) + @-ranlib $@ + +sample.$(SHLIBEXT): tests/sample_module.o + $(MDLD) $(MDLD_FLAGS) -o $@ tests/sample_module.o + +bin/ldbadd: tools/ldbadd.o tools/cmdline.o $(LIBS) + $(CC) -o bin/ldbadd tools/ldbadd.o tools/cmdline.o $(LIB_FLAGS) $(LD_EXPORT_DYNAMIC) + +bin/ldbsearch: tools/ldbsearch.o tools/cmdline.o $(LIBS) + $(CC) -o bin/ldbsearch tools/ldbsearch.o tools/cmdline.o $(LIB_FLAGS) $(LD_EXPORT_DYNAMIC) + +bin/ldbdel: tools/ldbdel.o tools/cmdline.o $(LIBS) + $(CC) -o bin/ldbdel tools/ldbdel.o tools/cmdline.o $(LIB_FLAGS) $(LD_EXPORT_DYNAMIC) + +bin/ldbmodify: tools/ldbmodify.o tools/cmdline.o $(LIBS) + $(CC) -o bin/ldbmodify tools/ldbmodify.o tools/cmdline.o $(LIB_FLAGS) $(LD_EXPORT_DYNAMIC) + +bin/ldbedit: tools/ldbedit.o tools/cmdline.o $(LIBS) + $(CC) -o bin/ldbedit tools/ldbedit.o tools/cmdline.o $(LIB_FLAGS) $(LD_EXPORT_DYNAMIC) + +bin/ldbrename: tools/ldbrename.o tools/cmdline.o $(LIBS) + $(CC) -o bin/ldbrename tools/ldbrename.o tools/cmdline.o $(LIB_FLAGS) $(LD_EXPORT_DYNAMIC) + +bin/ldbtest: tools/ldbtest.o tools/cmdline.o $(LIBS) + $(CC) -o bin/ldbtest tools/ldbtest.o tools/cmdline.o $(LIB_FLAGS) $(LD_EXPORT_DYNAMIC) + +bin/oLschema2ldif: tools/oLschema2ldif.o tools/cmdline.o tools/convert.o $(LIBS) + $(CC) -o bin/oLschema2ldif tools/oLschema2ldif.o tools/cmdline.o tools/convert.o $(LIB_FLAGS) + +examples/ldbreader: examples/ldbreader.o $(LIBS) + $(CC) -o examples/ldbreader examples/ldbreader.o $(LIB_FLAGS) + +examples/ldifreader: examples/ldifreader.o $(LIBS) + $(CC) -o examples/ldifreader examples/ldifreader.o $(LIB_FLAGS) + +# Python bindings +build-python:: _ldb.$(SHLIBEXT) + +ldb_wrap.o: $(ldbdir)/ldb_wrap.c + $(CC) $(PICFLAG) -c $(ldbdir)/ldb_wrap.c $(CFLAGS) `$(PYTHON_CONFIG) --cflags` + +_ldb.$(SHLIBEXT): $(LIBS) ldb_wrap.o + $(SHLD) $(SHLD_FLAGS) -o _ldb.$(SHLIBEXT) ldb_wrap.o $(LIB_FLAGS) + +install-python:: build-python + mkdir -p $(DESTDIR)`$(PYTHON) -c "import distutils.sysconfig; print distutils.sysconfig.get_python_lib(0, prefix='$(prefix)')"` \ + $(DESTDIR)`$(PYTHON) -c "import distutils.sysconfig; print distutils.sysconfig.get_python_lib(1, prefix='$(prefix)')"` + cp $(ldbdir)/ldb.py $(DESTDIR)`$(PYTHON) -c "import distutils.sysconfig; print distutils.sysconfig.get_python_lib(0, prefix='$(prefix)')"` + cp _ldb.$(SHLIBEXT) $(DESTDIR)`$(PYTHON) -c "import distutils.sysconfig; print distutils.sysconfig.get_python_lib(1, prefix='$(prefix)')"` + +install-swig:: + cp ldb.i `$(SWIG) -swiglib` + +check-python:: build-python + LD_LIBRARY_PATH=lib PYTHONPATH=.:$(ldbdir) $(PYTHON) $(ldbdir)/tests/python/api.py + +clean:: + rm -f _ldb.$(SHLIBEXT) diff --git a/source4/lib/ldb/ldb_ildap/config.mk b/source4/lib/ldb/ldb_ildap/config.mk index 01d9ec88ff..3062dc886f 100644 --- a/source4/lib/ldb/ldb_ildap/config.mk +++ b/source4/lib/ldb/ldb_ildap/config.mk @@ -5,7 +5,6 @@ SUBSYSTEM = LIBLDB CFLAGS = -Ilib/ldb/include OUTPUT_TYPE = SHARED_LIBRARY PRIVATE_DEPENDENCIES = LIBTALLOC LIBCLI_LDAP CREDENTIALS -INIT_FUNCTION = ldb_ildap_init ALIASES = ldapi ldaps ldap OBJ_FILES = \ ldb_ildap.o diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index a834e912d4..995b584f51 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -811,9 +811,18 @@ failed: return -1; } -int ldb_ildap_init(void) -{ - return ldb_register_backend("ldap", ildb_connect) + - ldb_register_backend("ldapi", ildb_connect) + - ldb_register_backend("ldaps", ildb_connect); -} +_PUBLIC_ const struct ldb_backend_ops ldb_ldap_backend_ops = { + .name = "ldap", + .connect_fn = ildb_connect +}; + +_PUBLIC_ const struct ldb_backend_ops ldb_ildap_backend_ops = { + .name = "ildap", + .connect_fn = ildb_connect +}; + +_PUBLIC_ const struct ldb_backend_ops ldb_ldaps_backend_ops = { + .name = "ldaps", + .connect_fn = ildb_connect +}; + diff --git a/source4/lib/ldb/ldb_ldap/ldb_ldap.c b/source4/lib/ldb/ldb_ldap/ldb_ldap.c index d897350c2f..3f6ff3fd5b 100644 --- a/source4/lib/ldb/ldb_ldap/ldb_ldap.c +++ b/source4/lib/ldb/ldb_ldap/ldb_ldap.c @@ -826,9 +826,17 @@ failed: return -1; } -int ldb_ldap_init(void) -{ - return ldb_register_backend("ldap", lldb_connect) + - ldb_register_backend("ldapi", lldb_connect) + - ldb_register_backend("ldaps", lldb_connect); -} +_PUBLIC_ struct ldb_backend_ops ldb_ldap_backend_ops = { + .name = "ldap", + .connect_fn = lldb_connect +}; + +_PUBLIC_ struct ldb_backend_ops ldb_ldapi_backend_ops = { + .name = "ldapi", + .connect_fn = lldb_connect +}; + +_PUBLIC_ struct ldb_backend_ops ldb_ldaps_backend_ops = { + .name = "ldaps", + .connect_fn = lldb_connect +}; diff --git a/source4/lib/ldb/ldb_map/ldb_map.c b/source4/lib/ldb/ldb_map/ldb_map.c index 9582f36130..9c189feb11 100644 --- a/source4/lib/ldb/ldb_map/ldb_map.c +++ b/source4/lib/ldb/ldb_map/ldb_map.c @@ -1186,7 +1186,7 @@ static int map_wait_all(struct ldb_handle *handle) } /* Wait for pending requests to finish. */ -static int map_wait(struct ldb_handle *handle, enum ldb_wait_type type) +int map_wait(struct ldb_handle *handle, enum ldb_wait_type type) { if (type == LDB_WAIT_ALL) { return map_wait_all(handle); @@ -1199,16 +1199,6 @@ static int map_wait(struct ldb_handle *handle, enum ldb_wait_type type) /* Module initialization * ===================== */ -/* Provided module operations */ -static const struct ldb_module_ops map_ops = { - .name = "ldb_map", - .add = map_add, - .modify = map_modify, - .del = map_delete, - .rename = map_rename, - .search = map_search, - .wait = map_wait, -}; /* Builtin mappings for DNs and objectClasses */ static const struct ldb_map_attribute builtin_attribute_maps[] = { @@ -1344,12 +1334,6 @@ static int map_init_maps(struct ldb_module *module, struct ldb_map_context *data return LDB_SUCCESS; } -/* Copy the list of provided module operations. */ -_PUBLIC_ struct ldb_module_ops ldb_map_get_ops(void) -{ - return map_ops; -} - /* Initialize global private data. */ _PUBLIC_ int ldb_map_init(struct ldb_module *module, const struct ldb_map_attribute *attrs, const struct ldb_map_objectclass *ocls, @@ -1393,23 +1377,3 @@ _PUBLIC_ int ldb_map_init(struct ldb_module *module, const struct ldb_map_attrib return LDB_SUCCESS; } - -/* Usage note for initialization of this module: - * - * ldb_map is meant to be used from a different module that sets up - * the mappings and gets registered in ldb. - * - * 'ldb_map_init' initializes the private data of this module and - * stores the attribute and objectClass maps in there. It also looks - * up the '@MAP' special DN so requests can be redirected to the - * remote partition. - * - * This function should be called from the 'init_context' op of the - * module using ldb_map. - * - * 'ldb_map_get_ops' returns a copy of ldb_maps module operations. - * - * It should be called from the initialize function of the using - * module, which should then override the 'init_context' op with a - * function making the appropriate calls to 'ldb_map_init'. - */ diff --git a/source4/lib/ldb/ldb_map/ldb_map.h b/source4/lib/ldb/ldb_map/ldb_map.h index ef4da4e654..e40bb9cd7e 100644 --- a/source4/lib/ldb/ldb_map/ldb_map.h +++ b/source4/lib/ldb/ldb_map/ldb_map.h @@ -155,8 +155,19 @@ int ldb_map_init(struct ldb_module *module, const struct ldb_map_attribute *attr const char *add_objectclass, const char *name); -/* get copy of map_ops */ -struct ldb_module_ops -ldb_map_get_ops(void); +int map_add(struct ldb_module *module, struct ldb_request *req); +int map_search(struct ldb_module *module, struct ldb_request *req); +int map_rename(struct ldb_module *module, struct ldb_request *req); +int map_delete(struct ldb_module *module, struct ldb_request *req); +int map_modify(struct ldb_module *module, struct ldb_request *req); +int map_wait(struct ldb_handle *handle, enum ldb_wait_type type); + +#define LDB_MAP_OPS \ + .add = map_add, \ + .modify = map_modify, \ + .del = map_delete, \ + .rename = map_rename, \ + .search = map_search, \ + .wait = map_wait, #endif /* __LDB_MAP_H__ */ diff --git a/source4/lib/ldb/ldb_map/ldb_map_private.h b/source4/lib/ldb/ldb_map/ldb_map_private.h index 2c35097069..58a9f2704e 100644 --- a/source4/lib/ldb/ldb_map/ldb_map_private.h +++ b/source4/lib/ldb/ldb_map/ldb_map_private.h @@ -98,20 +98,13 @@ int map_subtree_collect_remote_simple(struct ldb_module *module, void *mem_ctx, /* The following definitions come from lib/ldb/modules/ldb_map_inbound.c */ int map_add_do_remote(struct ldb_handle *handle); int map_add_do_local(struct ldb_handle *handle); -int map_add(struct ldb_module *module, struct ldb_request *req); int map_modify_do_remote(struct ldb_handle *handle); int map_modify_do_local(struct ldb_handle *handle); -int map_modify(struct ldb_module *module, struct ldb_request *req); int map_delete_do_remote(struct ldb_handle *handle); int map_delete_do_local(struct ldb_handle *handle); -int map_delete(struct ldb_module *module, struct ldb_request *req); int map_rename_do_remote(struct ldb_handle *handle); int map_rename_do_fixup(struct ldb_handle *handle); int map_rename_do_local(struct ldb_handle *handle); -int map_rename(struct ldb_module *module, struct ldb_request *req); - -/* The following definitions come from lib/ldb/modules/ldb_map_outbound.c */ -int map_search(struct ldb_module *module, struct ldb_request *req); diff --git a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c index 1ec3b1aabd..214e7eec5f 100644 --- a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c +++ b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c @@ -1903,7 +1903,7 @@ failed: return -1; } -int ldb_sqlite3_init(void) -{ - return ldb_register_backend("sqlite3", lsqlite3_connect); -} +_PUBLIC_ const struct ldb_backend_ops ldb_sqlite3_backend_ops = { + .name = "sqlite3", + .connect_fn = lsqlite3_connect +}; diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 45a8109584..11d6c30710 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -1107,7 +1107,7 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url, return 0; } -int ldb_tdb_init(void) -{ - return ldb_register_backend("tdb", ltdb_connect); -} +const struct ldb_backend_ops ldb_tdb_backend_ops = { + .name = "tdb", + .connect_fn = ltdb_connect +}; diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index b6a8594166..eb27263b16 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -473,15 +473,9 @@ static int asq_init(struct ldb_module *module) return ldb_next_init(module); } - -static const struct ldb_module_ops asq_ops = { +const struct ldb_module_ops ldb_asq_module_ops = { .name = "asq", .search = asq_search, .wait = asq_wait, .init_context = asq_init }; - -int ldb_asq_init(void) -{ - return ldb_register_module(&asq_ops); -} diff --git a/source4/lib/ldb/modules/operational.c b/source4/lib/ldb/modules/operational.c index 45f23aa0c1..7dc4ae08c3 100644 --- a/source4/lib/ldb/modules/operational.c +++ b/source4/lib/ldb/modules/operational.c @@ -304,13 +304,8 @@ static int operational_init(struct ldb_module *ctx) return ldb_next_init(ctx); } -static const struct ldb_module_ops operational_ops = { +const struct ldb_module_ops ldb_operational_module_ops = { .name = "operational", .search = operational_search, .init_context = operational_init }; - -int ldb_operational_init(void) -{ - return ldb_register_module(&operational_ops); -} diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index ee1bbe0335..b62b1f92cb 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -549,15 +549,9 @@ static int paged_request_init(struct ldb_module *module) return ldb_next_init(module); } -static const struct ldb_module_ops paged_ops = { +const struct ldb_module_ops ldb_paged_results_module_ops = { .name = "paged_results", .search = paged_search, .wait = paged_wait, .init_context = paged_request_init }; - -int ldb_paged_results_init(void) -{ - return ldb_register_module(&paged_ops); -} - diff --git a/source4/lib/ldb/modules/paged_searches.c b/source4/lib/ldb/modules/paged_searches.c index fd580a3c4a..40e87f70d6 100644 --- a/source4/lib/ldb/modules/paged_searches.c +++ b/source4/lib/ldb/modules/paged_searches.c @@ -455,15 +455,9 @@ static int ps_init(struct ldb_module *module) return ldb_next_init(module); } -static const struct ldb_module_ops ps_ops = { +_PUBLIC_ const struct ldb_module_ops ldb_paged_searches_module_ops = { .name = "paged_searches", .search = ps_search, .wait = ps_wait, .init_context = ps_init }; - -int ldb_paged_searches_init(void) -{ - return ldb_register_module(&ps_ops); -} - diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 1a0ddbb3c4..c4de8e8da8 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -326,15 +326,9 @@ static int rdn_name_wait(struct ldb_handle *handle, enum ldb_wait_type type) return rdn_name_wait_once(handle); } -static const struct ldb_module_ops rdn_name_ops = { +const struct ldb_module_ops ldb_rdn_name_module_ops = { .name = "rdn_name", .add = rdn_name_add, .rename = rdn_name_rename, .wait = rdn_name_wait }; - - -int ldb_rdn_name_init(void) -{ - return ldb_register_module(&rdn_name_ops); -} diff --git a/source4/lib/ldb/modules/skel.c b/source4/lib/ldb/modules/skel.c index 5400c502f1..0cd29ac4b7 100644 --- a/source4/lib/ldb/modules/skel.c +++ b/source4/lib/ldb/modules/skel.c @@ -116,7 +116,7 @@ static int skel_init(struct ldb_module *module) return ldb_next_init(module); } -static const struct ldb_module_ops skel_ops = { +const struct ldb_module_ops ldb_skel_module_ops = { .name = "skel", .init_context = skel_init, .search = skel_search, @@ -129,8 +129,3 @@ static const struct ldb_module_ops skel_ops = { .end_transaction = skel_end_trans, .del_transaction = skel_del_trans, }; - -int ldb_skel_init(void) -{ - return ldb_register_module(&skel_ops); -} diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 89b9a4fb19..746befa559 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -450,14 +450,9 @@ static int server_sort_init(struct ldb_module *module) return ldb_next_init(module); } -static const struct ldb_module_ops server_sort_ops = { +const struct ldb_module_ops ldb_server_sort_module_ops = { .name = "server_sort", .search = server_sort_search, .wait = server_sort_wait, .init_context = server_sort_init }; - -int ldb_sort_init(void) -{ - return ldb_register_module(&server_sort_ops); -} diff --git a/source4/lib/ldb/nssldb/ldb-nss.c b/source4/lib/ldb/nssldb/ldb-nss.c index 199212dbbf..e256f41a4d 100644 --- a/source4/lib/ldb/nssldb/ldb-nss.c +++ b/source4/lib/ldb/nssldb/ldb-nss.c @@ -45,11 +45,6 @@ NSS_STATUS _ldb_nss_init(void) _ldb_nss_ctx->pid = mypid; - ret = ldb_global_init(); - if (ret != 0) { - goto failed; - } - _ldb_nss_ctx->ldb = ldb_init(_ldb_nss_ctx); if (_ldb_nss_ctx->ldb == NULL) { goto failed; diff --git a/source4/lib/ldb/rules.mk b/source4/lib/ldb/rules.mk new file mode 100644 index 0000000000..534ba016ab --- /dev/null +++ b/source4/lib/ldb/rules.mk @@ -0,0 +1,30 @@ +etags: + etags `find $(srcdir) -name "*.[ch]"` + +ctags: + ctags `find $(srcdir) -name "*.[ch]"` + +.SUFFIXES: _wrap.c .i + +.i_wrap.c: + [ "$(SWIG)" == "no" ] || $(SWIG) -O -Wall -python -keyword $< + +.SUFFIXES: .1 .1.xml .3 .3.xml .xml .html .c .o + +.c.o: + @echo Compiling $*.c + @mkdir -p `dirname $@` + @$(CC) $(CFLAGS) $(PICFLAG) -c $< -o $@ + +.c.po: + @echo Compiling $*.c + @mkdir -p `dirname $@` + @$(CC) -fPIC $(CFLAGS) -c $< -o $@ + +showflags:: + @echo 'ldb will be compiled with flags:' + @echo ' CFLAGS = $(CFLAGS)' + @echo ' LIBS = $(LIBS)' + +distclean:: + rm -f *~ */*~ diff --git a/source4/lib/ldb/setup.py b/source4/lib/ldb/setup.py deleted file mode 100755 index b04f3b09f1..0000000000 --- a/source4/lib/ldb/setup.py +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/python -from distutils.core import setup -from distutils.extension import Extension - -setup(name="ldb", - version="1.0", - url="http://ldb.samba.org/", - author="LDB Developers", - author_email="ldb@samba.org", - license="LGPLv3", - keywords=["ldap","ldb","db","ldif"], - py_modules=["ldb"], - ext_modules=[Extension('_ldb', ['ldb_wrap.c'], include_dirs=['include'], - library_dirs=["lib"], libraries=['ldb'])], - ) diff --git a/source4/lib/ldb/tests/python/api.py b/source4/lib/ldb/tests/python/api.py index d5346c30b0..5f3f727b5d 100755 --- a/source4/lib/ldb/tests/python/api.py +++ b/source4/lib/ldb/tests/python/api.py @@ -418,3 +418,6 @@ class ModuleTests(unittest.TestCase): def test_register_module(self): ldb.register_module(ExampleModule()) +if __name__ == '__main__': + import unittest + unittest.TestProgram() diff --git a/source4/lib/ldb/tests/python/ldap.py b/source4/lib/ldb/tests/python/ldap.py index a425ddc830..f75bb8124d 100755 --- a/source4/lib/ldb/tests/python/ldap.py +++ b/source4/lib/ldb/tests/python/ldap.py @@ -6,17 +6,17 @@ import getopt import optparse import sys -# Add path to the library for in-tree use -sys.path.append("scripting/python") import samba.getopt as options from auth import system_session from ldb import (SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE, LdbError, LDB_ERR_NO_SUCH_OBJECT, LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS, LDB_ERR_ENTRY_ALREADY_EXISTS, LDB_ERR_UNWILLING_TO_PERFORM, - LDB_ERR_NOT_ALLOWED_ON_NON_LEAF) + LDB_ERR_NOT_ALLOWED_ON_NON_LEAF, LDB_ERR_OTHER) from samba import Ldb +from subunit import SubunitTestRunner import param +import unittest parser = optparse.OptionParser("ldap [options] <host>") sambaopts = options.SambaOptions(parser) @@ -36,122 +36,122 @@ host = args[0] lp = sambaopts.get_loadparm() -def delete_force(ldb, dn): - try: - ldb.delete(dn) - except LdbError, (num, _): - if num != LDB_ERR_NO_SUCH_OBJECT: - assert False - -def assertEquals(a1, a2): - assert a1 == a2, "Expected %r == %r" % (a1, a2) +class BasicTests(unittest.TestCase): + def delete_force(self, ldb, dn): + try: + ldb.delete(dn) + except LdbError, (num, _): + self.assertEquals(num, LDB_ERR_NO_SUCH_OBJECT) + + def find_basedn(self, ldb): + res = ldb.search(base="", expression="", scope=SCOPE_BASE, + attrs=["defaultNamingContext"]) + self.assertEquals(len(res), 1) + return res[0]["defaultNamingContext"][0] + + def find_configurationdn(self, ldb): + res = ldb.search(base="", expression="", scope=SCOPE_BASE, attrs=["configurationNamingContext"]) + self.assertEquals(len(res), 1) + return res[0]["configurationNamingContext"][0] + + def find_schemadn(self, ldb): + res = ldb.search(base="", expression="", scope=SCOPE_BASE, attrs=["schemaNamingContext"]) + self.assertEquals(len(res), 1) + return res[0]["schemaNamingContext"][0] + + def setUp(self): + self.ldb = ldb + self.gc_ldb = gc_ldb + self.base_dn = self.find_basedn(ldb) + self.configuration_dn = self.find_configurationdn(ldb) + self.schema_dn = self.find_schemadn(ldb) + + print "baseDN: %s\n" % self.base_dn + + self.delete_force(self.ldb, "cn=ldaptestuser,cn=users," + self.base_dn) + self.delete_force(self.ldb, "cn=ldaptestgroup,cn=users," + self.base_dn) + + def test_group_add_invalid_member(self): + """Testing group add with invalid member""" + try: + self.ldb.add({ + "dn": "cn=ldaptestgroup,cn=uSers," + self.base_dn, + "objectclass": "group", + "member": "cn=ldaptestuser,cn=useRs," + self.base_dn}) + self.fail() + except LdbError, (num, _): + self.assertEquals(num, LDB_ERR_NO_SUCH_OBJECT) -def basic_tests(ldb, gc_ldb, base_dn, configuration_dn, schema_dn): - print "Running basic tests" + def test_all(self): + """Basic tests""" - delete_force(ldb, "cn=ldaptestuser,cn=users," + base_dn) - delete_force(ldb, "cn=ldaptestgroup,cn=users," + base_dn) + self.delete_force(self.ldb, "cn=ldaptestuser,cn=users," + self.base_dn) - print "Testing group add with invalid member" - try: - ldb.add({ - "dn": "cn=ldaptestgroup,cn=uSers," + base_dn, - "objectclass": "group", - "member": "cn=ldaptestuser,cn=useRs," + base_dn}) - except LdbError, (num, _): - if num != LDB_ERR_NO_SUCH_OBJECT: - assert False - else: - assert False - - print "Testing user add" - try: + print "Testing user add" ldb.add({ - "dn": "cn=ldaptestuser,cn=uSers," + base_dn, + "dn": "cn=ldaptestuser,cn=uSers," + self.base_dn, "objectclass": ["user", "person"], "cN": "LDAPtestUSER", "givenname": "ldap", "sn": "testy"}) - except LdbError: - ldb.delete("cn=ldaptestuser,cn=users," + base_dn) - ldb.add({ - "dn": "cn=ldaptestuser,cn=uSers," + base_dn, - "objectclass": ["user", "person"], - "cN": "LDAPtestUSER", - "givenname": "ldap", - "sn": "testy"}) - - ldb.add({ - "dn": "cn=ldaptestgroup,cn=uSers," + base_dn, - "objectclass": "group", - "member": "cn=ldaptestuser,cn=useRs," + base_dn}) - - try: - ldb.add({ - "dn": "cn=ldaptestcomputer,cn=computers," + base_dn, - "objectclass": "computer", - "cN": "LDAPtestCOMPUTER"}) - except LdbError: - ldb.delete("cn=ldaptestcomputer,cn=computers," + base_dn) + ldb.add({ - "dn": "cn=ldaptestcomputer,cn=computers," + base_dn, - "objectClass": "computer", - "cn": "LDAPtestCOMPUTER"}) - - try: - ldb.add({"dn": "cn=ldaptest2computer,cn=computers," + base_dn, - "objectClass": "computer", - "cn": "LDAPtest2COMPUTER", - "userAccountControl": "4096", - "displayname": "ldap testy"}) - except LdbError: - ldb.delete("cn=ldaptest2computer,cn=computers," + base_dn) + "dn": "cn=ldaptestgroup,cn=uSers," + self.base_dn, + "objectclass": "group", + "member": "cn=ldaptestuser,cn=useRs," + self.base_dn}) + + self.delete_force(ldb, "cn=ldaptestcomputer,cn=computers," + self.base_dn) ldb.add({ - "dn": "cn=ldaptest2computer,cn=computers," + base_dn, + "dn": "cn=ldaptestcomputer,cn=computers," + self.base_dn, + "objectclass": "computer", + "cN": "LDAPtestCOMPUTER"}) + + self.delete_force(self.ldb, "cn=ldaptest2computer,cn=computers," + self.base_dn) + ldb.add({"dn": "cn=ldaptest2computer,cn=computers," + self.base_dn, "objectClass": "computer", "cn": "LDAPtest2COMPUTER", "userAccountControl": "4096", "displayname": "ldap testy"}) - print "Testing attribute or value exists behaviour" - try: - ldb.modify_ldif(""" -dn: cn=ldaptest2computer,cn=computers,""" + base_dn + """ + print "Testing attribute or value exists behaviour" + try: + ldb.modify_ldif(""" +dn: cn=ldaptest2computer,cn=computers,""" + self.base_dn + """ changetype: modify replace: servicePrincipalName servicePrincipalName: host/ldaptest2computer servicePrincipalName: host/ldaptest2computer servicePrincipalName: cifs/ldaptest2computer """) - except LdbError, (num, msg): - assert num == LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS + except LdbError, (num, msg): + self.assertEquals(num, LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS) - ldb.modify_ldif(""" -dn: cn=ldaptest2computer,cn=computers,""" + base_dn + """ + ldb.modify_ldif(""" +dn: cn=ldaptest2computer,cn=computers,""" + self.base_dn + """ changetype: modify replace: servicePrincipalName servicePrincipalName: host/ldaptest2computer servicePrincipalName: cifs/ldaptest2computer """) - try: - ldb.modify_ldif(""" -dn: cn=ldaptest2computer,cn=computers,""" + base_dn + """ + try: + ldb.modify_ldif(""" +dn: cn=ldaptest2computer,cn=computers,""" + self.base_dn + """ changetype: modify add: servicePrincipalName servicePrincipalName: host/ldaptest2computer """) - except LdbError, (num, msg): - assert num == LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS - - print "Testing ranged results" - ldb.modify_ldif(""" -dn: cn=ldaptest2computer,cn=computers,""" + base_dn + """ + except LdbError, (num, msg): + self.assertEquals(num, LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS) + + print "Testing ranged results" + ldb.modify_ldif(""" +dn: cn=ldaptest2computer,cn=computers,""" + self.base_dn + """ changetype: modify replace: servicePrincipalName """) - - ldb.modify_ldif(""" -dn: cn=ldaptest2computer,cn=computers,""" + base_dn + """ + + ldb.modify_ldif(""" +dn: cn=ldaptest2computer,cn=computers,""" + self.base_dn + """ changetype: modify add: servicePrincipalName servicePrincipalName: host/ldaptest2computer0 @@ -186,730 +186,685 @@ servicePrincipalName: host/ldaptest2computer28 servicePrincipalName: host/ldaptest2computer29 """) - res = ldb.search(base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, - attrs=["servicePrincipalName;range=0-*"]) - assert len(res) == 1, "Could not find (cn=ldaptest2computer)" - #print len(res[0]["servicePrincipalName;range=0-*"]) - assertEquals(len(res[0]["servicePrincipalName;range=0-*"]), 30) - - res = ldb.search(base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=0-19"]) - assert len(res) == 1, "Could not find (cn=ldaptest2computer)" -# print res[0]["servicePrincipalName;range=0-19"].length - assertEquals(len(res[0]["servicePrincipalName;range=0-19"]), 20) - - - res = ldb.search(base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=0-30"]) - assert len(res) == 1, "Could not find (cn=ldaptest2computer)" - assertEquals(len(res[0]["servicePrincipalName;range=0-*"]), 30) - - res = ldb.search(base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=0-40"]) - assert len(res) == 1, "Could not find (cn=ldaptest2computer)" - assertEquals(len(res[0]["servicePrincipalName;range=0-*"]), 30) - - res = ldb.search(base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=30-40"]) - assert len(res) == 1, "Could not find (cn=ldaptest2computer)" - assertEquals(len(res[0]["servicePrincipalName;range=30-*"]), 0) - - - res = ldb.search(base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=10-40"]) - assert len(res) == 1, "Could not find (cn=ldaptest2computer)" - assertEquals(len(res[0]["servicePrincipalName;range=10-*"]), 20) -# pos_11 = res[0]["servicePrincipalName;range=10-*"][18] - - res = ldb.search(base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=11-40"]) - assert len(res) == 1, "Could not find (cn=ldaptest2computer)" - assertEquals(len(res[0]["servicePrincipalName;range=11-*"]), 19) -# print res[0]["servicePrincipalName;range=11-*"][18] -# print pos_11 -# assertEquals((res[0]["servicePrincipalName;range=11-*"][18]), pos_11) - - res = ldb.search(base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=11-15"]) - assert len(res) == 1, "Could not find (cn=ldaptest2computer)" - assertEquals(len(res[0]["servicePrincipalName;range=11-15"]), 5) -# assertEquals(res[0]["servicePrincipalName;range=11-15"][4], pos_11) - - res = ldb.search(base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName"]) - assert len(res) == 1, "Could not find (cn=ldaptest2computer)" -# print res[0]["servicePrincipalName"][18] -# print pos_11 - assertEquals(len(res[0]["servicePrincipalName"]), 30) -# assertEquals(res[0]["servicePrincipalName"][18], pos_11) - - try: + res = ldb.search(self.base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, + attrs=["servicePrincipalName;range=0-*"]) + self.assertEquals(len(res), 1, "Could not find (cn=ldaptest2computer)") + #print len(res[0]["servicePrincipalName;range=0-*"]) + self.assertEquals(len(res[0]["servicePrincipalName;range=0-*"]), 30) + + res = ldb.search(self.base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=0-19"]) + self.assertEquals(len(res), 1, "Could not find (cn=ldaptest2computer)") + # print res[0]["servicePrincipalName;range=0-19"].length + self.assertEquals(len(res[0]["servicePrincipalName;range=0-19"]), 20) + + + res = ldb.search(self.base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=0-30"]) + self.assertEquals(len(res), 1, "Could not find (cn=ldaptest2computer)") + self.assertEquals(len(res[0]["servicePrincipalName;range=0-*"]), 30) + + res = ldb.search(self.base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=0-40"]) + self.assertEquals(len(res), 1, "Could not find (cn=ldaptest2computer)") + self.assertEquals(len(res[0]["servicePrincipalName;range=0-*"]), 30) + + res = ldb.search(self.base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=30-40"]) + self.assertEquals(len(res), 1, "Could not find (cn=ldaptest2computer)") + self.assertEquals(len(res[0]["servicePrincipalName;range=30-*"]), 0) + + + res = ldb.search(self.base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=10-40"]) + self.assertEquals(len(res), 1, "Could not find (cn=ldaptest2computer)") + self.assertEquals(len(res[0]["servicePrincipalName;range=10-*"]), 20) + # pos_11 = res[0]["servicePrincipalName;range=10-*"][18] + + res = ldb.search(self.base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=11-40"]) + self.assertEquals(len(res), 1, "Could not find (cn=ldaptest2computer)") + self.assertEquals(len(res[0]["servicePrincipalName;range=11-*"]), 19) + # print res[0]["servicePrincipalName;range=11-*"][18] + # print pos_11 + # self.assertEquals((res[0]["servicePrincipalName;range=11-*"][18]), pos_11) + + res = ldb.search(self.base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName;range=11-15"]) + self.assertEquals(len(res), 1, "Could not find (cn=ldaptest2computer)") + self.assertEquals(len(res[0]["servicePrincipalName;range=11-15"]), 5) + # self.assertEquals(res[0]["servicePrincipalName;range=11-15"][4], pos_11) + + res = ldb.search(self.base_dn, expression="(cn=ldaptest2computer))", scope=SCOPE_SUBTREE, attrs=["servicePrincipalName"]) + self.assertEquals(len(res), 1, "Could not find (cn=ldaptest2computer)") + # print res[0]["servicePrincipalName"][18] + # print pos_11 + self.assertEquals(len(res[0]["servicePrincipalName"]), 30) + # self.assertEquals(res[0]["servicePrincipalName"][18], pos_11) + + self.delete_force(self.ldb, "cn=ldaptestuser2,cn=users," + self.base_dn) ldb.add({ - "dn": "cn=ldaptestuser2,cn=useRs," + base_dn, - "objectClass": ["person", "user"], - "cn": "LDAPtestUSER2", - "givenname": "testy", - "sn": "ldap user2"}) - except LdbError: - ldb.delete("cn=ldaptestuser2,cn=users," + base_dn) - ldb.add({ - "dn": "cn=ldaptestuser2,cn=useRs," + base_dn, - "objectClass": ["person", "user"], - "cn": "LDAPtestUSER2", - "givenname": "testy", - "sn": "ldap user2"}) - - print "Testing Ambigious Name Resolution" -# Testing ldb.search for (&(anr=ldap testy)(objectClass=user)) - res = ldb.search(expression="(&(anr=ldap testy)(objectClass=user))") - assert len(res) == 3, "Could not find (&(anr=ldap testy)(objectClass=user))" - -# Testing ldb.search for (&(anr=testy ldap)(objectClass=user)) - res = ldb.search(expression="(&(anr=testy ldap)(objectClass=user))") - assert len(res) == 2, "Found only %d for (&(anr=testy ldap)(objectClass=user))" % len(res) - -# Testing ldb.search for (&(anr=ldap)(objectClass=user)) - res = ldb.search(expression="(&(anr=ldap)(objectClass=user))") - assert len(res) == 4, "Found only %d for (&(anr=ldap)(objectClass=user))" % len(res) - -# Testing ldb.search for (&(anr==ldap)(objectClass=user)) - res = ldb.search(expression="(&(anr==ldap)(objectClass=user))") - assert len(res) == 1, "Could not find (&(anr==ldap)(objectClass=user)). Found only %d for (&(anr=ldap)(objectClass=user))" % len(res) - - assertEquals(str(res[0].dn), ("CN=ldaptestuser,CN=Users," + base_dn)) - assertEquals(res[0]["cn"][0], "ldaptestuser") - assertEquals(res[0]["name"], "ldaptestuser") - -# Testing ldb.search for (&(anr=testy)(objectClass=user)) - res = ldb.search(expression="(&(anr=testy)(objectClass=user))") - assert len(res) == 2, "Found only %d for (&(anr=testy)(objectClass=user))" % len(res) - -# Testing ldb.search for (&(anr=ldap testy)(objectClass=user)) - res = ldb.search(expression="(&(anr=testy ldap)(objectClass=user))") - assert len(res) == 2, "Found only %d for (&(anr=ldap testy)(objectClass=user))" % len(res) - -# Testing ldb.search for (&(anr==ldap testy)(objectClass=user)) - res = ldb.search(expression="(&(anr==testy ldap)(objectClass=user))") - assert len(res) == 1, "Found only %d for (&(anr==ldap testy)(objectClass=user))" % len(res) - - assertEquals(str(res[0].dn), ("CN=ldaptestuser,CN=Users," + base_dn)) - assertEquals(res[0]["cn"][0], "ldaptestuser") - assertEquals(res[0]["name"][0], "ldaptestuser") - -# Testing ldb.search for (&(anr==testy ldap)(objectClass=user)) - res = ldb.search(expression="(&(anr==testy ldap)(objectClass=user))") - assert len(res) == 1, "Could not find (&(anr==testy ldap)(objectClass=user))" - - assertEquals(str(res[0].dn), ("CN=ldaptestuser,CN=Users," + base_dn)) - assertEquals(res[0]["cn"][0], "ldaptestuser") - assertEquals(res[0]["name"][0], "ldaptestuser") - - # Testing ldb.search for (&(anr=testy ldap user)(objectClass=user)) - res = ldb.search(expression="(&(anr=testy ldap user)(objectClass=user))") - assert len(res) == 1, "Could not find (&(anr=testy ldap user)(objectClass=user))" - - assertEquals(str(res[0].dn), ("CN=ldaptestuser2,CN=Users," + base_dn)) - assertEquals(res[0]["cn"], "ldaptestuser2") - assertEquals(res[0]["name"], "ldaptestuser2") - - # Testing ldb.search for (&(anr==testy ldap user2)(objectClass=user)) - res = ldb.search(expression="(&(anr==testy ldap user2)(objectClass=user))") - assert len(res) == 1, "Could not find (&(anr==testy ldap user2)(objectClass=user))" - - assertEquals(str(res[0].dn), ("CN=ldaptestuser2,CN=Users," + base_dn)) - assertEquals(res[0]["cn"], "ldaptestuser2") - assertEquals(res[0]["name"], "ldaptestuser2") - - # Testing ldb.search for (&(anr==ldap user2)(objectClass=user)) - res = ldb.search(expression="(&(anr==ldap user2)(objectClass=user))") - assert len(res) == 1, "Could not find (&(anr==ldap user2)(objectClass=user))" - - assertEquals(str(res[0].dn), ("CN=ldaptestuser2,CN=Users," + base_dn)) - assertEquals(res[0]["cn"], "ldaptestuser2") - assertEquals(res[0]["name"], "ldaptestuser2") - - # Testing ldb.search for (&(anr==not ldap user2)(objectClass=user)) - res = ldb.search(expression="(&(anr==not ldap user2)(objectClass=user))") - assert len(res) == 0, "Must not find (&(anr==not ldap user2)(objectClass=user))" - - # Testing ldb.search for (&(anr=not ldap user2)(objectClass=user)) - res = ldb.search(expression="(&(anr=not ldap user2)(objectClass=user))") - assert len(res) == 0, "Must not find (&(anr=not ldap user2)(objectClass=user))" - - print "Testing Group Modifies" - ldb.modify_ldif(""" -dn: cn=ldaptestgroup,cn=users,""" + base_dn + """ + "dn": "cn=ldaptestuser2,cn=useRs," + self.base_dn, + "objectClass": ["person", "user"], + "cn": "LDAPtestUSER2", + "givenname": "testy", + "sn": "ldap user2"}) + + print "Testing Ambigious Name Resolution" + # Testing ldb.search for (&(anr=ldap testy)(objectClass=user)) + res = ldb.search(expression="(&(anr=ldap testy)(objectClass=user))") + self.assertEquals(len(res), 3, "Could not find (&(anr=ldap testy)(objectClass=user))") + + # Testing ldb.search for (&(anr=testy ldap)(objectClass=user)) + res = ldb.search(expression="(&(anr=testy ldap)(objectClass=user))") + self.assertEquals(len(res), 2, "Found only %d for (&(anr=testy ldap)(objectClass=user))" % len(res)) + + # Testing ldb.search for (&(anr=ldap)(objectClass=user)) + res = ldb.search(expression="(&(anr=ldap)(objectClass=user))") + self.assertEquals(len(res), 4, "Found only %d for (&(anr=ldap)(objectClass=user))" % len(res)) + + # Testing ldb.search for (&(anr==ldap)(objectClass=user)) + res = ldb.search(expression="(&(anr==ldap)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(anr==ldap)(objectClass=user)). Found only %d for (&(anr=ldap)(objectClass=user))" % len(res)) + + self.assertEquals(str(res[0].dn), ("CN=ldaptestuser,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"][0], "ldaptestuser") + self.assertEquals(res[0]["name"], "ldaptestuser") + + # Testing ldb.search for (&(anr=testy)(objectClass=user)) + res = ldb.search(expression="(&(anr=testy)(objectClass=user))") + self.assertEquals(len(res), 2, "Found only %d for (&(anr=testy)(objectClass=user))" % len(res)) + + # Testing ldb.search for (&(anr=ldap testy)(objectClass=user)) + res = ldb.search(expression="(&(anr=testy ldap)(objectClass=user))") + self.assertEquals(len(res), 2, "Found only %d for (&(anr=ldap testy)(objectClass=user))" % len(res)) + + # Testing ldb.search for (&(anr==ldap testy)(objectClass=user)) + res = ldb.search(expression="(&(anr==testy ldap)(objectClass=user))") + self.assertEquals(len(res), 1, "Found only %d for (&(anr==ldap testy)(objectClass=user))" % len(res)) + + self.assertEquals(str(res[0].dn), ("CN=ldaptestuser,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"][0], "ldaptestuser") + self.assertEquals(res[0]["name"][0], "ldaptestuser") + + # Testing ldb.search for (&(anr==testy ldap)(objectClass=user)) + res = ldb.search(expression="(&(anr==testy ldap)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(anr==testy ldap)(objectClass=user))") + + self.assertEquals(str(res[0].dn), ("CN=ldaptestuser,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"][0], "ldaptestuser") + self.assertEquals(res[0]["name"][0], "ldaptestuser") + + # Testing ldb.search for (&(anr=testy ldap user)(objectClass=user)) + res = ldb.search(expression="(&(anr=testy ldap user)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(anr=testy ldap user)(objectClass=user))") + + self.assertEquals(str(res[0].dn), ("CN=ldaptestuser2,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"], "ldaptestuser2") + self.assertEquals(res[0]["name"], "ldaptestuser2") + + # Testing ldb.search for (&(anr==testy ldap user2)(objectClass=user)) + res = ldb.search(expression="(&(anr==testy ldap user2)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(anr==testy ldap user2)(objectClass=user))") + + self.assertEquals(str(res[0].dn), ("CN=ldaptestuser2,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"], "ldaptestuser2") + self.assertEquals(res[0]["name"], "ldaptestuser2") + + # Testing ldb.search for (&(anr==ldap user2)(objectClass=user)) + res = ldb.search(expression="(&(anr==ldap user2)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(anr==ldap user2)(objectClass=user))") + + self.assertEquals(str(res[0].dn), ("CN=ldaptestuser2,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"], "ldaptestuser2") + self.assertEquals(res[0]["name"], "ldaptestuser2") + + # Testing ldb.search for (&(anr==not ldap user2)(objectClass=user)) + res = ldb.search(expression="(&(anr==not ldap user2)(objectClass=user))") + self.assertEquals(len(res), 0, "Must not find (&(anr==not ldap user2)(objectClass=user))") + + # Testing ldb.search for (&(anr=not ldap user2)(objectClass=user)) + res = ldb.search(expression="(&(anr=not ldap user2)(objectClass=user))") + self.assertEquals(len(res), 0, "Must not find (&(anr=not ldap user2)(objectClass=user))") + + print "Testing Group Modifies" + ldb.modify_ldif(""" +dn: cn=ldaptestgroup,cn=users,""" + self.base_dn + """ changetype: modify add: member -member: cn=ldaptestuser2,cn=users,""" + base_dn + """ -member: cn=ldaptestcomputer,cn=computers,""" + base_dn + """ +member: cn=ldaptestuser2,cn=users,""" + self.base_dn + """ +member: cn=ldaptestcomputer,cn=computers,""" + self.base_dn + """ """) - delete_force(ldb, "cn=ldaptestuser3,cn=users," + base_dn) + self.delete_force(ldb, "cn=ldaptestuser3,cn=users," + self.base_dn) - print "Testing adding non-existent user to a group" - try: - ldb.modify_ldif(""" -dn: cn=ldaptestgroup,cn=users,""" + base_dn + """ + print "Testing adding non-existent user to a group" + try: + ldb.modify_ldif(""" +dn: cn=ldaptestgroup,cn=users,""" + self.base_dn + """ changetype: modify add: member -member: cn=ldaptestuser3,cn=users,""" + base_dn + """ +member: cn=ldaptestuser3,cn=users,""" + self.base_dn + """ """) - except LdbError, (num, _): - assert num == LDB_ERR_NO_SUCH_OBJECT - else: - assert False - - print "Testing Renames" - - ldb.rename("cn=ldaptestuser2,cn=users," + base_dn, "cn=ldaptestuser3,cn=users," + base_dn) - - ldb.rename("cn=ldaptestuser3,cn=users," + base_dn, "cn=ldaptestuser3,cn=users," + base_dn) - - ldb.rename("cn=ldaptestuser3,cn=users," + base_dn, "cn=ldaptestUSER3,cn=users," + base_dn) - - print "Testing ldb.search for (&(cn=ldaptestuser3)(objectClass=user))" - res = ldb.search(expression="(&(cn=ldaptestuser3)(objectClass=user))") - assert len(res) == 1, "Could not find (&(cn=ldaptestuser3)(objectClass=user))" - - assertEquals(str(res[0].dn), ("CN=ldaptestUSER3,CN=Users," + base_dn)) - assertEquals(res[0]["cn"], "ldaptestUSER3") - assertEquals(res[0]["name"], "ldaptestUSER3") - -# This is a Samba special, and does not exist in real AD -# print "Testing ldb.search for (dn=CN=ldaptestUSER3,CN=Users," + base_dn + ")" -# res = ldb.search("(dn=CN=ldaptestUSER3,CN=Users," + base_dn + ")") -# if (res.error != 0 || len(res) != 1) { -# print "Could not find (dn=CN=ldaptestUSER3,CN=Users," + base_dn + ")" -# assertEquals(len(res), 1) -# } -# assertEquals(res[0].dn, ("CN=ldaptestUSER3,CN=Users," + base_dn)) -# assertEquals(res[0].cn, "ldaptestUSER3") -# assertEquals(res[0].name, "ldaptestUSER3") - - print "Testing ldb.search for (distinguishedName=CN=ldaptestUSER3,CN=Users," + base_dn + ")" - res = ldb.search(expression="(distinguishedName=CN=ldaptestUSER3,CN=Users," + base_dn + ")") - assert len(res) == 1, "Could not find (dn=CN=ldaptestUSER3,CN=Users," + base_dn + ")" - assertEquals(str(res[0].dn), ("CN=ldaptestUSER3,CN=Users," + base_dn)) - assertEquals(res[0]["cn"], "ldaptestUSER3") - assertEquals(res[0]["name"], "ldaptestUSER3") - - # ensure we cannot add it again - try: - ldb.add({"dn": "cn=ldaptestuser3,cn=userS," + base_dn, - "objectClass": ["person", "user"], - "cn": "LDAPtestUSER3"}) - except LdbError, (num, _): - assert num == LDB_ERR_ENTRY_ALREADY_EXISTS - else: - assert False - - # rename back - ldb.rename("cn=ldaptestuser3,cn=users," + base_dn, "cn=ldaptestuser2,cn=users," + base_dn) - - # ensure we cannnot rename it twice - try: - ldb.rename("cn=ldaptestuser3,cn=users," + base_dn, "cn=ldaptestuser2,cn=users," + base_dn) - except LdbError, (num, _): - assert num == LDB_ERR_NO_SUCH_OBJECT - else: - assert False - - # ensure can now use that name - ldb.add({"dn": "cn=ldaptestuser3,cn=users," + base_dn, - "objectClass": ["person", "user"], - "cn": "LDAPtestUSER3"}) - - # ensure we now cannnot rename - try: - ldb.rename("cn=ldaptestuser2,cn=users," + base_dn, "cn=ldaptestuser3,cn=users," + base_dn) - except LdbError, (num, _): - assert num == LDB_ERR_ENTRY_ALREADY_EXISTS - else: - assert False - try: - ldb.rename("cn=ldaptestuser3,cn=users," + base_dn, "cn=ldaptestuser3,cn=configuration," + base_dn) - except LdbError, (num, _): - assert num in (71, 64) - else: - assert False - - ldb.rename("cn=ldaptestuser3,cn=users," + base_dn, "cn=ldaptestuser5,cn=users," + base_dn) - - ldb.delete("cn=ldaptestuser5,cn=users," + base_dn) - - delete_force(ldb, "cn=ldaptestgroup2,cn=users," + base_dn) - - ldb.rename("cn=ldaptestgroup,cn=users," + base_dn, "cn=ldaptestgroup2,cn=users," + base_dn) - - print "Testing subtree Renames" - - ldb.add({"dn": "cn=ldaptestcontainer," + base_dn, - "objectClass": "container"}) - - try: - ldb.add({"dn": "CN=ldaptestuser4,CN=ldaptestcontainer," + base_dn, - "objectClass": ["person", "user"], - "cn": "LDAPtestUSER4"}) - except LdbError: - ldb.delete("cn=ldaptestuser4,cn=ldaptestcontainer," + base_dn) - ldb.add({"dn": "CN=ldaptestuser4,CN=ldaptestcontainer," + base_dn, + self.fail() + except LdbError, (num, _): + self.assertEquals(num, LDB_ERR_NO_SUCH_OBJECT) + + print "Testing Renames" + + ldb.rename("cn=ldaptestuser2,cn=users," + self.base_dn, "cn=ldaptestuser3,cn=users," + self.base_dn) + + ldb.rename("cn=ldaptestuser3,cn=users," + self.base_dn, "cn=ldaptestuser3,cn=users," + self.base_dn) + + ldb.rename("cn=ldaptestuser3,cn=users," + self.base_dn, "cn=ldaptestUSER3,cn=users," + self.base_dn) + + print "Testing ldb.search for (&(cn=ldaptestuser3)(objectClass=user))" + res = ldb.search(expression="(&(cn=ldaptestuser3)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestuser3)(objectClass=user))") + + self.assertEquals(str(res[0].dn), ("CN=ldaptestUSER3,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"], "ldaptestUSER3") + self.assertEquals(res[0]["name"], "ldaptestUSER3") + + # This is a Samba special, and does not exist in real AD + # print "Testing ldb.search for (dn=CN=ldaptestUSER3,CN=Users," + self.base_dn + ")" + # res = ldb.search("(dn=CN=ldaptestUSER3,CN=Users," + self.base_dn + ")") + # if (res.error != 0 || len(res) != 1) { + # print "Could not find (dn=CN=ldaptestUSER3,CN=Users," + self.base_dn + ")" + # self.assertEquals(len(res), 1) + # } + # self.assertEquals(res[0].dn, ("CN=ldaptestUSER3,CN=Users," + self.base_dn)) + # self.assertEquals(res[0].cn, "ldaptestUSER3") + # self.assertEquals(res[0].name, "ldaptestUSER3") + + print "Testing ldb.search for (distinguishedName=CN=ldaptestUSER3,CN=Users," + self.base_dn + ")" + res = ldb.search(expression="(distinguishedName=CN=ldaptestUSER3,CN=Users," + self.base_dn + ")") + self.assertEquals(len(res), 1, "Could not find (dn=CN=ldaptestUSER3,CN=Users," + self.base_dn + ")") + self.assertEquals(str(res[0].dn), ("CN=ldaptestUSER3,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"], "ldaptestUSER3") + self.assertEquals(res[0]["name"], "ldaptestUSER3") + + # ensure we cannot add it again + try: + ldb.add({"dn": "cn=ldaptestuser3,cn=userS," + self.base_dn, "objectClass": ["person", "user"], - "cn": "LDAPtestUSER4"}) + "cn": "LDAPtestUSER3"}) + self.fail() + except LdbError, (num, _): + self.assertEquals(num, LDB_ERR_ENTRY_ALREADY_EXISTS) + + # rename back + ldb.rename("cn=ldaptestuser3,cn=users," + self.base_dn, "cn=ldaptestuser2,cn=users," + self.base_dn) + + # ensure we cannnot rename it twice + try: + ldb.rename("cn=ldaptestuser3,cn=users," + self.base_dn, + "cn=ldaptestuser2,cn=users," + self.base_dn) + self.fail() + except LdbError, (num, _): + self.assertEquals(num, LDB_ERR_NO_SUCH_OBJECT) + + # ensure can now use that name + ldb.add({"dn": "cn=ldaptestuser3,cn=users," + self.base_dn, + "objectClass": ["person", "user"], + "cn": "LDAPtestUSER3"}) + + # ensure we now cannnot rename + try: + ldb.rename("cn=ldaptestuser2,cn=users," + self.base_dn, "cn=ldaptestuser3,cn=users," + self.base_dn) + self.fail() + except LdbError, (num, _): + self.assertEquals(num, LDB_ERR_ENTRY_ALREADY_EXISTS) + try: + ldb.rename("cn=ldaptestuser3,cn=users," + self.base_dn, "cn=ldaptestuser3,cn=configuration," + self.base_dn) + self.fail() + except LdbError, (num, _): + self.assertTrue(num in (71, 64)) + + ldb.rename("cn=ldaptestuser3,cn=users," + self.base_dn, "cn=ldaptestuser5,cn=users," + self.base_dn) - ldb.modify_ldif(""" -dn: cn=ldaptestgroup2,cn=users,""" + base_dn + """ + ldb.delete("cn=ldaptestuser5,cn=users," + self.base_dn) + + self.delete_force(ldb, "cn=ldaptestgroup2,cn=users," + self.base_dn) + + ldb.rename("cn=ldaptestgroup,cn=users," + self.base_dn, "cn=ldaptestgroup2,cn=users," + self.base_dn) + + print "Testing subtree Renames" + + ldb.add({"dn": "cn=ldaptestcontainer," + self.base_dn, + "objectClass": "container"}) + + self.delete_force(self.ldb, "cn=ldaptestuser4,cn=ldaptestcontainer," + self.base_dn) + ldb.add({"dn": "CN=ldaptestuser4,CN=ldaptestcontainer," + self.base_dn, + "objectClass": ["person", "user"], + "cn": "LDAPtestUSER4"}) + + ldb.modify_ldif(""" +dn: cn=ldaptestgroup2,cn=users,""" + self.base_dn + """ changetype: modify add: member -member: cn=ldaptestuser4,cn=ldaptestcontainer,""" + base_dn + """ +member: cn=ldaptestuser4,cn=ldaptestcontainer,""" + self.base_dn + """ """) - - print "Testing ldb.rename of cn=ldaptestcontainer," + base_dn + " to cn=ldaptestcontainer2," + base_dn - ldb.rename("CN=ldaptestcontainer," + base_dn, "CN=ldaptestcontainer2," + base_dn) - - print "Testing ldb.search for (&(cn=ldaptestuser4)(objectClass=user))" - res = ldb.search(expression="(&(cn=ldaptestuser4)(objectClass=user))") - assert len(res) == 1, "Could not find (&(cn=ldaptestuser4)(objectClass=user))" - - print "Testing subtree ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in (just renamed from) cn=ldaptestcontainer," + base_dn - try: - ldb.search("cn=ldaptestcontainer," + base_dn, - expression="(&(cn=ldaptestuser4)(objectClass=user))", - scope=SCOPE_SUBTREE) - except LdbError, (num, _): - assert num == LDB_ERR_NO_SUCH_OBJECT - else: - assert False - - print "Testing one-level ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in (just renamed from) cn=ldaptestcontainer," + base_dn - try: - res = ldb.search("cn=ldaptestcontainer," + base_dn, expression="(&(cn=ldaptestuser4)(objectClass=user))", scope=SCOPE_ONELEVEL) - except LdbError, (num, _): - assert num == LDB_ERR_NO_SUCH_OBJECT - else: - assert False - - print "Testing ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in renamed container" - res = ldb.search("cn=ldaptestcontainer2," + base_dn, expression="(&(cn=ldaptestuser4)(objectClass=user))", scope=SCOPE_SUBTREE) - assert len(res) == 1, "Could not find (&(cn=ldaptestuser4)(objectClass=user)) under cn=ldaptestcontainer2," + base_dn - - assertEquals(str(res[0].dn), ("CN=ldaptestuser4,CN=ldaptestcontainer2," + base_dn)) - assertEquals(res[0]["memberOf"][0].upper(), ("CN=ldaptestgroup2,CN=Users," + base_dn).upper()) - - print "Testing ldb.search for (&(member=CN=ldaptestuser4,CN=ldaptestcontainer2," + base_dn + ")(objectclass=group)) to check subtree renames and linked attributes" - res = ldb.search(base_dn, expression="(&(member=CN=ldaptestuser4,CN=ldaptestcontainer2," + base_dn + ")(objectclass=group))", scope=SCOPE_SUBTREE) - assert len(res) == 1, "Could not find (&(member=CN=ldaptestuser4,CN=ldaptestcontainer2," + base_dn + ")(objectclass=group)), perhaps linked attributes are not conistant with subtree renames?" - - print "Testing ldb.rename (into itself) of cn=ldaptestcontainer2," + base_dn + " to cn=ldaptestcontainer,cn=ldaptestcontainer2," + base_dn - try: - ldb.rename("cn=ldaptestcontainer2," + base_dn, "cn=ldaptestcontainer,cn=ldaptestcontainer2," + base_dn) - except LdbError, (num, _): - assert num == LDB_ERR_UNWILLING_TO_PERFORM - else: - assert False - - print "Testing ldb.rename (into non-existent container) of cn=ldaptestcontainer2," + base_dn + " to cn=ldaptestcontainer,cn=ldaptestcontainer3," + base_dn - try: - ldb.rename("cn=ldaptestcontainer2," + base_dn, "cn=ldaptestcontainer,cn=ldaptestcontainer3," + base_dn) - except LdbError, (num, _): - assert num in (53, 80) - else: - assert False - - print "Testing delete (should fail, not a leaf node) of renamed cn=ldaptestcontainer2," + base_dn - try: - ldb.delete("cn=ldaptestcontainer2," + base_dn) - except LdbError, (num, _): - assert num == LDB_ERR_NOT_ALLOWED_ON_NON_LEAF - else: - assert False - - print "Testing base ldb.search for CN=ldaptestuser4,CN=ldaptestcontainer2," + base_dn - res = ldb.search(expression="(objectclass=*)", base=("CN=ldaptestuser4,CN=ldaptestcontainer2," + base_dn), scope=SCOPE_BASE) - assert len(res) == 1 - res = ldb.search(expression="(cn=ldaptestuser40)", base=("CN=ldaptestuser4,CN=ldaptestcontainer2," + base_dn), scope=SCOPE_BASE) - assert len(res) == 0 - - print "Testing one-level ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in cn=ldaptestcontainer2," + base_dn - res = ldb.search(expression="(&(cn=ldaptestuser4)(objectClass=user))", base=("cn=ldaptestcontainer2," + base_dn), scope=SCOPE_ONELEVEL) - assert len(res) == 0 - - print "Testing one-level ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in cn=ldaptestcontainer2," + base_dn - res = ldb.search(expression="(&(cn=ldaptestuser4)(objectClass=user))", base=("cn=ldaptestcontainer2," + base_dn), scope=SCOPE_SUBTREE) - assert len(res) == 0 - - print "Testing delete of subtree renamed "+("CN=ldaptestuser4,CN=ldaptestcontainer2," + base_dn) - ldb.delete(("CN=ldaptestuser4,CN=ldaptestcontainer2," + base_dn)) - print "Testing delete of renamed cn=ldaptestcontainer2," + base_dn - ldb.delete("cn=ldaptestcontainer2," + base_dn) - - try: - ldb.add({"dn": "cn=ldaptestutf8user èùéìòà ,cn=users," + base_dn, "objectClass": "user"}) - except LdbError, (num, _): - ldb.delete("cn=ldaptestutf8user èùéìòà ,cn=users," + base_dn) - ldb.add({"dn": "cn=ldaptestutf8user èùéìòà ,cn=users," + base_dn, "objectClass": "user"}) - - try: - ldb.add({"dn": "cn=ldaptestutf8user2 èùéìòà ,cn=users," + base_dn, "objectClass": "user"}) - except LdbError, (num, _): - ldb.delete("cn=ldaptestutf8user2 èùéìòà ,cn=users," + base_dn) - ldb.add({"dn": "cn=ldaptestutf8user2 èùéìòà ,cn=users," + base_dn, - "objectClass": "user"}) - - print "Testing ldb.search for (&(cn=ldaptestuser)(objectClass=user))" - res = ldb.search(expression="(&(cn=ldaptestuser)(objectClass=user))") - assert len(res) == 1, "Could not find (&(cn=ldaptestuser)(objectClass=user))" - - assertEquals(str(res[0].dn), ("CN=ldaptestuser,CN=Users," + base_dn)) - assertEquals(res[0]["cn"], "ldaptestuser") - assertEquals(res[0]["name"], "ldaptestuser") - assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user"]) - assert("objectGUID" in res[0]) - assert("whenCreated" in res[0]) - assertEquals(res[0]["objectCategory"], ("CN=Person,CN=Schema,CN=Configuration," + base_dn)) - assertEquals(int(res[0]["sAMAccountType"][0]), 805306368) -# assertEquals(res[0].userAccountControl, 546) - assertEquals(res[0]["memberOf"][0], ("CN=ldaptestgroup2,CN=Users," + base_dn)) - assertEquals(len(res[0]["memberOf"]), 1) - - print "Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=cn=person,cn=schema,cn=configuration," + base_dn + "))" - res2 = ldb.search(expression="(&(cn=ldaptestuser)(objectCategory=cn=person,cn=schema,cn=configuration," + base_dn + "))") - assert len(res2) == 1, "Could not find (&(cn=ldaptestuser)(objectCategory=cn=person,cn=schema,cn=configuration," + base_dn + "))" - - assertEquals(res[0].dn, res2[0].dn) - - print "Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=PerSon))" - res3 = ldb.search(expression="(&(cn=ldaptestuser)(objectCategory=PerSon))") - assert len(res3) == 1, "Could not find (&(cn=ldaptestuser)(objectCategory=PerSon)): matched " + len(res3) - - assertEquals(res[0].dn, res3[0].dn) - - if gc_ldb is not None: - print "Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=PerSon)) in Global Catalog" - res3gc = gc_ldb.search(expression="(&(cn=ldaptestuser)(objectCategory=PerSon))") - assert len(res3gc) == 1 - - assertEquals(res[0].dn, res3gc[0].dn) - - print "Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=PerSon)) in with 'phantom root' control" - - res3control = gc_ldb.search(base_dn, expression="(&(cn=ldaptestuser)(objectCategory=PerSon))", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["search_options:1:2"]) - assert len(res3control) == 1, "Could not find (&(cn=ldaptestuser)(objectCategory=PerSon)) in Global Catalog" - - assertEquals(res[0].dn, res3control[0].dn) - - ldb.delete(res[0].dn) - - print "Testing ldb.search for (&(cn=ldaptestcomputer)(objectClass=user))" - res = ldb.search(expression="(&(cn=ldaptestcomputer)(objectClass=user))") - assert len(res) == 1, "Could not find (&(cn=ldaptestuser)(objectClass=user))" - - assertEquals(str(res[0].dn), ("CN=ldaptestcomputer,CN=Computers," + base_dn)) - assertEquals(res[0]["cn"], "ldaptestcomputer") - assertEquals(res[0]["name"], "ldaptestcomputer") - assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user", "computer"]) - assert("objectGUID" in res[0]) - assert("whenCreated" in res[0]) - assertEquals(res[0]["objectCategory"], ("CN=Computer,CN=Schema,CN=Configuration," + base_dn)) - assertEquals(int(res[0]["primaryGroupID"][0]), 513) -# assertEquals(res[0].sAMAccountType, 805306368) -# assertEquals(res[0].userAccountControl, 546) - assertEquals(res[0]["memberOf"][0], "CN=ldaptestgroup2,CN=Users," + base_dn) - assertEquals(len(res[0]["memberOf"]), 1) - - print "Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + "))" - res2 = ldb.search(expression="(&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + "))") - assert len(res2) == 1, "Could not find (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + "))" - - assertEquals(res[0].dn, res2[0].dn) - - if gc_ldb is not None: - print "Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + ")) in Global Catlog" - res2gc = gc_ldb.search(expression="(&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + "))") - assert len(res2gc) == 1, "Could not find (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + base_dn + ")) in Global Catlog" - - assertEquals(res[0].dn, res2gc[0].dn) - - print "Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=compuTER))" - res3 = ldb.search(expression="(&(cn=ldaptestcomputer)(objectCategory=compuTER))") - assert len(res3) == 1, "Could not find (&(cn=ldaptestcomputer)(objectCategory=compuTER))" - - assertEquals(res[0].dn, res3[0].dn) - - if gc_ldb is not None: - print "Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=compuTER)) in Global Catalog" - res3gc = gc_ldb.search(expression="(&(cn=ldaptestcomputer)(objectCategory=compuTER))") - assert len(res3gc) == 1, "Could not find (&(cn=ldaptestcomputer)(objectCategory=compuTER)) in Global Catalog" - - assertEquals(res[0].dn, res3gc[0].dn) - - print "Testing ldb.search for (&(cn=ldaptestcomp*r)(objectCategory=compuTER))" - res4 = ldb.search(expression="(&(cn=ldaptestcomp*r)(objectCategory=compuTER))") - assert len(res4) == 1, "Could not find (&(cn=ldaptestcomp*r)(objectCategory=compuTER))" - - assertEquals(res[0].dn, res4[0].dn) - - print "Testing ldb.search for (&(cn=ldaptestcomput*)(objectCategory=compuTER))" - res5 = ldb.search(expression="(&(cn=ldaptestcomput*)(objectCategory=compuTER))") - assert len(res5) == 1, "Could not find (&(cn=ldaptestcomput*)(objectCategory=compuTER))" - - assertEquals(res[0].dn, res5[0].dn) - - print "Testing ldb.search for (&(cn=*daptestcomputer)(objectCategory=compuTER))" - res6 = ldb.search(expression="(&(cn=*daptestcomputer)(objectCategory=compuTER))") - assert len(res6) == 1, "Could not find (&(cn=*daptestcomputer)(objectCategory=compuTER))" - - assertEquals(res[0].dn, res6[0].dn) - - ldb.delete(res[0].dn) - - print "Testing ldb.search for (&(cn=ldaptest2computer)(objectClass=user))" - res = ldb.search(expression="(&(cn=ldaptest2computer)(objectClass=user))") - assert len(res) == 1, "Could not find (&(cn=ldaptest2computer)(objectClass=user))" - - assertEquals(res[0].dn, ("CN=ldaptest2computer,CN=Computers," + base_dn)) - assertEquals(res[0]["cn"], "ldaptest2computer") - assertEquals(res[0]["name"], "ldaptest2computer") - assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user", "computer"]) - assert("objectGUID" in res[0]) - assert("whenCreated" in res[0]) - assertEquals(res[0]["objectCategory"][0], "CN=Computer,CN=Schema,CN=Configuration," + base_dn) - assertEquals(int(res[0]["sAMAccountType"][0]), 805306369) -# assertEquals(res[0].userAccountControl, 4098) - - ldb.delete(res[0].dn) - - attrs = ["cn", "name", "objectClass", "objectGUID", "whenCreated", "nTSecurityDescriptor", "memberOf"] - print "Testing ldb.search for (&(cn=ldaptestUSer2)(objectClass=user))" - res = ldb.search(base_dn, expression="(&(cn=ldaptestUSer2)(objectClass=user))", scope=SCOPE_SUBTREE, attrs=attrs) - assert len(res) == 1, "Could not find (&(cn=ldaptestUSer2)(objectClass=user))" - - assertEquals(res[0].dn, ("CN=ldaptestuser2,CN=Users," + base_dn)) - assertEquals(res[0]["cn"], "ldaptestuser2") - assertEquals(res[0]["name"], "ldaptestuser2") - assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user"]) - assert("objectGUID" in res[0]) - assert("whenCreated" in res[0]) - assert("nTSecurityDescriptor" in res[0]) - assertEquals(res[0]["memberOf"][0], ("CN=ldaptestgroup2,CN=Users," + base_dn)) - - attrs = ["cn", "name", "objectClass", "objectGUID", "whenCreated", "nTSecurityDescriptor", "member"] - print "Testing ldb.search for (&(cn=ldaptestgroup2)(objectClass=group))" - res = ldb.search(base_dn, expression="(&(cn=ldaptestgroup2)(objectClass=group))", scope=SCOPE_SUBTREE, attrs=attrs) - assert len(res) == 1, "Could not find (&(cn=ldaptestgroup2)(objectClass=group))" - - assertEquals(res[0].dn, ("CN=ldaptestgroup2,CN=Users," + base_dn)) - assertEquals(res[0]["cn"], "ldaptestgroup2") - assertEquals(res[0]["name"], "ldaptestgroup2") - assertEquals(res[0]["objectClass"], ["top", "group"]) - assert("objectGuid" not in res[0]) - assert("whenCreated" in res[0]) - assert("nTSecurityDescriptor" in res[0]) - assertEquals(res[0]["member"], ["CN=ldaptestuser2,CN=Users," + base_dn]) - - ldb.modify_ldif(""" -dn: cn=ldaptestgroup2,cn=users,""" + base_dn + """ + + print "Testing ldb.rename of cn=ldaptestcontainer," + self.base_dn + " to cn=ldaptestcontainer2," + self.base_dn + ldb.rename("CN=ldaptestcontainer," + self.base_dn, "CN=ldaptestcontainer2," + self.base_dn) + + print "Testing ldb.search for (&(cn=ldaptestuser4)(objectClass=user))" + res = ldb.search(expression="(&(cn=ldaptestuser4)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestuser4)(objectClass=user))") + + print "Testing subtree ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in (just renamed from) cn=ldaptestcontainer," + self.base_dn + try: + ldb.search("cn=ldaptestcontainer," + self.base_dn, + expression="(&(cn=ldaptestuser4)(objectClass=user))", + scope=SCOPE_SUBTREE) + self.fail() + except LdbError, (num, _): + self.assertEquals(num, LDB_ERR_NO_SUCH_OBJECT) + + print "Testing one-level ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in (just renamed from) cn=ldaptestcontainer," + self.base_dn + try: + res = ldb.search("cn=ldaptestcontainer," + self.base_dn, + expression="(&(cn=ldaptestuser4)(objectClass=user))", scope=SCOPE_ONELEVEL) + self.fail() + except LdbError, (num, _): + self.assertEquals(num, LDB_ERR_NO_SUCH_OBJECT) + + print "Testing ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in renamed container" + res = ldb.search("cn=ldaptestcontainer2," + self.base_dn, expression="(&(cn=ldaptestuser4)(objectClass=user))", scope=SCOPE_SUBTREE) + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestuser4)(objectClass=user)) under cn=ldaptestcontainer2," + self.base_dn) + + self.assertEquals(str(res[0].dn), ("CN=ldaptestuser4,CN=ldaptestcontainer2," + self.base_dn)) + self.assertEquals(res[0]["memberOf"][0].upper(), ("CN=ldaptestgroup2,CN=Users," + self.base_dn).upper()) + + print "Testing ldb.search for (&(member=CN=ldaptestuser4,CN=ldaptestcontainer2," + self.base_dn + ")(objectclass=group)) to check subtree renames and linked attributes" + res = ldb.search(self.base_dn, expression="(&(member=CN=ldaptestuser4,CN=ldaptestcontainer2," + self.base_dn + ")(objectclass=group))", scope=SCOPE_SUBTREE) + self.assertEquals(len(res), 1, "Could not find (&(member=CN=ldaptestuser4,CN=ldaptestcontainer2," + self.base_dn + ")(objectclass=group)), perhaps linked attributes are not conistant with subtree renames?") + + print "Testing ldb.rename (into itself) of cn=ldaptestcontainer2," + self.base_dn + " to cn=ldaptestcontainer,cn=ldaptestcontainer2," + self.base_dn + try: + ldb.rename("cn=ldaptestcontainer2," + self.base_dn, "cn=ldaptestcontainer,cn=ldaptestcontainer2," + self.base_dn) + self.fail() + except LdbError, (num, _): + self.assertEquals(num, LDB_ERR_UNWILLING_TO_PERFORM) + + print "Testing ldb.rename (into non-existent container) of cn=ldaptestcontainer2," + self.base_dn + " to cn=ldaptestcontainer,cn=ldaptestcontainer3," + self.base_dn + try: + ldb.rename("cn=ldaptestcontainer2," + self.base_dn, "cn=ldaptestcontainer,cn=ldaptestcontainer3," + self.base_dn) + self.fail() + except LdbError, (num, _): + self.assertTrue(num in (LDB_ERR_UNWILLING_TO_PERFORM, LDB_ERR_OTHER)) + + print "Testing delete (should fail, not a leaf node) of renamed cn=ldaptestcontainer2," + self.base_dn + try: + ldb.delete("cn=ldaptestcontainer2," + self.base_dn) + self.fail() + except LdbError, (num, _): + self.assertEquals(num, LDB_ERR_NOT_ALLOWED_ON_NON_LEAF) + + print "Testing base ldb.search for CN=ldaptestuser4,CN=ldaptestcontainer2," + self.base_dn + res = ldb.search(expression="(objectclass=*)", base=("CN=ldaptestuser4,CN=ldaptestcontainer2," + self.base_dn), scope=SCOPE_BASE) + self.assertEquals(len(res), 1) + res = ldb.search(expression="(cn=ldaptestuser40)", base=("CN=ldaptestuser4,CN=ldaptestcontainer2," + self.base_dn), scope=SCOPE_BASE) + self.assertEquals(len(res), 0) + + print "Testing one-level ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in cn=ldaptestcontainer2," + self.base_dn + res = ldb.search(expression="(&(cn=ldaptestuser4)(objectClass=user))", base=("cn=ldaptestcontainer2," + self.base_dn), scope=SCOPE_ONELEVEL) + # FIXME: self.assertEquals(len(res), 0) + + print "Testing one-level ldb.search for (&(cn=ldaptestuser4)(objectClass=user)) in cn=ldaptestcontainer2," + self.base_dn + res = ldb.search(expression="(&(cn=ldaptestuser4)(objectClass=user))", base=("cn=ldaptestcontainer2," + self.base_dn), scope=SCOPE_SUBTREE) + # FIXME: self.assertEquals(len(res), 0) + + print "Testing delete of subtree renamed "+("CN=ldaptestuser4,CN=ldaptestcontainer2," + self.base_dn) + ldb.delete(("CN=ldaptestuser4,CN=ldaptestcontainer2," + self.base_dn)) + print "Testing delete of renamed cn=ldaptestcontainer2," + self.base_dn + ldb.delete("cn=ldaptestcontainer2," + self.base_dn) + + self.delete_force(self.ldb, "cn=ldaptestutf8user èùéìòà ,cn=users," + self.base_dn) + ldb.add({"dn": "cn=ldaptestutf8user èùéìòà ,cn=users," + self.base_dn, "objectClass": "user"}) + + self.delete_force(self.ldb, "cn=ldaptestutf8user2 èùéìòà ,cn=users," + self.base_dn) + ldb.add({"dn": "cn=ldaptestutf8user2 èùéìòà ,cn=users," + self.base_dn, "objectClass": "user"}) + + print "Testing ldb.search for (&(cn=ldaptestuser)(objectClass=user))" + res = ldb.search(expression="(&(cn=ldaptestuser)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestuser)(objectClass=user))") + + self.assertEquals(str(res[0].dn), ("CN=ldaptestuser,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"], "ldaptestuser") + self.assertEquals(res[0]["name"], "ldaptestuser") + self.assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user"]) + self.assertTrue("objectGUID" in res[0]) + self.assertTrue("whenCreated" in res[0]) + self.assertEquals(res[0]["objectCategory"], ("CN=Person,CN=Schema,CN=Configuration," + self.base_dn)) + self.assertEquals(int(res[0]["sAMAccountType"][0]), 805306368) + # self.assertEquals(res[0].userAccountControl, 546) + self.assertEquals(res[0]["memberOf"][0], ("CN=ldaptestgroup2,CN=Users," + self.base_dn)) + self.assertEquals(len(res[0]["memberOf"]), 1) + + print "Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=cn=person,cn=schema,cn=configuration," + self.base_dn + "))" + res2 = ldb.search(expression="(&(cn=ldaptestuser)(objectCategory=cn=person,cn=schema,cn=configuration," + self.base_dn + "))") + self.assertEquals(len(res2), 1, "Could not find (&(cn=ldaptestuser)(objectCategory=cn=person,cn=schema,cn=configuration," + self.base_dn + "))") + + self.assertEquals(res[0].dn, res2[0].dn) + + print "Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=PerSon))" + res3 = ldb.search(expression="(&(cn=ldaptestuser)(objectCategory=PerSon))") + self.assertEquals(len(res3), 1, "Could not find (&(cn=ldaptestuser)(objectCategory=PerSon)): matched %d" % len(res3)) + + self.assertEquals(res[0].dn, res3[0].dn) + + if gc_ldb is not None: + print "Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=PerSon)) in Global Catalog" + res3gc = gc_ldb.search(expression="(&(cn=ldaptestuser)(objectCategory=PerSon))") + self.assertEquals(len(res3gc), 1) + + self.assertEquals(res[0].dn, res3gc[0].dn) + + print "Testing ldb.search for (&(cn=ldaptestuser)(objectCategory=PerSon)) in with 'phantom root' control" + + res3control = gc_ldb.search(self.base_dn, expression="(&(cn=ldaptestuser)(objectCategory=PerSon))", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["search_options:1:2"]) + self.assertEquals(len(res3control), 1, "Could not find (&(cn=ldaptestuser)(objectCategory=PerSon)) in Global Catalog") + + self.assertEquals(res[0].dn, res3control[0].dn) + + ldb.delete(res[0].dn) + + print "Testing ldb.search for (&(cn=ldaptestcomputer)(objectClass=user))" + res = ldb.search(expression="(&(cn=ldaptestcomputer)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestuser)(objectClass=user))") + + self.assertEquals(str(res[0].dn), ("CN=ldaptestcomputer,CN=Computers," + self.base_dn)) + self.assertEquals(res[0]["cn"], "ldaptestcomputer") + self.assertEquals(res[0]["name"], "ldaptestcomputer") + self.assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user", "computer"]) + self.assertTrue("objectGUID" in res[0]) + self.assertTrue("whenCreated" in res[0]) + self.assertEquals(res[0]["objectCategory"], ("CN=Computer,CN=Schema,CN=Configuration," + self.base_dn)) + self.assertEquals(int(res[0]["primaryGroupID"][0]), 513) + # self.assertEquals(res[0].sAMAccountType, 805306368) + # self.assertEquals(res[0].userAccountControl, 546) + self.assertEquals(res[0]["memberOf"][0], "CN=ldaptestgroup2,CN=Users," + self.base_dn) + self.assertEquals(len(res[0]["memberOf"]), 1) + + print "Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + self.base_dn + "))" + res2 = ldb.search(expression="(&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + self.base_dn + "))") + self.assertEquals(len(res2), 1, "Could not find (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + self.base_dn + "))") + + self.assertEquals(res[0].dn, res2[0].dn) + + if gc_ldb is not None: + print "Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + self.base_dn + ")) in Global Catlog" + res2gc = gc_ldb.search(expression="(&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + self.base_dn + "))") + self.assertEquals(len(res2gc), 1, "Could not find (&(cn=ldaptestcomputer)(objectCategory=cn=computer,cn=schema,cn=configuration," + self.base_dn + ")) in Global Catlog") + + self.assertEquals(res[0].dn, res2gc[0].dn) + + print "Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=compuTER))" + res3 = ldb.search(expression="(&(cn=ldaptestcomputer)(objectCategory=compuTER))") + self.assertEquals(len(res3), 1, "Could not find (&(cn=ldaptestcomputer)(objectCategory=compuTER))") + + self.assertEquals(res[0].dn, res3[0].dn) + + if gc_ldb is not None: + print "Testing ldb.search for (&(cn=ldaptestcomputer)(objectCategory=compuTER)) in Global Catalog" + res3gc = gc_ldb.search(expression="(&(cn=ldaptestcomputer)(objectCategory=compuTER))") + self.assertEquals(len(res3gc), 1, "Could not find (&(cn=ldaptestcomputer)(objectCategory=compuTER)) in Global Catalog") + + self.assertEquals(res[0].dn, res3gc[0].dn) + + print "Testing ldb.search for (&(cn=ldaptestcomp*r)(objectCategory=compuTER))" + res4 = ldb.search(expression="(&(cn=ldaptestcomp*r)(objectCategory=compuTER))") + self.assertEquals(len(res4), 1, "Could not find (&(cn=ldaptestcomp*r)(objectCategory=compuTER))") + + self.assertEquals(res[0].dn, res4[0].dn) + + print "Testing ldb.search for (&(cn=ldaptestcomput*)(objectCategory=compuTER))" + res5 = ldb.search(expression="(&(cn=ldaptestcomput*)(objectCategory=compuTER))") + self.assertEquals(len(res5), 1, "Could not find (&(cn=ldaptestcomput*)(objectCategory=compuTER))") + + self.assertEquals(res[0].dn, res5[0].dn) + + print "Testing ldb.search for (&(cn=*daptestcomputer)(objectCategory=compuTER))" + res6 = ldb.search(expression="(&(cn=*daptestcomputer)(objectCategory=compuTER))") + self.assertEquals(len(res6), 1, "Could not find (&(cn=*daptestcomputer)(objectCategory=compuTER))") + + self.assertEquals(res[0].dn, res6[0].dn) + + ldb.delete(res[0].dn) + + print "Testing ldb.search for (&(cn=ldaptest2computer)(objectClass=user))" + res = ldb.search(expression="(&(cn=ldaptest2computer)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptest2computer)(objectClass=user))") + + self.assertEquals(res[0].dn, ("CN=ldaptest2computer,CN=Computers," + self.base_dn)) + self.assertEquals(res[0]["cn"], "ldaptest2computer") + self.assertEquals(res[0]["name"], "ldaptest2computer") + self.assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user", "computer"]) + self.assertTrue("objectGUID" in res[0]) + self.assertTrue("whenCreated" in res[0]) + self.assertEquals(res[0]["objectCategory"][0], "CN=Computer,CN=Schema,CN=Configuration," + self.base_dn) + self.assertEquals(int(res[0]["sAMAccountType"][0]), 805306369) + # self.assertEquals(res[0].userAccountControl, 4098) + + ldb.delete(res[0].dn) + + attrs = ["cn", "name", "objectClass", "objectGUID", "whenCreated", "nTSecurityDescriptor", "memberOf"] + print "Testing ldb.search for (&(cn=ldaptestUSer2)(objectClass=user))" + res = ldb.search(self.base_dn, expression="(&(cn=ldaptestUSer2)(objectClass=user))", scope=SCOPE_SUBTREE, attrs=attrs) + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestUSer2)(objectClass=user))") + + self.assertEquals(res[0].dn, ("CN=ldaptestuser2,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"], "ldaptestuser2") + self.assertEquals(res[0]["name"], "ldaptestuser2") + self.assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user"]) + self.assertTrue("objectGUID" in res[0]) + self.assertTrue("whenCreated" in res[0]) + self.assertTrue("nTSecurityDescriptor" in res[0]) + self.assertEquals(res[0]["memberOf"][0], ("CN=ldaptestgroup2,CN=Users," + self.base_dn)) + + attrs = ["cn", "name", "objectClass", "objectGUID", "whenCreated", "nTSecurityDescriptor", "member"] + print "Testing ldb.search for (&(cn=ldaptestgroup2)(objectClass=group))" + res = ldb.search(self.base_dn, expression="(&(cn=ldaptestgroup2)(objectClass=group))", scope=SCOPE_SUBTREE, attrs=attrs) + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestgroup2)(objectClass=group))") + + self.assertEquals(res[0].dn, ("CN=ldaptestgroup2,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"], "ldaptestgroup2") + self.assertEquals(res[0]["name"], "ldaptestgroup2") + self.assertEquals(res[0]["objectClass"], ["top", "group"]) + self.assertTrue("objectGuid" not in res[0]) + self.assertTrue("whenCreated" in res[0]) + self.assertTrue("nTSecurityDescriptor" in res[0]) + self.assertEquals(res[0]["member"], ["CN=ldaptestuser2,CN=Users," + self.base_dn]) + + ldb.modify_ldif(""" +dn: cn=ldaptestgroup2,cn=users,""" + self.base_dn + """ changetype: modify replace: member -member: CN=ldaptestuser2,CN=Users,""" + base_dn + """ -member: CN=ldaptestutf8user èùéìòà,CN=Users,""" + base_dn + """ +member: CN=ldaptestuser2,CN=Users,""" + self.base_dn + """ +member: CN=ldaptestutf8user èùéìòà,CN=Users,""" + self.base_dn + """ """) - - print "Testing Linked attribute behaviours" - ldb.modify_ldif(""" -dn: cn=ldaptestgroup2,cn=users,""" + base_dn + """ + + print "Testing Linked attribute behaviours" + ldb.modify_ldif(""" +dn: cn=ldaptestgroup2,cn=users,""" + self.base_dn + """ changetype: modify delete: member """) - ldb.modify_ldif(""" -dn: cn=ldaptestgroup2,cn=users,""" + base_dn + """ + ldb.modify_ldif(""" +dn: cn=ldaptestgroup2,cn=users,""" + self.base_dn + """ changetype: modify add: member -member: CN=ldaptestuser2,CN=Users,""" + base_dn + """ -member: CN=ldaptestutf8user èùéìòà,CN=Users,""" + base_dn + """ +member: CN=ldaptestuser2,CN=Users,""" + self.base_dn + """ +member: CN=ldaptestutf8user èùéìòà,CN=Users,""" + self.base_dn + """ """) - - ldb.modify_ldif(""" -dn: cn=ldaptestgroup2,cn=users,""" + base_dn + """ + + ldb.modify_ldif(""" +dn: cn=ldaptestgroup2,cn=users,""" + self.base_dn + """ changetype: modify replace: member """) - - ldb.modify_ldif(""" -dn: cn=ldaptestgroup2,cn=users,""" + base_dn + """ + + ldb.modify_ldif(""" +dn: cn=ldaptestgroup2,cn=users,""" + self.base_dn + """ changetype: modify add: member -member: CN=ldaptestuser2,CN=Users,""" + base_dn + """ -member: CN=ldaptestutf8user èùéìòà,CN=Users,""" + base_dn + """ +member: CN=ldaptestuser2,CN=Users,""" + self.base_dn + """ +member: CN=ldaptestutf8user èùéìòà,CN=Users,""" + self.base_dn + """ """) - - ldb.modify_ldif(""" -dn: cn=ldaptestgroup2,cn=users,""" + base_dn + """ + + ldb.modify_ldif(""" +dn: cn=ldaptestgroup2,cn=users,""" + self.base_dn + """ changetype: modify delete: member -member: CN=ldaptestutf8user èùéìòà,CN=Users,""" + base_dn + """ +member: CN=ldaptestutf8user èùéìòà,CN=Users,""" + self.base_dn + """ """) - - res = ldb.search(base_dn, expression="(&(cn=ldaptestgroup2)(objectClass=group))", scope=SCOPE_SUBTREE, attrs=attrs) - assert len(res) == 1, "Could not find (&(cn=ldaptestgroup2)(objectClass=group))" + + res = ldb.search(self.base_dn, expression="(&(cn=ldaptestgroup2)(objectClass=group))", scope=SCOPE_SUBTREE, attrs=attrs) + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestgroup2)(objectClass=group))") + + self.assertEquals(res[0].dn, ("CN=ldaptestgroup2,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["member"][0], ("CN=ldaptestuser2,CN=Users," + self.base_dn)) + self.assertEquals(len(res[0]["member"]), 1) - assertEquals(res[0].dn, ("CN=ldaptestgroup2,CN=Users," + base_dn)) - assertEquals(res[0]["member"][0], ("CN=ldaptestuser2,CN=Users," + base_dn)) - assertEquals(len(res[0]["member"]), 1) + ldb.delete(("CN=ldaptestuser2,CN=Users," + self.base_dn)) - ldb.delete(("CN=ldaptestuser2,CN=Users," + base_dn)) + attrs = ["cn", "name", "objectClass", "objectGUID", "whenCreated", "nTSecurityDescriptor", "member"] + print "Testing ldb.search for (&(cn=ldaptestgroup2)(objectClass=group)) to check linked delete" + res = ldb.search(self.base_dn, expression="(&(cn=ldaptestgroup2)(objectClass=group))", scope=SCOPE_SUBTREE, attrs=attrs) + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestgroup2)(objectClass=group)) to check linked delete") - attrs = ["cn", "name", "objectClass", "objectGUID", "whenCreated", "nTSecurityDescriptor", "member"] - print "Testing ldb.search for (&(cn=ldaptestgroup2)(objectClass=group)) to check linked delete" - res = ldb.search(base_dn, expression="(&(cn=ldaptestgroup2)(objectClass=group))", scope=SCOPE_SUBTREE, attrs=attrs) - assert len(res) == 1, "Could not find (&(cn=ldaptestgroup2)(objectClass=group)) to check linked delete" + self.assertEquals(res[0].dn, ("CN=ldaptestgroup2,CN=Users," + self.base_dn)) + self.assertTrue("member" not in res[0]) - assertEquals(res[0].dn, ("CN=ldaptestgroup2,CN=Users," + base_dn)) - assert("member" not in res[0]) + print "Testing ldb.search for (&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))" + res = ldb.search(expression="(&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))") - print "Testing ldb.search for (&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))" - res = ldb.search(expression="(&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))") - assert len(res) == 1, "Could not find (&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))" + self.assertEquals(res[0].dn, ("CN=ldaptestutf8user èùéìòà,CN=Users," + self.base_dn)) + self.assertEquals(res[0]["cn"], "ldaptestutf8user èùéìòà") + self.assertEquals(res[0]["name"], "ldaptestutf8user èùéìòà") + self.assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user"]) + self.assertTrue("objectGUID" in res[0]) + self.assertTrue("whenCreated" in res[0]) - assertEquals(res[0].dn, ("CN=ldaptestutf8user èùéìòà,CN=Users," + base_dn)) - assertEquals(res[0]["cn"], "ldaptestutf8user èùéìòà") - assertEquals(res[0]["name"], "ldaptestutf8user èùéìòà") - assertEquals(res[0]["objectClass"], ["top", "person", "organizationalPerson", "user"]) - assert("objectGUID" in res[0]) - assert("whenCreated" in res[0]) + ldb.delete(res[0].dn) - ldb.delete(res[0].dn) + print "Testing ldb.search for (&(cn=ldaptestutf8user2*)(objectClass=user))" + res = ldb.search(expression="(&(cn=ldaptestutf8user2*)(objectClass=user))") + self.assertEquals(len(res), 1, "Could not find (&(cn=ldaptestutf8user2*)(objectClass=user))") - print "Testing ldb.search for (&(cn=ldaptestutf8user2*)(objectClass=user))" - res = ldb.search(expression="(&(cn=ldaptestutf8user2*)(objectClass=user))") - assert len(res) == 1, "Could not find (&(cn=ldaptestutf8user2*)(objectClass=user))" + ldb.delete(res[0].dn) - ldb.delete(res[0].dn) + ldb.delete(("CN=ldaptestgroup2,CN=Users," + self.base_dn)) - ldb.delete(("CN=ldaptestgroup2,CN=Users," + base_dn)) + print "Testing ldb.search for (&(cn=ldaptestutf8user2 ÈÙÉÌÒÀ)(objectClass=user))" + res = ldb.search(expression="(&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))") - print "Testing ldb.search for (&(cn=ldaptestutf8user2 ÈÙÉÌÒÀ)(objectClass=user))" - res = ldb.search(expression="(&(cn=ldaptestutf8user ÈÙÉÌÒÀ)(objectClass=user))") + #FIXME: self.assert len(res) == 1, "Could not find (expect space collapse, win2k3 fails) (&(cn=ldaptestutf8user2 ÈÙÉÌÒÀ)(objectClass=user))" - #FIXME: assert len(res) == 1, "Could not find (expect space collapse, win2k3 fails) (&(cn=ldaptestutf8user2 ÈÙÉÌÒÀ)(objectClass=user))" + print "Testing that we can't get at the configuration DN from the main search base" + res = ldb.search(self.base_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"]) + self.assertEquals(len(res), 0) - print "Testing that we can't get at the configuration DN from the main search base" - res = ldb.search(base_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"]) - assert len(res) == 0, "Got configuration DN " + res[0].dn + " which should not be able to be seen from main search base" - assertEquals(len(res), 0) + print "Testing that we can get at the configuration DN from the main search base on the LDAP port with the 'phantom root' search_options control" + res = ldb.search(self.base_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["search_options:1:2"]) + self.assertTrue(len(res) > 0) - print "Testing that we can get at the configuration DN from the main search base on the LDAP port with the 'phantom root' search_options control" - res = ldb.search(base_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["search_options:1:2"]) - assert(len(res) > 0) + if gc_ldb is not None: + print "Testing that we can get at the configuration DN from the main search base on the GC port with the search_options control == 0" + + res = gc_ldb.search(self.base_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["search_options:1:0"]) + self.assertTrue(len(res) > 0) - if gc_ldb is not None: - print "Testing that we can get at the configuration DN from the main search base on the GC port with the search_options control == 0" + print "Testing that we do find configuration elements in the global catlog" + res = gc_ldb.search(self.base_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"]) + self.assertTrue(len(res) > 0) + + print "Testing that we do find configuration elements and user elements at the same time" + res = gc_ldb.search(self.base_dn, expression="(|(objectClass=crossRef)(objectClass=person))", scope=SCOPE_SUBTREE, attrs=["cn"]) + self.assertTrue(len(res) > 0) + + print "Testing that we do find configuration elements in the global catlog, with the configuration basedn" + res = gc_ldb.search(self.configuration_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"]) + self.assertTrue(len(res) > 0) + + print "Testing that we can get at the configuration DN on the main LDAP port" + res = ldb.search(self.configuration_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"]) + self.assertTrue(len(res) > 0) + + print "Testing objectCategory canonacolisation" + res = ldb.search(self.configuration_dn, expression="objectCategory=ntDsDSA", scope=SCOPE_SUBTREE, attrs=["cn"]) + self.assertTrue(len(res) > 0, "Didn't find any records with objectCategory=ntDsDSA") + self.assertTrue(len(res) != 0) - res = gc_ldb.search(base_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["search_options:1:0"]) - assert(len(res) > 0) - - print "Testing that we do find configuration elements in the global catlog" - res = gc_ldb.search(base_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"]) - assert (len(res) > 0) - - print "Testing that we do find configuration elements and user elements at the same time" - res = gc_ldb.search(base_dn, expression="(|(objectClass=crossRef)(objectClass=person))", scope=SCOPE_SUBTREE, attrs=["cn"]) - assert (len(res) > 0) - - print "Testing that we do find configuration elements in the global catlog, with the configuration basedn" - res = gc_ldb.search(configuration_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"]) - assert (len(res) > 0) - - print "Testing that we can get at the configuration DN on the main LDAP port" - res = ldb.search(configuration_dn, expression="objectClass=crossRef", scope=SCOPE_SUBTREE, attrs=["cn"]) - assert (len(res) > 0) - - print "Testing objectCategory canonacolisation" - res = ldb.search(configuration_dn, expression="objectCategory=ntDsDSA", scope=SCOPE_SUBTREE, attrs=["cn"]) - assert len(res) > 0, "Didn't find any records with objectCategory=ntDsDSA" - assert(len(res) != 0) - - res = ldb.search(configuration_dn, expression="objectCategory=CN=ntDs-DSA," + schema_dn, scope=SCOPE_SUBTREE, attrs=["cn"]) - assert len(res) > 0, "Didn't find any records with objectCategory=CN=ntDs-DSA," + schema_dn - assert(len(res) != 0) - - print "Testing objectClass attribute order on "+ base_dn - res = ldb.search(expression="objectClass=domain", base=base_dn, - scope=SCOPE_BASE, attrs=["objectClass"]) - assertEquals(len(res), 1) - - assertEquals(res[0]["objectClass"], ["top", "domain", "domainDNS"]) - -# check enumeration - - print "Testing ldb.search for objectCategory=person" - res = ldb.search(base_dn, expression="objectCategory=person", scope=SCOPE_SUBTREE, attrs=["cn"]) - assert(len(res) > 0) - - print "Testing ldb.search for objectCategory=person with domain scope control" - res = ldb.search(base_dn, expression="objectCategory=person", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["domain_scope:1"]) - assert(len(res) > 0) - - print "Testing ldb.search for objectCategory=user" - res = ldb.search(base_dn, expression="objectCategory=user", scope=SCOPE_SUBTREE, attrs=["cn"]) - assert(len(res) > 0) - - - print "Testing ldb.search for objectCategory=user with domain scope control" - res = ldb.search(base_dn, expression="objectCategory=user", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["domain_scope:1"]) - assert(len(res) > 0) - - print "Testing ldb.search for objectCategory=group" - res = ldb.search(base_dn, expression="objectCategory=group", scope=SCOPE_SUBTREE, attrs=["cn"]) - assert(len(res) > 0) - - print "Testing ldb.search for objectCategory=group with domain scope control" - res = ldb.search(base_dn, expression="objectCategory=group", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["domain_scope:1"]) - assert(len(res) > 0) - -def basedn_tests(ldb, gc_ldb): - print "Testing for all rootDSE attributes" - res = ldb.search(scope=SCOPE_BASE, attrs=[]) - assertEquals(len(res), 1) - - print "Testing for highestCommittedUSN" - res = ldb.search("", scope=SCOPE_BASE, attrs=["highestCommittedUSN"]) - assertEquals(len(res), 1) - assert(int(res[0]["highestCommittedUSN"][0]) != 0) - - print "Testing for netlogon via LDAP" - res = ldb.search("", scope=SCOPE_BASE, attrs=["netlogon"]) - assertEquals(len(res), 0) - - print "Testing for netlogon and highestCommittedUSN via LDAP" - res = ldb.search("", scope=SCOPE_BASE, - attrs=["netlogon", "highestCommittedUSN"]) - assertEquals(len(res), 0) - - -def find_basedn(ldb): - res = ldb.search(base="", expression="", scope=SCOPE_BASE, - attrs=["defaultNamingContext"]) - assertEquals(len(res), 1) - return res[0]["defaultNamingContext"][0] - - -def find_configurationdn(ldb): - res = ldb.search(base="", expression="", scope=SCOPE_BASE, attrs=["configurationNamingContext"]) - assertEquals(len(res), 1) - return res[0]["configurationNamingContext"][0] - - -def find_schemadn(ldb): - res = ldb.search(base="", expression="", scope=SCOPE_BASE, attrs=["schemaNamingContext"]) - assertEquals(len(res), 1) - return res[0]["schemaNamingContext"][0] + res = ldb.search(self.configuration_dn, expression="objectCategory=CN=ntDs-DSA," + self.schema_dn, scope=SCOPE_SUBTREE, attrs=["cn"]) + self.assertTrue(len(res) > 0, "Didn't find any records with objectCategory=CN=ntDs-DSA," + self.schema_dn) + self.assertTrue(len(res) != 0) + + print "Testing objectClass attribute order on "+ self.base_dn + res = ldb.search(expression="objectClass=domain", base=self.base_dn, + scope=SCOPE_BASE, attrs=["objectClass"]) + self.assertEquals(len(res), 1) + + self.assertEquals(res[0]["objectClass"], ["top", "domain", "domainDNS"]) + + # check enumeration + + print "Testing ldb.search for objectCategory=person" + res = ldb.search(self.base_dn, expression="objectCategory=person", scope=SCOPE_SUBTREE, attrs=["cn"]) + self.assertTrue(len(res) > 0) + + print "Testing ldb.search for objectCategory=person with domain scope control" + res = ldb.search(self.base_dn, expression="objectCategory=person", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["domain_scope:1"]) + self.assertTrue(len(res) > 0) + + print "Testing ldb.search for objectCategory=user" + res = ldb.search(self.base_dn, expression="objectCategory=user", scope=SCOPE_SUBTREE, attrs=["cn"]) + self.assertTrue(len(res) > 0) + + print "Testing ldb.search for objectCategory=user with domain scope control" + res = ldb.search(self.base_dn, expression="objectCategory=user", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["domain_scope:1"]) + self.assertTrue(len(res) > 0) + + print "Testing ldb.search for objectCategory=group" + res = ldb.search(self.base_dn, expression="objectCategory=group", scope=SCOPE_SUBTREE, attrs=["cn"]) + self.assertTrue(len(res) > 0) + + print "Testing ldb.search for objectCategory=group with domain scope control" + res = ldb.search(self.base_dn, expression="objectCategory=group", scope=SCOPE_SUBTREE, attrs=["cn"], controls=["domain_scope:1"]) + self.assertTrue(len(res) > 0) + + +class BaseDnTests(unittest.TestCase): + def setUp(self): + self.ldb = ldb + + def test_rootdse_attrs(self): + """Testing for all rootDSE attributes""" + res = self.ldb.search(scope=SCOPE_BASE, attrs=[]) + self.assertEquals(len(res), 1) + + def test_highestcommittedusn(self): + """Testing for highestCommittedUSN""" + res = self.ldb.search("", scope=SCOPE_BASE, attrs=["highestCommittedUSN"]) + self.assertEquals(len(res), 1) + self.assertTrue(int(res[0]["highestCommittedUSN"][0]) != 0) + + def test_netlogon(self): + """Testing for netlogon via LDAP""" + res = self.ldb.search("", scope=SCOPE_BASE, attrs=["netlogon"]) + self.assertEquals(len(res), 0) + + def test_netlogon_highestcommitted_usn(self): + """Testing for netlogon and highestCommittedUSN via LDAP""" + res = self.ldb.search("", scope=SCOPE_BASE, + attrs=["netlogon", "highestCommittedUSN"]) + self.assertEquals(len(res), 0) + if not "://" in host: host = "ldap://%s" % host ldb = Ldb(host, credentials=creds, session_info=system_session(), lp=lp) -base_dn = find_basedn(ldb) -configuration_dn = find_configurationdn(ldb) -schema_dn = find_schemadn(ldb) - -print "baseDN: %s\n" % base_dn - gc_ldb = Ldb("%s:3268" % host, credentials=creds, session_info=system_session(), lp=lp) -basic_tests(ldb, gc_ldb, base_dn, configuration_dn, schema_dn) -basedn_tests(ldb, gc_ldb) +runner = SubunitTestRunner() +runner.run(unittest.makeSuite(BaseDnTests)) +runner.run(unittest.makeSuite(BasicTests)) diff --git a/source4/lib/ldb/tests/sample_module.c b/source4/lib/ldb/tests/sample_module.c index 8ab1d33146..98d8e865dd 100644 --- a/source4/lib/ldb/tests/sample_module.c +++ b/source4/lib/ldb/tests/sample_module.c @@ -32,12 +32,7 @@ int sample_add(struct ldb_module *mod, struct ldb_request *req) return ldb_next_request(mod, req); } -static const struct ldb_module_ops sample_ops = { - .name = "sample_module", +_PUBLIC_ const struct ldb_module_ops ldb_sample_module_ops = { + .name = "sample", .add = sample_add, }; - -int init_module(void) -{ - return ldb_register_module(&sample_ops); -} diff --git a/source4/lib/ldb/tools/ad2oLschema.c b/source4/lib/ldb/tools/ad2oLschema.c index dec8a5f972..67b16dd06e 100644 --- a/source4/lib/ldb/tools/ad2oLschema.c +++ b/source4/lib/ldb/tools/ad2oLschema.c @@ -656,8 +656,6 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_ const char *target_str; enum convert_target target; - ldb_global_init(); - ctx = talloc_new(NULL); ldb = ldb_init(ctx); diff --git a/source4/lib/ldb/tools/cmdline.c b/source4/lib/ldb/tools/cmdline.c index 8ee1994615..c9c77c4e47 100644 --- a/source4/lib/ldb/tools/cmdline.c +++ b/source4/lib/ldb/tools/cmdline.c @@ -80,8 +80,6 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, { NULL } }; - ldb_global_init(); - #if (_SAMBA_BUILD_ >= 4) r = ldb_register_samba_handlers(ldb); if (r != 0) { diff --git a/source4/lib/ldb/tools/ldbadd.c b/source4/lib/ldb/tools/ldbadd.c index d34193b86c..4ee66c4fc0 100644 --- a/source4/lib/ldb/tools/ldbadd.c +++ b/source4/lib/ldb/tools/ldbadd.c @@ -88,8 +88,6 @@ int main(int argc, const char **argv) int i, ret=0, count=0; struct ldb_cmdline *options; - ldb_global_init(); - ldb = ldb_init(NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); diff --git a/source4/lib/ldb/tools/ldbdel.c b/source4/lib/ldb/tools/ldbdel.c index fcd0978779..184172b22b 100644 --- a/source4/lib/ldb/tools/ldbdel.c +++ b/source4/lib/ldb/tools/ldbdel.c @@ -77,8 +77,6 @@ int main(int argc, const char **argv) int ret = 0, i; struct ldb_cmdline *options; - ldb_global_init(); - ldb = ldb_init(NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index ed98a6d615..a9fd064bf8 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -279,8 +279,6 @@ int main(int argc, const char **argv) const char *expression = "(|(objectClass=*)(distinguishedName=*))"; const char * const * attrs = NULL; - ldb_global_init(); - ldb = ldb_init(NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index ed12380095..dd6206b824 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -89,8 +89,6 @@ int main(int argc, const char **argv) int i, ret=LDB_SUCCESS; struct ldb_cmdline *options; - ldb_global_init(); - ldb = ldb_init(NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); diff --git a/source4/lib/ldb/tools/ldbrename.c b/source4/lib/ldb/tools/ldbrename.c index c160e87ee4..b36310a500 100644 --- a/source4/lib/ldb/tools/ldbrename.c +++ b/source4/lib/ldb/tools/ldbrename.c @@ -56,8 +56,6 @@ int main(int argc, const char **argv) struct ldb_cmdline *options; struct ldb_dn *dn1, *dn2; - ldb_global_init(); - ldb = ldb_init(NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index 24ceb30963..e25bd19965 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -276,8 +276,6 @@ int main(int argc, const char **argv) int ret = -1; const char *expression = "(|(objectClass=*)(distinguishedName=*))"; - ldb_global_init(); - ldb = ldb_init(NULL); options = ldb_cmdline_process(ldb, argc, argv, usage); diff --git a/source4/lib/ldb/tools/ldbtest.c b/source4/lib/ldb/tools/ldbtest.c index 5c21dd3830..57a7848733 100644 --- a/source4/lib/ldb/tools/ldbtest.c +++ b/source4/lib/ldb/tools/ldbtest.c @@ -393,8 +393,6 @@ int main(int argc, const char **argv) TALLOC_CTX *mem_ctx = talloc_new(NULL); struct ldb_context *ldb; - ldb_global_init(); - ldb = ldb_init(mem_ctx); options = ldb_cmdline_process(ldb, argc, argv, usage); diff --git a/source4/lib/ldb/tools/oLschema2ldif.c b/source4/lib/ldb/tools/oLschema2ldif.c index 7b5f1b835c..1846a2c852 100644 --- a/source4/lib/ldb/tools/oLschema2ldif.c +++ b/source4/lib/ldb/tools/oLschema2ldif.c @@ -560,8 +560,6 @@ static void usage(void) struct ldb_cmdline *options; FILE *in = stdin; FILE *out = stdout; - ldb_global_init(); - ctx = talloc_new(NULL); ldb_ctx = ldb_init(ctx); |