diff options
Diffstat (limited to 'source4/lib')
91 files changed, 1762 insertions, 2964 deletions
diff --git a/source4/lib/basic.mk b/source4/lib/basic.mk index 8653779044..a118636c52 100644 --- a/source4/lib/basic.mk +++ b/source4/lib/basic.mk @@ -1,32 +1,28 @@ # LIB BASIC subsystem -include samba3/config.mk -include socket/config.mk -include charset/config.mk -include ldb-samba/config.mk -include tls/config.mk -include registry/config.mk -include policy/config.mk -include messaging/config.mk -include events/config.mk -include cmdline/config.mk -include socket_wrapper/config.mk -include nss_wrapper/config.mk -include appweb/config.mk -include stream/config.mk -include util/config.mk -include tdr/config.mk -include dbwrap/config.mk -include crypto/config.mk +mkinclude samba3/config.mk +mkinclude socket/config.mk +mkinclude charset/config.mk +mkinclude ldb-samba/config.mk +mkinclude tls/config.mk +mkinclude registry/config.mk +mkinclude policy/config.mk +mkinclude messaging/config.mk +mkinclude events/config.mk +mkinclude cmdline/config.mk +mkinclude socket_wrapper/config.mk +mkinclude nss_wrapper/config.mk +mkinclude appweb/config.mk +mkinclude stream/config.mk +mkinclude util/config.mk +mkinclude tdr/config.mk +mkinclude dbwrap/config.mk +mkinclude crypto/config.mk -################################################ -# Start SUBSYSTEM LIBCOMPRESSION [SUBSYSTEM::LIBCOMPRESSION] OBJ_FILES = compression/mszip.o -# End SUBSYSTEM LIBCOMPRESION -################################################ [SUBSYSTEM::GENCACHE] -PRIVATE_PROTO_HEADER = gencache/gencache.h +PUBLIC_HEADERS = gencache/gencache.h OBJ_FILES = gencache/gencache.o PRIVATE_DEPENDENCIES = TDB_WRAP diff --git a/source4/lib/events/events_select.c b/source4/lib/events/events_select.c index 3f9eeb5617..f4b7e4e5eb 100644 --- a/source4/lib/events/events_select.c +++ b/source4/lib/events/events_select.c @@ -300,7 +300,7 @@ bool events_select_init(void) } #if _SAMBA_BUILD_ -NTSTATUS s4_events_select_init(void) +_PUBLIC_ NTSTATUS s4_events_select_init(void) { if (!events_select_init()) { return NT_STATUS_INTERNAL_ERROR; diff --git a/source4/lib/events/events_standard.c b/source4/lib/events/events_standard.c index 5e529d66ab..7b945b154d 100644 --- a/source4/lib/events/events_standard.c +++ b/source4/lib/events/events_standard.c @@ -602,7 +602,7 @@ bool events_standard_init(void) } #if _SAMBA_BUILD_ -NTSTATUS s4_events_standard_init(void) +_PUBLIC_ NTSTATUS s4_events_standard_init(void) { if (!events_standard_init()) { return NT_STATUS_INTERNAL_ERROR; diff --git a/source4/lib/gencache/gencache.h b/source4/lib/gencache/gencache.h new file mode 100644 index 0000000000..1481676fd9 --- /dev/null +++ b/source4/lib/gencache/gencache.h @@ -0,0 +1,94 @@ +#ifndef __LIB_GENCACHE_GENCACHE_H__ +#define __LIB_GENCACHE_GENCACHE_H__ + +/** + * Cache initialisation function. Opens cache tdb file or creates + * it if does not exist. + * + * @return true on successful initialisation of the cache or + * false on failure + **/ +bool gencache_init(struct loadparm_context *lp_ctx); + +/** + * Cache shutdown function. Closes opened cache tdb file. + * + * @return true on successful closing the cache or + * false on failure during cache shutdown + **/ +bool gencache_shutdown(void); + +/** + * Set an entry in the cache file. If there's no such + * one, then add it. + * + * @param keystr string that represents a key of this entry + * @param value text representation value being cached + * @param timeout time when the value is expired + * + * @retval true when entry is successfuly stored + * @retval false on failure + **/ +bool gencache_set(const char *keystr, const char *value, time_t timeout); + +/** + * Set existing entry to the cache file. + * + * @param keystr string that represents a key of this entry + * @param valstr text representation value being cached + * @param timeout time when the value is expired + * + * @retval true when entry is successfuly set + * @retval false on failure + **/ +bool gencache_set_only(const char *keystr, const char *valstr, time_t timeout); + +/** + * Delete one entry from the cache file. + * + * @param keystr string that represents a key of this entry + * + * @retval true upon successful deletion + * @retval false in case of failure + **/ +bool gencache_del(const char *keystr); + +/** + * Get existing entry from the cache file. + * + * @param keystr string that represents a key of this entry + * @param valstr buffer that is allocated and filled with the entry value + * buffer's disposing must be done outside + * @param timeout pointer to a time_t that is filled with entry's + * timeout + * + * @retval true when entry is successfuly fetched + * @retval false for failure + **/ +bool gencache_get(const char *keystr, char **valstr, time_t *timeout); + +/** + * Iterate through all entries which key matches to specified pattern + * + * @param fn pointer to the function that will be supplied with each single + * matching cache entry (key, value and timeout) as an arguments + * @param data void pointer to an arbitrary data that is passed directly to the fn + * function on each call + * @param keystr_pattern pattern the existing entries' keys are matched to + * + **/ +void gencache_iterate(void (*fn)(const char* key, const char *value, time_t timeout, void* dptr), + void* data, const char* keystr_pattern); + +/******************************************************************** + lock a key +********************************************************************/ +int gencache_lock_entry( const char *key ); + +/******************************************************************** + unlock a key +********************************************************************/ +void gencache_unlock_entry( const char *key ); + +#endif /* __LIB_GENCACHE_GENCACHE_H__ */ + 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); diff --git a/source4/lib/registry/ldb.c b/source4/lib/registry/ldb.c index 262859f64b..0c8a55396e 100644 --- a/source4/lib/registry/ldb.c +++ b/source4/lib/registry/ldb.c @@ -400,7 +400,7 @@ static WERROR ldb_add_key(TALLOC_CTX *mem_ctx, const struct hive_key *parent, struct security_descriptor *sd, struct hive_key **newkey) { - struct ldb_key_data *parentkd = (const struct ldb_key_data *)parent; + struct ldb_key_data *parentkd = discard_const_p(struct ldb_key_data, parent); struct ldb_message *msg; struct ldb_key_data *newkd; int ret; diff --git a/source4/lib/registry/tools/regshell.c b/source4/lib/registry/tools/regshell.c index 93f28f3e5a..d5c506ab31 100644 --- a/source4/lib/registry/tools/regshell.c +++ b/source4/lib/registry/tools/regshell.c @@ -116,6 +116,9 @@ static WERROR cmd_predef(struct regshell_context *ctx, int argc, char **argv) argv[1], win_errstr(error)); return error; } + + ctx->path = strupper_talloc(ctx, argv[1]); + ctx->current = ret; } return WERR_OK; diff --git a/source4/lib/replace/dlfcn.c b/source4/lib/replace/dlfcn.c index 42848848e8..3b109d7e40 100644 --- a/source4/lib/replace/dlfcn.c +++ b/source4/lib/replace/dlfcn.c @@ -35,6 +35,8 @@ void *rep_dlopen(const char *name, int flags) #endif { #ifdef HAVE_SHL_LOAD + if (name == NULL) + return PROG_HANDLE; return (void *)shl_load(name, flags, 0); #else return NULL; diff --git a/source4/lib/replace/getifaddrs.m4 b/source4/lib/replace/getifaddrs.m4 index 297a82d0c3..4cf86d89cc 100644 --- a/source4/lib/replace/getifaddrs.m4 +++ b/source4/lib/replace/getifaddrs.m4 @@ -7,7 +7,7 @@ AC_CHECK_MEMBERS([struct sockaddr.sa_len], [#include <sys/socket.h>]) dnl test for getifaddrs and freeifaddrs -AC_CACHE_CHECK([for getifaddrs and freeifaddrs],samba_cv_HAVE_GETIFADDRS,[ +AC_CACHE_CHECK([for getifaddrs and freeifaddrs],libreplace_cv_HAVE_GETIFADDRS,[ AC_TRY_COMPILE([ #include <sys/types.h> #if STDC_HEADERS @@ -24,8 +24,8 @@ struct ifaddrs *ifp = NULL; int ret = getifaddrs (&ifp); freeifaddrs(ifp); ], -samba_cv_HAVE_GETIFADDRS=yes,samba_cv_HAVE_GETIFADDRS=no)]) -if test x"$samba_cv_HAVE_GETIFADDRS" = x"yes"; then +libreplace_cv_HAVE_GETIFADDRS=yes,libreplace_cv_HAVE_GETIFADDRS=no)]) +if test x"$libreplace_cv_HAVE_GETIFADDRS" = x"yes"; then AC_DEFINE(HAVE_GETIFADDRS,1,[Whether the system has getifaddrs]) AC_DEFINE(HAVE_FREEIFADDRS,1,[Whether the system has freeifaddrs]) AC_DEFINE(HAVE_STRUCT_IFADDRS,1,[Whether struct ifaddrs is available]) @@ -42,18 +42,15 @@ iface=no; ################## # look for a method of finding the list of network interfaces iface=no; -AC_CACHE_CHECK([for iface getifaddrs],samba_cv_HAVE_IFACE_GETIFADDRS,[ -SAVE_CPPFLAGS="$CPPFLAGS" -CPPFLAGS="$CPPFLAGS ${SAMBA_CONFIGURE_CPPFLAGS}" +AC_CACHE_CHECK([for iface getifaddrs],libreplace_cv_HAVE_IFACE_GETIFADDRS,[ AC_TRY_RUN([ #define NO_CONFIG_H 1 #define HAVE_IFACE_GETIFADDRS 1 #define AUTOCONF_TEST 1 #include "$libreplacedir/replace.c" #include "$libreplacedir/getifaddrs.c"], - samba_cv_HAVE_IFACE_GETIFADDRS=yes,samba_cv_HAVE_IFACE_GETIFADDRS=no,samba_cv_HAVE_IFACE_GETIFADDRS=cross)]) -CPPFLAGS="$SAVE_CPPFLAGS" -if test x"$samba_cv_HAVE_IFACE_GETIFADDRS" = x"yes"; then + libreplace_cv_HAVE_IFACE_GETIFADDRS=yes,libreplace_cv_HAVE_IFACE_GETIFADDRS=no,libreplace_cv_HAVE_IFACE_GETIFADDRS=cross)]) +if test x"$libreplace_cv_HAVE_IFACE_GETIFADDRS" = x"yes"; then iface=yes;AC_DEFINE(HAVE_IFACE_GETIFADDRS,1,[Whether iface getifaddrs is available]) else LIBREPLACEOBJ="${LIBREPLACEOBJ} getifaddrs.o" @@ -61,39 +58,39 @@ fi if test $iface = no; then -AC_CACHE_CHECK([for iface AIX],samba_cv_HAVE_IFACE_AIX,[ +AC_CACHE_CHECK([for iface AIX],libreplace_cv_HAVE_IFACE_AIX,[ AC_TRY_RUN([ #define HAVE_IFACE_AIX 1 #define AUTOCONF_TEST 1 #undef _XOPEN_SOURCE_EXTENDED #include "$libreplacedir/getifaddrs.c"], - samba_cv_HAVE_IFACE_AIX=yes,samba_cv_HAVE_IFACE_AIX=no,samba_cv_HAVE_IFACE_AIX=cross)]) -if test x"$samba_cv_HAVE_IFACE_AIX" = x"yes"; then + libreplace_cv_HAVE_IFACE_AIX=yes,libreplace_cv_HAVE_IFACE_AIX=no,libreplace_cv_HAVE_IFACE_AIX=cross)]) +if test x"$libreplace_cv_HAVE_IFACE_AIX" = x"yes"; then iface=yes;AC_DEFINE(HAVE_IFACE_AIX,1,[Whether iface AIX is available]) fi fi if test $iface = no; then -AC_CACHE_CHECK([for iface ifconf],samba_cv_HAVE_IFACE_IFCONF,[ +AC_CACHE_CHECK([for iface ifconf],libreplace_cv_HAVE_IFACE_IFCONF,[ AC_TRY_RUN([ #define HAVE_IFACE_IFCONF 1 #define AUTOCONF_TEST 1 #include "$libreplacedir/getifaddrs.c"], - samba_cv_HAVE_IFACE_IFCONF=yes,samba_cv_HAVE_IFACE_IFCONF=no,samba_cv_HAVE_IFACE_IFCONF=cross)]) -if test x"$samba_cv_HAVE_IFACE_IFCONF" = x"yes"; then + libreplace_cv_HAVE_IFACE_IFCONF=yes,libreplace_cv_HAVE_IFACE_IFCONF=no,libreplace_cv_HAVE_IFACE_IFCONF=cross)]) +if test x"$libreplace_cv_HAVE_IFACE_IFCONF" = x"yes"; then iface=yes;AC_DEFINE(HAVE_IFACE_IFCONF,1,[Whether iface ifconf is available]) fi fi if test $iface = no; then -AC_CACHE_CHECK([for iface ifreq],samba_cv_HAVE_IFACE_IFREQ,[ +AC_CACHE_CHECK([for iface ifreq],libreplace_cv_HAVE_IFACE_IFREQ,[ AC_TRY_RUN([ #define HAVE_IFACE_IFREQ 1 #define AUTOCONF_TEST 1 #include "$libreplacedir/getifaddrs.c"], - samba_cv_HAVE_IFACE_IFREQ=yes,samba_cv_HAVE_IFACE_IFREQ=no,samba_cv_HAVE_IFACE_IFREQ=cross)]) -if test x"$samba_cv_HAVE_IFACE_IFREQ" = x"yes"; then + libreplace_cv_HAVE_IFACE_IFREQ=yes,libreplace_cv_HAVE_IFACE_IFREQ=no,libreplace_cv_HAVE_IFACE_IFREQ=cross)]) +if test x"$libreplace_cv_HAVE_IFACE_IFREQ" = x"yes"; then iface=yes;AC_DEFINE(HAVE_IFACE_IFREQ,1,[Whether iface ifreq is available]) fi fi diff --git a/source4/lib/replace/getpass.m4 b/source4/lib/replace/getpass.m4 index c4da9aae59..b93817f9d3 100644 --- a/source4/lib/replace/getpass.m4 +++ b/source4/lib/replace/getpass.m4 @@ -1,22 +1,22 @@ -AC_CHECK_FUNC(getpass, samba_cv_HAVE_GETPASS=yes) -AC_CHECK_FUNC(getpassphrase, samba_cv_HAVE_GETPASSPHRASE=yes) -if test x"$samba_cv_HAVE_GETPASS" = x"yes" -a x"$samba_cv_HAVE_GETPASSPHRASE" = x"yes"; then +AC_CHECK_FUNC(getpass, libreplace_cv_HAVE_GETPASS=yes) +AC_CHECK_FUNC(getpassphrase, libreplace_cv_HAVE_GETPASSPHRASE=yes) +if test x"$libreplace_cv_HAVE_GETPASS" = x"yes" -a x"$libreplace_cv_HAVE_GETPASSPHRASE" = x"yes"; then AC_DEFINE(REPLACE_GETPASS_BY_GETPASSPHRASE, 1, [getpass returns <9 chars where getpassphrase returns <265 chars]) AC_DEFINE(REPLACE_GETPASS,1,[Whether getpass should be replaced]) LIBREPLACEOBJ="${LIBREPLACEOBJ} getpass.o" else -AC_CACHE_CHECK([whether getpass should be replaced],samba_cv_REPLACE_GETPASS,[ +AC_CACHE_CHECK([whether getpass should be replaced],libreplace_cv_REPLACE_GETPASS,[ SAVE_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS -I$libreplacedir/" AC_TRY_COMPILE([ #include "confdefs.h" #define NO_CONFIG_H #include "$libreplacedir/getpass.c" -],[],samba_cv_REPLACE_GETPASS=yes,samba_cv_REPLACE_GETPASS=no) +],[],libreplace_cv_REPLACE_GETPASS=yes,libreplace_cv_REPLACE_GETPASS=no) CPPFLAGS="$SAVE_CPPFLAGS" ]) -if test x"$samba_cv_REPLACE_GETPASS" = x"yes"; then +if test x"$libreplace_cv_REPLACE_GETPASS" = x"yes"; then AC_DEFINE(REPLACE_GETPASS,1,[Whether getpass should be replaced]) LIBREPLACEOBJ="${LIBREPLACEOBJ} getpass.o" fi diff --git a/source4/lib/replace/libreplace.m4 b/source4/lib/replace/libreplace.m4 index 6d1d6b8afc..2e0cd34f4a 100644 --- a/source4/lib/replace/libreplace.m4 +++ b/source4/lib/replace/libreplace.m4 @@ -85,10 +85,10 @@ AC_INCLUDES_DEFAULT #endif] ) -AC_CACHE_CHECK([for working mmap],samba_cv_HAVE_MMAP,[ +AC_CACHE_CHECK([for working mmap],libreplace_cv_HAVE_MMAP,[ AC_TRY_RUN([#include "$libreplacedir/test/shared_mmap.c"], - samba_cv_HAVE_MMAP=yes,samba_cv_HAVE_MMAP=no,samba_cv_HAVE_MMAP=cross)]) -if test x"$samba_cv_HAVE_MMAP" = x"yes"; then + libreplace_cv_HAVE_MMAP=yes,libreplace_cv_HAVE_MMAP=no,libreplace_cv_HAVE_MMAP=cross)]) +if test x"$libreplace_cv_HAVE_MMAP" = x"yes"; then AC_DEFINE(HAVE_MMAP,1,[Whether mmap works]) fi @@ -120,7 +120,7 @@ if test x"$libreplace_cv_USABLE_NET_IF_H" = x"yes";then AC_DEFINE(HAVE_NET_IF_H, 1, usability of net/if.h) fi -AC_CACHE_CHECK([for broken inet_ntoa],samba_cv_REPLACE_INET_NTOA,[ +AC_CACHE_CHECK([for broken inet_ntoa],libreplace_cv_REPLACE_INET_NTOA,[ AC_TRY_RUN([ #include <stdio.h> #include <unistd.h> @@ -133,8 +133,8 @@ main() { struct in_addr ip; ip.s_addr = 0x12345678; if (strcmp(inet_ntoa(ip),"18.52.86.120") && strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); } exit(1);}], - samba_cv_REPLACE_INET_NTOA=yes,samba_cv_REPLACE_INET_NTOA=no,samba_cv_REPLACE_INET_NTOA=cross)]) -if test x"$samba_cv_REPLACE_INET_NTOA" = x"yes"; then + libreplace_cv_REPLACE_INET_NTOA=yes,libreplace_cv_REPLACE_INET_NTOA=no,libreplace_cv_REPLACE_INET_NTOA=cross)]) +if test x"$libreplace_cv_REPLACE_INET_NTOA" = x"yes"; then AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced]) fi @@ -182,7 +182,7 @@ AC_HAVE_DECL(setresuid, [#include <unistd.h>]) AC_HAVE_DECL(setresgid, [#include <unistd.h>]) AC_HAVE_DECL(errno, [#include <errno.h>]) -AC_CACHE_CHECK([for secure mkstemp],samba_cv_HAVE_SECURE_MKSTEMP,[ +AC_CACHE_CHECK([for secure mkstemp],libreplace_cv_HAVE_SECURE_MKSTEMP,[ AC_TRY_RUN([#include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> @@ -197,10 +197,10 @@ main() { if ((st.st_mode & 0777) != 0600) exit(1); exit(0); }], -samba_cv_HAVE_SECURE_MKSTEMP=yes, -samba_cv_HAVE_SECURE_MKSTEMP=no, -samba_cv_HAVE_SECURE_MKSTEMP=cross)]) -if test x"$samba_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then +libreplace_cv_HAVE_SECURE_MKSTEMP=yes, +libreplace_cv_HAVE_SECURE_MKSTEMP=no, +libreplace_cv_HAVE_SECURE_MKSTEMP=cross)]) +if test x"$libreplace_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure]) fi @@ -209,7 +209,7 @@ AC_CHECK_HEADERS(stdio.h strings.h) AC_CHECK_DECLS([snprintf, vsnprintf, asprintf, vasprintf]) AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf) -AC_CACHE_CHECK([for C99 vsnprintf],samba_cv_HAVE_C99_VSNPRINTF,[ +AC_CACHE_CHECK([for C99 vsnprintf],libreplace_cv_HAVE_C99_VSNPRINTF,[ AC_TRY_RUN([ #include <sys/types.h> #include <stdio.h> @@ -243,43 +243,43 @@ void foo(const char *format, ...) { } main() { foo("hello"); } ], -samba_cv_HAVE_C99_VSNPRINTF=yes,samba_cv_HAVE_C99_VSNPRINTF=no,samba_cv_HAVE_C99_VSNPRINTF=cross)]) -if test x"$samba_cv_HAVE_C99_VSNPRINTF" = x"yes"; then +libreplace_cv_HAVE_C99_VSNPRINTF=yes,libreplace_cv_HAVE_C99_VSNPRINTF=no,libreplace_cv_HAVE_C99_VSNPRINTF=cross)]) +if test x"$libreplace_cv_HAVE_C99_VSNPRINTF" = x"yes"; then AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf]) fi dnl VA_COPY -AC_CACHE_CHECK([for va_copy],samba_cv_HAVE_VA_COPY,[ +AC_CACHE_CHECK([for va_copy],libreplace_cv_HAVE_VA_COPY,[ AC_TRY_LINK([#include <stdarg.h> va_list ap1,ap2;], [va_copy(ap1,ap2);], -samba_cv_HAVE_VA_COPY=yes,samba_cv_HAVE_VA_COPY=no)]) -if test x"$samba_cv_HAVE_VA_COPY" = x"yes"; then +libreplace_cv_HAVE_VA_COPY=yes,libreplace_cv_HAVE_VA_COPY=no)]) +if test x"$libreplace_cv_HAVE_VA_COPY" = x"yes"; then AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available]) fi -if test x"$samba_cv_HAVE_VA_COPY" != x"yes"; then -AC_CACHE_CHECK([for __va_copy],samba_cv_HAVE___VA_COPY,[ +if test x"$libreplace_cv_HAVE_VA_COPY" != x"yes"; then +AC_CACHE_CHECK([for __va_copy],libreplace_cv_HAVE___VA_COPY,[ AC_TRY_LINK([#include <stdarg.h> va_list ap1,ap2;], [__va_copy(ap1,ap2);], -samba_cv_HAVE___VA_COPY=yes,samba_cv_HAVE___VA_COPY=no)]) -if test x"$samba_cv_HAVE___VA_COPY" = x"yes"; then +libreplace_cv_HAVE___VA_COPY=yes,libreplace_cv_HAVE___VA_COPY=no)]) +if test x"$libreplace_cv_HAVE___VA_COPY" = x"yes"; then AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available]) fi fi dnl __FUNCTION__ macro -AC_CACHE_CHECK([for __FUNCTION__ macro],samba_cv_HAVE_FUNCTION_MACRO,[ +AC_CACHE_CHECK([for __FUNCTION__ macro],libreplace_cv_HAVE_FUNCTION_MACRO,[ AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);], -samba_cv_HAVE_FUNCTION_MACRO=yes,samba_cv_HAVE_FUNCTION_MACRO=no)]) -if test x"$samba_cv_HAVE_FUNCTION_MACRO" = x"yes"; then +libreplace_cv_HAVE_FUNCTION_MACRO=yes,libreplace_cv_HAVE_FUNCTION_MACRO=no)]) +if test x"$libreplace_cv_HAVE_FUNCTION_MACRO" = x"yes"; then AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro]) else dnl __func__ macro - AC_CACHE_CHECK([for __func__ macro],samba_cv_HAVE_func_MACRO,[ + AC_CACHE_CHECK([for __func__ macro],libreplace_cv_HAVE_func_MACRO,[ AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __func__);], - samba_cv_HAVE_func_MACRO=yes,samba_cv_HAVE_func_MACRO=no)]) - if test x"$samba_cv_HAVE_func_MACRO" = x"yes"; then + libreplace_cv_HAVE_func_MACRO=yes,libreplace_cv_HAVE_func_MACRO=no)]) + if test x"$libreplace_cv_HAVE_func_MACRO" = x"yes"; then AC_DEFINE(HAVE_func_MACRO,1,[Whether there is a __func__ macro]) fi fi @@ -302,7 +302,7 @@ eprintf("bla", "bar"); ], AC_DEFINE(HAVE__VA_ARGS__MACRO, 1, [Whether the __VA_ARGS__ macro is available])) -AC_CACHE_CHECK([for sig_atomic_t type],samba_cv_sig_atomic_t, [ +AC_CACHE_CHECK([for sig_atomic_t type],libreplace_cv_sig_atomic_t, [ AC_TRY_COMPILE([ #include <sys/types.h> #if STDC_HEADERS @@ -310,30 +310,30 @@ AC_CACHE_CHECK([for sig_atomic_t type],samba_cv_sig_atomic_t, [ #include <stddef.h> #endif #include <signal.h>],[sig_atomic_t i = 0], - samba_cv_sig_atomic_t=yes,samba_cv_sig_atomic_t=no)]) -if test x"$samba_cv_sig_atomic_t" = x"yes"; then + libreplace_cv_sig_atomic_t=yes,libreplace_cv_sig_atomic_t=no)]) +if test x"$libreplace_cv_sig_atomic_t" = x"yes"; then AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type]) fi -AC_CACHE_CHECK([for O_DIRECT flag to open(2)],samba_cv_HAVE_OPEN_O_DIRECT,[ +AC_CACHE_CHECK([for O_DIRECT flag to open(2)],libreplace_cv_HAVE_OPEN_O_DIRECT,[ AC_TRY_COMPILE([ #include <unistd.h> #ifdef HAVE_FCNTL_H #include <fcntl.h> #endif], [int fd = open("/dev/null", O_DIRECT);], -samba_cv_HAVE_OPEN_O_DIRECT=yes,samba_cv_HAVE_OPEN_O_DIRECT=no)]) -if test x"$samba_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then +libreplace_cv_HAVE_OPEN_O_DIRECT=yes,libreplace_cv_HAVE_OPEN_O_DIRECT=no)]) +if test x"$libreplace_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then AC_DEFINE(HAVE_OPEN_O_DIRECT,1,[Whether the open(2) accepts O_DIRECT]) fi dnl Check if the C compiler understands volatile (it should, being ANSI). -AC_CACHE_CHECK([that the C compiler understands volatile],samba_cv_volatile, [ +AC_CACHE_CHECK([that the C compiler understands volatile],libreplace_cv_volatile, [ AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0], - samba_cv_volatile=yes,samba_cv_volatile=no)]) -if test x"$samba_cv_volatile" = x"yes"; then + libreplace_cv_volatile=yes,libreplace_cv_volatile=no)]) +if test x"$libreplace_cv_volatile" = x"yes"; then AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile]) fi diff --git a/source4/lib/replace/libreplace_ld.m4 b/source4/lib/replace/libreplace_ld.m4 index 2aec698967..f0d10c1e3e 100644 --- a/source4/lib/replace/libreplace_ld.m4 +++ b/source4/lib/replace/libreplace_ld.m4 @@ -289,6 +289,9 @@ AC_DEFUN([AC_LIBREPLACE_RUNTIME_LIB_PATH_VAR], *linux*) LIB_PATH_VAR=LD_LIBRARY_PATH ;; + *netbsd*) + LIB_PATH_VAR=LD_LIBRARY_PATH + ;; *solaris*) LIB_PATH_VAR=LD_LIBRARY_PATH ;; diff --git a/source4/lib/replace/system/config.m4 b/source4/lib/replace/system/config.m4 index 1c05733126..66c2bd652a 100644 --- a/source4/lib/replace/system/config.m4 +++ b/source4/lib/replace/system/config.m4 @@ -18,7 +18,7 @@ AC_CHECK_HEADERS(sys/capability.h) case "$host_os" in *linux*) -AC_CACHE_CHECK([for broken RedHat 7.2 system header files],samba_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS,[ +AC_CACHE_CHECK([for broken RedHat 7.2 system header files],libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS,[ AC_TRY_COMPILE([ #ifdef HAVE_SYS_VFS_H #include <sys/vfs.h> @@ -29,14 +29,14 @@ AC_TRY_COMPILE([ ],[ int i; ], - samba_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS=no, - samba_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS=yes + libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS=no, + libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS=yes )]) -if test x"$samba_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS" = x"yes"; then +if test x"$libreplace_cv_BROKEN_REDHAT_7_SYSTEM_HEADERS" = x"yes"; then AC_DEFINE(BROKEN_REDHAT_7_SYSTEM_HEADERS,1,[Broken RedHat 7.2 system header files]) fi -AC_CACHE_CHECK([for broken RHEL5 sys/capability.h],samba_cv_BROKEN_RHEL5_SYS_CAP_HEADER,[ +AC_CACHE_CHECK([for broken RHEL5 sys/capability.h],libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER,[ AC_TRY_COMPILE([ #ifdef HAVE_SYS_CAPABILITY_H #include <sys/capability.h> @@ -45,10 +45,10 @@ AC_TRY_COMPILE([ ],[ __s8 i; ], - samba_cv_BROKEN_RHEL5_SYS_CAP_HEADER=no, - samba_cv_BROKEN_RHEL5_SYS_CAP_HEADER=yes + libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER=no, + libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER=yes )]) -if test x"$samba_cv_BROKEN_RHEL5_SYS_CAP_HEADER" = x"yes"; then +if test x"$libreplace_cv_BROKEN_RHEL5_SYS_CAP_HEADER" = x"yes"; then AC_DEFINE(BROKEN_RHEL5_SYS_CAP_HEADER,1,[Broken RHEL5 sys/capability.h]) fi ;; diff --git a/source4/lib/replace/system/network.h b/source4/lib/replace/system/network.h index 53bef66d48..d09e3f71f8 100644 --- a/source4/lib/replace/system/network.h +++ b/source4/lib/replace/system/network.h @@ -163,8 +163,15 @@ void rep_freeifaddrs(struct ifaddrs *); #endif #ifndef AI_ADDRCONFIG +/* + * logic copied from AI_NUMERICHOST + */ +#if defined(HAVE_STRUCT_ADDRINFO) && defined(HAVE_GETADDRINFO) +#define AI_ADDRCONFIG 0 +#else #define AI_ADDRCONFIG 0x0020 #endif +#endif #ifndef AI_NUMERICSERV /* diff --git a/source4/lib/samba3/config.mk b/source4/lib/samba3/config.mk index 705bdd4002..2d129c5f8c 100644 --- a/source4/lib/samba3/config.mk +++ b/source4/lib/samba3/config.mk @@ -1,19 +1,5 @@ ################################################ # Start SUBSYSTEM LIBSAMBA3 -[SUBSYSTEM::LIBSAMBA3] -PRIVATE_PROTO_HEADER = samba3_proto.h -PUBLIC_HEADERS = samba3.h -OBJ_FILES = tdbsam.o policy.o \ - idmap.o winsdb.o samba3.o group.o \ - registry.o secrets.o share_info.o -PRIVATE_DEPENDENCIES = LIBSAMBA-UTIL LIBTDB NDR_SECURITY \ - SMBPASSWD LIBSECURITY -PUBLIC_DEPENDENCIES = CREDENTIALS -# End SUBSYSTEM LIBSAMBA3 -################################################ - -################################################ -# Start SUBSYSTEM LIBSAMBA3 [SUBSYSTEM::SMBPASSWD] PRIVATE_PROTO_HEADER = samba3_smbpasswd_proto.h OBJ_FILES = smbpasswd.o diff --git a/source4/lib/samba3/group.c b/source4/lib/samba3/group.c deleted file mode 100644 index a0b4c15f0c..0000000000 --- a/source4/lib/samba3/group.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * RPC Pipe client / server routines - * Copyright (C) Andrew Tridgell 1992-2000, - * Copyright (C) Jean François Micouleau 1998-2001. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "includes.h" -#include "lib/samba3/samba3.h" -#include "lib/tdb/include/tdb.h" -#include "lib/util/util_tdb.h" -#include "system/filesys.h" -#include "libcli/security/security.h" - -#define DATABASE_VERSION_V1 1 /* native byte format. */ -#define DATABASE_VERSION_V2 2 /* le format. */ - -#define GROUP_PREFIX "UNIXGROUP/" - -/* Alias memberships are stored reverse, as memberships. The performance - * critical operation is to determine the aliases a SID is member of, not - * listing alias members. So we store a list of alias SIDs a SID is member of - * hanging of the member as key. - */ -#define MEMBEROF_PREFIX "MEMBEROF/" - -/**************************************************************************** - Open the group mapping tdb. -****************************************************************************/ -NTSTATUS samba3_read_grouptdb(const char *file, TALLOC_CTX *ctx, struct samba3_groupdb *db) -{ - int32_t vers_id; - TDB_DATA kbuf, dbuf, newkey; - int ret; - TDB_CONTEXT *tdb; - - tdb = tdb_open(file, 0, TDB_DEFAULT, O_RDONLY, 0600); - if (!tdb) { - DEBUG(0,("Failed to open group mapping database\n")); - return NT_STATUS_UNSUCCESSFUL; - } - - /* Cope with byte-reversed older versions of the db. */ - vers_id = tdb_fetch_int32(tdb, "INFO/version"); - if ((vers_id == DATABASE_VERSION_V1) || (IREV(vers_id) == DATABASE_VERSION_V1)) { - /* Written on a bigendian machine with old fetch_int code. Save as le. */ - vers_id = DATABASE_VERSION_V2; - } - - if (vers_id != DATABASE_VERSION_V2) { - DEBUG(0, ("Group database version mismatch: %d\n", vers_id)); - return NT_STATUS_UNSUCCESSFUL; - } - - db->groupmappings = NULL; - db->groupmap_count = 0; - db->aliases = NULL; - db->alias_count = 0; - - for (kbuf = tdb_firstkey(tdb); - kbuf.dptr; - newkey = tdb_nextkey(tdb, kbuf), free(kbuf.dptr), kbuf=newkey) { - struct samba3_groupmapping map; - const char *k = (const char *)kbuf.dptr; - - if (strncmp(k, GROUP_PREFIX, strlen(GROUP_PREFIX)) == 0) - { - dbuf = tdb_fetch(tdb, kbuf); - if (!dbuf.dptr) - continue; - - ZERO_STRUCT(map); - - map.sid = dom_sid_parse_talloc(ctx, k+strlen(GROUP_PREFIX)); - - ret = tdb_unpack(tdb, (char *)dbuf.dptr, dbuf.dsize, "dd", - &map.gid, &map.sid_name_use); - - if ( ret == -1 ) { - DEBUG(3,("enum_group_mapping: tdb_unpack failure\n")); - continue; - } - - map.nt_name = talloc_strdup(ctx, (const char *)(dbuf.dptr+ret)); - map.comment = talloc_strdup(ctx, (const char *)(dbuf.dptr+ret+strlen(map.nt_name))); - - db->groupmappings = talloc_realloc(ctx, db->groupmappings, struct samba3_groupmapping, db->groupmap_count+1); - - if (!db->groupmappings) - return NT_STATUS_NO_MEMORY; - - db->groupmappings[db->groupmap_count] = map; - - db->groupmap_count++; - } else if (strncmp(k, MEMBEROF_PREFIX, strlen(MEMBEROF_PREFIX)) == 0) - { - struct samba3_alias alias; - const char **member_strlist; - int i; - - dbuf = tdb_fetch(tdb, kbuf); - if (!dbuf.dptr) - continue; - - alias.sid = dom_sid_parse_talloc(ctx, k+strlen(MEMBEROF_PREFIX)); - alias.member_count = 0; - alias.members = NULL; - - member_strlist = str_list_make_shell(ctx, (const char *)dbuf.dptr, " "); - - for (i = 0; member_strlist[i]; i++) { - alias.members = talloc_realloc(ctx, alias.members, struct dom_sid *, alias.member_count+1); - alias.members[alias.member_count] = dom_sid_parse_talloc(ctx, member_strlist[i]); - alias.member_count++; - } - - talloc_free(member_strlist); - - db->aliases = talloc_realloc(ctx, db->aliases, struct samba3_alias, db->alias_count+1); - db->aliases[db->alias_count] = alias; - db->alias_count++; - } - } - - tdb_close(tdb); - - return NT_STATUS_OK; -} diff --git a/source4/lib/samba3/idmap.c b/source4/lib/samba3/idmap.c deleted file mode 100644 index 3eeb2931a8..0000000000 --- a/source4/lib/samba3/idmap.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - idmap TDB backend - - Copyright (C) Tim Potter 2000 - Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2003 - Copyright (C) Simo Sorce 2003 - Copyright (C) Jelmer Vernooij 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "includes.h" -#include "lib/tdb/include/tdb.h" -#include "lib/util/util_tdb.h" -#include "lib/samba3/samba3.h" -#include "system/filesys.h" -#include "libcli/security/security.h" - -/* High water mark keys */ -#define HWM_GROUP "GROUP HWM" -#define HWM_USER "USER HWM" - -/* idmap version determines auto-conversion */ -#define IDMAP_VERSION 2 - -/***************************************************************************** - Initialise idmap database. -*****************************************************************************/ - -NTSTATUS samba3_read_idmap(const char *fn, TALLOC_CTX *ctx, struct samba3_idmapdb *idmap) -{ - TDB_CONTEXT *tdb; - TDB_DATA key, val; - int32_t version; - - /* Open idmap repository */ - if (!(tdb = tdb_open(fn, 0, TDB_DEFAULT, O_RDONLY, 0644))) { - DEBUG(0, ("idmap_init: Unable to open idmap database '%s'\n", fn)); - return NT_STATUS_UNSUCCESSFUL; - } - - idmap->mapping_count = 0; - idmap->mappings = NULL; - idmap->user_hwm = tdb_fetch_int32(tdb, HWM_USER); - idmap->group_hwm = tdb_fetch_int32(tdb, HWM_GROUP); - - /* check against earlier versions */ - version = tdb_fetch_int32(tdb, "IDMAP_VERSION"); - if (version != IDMAP_VERSION) { - DEBUG(0, ("idmap_init: Unable to open idmap database, it's in an old format!\n")); - return NT_STATUS_INTERNAL_DB_ERROR; - } - - for (key = tdb_firstkey(tdb); key.dptr; key = tdb_nextkey(tdb, key)) - { - struct samba3_idmap_mapping map; - const char *k = (const char *)key.dptr; - const char *v; - - if (strncmp(k, "GID ", 4) == 0) { - map.type = IDMAP_GROUP; - map.unix_id = atoi(k+4); - val = tdb_fetch(tdb, key); - v = (const char *)val.dptr; - map.sid = dom_sid_parse_talloc(ctx, v); - } else if (strncmp(k, "UID ", 4) == 0) { - map.type = IDMAP_USER; - map.unix_id = atoi(k+4); - val = tdb_fetch(tdb, key); - v = (const char *)val.dptr; - map.sid = dom_sid_parse_talloc(ctx, v); - } else { - continue; - } - - idmap->mappings = talloc_realloc(ctx, idmap->mappings, struct samba3_idmap_mapping, idmap->mapping_count+1); - - idmap->mappings[idmap->mapping_count] = map; - idmap->mapping_count++; - } - - tdb_close(tdb); - - return NT_STATUS_OK; -} diff --git a/source4/lib/samba3/policy.c b/source4/lib/samba3/policy.c deleted file mode 100644 index 44944770c1..0000000000 --- a/source4/lib/samba3/policy.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * account policy storage - * Copyright (C) Jelmer Vernooij 2005 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "includes.h" -#include "lib/tdb/include/tdb.h" -#include "lib/util/util_tdb.h" -#include "lib/samba3/samba3.h" -#include "system/filesys.h" - -NTSTATUS samba3_read_account_policy(const char *fn, TALLOC_CTX *ctx, struct samba3_policy *ret) -{ - TDB_CONTEXT *tdb = tdb_open(fn, 0, TDB_DEFAULT, O_RDONLY, 0600); - if (!tdb) { - DEBUG(0,("Failed to open account policy database\n")); - return NT_STATUS_UNSUCCESSFUL; - } - - tdb_fetch_uint32(tdb, "min password length", &ret->min_password_length); - tdb_fetch_uint32(tdb, "password history", &ret->password_history); - tdb_fetch_uint32(tdb, "user must logon to change pasword", &ret->user_must_logon_to_change_password); - tdb_fetch_uint32(tdb, "maximum password age", &ret->maximum_password_age); - tdb_fetch_uint32(tdb, "minimum password age", &ret->minimum_password_age); - tdb_fetch_uint32(tdb, "lockout duration", &ret->lockout_duration); - tdb_fetch_uint32(tdb, "reset count minutes", &ret->reset_count_minutes); - tdb_fetch_uint32(tdb, "bad lockout minutes", &ret->bad_lockout_minutes); - tdb_fetch_uint32(tdb, "disconnect time", &ret->disconnect_time); - tdb_fetch_uint32(tdb, "refuse machine password change", &ret->refuse_machine_password_change); - - /* FIXME: Read privileges as well */ - - tdb_close(tdb); - - return NT_STATUS_OK; -} diff --git a/source4/lib/samba3/registry.c b/source4/lib/samba3/registry.c deleted file mode 100644 index 69197883b7..0000000000 --- a/source4/lib/samba3/registry.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * Virtual Windows Registry Layer - * Copyright (C) Gerald Carter 2002-2005 - * Copyright (C) Jelmer Vernooij 2005 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -/* Implementation of internal registry database functions. */ - -#include "includes.h" -#include "lib/samba3/samba3.h" -#include "librpc/gen_ndr/winreg.h" -#include "lib/tdb/include/tdb.h" -#include "lib/util/util_tdb.h" -#include "system/filesys.h" -#include "pstring.h" - -#define VALUE_PREFIX "SAMBA_REGVAL" -#define REGVER_V1 1 /* first db version with write support */ - -/**************************************************************************** - Unpack a list of registry values from the TDB - ***************************************************************************/ - -static int regdb_unpack_values(TDB_CONTEXT *tdb, TALLOC_CTX *ctx, struct samba3_regkey *key, TDB_DATA data ) -{ - int len = 0; - uint32_t type; - uint32_t size; - uint8_t *data_p; - uint32_t num_values = 0; - int i; - fstring valuename; - - /* loop and unpack the rest of the registry values */ - - len += tdb_unpack(tdb, (char *)data.dptr+len, data.dsize-len, "d", &num_values); - - for ( i=0; i<num_values; i++ ) { - struct samba3_regval val; - /* unpack the next regval */ - - type = REG_NONE; - size = 0; - data_p = NULL; - len += tdb_unpack(tdb, (char *)data.dptr+len, data.dsize-len, "fdB", - valuename, - &val.type, - &size, - &data_p); - val.name = talloc_strdup(ctx, valuename); - val.data = data_blob_talloc(ctx, data_p, size); - - key->values = talloc_realloc(ctx, key->values, struct samba3_regval, key->value_count+1); - key->values[key->value_count] = val; - key->value_count++; - } - - return len; -} - - - -/*********************************************************************** - Open the registry database - ***********************************************************************/ - -NTSTATUS samba3_read_regdb ( const char *fn, TALLOC_CTX *ctx, struct samba3_regdb *db ) -{ - uint32_t vers_id; - TDB_CONTEXT *tdb; - TDB_DATA kbuf, vbuf; - - /* placeholder tdb; reinit upon startup */ - - if ( !(tdb = tdb_open(fn, 0, TDB_DEFAULT, O_RDONLY, 0600)) ) - { - DEBUG(0, ("Unable to open registry database %s\n", fn)); - return NT_STATUS_UNSUCCESSFUL; - } - - vers_id = tdb_fetch_int32(tdb, "INFO/version"); - - db->key_count = 0; - db->keys = NULL; - - if (vers_id != -1 && vers_id >= REGVER_V1) { - DEBUG(0, ("Registry version mismatch: %d\n", vers_id)); - return NT_STATUS_UNSUCCESSFUL; - } - - for (kbuf = tdb_firstkey(tdb); kbuf.dptr; kbuf = tdb_nextkey(tdb, kbuf)) - { - uint32_t len; - int i; - struct samba3_regkey key; - char *skey; - - if (strncmp((char *)kbuf.dptr, VALUE_PREFIX, strlen(VALUE_PREFIX)) == 0) - continue; - - vbuf = tdb_fetch(tdb, kbuf); - - key.name = talloc_strdup(ctx, (char *)kbuf.dptr); - - len = tdb_unpack(tdb, (char *)vbuf.dptr, vbuf.dsize, "d", &key.subkey_count); - - key.value_count = 0; - key.values = NULL; - key.subkeys = talloc_array(ctx, char *, key.subkey_count); - - for (i = 0; i < key.subkey_count; i++) { - fstring tmp; - len += tdb_unpack( tdb, (char *)vbuf.dptr+len, vbuf.dsize-len, "f", tmp ); - key.subkeys[i] = talloc_strdup(ctx, tmp); - } - - skey = talloc_asprintf(ctx, "%s/%s", VALUE_PREFIX, kbuf.dptr ); - - vbuf = tdb_fetch_bystring( tdb, skey ); - - if ( vbuf.dptr ) { - regdb_unpack_values( tdb, ctx, &key, vbuf ); - } - - db->keys = talloc_realloc(ctx, db->keys, struct samba3_regkey, db->key_count+1); - db->keys[db->key_count] = key; - db->key_count++; - } - - tdb_close(tdb); - - return NT_STATUS_OK; -} diff --git a/source4/lib/samba3/samba3.c b/source4/lib/samba3/samba3.c deleted file mode 100644 index 4bd08f188a..0000000000 --- a/source4/lib/samba3/samba3.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * Copyright (C) Jelmer Vernooij 2005 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "includes.h" -#include "lib/samba3/samba3.h" - -struct samba3_domainsecrets *samba3_find_domainsecrets(struct samba3 *db, const char *name) -{ - int i; - - for (i = 0; i < db->secrets.domain_count; i++) { - if (!strcasecmp_m(db->secrets.domains[i].name, name)) - return &db->secrets.domains[i]; - } - - return NULL; -} - -NTSTATUS samba3_read_passdb_backends(TALLOC_CTX *ctx, const char *libdir, struct samba3 *samba3) -{ - char *dbfile; - NTSTATUS status = NT_STATUS_OK; - int i; - const char **backends = param_get_string_list(samba3->configuration, "passdb backend", NULL, NULL); - - /* Default to smbpasswd */ - if (backends == NULL) - backends = str_list_make(ctx, "smbpasswd", LIST_SEP); - else - backends = str_list_copy(ctx, backends); - - - for (i = 0; backends[i]; i++) { - if (!strncmp(backends[i], "tdbsam", strlen("tdbsam"))) { - const char *p = strchr(backends[i], ':'); - if (p && p[1]) { - dbfile = talloc_strdup(ctx, p+1); - } else { - dbfile = talloc_asprintf(ctx, "%s/passdb.tdb", libdir); - } - samba3_read_tdbsam(dbfile, ctx, &samba3->samaccounts, &samba3->samaccount_count); - talloc_free(dbfile); - } else if (!strncmp(backends[i], "smbpasswd", strlen("smbpasswd"))) { - const char *p = strchr(backends[i], ':'); - if (p && p[1]) { - dbfile = talloc_strdup(ctx, p+1); - } else if ((p = param_get_string(samba3->configuration, "smb passwd file", NULL))) { - dbfile = talloc_strdup(ctx, p); - } else { - dbfile = talloc_strdup(ctx, "/etc/samba/smbpasswd"); - } - - samba3_read_smbpasswd(dbfile, ctx, &samba3->samaccounts, &samba3->samaccount_count); - talloc_free(dbfile); - } else if (!strncmp(backends[i], "ldapsam", strlen("ldapsam"))) { - /* Will use samba3sam mapping module */ - } else { - DEBUG(0, ("Upgrade from %s database not supported", backends[i])); - status = NT_STATUS_NOT_SUPPORTED; - continue; - } - } - - talloc_free(backends); - - return status; -} - -NTSTATUS samba3_read(const char *libdir, const char *smbconf, TALLOC_CTX *ctx, struct samba3 **samba3) -{ - struct samba3 *ret; - char *dbfile = NULL; - - ret = talloc_zero(ctx, struct samba3); - - if (smbconf != NULL) { - ret->configuration = param_init(ret); - if (param_read(ret->configuration, smbconf) == -1) { - talloc_free(ret); - return NT_STATUS_UNSUCCESSFUL; - } - } - - dbfile = talloc_asprintf(ctx, "%s/account_policy.tdb", libdir); - samba3_read_account_policy(dbfile, ctx, &ret->policy); - talloc_free(dbfile); - - dbfile = talloc_asprintf(ctx, "%s/registry.tdb", libdir); - samba3_read_regdb(dbfile, ctx, &ret->registry); - talloc_free(dbfile); - - dbfile = talloc_asprintf(ctx, "%s/secrets.tdb", libdir); - samba3_read_secrets(dbfile, ctx, &ret->secrets); - talloc_free(dbfile); - - dbfile = talloc_asprintf(ctx, "%s/share_info.tdb", libdir); - samba3_read_share_info(dbfile, ctx, ret); - talloc_free(dbfile); - - dbfile = talloc_asprintf(ctx, "%s/winbindd_idmap.tdb", libdir); - samba3_read_idmap(dbfile, ctx, &ret->idmap); - talloc_free(dbfile); - - dbfile = talloc_asprintf(ctx, "%s/wins.dat", libdir); - samba3_read_winsdb(dbfile, ret, &ret->winsdb_entries, &ret->winsdb_count); - talloc_free(dbfile); - - samba3_read_passdb_backends(ctx, libdir, ret); - - dbfile = talloc_asprintf(ctx, "%s/group_mapping.tdb", libdir); - samba3_read_grouptdb(dbfile, ctx, &ret->group); - talloc_free(dbfile); - - *samba3 = ret; - - return NT_STATUS_OK; -} diff --git a/source4/lib/samba3/samba3.h b/source4/lib/samba3/samba3.h index 202ac767ec..aea87dac14 100644 --- a/source4/lib/samba3/samba3.h +++ b/source4/lib/samba3/samba3.h @@ -209,7 +209,6 @@ struct samba3 struct samba3_regdb registry; }; -#include "lib/samba3/samba3_proto.h" #include "lib/samba3/samba3_smbpasswd_proto.h" #endif /* _SAMBA3_H */ diff --git a/source4/lib/samba3/secrets.c b/source4/lib/samba3/secrets.c deleted file mode 100644 index cd1df991a4..0000000000 --- a/source4/lib/samba3/secrets.c +++ /dev/null @@ -1,263 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Copyright (C) Andrew Tridgell 1992-2001 - Copyright (C) Andrew Bartlett 2002 - Copyright (C) Rafal Szczesniak 2002 - Copyright (C) Tim Potter 2001 - Copyright (C) Jelmer Vernooij 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -/* the Samba secrets database stores any generated, private information - such as the local SID and machine trust password */ - -#include "includes.h" -#include "lib/tdb/include/tdb.h" -#include "lib/util/util_tdb.h" -#include "lib/samba3/samba3.h" -#include "system/filesys.h" -#include "librpc/gen_ndr/security.h" -#include "auth/credentials/credentials.h" - -/** - * Unpack SID into a pointer - * - * @param pack_buf pointer to buffer with packed representation - * @param bufsize size of the buffer - * @param sid pointer to sid structure to be filled with unpacked data - * - * @return size of structure unpacked from buffer - **/ -static size_t tdb_sid_unpack(TDB_CONTEXT *tdb, char* pack_buf, int bufsize, struct dom_sid* sid) -{ - int idx, len = 0; - - if (!sid || !pack_buf) return -1; - - len += tdb_unpack(tdb, pack_buf + len, bufsize - len, "bb", - &sid->sid_rev_num, &sid->num_auths); - - for (idx = 0; idx < 6; idx++) { - len += tdb_unpack(tdb, pack_buf + len, bufsize - len, "b", &sid->id_auth[idx]); - } - - for (idx = 0; idx < 15; idx++) { - len += tdb_unpack(tdb, pack_buf + len, bufsize - len, "d", &sid->sub_auths[idx]); - } - - return len; -} - -static struct samba3_domainsecrets *secrets_find_domain(TALLOC_CTX *ctx, struct samba3_secrets *db, const char *key) -{ - int i; - - for (i = 0; i < db->domain_count; i++) - { - if (!strcasecmp_m(db->domains[i].name, key)) - return &db->domains[i]; - } - - db->domains = talloc_realloc(ctx, db->domains, struct samba3_domainsecrets, db->domain_count+1); - ZERO_STRUCT(db->domains[db->domain_count]); - db->domains[db->domain_count].name = talloc_strdup(db->domains, key); - - db->domain_count++; - - return &db->domains[db->domain_count-1]; -} - -static NTSTATUS ipc_password (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db) -{ - cli_credentials_set_password(db->ipc_cred, (const char *)vbuf.dptr, CRED_SPECIFIED); - return NT_STATUS_OK; -} - -static NTSTATUS ipc_username (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db) -{ - cli_credentials_set_username(db->ipc_cred, (const char *)vbuf.dptr, CRED_SPECIFIED); - return NT_STATUS_OK; -} - -static NTSTATUS ipc_domain (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db) -{ - cli_credentials_set_domain(db->ipc_cred, (const char *)vbuf.dptr, CRED_SPECIFIED); - return NT_STATUS_OK; -} - -static NTSTATUS domain_sid (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db) -{ - struct samba3_domainsecrets *domainsec = secrets_find_domain(ctx, db, key); - domainsec->sid.sub_auths = talloc_array(ctx, uint32_t, 15); - tdb_sid_unpack(tdb, (char *)vbuf.dptr, vbuf.dsize, &domainsec->sid); - return NT_STATUS_OK; -} - -static NTSTATUS domain_guid (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db) -{ - struct samba3_domainsecrets *domainsec = secrets_find_domain(ctx, db, key); - memcpy(&domainsec->guid, vbuf.dptr, vbuf.dsize); - return NT_STATUS_OK; -} - -static NTSTATUS ldap_bind_pw (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db) -{ - struct samba3_ldappw pw; - pw.dn = talloc_strdup(ctx, key); - pw.password = talloc_strdup(ctx, (const char *)vbuf.dptr); - - db->ldappws = talloc_realloc(ctx, db->ldappws, struct samba3_ldappw, db->ldappw_count+1); - db->ldappws[db->ldappw_count] = pw; - db->ldappw_count++; - return NT_STATUS_OK; -} - -static NTSTATUS afs_keyfile (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db) -{ - struct samba3_afs_keyfile keyfile; - memcpy(&keyfile, vbuf.dptr, vbuf.dsize); - keyfile.cell = talloc_strdup(ctx, key); - - db->afs_keyfiles = talloc_realloc(ctx, db->afs_keyfiles, struct samba3_afs_keyfile, db->afs_keyfile_count+1); - db->afs_keyfiles[db->afs_keyfile_count] = keyfile; - db->afs_keyfile_count++; - - return NT_STATUS_OK; -} - -static NTSTATUS machine_sec_channel_type (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db) -{ - struct samba3_domainsecrets *domainsec = secrets_find_domain(ctx, db, key); - - domainsec->sec_channel_type = IVAL(vbuf.dptr, 0); - return NT_STATUS_OK; -} - -static NTSTATUS machine_last_change_time (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db) -{ - struct samba3_domainsecrets *domainsec = secrets_find_domain(ctx, db, key); - domainsec->last_change_time = IVAL(vbuf.dptr, 0); - return NT_STATUS_OK; -} - -static NTSTATUS machine_password (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db) -{ - struct samba3_domainsecrets *domainsec = secrets_find_domain(ctx, db, key); - domainsec->plaintext_pw = talloc_strdup(ctx, (const char *)vbuf.dptr); - return NT_STATUS_OK; -} - -static NTSTATUS machine_acc (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db) -{ - struct samba3_domainsecrets *domainsec = secrets_find_domain(ctx, db, key); - - memcpy(&domainsec->hash_pw, vbuf.dptr, vbuf.dsize); - - return NT_STATUS_OK; -} - -static NTSTATUS random_seed (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db) -{ - /* Ignore */ - return NT_STATUS_OK; -} - -static NTSTATUS domtrust_acc (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db) -{ - int idx, len = 0; - struct samba3_trusted_dom_pass pass; - int pass_len; - - if (!vbuf.dptr) - return NT_STATUS_UNSUCCESSFUL; - - /* unpack unicode domain name and plaintext password */ - len += tdb_unpack(tdb, (char *)vbuf.dptr, vbuf.dsize - len, "d", &pass.uni_name_len); - - for (idx = 0; idx < 32; idx++) - len += tdb_unpack(tdb, (char *)(vbuf.dptr + len), vbuf.dsize - len, "w", &pass.uni_name[idx]); - - len += tdb_unpack(tdb, (char *)(vbuf.dptr + len), vbuf.dsize - len, "d", &pass_len); - pass.pass = talloc_strdup(ctx, (char *)(vbuf.dptr+len)); - len += strlen((const char *)vbuf.dptr)+1; - len += tdb_unpack(tdb, (char *)(vbuf.dptr + len), vbuf.dsize - len, "d", &pass.mod_time); - - pass.domain_sid.sub_auths = talloc_array(ctx, uint32_t, 15); - /* unpack domain sid */ - len += tdb_sid_unpack(tdb, (char *)(vbuf.dptr + len), vbuf.dsize - len, &pass.domain_sid); - - /* FIXME: Add to list */ - - return NT_STATUS_OK; -} - -static const struct { - const char *prefix; - NTSTATUS (*handler) (TDB_CONTEXT *tdb, const char *key, TDB_DATA vbuf, TALLOC_CTX *ctx, struct samba3_secrets *db); -} secrets_handlers[] = { - { "SECRETS/AUTH_PASSWORD", ipc_password }, - { "SECRETS/AUTH_DOMAIN", ipc_domain }, - { "SECRETS/AUTH_USER", ipc_username }, - { "SECRETS/SID/", domain_sid }, - { "SECRETS/DOMGUID/", domain_guid }, - { "SECRETS/LDAP_BIND_PW/", ldap_bind_pw }, - { "SECRETS/AFS_KEYFILE/", afs_keyfile }, - { "SECRETS/MACHINE_SEC_CHANNEL_TYPE/", machine_sec_channel_type }, - { "SECRETS/MACHINE_LAST_CHANGE_TIME/", machine_last_change_time }, - { "SECRETS/MACHINE_PASSWORD/", machine_password }, - { "SECRETS/$MACHINE.ACC/", machine_acc }, - { "SECRETS/$DOMTRUST.ACC/", domtrust_acc }, - { "INFO/random_seed", random_seed }, -}; - - -NTSTATUS samba3_read_secrets(const char *fname, TALLOC_CTX *ctx, struct samba3_secrets *db) -{ - TDB_CONTEXT *tdb = tdb_open(fname, 0, TDB_DEFAULT, O_RDONLY, 0600); - TDB_DATA kbuf, vbuf; - - if (!tdb) { - DEBUG(0,("Failed to open %s\n", fname)); - return NT_STATUS_UNSUCCESSFUL; - } - - ZERO_STRUCTP(db); - - db->ipc_cred = cli_credentials_init(ctx); - - for (kbuf = tdb_firstkey(tdb); kbuf.dptr; kbuf = tdb_nextkey(tdb, kbuf)) - { - int i; - char *key; - vbuf = tdb_fetch(tdb, kbuf); - - for (i = 0; secrets_handlers[i].prefix; i++) { - if (!strncmp((const char *)kbuf.dptr, secrets_handlers[i].prefix, strlen(secrets_handlers[i].prefix))) { - key = talloc_strndup(ctx, (const char *)(kbuf.dptr+strlen(secrets_handlers[i].prefix)), kbuf.dsize-strlen(secrets_handlers[i].prefix)); - secrets_handlers[i].handler(tdb, key, vbuf, ctx, db); - talloc_free(key); - break; - } - } - - if (!secrets_handlers[i].prefix) { - DEBUG(0, ("Unable to find handler for string %s\n", kbuf.dptr)); - } - } - - tdb_close(tdb); - - return NT_STATUS_OK; -} diff --git a/source4/lib/samba3/share_info.c b/source4/lib/samba3/share_info.c deleted file mode 100644 index 4dd15aa918..0000000000 --- a/source4/lib/samba3/share_info.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * Share Info parsing - * Copyright (C) Andrew Tridgell 1992-1997, - * Copyright (C) Jeremy Allison 2001. - * Copyright (C) Nigel Williams 2001. - * Copyright (C) Jelmer Vernooij 2005. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see <http://www.gnu.org/licenses/>. - */ - -#include "includes.h" -#include "librpc/gen_ndr/ndr_security.h" -#include "lib/tdb/include/tdb.h" -#include "lib/util/util_tdb.h" -#include "lib/samba3/samba3.h" -#include "system/filesys.h" - -#define SHARE_DATABASE_VERSION_V1 1 -#define SHARE_DATABASE_VERSION_V2 2 /* version id in little endian. */ - -NTSTATUS samba3_read_share_info(const char *fn, TALLOC_CTX *ctx, struct samba3 *db) -{ - int32_t vers_id; - TDB_CONTEXT *tdb; - TDB_DATA kbuf, vbuf; - DATA_BLOB blob; - - tdb = tdb_open(fn, 0, TDB_DEFAULT, O_RDONLY, 0600); - if (!tdb) { - DEBUG(0,("Failed to open share info database %s (%s)\n", - fn, strerror(errno) )); - return NT_STATUS_UNSUCCESSFUL; - } - - /* Cope with byte-reversed older versions of the db. */ - vers_id = tdb_fetch_int32(tdb, "INFO/version"); - if ((vers_id == SHARE_DATABASE_VERSION_V1) || (IREV(vers_id) == SHARE_DATABASE_VERSION_V1)) { - /* Written on a bigendian machine with old fetch_int code. Save as le. */ - vers_id = SHARE_DATABASE_VERSION_V2; - } - - if (vers_id != SHARE_DATABASE_VERSION_V2) { - return NT_STATUS_UNSUCCESSFUL; - } - - for (kbuf = tdb_firstkey(tdb); kbuf.dptr; kbuf = tdb_nextkey(tdb, kbuf)) - { - struct ndr_pull *pull; - struct samba3_share_info *share; - char *name; - - if (strncmp((char *)kbuf.dptr, "SECDESC/", strlen("SECDESC/")) != 0) - continue; - - name = talloc_strndup(ctx, (char *)kbuf.dptr+strlen("SECDESC/"), kbuf.dsize-strlen("SECDESC/")); - - db->shares = talloc_realloc(db, db->shares, struct samba3_share_info, db->share_count+1); - share = &db->shares[db->share_count]; - db->share_count++; - - share->name = talloc_strdup(db, name); - - vbuf = tdb_fetch(tdb, kbuf); - blob.data = (uint8_t *)vbuf.dptr; - blob.length = vbuf.dsize; - - pull = ndr_pull_init_blob(&blob, ctx, lp_iconv_convenience(global_loadparm)); - - ndr_pull_security_descriptor(pull, NDR_SCALARS|NDR_BUFFERS, &share->secdesc); - - talloc_free(pull); - } - - tdb_close(tdb); - - return NT_STATUS_OK; -} diff --git a/source4/lib/samba3/smbpasswd.c b/source4/lib/samba3/smbpasswd.c index 39e2448b98..47c826f9df 100644 --- a/source4/lib/samba3/smbpasswd.c +++ b/source4/lib/samba3/smbpasswd.c @@ -204,142 +204,3 @@ char *smbpasswd_encode_acb_info(TALLOC_CTX *mem_ctx, uint16_t acb_info) return acct_str; } - -NTSTATUS samba3_read_smbpasswd(const char *filename, TALLOC_CTX *ctx, struct samba3_samaccount **accounts, uint32_t *count) -{ - int numlines; - char **lines; - int i; - - *count = 0; - *accounts = NULL; - - lines = file_lines_load(filename, &numlines, ctx); - - if (lines == NULL) { - DEBUG(0, ("Unable to load lines from %s\n", filename)); - return NT_STATUS_UNSUCCESSFUL; - } - - *accounts = talloc_array(ctx, struct samba3_samaccount, numlines); - - for (i = 0; i < numlines; i++) { - char *p = lines[i], *q; - uid_t uid; - struct samba3_samaccount *acc = &((*accounts)[*count]); - - if (p[0] == '\0' || p[0] == '#') - continue; - - ZERO_STRUCTP(acc); - - q = strchr(p, ':'); - if (!q) { - DEBUG(0, ("%s:%d: expected ':'\n", filename, i)); - continue; - } - - acc->username = talloc_strndup(ctx, p, PTR_DIFF(q, p)); - p = q+1; - - uid = atoi(p); - - /* uid is ignored here.. */ - - q = strchr(p, ':'); - if (!q) { - DEBUG(0, ("%s:%d: expected ':'\n", filename, i)); - continue; - } - p = q+1; - - if (strlen(p) < 33) { - DEBUG(0, ("%s:%d: expected 32 byte password blob\n", filename, i)); - continue; - } - - if (!strncmp(p, "NO PASSWORD", strlen("NO PASSWORD"))) { - acc->acct_ctrl |= ACB_PWNOTREQ; - } else if (p[0] == '*' || p[0] == 'X') { - /* No password set */ - } else { - struct samr_Password *pw = smbpasswd_gethexpwd(*accounts, p); - - if (!pw) { - DEBUG(0, ("%s:%d: Malformed LM pw entry\n", filename, i)); - continue; - } - - memcpy(acc->lm_pw.hash, pw, sizeof(*pw)); - } - - if (p[32] != ':') { - DEBUG(0, ("%s:%d: expected ':' after 32 byte password blob\n", filename, i)); - continue; - } - - p += 33; - - if (p[0] == '*' || p[0] == 'X') { - /* No password set */ - } else { - struct samr_Password *pw = smbpasswd_gethexpwd(*accounts, p); - - if (!pw) { - DEBUG(0, ("%s:%d: Malformed LM pw entry\n", filename, i)); - continue; - } - - memcpy(acc->nt_pw.hash, pw, sizeof(*pw)); - } - - if (p[32] != ':') { - DEBUG(0, ("%s:%d: expected ':' after 32 byte password blob\n", filename, i)); - continue; - } - - p += 33; - - if (p[0] == '[') { - q = strchr(p, ']'); - if (!q) { - DEBUG(0, ("%s:%d: expected ']'\n", filename, i)); - continue; - } - - acc->acct_ctrl |= smbpasswd_decode_acb_info(p); - - p = q+1; - if (p[0] == ':' && strncmp(p, "LCT-", 4) == 0) { - int j; - p += 4; - - for(j = 0; j < 8; j++) { - if(p[j] == '\0' || !isxdigit(p[j])) { - break; - } - } - if(i == 8) { - acc->pass_last_set_time = (time_t)strtol((char *)p, NULL, 16); - } - } - } else { - /* 'Old' style file. Fake up based on user name. */ - /* - * Currently trust accounts are kept in the same - * password file as 'normal accounts'. If this changes - * we will have to fix this code. JRA. - */ - if(acc->username[strlen(acc->username) - 1] == '$') { - acc->acct_ctrl &= ~ACB_NORMAL; - acc->acct_ctrl |= ACB_WSTRUST; - } - } - - (*count)++; - } - - talloc_free(lines); - - return NT_STATUS_OK; -} diff --git a/source4/lib/samba3/tdbsam.c b/source4/lib/samba3/tdbsam.c deleted file mode 100644 index 8e6b0daf2b..0000000000 --- a/source4/lib/samba3/tdbsam.c +++ /dev/null @@ -1,263 +0,0 @@ -/* - Unix SMB/CIFS implementation. - tdb passdb backend format routines - - Copyright (C) Simo Sorce 2000-2003 - Copyright (C) Jelmer Vernooij 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "includes.h" -#include "system/filesys.h" -#include "lib/tdb/include/tdb.h" -#include "lib/util/util_tdb.h" -#include "lib/samba3/samba3.h" - -#define TDB_FORMAT_STRING_V0 "ddddddBBBBBBBBBBBBddBBwdwdBwwd" -#define TDB_FORMAT_STRING_V1 "dddddddBBBBBBBBBBBBddBBwdwdBwwd" -#define TDB_FORMAT_STRING_V2 "dddddddBBBBBBBBBBBBddBBBwwdBwwd" -#define TDBSAM_VERSION_STRING "INFO/version" - -static bool init_sam_from_buffer_v0(TDB_CONTEXT *tdb, struct samba3_samaccount *sampass, TDB_DATA buf) -{ - uint32_t username_len, domain_len, nt_username_len, - dir_drive_len, unknown_str_len, munged_dial_len, - fullname_len, homedir_len, logon_script_len, - profile_path_len, acct_desc_len, workstations_len; - - uint32_t remove_me; - uint32_t len = 0; - uint32_t lm_pw_len, nt_pw_len, hourslen; - - if(sampass == NULL || buf.dptr == NULL) { - DEBUG(0, ("init_sam_from_buffer_v0: NULL parameters found!\n")); - return false; - } - - /* unpack the buffer into variables */ - len = tdb_unpack (tdb, (char *)buf.dptr, buf.dsize, TDB_FORMAT_STRING_V0, - &sampass->logon_time, /* d */ - &sampass->logoff_time, /* d */ - &sampass->kickoff_time, /* d */ - &sampass->pass_last_set_time, /* d */ - &sampass->pass_can_change_time, /* d */ - &sampass->pass_must_change_time, /* d */ - &username_len, &sampass->username, /* B */ - &domain_len, &sampass->domain, /* B */ - &nt_username_len, &sampass->nt_username, /* B */ - &fullname_len, &sampass->fullname, /* B */ - &homedir_len, &sampass->homedir, /* B */ - &dir_drive_len, &sampass->dir_drive, /* B */ - &logon_script_len, &sampass->logon_script, /* B */ - &profile_path_len, &sampass->profile_path, /* B */ - &acct_desc_len, &sampass->acct_desc, /* B */ - &workstations_len, &sampass->workstations, /* B */ - &unknown_str_len, &sampass->unknown_str, /* B */ - &munged_dial_len, &sampass->munged_dial, /* B */ - &sampass->user_rid, /* d */ - &sampass->group_rid, /* d */ - &lm_pw_len, sampass->lm_pw.hash, /* B */ - &nt_pw_len, sampass->nt_pw.hash, /* B */ - &sampass->acct_ctrl, /* w */ - &remove_me, /* remove on the next TDB_FORMAT upgarde */ /* d */ - &sampass->logon_divs, /* w */ - &sampass->hours_len, /* d */ - &hourslen, &sampass->hours, /* B */ - &sampass->bad_password_count, /* w */ - &sampass->logon_count, /* w */ - &sampass->unknown_6); /* d */ - - if (len == (uint32_t) -1) { - return false; - } - - return true; -} - -static bool init_sam_from_buffer_v1(TDB_CONTEXT *tdb, struct samba3_samaccount *sampass, TDB_DATA buf) -{ - uint32_t username_len, domain_len, nt_username_len, - dir_drive_len, unknown_str_len, munged_dial_len, - fullname_len, homedir_len, logon_script_len, - profile_path_len, acct_desc_len, workstations_len; - - uint32_t remove_me; - uint32_t len = 0; - uint32_t lm_pw_len, nt_pw_len, hourslen; - - if(sampass == NULL || buf.dptr == NULL) { - DEBUG(0, ("init_sam_from_buffer_v1: NULL parameters found!\n")); - return false; - } - - /* unpack the buffer into variables */ - len = tdb_unpack (tdb, (char *)buf.dptr, buf.dsize, TDB_FORMAT_STRING_V1, - &sampass->logon_time, /* d */ - &sampass->logoff_time, /* d */ - &sampass->kickoff_time, /* d */ - /* Change from V0 is addition of bad_password_time field. */ - &sampass->bad_password_time, /* d */ - &sampass->pass_last_set_time, /* d */ - &sampass->pass_can_change_time, /* d */ - &sampass->pass_must_change_time, /* d */ - &username_len, &sampass->username, /* B */ - &domain_len, &sampass->domain, /* B */ - &nt_username_len, &sampass->nt_username, /* B */ - &fullname_len, &sampass->fullname, /* B */ - &homedir_len, &sampass->homedir, /* B */ - &dir_drive_len, &sampass->dir_drive, /* B */ - &logon_script_len, &sampass->logon_script, /* B */ - &profile_path_len, &sampass->profile_path, /* B */ - &acct_desc_len, &sampass->acct_desc, /* B */ - &workstations_len, &sampass->workstations, /* B */ - &unknown_str_len, &sampass->unknown_str, /* B */ - &munged_dial_len, &sampass->munged_dial, /* B */ - &sampass->user_rid, /* d */ - &sampass->group_rid, /* d */ - &lm_pw_len, sampass->lm_pw.hash, /* B */ - &nt_pw_len, sampass->nt_pw.hash, /* B */ - &sampass->acct_ctrl, /* w */ - &remove_me, /* d */ - &sampass->logon_divs, /* w */ - &sampass->hours_len, /* d */ - &hourslen, &sampass->hours, /* B */ - &sampass->bad_password_count, /* w */ - &sampass->logon_count, /* w */ - &sampass->unknown_6); /* d */ - - if (len == (uint32_t) -1) { - return false; - } - - return true; -} - -static bool init_sam_from_buffer_v2(TDB_CONTEXT *tdb, struct samba3_samaccount *sampass, TDB_DATA buf) -{ - uint32_t username_len, domain_len, nt_username_len, - dir_drive_len, unknown_str_len, munged_dial_len, - fullname_len, homedir_len, logon_script_len, - profile_path_len, acct_desc_len, workstations_len; - - uint32_t len = 0; - uint32_t lm_pw_len, nt_pw_len, nt_pw_hist_len, hourslen; - - if(sampass == NULL || buf.dptr == NULL) { - DEBUG(0, ("init_sam_from_buffer_v2: NULL parameters found!\n")); - return false; - } - - /* unpack the buffer into variables */ - len = tdb_unpack (tdb, (char *)buf.dptr, buf.dsize, TDB_FORMAT_STRING_V2, - &sampass->logon_time, /* d */ - &sampass->logoff_time, /* d */ - &sampass->kickoff_time, /* d */ - &sampass->bad_password_time, /* d */ - &sampass->pass_last_set_time, /* d */ - &sampass->pass_can_change_time, /* d */ - &sampass->pass_must_change_time, /* d */ - &username_len, &sampass->username, /* B */ - &domain_len, &sampass->domain, /* B */ - &nt_username_len, &sampass->nt_username, /* B */ - &fullname_len, &sampass->fullname, /* B */ - &homedir_len, &sampass->homedir, /* B */ - &dir_drive_len, &sampass->dir_drive, /* B */ - &logon_script_len, &sampass->logon_script, /* B */ - &profile_path_len, &sampass->profile_path, /* B */ - &acct_desc_len, &sampass->acct_desc, /* B */ - &workstations_len, &sampass->workstations, /* B */ - &unknown_str_len, &sampass->unknown_str, /* B */ - &munged_dial_len, &sampass->munged_dial, /* B */ - &sampass->user_rid, /* d */ - &sampass->group_rid, /* d */ - &lm_pw_len, sampass->lm_pw.hash, /* B */ - &nt_pw_len, sampass->nt_pw.hash, /* B */ - /* Change from V1 is addition of password history field. */ - &nt_pw_hist_len, &sampass->nt_pw_hist_ptr, /* B */ - &sampass->acct_ctrl, /* w */ - /* Also "remove_me" field was removed. */ - &sampass->logon_divs, /* w */ - &sampass->hours_len, /* d */ - &hourslen, &sampass->hours, /* B */ - &sampass->bad_password_count, /* w */ - &sampass->logon_count, /* w */ - &sampass->unknown_6); /* d */ - - if (len == (uint32_t) -1) { - return false; - } - - return true; -} - -NTSTATUS samba3_read_tdbsam(const char *filename, TALLOC_CTX *ctx, struct samba3_samaccount **accounts, uint32_t *count) -{ - int32_t version; - TDB_CONTEXT *tdb; - TDB_DATA key, val; - - /* Try to open tdb passwd */ - if (!(tdb = tdb_open(filename, 0, TDB_DEFAULT, O_RDONLY, 0600))) { - DEBUG(0, ("Unable to open TDB passwd file '%s'\n", filename)); - return NT_STATUS_UNSUCCESSFUL; - } - - /* Check the version */ - version = tdb_fetch_int32(tdb, - TDBSAM_VERSION_STRING); - if (version == -1) - version = 0; /* Version not found, assume version 0 */ - - /* Compare the version */ - if (version > 2) { - /* Version more recent than the latest known */ - DEBUG(0, ("TDBSAM version unknown: %d\n", version)); - tdb_close(tdb); - return NT_STATUS_NOT_SUPPORTED; - } - - *accounts = NULL; - *count = 0; - - for (key = tdb_firstkey(tdb); key.dptr; key = tdb_nextkey(tdb, key)) - { - bool ret; - if (strncmp((const char *)key.dptr, "USER_", 5) != 0) - continue; - - val = tdb_fetch(tdb, key); - - *accounts = talloc_realloc(ctx, *accounts, struct samba3_samaccount, (*count)+1); - - switch (version) - { - case 0: ret = init_sam_from_buffer_v0(tdb, &(*accounts)[*count], val); break; - case 1: ret = init_sam_from_buffer_v1(tdb, &(*accounts)[*count], val); break; - case 2: ret = init_sam_from_buffer_v2(tdb, &(*accounts)[*count], val); break; - default: ret = false; break; - - } - - if (!ret) { - DEBUG(0, ("Unable to parse SAM account %s\n", key.dptr)); - } - - (*count)++; - } - - tdb_close(tdb); - - return NT_STATUS_OK; -} diff --git a/source4/lib/samba3/winsdb.c b/source4/lib/samba3/winsdb.c deleted file mode 100644 index 5bed3523ea..0000000000 --- a/source4/lib/samba3/winsdb.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Wins Database - - Copyright (C) Jeremy Allison 1994-2003 - Copyright (C) Jelmer Vernooij 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - -*/ - -#include "includes.h" -#include "system/filesys.h" -#include "lib/samba3/samba3.h" -#include "system/network.h" - -#define WINS_VERSION 1 - -NTSTATUS samba3_read_winsdb( const char *fn, TALLOC_CTX *ctx, struct samba3_winsdb_entry **entries, uint32_t *count ) -{ - XFILE *fp; - char *line; - - if((fp = x_fopen(fn,O_RDONLY,0)) == NULL) { - DEBUG(0,("initialise_wins: Can't open wins database file %s. Error was %s\n", - fn, strerror(errno) )); - return NT_STATUS_OPEN_FAILED; - } - - *count = 0; - *entries = NULL; - - while (!x_feof(fp)) { - struct samba3_winsdb_entry entry; - const char *name_str, *ttl_str, *nb_flags_str; - const char **args; - char *p; - int i; - unsigned int hash; - int version; - - /* Read a line from the wins.dat file. Strips whitespace - from the beginning and end of the line. */ - line = fgets_slash(NULL,8,fp); - if (!line) { - return NT_STATUS_UNEXPECTED_IO_ERROR; - } - - if (*line == '#') { - SAFE_FREE(line); - continue; - } - - if (strncmp(line,"VERSION ", 8) == 0) { - if (sscanf(line,"VERSION %d %u", &version, &hash) != 2 || - version != WINS_VERSION) { - DEBUG(0,("Discarding invalid wins.dat file [%s]\n",line)); - SAFE_FREE(line); - x_fclose(fp); - return NT_STATUS_REVISION_MISMATCH; - } - SAFE_FREE(line); - - continue; - } - - args = str_list_make_shell(ctx, line, NULL); - - /* - * Now we handle multiple IP addresses per name we need - * to iterate over the line twice. The first time to - * determine how many IP addresses there are, the second - * time to actually parse them into the ip_list array. - */ - - name_str = args[0]; - if (!name_str) { - DEBUG(0,("initialise_wins: Failed to parse name when parsing line %s\n", line )); - SAFE_FREE(line); - continue; - } - - ttl_str = args[1]; - if (!ttl_str) { - DEBUG(0,("initialise_wins: Failed to parse time to live when parsing line %s\n", line )); - SAFE_FREE(line); - continue; - } - - /* - * Determine the number of IP addresses per line. - */ - entry.ip_count = 0; - for (i = 2; args[i] && strchr(args[i], '.'); i++) entry.ip_count++; - - if(entry.ip_count == 0) { - DEBUG(0,("initialise_wins: Missing IP address when parsing line %s\n", line )); - SAFE_FREE(line); - continue; - } - - /* Allocate the space for the ip_list. */ - if((entry.ips = talloc_array ( ctx, struct in_addr, entry.ip_count)) == NULL) { - DEBUG(0,("initialise_wins: Malloc fail !\n")); - SAFE_FREE(line); - return NT_STATUS_NO_MEMORY; - } - - /* Reset and re-parse the line. */ - for(i = 0; i < entry.ip_count; i++) { - entry.ips[i] = interpret_addr2(args[i+2]); - } - nb_flags_str = args[2 + entry.ip_count]; - - SMB_ASSERT(nb_flags_str); - - /* - * Deal with SELF or REGISTER name encoding. Default is REGISTER - * for compatibility with old nmbds. - */ - - if(nb_flags_str[strlen(nb_flags_str)-1] == 'S') { - DEBUG(5,("initialise_wins: Ignoring SELF name %s\n", line)); - talloc_free(entry.ips); - SAFE_FREE(line); - continue; - } - - /* Netbios name. # divides the name from the type (hex): netbios#xx */ - entry.name = talloc_strdup(ctx, name_str); - - if((p = strchr(entry.name,'#')) != NULL) { - *p = 0; - sscanf(p+1,"%x",&entry.type); - } - - /* Decode the netbios flags (hex) and the time-to-live (in seconds). */ - sscanf(nb_flags_str,"%x",&entry.nb_flags); - entry.ttl = atol(ttl_str); - - *entries = talloc_realloc(ctx, *entries, struct samba3_winsdb_entry, (*count)+1); - (*entries)[*count] = entry; - - (*count)++; - } - - x_fclose(fp); - return NT_STATUS_OK; -} diff --git a/source4/lib/socket/config.mk b/source4/lib/socket/config.mk index fe64c90b81..5a7a62d8ae 100644 --- a/source4/lib/socket/config.mk +++ b/source4/lib/socket/config.mk @@ -13,7 +13,7 @@ PRIVATE_DEPENDENCIES = LIBSAMBA-UTIL EXT_SOCKET EXT_NSL # Start MODULE socket_ip [MODULE::socket_ip] SUBSYSTEM = samba-socket -OUTPUT_TYPE = INTEGRATED +OUTPUT_TYPE = MERGED_OBJ OBJ_FILES = \ socket_ip.o PRIVATE_DEPENDENCIES = EXT_SOCKET EXT_NSL LIBSAMBA-ERRORS @@ -24,7 +24,7 @@ PRIVATE_DEPENDENCIES = EXT_SOCKET EXT_NSL LIBSAMBA-ERRORS # Start MODULE socket_unix [MODULE::socket_unix] SUBSYSTEM = samba-socket -OUTPUT_TYPE = INTEGRATED +OUTPUT_TYPE = MERGED_OBJ OBJ_FILES = \ socket_unix.o PRIVATE_DEPENDENCIES = EXT_SOCKET EXT_NSL diff --git a/source4/lib/socket/socket_ip.c b/source4/lib/socket/socket_ip.c index e61b6d82fc..bca0aab924 100644 --- a/source4/lib/socket/socket_ip.c +++ b/source4/lib/socket/socket_ip.c @@ -540,7 +540,7 @@ static const struct socket_ops ipv4_ops = { .fn_get_fd = ip_get_fd }; -const struct socket_ops *socket_ipv4_ops(enum socket_type type) +_PUBLIC_ const struct socket_ops *socket_ipv4_ops(enum socket_type type) { return &ipv4_ops; } @@ -977,7 +977,7 @@ static const struct socket_ops ipv6_tcp_ops = { .fn_get_fd = ip_get_fd }; -const struct socket_ops *socket_ipv6_ops(enum socket_type type) +_PUBLIC_ const struct socket_ops *socket_ipv6_ops(enum socket_type type) { return &ipv6_tcp_ops; } diff --git a/source4/lib/socket/socket_unix.c b/source4/lib/socket/socket_unix.c index cac4b8e913..af7d2bb79f 100644 --- a/source4/lib/socket/socket_unix.c +++ b/source4/lib/socket/socket_unix.c @@ -414,7 +414,7 @@ static const struct socket_ops unixdom_ops = { .fn_get_fd = unixdom_get_fd }; -const struct socket_ops *socket_unixdom_ops(enum socket_type type) +_PUBLIC_ const struct socket_ops *socket_unixdom_ops(enum socket_type type) { return &unixdom_ops; } diff --git a/source4/lib/socket_wrapper/config.m4 b/source4/lib/socket_wrapper/config.m4 index f3ffb895a9..8ff91075bb 100644 --- a/source4/lib/socket_wrapper/config.m4 +++ b/source4/lib/socket_wrapper/config.m4 @@ -20,3 +20,10 @@ fi AC_SUBST(DEFAULT_TEST_OPTIONS) AC_SUBST(HAVE_SOCKET_WRAPPER) AC_SUBST(SOCKET_WRAPPER_OBJS) + +# Look for the vdeplug library +AC_CHECK_HEADERS(libvdeplug.h) +if test x"$ac_cv_header_libvdeplug_h" = xyes; then + AC_DEFINE(HAVE_VDEPLUG, 1, [Whether the VDE plug library is available]) + SMB_EXT_LIB(VDEPLUG,[-lvdeplug],[],[],[]) +fi diff --git a/source4/lib/socket_wrapper/socket_wrapper.c b/source4/lib/socket_wrapper/socket_wrapper.c index 574d8ec5e4..644365a665 100644 --- a/source4/lib/socket_wrapper/socket_wrapper.c +++ b/source4/lib/socket_wrapper/socket_wrapper.c @@ -1,5 +1,5 @@ /* - * Copyright (C) Jelmer Vernooij 2005 <jelmer@samba.org> + * Copyright (C) Jelmer Vernooij 2005,2008 <jelmer@samba.org> * Copyright (C) Stefan Metzmacher 2006 <metze@samba.org> * * All rights reserved. @@ -212,7 +212,6 @@ struct socket_info static struct socket_info *sockets; - const char *socket_wrapper_dir(void) { const char *s = getenv("SOCKET_WRAPPER_DIR"); @@ -908,40 +907,31 @@ static int swrap_get_pcap_fd(const char *fname) return fd; } -static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *addr, - enum swrap_packet_type type, - const void *buf, size_t len) +static struct swrap_packet *swrap_marshall_packet(struct socket_info *si, + const struct sockaddr *addr, + enum swrap_packet_type type, + const void *buf, size_t len, + size_t *packet_len) { const struct sockaddr_in *src_addr; const struct sockaddr_in *dest_addr; - const char *file_name; unsigned long tcp_seq = 0; unsigned long tcp_ack = 0; unsigned char tcp_ctl = 0; int unreachable = 0; - struct timeval tv; - struct swrap_packet *packet; - size_t packet_len = 0; - int fd; - file_name = socket_wrapper_pcap_file(); - if (!file_name) { - return; - } + struct timeval tv; switch (si->family) { case AF_INET: -#ifdef HAVE_IPV6 - case AF_INET6: -#endif break; default: - return; + return NULL; } switch (type) { case SWRAP_CONNECT_SEND: - if (si->type != SOCK_STREAM) return; + if (si->type != SOCK_STREAM) return NULL; src_addr = (const struct sockaddr_in *)si->myname; dest_addr = (const struct sockaddr_in *)addr; @@ -955,7 +945,7 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add break; case SWRAP_CONNECT_RECV: - if (si->type != SOCK_STREAM) return; + if (si->type != SOCK_STREAM) return NULL; dest_addr = (const struct sockaddr_in *)si->myname; src_addr = (const struct sockaddr_in *)addr; @@ -969,7 +959,7 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add break; case SWRAP_CONNECT_UNREACH: - if (si->type != SOCK_STREAM) return; + if (si->type != SOCK_STREAM) return NULL; dest_addr = (const struct sockaddr_in *)si->myname; src_addr = (const struct sockaddr_in *)addr; @@ -983,7 +973,7 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add break; case SWRAP_CONNECT_ACK: - if (si->type != SOCK_STREAM) return; + if (si->type != SOCK_STREAM) return NULL; src_addr = (const struct sockaddr_in *)si->myname; dest_addr = (const struct sockaddr_in *)addr; @@ -995,7 +985,7 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add break; case SWRAP_ACCEPT_SEND: - if (si->type != SOCK_STREAM) return; + if (si->type != SOCK_STREAM) return NULL; dest_addr = (const struct sockaddr_in *)si->myname; src_addr = (const struct sockaddr_in *)addr; @@ -1009,7 +999,7 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add break; case SWRAP_ACCEPT_RECV: - if (si->type != SOCK_STREAM) return; + if (si->type != SOCK_STREAM) return NULL; src_addr = (const struct sockaddr_in *)si->myname; dest_addr = (const struct sockaddr_in *)addr; @@ -1023,7 +1013,7 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add break; case SWRAP_ACCEPT_ACK: - if (si->type != SOCK_STREAM) return; + if (si->type != SOCK_STREAM) return NULL; dest_addr = (const struct sockaddr_in *)si->myname; src_addr = (const struct sockaddr_in *)addr; @@ -1051,10 +1041,9 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add src_addr = (const struct sockaddr_in *)si->peername; if (si->type == SOCK_DGRAM) { - swrap_dump_packet(si, si->peername, + return swrap_marshall_packet(si, si->peername, SWRAP_SENDTO_UNREACH, - buf, len); - return; + buf, len, packet_len); } tcp_seq = si->io.pck_rcv; @@ -1068,7 +1057,7 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add src_addr = (const struct sockaddr_in *)si->peername; if (si->type == SOCK_DGRAM) { - return; + return NULL; } tcp_seq = si->io.pck_rcv; @@ -1094,7 +1083,7 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add src_addr = (const struct sockaddr_in *)si->peername; if (si->type == SOCK_DGRAM) { - return; + return NULL; } tcp_seq = si->io.pck_rcv; @@ -1128,7 +1117,7 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add break; case SWRAP_CLOSE_SEND: - if (si->type != SOCK_STREAM) return; + if (si->type != SOCK_STREAM) return NULL; src_addr = (const struct sockaddr_in *)si->myname; dest_addr = (const struct sockaddr_in *)si->peername; @@ -1142,7 +1131,7 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add break; case SWRAP_CLOSE_RECV: - if (si->type != SOCK_STREAM) return; + if (si->type != SOCK_STREAM) return NULL; dest_addr = (const struct sockaddr_in *)si->myname; src_addr = (const struct sockaddr_in *)si->peername; @@ -1156,7 +1145,7 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add break; case SWRAP_CLOSE_ACK: - if (si->type != SOCK_STREAM) return; + if (si->type != SOCK_STREAM) return NULL; src_addr = (const struct sockaddr_in *)si->myname; dest_addr = (const struct sockaddr_in *)si->peername; @@ -1167,15 +1156,33 @@ static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *add break; default: - return; + return NULL; } swrapGetTimeOfDay(&tv); - packet = swrap_packet_init(&tv, src_addr, dest_addr, si->type, + return swrap_packet_init(&tv, src_addr, dest_addr, si->type, (const unsigned char *)buf, len, tcp_seq, tcp_ack, tcp_ctl, unreachable, - &packet_len); + packet_len); +} + +static void swrap_dump_packet(struct socket_info *si, + const struct sockaddr *addr, + enum swrap_packet_type type, + const void *buf, size_t len) +{ + const char *file_name; + struct swrap_packet *packet; + size_t packet_len = 0; + int fd; + + file_name = socket_wrapper_pcap_file(); + if (!file_name) { + return; + } + + packet = swrap_marshall_packet(si, addr, type, buf, len, &packet_len); if (!packet) { return; } diff --git a/source4/lib/talloc/Makefile.in b/source4/lib/talloc/Makefile.in index a33085f95b..07b8fd4ff0 100644 --- a/source4/lib/talloc/Makefile.in +++ b/source4/lib/talloc/Makefile.in @@ -19,71 +19,25 @@ PACKAGE_VERSION = @PACKAGE_VERSION@ SHLIBEXT = @SHLIBEXT@ SHLD = @SHLD@ SHLD_FLAGS = @SHLD_FLAGS@ +tallocdir = @tallocdir@ -.SUFFIXES: .c .o .3 .3.xml .xml .html +LIBOBJ = $(TALLOC_OBJ) @LIBREPLACEOBJ@ -LIBOBJ = @TALLOC_OBJ@ @LIBREPLACEOBJ@ +all:: showflags $(EXTRA_TARGETS) -SOLIB = libtalloc.$(SHLIBEXT).$(PACKAGE_VERSION) -SONAME = libtalloc.$(SHLIBEXT).1 +include $(tallocdir)/rules.mk +include $(tallocdir)/talloc.mk -.c.o: - $(CC) $(PICFLAG) -o $@ -c $< $(CFLAGS) +$(TALLOC_SOLIB): $(LIBOBJ) + $(SHLD) $(SHLD_FLAGS) -o $@ $(LIBOBJ) @SONAMEFLAG@$(TALLOC_SONAME) -all: showflags libtalloc.a $(SOLIB) testsuite $(EXTRA_TARGETS) +check: test -showflags: - @echo 'talloc will be compiled with flags:' - @echo ' CFLAGS = $(CFLAGS)' - @echo ' LIBS = $(LIBS)' +installcheck:: test install -testsuite: $(LIBOBJ) testsuite.o - $(CC) $(CFLAGS) -o testsuite testsuite.o $(LIBOBJ) $(LIBS) - -libtalloc.a: $(LIBOBJ) - ar -rv $@ $(LIBOBJ) - @-ranlib $@ - -$(SOLIB): $(LIBOBJ) - $(SHLD) $(SHLD_FLAGS) -o $@ $(LIBOBJ) @SONAMEFLAG@$(SONAME) - -install: all - ${INSTALLCMD} -d $(DESTDIR)$(libdir) - ${INSTALLCMD} -d $(DESTDIR)$(libdir)/pkgconfig - ${INSTALLCMD} -m 755 libtalloc.a $(DESTDIR)$(libdir) - ${INSTALLCMD} -m 755 $(SOLIB) $(DESTDIR)$(libdir) - ${INSTALLCMD} -d $(DESTDIR)${includedir} - ${INSTALLCMD} -m 644 $(srcdir)/talloc.h $(DESTDIR)$(includedir) - ${INSTALLCMD} -m 644 talloc.pc $(DESTDIR)$(libdir)/pkgconfig - if [ -f talloc.3 ];then ${INSTALLCMD} -d $(DESTDIR)$(mandir)/man3; fi - if [ -f talloc.3 ];then ${INSTALLCMD} -m 644 talloc.3 $(DESTDIR)$(mandir)/man3; fi - which swig >/dev/null 2>&1 && ${INSTALLCMD} -d $(DESTDIR)`swig -swiglib` || true - which swig >/dev/null 2>&1 && ${INSTALLCMD} -m 644 talloc.i $(DESTDIR)`swig -swiglib` || true - -doc: talloc.3 talloc.3.html - -.3.xml.3: - -test -z "$(XSLTPROC)" || $(XSLTPROC) --nonet -o $@ http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $< - -.xml.html: - -test -z "$(XSLTPROC)" || $(XSLTPROC) --nonet -o $@ http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl $< - -clean: - rm -f *~ $(LIBOBJ) $(SOLIB) libtalloc.a testsuite testsuite.o *.gc?? talloc.3 talloc.3.html - -test: testsuite - ./testsuite - -gcov: - gcov talloc.c - -installcheck: - $(MAKE) test - -distclean: clean - rm -f *~ */*~ +distclean:: clean rm -f Makefile rm -f config.log config.status config.h config.cache -realdistclean: distclean +realdistclean:: distclean rm -f configure config.h.in diff --git a/source4/lib/talloc/config.mk b/source4/lib/talloc/config.mk index 16b5063f87..af1b590c98 100644 --- a/source4/lib/talloc/config.mk +++ b/source4/lib/talloc/config.mk @@ -1,8 +1,6 @@ [LIBRARY::LIBTALLOC] -VERSION = 1.0.0 -SO_VERSION = 1 +OUTPUT_TYPE = STATIC_LIBRARY OBJ_FILES = talloc.o -PC_FILE = talloc.pc MANPAGE = talloc.3 CFLAGS = -Ilib/talloc PUBLIC_HEADERS = talloc.h diff --git a/source4/lib/talloc/configure.ac b/source4/lib/talloc/configure.ac index 7878d59300..4719aa04b5 100644 --- a/source4/lib/talloc/configure.ac +++ b/source4/lib/talloc/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ(2.50) -AC_INIT(talloc, 1.1.0) +AC_INIT(talloc, 1.2.0) AC_CONFIG_SRCDIR([talloc.c]) AC_SUBST(datarootdir) AC_CONFIG_HEADER(config.h) diff --git a/source4/lib/talloc/rules.mk b/source4/lib/talloc/rules.mk new file mode 100644 index 0000000000..6cee126529 --- /dev/null +++ b/source4/lib/talloc/rules.mk @@ -0,0 +1,18 @@ +.SUFFIXES: .c .o .3 .3.xml .xml .html + +showflags:: + @echo 'talloc will be compiled with flags:' + @echo ' CFLAGS = $(CFLAGS)' + @echo ' LIBS = $(LIBS)' + +.c.o: + $(CC) $(PICFLAG) -o $@ -c $< $(CFLAGS) + +.3.xml.3: + -test -z "$(XSLTPROC)" || $(XSLTPROC) --nonet -o $@ http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $< + +.xml.html: + -test -z "$(XSLTPROC)" || $(XSLTPROC) --nonet -o $@ http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl $< + +distclean:: + rm -f *~ */*~ diff --git a/source4/lib/talloc/talloc.c b/source4/lib/talloc/talloc.c index f9aefcd6de..12b85f5a65 100644 --- a/source4/lib/talloc/talloc.c +++ b/source4/lib/talloc/talloc.c @@ -60,6 +60,8 @@ #define TALLOC_MAGIC 0xe814ec70 #define TALLOC_FLAG_FREE 0x01 #define TALLOC_FLAG_LOOP 0x02 +#define TALLOC_FLAG_POOL 0x04 /* This is a talloc pool */ +#define TALLOC_FLAG_POOLMEM 0x08 /* This is allocated in a pool */ #define TALLOC_MAGIC_REFERENCE ((const char *)1) /* by default we abort when given a bad pointer (such as when talloc_free() is called @@ -109,6 +111,19 @@ struct talloc_chunk { const char *name; size_t size; unsigned flags; + + /* + * "pool" has dual use: + * + * For the talloc pool itself (i.e. TALLOC_FLAG_POOL is set), "pool" + * marks the end of the currently allocated area. + * + * For members of the pool (i.e. TALLOC_FLAG_POOLMEM is set), "pool" + * is a pointer to the struct talloc_chunk of the pool that it was + * allocated from. This way children can quickly find the pool to chew + * from. + */ + void *pool; }; /* 16 byte alignment seems to keep everyone happy */ @@ -200,12 +215,87 @@ const char *talloc_parent_name(const void *ptr) return tc? tc->name : NULL; } +/* + A pool carries an in-pool object count count in the first 16 bytes. + bytes. This is done to support talloc_steal() to a parent outside of the + pool. The count includes the pool itself, so a talloc_free() on a pool will + only destroy the pool if the count has dropped to zero. A talloc_free() of a + pool member will reduce the count, and eventually also call free(3) on the + pool memory. + + The object count is not put into "struct talloc_chunk" because it is only + relevant for talloc pools and the alignment to 16 bytes would increase the + memory footprint of each talloc chunk by those 16 bytes. +*/ + +#define TALLOC_POOL_HDR_SIZE 16 + +static unsigned int *talloc_pool_objectcount(struct talloc_chunk *tc) +{ + return (unsigned int *)((char *)tc + sizeof(struct talloc_chunk)); +} + +/* + Allocate from a pool +*/ + +static struct talloc_chunk *talloc_alloc_pool(struct talloc_chunk *parent, + size_t size) +{ + struct talloc_chunk *pool_ctx = NULL; + size_t space_left; + struct talloc_chunk *result; + size_t chunk_size; + + if (parent == NULL) { + return NULL; + } + + if (parent->flags & TALLOC_FLAG_POOL) { + pool_ctx = parent; + } + else if (parent->flags & TALLOC_FLAG_POOLMEM) { + pool_ctx = (struct talloc_chunk *)parent->pool; + } + + if (pool_ctx == NULL) { + return NULL; + } + + space_left = ((char *)pool_ctx + TC_HDR_SIZE + pool_ctx->size) + - ((char *)pool_ctx->pool); + + /* + * Align size to 16 bytes + */ + chunk_size = ((size + 15) & ~15); + + if (space_left < chunk_size) { + return NULL; + } + + result = (struct talloc_chunk *)pool_ctx->pool; + +#if defined(DEVELOPER) && defined(VALGRIND_MAKE_MEM_UNDEFINED) + VALGRIND_MAKE_MEM_UNDEFINED(result, size); +#endif + + pool_ctx->pool = (void *)((char *)result + chunk_size); + + result->flags = TALLOC_MAGIC | TALLOC_FLAG_POOLMEM; + result->pool = pool_ctx; + + *talloc_pool_objectcount(pool_ctx) += 1; + + return result; +} + /* Allocate a bit of memory as a child of an existing pointer */ static inline void *__talloc(const void *context, size_t size) { - struct talloc_chunk *tc; + struct talloc_chunk *tc = NULL; if (unlikely(context == NULL)) { context = null_context; @@ -215,11 +305,19 @@ static inline void *__talloc(const void *context, size_t size) return NULL; } - tc = (struct talloc_chunk *)malloc(TC_HDR_SIZE+size); - if (unlikely(tc == NULL)) return NULL; + if (context != NULL) { + tc = talloc_alloc_pool(talloc_chunk_from_ptr(context), + TC_HDR_SIZE+size); + } + + if (tc == NULL) { + tc = (struct talloc_chunk *)malloc(TC_HDR_SIZE+size); + if (unlikely(tc == NULL)) return NULL; + tc->flags = TALLOC_MAGIC; + tc->pool = NULL; + } tc->size = size; - tc->flags = TALLOC_MAGIC; tc->destructor = NULL; tc->child = NULL; tc->name = NULL; @@ -246,6 +344,33 @@ static inline void *__talloc(const void *context, size_t size) } /* + * Create a talloc pool + */ + +void *talloc_pool(const void *context, size_t size) +{ + void *result = __talloc(context, size + TALLOC_POOL_HDR_SIZE); + struct talloc_chunk *tc; + + if (unlikely(result == NULL)) { + return NULL; + } + + tc = talloc_chunk_from_ptr(result); + + tc->flags |= TALLOC_FLAG_POOL; + tc->pool = (char *)result + TALLOC_POOL_HDR_SIZE; + + *talloc_pool_objectcount(tc) = 1; + +#if defined(DEVELOPER) && defined(VALGRIND_MAKE_MEM_NOACCESS) + VALGRIND_MAKE_MEM_NOACCESS(tc->pool, size); +#endif + + return result; +} + +/* setup a destructor to be called on free of a pointer the destructor should return 0 on success, or -1 on failure. if the destructor fails then the free is failed, and the memory can @@ -420,7 +545,29 @@ static inline int _talloc_free(void *ptr) } tc->flags |= TALLOC_FLAG_FREE; - free(tc); + + if (tc->flags & (TALLOC_FLAG_POOL|TALLOC_FLAG_POOLMEM)) { + struct talloc_chunk *pool; + unsigned int *pool_object_count; + + pool = (tc->flags & TALLOC_FLAG_POOL) + ? tc : (struct talloc_chunk *)tc->pool; + + pool_object_count = talloc_pool_objectcount(pool); + + if (*pool_object_count == 0) { + TALLOC_ABORT("Pool object count zero!"); + } + + *pool_object_count -= 1; + + if (*pool_object_count == 0) { + free(pool); + } + } + else { + free(tc); + } return 0; } @@ -718,6 +865,15 @@ void talloc_free_children(void *ptr) talloc_steal(new_parent, child); } } + + if ((tc->flags & TALLOC_FLAG_POOL) + && (*talloc_pool_objectcount(tc) == 1)) { + tc->pool = ((char *)tc + TC_HDR_SIZE + TALLOC_POOL_HDR_SIZE); +#if defined(DEVELOPER) && defined(VALGRIND_MAKE_MEM_NOACCESS) + VALGRIND_MAKE_MEM_NOACCESS( + tc->pool, tc->size - TALLOC_POOL_HDR_SIZE); +#endif + } } /* @@ -769,6 +925,7 @@ void *_talloc_realloc(const void *context, void *ptr, size_t size, const char *n { struct talloc_chunk *tc; void *new_ptr; + bool malloced = false; /* size zero is equivalent to free() */ if (unlikely(size == 0)) { @@ -792,6 +949,12 @@ void *_talloc_realloc(const void *context, void *ptr, size_t size, const char *n return NULL; } + /* don't shrink if we have less than 1k to gain */ + if ((size < tc->size) && ((tc->size - size) < 1024)) { + tc->size = size; + return ptr; + } + /* by resetting magic we catch users of the old memory */ tc->flags |= TALLOC_FLAG_FREE; @@ -802,7 +965,24 @@ void *_talloc_realloc(const void *context, void *ptr, size_t size, const char *n free(tc); } #else - new_ptr = realloc(tc, size + TC_HDR_SIZE); + if (tc->flags & TALLOC_FLAG_POOLMEM) { + + new_ptr = talloc_alloc_pool(tc, size + TC_HDR_SIZE); + *talloc_pool_objectcount((struct talloc_chunk *) + (tc->pool)) -= 1; + + if (new_ptr == NULL) { + new_ptr = malloc(TC_HDR_SIZE+size); + malloced = true; + } + + if (new_ptr) { + memcpy(new_ptr, tc, MIN(tc->size,size) + TC_HDR_SIZE); + } + } + else { + new_ptr = realloc(tc, size + TC_HDR_SIZE); + } #endif if (unlikely(!new_ptr)) { tc->flags &= ~TALLOC_FLAG_FREE; @@ -810,7 +990,10 @@ void *_talloc_realloc(const void *context, void *ptr, size_t size, const char *n } tc = (struct talloc_chunk *)new_ptr; - tc->flags &= ~TALLOC_FLAG_FREE; + tc->flags &= ~TALLOC_FLAG_FREE; + if (malloced) { + tc->flags &= ~TALLOC_FLAG_POOLMEM; + } if (tc->parent) { tc->parent->child = tc; } diff --git a/source4/lib/talloc/talloc.h b/source4/lib/talloc/talloc.h index e103391681..5431971655 100644 --- a/source4/lib/talloc/talloc.h +++ b/source4/lib/talloc/talloc.h @@ -116,6 +116,7 @@ typedef void TALLOC_CTX; /* The following definitions come from talloc.c */ void *_talloc(const void *context, size_t size); +void *talloc_pool(const void *context, size_t size); void _talloc_set_destructor(const void *ptr, int (*destructor)(void *)); int talloc_increase_ref_count(const void *ptr); size_t talloc_reference_count(const void *ptr); diff --git a/source4/lib/talloc/talloc.mk b/source4/lib/talloc/talloc.mk new file mode 100644 index 0000000000..e1fe88c84b --- /dev/null +++ b/source4/lib/talloc/talloc.mk @@ -0,0 +1,37 @@ +TALLOC_OBJ = $(tallocdir)/talloc.o + +TALLOC_SOLIB = libtalloc.$(SHLIBEXT).$(PACKAGE_VERSION) +TALLOC_SONAME = libtalloc.$(SHLIBEXT).1 + +all:: libtalloc.a $(TALLOC_SOLIB) testsuite + +testsuite:: $(LIBOBJ) testsuite.o + $(CC) $(CFLAGS) -o testsuite testsuite.o $(LIBOBJ) $(LIBS) + +libtalloc.a: $(LIBOBJ) + ar -rv $@ $(LIBOBJ) + @-ranlib $@ + +install:: all + ${INSTALLCMD} -d $(DESTDIR)$(libdir) + ${INSTALLCMD} -d $(DESTDIR)$(libdir)/pkgconfig + ${INSTALLCMD} -m 755 libtalloc.a $(DESTDIR)$(libdir) + ${INSTALLCMD} -m 755 $(TALLOC_SOLIB) $(DESTDIR)$(libdir) + ${INSTALLCMD} -d $(DESTDIR)${includedir} + ${INSTALLCMD} -m 644 $(srcdir)/talloc.h $(DESTDIR)$(includedir) + ${INSTALLCMD} -m 644 talloc.pc $(DESTDIR)$(libdir)/pkgconfig + if [ -f talloc.3 ];then ${INSTALLCMD} -d $(DESTDIR)$(mandir)/man3; fi + if [ -f talloc.3 ];then ${INSTALLCMD} -m 644 talloc.3 $(DESTDIR)$(mandir)/man3; fi + which swig >/dev/null 2>&1 && ${INSTALLCMD} -d $(DESTDIR)`swig -swiglib` || true + which swig >/dev/null 2>&1 && ${INSTALLCMD} -m 644 talloc.i $(DESTDIR)`swig -swiglib` || true + +doc:: talloc.3 talloc.3.html + +clean:: + rm -f *~ $(LIBOBJ) $(TALLOC_SOLIB) libtalloc.a testsuite testsuite.o *.gc?? talloc.3 talloc.3.html + +test:: testsuite + ./testsuite + +gcov:: + gcov talloc.c diff --git a/source4/lib/talloc/testsuite.c b/source4/lib/talloc/testsuite.c index e16c91f8b9..fedbda95aa 100644 --- a/source4/lib/talloc/testsuite.c +++ b/source4/lib/talloc/testsuite.c @@ -813,6 +813,25 @@ static bool test_speed(void) talloc_free(ctx); + ctx = talloc_pool(NULL, 1024); + + tv = timeval_current(); + count = 0; + do { + void *p1, *p2, *p3; + for (i=0;i<loop;i++) { + p1 = talloc_size(ctx, loop % 100); + p2 = talloc_strdup(p1, "foo bar"); + p3 = talloc_size(p1, 300); + talloc_free_children(ctx); + } + count += 3 * loop; + } while (timeval_elapsed(&tv) < 5.0); + + talloc_free(ctx); + + fprintf(stderr, "talloc_pool: %.0f ops/sec\n", count/timeval_elapsed(&tv)); + tv = timeval_current(); count = 0; do { @@ -1066,6 +1085,23 @@ static bool test_autofree(void) return true; } +static bool test_pool(void) +{ + void *pool; + void *p1, *p2, *p3, *p4; + + pool = talloc_pool(NULL, 1024); + + p1 = talloc_size(pool, 80); + p2 = talloc_size(pool, 20); + p3 = talloc_size(p1, 50); + p4 = talloc_size(p3, 1000); + + talloc_free(pool); + + return true; +} + struct torture_context; bool torture_local_talloc(struct torture_context *tctx) { @@ -1094,6 +1130,7 @@ bool torture_local_talloc(struct torture_context *tctx) ret &= test_free_parent_deny_child(); ret &= test_talloc_ptrtype(); ret &= test_talloc_free_in_destructor(); + ret &= test_pool(); if (ret) { ret &= test_speed(); diff --git a/source4/lib/talloc/web/index.html b/source4/lib/talloc/web/index.html index 106920e8a5..628030ad4c 100644 --- a/source4/lib/talloc/web/index.html +++ b/source4/lib/talloc/web/index.html @@ -12,7 +12,7 @@ destructors. It is the core memory allocator used in Samba4, and has made a huge difference in many aspects of Samba4 development.<p> To get started with talloc, I would recommend you read the <a -href="http://samba.org/ftp/unpacked/samba4/source/lib/talloc/talloc_guide.txt">talloc guide</a>. +href="http://samba.org/ftp/unpacked/samba_4_0_test/source/lib/talloc/talloc_guide.txt">talloc guide</a>. <h2>Discussion and bug reports</h2> @@ -24,19 +24,20 @@ bugzilla</a> bug tracking system. <h2>Download</h2> -You can download the latest release either via rsync or anonymous -svn. To fetch via svn use the following command: +You can download the latest release either via rsync or git. +To fetch via git use the following command: <pre> - svn co svn://svnanon.samba.org/samba/branches/SAMBA_4_0/source/lib/talloc talloc - svn co svn://svnanon.samba.org/samba/branches/SAMBA_4_0/source/lib/replace libreplace + git-clone git://git.samba.org/samba.git samba + cd samba + git checkout -b samba4 origin/v4-0-test </pre> To fetch via rsync use this command: <pre> - rsync -Pavz samba.org::ftp/unpacked/samba4/source/lib/talloc . - rsync -Pavz samba.org::ftp/unpacked/samba4/source/lib/libreplace . + rsync -Pavz samba.org::ftp/unpacked/samba_4_0_test/source/lib/talloc . + rsync -Pavz samba.org::ftp/unpacked/samba_4_0_test/source/lib/libreplace . </pre> <hr> diff --git a/source4/lib/tdb/Makefile.in b/source4/lib/tdb/Makefile.in index c98d7e0497..090bb6e2dc 100644 --- a/source4/lib/tdb/Makefile.in +++ b/source4/lib/tdb/Makefile.in @@ -22,122 +22,38 @@ PACKAGE_VERSION = @PACKAGE_VERSION@ PICFLAG = @PICFLAG@ SHLIBEXT = @SHLIBEXT@ SWIG = swig - -.PHONY: test - -PROGS = bin/tdbtool$(EXEEXT) bin/tdbdump$(EXEEXT) bin/tdbbackup$(EXEEXT) -PROGS_NOINSTALL = bin/tdbtest$(EXEEXT) bin/tdbtorture$(EXEEXT) -ALL_PROGS = $(PROGS) $(PROGS_NOINSTALL) +PYTHON = @PYTHON@ +PYTHON_CONFIG = @PYTHON_CONFIG@ +PYTHON_BUILD_TARGET = @PYTHON_BUILD_TARGET@ +PYTHON_INSTALL_TARGET = @PYTHON_INSTALL_TARGET@ +PYTHON_CHECK_TARGET = @PYTHON_CHECK_TARGET@ +LIB_PATH_VAR = @LIB_PATH_VAR@ +tdbdir = @tdbdir@ TDB_OBJ = @TDB_OBJ@ @LIBREPLACEOBJ@ -DIRS = bin common tools - -SONAME = libtdb.$(SHLIBEXT).1 -SOLIB = libtdb.$(SHLIBEXT).$(PACKAGE_VERSION) - -all: showflags dirs $(PROGS) $(SOLIB) libtdb.a @PYTHON_BUILD_TARGET@ - -showflags: - @echo 'tdb will be compiled with flags:' - @echo ' CFLAGS = $(CFLAGS)' - @echo ' CPPFLAGS = $(CPPFLAGS)' - @echo ' LDFLAGS = $(LDFLAGS)' - @echo ' LIBS = $(LIBS)' - -.SUFFIXES: .c .o - -.c.o: - @echo Compiling $*.c - @mkdir -p `dirname $@` - @$(CC) $(PICFLAG) $(CFLAGS) -c $< -o $@ - -dirs: - @mkdir -p $(DIRS) - -install: all installdirs installbin installheaders installlibs @PYTHON_INSTALL_TARGET@ - -installdirs: - mkdir -p $(DESTDIR)$(bindir) - mkdir -p $(DESTDIR)$(includedir) - mkdir -p $(DESTDIR)$(libdir) - mkdir -p $(DESTDIR)$(libdir)/pkgconfig - -installbin: installdirs - cp $(PROGS) $(DESTDIR)$(bindir) - -installheaders: installdirs - cp $(srcdir)/include/tdb.h $(DESTDIR)$(includedir) - -installlibs: installdirs - cp tdb.pc $(DESTDIR)$(libdir)/pkgconfig - cp libtdb.a $(SOLIB) $(DESTDIR)$(libdir) - -libtdb.a: $(TDB_OBJ) - ar -rv libtdb.a $(TDB_OBJ) +default: all -libtdb.$(SHLIBEXT): $(SOLIB) - ln -fs $< $@ +include $(tdbdir)/tdb.mk +include $(tdbdir)/rules.mk -$(SONAME): $(SOLIB) - ln -fs $< $@ +all:: showflags dirs $(PROGS) $(TDB_SOLIB) libtdb.a $(PYTHON_BUILD_TARGET) -$(SOLIB): $(TDB_OBJ) - $(SHLD) $(SHLD_FLAGS) -o $@ $(TDB_OBJ) @SONAMEFLAG@$(SONAME) +install:: all +$(TDB_SOLIB): $(TDB_OBJ) + $(SHLD) $(SHLD_FLAGS) -o $@ $(TDB_OBJ) @SONAMEFLAG@$(TDB_SONAME) -TDB_LIB = libtdb.a +check: test -bin/tdbtest$(EXEEXT): tools/tdbtest.o $(TDB_LIB) - $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtest tools/tdbtest.o -L. -ltdb -lgdbm +test:: $(PYTHON_CHECK_TARGET) +installcheck:: test install -bin/tdbtool$(EXEEXT): tools/tdbtool.o $(TDB_LIB) - $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtool tools/tdbtool.o -L. -ltdb +clean:: + rm -f *.o *.a */*.o -bin/tdbtorture$(EXEEXT): tools/tdbtorture.o $(TDB_LIB) - $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtorture tools/tdbtorture.o -L. -ltdb - -bin/tdbdump$(EXEEXT): tools/tdbdump.o $(TDB_LIB) - $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbdump tools/tdbdump.o -L. -ltdb - -bin/tdbbackup$(EXEEXT): tools/tdbbackup.o $(TDB_LIB) - $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbbackup tools/tdbbackup.o -L. -ltdb - -test: bin/tdbtorture$(EXEEXT) - bin/tdbtorture$(EXEEXT) - -installcheck: test install - -clean: - rm -f $(ALL_PROGS) *.o *.a common/*.o tools/*.o tdb.pc - rm -f test.db test.tdb torture.tdb test.gdbm - rm -f $(SONAME) $(SOLIB) libtdb.a libtdb.$(SHLIBEXT) - -distclean: clean - rm -f *~ */*~ +distclean:: clean rm -f config.log config.status include/config.h config.cache rm -f Makefile -realdistclean: distclean +realdistclean:: distclean rm -f configure include/config.h.in - -.SUFFIXES: .i _wrap.c - -.i_wrap.c: - $(SWIG) -O -Wall -python -keyword $< - -build-python: libtdb.$(SHLIBEXT) tdb_wrap.c - ./setup.py build - -installpython: build-python - ./setup.py install --prefix=$(DESTDIR)$(prefix) - -check-python: build-python - # FIXME: Should be more portable: - LD_LIBRARY_PATH=. PYTHONPATH=.:build/lib.linux-i686-2.4 trial python/tests/simple.py - -install-swig: - mkdir -p $(DESTDIR)`$(SWIG) -swiglib` - cp tdb.i $(DESTDIR)`$(SWIG) -swiglib` - -clean-python: - ./setup.py clean diff --git a/source4/lib/tdb/config.mk b/source4/lib/tdb/config.mk index 820c55e363..89d6af9043 100644 --- a/source4/lib/tdb/config.mk +++ b/source4/lib/tdb/config.mk @@ -1,9 +1,7 @@ ################################################ # Start SUBSYSTEM LIBTDB [LIBRARY::LIBTDB] -VERSION = 0.0.1 -SO_VERSION = 0 -PC_FILE = tdb.pc +OUTPUT_TYPE = STATIC_LIBRARY OBJ_FILES = \ common/tdb.o common/dump.o common/io.o common/lock.o \ common/open.o common/traverse.o common/freelist.o \ diff --git a/source4/lib/tdb/configure.ac b/source4/lib/tdb/configure.ac index 5747107f38..9b16a82c33 100644 --- a/source4/lib/tdb/configure.ac +++ b/source4/lib/tdb/configure.ac @@ -11,15 +11,20 @@ AC_LD_PICFLAG AC_LD_SHLIBEXT AC_LIBREPLACE_SHLD AC_LIBREPLACE_SHLD_FLAGS +AC_LIBREPLACE_RUNTIME_LIB_PATH_VAR m4_include(libtdb.m4) 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_INSTALL_TARGET="" + PYTHON_CHECK_TARGET="" fi AC_OUTPUT(Makefile tdb.pc) diff --git a/source4/lib/tdb/python/tests/simple.py b/source4/lib/tdb/python/tests/simple.py index 1cc51aea07..94407b6398 100644 --- a/source4/lib/tdb/python/tests/simple.py +++ b/source4/lib/tdb/python/tests/simple.py @@ -142,3 +142,8 @@ class SimpleTdbTests(TestCase): self.assertEquals(0, len(self.tdb)) self.tdb["entry"] = "value" self.assertEquals(1, len(self.tdb)) + + +if __name__ == '__main__': + import unittest + unittest.TestProgram() diff --git a/source4/lib/tdb/rules.mk b/source4/lib/tdb/rules.mk new file mode 100644 index 0000000000..7b765625df --- /dev/null +++ b/source4/lib/tdb/rules.mk @@ -0,0 +1,21 @@ +.SUFFIXES: .i _wrap.c + +.i_wrap.c: + $(SWIG) -O -Wall -python -keyword $< + +showflags:: + @echo 'tdb will be compiled with flags:' + @echo ' CFLAGS = $(CFLAGS)' + @echo ' CPPFLAGS = $(CPPFLAGS)' + @echo ' LDFLAGS = $(LDFLAGS)' + @echo ' LIBS = $(LIBS)' + +.SUFFIXES: .c .o + +.c.o: + @echo Compiling $*.c + @mkdir -p `dirname $@` + @$(CC) $(PICFLAG) $(CFLAGS) -c $< -o $@ + +distclean:: + rm -f *~ */*~ diff --git a/source4/lib/tdb/setup.py b/source4/lib/tdb/setup.py deleted file mode 100755 index 8be0c67e0b..0000000000 --- a/source4/lib/tdb/setup.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/python -from distutils.core import setup -from distutils.extension import Extension - -setup(name='tdb', - version='1.0', - url="http://tdb.samba.org/", - py_modules=["tdb"], - ext_modules=[Extension('_tdb', ['tdb_wrap.c'], include_dirs=['include'], - library_dirs=["."], libraries=['tdb'])], -) diff --git a/source4/lib/tdb/tdb.mk b/source4/lib/tdb/tdb.mk new file mode 100644 index 0000000000..0e53927366 --- /dev/null +++ b/source4/lib/tdb/tdb.mk @@ -0,0 +1,86 @@ +dirs:: + @mkdir -p bin common tools + +PROGS = bin/tdbtool$(EXEEXT) bin/tdbdump$(EXEEXT) bin/tdbbackup$(EXEEXT) +PROGS_NOINSTALL = bin/tdbtest$(EXEEXT) bin/tdbtorture$(EXEEXT) +ALL_PROGS = $(PROGS) $(PROGS_NOINSTALL) + +TDB_SONAME = libtdb.$(SHLIBEXT).1 +TDB_SOLIB = libtdb.$(SHLIBEXT).$(PACKAGE_VERSION) + +TDB_LIB = libtdb.a + +bin/tdbtest$(EXEEXT): tools/tdbtest.o $(TDB_LIB) + $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtest tools/tdbtest.o -L. -ltdb -lgdbm + +bin/tdbtool$(EXEEXT): tools/tdbtool.o $(TDB_LIB) + $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtool tools/tdbtool.o -L. -ltdb + +bin/tdbtorture$(EXEEXT): tools/tdbtorture.o $(TDB_LIB) + $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbtorture tools/tdbtorture.o -L. -ltdb + +bin/tdbdump$(EXEEXT): tools/tdbdump.o $(TDB_LIB) + $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbdump tools/tdbdump.o -L. -ltdb + +bin/tdbbackup$(EXEEXT): tools/tdbbackup.o $(TDB_LIB) + $(CC) $(CFLAGS) $(LDFLAGS) -o bin/tdbbackup tools/tdbbackup.o -L. -ltdb + +test:: bin/tdbtorture$(EXEEXT) $(TDB_SONAME) + $(LIB_PATH_VAR)=. bin/tdbtorture$(EXEEXT) + +clean:: + rm -f test.db test.tdb torture.tdb test.gdbm + rm -f $(TDB_SONAME) $(TDB_SOLIB) libtdb.a libtdb.$(SHLIBEXT) + rm -f $(ALL_PROGS) tdb.pc + +build-python:: _tdb.$(SHLIBEXT) + +tdb_wrap.o: $(tdbdir)/tdb_wrap.c + $(CC) $(PICFLAG) -c $(tdbdir)/tdb_wrap.c $(CFLAGS) `$(PYTHON_CONFIG) --cflags` + +_tdb.$(SHLIBEXT): libtdb.$(SHLIBEXT) tdb_wrap.o + $(SHLD) $(SHLD_FLAGS) -o $@ tdb_wrap.o -L. -ltdb `$(PYTHON_CONFIG) --libs` + +install:: installdirs installbin installheaders installlibs \ + $(PYTHON_INSTALL_TARGET) + +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 $(tdbdir)/tdb.py $(DESTDIR)`$(PYTHON) -c "import distutils.sysconfig; print distutils.sysconfig.get_python_lib(0, prefix='$(prefix)')"` + cp _tdb.$(SHLIBEXT) $(DESTDIR)`$(PYTHON) -c "import distutils.sysconfig; print distutils.sysconfig.get_python_lib(1, prefix='$(prefix)')"` + +check-python:: build-python + $(LIB_PATH_VAR)=. PYTHONPATH=".:$(tdbdir)" $(PYTHON) $(tdbdir)/python/tests/simple.py + +install-swig:: + mkdir -p $(DESTDIR)`$(SWIG) -swiglib` + cp tdb.i $(DESTDIR)`$(SWIG) -swiglib` + +clean:: + rm -f _tdb.$(SHLIBEXT) + +installdirs:: + mkdir -p $(DESTDIR)$(bindir) + mkdir -p $(DESTDIR)$(includedir) + mkdir -p $(DESTDIR)$(libdir) + mkdir -p $(DESTDIR)$(libdir)/pkgconfig + +installbin:: all installdirs + cp $(PROGS) $(DESTDIR)$(bindir) + +installheaders:: installdirs + cp $(srcdir)/include/tdb.h $(DESTDIR)$(includedir) + +installlibs:: all installdirs + cp tdb.pc $(DESTDIR)$(libdir)/pkgconfig + cp libtdb.a $(TDB_SOLIB) $(DESTDIR)$(libdir) + +libtdb.a: $(TDB_OBJ) + ar -rv libtdb.a $(TDB_OBJ) + +libtdb.$(SHLIBEXT): $(TDB_SOLIB) + ln -fs $< $@ + +$(TDB_SONAME): $(TDB_SOLIB) + ln -fs $< $@ diff --git a/source4/lib/tls/config.m4 b/source4/lib/tls/config.m4 index 00d4194b3a..8b6ad7dcbc 100644 --- a/source4/lib/tls/config.m4 +++ b/source4/lib/tls/config.m4 @@ -1,7 +1,9 @@ ############################### # start SMB_EXT_LIB_GNUTLS # check for gnutls/gnutls.h and -lgnutls -SMB_EXT_LIB_FROM_PKGCONFIG(GNUTLS, gnutls) +SMB_EXT_LIB_FROM_PKGCONFIG(GNUTLS, gnutls, + [SMB_ENABLE_GNUTLS=YES], + [SMB_ENABLE_GNUTLS=NO]) if test x$SMB_ENABLE_GNUTLS = xNO; then AC_CHECK_HEADERS(gnutls/gnutls.h) diff --git a/source4/lib/util/attr.h b/source4/lib/util/attr.h index 8f6c4f5d8a..f64b272a67 100644 --- a/source4/lib/util/attr.h +++ b/source4/lib/util/attr.h @@ -29,13 +29,11 @@ /** Feel free to add definitions for other compilers here. */ #endif -#ifndef _PUBLIC_ #ifdef HAVE_VISIBILITY_ATTR # define _PUBLIC_ __attribute__((visibility("default"))) #else # define _PUBLIC_ #endif -#endif #ifndef _DEPRECATED_ #if (__GNUC__ >= 3) && (__GNUC_MINOR__ >= 1 ) diff --git a/source4/lib/util/fault.c b/source4/lib/util/fault.c index cd347a5ef9..cb51cbd859 100644 --- a/source4/lib/util/fault.c +++ b/source4/lib/util/fault.c @@ -178,7 +178,7 @@ _NORETURN_ static void sig_fault(int sig) /* we have a fault handler, call it. It may not return. */ fault_handlers.fault_handler(sig); } - /* If it returns or doean't exist, use regular reporter */ + /* If it returns or doesn't exist, use regular reporter */ fault_report(sig); } diff --git a/source4/lib/util/time.c b/source4/lib/util/time.c index fc51498009..a181885806 100644 --- a/source4/lib/util/time.c +++ b/source4/lib/util/time.c @@ -612,3 +612,11 @@ _PUBLIC_ int get_time_zone(time_t t) return 0; return tm_diff(&tm_utc,tm); } + +/** + check if 2 NTTIMEs are equal. +*/ +bool nt_time_equal(NTTIME *t1, NTTIME *t2) +{ + return *t1 == *t2; +} diff --git a/source4/lib/util/time.h b/source4/lib/util/time.h index 557c5d4eab..1ab976ca78 100644 --- a/source4/lib/util/time.h +++ b/source4/lib/util/time.h @@ -224,6 +224,9 @@ _PUBLIC_ void nttime_to_timeval(struct timeval *tv, NTTIME t); */ _PUBLIC_ int get_time_zone(time_t t); - +/** + check if 2 NTTIMEs are equal. +*/ +bool nt_time_equal(NTTIME *t1, NTTIME *t2); #endif /* _SAMBA_TIME_H_ */ diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index 9e106052f2..550b60c625 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -21,6 +21,8 @@ #ifndef _SAMBA_UTIL_H_ #define _SAMBA_UTIL_H_ +#include "util/attr.h" + #include "charset/charset.h" /* for TALLOC_CTX */ @@ -36,7 +38,6 @@ struct smbsrv_tcon; extern const char *logfile; extern const char *panic_action; -#include "util/attr.h" #include "util/time.h" #include "util/data_blob.h" #include "util/xfile.h" diff --git a/source4/lib/util/util_ldb.c b/source4/lib/util/util_ldb.c index a8719af190..f1b42effd8 100644 --- a/source4/lib/util/util_ldb.c +++ b/source4/lib/util/util_ldb.c @@ -1,21 +1,21 @@ -/* +/* Unix SMB/CIFS implementation. common share info functions Copyright (C) Andrew Tridgell 2004 Copyright (C) Tim Potter 2004 - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -56,7 +56,7 @@ int gendb_search_v(struct ldb_context *ldb, if (ret == LDB_SUCCESS) { talloc_steal(mem_ctx, res->msgs); - DEBUG(6,("gendb_search_v: %s %s -> %d\n", + DEBUG(6,("gendb_search_v: %s %s -> %d\n", basedn?ldb_dn_get_linearized(basedn):"NULL", expr?expr:"NULL", res->count)); @@ -67,7 +67,8 @@ int gendb_search_v(struct ldb_context *ldb, ret = 0; *msgs = NULL; } else { - DEBUG(4,("gendb_search_v: search failed: %s", ldb_errstring(ldb))); + DEBUG(4,("gendb_search_v: search failed: %s\n", + ldb_errstring(ldb))); ret = -1; } @@ -80,7 +81,7 @@ int gendb_search_v(struct ldb_context *ldb, search the LDB for the specified attributes - varargs variant */ int gendb_search(struct ldb_context *ldb, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, struct ldb_dn *basedn, struct ldb_message ***res, const char * const *attrs, @@ -101,7 +102,7 @@ int gendb_search(struct ldb_context *ldb, */ int gendb_search_dn(struct ldb_context *ldb, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, struct ldb_dn *dn, struct ldb_message ***res, const char * const *attrs) |