diff options
Diffstat (limited to 'source4/lib')
75 files changed, 1352 insertions, 941 deletions
diff --git a/source4/lib/events/config.mk b/source4/lib/events/config.mk index c07a21bc75..5c7e1b7210 100644 --- a/source4/lib/events/config.mk +++ b/source4/lib/events/config.mk @@ -3,5 +3,3 @@ PUBLIC_DEPENDENCIES = LIBTEVENT CFLAGS = -Ilib/events LIBEVENTS_OBJ_FILES = $(addprefix $(libeventssrcdir)/, tevent_s4.o) - -PUBLIC_HEADERS += $(addprefix $(libeventssrcdir)/, events.h) diff --git a/source4/lib/ldb-samba/ldif_handlers.c b/source4/lib/ldb-samba/ldif_handlers.c index 5ab31d771b..fc87e6ca7a 100644 --- a/source4/lib/ldb-samba/ldif_handlers.c +++ b/source4/lib/ldb-samba/ldif_handlers.c @@ -22,7 +22,8 @@ */ #include "includes.h" -#include "lib/ldb/include/ldb_includes.h" +#include "ldb_private.h" +#include "ldb_handlers.h" #include "dsdb/samdb/samdb.h" #include "librpc/gen_ndr/ndr_security.h" #include "librpc/gen_ndr/ndr_misc.h" @@ -365,7 +366,7 @@ static int ldif_canonicalise_objectCategory(struct ldb_context *ldb, void *mem_c { struct ldb_dn *dn1 = NULL; const struct dsdb_schema *schema = dsdb_get_schema(ldb); - const struct dsdb_class *class; + const struct dsdb_class *sclass; TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx); if (!tmp_ctx) { return LDB_ERR_OPERATIONS_ERROR; @@ -381,10 +382,10 @@ static int ldif_canonicalise_objectCategory(struct ldb_context *ldb, void *mem_c dn1 = ldb_dn_from_ldb_val(tmp_ctx, ldb, in); if ( ! ldb_dn_validate(dn1)) { const char *lDAPDisplayName = talloc_strndup(tmp_ctx, (char *)in->data, in->length); - class = dsdb_class_by_lDAPDisplayName(schema, lDAPDisplayName); - if (class) { + sclass = dsdb_class_by_lDAPDisplayName(schema, lDAPDisplayName); + if (sclass) { struct ldb_dn *dn = ldb_dn_new(mem_ctx, ldb, - class->defaultObjectCategory); + sclass->defaultObjectCategory); *out = data_blob_string_const(ldb_dn_alloc_casefold(mem_ctx, dn)); talloc_free(tmp_ctx); diff --git a/source4/lib/ldb/Makefile.in b/source4/lib/ldb/Makefile.in index 6313fc1622..7f00e8ebee 100644 --- a/source4/lib/ldb/Makefile.in +++ b/source4/lib/ldb/Makefile.in @@ -67,7 +67,7 @@ MDLD_FLAGS = @MDLD_FLAGS@ OBJS = $(MODULES_OBJ) $(COMMON_OBJ) $(LDB_TDB_OBJ) $(TDB_OBJ) $(TEVENT_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 +headers = $(srcdir)/include/ldb.h $(srcdir)/include/ldb_errors.h $(srcdir)/include/ldb_handlers.h $(srcdir)/include/ldb_includes.h $(srcdir)/include/ldb_module.h BINS = bin/ldbadd bin/ldbsearch bin/ldbdel bin/ldbmodify bin/ldbedit bin/ldbrename bin/ldbtest diff --git a/source4/lib/ldb/build_macros.m4 b/source4/lib/ldb/build_macros.m4 index c036668cd1..bb7fad8f7a 100644 --- a/source4/lib/ldb/build_macros.m4 +++ b/source4/lib/ldb/build_macros.m4 @@ -7,6 +7,7 @@ AC_DEFUN(BUILD_WITH_SHARED_BUILD_DIR, if test x"$with_shared_build_dir" != x; then sharedbuilddir=$with_shared_build_dir CFLAGS="$CFLAGS -I$with_shared_build_dir/include" + CPPFLAGS="$CPPFLAGS -I$with_shared_build_dir/include" LDFLAGS="$LDFLAGS -L$with_shared_build_dir/lib" fi AC_SUBST(sharedbuilddir) diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index 5ec86b5b8f..80725ec04f 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -25,7 +25,7 @@ see rfc2252 */ -#include "ldb_includes.h" +#include "ldb_private.h" #include "system/locale.h" #include "ldb_handlers.h" diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c index fe55d1499a..2fb5a8f9be 100644 --- a/source4/lib/ldb/common/ldb.c +++ b/source4/lib/ldb/common/ldb.c @@ -32,7 +32,7 @@ * Author: Andrew Tridgell */ -#include "ldb_includes.h" +#include "ldb_private.h" /* initialise a ldb context @@ -481,6 +481,11 @@ void ldb_set_create_perms(struct ldb_context *ldb, unsigned int perms) ldb->create_perms = perms; } +unsigned int ldb_get_create_perms(struct ldb_context *ldb) +{ + return ldb->create_perms; +} + void ldb_set_event_context(struct ldb_context *ldb, struct tevent_context *ev) { ldb->ev_ctx = ev; @@ -491,6 +496,16 @@ struct tevent_context * ldb_get_event_context(struct ldb_context *ldb) return ldb->ev_ctx; } +void ldb_request_set_state(struct ldb_request *req, int state) +{ + req->handle->state = state; +} + +int ldb_request_get_status(struct ldb_request *req) +{ + return req->handle->status; +} + /* start an ldb request NOTE: the request must be a talloc context. diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index 001bc45ee1..9fa0fb2ccd 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -28,7 +28,8 @@ message matching logic generic */ -#include "ldb_includes.h" +#include "ldb_private.h" +#include "ldb_handlers.h" /* add a attribute to the ldb_schema diff --git a/source4/lib/ldb/common/ldb_controls.c b/source4/lib/ldb/common/ldb_controls.c index 6fad5012b6..0c587e0905 100644 --- a/source4/lib/ldb/common/ldb_controls.c +++ b/source4/lib/ldb/common/ldb_controls.c @@ -31,7 +31,7 @@ * Author: Simo Sorce */ -#include "ldb_includes.h" +#include "ldb_private.h" /* check if a control with the specified "oid" exist and return it */ /* returns NULL if not found */ diff --git a/source4/lib/ldb/common/ldb_debug.c b/source4/lib/ldb/common/ldb_debug.c index 0f78e37c1c..f8009eb8a3 100644 --- a/source4/lib/ldb/common/ldb_debug.c +++ b/source4/lib/ldb/common/ldb_debug.c @@ -31,7 +31,7 @@ * Author: Andrew Tridgell */ -#include "ldb_includes.h" +#include "ldb_private.h" /* this allows the user to choose their own debug function diff --git a/source4/lib/ldb/common/ldb_dn.c b/source4/lib/ldb/common/ldb_dn.c index 02e21a2b25..402d629501 100644 --- a/source4/lib/ldb/common/ldb_dn.c +++ b/source4/lib/ldb/common/ldb_dn.c @@ -33,7 +33,7 @@ * Author: Simo Sorce */ -#include "ldb_includes.h" +#include "ldb_private.h" #include <ctype.h> #define LDB_DN_NULL_FAILED(x) if (!(x)) goto failed diff --git a/source4/lib/ldb/common/ldb_ldif.c b/source4/lib/ldb/common/ldb_ldif.c index 619c10e11e..400fb352ff 100644 --- a/source4/lib/ldb/common/ldb_ldif.c +++ b/source4/lib/ldb/common/ldb_ldif.c @@ -35,7 +35,7 @@ see RFC2849 for the LDIF format definition */ -#include "ldb_includes.h" +#include "ldb_private.h" #include "system/locale.h" /* diff --git a/source4/lib/ldb/common/ldb_match.c b/source4/lib/ldb/common/ldb_match.c index 4cde739d67..c622701d30 100644 --- a/source4/lib/ldb/common/ldb_match.c +++ b/source4/lib/ldb/common/ldb_match.c @@ -32,7 +32,7 @@ * Author: Andrew Tridgell */ -#include "ldb_includes.h" +#include "ldb_private.h" /* check if the scope matches in a search result diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c index 8db28d262c..99a47767e1 100644 --- a/source4/lib/ldb/common/ldb_modules.c +++ b/source4/lib/ldb/common/ldb_modules.c @@ -31,7 +31,7 @@ * Author: Simo Sorce */ -#include "ldb_includes.h" +#include "ldb_private.h" #if (_SAMBA_BUILD_ >= 4) #include "includes.h" @@ -486,6 +486,46 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[]) } while (0) +struct ldb_module *ldb_module_new(TALLOC_CTX *memctx, + struct ldb_context *ldb, + const char *module_name, + const struct ldb_module_ops *ops) +{ + struct ldb_module *module; + + module = talloc(memctx, struct ldb_module); + if (!module) { + ldb_oom(ldb); + return NULL; + } + talloc_set_name_const(module, module_name); + module->ldb = ldb; + module->prev = module->next = NULL; + module->ops = ops; + + return module; +} + +const char * ldb_module_get_name(struct ldb_module *module) +{ + return module->ops->name; +} + +struct ldb_context *ldb_module_get_ctx(struct ldb_module *module) +{ + return module->ldb; +} + +void *ldb_module_get_private(struct ldb_module *module) +{ + return module->private_data; +} + +void ldb_module_set_private(struct ldb_module *module, void *private_data) +{ + module->private_data = private_data; +} + /* helper functions to call the next module in chain */ diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c index 2f5fe1d18c..ad53a3d29d 100644 --- a/source4/lib/ldb/common/ldb_msg.c +++ b/source4/lib/ldb/common/ldb_msg.c @@ -31,7 +31,7 @@ * Author: Andrew Tridgell */ -#include "ldb_includes.h" +#include "ldb_private.h" /* create a new ldb_message in a given memory context (NULL for top level) diff --git a/source4/lib/ldb/common/ldb_parse.c b/source4/lib/ldb/common/ldb_parse.c index b233975220..654a635abf 100644 --- a/source4/lib/ldb/common/ldb_parse.c +++ b/source4/lib/ldb/common/ldb_parse.c @@ -40,7 +40,7 @@ */ -#include "ldb_includes.h" +#include "ldb_private.h" #include "system/locale.h" /* diff --git a/source4/lib/ldb/common/ldb_utf8.c b/source4/lib/ldb/common/ldb_utf8.c index 69ee2b6964..0a8a89ac1d 100644 --- a/source4/lib/ldb/common/ldb_utf8.c +++ b/source4/lib/ldb/common/ldb_utf8.c @@ -31,7 +31,7 @@ * Author: Andrew Tridgell */ -#include "ldb_includes.h" +#include "ldb_private.h" #include "system/locale.h" diff --git a/source4/lib/ldb/common/qsort.c b/source4/lib/ldb/common/qsort.c index 0fa76d3b47..1a0b886b8c 100644 --- a/source4/lib/ldb/common/qsort.c +++ b/source4/lib/ldb/common/qsort.c @@ -23,7 +23,7 @@ * Simo Sorce <idra@samba.org> 2005 */ -#include "ldb_includes.h" +#include "ldb_private.h" /* Byte-wise swap two items of size SIZE. */ #define SWAP(a, b, size) \ diff --git a/source4/lib/ldb/configure.ac b/source4/lib/ldb/configure.ac index 7bc081cfe5..d61b31afd4 100644 --- a/source4/lib/ldb/configure.ac +++ b/source4/lib/ldb/configure.ac @@ -11,7 +11,7 @@ AC_DEFUN([SMB_MODULE_DEFAULT], [echo -n ""]) AC_DEFUN([SMB_LIBRARY_ENABLE], [echo -n ""]) AC_DEFUN([SMB_EXT_LIB], [echo -n ""]) AC_DEFUN([SMB_ENABLE], [echo -n ""]) -AC_INIT(ldb, 0.9.2) +AC_INIT(ldb, 0.9.3) AC_CONFIG_SRCDIR([common/ldb.c]) AC_LIBREPLACE_ALL_CHECKS diff --git a/source4/lib/ldb/examples/ldbreader.c b/source4/lib/ldb/examples/ldbreader.c index e48b3d338a..3496baf4ce 100644 --- a/source4/lib/ldb/examples/ldbreader.c +++ b/source4/lib/ldb/examples/ldbreader.c @@ -29,9 +29,7 @@ It lists / dumps the records in a LDB database to standard output. */ -#include "ldb_includes.h" #include "ldb.h" -#include "ldb_errors.h" /* ldb_ldif_write takes a function pointer to a custom output diff --git a/source4/lib/ldb/examples/ldifreader.c b/source4/lib/ldb/examples/ldifreader.c index 12e7a1a6fd..dcd9daf812 100644 --- a/source4/lib/ldb/examples/ldifreader.c +++ b/source4/lib/ldb/examples/ldifreader.c @@ -29,9 +29,7 @@ It lists / dumps the entries in an LDIF file to standard output. */ -#include "ldb_includes.h" #include "ldb.h" -#include "ldb_errors.h" /* ldb_ldif_write takes a function pointer to a custom output diff --git a/source4/lib/ldb/external/libevents.m4 b/source4/lib/ldb/external/libevents.m4 index 24534f2c21..6a0e36af8b 100644 --- a/source4/lib/ldb/external/libevents.m4 +++ b/source4/lib/ldb/external/libevents.m4 @@ -3,5 +3,5 @@ AC_SUBST(TEVENT_CFLAGS) AC_SUBST(TEVENT_LIBS) AC_CHECK_HEADER(tevent.h, - [AC_CHECK_LIB(tevent, event_context_init, [TEVENT_LIBS="-ltevent"]) ], + [AC_CHECK_LIB(tevent, tevent_context_init, [TEVENT_LIBS="-ltevent"]) ], [PKG_CHECK_MODULES(TEVENT, tevent)]) diff --git a/source4/lib/ldb/include/dlinklist.h b/source4/lib/ldb/include/dlinklist.h index d3252751db..acab9fa043 100644 --- a/source4/lib/ldb/include/dlinklist.h +++ b/source4/lib/ldb/include/dlinklist.h @@ -20,6 +20,8 @@ /* To use these macros you must have a structure containing a next and prev pointer */ +#ifndef _DLINKLIST_H +#define _DLINKLIST_H /* hook into the front of the list */ #define DLIST_ADD(list, p) \ @@ -108,3 +110,5 @@ do { \ } \ } \ } while (0) + +#endif /* _DLINKLIST_H */ diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h index 28c54f5a3c..6990397a74 100644 --- a/source4/lib/ldb/include/ldb.h +++ b/source4/lib/ldb/include/ldb.h @@ -46,18 +46,18 @@ #define _LDB_H_ 1 /*! \endcond */ +#include "ldb_includes.h" + /* major restrictions as compared to normal LDAP: - - no async calls. - each record must have a unique key field - the key must be representable as a NULL terminated C string and may not contain a comma or braces major restrictions as compared to tdb: - - no explicit locking calls - UPDATE: we have transactions now, better than locking --SSS. + - no explicit locking calls, but we have transactions when using ldb_tdb */ @@ -695,6 +695,9 @@ enum ldb_sequence_type { LDB_SEQ_NEXT }; +#define LDB_SEQ_GLOBAL_SEQUENCE 0x01 +#define LDB_SEQ_TIMESTAMP_SEQUENCE 0x02 + struct ldb_seqnum_request { enum ldb_sequence_type type; }; @@ -1233,6 +1236,11 @@ int ldb_extended(struct ldb_context *ldb, struct ldb_result **res); /** + Obtain current/next database sequence number +*/ +int ldb_sequence_number(struct ldb_context *ldb, enum ldb_sequence_type type, uint64_t *seq_num); + +/** start a transaction */ int ldb_transaction_start(struct ldb_context *ldb); @@ -1633,6 +1641,8 @@ int ldb_msg_add_fmt(struct ldb_message *msg, */ int ldb_msg_element_compare(struct ldb_message_element *el1, struct ldb_message_element *el2); +int ldb_msg_element_compare_name(struct ldb_message_element *el1, + struct ldb_message_element *el2); /** Find elements in a message. @@ -1746,14 +1756,16 @@ const char **ldb_attr_list_copy(TALLOC_CTX *mem_ctx, const char * const *attrs); const char **ldb_attr_list_copy_add(TALLOC_CTX *mem_ctx, const char * const *attrs, const char *new_attr); int ldb_attr_in_list(const char * const *attrs, const char *attr); +int ldb_msg_rename_attr(struct ldb_message *msg, const char *attr, const char *replace); +int ldb_msg_copy_attr(struct ldb_message *msg, const char *attr, const char *replace); +void ldb_msg_remove_attr(struct ldb_message *msg, const char *attr); +void ldb_msg_remove_element(struct ldb_message *msg, struct ldb_message_element *el); + void ldb_parse_tree_attr_replace(struct ldb_parse_tree *tree, const char *attr, const char *replace); -int ldb_msg_rename_attr(struct ldb_message *msg, const char *attr, const char *replace); -int ldb_msg_copy_attr(struct ldb_message *msg, const char *attr, const char *replace); -void ldb_msg_remove_attr(struct ldb_message *msg, const char *attr); /** Convert a time structure to a string diff --git a/source4/lib/ldb/include/ldb_includes.h b/source4/lib/ldb/include/ldb_includes.h index 8356404409..a2927139c8 100644 --- a/source4/lib/ldb/include/ldb_includes.h +++ b/source4/lib/ldb/include/ldb_includes.h @@ -21,9 +21,7 @@ #include "system/time.h" #include <talloc.h> #include <tevent.h> -#include "ldb.h" #include "ldb_errors.h" -#include "ldb_private.h" #include "dlinklist.h" #endif /*_LDB_PRIVATE_INCLUDES_H_*/ diff --git a/source4/lib/ldb/include/ldb_module.h b/source4/lib/ldb/include/ldb_module.h new file mode 100644 index 0000000000..4e1019184d --- /dev/null +++ b/source4/lib/ldb/include/ldb_module.h @@ -0,0 +1,161 @@ +/* + ldb database library + + Copyright (C) Simo Sorce 2008 + + ** NOTE! The following LGPL license applies to the ldb + ** library. This does NOT imply that all of Samba is released + ** under the LGPL + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +/* + * Name: ldb + * + * Component: ldb module header + * + * Description: defines ldb modules structures and helpers + * + */ + +#ifndef _LDB_MODULE_H_ +#define _LDB_MODULE_H_ + +#include "ldb.h" + +struct ldb_context; +struct ldb_module; + +/* + these function pointers define the operations that a ldb module can intercept +*/ +struct ldb_module_ops { + const char *name; + int (*init_context) (struct ldb_module *); + int (*search)(struct ldb_module *, struct ldb_request *); /* search */ + int (*add)(struct ldb_module *, struct ldb_request *); /* add */ + int (*modify)(struct ldb_module *, struct ldb_request *); /* modify */ + int (*del)(struct ldb_module *, struct ldb_request *); /* delete */ + int (*rename)(struct ldb_module *, struct ldb_request *); /* rename */ + int (*request)(struct ldb_module *, struct ldb_request *); /* match any other operation */ + int (*extended)(struct ldb_module *, struct ldb_request *); /* extended operations */ + int (*start_transaction)(struct ldb_module *); + int (*end_transaction)(struct ldb_module *); + int (*del_transaction)(struct ldb_module *); + int (*sequence_number)(struct ldb_module *, struct ldb_request *); + void *private_data; +}; + + +/* The following definitions come from lib/ldb/common/ldb_debug.c */ +void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4); +void ldb_debug_set(struct ldb_context *ldb, enum ldb_debug_level level, + const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4); + +#define ldb_oom(ldb) ldb_debug_set(ldb, LDB_DEBUG_FATAL, "ldb out of memory at %s:%d\n", __FILE__, __LINE__) + +/* The following definitions come from lib/ldb/common/ldb.c */ + +void ldb_request_set_state(struct ldb_request *req, int state); +int ldb_request_get_status(struct ldb_request *req); + +unsigned int ldb_get_create_perms(struct ldb_context *ldb); + +const struct ldb_schema_syntax *ldb_standard_syntax_by_name(struct ldb_context *ldb, + const char *syntax); + +/* The following definitions come from lib/ldb/common/ldb_attributes.c */ + +int ldb_schema_attribute_add_with_syntax(struct ldb_context *ldb, + const char *name, + unsigned flags, + const struct ldb_schema_syntax *syntax); +int ldb_schema_attribute_add(struct ldb_context *ldb, + const char *name, + unsigned flags, + const char *syntax); +void ldb_schema_attribute_remove(struct ldb_context *ldb, const char *name); + +/* The following definitions come from lib/ldb/common/ldb_controls.c */ +struct ldb_control *get_control_from_list(struct ldb_control **controls, const char *oid); +int save_controls(struct ldb_control *exclude, struct ldb_request *req, struct ldb_control ***saver); +int check_critical_controls(struct ldb_control **controls); + +/* The following definitions come from lib/ldb/common/ldb_ldif.c */ +int ldb_should_b64_encode(const struct ldb_val *val); + +/* The following definitions come from lib/ldb/common/ldb_match.c */ +int ldb_match_msg(struct ldb_context *ldb, + const struct ldb_message *msg, + const struct ldb_parse_tree *tree, + struct ldb_dn *base, + enum ldb_scope scope); + +/* The following definitions come from lib/ldb/common/ldb_modules.c */ + +struct ldb_module *ldb_module_new(TALLOC_CTX *memctx, + struct ldb_context *ldb, + const char *module_name, + const struct ldb_module_ops *ops); + +const char * ldb_module_get_name(struct ldb_module *module); +struct ldb_context *ldb_module_get_ctx(struct ldb_module *module); +void *ldb_module_get_private(struct ldb_module *module); +void ldb_module_set_private(struct ldb_module *module, void *private_data); + +int ldb_next_request(struct ldb_module *module, struct ldb_request *request); +int ldb_next_start_trans(struct ldb_module *module); +int ldb_next_end_trans(struct ldb_module *module); +int ldb_next_del_trans(struct ldb_module *module); +int ldb_next_init(struct ldb_module *module); + +void ldb_set_errstring(struct ldb_context *ldb, const char *err_string); +void ldb_asprintf_errstring(struct ldb_context *ldb, const char *format, ...) PRINTF_ATTRIBUTE(2,3); +void ldb_reset_err_string(struct ldb_context *ldb); + +const char *ldb_default_modules_dir(void); + +int ldb_register_module(const struct ldb_module_ops *); + +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); + +int ldb_register_backend(const char *url_prefix, ldb_connect_fn); + +struct ldb_handle *ldb_handle_new(TALLOC_CTX *mem_ctx, struct ldb_context *ldb); + +int ldb_module_send_entry(struct ldb_request *req, + struct ldb_message *msg, + struct ldb_control **ctrls); + +int ldb_module_send_referral(struct ldb_request *req, + char *ref); + +int ldb_module_done(struct ldb_request *req, + struct ldb_control **ctrls, + struct ldb_extended *response, + int error); + +int ldb_mod_register_control(struct ldb_module *module, const char *oid); + +#endif diff --git a/source4/lib/ldb/include/ldb_private.h b/source4/lib/ldb/include/ldb_private.h index cf4017ef14..1ce9e9ecfd 100644 --- a/source4/lib/ldb/include/ldb_private.h +++ b/source4/lib/ldb/include/ldb_private.h @@ -37,6 +37,9 @@ #ifndef _LDB_PRIVATE_H_ #define _LDB_PRIVATE_H_ 1 +#include "ldb.h" +#include "ldb_module.h" + struct ldb_context; struct ldb_module_ops; @@ -58,26 +61,6 @@ struct ldb_module { }; /* - these function pointers define the operations that a ldb module can intercept -*/ -struct ldb_module_ops { - const char *name; - int (*init_context) (struct ldb_module *); - int (*search)(struct ldb_module *, struct ldb_request *); /* search */ - int (*add)(struct ldb_module *, struct ldb_request *); /* add */ - int (*modify)(struct ldb_module *, struct ldb_request *); /* modify */ - int (*del)(struct ldb_module *, struct ldb_request *); /* delete */ - int (*rename)(struct ldb_module *, struct ldb_request *); /* rename */ - int (*request)(struct ldb_module *, struct ldb_request *); /* match any other operation */ - int (*extended)(struct ldb_module *, struct ldb_request *); /* extended operations */ - int (*start_transaction)(struct ldb_module *); - int (*end_transaction)(struct ldb_module *); - int (*del_transaction)(struct ldb_module *); - int (*sequence_number)(struct ldb_module *, struct ldb_request *); - void *private_data; -}; - -/* schema related information needed for matching rules */ struct ldb_schema { @@ -130,24 +113,12 @@ struct ldb_context { #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) #endif -/* - simplify out of memory handling -*/ -#define ldb_oom(ldb) ldb_debug_set(ldb, LDB_DEBUG_FATAL, "ldb out of memory at %s:%d\n", __FILE__, __LINE__) - /* The following definitions come from lib/ldb/common/ldb.c */ int ldb_connect_backend(struct ldb_context *ldb, const char *url, const char *options[], struct ldb_module **backend_module); void ldb_set_default_dns(struct ldb_context *ldb); -/* The following definitions come from lib/ldb/common/ldb_debug.c */ -void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4); -void ldb_debug_set(struct ldb_context *ldb, enum ldb_debug_level level, - const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4); - -/* The following definitions come from lib/ldb/common/ldb_ldif.c */ -int ldb_should_b64_encode(const struct ldb_val *val); extern const struct ldb_module_ops ldb_objectclass_module_ops; extern const struct ldb_module_ops ldb_operational_module_ops; @@ -173,61 +144,17 @@ extern const struct ldb_backend_ops ldb_ldap_backend_ops; extern const struct ldb_backend_ops ldb_ldapi_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, - const struct ldb_parse_tree *tree, - struct ldb_dn *base, - enum ldb_scope scope); - -const struct ldb_schema_syntax *ldb_standard_syntax_by_name(struct ldb_context *ldb, - const char *syntax); - -/* The following definitions come from lib/ldb/common/ldb_attributes.c */ - -int ldb_schema_attribute_add_with_syntax(struct ldb_context *ldb, - const char *name, - unsigned flags, - const struct ldb_schema_syntax *syntax); -int ldb_schema_attribute_add(struct ldb_context *ldb, - const char *name, - unsigned flags, - const char *syntax); -void ldb_schema_attribute_remove(struct ldb_context *ldb, const char *name); int ldb_setup_wellknown_attributes(struct ldb_context *ldb); const char **ldb_subclass_list(struct ldb_context *ldb, const char *classname); void ldb_subclass_remove(struct ldb_context *ldb, const char *classname); int ldb_subclass_add(struct ldb_context *ldb, const char *classname, const char *subclass); -int ldb_handler_copy(struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *in, struct ldb_val *out); -int ldb_comparison_binary(struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *v1, const struct ldb_val *v2); - -/* The following definitions come from lib/ldb/common/ldb_controls.c */ -struct ldb_control *get_control_from_list(struct ldb_control **controls, const char *oid); -int save_controls(struct ldb_control *exclude, struct ldb_request *req, struct ldb_control ***saver); -int check_critical_controls(struct ldb_control **controls); - /* The following definitions come from lib/ldb/common/ldb_utf8.c */ char *ldb_casefold_default(void *context, void *mem_ctx, const char *s, size_t n); -void ldb_msg_remove_element(struct ldb_message *msg, struct ldb_message_element *el); - -int ldb_msg_element_compare_name(struct ldb_message_element *el1, - struct ldb_message_element *el2); void ldb_dump_results(struct ldb_context *ldb, struct ldb_result *result, FILE *f); -/** - Obtain current/next database sequence number -*/ -int ldb_sequence_number(struct ldb_context *ldb, enum ldb_sequence_type type, uint64_t *seq_num); - -#define LDB_SEQ_GLOBAL_SEQUENCE 0x01 -#define LDB_SEQ_TIMESTAMP_SEQUENCE 0x02 - - -/* MODULES specific headers -- SSS */ /* The following definitions come from lib/ldb/common/ldb_modules.c */ @@ -235,49 +162,6 @@ const char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *m int ldb_load_modules_list(struct ldb_context *ldb, const char **module_list, struct ldb_module *backend, struct ldb_module **out); int ldb_load_modules(struct ldb_context *ldb, const char *options[]); int ldb_init_module_chain(struct ldb_context *ldb, struct ldb_module *module); -int ldb_next_request(struct ldb_module *module, struct ldb_request *request); -int ldb_next_start_trans(struct ldb_module *module); -int ldb_next_end_trans(struct ldb_module *module); -int ldb_next_del_trans(struct ldb_module *module); -int ldb_next_init(struct ldb_module *module); - -void ldb_set_errstring(struct ldb_context *ldb, const char *err_string); -void ldb_asprintf_errstring(struct ldb_context *ldb, const char *format, ...) PRINTF_ATTRIBUTE(2,3); -void ldb_reset_err_string(struct ldb_context *ldb); - -const char *ldb_default_modules_dir(void); - -int ldb_register_module(const struct ldb_module_ops *); - -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); - -int ldb_register_backend(const char *url_prefix, ldb_connect_fn); - -struct ldb_handle *ldb_handle_new(TALLOC_CTX *mem_ctx, struct ldb_context *ldb); - -int ldb_module_send_entry(struct ldb_request *req, - struct ldb_message *msg, - struct ldb_control **ctrls); - -int ldb_module_send_referral(struct ldb_request *req, - char *ref); - -int ldb_module_done(struct ldb_request *req, - struct ldb_control **ctrls, - struct ldb_extended *response, - int error); - -int ldb_mod_register_control(struct ldb_module *module, const char *oid); - struct ldb_val ldb_binary_decode(void *mem_ctx, const char *str); diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 791cc75dc1..3901b9b436 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -42,7 +42,7 @@ #include "includes.h" -#include "ldb_includes.h" +#include "ldb_module.h" #include "tevent.h" #include "libcli/ldap/ldap.h" @@ -70,8 +70,11 @@ struct ildb_context { static void ildb_request_done(struct ildb_context *ctx, struct ldb_control **ctrls, int error) { + struct ldb_context *ldb; struct ldb_reply *ares; + ldb = ldb_module_get_ctx(ctx->module); + ctx->done = true; if (ctx->req == NULL) { @@ -81,7 +84,7 @@ static void ildb_request_done(struct ildb_context *ctx, ares = talloc_zero(ctx->req, struct ldb_reply); if (!ares) { - ldb_oom(ctx->req->handle->ldb); + ldb_oom(ldb); ctx->req->callback(ctx->req, NULL); return; } @@ -163,17 +166,21 @@ failed: */ static int ildb_map_error(struct ldb_module *module, NTSTATUS status) { - struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); + struct ildb_private *ildb; + struct ldb_context *ldb; + + ildb = talloc_get_type(ldb_module_get_private(module), struct ildb_private); + ldb = ldb_module_get_ctx(module); TALLOC_CTX *mem_ctx = talloc_new(ildb); if (NT_STATUS_IS_OK(status)) { return LDB_SUCCESS; } if (!mem_ctx) { - ldb_oom(module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } - ldb_set_errstring(module->ldb, + ldb_set_errstring(ldb, ldap_errstr(ildb->ldap, mem_ctx, status)); talloc_free(mem_ctx); if (NT_STATUS_IS_LDAP(status)) { @@ -196,6 +203,7 @@ static void ildb_request_timeout(struct tevent_context *ev, struct tevent_timer static void ildb_callback(struct ldap_request *req) { + struct ldb_context *ldb; struct ildb_context *ac; NTSTATUS status; struct ldap_SearchResEntry *search; @@ -209,6 +217,7 @@ static void ildb_callback(struct ldap_request *req) int i; ac = talloc_get_type(req->async.private_data, struct ildb_context); + ldb = ldb_module_get_ctx(ac->module); callback_failed = false; request_done = false; controls = NULL; @@ -285,7 +294,7 @@ static void ildb_callback(struct ldap_request *req) controls = talloc_steal(ac, msg->controls); if (msg->r.SearchResultDone.resultcode) { if (msg->r.SearchResultDone.errormessage) { - ldb_set_errstring(ac->module->ldb, msg->r.SearchResultDone.errormessage); + ldb_set_errstring(ldb, msg->r.SearchResultDone.errormessage); } } @@ -303,7 +312,7 @@ static void ildb_callback(struct ldap_request *req) search = &(msg->r.SearchResultEntry); - ldbmsg->dn = ldb_dn_new(ldbmsg, ac->module->ldb, search->dn); + ldbmsg->dn = ldb_dn_new(ldbmsg, ldb, search->dn); if ( ! ldb_dn_validate(ldbmsg->dn)) { ret = LDB_ERR_OPERATIONS_ERROR; break; @@ -368,21 +377,24 @@ static void ildb_callback(struct ldap_request *req) static int ildb_request_send(struct ildb_context *ac, struct ldap_message *msg) { + struct ldb_context *ldb; struct ldap_request *req; if (!ac) { return LDB_ERR_OPERATIONS_ERROR; } + ldb = ldb_module_get_ctx(ac->module); + req = ldap_request_send(ac->ildb->ldap, msg); if (req == NULL) { - ldb_set_errstring(ac->module->ldb, "async send request failed"); + ldb_set_errstring(ldb, "async send request failed"); return LDB_ERR_OPERATIONS_ERROR; } ac->ireq = talloc_steal(ac, req); if (!ac->ireq->conn) { - ldb_set_errstring(ac->module->ldb, "connection to remote LDAP server dropped?"); + ldb_set_errstring(ldb, "connection to remote LDAP server dropped?"); return LDB_ERR_OPERATIONS_ERROR; } @@ -405,23 +417,26 @@ static int ildb_request_send(struct ildb_context *ac, struct ldap_message *msg) */ static int ildb_search(struct ildb_context *ac) { + struct ldb_context *ldb; struct ldb_request *req = ac->req; struct ldap_message *msg; int n; + ldb = ldb_module_get_ctx(ac->module); + if (!req->callback || !req->context) { - ldb_set_errstring(ac->module->ldb, "Async interface called with NULL callback function or NULL context"); + ldb_set_errstring(ldb, "Async interface called with NULL callback function or NULL context"); return LDB_ERR_OPERATIONS_ERROR; } if (req->op.search.tree == NULL) { - ldb_set_errstring(ac->module->ldb, "Invalid expression parse tree"); + ldb_set_errstring(ldb, "Invalid expression parse tree"); return LDB_ERR_OPERATIONS_ERROR; } msg = new_ldap_message(req); if (msg == NULL) { - ldb_set_errstring(ac->module->ldb, "Out of Memory"); + ldb_set_errstring(ldb, "Out of Memory"); return LDB_ERR_OPERATIONS_ERROR; } @@ -433,7 +448,7 @@ static int ildb_search(struct ildb_context *ac) msg->r.SearchRequest.basedn = ldb_dn_get_extended_linearized(msg, req->op.search.base, 0); } if (msg->r.SearchRequest.basedn == NULL) { - ldb_set_errstring(ac->module->ldb, "Unable to determine baseDN"); + ldb_set_errstring(ldb, "Unable to determine baseDN"); talloc_free(msg); return LDB_ERR_OPERATIONS_ERROR; } @@ -659,21 +674,23 @@ static bool ildb_dn_is_special(struct ldb_request *req) static int ildb_handle_request(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; struct ildb_private *ildb; struct ildb_context *ac; struct tevent_timer *te; int ret; - ildb = talloc_get_type(module->private_data, struct ildb_private); + ildb = talloc_get_type(ldb_module_get_private(module), struct ildb_private); + ldb = ldb_module_get_ctx(module); if (req->starttime == 0 || req->timeout == 0) { - ldb_set_errstring(module->ldb, "Invalid timeout settings"); + ldb_set_errstring(ldb, "Invalid timeout settings"); return LDB_ERR_TIME_LIMIT_EXCEEDED; } ac = talloc_zero(req, struct ildb_context); if (ac == NULL) { - ldb_set_errstring(module->ldb, "Out of Memory"); + ldb_set_errstring(ldb, "Out of Memory"); return LDB_ERR_OPERATIONS_ERROR; } @@ -743,22 +760,15 @@ static int ildb_connect(struct ldb_context *ldb, const char *url, NTSTATUS status; struct cli_credentials *creds; - module = talloc(ldb, struct ldb_module); - if (!module) { - ldb_oom(ldb); - return -1; - } - talloc_set_name_const(module, "ldb_ildap backend"); - module->ldb = ldb; - module->prev = module->next = NULL; - module->ops = &ildb_ops; + module = ldb_module_new(ldb, ldb, "ldb_ildap backend", &ildb_ops); + if (!module) return -1; ildb = talloc(module, struct ildb_private); if (!ildb) { ldb_oom(ldb); goto failed; } - module->private_data = ildb; + ldb_module_set_private(module, ildb); ildb->event_ctx = ldb_get_event_context(ldb); diff --git a/source4/lib/ldb/ldb_ldap/ldb_ldap.c b/source4/lib/ldb/ldb_ldap/ldb_ldap.c index 8e053818e5..e1fcdb1353 100644 --- a/source4/lib/ldb/ldb_ldap/ldb_ldap.c +++ b/source4/lib/ldb/ldb_ldap/ldb_ldap.c @@ -38,7 +38,7 @@ * author: Simo Sorce */ -#include "ldb_includes.h" +#include "ldb_module.h" #define LDAP_DEPRECATED 1 #include <ldap.h> @@ -195,6 +195,7 @@ static int lldb_add_msg_attr(struct ldb_context *ldb, */ static int lldb_search(struct lldb_context *lldb_ac) { + struct ldb_context *ldb; struct lldb_private *lldb = lldb_ac->lldb; struct ldb_module *module = lldb_ac->module; struct ldb_request *req = lldb_ac->req; @@ -204,21 +205,23 @@ static int lldb_search(struct lldb_context *lldb_ac) char *expression; int ret; + ldb = ldb_module_get_ctx(module); + if (!req->callback || !req->context) { - ldb_set_errstring(module->ldb, "Async interface called with NULL callback function or NULL context"); + ldb_set_errstring(ldb, "Async interface called with NULL callback function or NULL context"); return LDB_ERR_OPERATIONS_ERROR; } if (req->op.search.tree == NULL) { - ldb_set_errstring(module->ldb, "Invalid expression parse tree"); + ldb_set_errstring(ldb, "Invalid expression parse tree"); return LDB_ERR_OPERATIONS_ERROR; } if (req->controls != NULL) { - ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls are not yet supported by ldb_ldap backend!\n"); + ldb_debug(ldb, LDB_DEBUG_WARNING, "Controls are not yet supported by ldb_ldap backend!\n"); } - req->handle->state = LDB_ASYNC_PENDING; + ldb_request_set_state(req, LDB_ASYNC_PENDING); search_base = ldb_dn_alloc_linearized(lldb_ac, req->op.search.base); if (req->op.search.base == NULL) { @@ -259,7 +262,7 @@ static int lldb_search(struct lldb_context *lldb_ac) &lldb_ac->msgid); if (ret != LDAP_SUCCESS) { - ldb_set_errstring(module->ldb, ldap_err2string(ret)); + ldb_set_errstring(ldb, ldap_err2string(ret)); } return lldb_ldap_to_ldb(ret); @@ -270,6 +273,7 @@ static int lldb_search(struct lldb_context *lldb_ac) */ static int lldb_add(struct lldb_context *lldb_ac) { + struct ldb_context *ldb; struct lldb_private *lldb = lldb_ac->lldb; struct ldb_module *module = lldb_ac->module; struct ldb_request *req = lldb_ac->req; @@ -277,7 +281,9 @@ static int lldb_add(struct lldb_context *lldb_ac) char *dn; int ret; - req->handle->state = LDB_ASYNC_PENDING; + ldb_module_get_ctx(module); + + ldb_request_set_state(req, LDB_ASYNC_PENDING); mods = lldb_msg_to_mods(lldb_ac, req->op.add.message, 0); if (mods == NULL) { @@ -295,7 +301,7 @@ static int lldb_add(struct lldb_context *lldb_ac) &lldb_ac->msgid); if (ret != LDAP_SUCCESS) { - ldb_set_errstring(module->ldb, ldap_err2string(ret)); + ldb_set_errstring(ldb, ldap_err2string(ret)); } return lldb_ldap_to_ldb(ret); @@ -306,6 +312,7 @@ static int lldb_add(struct lldb_context *lldb_ac) */ static int lldb_modify(struct lldb_context *lldb_ac) { + struct ldb_context *ldb; struct lldb_private *lldb = lldb_ac->lldb; struct ldb_module *module = lldb_ac->module; struct ldb_request *req = lldb_ac->req; @@ -313,7 +320,9 @@ static int lldb_modify(struct lldb_context *lldb_ac) char *dn; int ret; - req->handle->state = LDB_ASYNC_PENDING; + ldb_module_get_ctx(module); + + ldb_request_set_state(req, LDB_ASYNC_PENDING); mods = lldb_msg_to_mods(lldb_ac, req->op.mod.message, 1); if (mods == NULL) { @@ -331,7 +340,7 @@ static int lldb_modify(struct lldb_context *lldb_ac) &lldb_ac->msgid); if (ret != LDAP_SUCCESS) { - ldb_set_errstring(module->ldb, ldap_err2string(ret)); + ldb_set_errstring(ldb, ldap_err2string(ret)); } return lldb_ldap_to_ldb(ret); @@ -342,13 +351,16 @@ static int lldb_modify(struct lldb_context *lldb_ac) */ static int lldb_delete(struct lldb_context *lldb_ac) { + struct ldb_context *ldb; struct lldb_private *lldb = lldb_ac->lldb; struct ldb_module *module = lldb_ac->module; struct ldb_request *req = lldb_ac->req; char *dnstr; int ret; - req->handle->state = LDB_ASYNC_PENDING; + ldb_module_get_ctx(module); + + ldb_request_set_state(req, LDB_ASYNC_PENDING); dnstr = ldb_dn_alloc_linearized(lldb_ac, req->op.del.dn); @@ -358,7 +370,7 @@ static int lldb_delete(struct lldb_context *lldb_ac) &lldb_ac->msgid); if (ret != LDAP_SUCCESS) { - ldb_set_errstring(module->ldb, ldap_err2string(ret)); + ldb_set_errstring(ldb, ldap_err2string(ret)); } return lldb_ldap_to_ldb(ret); @@ -369,6 +381,7 @@ static int lldb_delete(struct lldb_context *lldb_ac) */ static int lldb_rename(struct lldb_context *lldb_ac) { + struct ldb_context *ldb; struct lldb_private *lldb = lldb_ac->lldb; struct ldb_module *module = lldb_ac->module; struct ldb_request *req = lldb_ac->req; @@ -377,7 +390,9 @@ static int lldb_rename(struct lldb_context *lldb_ac) char *parentdn; int ret; - req->handle->state = LDB_ASYNC_PENDING; + ldb_module_get_ctx(module); + + ldb_request_set_state(req, LDB_ASYNC_PENDING); old_dn = ldb_dn_alloc_linearized(lldb_ac, req->op.rename.olddn); if (old_dn == NULL) { @@ -401,7 +416,7 @@ static int lldb_rename(struct lldb_context *lldb_ac) &lldb_ac->msgid); if (ret != LDAP_SUCCESS) { - ldb_set_errstring(module->ldb, ldap_err2string(ret)); + ldb_set_errstring(ldb, ldap_err2string(ret)); } return lldb_ldap_to_ldb(ret); @@ -428,14 +443,17 @@ static int lldb_del_trans(struct ldb_module *module) return LDB_SUCCESS; } -void lldb_request_done(struct ldb_request *req, +void lldb_request_done(struct lldb_context *ac, struct ldb_control **ctrls, int error) { + struct ldb_request *req; struct ldb_reply *ares; + req = ac->req; + ares = talloc_zero(req, struct ldb_reply); if (!ares) { - ldb_oom(req->handle->ldb); + ldb_oom(ldb_module_get_ctx(ac->module)); req->callback(req, NULL); return; } @@ -451,6 +469,7 @@ void lldb_request_done(struct ldb_request *req, */ static bool lldb_parse_result(struct lldb_context *ac, LDAPMessage *result) { + struct ldb_context *ldb; struct lldb_private *lldb = ac->lldb; LDAPControl **serverctrlsp = NULL; char **referralsp = NULL; @@ -466,6 +485,8 @@ static bool lldb_parse_result(struct lldb_context *ac, LDAPMessage *result) int ret; int i; + ldb = ldb_module_get_ctx(ac->module); + type = ldap_msgtype(result); callback_failed = false; request_done = false; @@ -490,7 +511,7 @@ static bool lldb_parse_result(struct lldb_context *ac, LDAPMessage *result) ret = LDB_ERR_OPERATIONS_ERROR; break; } - ldbmsg->dn = ldb_dn_new(ldbmsg, ac->module->ldb, dn); + ldbmsg->dn = ldb_dn_new(ldbmsg, ldb, dn); if ( ! ldb_dn_validate(ldbmsg->dn)) { talloc_free(ldbmsg); ret = LDB_ERR_OPERATIONS_ERROR; @@ -509,7 +530,7 @@ static bool lldb_parse_result(struct lldb_context *ac, LDAPMessage *result) bval = ldap_get_values_len(lldb->ldap, msg, attr); if (bval) { - lldb_add_msg_attr(ac->module->ldb, ldbmsg, attr, bval); + lldb_add_msg_attr(ldb, ldbmsg, attr, bval); ldap_value_free_len(bval); } } @@ -595,7 +616,7 @@ static bool lldb_parse_result(struct lldb_context *ac, LDAPMessage *result) } if (request_done) { - lldb_request_done(ac->req, ac->controls, ret); + lldb_request_done(ac, ac->controls, ret); lret = true; goto free_and_return; } @@ -606,7 +627,7 @@ free_and_return: if (matcheddnp) ldap_memfree(matcheddnp); if (errmsgp && *errmsgp) { - ldb_set_errstring(ac->module->ldb, errmsgp); + ldb_set_errstring(ldb, errmsgp); } if (errmsgp) { ldap_memfree(errmsgp); @@ -627,7 +648,7 @@ static void lldb_timeout(struct tevent_context *ev, struct lldb_context *ac; ac = talloc_get_type(private_data, struct lldb_context); - lldb_request_done(ac->req, NULL, LDB_ERR_TIME_LIMIT_EXCEEDED); + lldb_request_done(ac, NULL, LDB_ERR_TIME_LIMIT_EXCEEDED); } static void lldb_callback(struct tevent_context *ev, @@ -644,7 +665,7 @@ static void lldb_callback(struct tevent_context *ev, ac = talloc_get_type(private_data, struct lldb_context); if (!ac->msgid) { - lldb_request_done(ac->req, NULL, LDB_ERR_OPERATIONS_ERROR); + lldb_request_done(ac, NULL, LDB_ERR_OPERATIONS_ERROR); return; } @@ -655,7 +676,7 @@ static void lldb_callback(struct tevent_context *ev, goto respin; } if (lret == -1) { - lldb_request_done(ac->req, NULL, LDB_ERR_OPERATIONS_ERROR); + lldb_request_done(ac, NULL, LDB_ERR_OPERATIONS_ERROR); return; } @@ -668,9 +689,9 @@ static void lldb_callback(struct tevent_context *ev, respin: tv.tv_sec = 0; tv.tv_usec = 100; - lte = event_add_timed(ev, ac, tv, lldb_callback, ac); + lte = tevent_add_timer(ev, ac, tv, lldb_callback, ac); if (NULL == lte) { - lldb_request_done(ac->req, NULL, LDB_ERR_OPERATIONS_ERROR); + lldb_request_done(ac, NULL, LDB_ERR_OPERATIONS_ERROR); } } @@ -709,11 +730,12 @@ static void lldb_auto_done_callback(struct tevent_context *ev, struct lldb_context *ac; ac = talloc_get_type(private_data, struct lldb_context); - lldb_request_done(ac->req, NULL, LDB_SUCCESS); + lldb_request_done(ac, NULL, LDB_SUCCESS); } static int lldb_handle_request(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; struct lldb_private *lldb; struct lldb_context *ac; struct tevent_context *ev; @@ -721,21 +743,22 @@ static int lldb_handle_request(struct ldb_module *module, struct ldb_request *re struct timeval tv; int ret; - lldb = talloc_get_type(module->private_data, struct lldb_private); + lldb = talloc_get_type(ldb_module_get_private(module), struct lldb_private); + ldb = ldb_module_get_ctx(module); if (req->starttime == 0 || req->timeout == 0) { - ldb_set_errstring(module->ldb, "Invalid timeout settings"); + ldb_set_errstring(ldb, "Invalid timeout settings"); return LDB_ERR_TIME_LIMIT_EXCEEDED; } - ev = ldb_get_event_context(module->ldb); + ev = ldb_get_event_context(ldb); if (NULL == ev) { return LDB_ERR_OPERATIONS_ERROR; } - ac = talloc_zero(module->ldb, struct lldb_context); + ac = talloc_zero(ldb, struct lldb_context); if (ac == NULL) { - ldb_set_errstring(module->ldb, "Out of Memory"); + ldb_set_errstring(ldb, "Out of Memory"); return LDB_ERR_OPERATIONS_ERROR; } @@ -747,7 +770,7 @@ static int lldb_handle_request(struct ldb_module *module, struct ldb_request *re if (lldb_dn_is_special(req)) { tv.tv_sec = 0; tv.tv_usec = 0; - te = event_add_timed(ev, ac, tv, + te = tevent_add_timer(ev, ac, tv, lldb_auto_done_callback, ac); if (NULL == te) { return LDB_ERR_OPERATIONS_ERROR; @@ -779,13 +802,13 @@ static int lldb_handle_request(struct ldb_module *module, struct ldb_request *re } if (ret != LDB_SUCCESS) { - lldb_request_done(req, NULL, ret); + lldb_request_done(ac, NULL, ret); return ret; } tv.tv_sec = 0; tv.tv_usec = 0; - te = event_add_timed(ev, ac, tv, lldb_callback, ac); + te = tevent_add_timer(ev, ac, tv, lldb_callback, ac); if (NULL == te) { return LDB_ERR_OPERATIONS_ERROR; } @@ -793,7 +816,7 @@ static int lldb_handle_request(struct ldb_module *module, struct ldb_request *re tv.tv_sec = req->starttime + req->timeout; tv.tv_usec = 0; - te = event_add_timed(ev, ac, tv, lldb_timeout, ac); + te = tevent_add_timer(ev, ac, tv, lldb_timeout, ac); if (NULL == te) { return LDB_ERR_OPERATIONS_ERROR; } @@ -835,24 +858,15 @@ static int lldb_connect(struct ldb_context *ldb, int version = 3; int ret; - module = talloc(ldb, struct ldb_module); - if (module == NULL) { - ldb_oom(ldb); - talloc_free(lldb); - return -1; - } - talloc_set_name_const(module, "ldb_ldap backend"); - module->ldb = ldb; - module->prev = module->next = NULL; - module->ops = &lldb_ops; + module = ldb_module_new(ldb, ldb, "ldb_ldap backend", &lldb_ops); + if (!module) return -1; - lldb = talloc(module, struct lldb_private); + lldb = talloc_zero(module, struct lldb_private); if (!lldb) { ldb_oom(ldb); goto failed; } - module->private_data = lldb; - lldb->ldap = NULL; + ldb_module_set_private(module, lldb); ret = ldap_initialize(&lldb->ldap, url); if (ret != LDAP_SUCCESS) { diff --git a/source4/lib/ldb/ldb_map/ldb_map.c b/source4/lib/ldb/ldb_map/ldb_map.c index 72d8378a07..ea2bfd1dc1 100644 --- a/source4/lib/ldb/ldb_map/ldb_map.c +++ b/source4/lib/ldb/ldb_map/ldb_map.c @@ -35,7 +35,7 @@ * Author: Jelmer Vernooij, Martin Kuehl */ -#include "ldb_includes.h" +#include "ldb_module.h" #include "ldb_map.h" #include "ldb_map_private.h" @@ -102,7 +102,7 @@ /* Extract mappings from private data. */ const struct ldb_map_context *map_get_context(struct ldb_module *module) { - const struct map_private *data = talloc_get_type(module->private_data, struct map_private); + const struct map_private *data = talloc_get_type(ldb_module_get_private(module), struct map_private); return data->context; } @@ -110,11 +110,14 @@ const struct ldb_map_context *map_get_context(struct ldb_module *module) struct map_context *map_init_context(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; struct map_context *ac; + ldb = ldb_module_get_ctx(module); + ac = talloc_zero(req, struct map_context); if (ac == NULL) { - ldb_set_errstring(module->ldb, "Out of Memory"); + ldb_set_errstring(ldb, "Out of Memory"); return NULL; } @@ -202,8 +205,11 @@ static struct ldb_dn *ldb_dn_rebase_remote(void *mem_ctx, const struct ldb_map_c int ldb_next_remote_request(struct ldb_module *module, struct ldb_request *request) { const struct ldb_map_context *data = map_get_context(module); + struct ldb_context *ldb; struct ldb_message *msg; + ldb = ldb_module_get_ctx(module); + switch (request->operation) { case LDB_SEARCH: if (request->op.search.base) { @@ -236,7 +242,7 @@ int ldb_next_remote_request(struct ldb_module *module, struct ldb_request *reque break; default: - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: " + ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: " "Invalid remote request!\n"); return LDB_ERR_OPERATIONS_ERROR; } @@ -462,6 +468,7 @@ bool ldb_dn_check_local(struct ldb_module *module, struct ldb_dn *dn) struct ldb_dn *ldb_dn_map_local(struct ldb_module *module, void *mem_ctx, struct ldb_dn *dn) { const struct ldb_map_context *data = map_get_context(module); + struct ldb_context *ldb; struct ldb_dn *newdn; const struct ldb_map_attribute *map; enum ldb_map_attr_type map_type; @@ -473,6 +480,8 @@ struct ldb_dn *ldb_dn_map_local(struct ldb_module *module, void *mem_ctx, struct return NULL; } + ldb = ldb_module_get_ctx(module); + newdn = ldb_dn_copy(mem_ctx, dn); if (newdn == NULL) { map_oom(module); @@ -493,14 +502,14 @@ struct ldb_dn *ldb_dn_map_local(struct ldb_module *module, void *mem_ctx, struct switch (map_type) { case MAP_IGNORE: case MAP_GENERATE: - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: " + ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: " "MAP_IGNORE/MAP_GENERATE attribute '%s' " "used in DN!\n", ldb_dn_get_component_name(dn, i)); goto failed; case MAP_CONVERT: if (map->u.convert.convert_local == NULL) { - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: " + ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: " "'convert_local' not set for attribute '%s' " "used in DN!\n", ldb_dn_get_component_name(dn, i)); goto failed; @@ -534,6 +543,7 @@ failed: struct ldb_dn *ldb_dn_map_remote(struct ldb_module *module, void *mem_ctx, struct ldb_dn *dn) { const struct ldb_map_context *data = map_get_context(module); + struct ldb_context *ldb; struct ldb_dn *newdn; const struct ldb_map_attribute *map; enum ldb_map_attr_type map_type; @@ -545,6 +555,8 @@ struct ldb_dn *ldb_dn_map_remote(struct ldb_module *module, void *mem_ctx, struc return NULL; } + ldb = ldb_module_get_ctx(module); + newdn = ldb_dn_copy(mem_ctx, dn); if (newdn == NULL) { map_oom(module); @@ -565,14 +577,14 @@ struct ldb_dn *ldb_dn_map_remote(struct ldb_module *module, void *mem_ctx, struc switch (map_type) { case MAP_IGNORE: case MAP_GENERATE: - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: " + ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: " "MAP_IGNORE/MAP_GENERATE attribute '%s' " "used in DN!\n", ldb_dn_get_component_name(dn, i)); goto failed; case MAP_CONVERT: if (map->u.convert.convert_remote == NULL) { - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: " + ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: " "'convert_remote' not set for attribute '%s' " "used in DN!\n", ldb_dn_get_component_name(dn, i)); goto failed; @@ -623,10 +635,13 @@ struct ldb_dn *ldb_dn_map_rebase_remote(struct ldb_module *module, void *mem_ctx /* Map a DN contained in an ldb value into the remote partition. */ static struct ldb_val ldb_dn_convert_local(struct ldb_module *module, void *mem_ctx, const struct ldb_val *val) { + struct ldb_context *ldb; struct ldb_dn *dn, *newdn; struct ldb_val newval; - dn = ldb_dn_from_ldb_val(mem_ctx, module->ldb, val); + ldb = ldb_module_get_ctx(module); + + dn = ldb_dn_from_ldb_val(mem_ctx, ldb, val); if (! ldb_dn_validate(dn)) { newval.length = 0; newval.data = NULL; @@ -649,10 +664,13 @@ static struct ldb_val ldb_dn_convert_local(struct ldb_module *module, void *mem_ /* Map a DN contained in an ldb value into the local partition. */ static struct ldb_val ldb_dn_convert_remote(struct ldb_module *module, void *mem_ctx, const struct ldb_val *val) { + struct ldb_context *ldb; struct ldb_dn *dn, *newdn; struct ldb_val newval; - dn = ldb_dn_from_ldb_val(mem_ctx, module->ldb, val); + ldb = ldb_module_get_ctx(module); + + dn = ldb_dn_from_ldb_val(mem_ctx, ldb, val); if (! ldb_dn_validate(dn)) { newval.length = 0; newval.data = NULL; @@ -693,11 +711,14 @@ static struct ldb_val map_objectclass_convert_local(struct ldb_module *module, v static void map_objectclass_generate_remote(struct ldb_module *module, const char *local_attr, const struct ldb_message *old, struct ldb_message *remote, struct ldb_message *local) { const struct ldb_map_context *data = map_get_context(module); + struct ldb_context *ldb; struct ldb_message_element *el, *oc; struct ldb_val val; bool found_extensibleObject = false; int i; + ldb = ldb_module_get_ctx(module); + /* Find old local objectClass */ oc = ldb_msg_find_element(old, "objectClass"); if (oc == NULL) { @@ -707,7 +728,7 @@ static void map_objectclass_generate_remote(struct ldb_module *module, const cha /* Prepare new element */ el = talloc_zero(remote, struct ldb_message_element); if (el == NULL) { - ldb_oom(module->ldb); + ldb_oom(ldb); return; /* TODO: fail? */ } @@ -716,7 +737,7 @@ static void map_objectclass_generate_remote(struct ldb_module *module, const cha el->values = talloc_array(el, struct ldb_val, el->num_values); if (el->values == NULL) { talloc_free(el); - ldb_oom(module->ldb); + ldb_oom(ldb); return; /* TODO: fail? */ } @@ -766,10 +787,13 @@ static struct ldb_val map_objectclass_convert_remote(struct ldb_module *module, static struct ldb_message_element *map_objectclass_generate_local(struct ldb_module *module, void *mem_ctx, const char *local_attr, const struct ldb_message *remote) { const struct ldb_map_context *data = map_get_context(module); + struct ldb_context *ldb; struct ldb_message_element *el, *oc; struct ldb_val val; int i; + ldb = ldb_module_get_ctx(module); + /* Find old remote objectClass */ oc = ldb_msg_find_element(remote, "objectClass"); if (oc == NULL) { @@ -779,7 +803,7 @@ static struct ldb_message_element *map_objectclass_generate_local(struct ldb_mod /* Prepare new element */ el = talloc_zero(mem_ctx, struct ldb_message_element); if (el == NULL) { - ldb_oom(module->ldb); + ldb_oom(ldb); return NULL; } @@ -788,7 +812,7 @@ static struct ldb_message_element *map_objectclass_generate_local(struct ldb_mod el->values = talloc_array(el, struct ldb_val, el->num_values); if (el->values == NULL) { talloc_free(el); - ldb_oom(module->ldb); + ldb_oom(ldb); return NULL; } @@ -809,7 +833,7 @@ static struct ldb_message_element *map_objectclass_generate_local(struct ldb_mod el->values = talloc_realloc(el, el->values, struct ldb_val, el->num_values); if (el->values == NULL) { talloc_free(el); - ldb_oom(module->ldb); + ldb_oom(ldb); return NULL; } } @@ -847,9 +871,12 @@ static int map_objectclass_convert_operator(struct ldb_module *module, void *mem struct ldb_request *map_search_base_req(struct map_context *ac, struct ldb_dn *dn, const char * const *attrs, const struct ldb_parse_tree *tree, void *context, ldb_map_callback_t callback) { const struct ldb_parse_tree *search_tree; + struct ldb_context *ldb; struct ldb_request *req; int ret; + ldb = ldb_module_get_ctx(ac->module); + if (tree) { search_tree = tree; } else { @@ -859,7 +886,7 @@ struct ldb_request *map_search_base_req(struct map_context *ac, struct ldb_dn *d } } - ret = ldb_build_search_req_ex(&req, ac->module->ldb, ac, + ret = ldb_build_search_req_ex(&req, ldb, ac, dn, LDB_SCOPE_BASE, search_tree, attrs, NULL, @@ -879,11 +906,14 @@ struct ldb_request *map_build_fixup_req(struct map_context *ac, void *context, ldb_map_callback_t callback) { + struct ldb_context *ldb; struct ldb_request *req; struct ldb_message *msg; const char *dn; int ret; + ldb = ldb_module_get_ctx(ac->module); + /* Prepare message */ msg = ldb_msg_new(ac); if (msg == NULL) { @@ -905,7 +935,7 @@ struct ldb_request *map_build_fixup_req(struct map_context *ac, } /* Prepare request */ - ret = ldb_build_mod_req(&req, ac->module->ldb, + ret = ldb_build_mod_req(&req, ldb, ac, msg, NULL, context, callback, ac->req); @@ -961,6 +991,7 @@ static const struct ldb_map_attribute objectclass_attribute_map = { static int map_init_dns(struct ldb_module *module, struct ldb_map_context *data, const char *name) { static const char * const attrs[] = { MAP_DN_FROM, MAP_DN_TO, NULL }; + struct ldb_context *ldb; struct ldb_dn *dn; struct ldb_message *msg; struct ldb_result *res; @@ -972,34 +1003,36 @@ static int map_init_dns(struct ldb_module *module, struct ldb_map_context *data, return LDB_SUCCESS; } - dn = ldb_dn_new_fmt(data, module->ldb, "%s=%s", MAP_DN_NAME, name); + ldb = ldb_module_get_ctx(module); + + dn = ldb_dn_new_fmt(data, ldb, "%s=%s", MAP_DN_NAME, name); if ( ! ldb_dn_validate(dn)) { - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: " + ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: " "Failed to construct '%s' DN!\n", MAP_DN_NAME); return LDB_ERR_OPERATIONS_ERROR; } - ret = ldb_search(module->ldb, data, &res, dn, LDB_SCOPE_BASE, attrs, NULL); + ret = ldb_search(ldb, data, &res, dn, LDB_SCOPE_BASE, attrs, NULL); talloc_free(dn); if (ret != LDB_SUCCESS) { return ret; } if (res->count == 0) { - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: " + ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: " "No results for '%s=%s'!\n", MAP_DN_NAME, name); talloc_free(res); return LDB_ERR_CONSTRAINT_VIOLATION; } if (res->count > 1) { - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: " + ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: " "Too many results for '%s=%s'!\n", MAP_DN_NAME, name); talloc_free(res); return LDB_ERR_CONSTRAINT_VIOLATION; } msg = res->msgs[0]; - data->local_base_dn = ldb_msg_find_attr_as_dn(module->ldb, data, msg, MAP_DN_FROM); - data->remote_base_dn = ldb_msg_find_attr_as_dn(module->ldb, data, msg, MAP_DN_TO); + data->local_base_dn = ldb_msg_find_attr_as_dn(ldb, data, msg, MAP_DN_FROM); + data->remote_base_dn = ldb_msg_find_attr_as_dn(ldb, data, msg, MAP_DN_TO); talloc_free(res); return LDB_SUCCESS; @@ -1075,7 +1108,7 @@ _PUBLIC_ int ldb_map_init(struct ldb_module *module, const struct ldb_map_attrib return LDB_ERR_OPERATIONS_ERROR; } - module->private_data = data; + ldb_module_set_private(module, data); data->context = talloc_zero(data, struct ldb_map_context); if (!data->context) { diff --git a/source4/lib/ldb/ldb_map/ldb_map.h b/source4/lib/ldb/ldb_map/ldb_map.h index 7f92c15b98..872208174e 100644 --- a/source4/lib/ldb/ldb_map/ldb_map.h +++ b/source4/lib/ldb/ldb_map/ldb_map.h @@ -67,7 +67,7 @@ struct ldb_map_attribute { } type; /* if set, will be called for search expressions that contain this attribute */ - int (*convert_operator)(struct ldb_module *, TALLOC_CTX *ctx, struct ldb_parse_tree **new, const struct ldb_parse_tree *); + int (*convert_operator)(struct ldb_module *, TALLOC_CTX *ctx, struct ldb_parse_tree **ntree, const struct ldb_parse_tree *otree); union { struct { diff --git a/source4/lib/ldb/ldb_map/ldb_map_inbound.c b/source4/lib/ldb/ldb_map/ldb_map_inbound.c index 96605f23eb..e915a5f46a 100644 --- a/source4/lib/ldb/ldb_map/ldb_map_inbound.c +++ b/source4/lib/ldb/ldb_map/ldb_map_inbound.c @@ -24,7 +24,7 @@ */ -#include "ldb_includes.h" +#include "ldb_module.h" #include "ldb_map.h" #include "ldb_map_private.h" @@ -69,10 +69,11 @@ static int ldb_msg_el_partition(struct ldb_module *module, struct ldb_message *l const struct ldb_map_context *data = map_get_context(module); const struct ldb_map_attribute *map = map_attr_find_local(data, attr_name); struct ldb_message_element *el=NULL; + struct ldb_context *ldb = ldb_module_get_ctx(module); /* Unknown attribute: ignore */ if (map == NULL) { - ldb_debug(module->ldb, LDB_DEBUG_WARNING, "ldb_map: " + ldb_debug(ldb, LDB_DEBUG_WARNING, "ldb_map: " "Not mapping attribute '%s': no mapping found\n", old->name); goto local; @@ -84,7 +85,7 @@ static int ldb_msg_el_partition(struct ldb_module *module, struct ldb_message *l case MAP_CONVERT: if (map->u.convert.convert_local == NULL) { - ldb_debug(module->ldb, LDB_DEBUG_WARNING, "ldb_map: " + ldb_debug(ldb, LDB_DEBUG_WARNING, "ldb_map: " "Not mapping attribute '%s': " "'convert_local' not set\n", map->local_name); @@ -98,7 +99,7 @@ static int ldb_msg_el_partition(struct ldb_module *module, struct ldb_message *l case MAP_GENERATE: if (map->u.generate.generate_remote == NULL) { - ldb_debug(module->ldb, LDB_DEBUG_WARNING, "ldb_map: " + ldb_debug(ldb, LDB_DEBUG_WARNING, "ldb_map: " "Not mapping attribute '%s': " "'generate_remote' not set\n", map->local_name); @@ -158,12 +159,15 @@ static bool ldb_msg_check_remote(struct ldb_module *module, const struct ldb_mes static int ldb_msg_partition(struct ldb_module *module, struct ldb_message *local, struct ldb_message *remote, const struct ldb_message *msg) { /* const char * const names[]; */ + struct ldb_context *ldb; int i, ret; + ldb = ldb_module_get_ctx(module); + for (i = 0; i < msg->num_elements; i++) { /* Skip 'IS_MAPPED' */ if (ldb_attr_cmp(msg->elements[i].name, IS_MAPPED) == 0) { - ldb_debug(module->ldb, LDB_DEBUG_WARNING, "ldb_map: " + ldb_debug(ldb, LDB_DEBUG_WARNING, "ldb_map: " "Skipping attribute '%s'\n", msg->elements[i].name); continue; @@ -195,10 +199,12 @@ static int map_rename_local_callback(struct ldb_request *req, /* Store the DN of a single search result in context. */ static int map_search_self_callback(struct ldb_request *req, struct ldb_reply *ares) { + struct ldb_context *ldb; struct map_context *ac; int ret; ac = talloc_get_type(req->context, struct map_context); + ldb = ldb_module_get_ctx(ac->module); if (!ares) { return ldb_module_done(ac->req, NULL, NULL, @@ -214,7 +220,7 @@ static int map_search_self_callback(struct ldb_request *req, struct ldb_reply *a case LDB_REPLY_ENTRY: /* We have already found a remote DN */ if (ac->local_dn) { - ldb_set_errstring(ac->module->ldb, + ldb_set_errstring(ldb, "Too many results!"); return ldb_module_done(ac->req, NULL, NULL, LDB_ERR_OPERATIONS_ERROR); @@ -284,10 +290,12 @@ static int map_search_self_req(struct ldb_request **req, static int map_op_local_callback(struct ldb_request *req, struct ldb_reply *ares) { + struct ldb_context *ldb; struct map_context *ac; int ret; ac = talloc_get_type(req->context, struct map_context); + ldb = ldb_module_get_ctx(ac->module); if (!ares) { return ldb_module_done(ac->req, NULL, NULL, @@ -299,7 +307,7 @@ static int map_op_local_callback(struct ldb_request *req, } if (ares->type != LDB_REPLY_DONE) { - ldb_set_errstring(req->handle->ldb, "Invalid reply type!"); + ldb_set_errstring(ldb, "Invalid reply type!"); return ldb_module_done(ac->req, NULL, NULL, LDB_ERR_OPERATIONS_ERROR); } @@ -317,9 +325,11 @@ static int map_op_local_callback(struct ldb_request *req, static int map_op_remote_callback(struct ldb_request *req, struct ldb_reply *ares) { + struct ldb_context *ldb; struct map_context *ac; ac = talloc_get_type(req->context, struct map_context); + ldb = ldb_module_get_ctx(ac->module); if (!ares) { return ldb_module_done(ac->req, NULL, NULL, @@ -331,7 +341,7 @@ static int map_op_remote_callback(struct ldb_request *req, } if (ares->type != LDB_REPLY_DONE) { - ldb_set_errstring(req->handle->ldb, "Invalid reply type!"); + ldb_set_errstring(ldb, "Invalid reply type!"); return ldb_module_done(ac->req, NULL, NULL, LDB_ERR_OPERATIONS_ERROR); } @@ -350,11 +360,14 @@ static int map_op_remote_callback(struct ldb_request *req, int map_add(struct ldb_module *module, struct ldb_request *req) { const struct ldb_message *msg = req->op.add.message; + struct ldb_context *ldb; struct map_context *ac; struct ldb_message *remote_msg; const char *dn; int ret; + ldb = ldb_module_get_ctx(module); + /* Do not manipulate our control entries */ if (ldb_dn_is_special(msg->dn)) { return ldb_next_request(module, req); @@ -397,7 +410,7 @@ int map_add(struct ldb_module *module, struct ldb_request *req) ldb_msg_partition(module, ac->local_msg, remote_msg, msg); /* Prepare the remote operation */ - ret = ldb_build_add_req(&ac->remote_req, module->ldb, + ret = ldb_build_add_req(&ac->remote_req, ldb, ac, remote_msg, req->controls, ac, map_op_remote_callback, @@ -426,10 +439,13 @@ int map_add(struct ldb_module *module, struct ldb_request *req) static int map_add_do_local(struct map_context *ac) { struct ldb_request *local_req; + struct ldb_context *ldb; int ret; + ldb = ldb_module_get_ctx(ac->module); + /* Prepare the local operation */ - ret = ldb_build_add_req(&local_req, ac->module->ldb, ac, + ret = ldb_build_add_req(&local_req, ldb, ac, ac->local_msg, ac->req->controls, ac, @@ -451,9 +467,12 @@ int map_modify(struct ldb_module *module, struct ldb_request *req) const struct ldb_message *msg = req->op.mod.message; struct ldb_request *search_req; struct ldb_message *remote_msg; + struct ldb_context *ldb; struct map_context *ac; int ret; + ldb = ldb_module_get_ctx(module); + /* Do not manipulate our control entries */ if (ldb_dn_is_special(msg->dn)) { return ldb_next_request(module, req); @@ -498,7 +517,7 @@ int map_modify(struct ldb_module *module, struct ldb_request *req) ldb_msg_partition(module, ac->local_msg, remote_msg, msg); /* Prepare the remote operation */ - ret = ldb_build_mod_req(&ac->remote_req, module->ldb, + ret = ldb_build_mod_req(&ac->remote_req, ldb, ac, remote_msg, req->controls, ac, map_op_remote_callback, @@ -526,9 +545,12 @@ int map_modify(struct ldb_module *module, struct ldb_request *req) static int map_modify_do_local(struct map_context *ac) { struct ldb_request *local_req; + struct ldb_context *ldb; char *dn; int ret; + ldb = ldb_module_get_ctx(ac->module); + if (ac->local_dn == NULL) { /* No local record present, add it instead */ /* Add local 'IS_MAPPED' */ @@ -544,7 +566,7 @@ static int map_modify_do_local(struct map_context *ac) } /* Prepare the local operation */ - ret = ldb_build_add_req(&local_req, ac->module->ldb, ac, + ret = ldb_build_add_req(&local_req, ldb, ac, ac->local_msg, ac->req->controls, ac, @@ -555,7 +577,7 @@ static int map_modify_do_local(struct map_context *ac) } } else { /* Prepare the local operation */ - ret = ldb_build_mod_req(&local_req, ac->module->ldb, ac, + ret = ldb_build_mod_req(&local_req, ldb, ac, ac->local_msg, ac->req->controls, ac, @@ -577,9 +599,12 @@ static int map_modify_do_local(struct map_context *ac) int map_delete(struct ldb_module *module, struct ldb_request *req) { struct ldb_request *search_req; + struct ldb_context *ldb; struct map_context *ac; int ret; + ldb = ldb_module_get_ctx(module); + /* Do not manipulate our control entries */ if (ldb_dn_is_special(req->op.del.dn)) { return ldb_next_request(module, req); @@ -598,7 +623,7 @@ int map_delete(struct ldb_module *module, struct ldb_request *req) } /* Prepare the remote operation */ - ret = ldb_build_del_req(&ac->remote_req, module->ldb, ac, + ret = ldb_build_del_req(&ac->remote_req, ldb, ac, ldb_dn_map_local(module, ac, req->op.del.dn), req->controls, ac, @@ -628,8 +653,11 @@ int map_delete(struct ldb_module *module, struct ldb_request *req) static int map_delete_do_local(struct map_context *ac) { struct ldb_request *local_req; + struct ldb_context *ldb; int ret; + ldb = ldb_module_get_ctx(ac->module); + /* No local record, continue remotely */ if (ac->local_dn == NULL) { /* Do the remote request. */ @@ -637,7 +665,7 @@ static int map_delete_do_local(struct map_context *ac) } /* Prepare the local operation */ - ret = ldb_build_del_req(&local_req, ac->module->ldb, ac, + ret = ldb_build_del_req(&local_req, ldb, ac, ac->req->op.del.dn, ac->req->controls, ac, @@ -657,9 +685,12 @@ static int map_delete_do_local(struct map_context *ac) int map_rename(struct ldb_module *module, struct ldb_request *req) { struct ldb_request *search_req; + struct ldb_context *ldb; struct map_context *ac; int ret; + ldb = ldb_module_get_ctx(module); + /* Do not manipulate our control entries */ if (ldb_dn_is_special(req->op.rename.olddn)) { return ldb_next_request(module, req); @@ -685,7 +716,7 @@ int map_rename(struct ldb_module *module, struct ldb_request *req) } /* Prepare the remote operation */ - ret = ldb_build_rename_req(&ac->remote_req, module->ldb, ac, + ret = ldb_build_rename_req(&ac->remote_req, ldb, ac, ldb_dn_map_local(module, ac, req->op.rename.olddn), ldb_dn_map_local(module, ac, req->op.rename.newdn), req->controls, @@ -715,8 +746,11 @@ int map_rename(struct ldb_module *module, struct ldb_request *req) static int map_rename_do_local(struct map_context *ac) { struct ldb_request *local_req; + struct ldb_context *ldb; int ret; + ldb = ldb_module_get_ctx(ac->module); + /* No local record, continue remotely */ if (ac->local_dn == NULL) { /* Do the remote request. */ @@ -724,7 +758,7 @@ static int map_rename_do_local(struct map_context *ac) } /* Prepare the local operation */ - ret = ldb_build_rename_req(&local_req, ac->module->ldb, ac, + ret = ldb_build_rename_req(&local_req, ldb, ac, ac->req->op.rename.olddn, ac->req->op.rename.newdn, ac->req->controls, @@ -741,10 +775,12 @@ static int map_rename_do_local(struct map_context *ac) static int map_rename_local_callback(struct ldb_request *req, struct ldb_reply *ares) { + struct ldb_context *ldb; struct map_context *ac; int ret; ac = talloc_get_type(req->context, struct map_context); + ldb = ldb_module_get_ctx(ac->module); if (!ares) { return ldb_module_done(ac->req, NULL, NULL, @@ -756,7 +792,7 @@ static int map_rename_local_callback(struct ldb_request *req, } if (ares->type != LDB_REPLY_DONE) { - ldb_set_errstring(req->handle->ldb, "Invalid reply type!"); + ldb_set_errstring(ldb, "Invalid reply type!"); return ldb_module_done(ac->req, NULL, NULL, LDB_ERR_OPERATIONS_ERROR); } diff --git a/source4/lib/ldb/ldb_map/ldb_map_outbound.c b/source4/lib/ldb/ldb_map/ldb_map_outbound.c index 5588eaaf46..327fa92f8d 100644 --- a/source4/lib/ldb/ldb_map/ldb_map_outbound.c +++ b/source4/lib/ldb/ldb_map/ldb_map_outbound.c @@ -25,7 +25,7 @@ */ -#include "ldb_includes.h" +#include "ldb_module.h" #include "ldb_map.h" #include "ldb_map_private.h" @@ -264,6 +264,9 @@ static int ldb_msg_el_merge(struct ldb_module *module, struct ldb_message *local const struct ldb_map_attribute *map; struct ldb_message_element *old, *el=NULL; const char *remote_name = NULL; + struct ldb_context *ldb; + + ldb = ldb_module_get_ctx(module); /* We handle wildcards in ldb_msg_el_merge_wildcard */ if (ldb_attr_cmp(attr_name, "*") == 0) { @@ -300,7 +303,7 @@ static int ldb_msg_el_merge(struct ldb_module *module, struct ldb_message *local case MAP_CONVERT: if (map->u.convert.convert_remote == NULL) { - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: " + ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: " "Skipping attribute '%s': " "'convert_remote' not set\n", attr_name); @@ -319,7 +322,7 @@ static int ldb_msg_el_merge(struct ldb_module *module, struct ldb_message *local case MAP_GENERATE: if (map->u.generate.generate_local == NULL) { - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: " + ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_map: " "Skipping attribute '%s': " "'generate_local' not set\n", attr_name); @@ -869,6 +872,9 @@ static int map_subtree_collect_remote(struct ldb_module *module, void *mem_ctx, { const struct ldb_map_context *data = map_get_context(module); const struct ldb_map_attribute *map; + struct ldb_context *ldb; + + ldb = ldb_module_get_ctx(module); if (tree == NULL) { return 0; @@ -893,7 +899,7 @@ static int map_subtree_collect_remote(struct ldb_module *module, void *mem_ctx, } if (map->type == MAP_GENERATE) { - ldb_debug(module->ldb, LDB_DEBUG_WARNING, "ldb_map: " + ldb_debug(ldb, LDB_DEBUG_WARNING, "ldb_map: " "Skipping attribute '%s': " "'convert_operator' not set\n", tree->u.equality.attr); @@ -1045,14 +1051,17 @@ int map_return_entry(struct map_context *ac, struct ldb_reply *ares) { struct ldb_message_element *el; const char * const *attrs; + struct ldb_context *ldb; int i; + ldb = ldb_module_get_ctx(ac->module); + /* Merged result doesn't match original query, skip */ - if (!ldb_match_msg(ac->module->ldb, ares->message, + if (!ldb_match_msg(ldb, ares->message, ac->req->op.search.tree, ac->req->op.search.base, ac->req->op.search.scope)) { - ldb_debug(ac->module->ldb, LDB_DEBUG_TRACE, "ldb_map: " + ldb_debug(ldb, LDB_DEBUG_TRACE, "ldb_map: " "Skipping record '%s': " "doesn't match original search\n", ldb_dn_get_linearized(ares->message->dn)); @@ -1086,13 +1095,17 @@ int map_search(struct ldb_module *module, struct ldb_request *req) struct ldb_parse_tree *remote_tree; struct ldb_parse_tree *local_tree; struct ldb_request *remote_req; + struct ldb_context *ldb; struct map_context *ac; int ret; const char *wildcard[] = { "*", NULL }; const char * const *attrs; - if (!module->private_data) /* if we're not yet initialized, go to the next module */ + ldb = ldb_module_get_ctx(module); + + /* if we're not yet initialized, go to the next module */ + if (!ldb_module_get_private(module)) return ldb_next_request(module, req); /* Do not manipulate our control entries */ @@ -1165,7 +1178,7 @@ int map_search(struct ldb_module *module, struct ldb_request *req) ac->local_tree = local_tree; /* Prepare the remote operation */ - ret = ldb_build_search_req_ex(&remote_req, module->ldb, ac, + ret = ldb_build_search_req_ex(&remote_req, ldb, ac, req->op.search.base, req->op.search.scope, remote_tree, @@ -1282,10 +1295,12 @@ static int map_search_local(struct map_context *ac) /* Merge the remote and local parts of a search result. */ int map_local_merge_callback(struct ldb_request *req, struct ldb_reply *ares) { + struct ldb_context *ldb; struct map_context *ac; int ret; ac = talloc_get_type(req->context, struct map_context); + ldb = ldb_module_get_ctx(ac->module); if (!ares) { return ldb_module_done(ac->req, NULL, NULL, @@ -1301,7 +1316,7 @@ int map_local_merge_callback(struct ldb_request *req, struct ldb_reply *ares) /* We have already found a local record */ if (ac->r_current->local) { talloc_free(ares); - ldb_set_errstring(ac->module->ldb, "ldb_map: Too many results!"); + ldb_set_errstring(ldb, "ldb_map: Too many results!"); return ldb_module_done(ac->req, NULL, NULL, LDB_ERR_OPERATIONS_ERROR); } diff --git a/source4/lib/ldb/ldb_map/ldb_map_private.h b/source4/lib/ldb/ldb_map/ldb_map_private.h index 0543ba71b9..0c46443253 100644 --- a/source4/lib/ldb/ldb_map/ldb_map_private.h +++ b/source4/lib/ldb/ldb_map/ldb_map_private.h @@ -1,6 +1,6 @@ /* A handy macro to report Out of Memory conditions */ -#define map_oom(module) ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); +#define map_oom(module) ldb_set_errstring(ldb_module_get_ctx(module), talloc_asprintf(module, "Out of Memory")); /* The type of search callback functions */ typedef int (*ldb_map_callback_t)(struct ldb_request *, struct ldb_reply *); diff --git a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c index be99c29d1e..8acbac4cc3 100644 --- a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c +++ b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c @@ -1,23 +1,23 @@ -/* +/* ldb database library - + Copyright (C) Derrell Lipman 2005 - Copyright (C) Simo Sorce 2005-2006 - + Copyright (C) Simo Sorce 2005-2009 + ** NOTE! The following LGPL license applies to the ldb ** library. This does NOT imply that all of Samba is released ** under the LGPL - + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. - + This library 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 Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with this library; if not, see <http://www.gnu.org/licenses/>. */ @@ -32,7 +32,7 @@ * Author: Derrell Lipman (based on Andrew Tridgell's LDAP backend) */ -#include "ldb_includes.h" +#include "ldb_module.h" #include <sqlite3.h> @@ -50,6 +50,9 @@ struct lsql_context { long long current_eid; const char * const * attrs; struct ldb_reply *ares; + + bool callback_failed; + struct tevent_timer *timeout_event; }; /* @@ -63,7 +66,8 @@ struct lsql_context { #define RESULT_ATTR_TABLE "temp_result_attrs" -//#define TEMPTAB /* for testing, create non-temporary table */ + +/* for testing, define to nothing, (create non-temporary table) */ #define TEMPTAB "TEMPORARY" /* @@ -144,7 +148,7 @@ base160_sql(sqlite3_context * hContext, val = sqlite3_value_int64(argv[0]); for (i = 3; i >= 0; i--) { - + result[i] = base160tab[val % 160]; val /= 160; } @@ -244,6 +248,7 @@ static char *parsetree_to_sql(struct ldb_module *module, void *mem_ctx, const struct ldb_parse_tree *t) { + struct ldb_context *ldb; const struct ldb_schema_attribute *a; struct ldb_val value, subval; char *wild_card_string; @@ -252,6 +257,7 @@ static char *parsetree_to_sql(struct ldb_module *module, char *attr; int i; + ldb = ldb_module_get_ctx(module); switch(t->operation) { case LDB_OP_AND: @@ -271,7 +277,7 @@ static char *parsetree_to_sql(struct ldb_module *module, ret = talloc_asprintf(mem_ctx, "SELECT * FROM ( %s )\n", tmp); return ret; - + case LDB_OP_OR: tmp = parsetree_to_sql(module, mem_ctx, t->u.list.elements[0]); @@ -304,10 +310,10 @@ static char *parsetree_to_sql(struct ldb_module *module, */ attr = ldb_attr_casefold(mem_ctx, t->u.equality.attr); if (attr == NULL) return NULL; - a = ldb_schema_attribute_by_name(module->ldb, attr); + a = ldb_schema_attribute_by_name(ldb, attr); /* Get a canonicalised copy of the data */ - a->syntax->canonicalise_fn(module->ldb, mem_ctx, &(t->u.equality.value), &value); + a->syntax->canonicalise_fn(ldb, mem_ctx, &(t->u.equality.value), &value); if (value.data == NULL) { return NULL; } @@ -315,7 +321,7 @@ static char *parsetree_to_sql(struct ldb_module *module, if (strcasecmp(t->u.equality.attr, "dn") == 0) { /* DN query is a special ldb case */ const char *cdn = ldb_dn_get_casefold( - ldb_dn_new(mem_ctx, module->ldb, + ldb_dn_new(mem_ctx, ldb, (const char *)value.data)); return lsqlite3_tprintf(mem_ctx, @@ -352,13 +358,13 @@ static char *parsetree_to_sql(struct ldb_module *module, attr = ldb_attr_casefold(mem_ctx, t->u.substring.attr); if (attr == NULL) return NULL; - a = ldb_schema_attribute_by_name(module->ldb, attr); + a = ldb_schema_attribute_by_name(ldb, attr); subval.data = (void *)wild_card_string; subval.length = strlen(wild_card_string) + 1; /* Get a canonicalised copy of the data */ - a->syntax->canonicalise_fn(module->ldb, mem_ctx, &(subval), &value); + a->syntax->canonicalise_fn(ldb, mem_ctx, &(subval), &value); if (value.data == NULL) { return NULL; } @@ -373,10 +379,10 @@ static char *parsetree_to_sql(struct ldb_module *module, case LDB_OP_GREATER: attr = ldb_attr_casefold(mem_ctx, t->u.equality.attr); if (attr == NULL) return NULL; - a = ldb_schema_attribute_by_name(module->ldb, attr); + a = ldb_schema_attribute_by_name(ldb, attr); /* Get a canonicalised copy of the data */ - a->syntax->canonicalise_fn(module->ldb, mem_ctx, &(t->u.equality.value), &value); + a->syntax->canonicalise_fn(ldb, mem_ctx, &(t->u.equality.value), &value); if (value.data == NULL) { return NULL; } @@ -392,10 +398,10 @@ static char *parsetree_to_sql(struct ldb_module *module, case LDB_OP_LESS: attr = ldb_attr_casefold(mem_ctx, t->u.equality.attr); if (attr == NULL) return NULL; - a = ldb_schema_attribute_by_name(module->ldb, attr); + a = ldb_schema_attribute_by_name(ldb, attr); /* Get a canonicalised copy of the data */ - a->syntax->canonicalise_fn(module->ldb, mem_ctx, &(t->u.equality.value), &value); + a->syntax->canonicalise_fn(ldb, mem_ctx, &(t->u.equality.value), &value); if (value.data == NULL) { return NULL; } @@ -424,10 +430,10 @@ static char *parsetree_to_sql(struct ldb_module *module, case LDB_OP_APPROX: attr = ldb_attr_casefold(mem_ctx, t->u.equality.attr); if (attr == NULL) return NULL; - a = ldb_schema_attribute_by_name(module->ldb, attr); + a = ldb_schema_attribute_by_name(ldb, attr); /* Get a canonicalised copy of the data */ - a->syntax->canonicalise_fn(module->ldb, mem_ctx, &(t->u.equality.value), &value); + a->syntax->canonicalise_fn(ldb, mem_ctx, &(t->u.equality.value), &value); if (value.data == NULL) { return NULL; } @@ -439,7 +445,7 @@ static char *parsetree_to_sql(struct ldb_module *module, attr, value.data, attr); - + case LDB_OP_EXTENDED: #warning "work out how to handle bitops" return NULL; @@ -473,22 +479,22 @@ query_int(const struct lsqlite3_private * lsqlite3, char * p; sqlite3_stmt * pStmt; va_list args; - + /* Begin access to variable argument list */ va_start(args, pSql); - + /* Format the query */ if ((p = sqlite3_vmprintf(pSql, args)) == NULL) { return SQLITE_NOMEM; } - + /* * Prepare and execute the SQL statement. Loop allows retrying on * certain errors, e.g. SQLITE_SCHEMA occurs if the schema changes, * requiring retrying the operation. */ for (bLoop = TRUE; bLoop; ) { - + /* Compile the SQL statement into sqlite virtual machine */ if ((ret = sqlite3_prepare(lsqlite3->sqlite, p, @@ -503,7 +509,7 @@ query_int(const struct lsqlite3_private * lsqlite3, } else if (ret != SQLITE_OK) { break; } - + /* One row expected */ if ((ret = sqlite3_step(pStmt)) == SQLITE_SCHEMA) { if (stmtGetEID != NULL) { @@ -516,10 +522,10 @@ query_int(const struct lsqlite3_private * lsqlite3, (void) sqlite3_finalize(pStmt); break; } - + /* Get the value to be returned */ *pRet = sqlite3_column_int64(pStmt, 0); - + /* Free the virtual machine */ if ((ret = sqlite3_finalize(pStmt)) == SQLITE_SCHEMA) { if (stmtGetEID != NULL) { @@ -531,21 +537,21 @@ query_int(const struct lsqlite3_private * lsqlite3, (void) sqlite3_finalize(pStmt); break; } - + /* * Normal condition is only one time through loop. Loop is * rerun in error conditions, via "continue", above. */ bLoop = FALSE; } - + /* All done with variable argument list */ va_end(args); - + /* Free the memory we allocated for our query string */ sqlite3_free(p); - + return ret; } @@ -574,9 +580,9 @@ static void lsqlite3_compare(sqlite3_context *ctx, int argc, /* greater */ case '>': /* >= */ a = ldb_schema_attribute_by_name(ldb, attr); - valX.data = (void *)cmp; + valX.data = (uint8_t *)cmp; valX.length = strlen(cmp); - valY.data = (void *)val; + valY.data = (uint8_t *)val; valY.length = strlen(val); ret = a->syntax->comparison_fn(ldb, ldb, &valY, &valX); if (ret >= 0) @@ -588,9 +594,9 @@ static void lsqlite3_compare(sqlite3_context *ctx, int argc, /* lesser */ case '<': /* <= */ a = ldb_schema_attribute_by_name(ldb, attr); - valX.data = (void *)cmp; + valX.data = (uint8_t *)cmp; valX.length = strlen(cmp); - valY.data = (void *)val; + valY.data = (uint8_t *)val; valY.length = strlen(val); ret = a->syntax->comparison_fn(ldb, ldb, &valY, &valX); if (ret <= 0) @@ -656,49 +662,52 @@ static int lsqlite3_eid_callback(void *result, int col_num, char **cols, char ** */ static int lsqlite3_search_callback(void *result, int col_num, char **cols, char **names) { - struct ldb_handle *handle = talloc_get_type(result, struct ldb_handle); - struct lsql_context *ac = talloc_get_type(handle->private_data, struct lsql_context); + struct ldb_context *ldb; + struct lsql_context *ac; struct ldb_message *msg; long long eid; - int i; + int i, ret; + + ac = talloc_get_type(result, struct lsql_context); + ldb = ldb_module_get_ctx(ac->module); /* eid, dn, attr_name, attr_value */ - if (col_num != 4) - return SQLITE_ABORT; + if (col_num != 4) return SQLITE_ABORT; eid = atoll(cols[0]); + if (ac->ares) { + msg = ac->ares->message; + } + if (eid != ac->current_eid) { /* here begin a new entry */ /* call the async callback for the last entry * except the first time */ if (ac->current_eid != 0) { - ac->ares->message = ldb_msg_canonicalize(ac->module->ldb, ac->ares->message); - if (ac->ares->message == NULL) - return SQLITE_ABORT; - - handle->status = ac->callback(ac->module->ldb, ac->context, ac->ares); - if (handle->status != LDB_SUCCESS) + msg = ldb_msg_canonicalize(ldb, msg); + if (!msg) return SQLITE_ABORT; + + ret = ldb_module_send_entry(ac->req, msg, NULL); + if (ret != LDB_SUCCESS) { + ac->callback_failed = true; return SQLITE_ABORT; + } } /* start over */ ac->ares = talloc_zero(ac, struct ldb_reply); - if (!ac->ares) - return SQLITE_ABORT; + if (!ac->ares) return SQLITE_ABORT; - ac->ares->message = ldb_msg_new(ac->ares); - if (!ac->ares->message) - return SQLITE_ABORT; + msg = ldb_msg_new(ac->ares); + if (!msg) return SQLITE_ABORT; ac->ares->type = LDB_REPLY_ENTRY; ac->current_eid = eid; } - msg = ac->ares->message; - if (msg->dn == NULL) { - msg->dn = ldb_dn_new(msg, ac->module->ldb, cols[1]); + msg->dn = ldb_dn_new(msg, ldb, cols[1]); if (msg->dn == NULL) return SQLITE_ABORT; } @@ -711,13 +720,15 @@ static int lsqlite3_search_callback(void *result, int col_num, char **cols, char break; } } - if (!found) return SQLITE_OK; + if (!found) goto done; } if (ldb_msg_add_string(msg, cols[2], cols[3]) != 0) { return SQLITE_ABORT; } +done: + ac->ares->message = msg; return SQLITE_OK; } @@ -755,10 +766,10 @@ static long long lsqlite3_get_eid_ndn(sqlite3 *sqlite, void *mem_ctx, const char return eid; } -static long long lsqlite3_get_eid(struct ldb_module *module, struct ldb_dn *dn) +static long long lsqlite3_get_eid(struct lsqlite3_private *lsqlite3, + struct ldb_dn *dn) { TALLOC_CTX *local_ctx; - struct lsqlite3_private *lsqlite3 = module->private_data; long long eid = -1; char *cdn; @@ -788,38 +799,44 @@ done: */ /* search for matching records, by tree */ -int lsql_search(struct ldb_module *module, struct ldb_request *req) +int lsql_search(struct lsql_context *ctx) { - struct lsqlite3_private *lsqlite3 = talloc_get_type(module->private_data, struct lsqlite3_private); - struct lsql_context *lsql_ac; + struct ldb_module *module = ctx->module; + struct ldb_request *req = ctx->req; + struct lsqlite3_private *lsqlite3; + struct ldb_context *ldb; char *norm_basedn; char *sqlfilter; char *errmsg; char *query = NULL; int ret; - lsql_ac = talloc_get_type(req->handle->private_data, struct lsql_context); + ldb = ldb_module_get_ctx(module); + lsqlite3 = talloc_get_type(ldb_module_get_private(module), + struct lsqlite3_private); - if ((( ! ldb_dn_is_valid(req->op.search.base)) || ldb_dn_is_null(req->op.search.base)) && - (req->op.search.scope == LDB_SCOPE_BASE || req->op.search.scope == LDB_SCOPE_ONELEVEL)) + if ((( ! ldb_dn_is_valid(req->op.search.base)) || + ldb_dn_is_null(req->op.search.base)) && + (req->op.search.scope == LDB_SCOPE_BASE || + req->op.search.scope == LDB_SCOPE_ONELEVEL)) { return LDB_ERR_OPERATIONS_ERROR; + } if (req->op.search.base) { - norm_basedn = ldb_dn_alloc_casefold(lsql_ac, req->op.search.base); + norm_basedn = ldb_dn_alloc_casefold(ctx, req->op.search.base); if (norm_basedn == NULL) { - ret = LDB_ERR_INVALID_DN_SYNTAX; - goto failed; + return LDB_ERR_OPERATIONS_ERROR; } - } else norm_basedn = talloc_strdup(lsql_ac, ""); + } else norm_basedn = talloc_strdup(ctx, ""); /* Convert filter into a series of SQL conditions (constraints) */ - sqlfilter = parsetree_to_sql(module, lsql_ac, req->op.search.tree); - + sqlfilter = parsetree_to_sql(module, ctx, req->op.search.tree); + switch(req->op.search.scope) { case LDB_SCOPE_DEFAULT: case LDB_SCOPE_SUBTREE: if (*norm_basedn != '\0') { - query = lsqlite3_tprintf(lsql_ac, + query = lsqlite3_tprintf(ctx, "SELECT entry.eid,\n" " entry.dn,\n" " av.attr_name,\n" @@ -843,7 +860,7 @@ int lsql_search(struct ldb_module *module, struct ldb_request *req) norm_basedn, sqlfilter); } else { - query = lsqlite3_tprintf(lsql_ac, + query = lsqlite3_tprintf(ctx, "SELECT entry.eid,\n" " entry.dn,\n" " av.attr_name,\n" @@ -865,9 +882,9 @@ int lsql_search(struct ldb_module *module, struct ldb_request *req) } break; - + case LDB_SCOPE_BASE: - query = lsqlite3_tprintf(lsql_ac, + query = lsqlite3_tprintf(ctx, "SELECT entry.eid,\n" " entry.dn,\n" " av.attr_name,\n" @@ -889,9 +906,9 @@ int lsql_search(struct ldb_module *module, struct ldb_request *req) norm_basedn, sqlfilter); break; - + case LDB_SCOPE_ONELEVEL: - query = lsqlite3_tprintf(lsql_ac, + query = lsqlite3_tprintf(ctx, "SELECT entry.eid,\n" " entry.dn,\n" " av.attr_name,\n" @@ -917,113 +934,108 @@ int lsql_search(struct ldb_module *module, struct ldb_request *req) } if (query == NULL) { - goto failed; + return LDB_ERR_OPERATIONS_ERROR; } /* * / printf ("%s\n", query); / * */ - lsql_ac->current_eid = 0; - lsql_ac->attrs = req->op.search.attrs; - lsql_ac->ares = NULL; + ctx->current_eid = 0; + ctx->attrs = req->op.search.attrs; + ctx->ares = NULL; - req->handle->state = LDB_ASYNC_PENDING; + ldb_request_set_state(req, LDB_ASYNC_PENDING); - ret = sqlite3_exec(lsqlite3->sqlite, query, lsqlite3_search_callback, req->handle, &errmsg); + ret = sqlite3_exec(lsqlite3->sqlite, query, lsqlite3_search_callback, ctx, &errmsg); if (ret != SQLITE_OK) { if (errmsg) { - ldb_set_errstring(module->ldb, errmsg); + ldb_set_errstring(ldb, errmsg); free(errmsg); } - goto failed; + return LDB_ERR_OPERATIONS_ERROR; } /* complete the last message if any */ - if (lsql_ac->ares) { - lsql_ac->ares->message = ldb_msg_canonicalize(module->ldb, lsql_ac->ares->message); - if (lsql_ac->ares->message == NULL) - goto failed; - - req->handle->status = lsql_ac->callback(module->ldb, lsql_ac->context, lsql_ac->ares); - if (req->handle->status != LDB_SUCCESS) - goto failed; + if (ctx->ares) { + ctx->ares->message = ldb_msg_canonicalize(ldb, ctx->ares->message); + if (ctx->ares->message == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + + ret = ldb_module_send_entry(req, ctx->ares->message, NULL); + if (ret != LDB_SUCCESS) { + return ret; + } } - req->handle->state = LDB_ASYNC_DONE; return LDB_SUCCESS; - -failed: - return LDB_ERR_OPERATIONS_ERROR; } /* add a record */ -static int lsql_add(struct ldb_module *module, struct ldb_request *req) +static int lsql_add(struct lsql_context *ctx) { - struct lsqlite3_private *lsqlite3 = talloc_get_type(module->private_data, struct lsqlite3_private); - struct lsql_context *lsql_ac; + struct ldb_module *module = ctx->module; + struct ldb_request *req = ctx->req; + struct lsqlite3_private *lsqlite3; + struct ldb_context *ldb; struct ldb_message *msg = req->op.add.message; long long eid; char *dn, *ndn; char *errmsg; char *query; int i; - int ret = LDB_SUCCESS; + int ret; - lsql_ac = talloc_get_type(req->handle->private_data, struct lsql_context); - req->handle->state = LDB_ASYNC_DONE; - req->handle->status = LDB_SUCCESS; + ldb = ldb_module_get_ctx(module); + lsqlite3 = talloc_get_type(ldb_module_get_private(module), + struct lsqlite3_private); /* See if this is an ltdb special */ if (ldb_dn_is_special(msg->dn)) { /* struct ldb_dn *c; - c = ldb_dn_new(local_ctx, module->ldb, "@INDEXLIST"); - if (ldb_dn_compare(module->ldb, msg->dn, c) == 0) { + c = ldb_dn_new(local_ctx, ldb, "@INDEXLIST"); + if (ldb_dn_compare(ldb, msg->dn, c) == 0) { #warning "should we handle indexes somehow ?" ret = LDB_ERR_UNWILLING_TO_PERFORM; goto done; } */ /* Others return an error */ - ret = LDB_ERR_UNWILLING_TO_PERFORM; - goto done; + return LDB_ERR_UNWILLING_TO_PERFORM; } /* create linearized and normalized dns */ - dn = ldb_dn_alloc_linearized(lsql_ac, msg->dn); - ndn = ldb_dn_alloc_casefold(lsql_ac, msg->dn); + dn = ldb_dn_alloc_linearized(ctx, msg->dn); + ndn = ldb_dn_alloc_casefold(ctx, msg->dn); if (dn == NULL || ndn == NULL) { - ret = LDB_ERR_OTHER; - goto done; + return LDB_ERR_OPERATIONS_ERROR; } - query = lsqlite3_tprintf(lsql_ac, + query = lsqlite3_tprintf(ctx, /* Add new entry */ "INSERT OR ABORT INTO ldb_entry " "('dn', 'norm_dn') " "VALUES ('%q', '%q');", dn, ndn); if (query == NULL) { - ret = LDB_ERR_OTHER; - goto done; + return LDB_ERR_OPERATIONS_ERROR; } ret = sqlite3_exec(lsqlite3->sqlite, query, NULL, NULL, &errmsg); if (ret != SQLITE_OK) { if (errmsg) { - ldb_set_errstring(module->ldb, errmsg); + ldb_set_errstring(ldb, errmsg); free(errmsg); } - ret = LDB_ERR_OTHER; - goto done; + return LDB_ERR_OPERATIONS_ERROR; } - eid = lsqlite3_get_eid_ndn(lsqlite3->sqlite, lsql_ac, ndn); + eid = lsqlite3_get_eid_ndn(lsqlite3->sqlite, ctx, ndn); if (eid == -1) { - ret = LDB_ERR_OTHER; - goto done; + return LDB_ERR_OPERATIONS_ERROR; } for (i = 0; i < msg->num_elements; i++) { @@ -1033,13 +1045,12 @@ static int lsql_add(struct ldb_module *module, struct ldb_request *req) int j; /* Get a case-folded copy of the attribute name */ - attr = ldb_attr_casefold(lsql_ac, el->name); + attr = ldb_attr_casefold(ctx, el->name); if (attr == NULL) { - ret = LDB_ERR_OTHER; - goto done; + return LDB_ERR_OPERATIONS_ERROR; } - a = ldb_schema_attribute_by_name(module->ldb, el->name); + a = ldb_schema_attribute_by_name(ldb, el->name); /* For each value of the specified attribute name... */ for (j = 0; j < el->num_values; j++) { @@ -1047,13 +1058,12 @@ static int lsql_add(struct ldb_module *module, struct ldb_request *req) char *insert; /* Get a canonicalised copy of the data */ - a->syntax->canonicalise_fn(module->ldb, lsql_ac, &(el->values[j]), &value); + a->syntax->canonicalise_fn(ldb, ctx, &(el->values[j]), &value); if (value.data == NULL) { - ret = LDB_ERR_OTHER; - goto done; + return LDB_ERR_OPERATIONS_ERROR; } - insert = lsqlite3_tprintf(lsql_ac, + insert = lsqlite3_tprintf(ctx, "INSERT OR ROLLBACK INTO ldb_attribute_values " "('eid', 'attr_name', 'norm_attr_name'," " 'attr_value', 'norm_attr_value') " @@ -1061,57 +1071,49 @@ static int lsql_add(struct ldb_module *module, struct ldb_request *req) eid, el->name, attr, el->values[j].data, value.data); if (insert == NULL) { - ret = LDB_ERR_OTHER; - goto done; + return LDB_ERR_OPERATIONS_ERROR; } ret = sqlite3_exec(lsqlite3->sqlite, insert, NULL, NULL, &errmsg); if (ret != SQLITE_OK) { if (errmsg) { - ldb_set_errstring(module->ldb, errmsg); + ldb_set_errstring(ldb, errmsg); free(errmsg); } - ret = LDB_ERR_OTHER; - goto done; + return LDB_ERR_OPERATIONS_ERROR; } } } - if (lsql_ac->callback) { - req->handle->status = lsql_ac->callback(module->ldb, lsql_ac->context, NULL); - } - -done: - req->handle->state = LDB_ASYNC_DONE; - return ret; + return LDB_SUCCESS; } /* modify a record */ -static int lsql_modify(struct ldb_module *module, struct ldb_request *req) +static int lsql_modify(struct lsql_context *ctx) { - struct lsqlite3_private *lsqlite3 = talloc_get_type(module->private_data, struct lsqlite3_private); - struct lsql_context *lsql_ac; + struct ldb_module *module = ctx->module; + struct ldb_request *req = ctx->req; + struct lsqlite3_private *lsqlite3; + struct ldb_context *ldb; struct ldb_message *msg = req->op.mod.message; long long eid; char *errmsg; int i; - int ret = LDB_SUCCESS; + int ret; - lsql_ac = talloc_get_type(req->handle->private_data, struct lsql_context); - req->handle->state = LDB_ASYNC_DONE; - req->handle->status = LDB_SUCCESS; + ldb = ldb_module_get_ctx(module); + lsqlite3 = talloc_get_type(ldb_module_get_private(module), + struct lsqlite3_private); /* See if this is an ltdb special */ if (ldb_dn_is_special(msg->dn)) { /* Others return an error */ - ret = LDB_ERR_UNWILLING_TO_PERFORM; - goto done; + return LDB_ERR_UNWILLING_TO_PERFORM; } - eid = lsqlite3_get_eid(module, msg->dn); + eid = lsqlite3_get_eid(lsqlite3, msg->dn); if (eid == -1) { - ret = LDB_ERR_OTHER; - goto done; + return LDB_ERR_OPERATIONS_ERROR; } for (i = 0; i < msg->num_elements; i++) { @@ -1123,37 +1125,34 @@ static int lsql_modify(struct ldb_module *module, struct ldb_request *req) int j; /* Get a case-folded copy of the attribute name */ - attr = ldb_attr_casefold(lsql_ac, el->name); + attr = ldb_attr_casefold(ctx, el->name); if (attr == NULL) { - ret = LDB_ERR_OTHER; - goto done; + return LDB_ERR_OPERATIONS_ERROR; } - a = ldb_schema_attribute_by_name(module->ldb, el->name); + a = ldb_schema_attribute_by_name(ldb, el->name); switch (flags) { case LDB_FLAG_MOD_REPLACE: - + /* remove all attributes before adding the replacements */ - mod = lsqlite3_tprintf(lsql_ac, + mod = lsqlite3_tprintf(ctx, "DELETE FROM ldb_attribute_values " "WHERE eid = '%lld' " "AND norm_attr_name = '%q';", eid, attr); if (mod == NULL) { - ret = LDB_ERR_OTHER; - goto done; + return LDB_ERR_OPERATIONS_ERROR; } ret = sqlite3_exec(lsqlite3->sqlite, mod, NULL, NULL, &errmsg); if (ret != SQLITE_OK) { if (errmsg) { - ldb_set_errstring(module->ldb, errmsg); + ldb_set_errstring(ldb, errmsg); free(errmsg); } - ret = LDB_ERR_OTHER; - goto done; + return LDB_ERR_OPERATIONS_ERROR; } /* MISSING break is INTENTIONAL */ @@ -1165,13 +1164,12 @@ static int lsql_modify(struct ldb_module *module, struct ldb_request *req) struct ldb_val value; /* Get a canonicalised copy of the data */ - a->syntax->canonicalise_fn(module->ldb, lsql_ac, &(el->values[j]), &value); + a->syntax->canonicalise_fn(ldb, ctx, &(el->values[j]), &value); if (value.data == NULL) { - ret = LDB_ERR_OTHER; - goto done; + return LDB_ERR_OPERATIONS_ERROR; } - mod = lsqlite3_tprintf(lsql_ac, + mod = lsqlite3_tprintf(ctx, "INSERT OR ROLLBACK INTO ldb_attribute_values " "('eid', 'attr_name', 'norm_attr_name'," " 'attr_value', 'norm_attr_value') " @@ -1180,18 +1178,16 @@ static int lsql_modify(struct ldb_module *module, struct ldb_request *req) el->values[j].data, value.data); if (mod == NULL) { - ret = LDB_ERR_OTHER; - goto done; + return LDB_ERR_OPERATIONS_ERROR; } ret = sqlite3_exec(lsqlite3->sqlite, mod, NULL, NULL, &errmsg); if (ret != SQLITE_OK) { if (errmsg) { - ldb_set_errstring(module->ldb, errmsg); + ldb_set_errstring(ldb, errmsg); free(errmsg); } - ret = LDB_ERR_OTHER; - goto done; + return LDB_ERR_OPERATIONS_ERROR; } } @@ -1200,24 +1196,22 @@ static int lsql_modify(struct ldb_module *module, struct ldb_request *req) case LDB_FLAG_MOD_DELETE: #warning "We should throw an error if the attribute we are trying to delete does not exist!" if (el->num_values == 0) { - mod = lsqlite3_tprintf(lsql_ac, + mod = lsqlite3_tprintf(ctx, "DELETE FROM ldb_attribute_values " "WHERE eid = '%lld' " "AND norm_attr_name = '%q';", eid, attr); if (mod == NULL) { - ret = LDB_ERR_OTHER; - goto done; + return LDB_ERR_OPERATIONS_ERROR; } ret = sqlite3_exec(lsqlite3->sqlite, mod, NULL, NULL, &errmsg); if (ret != SQLITE_OK) { if (errmsg) { - ldb_set_errstring(module->ldb, errmsg); + ldb_set_errstring(ldb, errmsg); free(errmsg); } - ret = LDB_ERR_OTHER; - goto done; + return LDB_ERR_OPERATIONS_ERROR; } } @@ -1226,13 +1220,12 @@ static int lsql_modify(struct ldb_module *module, struct ldb_request *req) struct ldb_val value; /* Get a canonicalised copy of the data */ - a->syntax->canonicalise_fn(module->ldb, lsql_ac, &(el->values[j]), &value); + a->syntax->canonicalise_fn(ldb, ctx, &(el->values[j]), &value); if (value.data == NULL) { - ret = LDB_ERR_OTHER; - goto done; + return LDB_ERR_OPERATIONS_ERROR; } - mod = lsqlite3_tprintf(lsql_ac, + mod = lsqlite3_tprintf(ctx, "DELETE FROM ldb_attribute_values " "WHERE eid = '%lld' " "AND norm_attr_name = '%q' " @@ -1240,18 +1233,16 @@ static int lsql_modify(struct ldb_module *module, struct ldb_request *req) eid, attr, value.data); if (mod == NULL) { - ret = LDB_ERR_OTHER; - goto done; + return LDB_ERR_OPERATIONS_ERROR; } ret = sqlite3_exec(lsqlite3->sqlite, mod, NULL, NULL, &errmsg); if (ret != SQLITE_OK) { if (errmsg) { - ldb_set_errstring(module->ldb, errmsg); + ldb_set_errstring(ldb, errmsg); free(errmsg); } - ret = LDB_ERR_OTHER; - goto done; + return LDB_ERR_OPERATIONS_ERROR; } } @@ -1259,121 +1250,106 @@ static int lsql_modify(struct ldb_module *module, struct ldb_request *req) } } - if (lsql_ac->callback) { - req->handle->status = lsql_ac->callback(module->ldb, lsql_ac->context, NULL); - } - -done: - req->handle->state = LDB_ASYNC_DONE; - return ret; + return LDB_SUCCESS; } /* delete a record */ -static int lsql_delete(struct ldb_module *module, struct ldb_request *req) +static int lsql_delete(struct lsql_context *ctx) { - struct lsqlite3_private *lsqlite3 = talloc_get_type(module->private_data, struct lsqlite3_private); - struct lsql_context *lsql_ac; + struct ldb_module *module = ctx->module; + struct ldb_request *req = ctx->req; + struct lsqlite3_private *lsqlite3; + struct ldb_context *ldb; long long eid; char *errmsg; char *query; - int ret = LDB_SUCCESS; - + int ret; - lsql_ac = talloc_get_type(req->handle->private_data, struct lsql_context); - req->handle->state = LDB_ASYNC_DONE; - req->handle->status = LDB_SUCCESS; + ldb = ldb_module_get_ctx(module); + lsqlite3 = talloc_get_type(ldb_module_get_private(module), + struct lsqlite3_private); - eid = lsqlite3_get_eid(module, req->op.del.dn); + eid = lsqlite3_get_eid(lsqlite3, req->op.del.dn); if (eid == -1) { - goto done; + return LDB_ERR_OPERATIONS_ERROR; } - query = lsqlite3_tprintf(lsql_ac, + query = lsqlite3_tprintf(ctx, /* Delete entry */ "DELETE FROM ldb_entry WHERE eid = %lld; " /* Delete attributes */ "DELETE FROM ldb_attribute_values WHERE eid = %lld; ", eid, eid); if (query == NULL) { - ret = LDB_ERR_OTHER; - goto done; + return LDB_ERR_OPERATIONS_ERROR; } ret = sqlite3_exec(lsqlite3->sqlite, query, NULL, NULL, &errmsg); if (ret != SQLITE_OK) { if (errmsg) { - ldb_set_errstring(module->ldb, errmsg); + ldb_set_errstring(ldb, errmsg); free(errmsg); } - req->handle->status = LDB_ERR_OPERATIONS_ERROR; - goto done; + return LDB_ERR_OPERATIONS_ERROR; } - if (lsql_ac->callback) { - ret = lsql_ac->callback(module->ldb, lsql_ac->context, NULL); - } - -done: - req->handle->state = LDB_ASYNC_DONE; - return ret; + return LDB_SUCCESS; } /* rename a record */ -static int lsql_rename(struct ldb_module *module, struct ldb_request *req) +static int lsql_rename(struct lsql_context *ctx) { - struct lsqlite3_private *lsqlite3 = talloc_get_type(module->private_data, struct lsqlite3_private); - struct lsql_context *lsql_ac; + struct ldb_module *module = ctx->module; + struct ldb_request *req = ctx->req; + struct lsqlite3_private *lsqlite3; + struct ldb_context *ldb; char *new_dn, *new_cdn, *old_cdn; char *errmsg; char *query; - int ret = LDB_SUCCESS; + int ret; - lsql_ac = talloc_get_type(req->handle->private_data, struct lsql_context); - req->handle->state = LDB_ASYNC_DONE; - req->handle->status = LDB_SUCCESS; + ldb = ldb_module_get_ctx(module); + lsqlite3 = talloc_get_type(ldb_module_get_private(module), + struct lsqlite3_private); /* create linearized and normalized dns */ - old_cdn = ldb_dn_alloc_casefold(lsql_ac, req->op.rename.olddn); - new_cdn = ldb_dn_alloc_casefold(lsql_ac, req->op.rename.newdn); - new_dn = ldb_dn_alloc_linearized(lsql_ac, req->op.rename.newdn); + old_cdn = ldb_dn_alloc_casefold(ctx, req->op.rename.olddn); + new_cdn = ldb_dn_alloc_casefold(ctx, req->op.rename.newdn); + new_dn = ldb_dn_alloc_linearized(ctx, req->op.rename.newdn); if (old_cdn == NULL || new_cdn == NULL || new_dn == NULL) { - goto done; + return LDB_ERR_OPERATIONS_ERROR; } /* build the SQL query */ - query = lsqlite3_tprintf(lsql_ac, + query = lsqlite3_tprintf(ctx, "UPDATE ldb_entry SET dn = '%q', norm_dn = '%q' " "WHERE norm_dn = '%q';", new_dn, new_cdn, old_cdn); if (query == NULL) { - goto done; + return LDB_ERR_OPERATIONS_ERROR; } /* execute */ ret = sqlite3_exec(lsqlite3->sqlite, query, NULL, NULL, &errmsg); if (ret != SQLITE_OK) { if (errmsg) { - ldb_set_errstring(module->ldb, errmsg); + ldb_set_errstring(ldb, errmsg); free(errmsg); } - ret = LDB_ERR_OPERATIONS_ERROR; - goto done; - } - - if (lsql_ac->callback) { - ret = lsql_ac->callback(module->ldb, lsql_ac->context, NULL); + return LDB_ERR_OPERATIONS_ERROR; } -done: - req->handle->state = LDB_ASYNC_DONE; - return ret; + return LDB_SUCCESS; } static int lsql_start_trans(struct ldb_module * module) { int ret; char *errmsg; - struct lsqlite3_private * lsqlite3 = module->private_data; + struct lsqlite3_private *lsqlite3; + + lsqlite3 = talloc_get_type(ldb_module_get_private(module), + struct lsqlite3_private); if (lsqlite3->trans_count == 0) { ret = sqlite3_exec(lsqlite3->sqlite, "BEGIN IMMEDIATE;", NULL, NULL, &errmsg); @@ -1395,7 +1371,10 @@ static int lsql_end_trans(struct ldb_module *module) { int ret; char *errmsg; - struct lsqlite3_private *lsqlite3 = module->private_data; + struct lsqlite3_private *lsqlite3; + + lsqlite3 = talloc_get_type(ldb_module_get_private(module), + struct lsqlite3_private); if (lsqlite3->trans_count > 0) { lsqlite3->trans_count--; @@ -1417,7 +1396,10 @@ static int lsql_end_trans(struct ldb_module *module) static int lsql_del_trans(struct ldb_module *module) { - struct lsqlite3_private *lsqlite3 = module->private_data; + struct lsqlite3_private *lsqlite3; + + lsqlite3 = talloc_get_type(ldb_module_get_private(module), + struct lsqlite3_private); if (lsqlite3->trans_count > 0) { lsqlite3->trans_count--; @@ -1431,69 +1413,132 @@ static int lsql_del_trans(struct ldb_module *module) } static int destructor(struct lsqlite3_private *lsqlite3) -{ +{ if (lsqlite3->sqlite) { sqlite3_close(lsqlite3->sqlite); } return 0; } -static int lsql_request(struct ldb_module *module, struct ldb_request *req) +static void lsql_request_done(struct lsql_context *ctx, int error) { - return LDB_ERR_OPERATIONS_ERROR; + struct ldb_context *ldb; + struct ldb_request *req; + struct ldb_reply *ares; + + ldb = ldb_module_get_ctx(ctx->module); + req = ctx->req; + + /* if we already returned an error just return */ + if (ldb_request_get_status(req) != LDB_SUCCESS) { + return; + } + + ares = talloc_zero(req, struct ldb_reply); + if (!ares) { + ldb_oom(ldb); + req->callback(req, NULL); + return; + } + ares->type = LDB_REPLY_DONE; + ares->error = error; + + req->callback(req, ares); +} + +static void lsql_timeout(struct tevent_context *ev, + struct tevent_timer *te, + struct timeval t, + void *private_data) +{ + struct lsql_context *ctx; + ctx = talloc_get_type(private_data, struct lsql_context); + + lsql_request_done(ctx, LDB_ERR_TIME_LIMIT_EXCEEDED); } -static int lsql_run_request(struct ldb_module *module, struct ldb_request *req) +static void lsql_callback(struct tevent_context *ev, + struct tevent_timer *te, + struct timeval t, + void *private_data) { - switch (req->operation) { + struct lsql_context *ctx; + int ret; + + ctx = talloc_get_type(private_data, struct lsql_context); + + switch (ctx->req->operation) { case LDB_SEARCH: - return lsql_search(module, req); + ret = lsql_search(ctx); break; case LDB_ADD: - return lsql_add(module, req); + ret = lsql_add(ctx); break; case LDB_MODIFY: - return lsql_modify(module, req); + ret = lsql_modify(ctx); break; case LDB_DELETE: - return lsql_delete(module, req); + ret = lsql_delete(ctx); break; case LDB_RENAME: - return lsql_rename(module, req); + ret = lsql_rename(ctx); break; /* TODO: - case LDB_SEQUENCE_NUMBER: - return lsql_sequence_number(module, req); + case LDB_EXTENDED: + ret = lsql_extended(ctx); break; */ default: - return lsql_request(module, req); - break; + /* no other op supported */ + ret = LDB_ERR_UNWILLING_TO_PERFORM; } - return LDB_ERR_OPERATIONS_ERROR; + if (!ctx->callback_failed) { + /* Once we are done, we do not need timeout events */ + talloc_free(ctx->timeout_event); + lsql_request_done(ctx, ret); + } } static int lsql_handle_request(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; + struct tevent_context *ev; struct lsql_context *ac; + struct tevent_timer *te; + struct timeval tv; if (check_critical_controls(req->controls)) { return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; } + if (req->starttime == 0 || req->timeout == 0) { + ldb_set_errstring(ldb, "Invalid timeout settings"); + return LDB_ERR_TIME_LIMIT_EXCEEDED; + } + + ldb = ldb_module_get_ctx(module); + ev = ldb_get_event_context(ldb); + ac = talloc_zero(req, struct lsql_context); if (ac == NULL) { - ldb_set_errstring(module->ldb, "Out of Memory"); + ldb_set_errstring(ldb, "Out of Memory"); return LDB_ERR_OPERATIONS_ERROR; } ac->module = module; ac->req = req; - req->handle = ldb_handle_new(req, lsql_run_request, ac); - if (req->handle == NULL) { - talloc_free(ac); + tv.tv_sec = 0; + tv.tv_usec = 0; + te = tevent_add_timer(ev, ac, tv, lsql_callback, ac); + if (NULL == te) { + return LDB_ERR_OPERATIONS_ERROR; + } + + tv.tv_sec = req->starttime + req->timeout; + ac->timeout_event = tevent_add_timer(ev, ac, tv, lsql_timeout, ac); + if (NULL == ac->timeout_event) { return LDB_ERR_OPERATIONS_ERROR; } @@ -1510,11 +1555,10 @@ static const struct ldb_module_ops lsqlite3_ops = { .modify = lsql_handle_request, .del = lsql_handle_request, .rename = lsql_handle_request, - .request = lsql_handle_request, + .extended = lsql_handle_request, .start_transaction = lsql_start_trans, .end_transaction = lsql_end_trans, .del_transaction = lsql_del_trans, - /* TODO: .sequence_number = lsql_handle_request */ }; /* @@ -1538,15 +1582,15 @@ static int initialize(struct lsqlite3_private *lsqlite3, } schema = lsqlite3_tprintf(local_ctx, - - + + "CREATE TABLE ldb_info AS " " SELECT 'LDB' AS database_type," " '1.0' AS version;" - + /* - * The entry table holds the information about an entry. - * This table is used to obtain the EID of the entry and to + * The entry table holds the information about an entry. + * This table is used to obtain the EID of the entry and to * support scope=one and scope=base. The parent and child * table is included in the entry table since all the other * attributes are dependent on EID. @@ -1557,7 +1601,7 @@ static int initialize(struct lsqlite3_private *lsqlite3, " dn TEXT UNIQUE NOT NULL," " norm_dn TEXT UNIQUE NOT NULL" ");" - + "CREATE TABLE ldb_object_classes" "(" @@ -1566,7 +1610,7 @@ static int initialize(struct lsqlite3_private *lsqlite3, " tree_key TEXT UNIQUE," " max_child_num INTEGER DEFAULT 0" ");" - + /* * We keep a full listing of attribute/value pairs here */ @@ -1578,23 +1622,23 @@ static int initialize(struct lsqlite3_private *lsqlite3, " attr_value TEXT," " norm_attr_value TEXT " ");" - - + + /* * Indexes */ "CREATE INDEX ldb_attribute_values_eid_idx " " ON ldb_attribute_values (eid);" - + "CREATE INDEX ldb_attribute_values_name_value_idx " " ON ldb_attribute_values (attr_name, norm_attr_value);" - - + + /* * Triggers */ - + "CREATE TRIGGER ldb_object_classes_insert_tr" " AFTER INSERT" " ON ldb_object_classes" @@ -1624,20 +1668,20 @@ static int initialize(struct lsqlite3_private *lsqlite3, " (class_name, tree_key) " " VALUES " " ('TOP', '0001');"); - + /* Skip protocol indicator of url */ if (strncmp(url, "sqlite3://", 10) != 0) { return SQLITE_MISUSE; } - + /* Update pointer to just after the protocol indicator */ url += 10; - + /* Try to open the (possibly empty/non-existent) database */ if ((ret = sqlite3_open(url, &lsqlite3->sqlite)) != SQLITE_OK) { return ret; } - + /* In case this is a new database, enable auto_vacuum */ ret = sqlite3_exec(lsqlite3->sqlite, "PRAGMA auto_vacuum = 1;", NULL, NULL, &errmsg); if (ret != SQLITE_OK) { @@ -1647,7 +1691,7 @@ static int initialize(struct lsqlite3_private *lsqlite3, } goto failed; } - + if (flags & LDB_FLG_NOSYNC) { /* DANGEROUS */ ret = sqlite3_exec(lsqlite3->sqlite, "PRAGMA synchronous = OFF;", NULL, NULL, &errmsg); @@ -1659,9 +1703,9 @@ static int initialize(struct lsqlite3_private *lsqlite3, goto failed; } } - + /* */ - + /* Establish a busy timeout of 30 seconds */ if ((ret = sqlite3_busy_timeout(lsqlite3->sqlite, 30000)) != SQLITE_OK) { @@ -1720,7 +1764,7 @@ static int initialize(struct lsqlite3_private *lsqlite3, goto failed; } rollback = 1; - + /* Determine if this is a new database. No tables means it is. */ if (query_int(lsqlite3, &queryInt, @@ -1729,7 +1773,7 @@ static int initialize(struct lsqlite3_private *lsqlite3, " WHERE type = 'table';") != 0) { goto failed; } - + if (queryInt == 0) { /* * Create the database schema @@ -1765,12 +1809,12 @@ static int initialize(struct lsqlite3_private *lsqlite3, " AND version = '1.0'" " );") != 0 || queryInt != 1) { - + /* It's not one that we created. See ya! */ goto failed; } } - + /* Commit the transaction */ ret = sqlite3_exec(lsqlite3->sqlite, "COMMIT;", NULL, NULL, &errmsg); if (ret != SQLITE_OK) { @@ -1780,11 +1824,11 @@ static int initialize(struct lsqlite3_private *lsqlite3, } goto failed; } - + return SQLITE_OK; failed: - if (rollback) lsqlite3_safe_rollback(lsqlite3->sqlite); + if (rollback) lsqlite3_safe_rollback(lsqlite3->sqlite); sqlite3_close(lsqlite3->sqlite); return -1; } @@ -1793,43 +1837,35 @@ failed: * connect to the database */ static int lsqlite3_connect(struct ldb_context *ldb, - const char *url, - unsigned int flags, + const char *url, + unsigned int flags, const char *options[], - struct ldb_module **module) + struct ldb_module **_module) { - int i; - int ret; - struct lsqlite3_private * lsqlite3 = NULL; - - lsqlite3 = talloc(ldb, struct lsqlite3_private); + struct ldb_module *module; + struct lsqlite3_private *lsqlite3; + int i, ret; + + module = ldb_module_new(ldb, ldb, "ldb_sqlite3 backend", &lsqlite3_ops); + if (!module) return -1; + + lsqlite3 = talloc(module, struct lsqlite3_private); if (!lsqlite3) { goto failed; } - + lsqlite3->sqlite = NULL; lsqlite3->options = NULL; lsqlite3->trans_count = 0; - + ret = initialize(lsqlite3, ldb, url, flags); if (ret != SQLITE_OK) { goto failed; } - - talloc_set_destructor(lsqlite3, destructor); - + talloc_set_destructor(lsqlite3, destructor); - *module = talloc(ldb, struct ldb_module); - if (!module) { - ldb_oom(ldb); - goto failed; - } - talloc_set_name_const(*module, "ldb_sqlite3 backend"); - (*module)->ldb = ldb; - (*module)->prev = (*module)->next = NULL; - (*module)->private_data = lsqlite3; - (*module)->ops = &lsqlite3_ops; + ldb_module_set_private(module, lsqlite3); if (options) { /* @@ -1837,14 +1873,14 @@ static int lsqlite3_connect(struct ldb_context *ldb, * on the caller keeping it around (it might be dynamic) */ for (i=0;options[i];i++) ; - + lsqlite3->options = talloc_array(lsqlite3, char *, i+1); if (!lsqlite3->options) { goto failed; } - + for (i=0;options[i];i++) { - + lsqlite3->options[i+1] = NULL; lsqlite3->options[i] = talloc_strdup(lsqlite3->options, options[i]); @@ -1853,11 +1889,12 @@ static int lsqlite3_connect(struct ldb_context *ldb, } } } - + + *_module = module; return 0; - + failed: - if (lsqlite3->sqlite != NULL) { + if (lsqlite3 && lsqlite3->sqlite != NULL) { (void) sqlite3_close(lsqlite3->sqlite); } talloc_free(lsqlite3); diff --git a/source4/lib/ldb/ldb_tdb/ldb_cache.c b/source4/lib/ldb/ldb_tdb/ldb_cache.c index 2576e2c7bd..43b965f239 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source4/lib/ldb/ldb_tdb/ldb_cache.c @@ -31,8 +31,6 @@ * Author: Andrew Tridgell */ -#include "ldb_includes.h" - #include "ldb_tdb.h" #define LTDB_FLAG_CASE_INSENSITIVE (1<<0) @@ -57,10 +55,14 @@ static const struct { */ static void ltdb_attributes_unload(struct ldb_module *module) { - struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; + struct ldb_context *ldb; + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); struct ldb_message *msg; int i; + ldb = ldb_module_get_ctx(module); + if (ltdb->cache->attributes == NULL) { /* no previously loaded attributes */ return; @@ -68,7 +70,7 @@ static void ltdb_attributes_unload(struct ldb_module *module) msg = ltdb->cache->attributes; for (i=0;i<msg->num_elements;i++) { - ldb_schema_attribute_remove(module->ldb, msg->elements[i].name); + ldb_schema_attribute_remove(ldb, msg->elements[i].name); } talloc_free(ltdb->cache->attributes); @@ -104,12 +106,16 @@ static int ltdb_attributes_flags(struct ldb_message_element *el, unsigned *v) */ static int ltdb_attributes_load(struct ldb_module *module) { - struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; + struct ldb_context *ldb; + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); struct ldb_message *msg = ltdb->cache->attributes; struct ldb_dn *dn; int i, r; - dn = ldb_dn_new(module, module->ldb, LTDB_ATTRIBUTES); + ldb = ldb_module_get_ctx(module); + + dn = ldb_dn_new(module, ldb, LTDB_ATTRIBUTES); if (dn == NULL) goto failed; r = ltdb_search_dn1(module, dn, msg); @@ -128,7 +134,7 @@ static int ltdb_attributes_load(struct ldb_module *module) const struct ldb_schema_syntax *s; if (ltdb_attributes_flags(&msg->elements[i], &flags) != 0) { - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "Invalid @ATTRIBUTES element for '%s'\n", msg->elements[i].name); + ldb_debug(ldb, LDB_DEBUG_ERROR, "Invalid @ATTRIBUTES element for '%s'\n", msg->elements[i].name); goto failed; } switch (flags & ~LTDB_FLAG_HIDDEN) { @@ -142,22 +148,22 @@ static int ltdb_attributes_load(struct ldb_module *module) syntax = LDB_SYNTAX_INTEGER; break; default: - ldb_debug(module->ldb, LDB_DEBUG_ERROR, + ldb_debug(ldb, LDB_DEBUG_ERROR, "Invalid flag combination 0x%x for '%s' in @ATTRIBUTES\n", flags, msg->elements[i].name); goto failed; } - s = ldb_standard_syntax_by_name(module->ldb, syntax); + s = ldb_standard_syntax_by_name(ldb, syntax); if (s == NULL) { - ldb_debug(module->ldb, LDB_DEBUG_ERROR, + ldb_debug(ldb, LDB_DEBUG_ERROR, "Invalid attribute syntax '%s' for '%s' in @ATTRIBUTES\n", syntax, msg->elements[i].name); goto failed; } flags |= LDB_ATTR_FLAG_ALLOCATED; - if (ldb_schema_attribute_add_with_syntax(module->ldb, msg->elements[i].name, flags, s) != 0) { + if (ldb_schema_attribute_add_with_syntax(ldb, msg->elements[i].name, flags, s) != 0) { goto failed; } } @@ -173,7 +179,9 @@ failed: */ static int ltdb_baseinfo_init(struct ldb_module *module) { - struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; + struct ldb_context *ldb; + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); struct ldb_message *msg; struct ldb_message_element el; struct ldb_val val; @@ -183,6 +191,8 @@ static int ltdb_baseinfo_init(struct ldb_module *module) out. */ const char *initial_sequence_number = "1"; + ldb = ldb_module_get_ctx(module); + ltdb->sequence_number = atof(initial_sequence_number); msg = talloc(ltdb, struct ldb_message); @@ -192,7 +202,7 @@ static int ltdb_baseinfo_init(struct ldb_module *module) msg->num_elements = 1; msg->elements = ⪙ - msg->dn = ldb_dn_new(msg, module->ldb, LTDB_BASEINFO); + msg->dn = ldb_dn_new(msg, ldb, LTDB_BASEINFO); if (!msg->dn) { goto failed; } @@ -226,7 +236,8 @@ failed: */ static void ltdb_cache_free(struct ldb_module *module) { - struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); ltdb->sequence_number = 0; talloc_free(ltdb->cache); @@ -248,13 +259,17 @@ int ltdb_cache_reload(struct ldb_module *module) */ int ltdb_cache_load(struct ldb_module *module) { - struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; + struct ldb_context *ldb; + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); struct ldb_dn *baseinfo_dn = NULL, *options_dn = NULL; struct ldb_dn *indexlist_dn = NULL; uint64_t seq; struct ldb_message *baseinfo = NULL, *options = NULL; int r; + ldb = ldb_module_get_ctx(module); + /* a very fast check to avoid extra database reads */ if (ltdb->cache != NULL && tdb_get_seqnum(ltdb->tdb) == ltdb->tdb_seqnum) { @@ -275,7 +290,7 @@ int ltdb_cache_load(struct ldb_module *module) baseinfo = talloc(ltdb->cache, struct ldb_message); if (baseinfo == NULL) goto failed; - baseinfo_dn = ldb_dn_new(module, module->ldb, LTDB_BASEINFO); + baseinfo_dn = ldb_dn_new(module, ldb, LTDB_BASEINFO); if (baseinfo_dn == NULL) goto failed; r= ltdb_search_dn1(module, baseinfo_dn, baseinfo); @@ -307,7 +322,7 @@ int ltdb_cache_load(struct ldb_module *module) options = talloc(ltdb->cache, struct ldb_message); if (options == NULL) goto failed; - options_dn = ldb_dn_new(options, module->ldb, LTDB_OPTIONS); + options_dn = ldb_dn_new(options, ldb, LTDB_OPTIONS); if (options_dn == NULL) goto failed; r= ltdb_search_dn1(module, options_dn, options); @@ -336,7 +351,7 @@ int ltdb_cache_load(struct ldb_module *module) goto failed; } - indexlist_dn = ldb_dn_new(module, module->ldb, LTDB_INDEXLIST); + indexlist_dn = ldb_dn_new(module, ldb, LTDB_INDEXLIST); if (indexlist_dn == NULL) goto failed; r = ltdb_search_dn1(module, indexlist_dn, ltdb->cache->indexlist); @@ -369,7 +384,9 @@ failed: */ int ltdb_increase_sequence_number(struct ldb_module *module) { - struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; + struct ldb_context *ldb; + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); struct ldb_message *msg; struct ldb_message_element el[2]; struct ldb_val val; @@ -378,6 +395,8 @@ int ltdb_increase_sequence_number(struct ldb_module *module) char *s = NULL; int ret; + ldb = ldb_module_get_ctx(module); + msg = talloc(ltdb, struct ldb_message); if (msg == NULL) { errno = ENOMEM; @@ -392,7 +411,7 @@ int ltdb_increase_sequence_number(struct ldb_module *module) msg->num_elements = ARRAY_SIZE(el); msg->elements = el; - msg->dn = ldb_dn_new(msg, module->ldb, LTDB_BASEINFO); + msg->dn = ldb_dn_new(msg, ldb, LTDB_BASEINFO); if (msg->dn == NULL) { talloc_free(msg); errno = ENOMEM; diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c index c4c23022f8..cdbef3944b 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_index.c +++ b/source4/lib/ldb/ldb_tdb/ldb_index.c @@ -31,8 +31,6 @@ * Author: Andrew Tridgell */ -#include "ldb_includes.h" - #include "ldb_tdb.h" /* @@ -69,8 +67,8 @@ struct ltdb_idxptr { */ static int ltdb_idxptr_add(struct ldb_module *module, const struct ldb_message *msg) { - struct ltdb_private *ltdb = - talloc_get_type(module->private_data, struct ltdb_private); + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); ltdb->idxptr->dn_list = talloc_realloc(ltdb->idxptr, ltdb->idxptr->dn_list, const char *, ltdb->idxptr->num_dns+1); if (ltdb->idxptr->dn_list == NULL) { @@ -177,8 +175,8 @@ static int ltdb_convert_to_idxptr(struct ldb_module *module, struct ldb_message_ struct ldb_index_pointer *ptr, *tmp; int i; struct ldb_val *val2; - struct ltdb_private *ltdb = - talloc_get_type(module->private_data, struct ltdb_private); + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); ptr = NULL; @@ -216,8 +214,8 @@ static int ltdb_convert_to_idxptr(struct ldb_module *module, struct ldb_message_ /* enable the idxptr mode when transactions start */ int ltdb_index_transaction_start(struct ldb_module *module) { - struct ltdb_private *ltdb = - talloc_get_type(module->private_data, struct ltdb_private); + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); ltdb->idxptr = talloc_zero(module, struct ltdb_idxptr); return LDB_SUCCESS; } @@ -260,11 +258,14 @@ static int ltdb_search_dn1_index(struct ldb_module *module, */ static int ltdb_idxptr_fix_dn(struct ldb_module *module, const char *strdn) { + struct ldb_context *ldb; struct ldb_dn *dn; struct ldb_message *msg = ldb_msg_new(module); int ret; - dn = ldb_dn_new(msg, module->ldb, strdn); + ldb = ldb_module_get_ctx(module); + + dn = ldb_dn_new(msg, ldb, strdn); if (ltdb_search_dn1_index(module, dn, msg) == LDB_SUCCESS) { ret = ltdb_store(module, msg, TDB_REPLACE); } @@ -276,8 +277,8 @@ static int ltdb_idxptr_fix_dn(struct ldb_module *module, const char *strdn) int ltdb_index_transaction_commit(struct ldb_module *module) { int i; - struct ltdb_private *ltdb = - talloc_get_type(module->private_data, struct ltdb_private); + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); /* fix all the DNs that we have modified */ if (ltdb->idxptr) { @@ -298,8 +299,8 @@ int ltdb_index_transaction_commit(struct ldb_module *module) /* cleanup the idxptr mode when transaction cancels */ int ltdb_index_transaction_cancel(struct ldb_module *module) { - struct ltdb_private *ltdb = - talloc_get_type(module->private_data, struct ltdb_private); + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); talloc_free(ltdb->idxptr); ltdb->idxptr = NULL; return LDB_SUCCESS; @@ -314,8 +315,8 @@ int ltdb_index_transaction_cancel(struct ldb_module *module) */ int ltdb_store_idxptr(struct ldb_module *module, const struct ldb_message *msg, int flgs) { - struct ltdb_private *ltdb = - talloc_get_type(module->private_data, struct ltdb_private); + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); int ret; if (ltdb->idxptr) { @@ -510,12 +511,14 @@ static int ltdb_index_dn_simple(struct ldb_module *module, const struct ldb_message *index_list, struct dn_list *list) { - struct ldb_context *ldb = module->ldb; + struct ldb_context *ldb; struct ldb_dn *dn; int ret; unsigned int i, j; struct ldb_message *msg; + ldb = ldb_module_get_ctx(module); + list->count = 0; list->dn = NULL; @@ -587,15 +590,18 @@ static int ltdb_index_dn_leaf(struct ldb_module *module, const struct ldb_message *index_list, struct dn_list *list) { + struct ldb_context *ldb; + ldb = ldb_module_get_ctx(module); + if (ldb_attr_dn(tree->u.equality.attr) == 0) { list->dn = talloc_array(list, char *, 1); if (list->dn == NULL) { - ldb_oom(module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } list->dn[0] = talloc_strdup(list->dn, (char *)tree->u.equality.value.data); if (list->dn[0] == NULL) { - ldb_oom(module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } list->count = 1; @@ -707,10 +713,12 @@ static int ltdb_index_dn_or(struct ldb_module *module, const struct ldb_message *index_list, struct dn_list *list) { - struct ldb_context *ldb = module->ldb; + struct ldb_context *ldb; unsigned int i; int ret; + ldb = ldb_module_get_ctx(module); + ret = LDB_ERR_OPERATIONS_ERROR; list->dn = NULL; list->count = 0; @@ -791,10 +799,12 @@ static int ltdb_index_dn_and(struct ldb_module *module, const struct ldb_message *index_list, struct dn_list *list) { - struct ldb_context *ldb = module->ldb; + struct ldb_context *ldb; unsigned int i; int ret; + ldb = ldb_module_get_ctx(module); + ret = LDB_ERR_OPERATIONS_ERROR; list->dn = NULL; list->count = 0; @@ -852,7 +862,7 @@ static int ltdb_index_dn_one(struct ldb_module *module, struct ldb_dn *parent_dn, struct dn_list *list) { - struct ldb_context *ldb = module->ldb; + struct ldb_context *ldb; struct dn_list *list2; struct ldb_message *msg; struct ldb_dn *key; @@ -860,6 +870,8 @@ static int ltdb_index_dn_one(struct ldb_module *module, unsigned int i, j; int ret; + ldb = ldb_module_get_ctx(module); + list2 = talloc_zero(module, struct dn_list); if (list2 == NULL) { return LDB_ERR_OPERATIONS_ERROR; @@ -991,9 +1003,12 @@ static int ltdb_index_dn(struct ldb_module *module, static int ltdb_index_filter(const struct dn_list *dn_list, struct ltdb_context *ac) { + struct ldb_context *ldb; struct ldb_message *msg; unsigned int i; + ldb = ldb_module_get_ctx(ac->module); + for (i = 0; i < dn_list->count; i++) { struct ldb_dn *dn; int ret; @@ -1003,7 +1018,7 @@ static int ltdb_index_filter(const struct dn_list *dn_list, return LDB_ERR_OPERATIONS_ERROR; } - dn = ldb_dn_new(msg, ac->module->ldb, dn_list->dn[i]); + dn = ldb_dn_new(msg, ldb, dn_list->dn[i]); if (dn == NULL) { talloc_free(msg); return LDB_ERR_OPERATIONS_ERROR; @@ -1023,7 +1038,7 @@ static int ltdb_index_filter(const struct dn_list *dn_list, return LDB_ERR_OPERATIONS_ERROR; } - if (!ldb_match_msg(ac->module->ldb, msg, + if (!ldb_match_msg(ldb, msg, ac->tree, ac->base, ac->scope)) { talloc_free(msg); continue; @@ -1054,10 +1069,14 @@ static int ltdb_index_filter(const struct dn_list *dn_list, */ int ltdb_search_indexed(struct ltdb_context *ac) { - struct ltdb_private *ltdb = talloc_get_type(ac->module->private_data, struct ltdb_private); + struct ldb_context *ldb; + void *data = ldb_module_get_private(ac->module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); struct dn_list *dn_list; int ret, idxattr, idxone; + ldb = ldb_module_get_ctx(ac->module); + idxattr = idxone = 0; ret = ldb_msg_find_idx(ltdb->cache->indexlist, NULL, NULL, LTDB_IDXATTR); if (ret == 0 ) { @@ -1087,12 +1106,12 @@ int ltdb_search_indexed(struct ltdb_context *ac) /* with BASE searches only one DN can match */ dn_list->dn = talloc_array(dn_list, char *, 1); if (dn_list->dn == NULL) { - ldb_oom(ac->module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } dn_list->dn[0] = ldb_dn_alloc_linearized(dn_list, ac->base); if (dn_list->dn[0] == NULL) { - ldb_oom(ac->module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } dn_list->count = 1; @@ -1198,12 +1217,14 @@ static int ltdb_index_add1_add(struct ldb_context *ldb, static int ltdb_index_add1(struct ldb_module *module, const char *dn, struct ldb_message_element *el, int v_idx) { - struct ldb_context *ldb = module->ldb; + struct ldb_context *ldb; struct ldb_message *msg; struct ldb_dn *dn_key; int ret; unsigned int i; + ldb = ldb_module_get_ctx(module); + msg = talloc(module, struct ldb_message); if (msg == NULL) { errno = ENOMEM; @@ -1253,7 +1274,8 @@ static int ltdb_index_add1(struct ldb_module *module, const char *dn, static int ltdb_index_add0(struct ldb_module *module, const char *dn, struct ldb_message_element *elements, int num_el) { - struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); int ret; unsigned int i, j; @@ -1308,12 +1330,14 @@ int ltdb_index_add(struct ldb_module *module, const struct ldb_message *msg) int ltdb_index_del_value(struct ldb_module *module, const char *dn, struct ldb_message_element *el, int v_idx) { - struct ldb_context *ldb = module->ldb; + struct ldb_context *ldb; struct ldb_message *msg; struct ldb_dn *dn_key; int ret, i; unsigned int j; + ldb = ldb_module_get_ctx(module); + if (dn[0] == '@') { return LDB_SUCCESS; } @@ -1351,7 +1375,7 @@ int ltdb_index_del_value(struct ldb_module *module, const char *dn, ldb_dn_get_linearized(dn_key)); ldif.changetype = LDB_CHANGETYPE_NONE; ldif.msg = msg; - ldb_ldif_write_file(module->ldb, stdout, &ldif); + ldb_ldif_write_file(ldb, stdout, &ldif); sleep(100); /* it ain't there. hmmm */ talloc_free(dn_key); @@ -1383,7 +1407,8 @@ int ltdb_index_del_value(struct ldb_module *module, const char *dn, */ int ltdb_index_del(struct ldb_module *module, const struct ldb_message *msg) { - struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); int ret; const char *dn; unsigned int i, j; @@ -1425,7 +1450,8 @@ int ltdb_index_del(struct ldb_module *module, const struct ldb_message *msg) */ int ltdb_index_one(struct ldb_module *module, const struct ldb_message *msg, int add) { - struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); struct ldb_message_element el; struct ldb_val val; struct ldb_dn *pdn; @@ -1489,12 +1515,15 @@ static int delete_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, vo */ static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state) { + struct ldb_context *ldb; struct ldb_module *module = (struct ldb_module *)state; struct ldb_message *msg; const char *dn = NULL; int ret; TDB_DATA key2; + ldb = ldb_module_get_ctx(module); + if (strncmp((char *)key.dptr, "DN=@", 4) == 0 || strncmp((char *)key.dptr, "DN=", 3) != 0) { return 0; @@ -1516,7 +1545,7 @@ static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void * key2 = ltdb_key(module, msg->dn); if (key2.dptr == NULL) { /* probably a corrupt record ... darn */ - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "Invalid DN in re_index: %s\n", + ldb_debug(ldb, LDB_DEBUG_ERROR, "Invalid DN in re_index: %s\n", ldb_dn_get_linearized(msg->dn)); talloc_free(msg); return 0; @@ -1537,7 +1566,7 @@ static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void * if (ret == LDB_SUCCESS) { ret = ltdb_index_add0(module, dn, msg->elements, msg->num_elements); } else { - ldb_debug(module->ldb, LDB_DEBUG_ERROR, + ldb_debug(ldb, LDB_DEBUG_ERROR, "Adding special ONE LEVEL index failed (%s)!\n", ldb_dn_get_linearized(msg->dn)); } @@ -1554,7 +1583,8 @@ static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void * */ int ltdb_reindex(struct ldb_module *module) { - struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); int ret; if (ltdb_cache_reload(module) != 0) { diff --git a/source4/lib/ldb/ldb_tdb/ldb_pack.c b/source4/lib/ldb/ldb_tdb/ldb_pack.c index afb07dcbca..1995606f88 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_pack.c +++ b/source4/lib/ldb/ldb_tdb/ldb_pack.c @@ -31,7 +31,6 @@ * Author: Andrew Tridgell */ -#include "ldb_includes.h" #include "ldb_tdb.h" /* change this if the data format ever changes */ @@ -79,13 +78,15 @@ int ltdb_pack_data(struct ldb_module *module, const struct ldb_message *message, struct TDB_DATA *data) { - struct ldb_context *ldb = module->ldb; + struct ldb_context *ldb; unsigned int i, j, real_elements=0; size_t size; const char *dn; uint8_t *p; size_t len; + ldb = ldb_module_get_ctx(module); + dn = ldb_dn_get_linearized(message->dn); if (dn == NULL) { errno = ENOMEM; @@ -159,13 +160,14 @@ int ltdb_unpack_data(struct ldb_module *module, const struct TDB_DATA *data, struct ldb_message *message) { - struct ldb_context *ldb = module->ldb; + struct ldb_context *ldb; uint8_t *p; unsigned int remaining; unsigned int i, j; unsigned format; size_t len; + ldb = ldb_module_get_ctx(module); message->elements = NULL; p = data->dptr; diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c index 35149c4b77..0f595267fc 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_search.c +++ b/source4/lib/ldb/ldb_tdb/ldb_search.c @@ -31,8 +31,6 @@ * Author: Andrew Tridgell */ -#include "ldb_includes.h" - #include "ldb_tdb.h" /* @@ -112,10 +110,12 @@ static int msg_add_distinguished_name(struct ldb_message *msg) static int msg_add_all_elements(struct ldb_module *module, struct ldb_message *ret, const struct ldb_message *msg) { - struct ldb_context *ldb = module->ldb; + struct ldb_context *ldb; unsigned int i; int check_duplicates = (ret->num_elements != 0); + ldb = ldb_module_get_ctx(module); + if (msg_add_distinguished_name(ret) != 0) { return -1; } @@ -207,7 +207,8 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, */ static int ltdb_search_base(struct ldb_module *module, struct ldb_dn *dn) { - struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); TDB_DATA tdb_key, tdb_data; if (ldb_dn_is_null(dn)) { @@ -239,7 +240,8 @@ static int ltdb_search_base(struct ldb_module *module, struct ldb_dn *dn) */ int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_message *msg) { - struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); int ret; TDB_DATA tdb_key, tdb_data; @@ -371,11 +373,13 @@ int ltdb_filter_attrs(struct ldb_message *msg, const char * const *attrs) */ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state) { + struct ldb_context *ldb; struct ltdb_context *ac; struct ldb_message *msg; int ret; ac = talloc_get_type(state, struct ltdb_context); + ldb = ldb_module_get_ctx(ac->module); if (key.dsize < 4 || strncmp((char *)key.dptr, "DN=", 3) != 0) { @@ -395,7 +399,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi } if (!msg->dn) { - msg->dn = ldb_dn_new(msg, ac->module->ldb, + msg->dn = ldb_dn_new(msg, ldb, (char *)key.dptr + 3); if (msg->dn == NULL) { talloc_free(msg); @@ -404,7 +408,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi } /* see if it matches the given expression */ - if (!ldb_match_msg(ac->module->ldb, msg, + if (!ldb_match_msg(ldb, msg, ac->tree, ac->base, ac->scope)) { talloc_free(msg); return 0; @@ -435,7 +439,8 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi */ static int ltdb_search_full(struct ltdb_context *ctx) { - struct ltdb_private *ltdb = talloc_get_type(ctx->module->private_data, struct ltdb_private); + void *data = ldb_module_get_private(ctx->module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); int ret; if (ltdb->in_transaction != 0) { @@ -457,12 +462,16 @@ static int ltdb_search_full(struct ltdb_context *ctx) */ int ltdb_search(struct ltdb_context *ctx) { + struct ldb_context *ldb; struct ldb_module *module = ctx->module; struct ldb_request *req = ctx->req; - struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private); + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); int ret; - req->handle->state = LDB_ASYNC_PENDING; + ldb = ldb_module_get_ctx(module); + + ldb_request_set_state(req, LDB_ASYNC_PENDING); if (ltdb_lock_read(module) != 0) { return LDB_ERR_OPERATIONS_ERROR; @@ -483,12 +492,12 @@ int ltdb_search(struct ltdb_context *ctx) /* Check what we should do with a NULL dn */ switch (req->op.search.scope) { case LDB_SCOPE_BASE: - ldb_asprintf_errstring(module->ldb, + ldb_asprintf_errstring(ldb, "NULL Base DN invalid for a base search"); ret = LDB_ERR_INVALID_DN_SYNTAX; break; case LDB_SCOPE_ONELEVEL: - ldb_asprintf_errstring(module->ldb, + ldb_asprintf_errstring(ldb, "NULL Base DN invalid for a one-level search"); ret = LDB_ERR_INVALID_DN_SYNTAX; break; @@ -500,7 +509,7 @@ int ltdb_search(struct ltdb_context *ctx) } else if (ldb_dn_is_valid(req->op.search.base) == false) { /* We don't want invalid base DNs here */ - ldb_asprintf_errstring(module->ldb, + ldb_asprintf_errstring(ldb, "Invalid Base DN: %s", ldb_dn_get_linearized(req->op.search.base)); ret = LDB_ERR_INVALID_DN_SYNTAX; @@ -510,7 +519,7 @@ int ltdb_search(struct ltdb_context *ctx) ret = ltdb_search_base(module, req->op.search.base); if (ret == LDB_ERR_NO_SUCH_OBJECT) { - ldb_asprintf_errstring(module->ldb, + ldb_asprintf_errstring(ldb, "No such Base DN: %s", ldb_dn_get_linearized(req->op.search.base)); } @@ -539,7 +548,7 @@ int ltdb_search(struct ltdb_context *ctx) /* Not indexed, so we need to do a full scan */ ret = ltdb_search_full(ctx); if (ret != LDB_SUCCESS) { - ldb_set_errstring(module->ldb, "Indexed and full searches both failed!\n"); + ldb_set_errstring(ldb, "Indexed and full searches both failed!\n"); } } } diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c index 9528f5a662..d6276c4b86 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c @@ -45,8 +45,6 @@ * Author: Simo Sorce */ -#include "ldb_includes.h" - #include "ldb_tdb.h" @@ -84,7 +82,8 @@ static int ltdb_err_map(enum TDB_ERROR tdb_code) */ int ltdb_lock_read(struct ldb_module *module) { - struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); if (ltdb->in_transaction == 0) { return tdb_lockall_read(ltdb->tdb); } @@ -96,7 +95,8 @@ int ltdb_lock_read(struct ldb_module *module) */ int ltdb_unlock_read(struct ldb_module *module) { - struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data; + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); if (ltdb->in_transaction == 0) { return tdb_unlockall_read(ltdb->tdb); } @@ -113,7 +113,7 @@ int ltdb_unlock_read(struct ldb_module *module) */ struct TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn) { - struct ldb_context *ldb = module->ldb; + struct ldb_context *ldb = ldb_module_get_ctx(module); TDB_DATA key; char *key_str = NULL; const char *dn_folded = NULL; @@ -164,6 +164,7 @@ failed: static int ltdb_check_special_dn(struct ldb_module *module, const struct ldb_message *msg) { + struct ldb_context *ldb = ldb_module_get_ctx(module); int i, j; if (! ldb_dn_is_special(msg->dn) || @@ -176,7 +177,7 @@ static int ltdb_check_special_dn(struct ldb_module *module, for (i = 0; i < msg->num_elements; i++) { for (j = 0; j < msg->elements[i].num_values; j++) { if (ltdb_check_at_attributes_values(&msg->elements[i].values[j]) != 0) { - ldb_set_errstring(module->ldb, "Invalid attribute value in an @ATTRIBUTES entry"); + ldb_set_errstring(ldb, "Invalid attribute value in an @ATTRIBUTES entry"); return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX; } } @@ -214,8 +215,8 @@ static int ltdb_modified(struct ldb_module *module, struct ldb_dn *dn) */ int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs) { - struct ltdb_private *ltdb = - talloc_get_type(module->private_data, struct ltdb_private); + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); TDB_DATA tdb_key, tdb_data; int ret; @@ -252,6 +253,7 @@ done: static int ltdb_add_internal(struct ldb_module *module, const struct ldb_message *msg) { + struct ldb_context *ldb = ldb_module_get_ctx(module); int ret; ret = ltdb_check_special_dn(module, msg); @@ -266,7 +268,7 @@ static int ltdb_add_internal(struct ldb_module *module, ret = ltdb_store(module, msg, TDB_INSERT); if (ret == LDB_ERR_ENTRY_ALREADY_EXISTS) { - ldb_asprintf_errstring(module->ldb, + ldb_asprintf_errstring(ldb, "Entry %s already exists", ldb_dn_get_linearized(msg->dn)); return ret; @@ -296,7 +298,7 @@ static int ltdb_add(struct ltdb_context *ctx) struct ldb_request *req = ctx->req; int tret; - req->handle->state = LDB_ASYNC_PENDING; + ldb_request_set_state(req, LDB_ASYNC_PENDING); tret = ltdb_add_internal(module, req->op.add.message); if (tret != LDB_SUCCESS) { @@ -312,8 +314,8 @@ static int ltdb_add(struct ltdb_context *ctx) */ int ltdb_delete_noindex(struct ldb_module *module, struct ldb_dn *dn) { - struct ltdb_private *ltdb = - talloc_get_type(module->private_data, struct ltdb_private); + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); TDB_DATA tdb_key; int ret; @@ -386,7 +388,7 @@ static int ltdb_delete(struct ltdb_context *ctx) struct ldb_request *req = ctx->req; int tret; - req->handle->state = LDB_ASYNC_PENDING; + ldb_request_set_state(req, LDB_ASYNC_PENDING); if (ltdb_cache_load(module) != 0) { return LDB_ERR_OPERATIONS_ERROR; @@ -514,7 +516,7 @@ static int msg_delete_element(struct ldb_module *module, const char *name, const struct ldb_val *val) { - struct ldb_context *ldb = module->ldb; + struct ldb_context *ldb = ldb_module_get_ctx(module); unsigned int i; int found; struct ldb_message_element *el; @@ -560,9 +562,9 @@ static int msg_delete_element(struct ldb_module *module, int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg) { - struct ldb_context *ldb = module->ldb; - struct ltdb_private *ltdb = - talloc_get_type(module->private_data, struct ltdb_private); + struct ldb_context *ldb = ldb_module_get_ctx(module); + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); TDB_DATA tdb_key, tdb_data; struct ldb_message *msg2; unsigned i, j; @@ -625,12 +627,12 @@ int ltdb_modify_internal(struct ldb_module *module, for (j=0;j<el->num_values;j++) { if (ldb_msg_find_val(el2, &el->values[j])) { - ldb_asprintf_errstring(module->ldb, "%s: value #%d already exists", el->name, j); + ldb_asprintf_errstring(ldb, "%s: value #%d already exists", el->name, j); ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS; goto failed; } if (ldb_msg_find_val(el, &el->values[j]) != &el->values[j]) { - ldb_asprintf_errstring(module->ldb, "%s: value #%d provided more than once", el->name, j); + ldb_asprintf_errstring(ldb, "%s: value #%d provided more than once", el->name, j); ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS; goto failed; } @@ -661,7 +663,7 @@ int ltdb_modify_internal(struct ldb_module *module, for (j=0;j<el->num_values;j++) { if (ldb_msg_find_val(el, &el->values[j]) != &el->values[j]) { - ldb_asprintf_errstring(module->ldb, "%s: value #%d provided more than once", el->name, j); + ldb_asprintf_errstring(ldb, "%s: value #%d provided more than once", el->name, j); ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS; goto failed; } @@ -688,7 +690,7 @@ int ltdb_modify_internal(struct ldb_module *module, if (msg->elements[i].num_values == 0) { if (msg_delete_attribute(module, ldb, msg2, msg->elements[i].name) != 0) { - ldb_asprintf_errstring(module->ldb, "No such attribute: %s for delete on %s", msg->elements[i].name, dn); + ldb_asprintf_errstring(ldb, "No such attribute: %s for delete on %s", msg->elements[i].name, dn); ret = LDB_ERR_NO_SUCH_ATTRIBUTE; goto failed; } @@ -699,7 +701,7 @@ int ltdb_modify_internal(struct ldb_module *module, msg2, msg->elements[i].name, &msg->elements[i].values[j]) != 0) { - ldb_asprintf_errstring(module->ldb, "No matching attribute value when deleting attribute: %s on %s", msg->elements[i].name, dn); + ldb_asprintf_errstring(ldb, "No matching attribute value when deleting attribute: %s on %s", msg->elements[i].name, dn); ret = LDB_ERR_NO_SUCH_ATTRIBUTE; goto failed; } @@ -710,7 +712,7 @@ int ltdb_modify_internal(struct ldb_module *module, } break; default: - ldb_asprintf_errstring(module->ldb, + ldb_asprintf_errstring(ldb, "Invalid ldb_modify flags on %s: 0x%x", msg->elements[i].name, msg->elements[i].flags & LDB_FLAG_MOD_MASK); @@ -750,7 +752,7 @@ static int ltdb_modify(struct ltdb_context *ctx) struct ldb_request *req = ctx->req; int tret; - req->handle->state = LDB_ASYNC_PENDING; + ldb_request_set_state(req, LDB_ASYNC_PENDING); tret = ltdb_check_special_dn(module, req->op.mod.message); if (tret != LDB_SUCCESS) { @@ -779,7 +781,7 @@ static int ltdb_rename(struct ltdb_context *ctx) struct ldb_message *msg; int tret; - req->handle->state = LDB_ASYNC_PENDING; + ldb_request_set_state(req, LDB_ASYNC_PENDING); if (ltdb_cache_load(ctx->module) != 0) { return LDB_ERR_OPERATIONS_ERROR; @@ -841,8 +843,8 @@ static int ltdb_rename(struct ltdb_context *ctx) static int ltdb_start_trans(struct ldb_module *module) { - struct ltdb_private *ltdb = - talloc_get_type(module->private_data, struct ltdb_private); + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); if (tdb_transaction_start(ltdb->tdb) != 0) { return ltdb_err_map(tdb_error(ltdb->tdb)); @@ -857,8 +859,8 @@ static int ltdb_start_trans(struct ldb_module *module) static int ltdb_end_trans(struct ldb_module *module) { - struct ltdb_private *ltdb = - talloc_get_type(module->private_data, struct ltdb_private); + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); ltdb->in_transaction--; @@ -875,8 +877,8 @@ static int ltdb_end_trans(struct ldb_module *module) static int ltdb_del_trans(struct ldb_module *module) { - struct ltdb_private *ltdb = - talloc_get_type(module->private_data, struct ltdb_private); + void *data = ldb_module_get_private(module); + struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); ltdb->in_transaction--; @@ -897,6 +899,7 @@ static int ltdb_del_trans(struct ldb_module *module) static int ltdb_sequence_number(struct ltdb_context *ctx, struct ldb_extended **ext) { + struct ldb_context *ldb; struct ldb_module *module = ctx->module; struct ldb_request *req = ctx->req; TALLOC_CTX *tmp_ctx; @@ -907,13 +910,15 @@ static int ltdb_sequence_number(struct ltdb_context *ctx, const char *date; int ret; + ldb = ldb_module_get_ctx(module); + seq = talloc_get_type(req->op.extended.data, struct ldb_seqnum_request); if (seq == NULL) { return LDB_ERR_OPERATIONS_ERROR; } - req->handle->state = LDB_ASYNC_PENDING; + ldb_request_set_state(req, LDB_ASYNC_PENDING); if (ltdb_lock_read(module) != 0) { return LDB_ERR_OPERATIONS_ERROR; @@ -930,7 +935,7 @@ static int ltdb_sequence_number(struct ltdb_context *ctx, goto done; } - dn = ldb_dn_new(tmp_ctx, module->ldb, LTDB_BASEINFO); + dn = ldb_dn_new(tmp_ctx, ldb, LTDB_BASEINFO); msg = talloc(tmp_ctx, struct ldb_message); if (msg == NULL) { @@ -978,18 +983,23 @@ done: return ret; } -static void ltdb_request_done(struct ldb_request *req, int error) +static void ltdb_request_done(struct ltdb_context *ctx, int error) { + struct ldb_context *ldb; + struct ldb_request *req; struct ldb_reply *ares; + ldb = ldb_module_get_ctx(ctx->module); + req = ctx->req; + /* if we already returned an error just return */ - if (req->handle->status != LDB_SUCCESS) { + if (ldb_request_get_status(req) != LDB_SUCCESS) { return; } ares = talloc_zero(req, struct ldb_reply); if (!ares) { - ldb_oom(req->handle->ldb); + ldb_oom(ldb); req->callback(req, NULL); return; } @@ -1007,23 +1017,28 @@ static void ltdb_timeout(struct tevent_context *ev, struct ltdb_context *ctx; ctx = talloc_get_type(private_data, struct ltdb_context); - ltdb_request_done(ctx->req, LDB_ERR_TIME_LIMIT_EXCEEDED); + ltdb_request_done(ctx, LDB_ERR_TIME_LIMIT_EXCEEDED); } -static void ltdb_request_extended_done(struct ldb_request *req, +static void ltdb_request_extended_done(struct ltdb_context *ctx, struct ldb_extended *ext, int error) { + struct ldb_context *ldb; + struct ldb_request *req; struct ldb_reply *ares; + ldb = ldb_module_get_ctx(ctx->module); + req = ctx->req; + /* if we already returned an error just return */ - if (req->handle->status != LDB_SUCCESS) { + if (ldb_request_get_status(req) != LDB_SUCCESS) { return; } ares = talloc_zero(req, struct ldb_reply); if (!ares) { - ldb_oom(req->handle->ldb); + ldb_oom(ldb); req->callback(req, NULL); return; } @@ -1048,7 +1063,7 @@ static void ltdb_handle_extended(struct ltdb_context *ctx) ret = LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; } - ltdb_request_extended_done(ctx->req, ext, ret); + ltdb_request_extended_done(ctx, ext, ret); } static void ltdb_callback(struct tevent_context *ev, @@ -1088,13 +1103,14 @@ static void ltdb_callback(struct tevent_context *ev, if (!ctx->callback_failed) { /* Once we are done, we do not need timeout events */ talloc_free(ctx->timeout_event); - ltdb_request_done(ctx->req, ret); + ltdb_request_done(ctx, ret); } } static int ltdb_handle_request(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; struct tevent_context *ev; struct ltdb_context *ac; struct tevent_timer *te; @@ -1104,16 +1120,18 @@ static int ltdb_handle_request(struct ldb_module *module, return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION; } + ldb = ldb_module_get_ctx(module); + if (req->starttime == 0 || req->timeout == 0) { - ldb_set_errstring(module->ldb, "Invalid timeout settings"); + ldb_set_errstring(ldb, "Invalid timeout settings"); return LDB_ERR_TIME_LIMIT_EXCEEDED; } - ev = ldb_get_event_context(module->ldb); + ev = ldb_get_event_context(ldb); ac = talloc_zero(req, struct ltdb_context); if (ac == NULL) { - ldb_set_errstring(module->ldb, "Out of Memory"); + ldb_set_errstring(ldb, "Out of Memory"); return LDB_ERR_OPERATIONS_ERROR; } @@ -1154,8 +1172,9 @@ static const struct ldb_module_ops ltdb_ops = { */ static int ltdb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[], - struct ldb_module **module) + struct ldb_module **_module) { + struct ldb_module *module; const char *path; int tdb_flags, open_flags; struct ltdb_private *ltdb; @@ -1199,7 +1218,7 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url, /* note that we use quite a large default hash size */ ltdb->tdb = ltdb_wrap_open(ltdb, path, 10000, tdb_flags, open_flags, - ldb->create_perms, ldb); + ldb_get_create_perms(ldb), ldb); if (!ltdb->tdb) { ldb_debug(ldb, LDB_DEBUG_ERROR, "Unable to open tdb '%s'\n", path); @@ -1209,24 +1228,20 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url, ltdb->sequence_number = 0; - *module = talloc(ldb, struct ldb_module); - if ((*module) == NULL) { - ldb_oom(ldb); + module = ldb_module_new(ldb, ldb, "ldb_tdb backend", <db_ops); + if (!module) { talloc_free(ltdb); return -1; } - talloc_set_name_const(*module, "ldb_tdb backend"); - (*module)->ldb = ldb; - (*module)->prev = (*module)->next = NULL; - (*module)->private_data = ltdb; - (*module)->ops = <db_ops; + ldb_module_set_private(module, ltdb); - if (ltdb_cache_load(*module) != 0) { - talloc_free(*module); + if (ltdb_cache_load(module) != 0) { + talloc_free(module); talloc_free(ltdb); return -1; } + *_module = module; return 0; } diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.h b/source4/lib/ldb/ldb_tdb/ldb_tdb.h index b373d37b7e..7ebf199f6f 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb.h +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.h @@ -6,6 +6,8 @@ #include "tdb.h" #endif +#include "ldb_module.h" + /* this private structure is used by the ltdb backend in the ldb_context */ struct ltdb_private { diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c index 4fea43c8c8..6ee8417e25 100644 --- a/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c +++ b/source4/lib/ldb/ldb_tdb/ldb_tdb_wrap.c @@ -21,8 +21,6 @@ License along with this library; if not, see <http://www.gnu.org/licenses/>. */ -#include "ldb_includes.h" - #include "ldb_tdb.h" /* diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c index c650970af4..475b609e41 100644 --- a/source4/lib/ldb/modules/asq.c +++ b/source4/lib/ldb/modules/asq.c @@ -32,7 +32,7 @@ * Author: Simo Sorce */ -#include "ldb_includes.h" +#include "ldb_module.h" struct asq_context { @@ -63,11 +63,14 @@ struct asq_context { static struct asq_context *asq_context_init(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; struct asq_context *ac; + ldb = ldb_module_get_ctx(module); + ac = talloc_zero(req, struct asq_context); if (ac == NULL) { - ldb_oom(module->ldb); + ldb_oom(ldb); return NULL; } @@ -206,9 +209,12 @@ static int asq_reqs_callback(struct ldb_request *req, struct ldb_reply *ares) static int asq_build_first_request(struct asq_context *ac, struct ldb_request **base_req) { + struct ldb_context *ldb; const char **base_attrs; int ret; + ldb = ldb_module_get_ctx(ac->module); + ac->req_attrs = ac->req->op.search.attrs; ac->req_attribute = talloc_strdup(ac, ac->asq_ctrl->source_attribute); if (ac->req_attribute == NULL) @@ -222,7 +228,7 @@ static int asq_build_first_request(struct asq_context *ac, struct ldb_request ** base_attrs[1] = NULL; - ret = ldb_build_search_req(base_req, ac->module->ldb, ac, + ret = ldb_build_search_req(base_req, ldb, ac, ac->req->op.search.base, LDB_SCOPE_BASE, NULL, @@ -239,6 +245,7 @@ static int asq_build_first_request(struct asq_context *ac, struct ldb_request ** static int asq_build_multiple_requests(struct asq_context *ac, bool *terminated) { + struct ldb_context *ldb; struct ldb_control **saved_controls; struct ldb_control *control; struct ldb_dn *dn; @@ -249,6 +256,8 @@ static int asq_build_multiple_requests(struct asq_context *ac, bool *terminated) return LDB_ERR_NO_SUCH_OBJECT; } + ldb = ldb_module_get_ctx(ac->module); + el = ldb_msg_find_element(ac->base_res->message, ac->req_attribute); /* no values found */ if (el == NULL) { @@ -266,7 +275,7 @@ static int asq_build_multiple_requests(struct asq_context *ac, bool *terminated) for (i = 0; i < el->num_values; i++) { - dn = ldb_dn_new(ac, ac->module->ldb, + dn = ldb_dn_new(ac, ldb, (const char *)el->values[i].data); if ( ! ldb_dn_validate(dn)) { ac->asq_ret = ASQ_CTRL_INVALID_ATTRIBUTE_SYNTAX; @@ -275,7 +284,7 @@ static int asq_build_multiple_requests(struct asq_context *ac, bool *terminated) } ret = ldb_build_search_req_ex(&ac->reqs[i], - ac->module->ldb, ac, + ldb, ac, dn, LDB_SCOPE_BASE, ac->req->op.search.tree, ac->req_attrs, @@ -298,9 +307,12 @@ static int asq_build_multiple_requests(struct asq_context *ac, bool *terminated) static int asq_search_continue(struct asq_context *ac) { + struct ldb_context *ldb; bool terminated = false; int ret; + ldb = ldb_module_get_ctx(ac->module); + switch (ac->step) { case ASQ_SEARCH_BASE: @@ -312,7 +324,7 @@ static int asq_search_continue(struct asq_context *ac) ac->step = ASQ_SEARCH_MULTI; - return ldb_request(ac->module->ldb, ac->reqs[ac->cur_req]); + return ldb_request(ldb, ac->reqs[ac->cur_req]); case ASQ_SEARCH_MULTI: @@ -323,7 +335,7 @@ static int asq_search_continue(struct asq_context *ac) return asq_search_terminate(ac); } - return ldb_request(ac->module->ldb, ac->reqs[ac->cur_req]); + return ldb_request(ldb, ac->reqs[ac->cur_req]); } return LDB_ERR_OPERATIONS_ERROR; @@ -331,11 +343,14 @@ static int asq_search_continue(struct asq_context *ac) static int asq_search(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; struct ldb_request *base_req; struct ldb_control *control; struct asq_context *ac; int ret; + ldb = ldb_module_get_ctx(module); + /* check if there's a paged request control */ control = ldb_request_get_control(req, LDB_CONTROL_ASQ_OID); if (control == NULL) { @@ -366,16 +381,19 @@ static int asq_search(struct ldb_module *module, struct ldb_request *req) ac->step = ASQ_SEARCH_BASE; - return ldb_request(module->ldb, base_req); + return ldb_request(ldb, base_req); } static int asq_init(struct ldb_module *module) { + struct ldb_context *ldb; int ret; + ldb = ldb_module_get_ctx(module); + ret = ldb_mod_register_control(module, LDB_CONTROL_ASQ_OID); if (ret != LDB_SUCCESS) { - ldb_debug(module->ldb, LDB_DEBUG_WARNING, "asq: Unable to register control with rootdse!\n"); + ldb_debug(ldb, LDB_DEBUG_WARNING, "asq: Unable to register control with rootdse!\n"); } return ldb_next_init(module); diff --git a/source4/lib/ldb/modules/operational.c b/source4/lib/ldb/modules/operational.c index 11c06c81bb..d862638389 100644 --- a/source4/lib/ldb/modules/operational.c +++ b/source4/lib/ldb/modules/operational.c @@ -73,7 +73,7 @@ modifiersName: not supported by w2k3? */ -#include "ldb_includes.h" +#include "ldb_module.h" /* construct a canonical name from a message @@ -126,8 +126,11 @@ static int operational_search_post_process(struct ldb_module *module, struct ldb_message *msg, const char * const *attrs) { + struct ldb_context *ldb; int i, a=0; + ldb = ldb_module_get_ctx(module); + for (a=0;attrs && attrs[a];a++) { for (i=0;i<ARRAY_SIZE(search_sub);i++) { if (ldb_attr_cmp(attrs[a], search_sub[i].attr) != 0) { @@ -161,7 +164,7 @@ static int operational_search_post_process(struct ldb_module *module, return 0; failed: - ldb_debug_set(module->ldb, LDB_DEBUG_WARNING, + ldb_debug_set(ldb, LDB_DEBUG_WARNING, "operational_search_post_process failed for attribute '%s'\n", attrs[a]); return -1; @@ -224,12 +227,15 @@ static int operational_callback(struct ldb_request *req, struct ldb_reply *ares) static int operational_search(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; struct operational_context *ac; struct ldb_request *down_req; const char **search_attrs = NULL; int i, a; int ret; + ldb = ldb_module_get_ctx(module); + ac = talloc(req, struct operational_context); if (ac == NULL) { return LDB_ERR_OPERATIONS_ERROR; @@ -268,7 +274,7 @@ static int operational_search(struct ldb_module *module, struct ldb_request *req } } - ret = ldb_build_search_req_ex(&down_req, module->ldb, ac, + ret = ldb_build_search_req_ex(&down_req, ldb, ac, req->op.search.base, req->op.search.scope, req->op.search.tree, diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c index dfc565fef8..7d7cdf66a0 100644 --- a/source4/lib/ldb/modules/paged_results.c +++ b/source4/lib/ldb/modules/paged_results.c @@ -32,7 +32,7 @@ * Author: Simo Sorce */ -#include "ldb_includes.h" +#include "ldb_module.h" struct message_store { /* keep the whole ldb_reply as an optimization @@ -290,6 +290,7 @@ static int paged_search_callback(struct ldb_request *req, struct ldb_reply *ares static int paged_search(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; struct ldb_control *control; struct private_data *private_data; struct ldb_paged_control *paged_ctrl; @@ -298,6 +299,8 @@ static int paged_search(struct ldb_module *module, struct ldb_request *req) struct paged_context *ac; int ret; + ldb = ldb_module_get_ctx(module); + /* check if there's a paged request control */ control = ldb_request_get_control(req, LDB_CONTROL_PAGED_RESULTS_OID); if (control == NULL) { @@ -310,11 +313,12 @@ static int paged_search(struct ldb_module *module, struct ldb_request *req) return LDB_ERR_PROTOCOL_ERROR; } - private_data = talloc_get_type(module->private_data, struct private_data); + private_data = talloc_get_type(ldb_module_get_private(module), + struct private_data); ac = talloc_zero(req, struct paged_context); if (ac == NULL) { - ldb_set_errstring(module->ldb, "Out of Memory"); + ldb_set_errstring(ldb, "Out of Memory"); return LDB_ERR_OPERATIONS_ERROR; } @@ -333,7 +337,7 @@ static int paged_search(struct ldb_module *module, struct ldb_request *req) return LDB_ERR_OPERATIONS_ERROR; } - ret = ldb_build_search_req_ex(&search_req, module->ldb, ac, + ret = ldb_build_search_req_ex(&search_req, ldb, ac, req->op.search.base, req->op.search.scope, req->op.search.tree, @@ -385,9 +389,12 @@ static int paged_search(struct ldb_module *module, struct ldb_request *req) static int paged_request_init(struct ldb_module *module) { + struct ldb_context *ldb; struct private_data *data; int ret; + ldb = ldb_module_get_ctx(module); + data = talloc(module, struct private_data); if (data == NULL) { return LDB_ERR_OTHER; @@ -395,11 +402,11 @@ static int paged_request_init(struct ldb_module *module) data->next_free_id = 1; data->store = NULL; - module->private_data = data; + ldb_module_set_private(module, data); ret = ldb_mod_register_control(module, LDB_CONTROL_PAGED_RESULTS_OID); if (ret != LDB_SUCCESS) { - ldb_debug(module->ldb, LDB_DEBUG_WARNING, + ldb_debug(ldb, LDB_DEBUG_WARNING, "paged_request:" "Unable to register control with rootdse!\n"); } diff --git a/source4/lib/ldb/modules/paged_searches.c b/source4/lib/ldb/modules/paged_searches.c index 56f9b1cac3..01e77cb22c 100644 --- a/source4/lib/ldb/modules/paged_searches.c +++ b/source4/lib/ldb/modules/paged_searches.c @@ -33,7 +33,7 @@ */ #include "includes.h" -#include "ldb_includes.h" +#include "ldb_module.h" #define PS_DEFAULT_PAGE_SIZE 500 /* 500 objects per query seem to be a decent compromise @@ -211,10 +211,12 @@ static int ps_callback(struct ldb_request *req, struct ldb_reply *ares) static int ps_search(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; struct private_data *private_data; struct ps_context *ac; - private_data = talloc_get_type(module->private_data, struct private_data); + private_data = talloc_get_type(ldb_module_get_private(module), struct private_data); + ldb = ldb_module_get_ctx(module); /* check if paging is supported and if there is a any control */ if (!private_data || !private_data->paged_supported || req->controls) { @@ -226,7 +228,7 @@ static int ps_search(struct ldb_module *module, struct ldb_request *req) ac = talloc_zero(req, struct ps_context); if (ac == NULL) { - ldb_oom(module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } @@ -241,11 +243,14 @@ static int ps_search(struct ldb_module *module, struct ldb_request *req) static int ps_next_request(struct ps_context *ac) { + struct ldb_context *ldb; struct ldb_paged_control *control; struct ldb_control **controls; struct ldb_request *new_req; int ret; + ldb = ldb_module_get_ctx(ac->module); + controls = talloc_array(ac, struct ldb_control *, 2); if (!controls) { return LDB_ERR_OPERATIONS_ERROR; @@ -270,7 +275,7 @@ static int ps_next_request(struct ps_context *ac) { controls[0]->data = control; controls[1] = NULL; - ret = ldb_build_search_req_ex(&new_req, ac->module->ldb, ac, + ret = ldb_build_search_req_ex(&new_req, ldb, ac, ac->req->op.search.base, ac->req->op.search.scope, ac->req->op.search.tree, @@ -324,26 +329,30 @@ static int check_supported_paged(struct ldb_request *req, static int ps_init(struct ldb_module *module) { + struct ldb_context *ldb; static const char *attrs[] = { "supportedControl", NULL }; struct private_data *data; struct ldb_dn *base; int ret; struct ldb_request *req; + ldb = ldb_module_get_ctx(module); + data = talloc(module, struct private_data); if (data == NULL) { - ldb_oom(module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } - module->private_data = data; data->paged_supported = false; - base = ldb_dn_new(module, module->ldb, ""); + ldb_module_set_private(module, data); + + base = ldb_dn_new(module, ldb, ""); if (base == NULL) { - ldb_oom(module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } - ret = ldb_build_search_req(&req, module->ldb, module, + ret = ldb_build_search_req(&req, ldb, module, base, LDB_SCOPE_BASE, "(objectClass=*)", attrs, NULL, diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 62b8ce5112..a5ffcc034a 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -36,7 +36,7 @@ * Simo Sorce Mar 2006 */ -#include "ldb_includes.h" +#include "ldb_module.h" struct rename_context { @@ -86,6 +86,7 @@ static int rdn_name_add_callback(struct ldb_request *req, static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; struct ldb_request *down_req; struct rename_context *ac; struct ldb_message *msg; @@ -95,7 +96,8 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) struct ldb_val rdn_val; int i, ret; - ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_add_record\n"); + ldb = ldb_module_get_ctx(module); + ldb_debug(ldb, LDB_DEBUG_TRACE, "rdn_name_add_record\n"); /* do not manipulate our control entries */ if (ldb_dn_is_special(req->op.add.message->dn)) { @@ -141,10 +143,10 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) return LDB_ERR_OPERATIONS_ERROR; } } else { - a = ldb_schema_attribute_by_name(module->ldb, rdn_name); + a = ldb_schema_attribute_by_name(ldb, rdn_name); for (i = 0; i < attribute->num_values; i++) { - ret = a->syntax->comparison_fn(module->ldb, msg, + ret = a->syntax->comparison_fn(ldb, msg, &rdn_val, &attribute->values[i]); if (ret == 0) { /* overwrite so it matches in case */ @@ -153,7 +155,7 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) } } if (i == attribute->num_values) { - ldb_debug_set(module->ldb, LDB_DEBUG_FATAL, + ldb_debug_set(ldb, LDB_DEBUG_FATAL, "RDN mismatch on %s: %s (%s)", ldb_dn_get_linearized(msg->dn), rdn_name, rdn_val.data); talloc_free(ac); @@ -162,7 +164,7 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) } } - ret = ldb_build_add_req(&down_req, module->ldb, req, + ret = ldb_build_add_req(&down_req, ldb, req, msg, req->controls, ac, rdn_name_add_callback, @@ -205,6 +207,7 @@ static int rdn_modify_callback(struct ldb_request *req, struct ldb_reply *ares) static int rdn_rename_callback(struct ldb_request *req, struct ldb_reply *ares) { + struct ldb_context *ldb; struct rename_context *ac; struct ldb_request *mod_req; const char *rdn_name; @@ -213,6 +216,7 @@ static int rdn_rename_callback(struct ldb_request *req, struct ldb_reply *ares) int ret; ac = talloc_get_type(req->context, struct rename_context); + ldb = ldb_module_get_ctx(ac->module); if (!ares) { goto error; @@ -258,7 +262,7 @@ static int rdn_rename_callback(struct ldb_request *req, struct ldb_reply *ares) goto error; } - ret = ldb_build_mod_req(&mod_req, ac->module->ldb, + ret = ldb_build_mod_req(&mod_req, ldb, ac, msg, NULL, ac, rdn_modify_callback, req); @@ -268,7 +272,7 @@ static int rdn_rename_callback(struct ldb_request *req, struct ldb_reply *ares) talloc_steal(mod_req, msg); /* do the mod call */ - return ldb_request(ac->module->ldb, mod_req); + return ldb_request(ldb, mod_req); error: return ldb_module_done(ac->req, NULL, NULL, @@ -277,11 +281,13 @@ error: static int rdn_name_rename(struct ldb_module *module, struct ldb_request *req) { + struct ldb_context *ldb; struct rename_context *ac; struct ldb_request *down_req; int ret; - ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_rename\n"); + ldb = ldb_module_get_ctx(module); + ldb_debug(ldb, LDB_DEBUG_TRACE, "rdn_name_rename\n"); /* do not manipulate our control entries */ if (ldb_dn_is_special(req->op.rename.newdn)) { @@ -297,7 +303,7 @@ static int rdn_name_rename(struct ldb_module *module, struct ldb_request *req) ac->req = req; ret = ldb_build_rename_req(&down_req, - module->ldb, + ldb, ac, req->op.rename.olddn, req->op.rename.newdn, diff --git a/source4/lib/ldb/modules/skel.c b/source4/lib/ldb/modules/skel.c index 0cd29ac4b7..248f9b346b 100644 --- a/source4/lib/ldb/modules/skel.c +++ b/source4/lib/ldb/modules/skel.c @@ -31,7 +31,7 @@ * Author: Simo Sorce */ -#include "ldb_includes.h" +#include "ldb_module.h" struct private_data { @@ -87,9 +87,13 @@ static int skel_del_trans(struct ldb_module *module) static int skel_destructor(struct ldb_module *ctx) { - struct private_data *data = talloc_get_type(ctx->private_data, struct private_data); + struct private_data *data; + + data = talloc_get_type(ldb_module_get_private(ctx), struct private_data); + /* put your clean-up functions here */ if (data->some_private_data) talloc_free(data->some_private_data); + return 0; } @@ -100,16 +104,19 @@ static int skel_request(struct ldb_module *module, struct ldb_request *req) static int skel_init(struct ldb_module *module) { + struct ldb_context *ldb; struct private_data *data; + ldb = ldb_module_get_ctx(module); + data = talloc(module, struct private_data); if (data == NULL) { - ldb_oom(module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } data->some_private_data = NULL; - module->private_data = data; + ldb_module_set_private(module, data); talloc_set_destructor (module, skel_destructor); diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c index 25e56b24c8..2b2a1ab1e3 100644 --- a/source4/lib/ldb/modules/sort.c +++ b/source4/lib/ldb/modules/sort.c @@ -31,7 +31,7 @@ * Author: Simo Sorce */ -#include "ldb_includes.h" +#include "ldb_module.h" struct opaque { struct ldb_context *ldb; @@ -104,6 +104,9 @@ static int sort_compare(struct ldb_message **msg1, struct ldb_message **msg2, vo { struct sort_context *ac = talloc_get_type(opaque, struct sort_context); struct ldb_message_element *el1, *el2; + struct ldb_context *ldb; + + ldb = ldb_module_get_ctx(ac->module); if (!ac || ac->sort_result != 0) { /* an error occurred previously, @@ -122,17 +125,20 @@ static int sort_compare(struct ldb_message **msg1, struct ldb_message **msg2, vo } if (ac->reverse) - return ac->a->syntax->comparison_fn(ac->module->ldb, ac, &el2->values[0], &el1->values[0]); + return ac->a->syntax->comparison_fn(ldb, ac, &el2->values[0], &el1->values[0]); - return ac->a->syntax->comparison_fn(ac->module->ldb, ac, &el1->values[0], &el2->values[0]); + return ac->a->syntax->comparison_fn(ldb, ac, &el1->values[0], &el2->values[0]); } static int server_sort_results(struct sort_context *ac) { + struct ldb_context *ldb; struct ldb_reply *ares; int i, ret; - ac->a = ldb_schema_attribute_by_name(ac->module->ldb, ac->attributeName); + ldb = ldb_module_get_ctx(ac->module); + + ac->a = ldb_schema_attribute_by_name(ldb, ac->attributeName); ac->sort_result = 0; ldb_qsort(ac->msgs, ac->num_msgs, @@ -179,9 +185,11 @@ static int server_sort_results(struct sort_context *ac) static int server_sort_search_callback(struct ldb_request *req, struct ldb_reply *ares) { struct sort_context *ac; + struct ldb_context *ldb; int ret; ac = talloc_get_type(req->context, struct sort_context); + ldb = ldb_module_get_ctx(ac->module); if (!ares) { return ldb_module_done(ac->req, NULL, NULL, @@ -197,7 +205,7 @@ static int server_sort_search_callback(struct ldb_request *req, struct ldb_reply ac->msgs = talloc_realloc(ac, ac->msgs, struct ldb_message *, ac->num_msgs + 2); if (! ac->msgs) { talloc_free(ares); - ldb_oom(ac->module->ldb); + ldb_oom(ldb); return ldb_module_done(ac->req, NULL, NULL, LDB_ERR_OPERATIONS_ERROR); } @@ -212,7 +220,7 @@ static int server_sort_search_callback(struct ldb_request *req, struct ldb_reply ac->referrals = talloc_realloc(ac, ac->referrals, char *, ac->num_refs + 2); if (! ac->referrals) { talloc_free(ares); - ldb_oom(ac->module->ldb); + ldb_oom(ldb); return ldb_module_done(ac->req, NULL, NULL, LDB_ERR_OPERATIONS_ERROR); } @@ -242,8 +250,11 @@ static int server_sort_search(struct ldb_module *module, struct ldb_request *req struct ldb_control **controls; struct ldb_request *down_req; struct sort_context *ac; + struct ldb_context *ldb; int ret; + ldb = ldb_module_get_ctx(module); + /* check if there's a paged request control */ control = ldb_request_get_control(req, LDB_CONTROL_SERVER_SORT_OID); if (control == NULL) { @@ -253,7 +264,7 @@ static int server_sort_search(struct ldb_module *module, struct ldb_request *req ac = talloc_zero(req, struct sort_context); if (ac == NULL) { - ldb_oom(module->ldb); + ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } @@ -291,7 +302,7 @@ static int server_sort_search(struct ldb_module *module, struct ldb_request *req ac->orderingRule = sort_ctrls[0]->orderingRule; ac->reverse = sort_ctrls[0]->reverse; - ret = ldb_build_search_req_ex(&down_req, module->ldb, ac, + ret = ldb_build_search_req_ex(&down_req, ldb, ac, req->op.search.base, req->op.search.scope, req->op.search.tree, @@ -316,11 +327,14 @@ static int server_sort_search(struct ldb_module *module, struct ldb_request *req static int server_sort_init(struct ldb_module *module) { + struct ldb_context *ldb; int ret; + ldb = ldb_module_get_ctx(module); + ret = ldb_mod_register_control(module, LDB_CONTROL_SERVER_SORT_OID); if (ret != LDB_SUCCESS) { - ldb_debug(module->ldb, LDB_DEBUG_WARNING, + ldb_debug(ldb, LDB_DEBUG_WARNING, "server_sort:" "Unable to register control with rootdse!\n"); } diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index 9e98363c6f..ef2af060f2 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -25,7 +25,8 @@ License along with this library; if not, see <http://www.gnu.org/licenses/>. */ -#include "ldb_includes.h" +#include "replace.h" +#include "ldb_private.h" #include <Python.h> #include "pyldb.h" diff --git a/source4/lib/ldb/python.mk b/source4/lib/ldb/python.mk index 6e73b7e33d..6cc6d2e90e 100644 --- a/source4/lib/ldb/python.mk +++ b/source4/lib/ldb/python.mk @@ -4,5 +4,3 @@ PUBLIC_DEPENDENCIES = LIBLDB PYTALLOC pyldb_OBJ_FILES = $(ldbsrcdir)/pyldb.o $(pyldb_OBJ_FILES): CFLAGS+=-I$(ldbsrcdir)/include - -$(pyldb_OBJ_FILES): CFLAGS+=$(CFLAG_NO_CAST_QUAL) diff --git a/source4/lib/ldb/tests/sample_module.c b/source4/lib/ldb/tests/sample_module.c index 1a9e72c907..bbe4419b59 100644 --- a/source4/lib/ldb/tests/sample_module.c +++ b/source4/lib/ldb/tests/sample_module.c @@ -21,9 +21,7 @@ License along with this library; if not, see <http://www.gnu.org/licenses/>. */ -#include "ldb_includes.h" -#include "ldb.h" -#include "ldb_errors.h" +#include "ldb_module.h" int sample_add(struct ldb_module *mod, struct ldb_request *req) { diff --git a/source4/lib/ldb/tests/test-extended.sh b/source4/lib/ldb/tests/test-extended.sh index a84e3b78a3..14b988e3f9 100755 --- a/source4/lib/ldb/tests/test-extended.sh +++ b/source4/lib/ldb/tests/test-extended.sh @@ -4,7 +4,7 @@ echo "Running extended search tests" mv $LDB_URL $LDB_URL.1 -cat <<EOF | bin/ldbadd || exit 1 +cat <<EOF | $VALGRIND ldbadd$EXEEXT || exit 1 dn: cn=testrec1,cn=TEST i1: 1 i2: 0 @@ -38,10 +38,10 @@ EOF checkcount() { count=$1 expression="$2" - n=`bin/ldbsearch "$expression" | grep '^dn' | wc -l` + n=`$VALGRIND ldbsearch$EXEEXT "$expression" | grep '^dn' | wc -l` if [ $n != $count ]; then echo "Got $n but expected $count for $expression" - bin/ldbsearch "$expression" + $VALGRIND ldbsearch$EXEEXT "$expression" exit 1 fi echo "OK: $count $expression" diff --git a/source4/lib/ldb/tests/test-generic.sh b/source4/lib/ldb/tests/test-generic.sh index 50b5ff99a0..fec4b5b078 100755 --- a/source4/lib/ldb/tests/test-generic.sh +++ b/source4/lib/ldb/tests/test-generic.sh @@ -8,73 +8,73 @@ fi echo "LDB_URL: $LDB_URL" echo "Adding base elements" -$VALGRIND ldbadd $LDBDIR/tests/test.ldif || exit 1 +$VALGRIND ldbadd$EXEEXT $LDBDIR/tests/test.ldif || exit 1 echo "Adding again - should fail" -ldbadd $LDBDIR/tests/test.ldif 2> /dev/null && { +$VALGRIND ldbadd$EXEEXT $LDBDIR/tests/test.ldif 2> /dev/null && { echo "Should have failed to add again - gave $?" exit 1 } echo "Modifying elements" -$VALGRIND ldbmodify $LDBDIR/tests/test-modify.ldif || exit 1 +$VALGRIND ldbmodify$EXEEXT $LDBDIR/tests/test-modify.ldif || exit 1 echo "Showing modified record" -$VALGRIND ldbsearch '(uid=uham)' || exit 1 +$VALGRIND ldbsearch$EXEEXT '(uid=uham)' || exit 1 echo "Rename entry" OLDDN="cn=Ursula Hampster,ou=Alumni Association,ou=People,o=University of Michigan,c=TEST" NEWDN="cn=Hampster Ursula,ou=Alumni Association,ou=People,o=University of Michigan,c=TEST" -$VALGRIND ldbrename "$OLDDN" "$NEWDN" || exit 1 +$VALGRIND ldbrename$EXEEXT "$OLDDN" "$NEWDN" || exit 1 echo "Showing renamed record" -$VALGRIND ldbsearch '(uid=uham)' || exit 1 +$VALGRIND ldbsearch$EXEEXT '(uid=uham)' || exit 1 echo "Starting ldbtest" -$VALGRIND ldbtest --num-records 100 --num-searches 10 || exit 1 +$VALGRIND ldbtest$EXEEXT --num-records 100 --num-searches 10 || exit 1 if [ $LDB_SPECIALS = 1 ]; then echo "Adding index" - $VALGRIND ldbadd $LDBDIR/tests/test-index.ldif || exit 1 + $VALGRIND ldbadd$EXEEXT $LDBDIR/tests/test-index.ldif || exit 1 fi echo "Adding bad attributes - should fail" -$VALGRIND ldbadd $LDBDIR/tests/test-wrong_attributes.ldif && { +$VALGRIND ldbadd$EXEEXT $LDBDIR/tests/test-wrong_attributes.ldif && { echo "Should fhave failed - gave $?" exit 1 } echo "testing indexed search" -$VALGRIND ldbsearch '(uid=uham)' || exit 1 -$VALGRIND ldbsearch '(&(objectclass=person)(objectclass=person)(objectclass=top))' || exit 1 -$VALGRIND ldbsearch '(&(uid=uham)(uid=uham))' || exit 1 -$VALGRIND ldbsearch '(|(uid=uham)(uid=uham))' || exit 1 -$VALGRIND ldbsearch '(|(uid=uham)(uid=uham)(objectclass=OpenLDAPperson))' || exit 1 -$VALGRIND ldbsearch '(&(uid=uham)(uid=uham)(!(objectclass=xxx)))' || exit 1 -$VALGRIND ldbsearch '(&(objectclass=person)(uid=uham)(!(uid=uhamxx)))' uid \* \+ dn || exit 1 -$VALGRIND ldbsearch '(&(uid=uham)(uid=uha*)(title=*))' uid || exit 1 +$VALGRIND ldbsearch$EXEEXT '(uid=uham)' || exit 1 +$VALGRIND ldbsearch$EXEEXT '(&(objectclass=person)(objectclass=person)(objectclass=top))' || exit 1 +$VALGRIND ldbsearch$EXEEXT '(&(uid=uham)(uid=uham))' || exit 1 +$VALGRIND ldbsearch$EXEEXT '(|(uid=uham)(uid=uham))' || exit 1 +$VALGRIND ldbsearch$EXEEXT '(|(uid=uham)(uid=uham)(objectclass=OpenLDAPperson))' || exit 1 +$VALGRIND ldbsearch$EXEEXT '(&(uid=uham)(uid=uham)(!(objectclass=xxx)))' || exit 1 +$VALGRIND ldbsearch$EXEEXT '(&(objectclass=person)(uid=uham)(!(uid=uhamxx)))' uid \* \+ dn || exit 1 +$VALGRIND ldbsearch$EXEEXT '(&(uid=uham)(uid=uha*)(title=*))' uid || exit 1 # note that the "((" is treated as an attribute not an expression # this matches the openldap ldapsearch behaviour of looking for a '=' # to see if the first argument is an expression or not -$VALGRIND ldbsearch '((' uid || exit 1 -$VALGRIND ldbsearch '(objectclass=)' uid || exit 1 -$VALGRIND ldbsearch -b 'cn=Hampster Ursula,ou=Alumni Association,ou=People,o=University of Michigan,c=TEST' -s base "" sn || exit 1 +$VALGRIND ldbsearch$EXEEXT '((' uid || exit 1 +$VALGRIND ldbsearch$EXEEXT '(objectclass=)' uid || exit 1 +$VALGRIND ldbsearch$EXEEXT -b 'cn=Hampster Ursula,ou=Alumni Association,ou=People,o=University of Michigan,c=TEST' -s base "" sn || exit 1 echo "Test wildcard match" -$VALGRIND ldbadd $LDBDIR/tests/test-wildcard.ldif || exit 1 -$VALGRIND ldbsearch '(cn=test*multi)' || exit 1 -$VALGRIND ldbsearch '(cn=*test*multi*)' || exit 1 -$VALGRIND ldbsearch '(cn=*test_multi)' || exit 1 -$VALGRIND ldbsearch '(cn=test_multi*)' || exit 1 -$VALGRIND ldbsearch '(cn=test*multi*test*multi)' || exit 1 -$VALGRIND ldbsearch '(cn=test*multi*test*multi*multi_*)' || exit 1 +$VALGRIND ldbadd$EXEEXT $LDBDIR/tests/test-wildcard.ldif || exit 1 +$VALGRIND ldbsearch$EXEEXT '(cn=test*multi)' || exit 1 +$VALGRIND ldbsearch$EXEEXT '(cn=*test*multi*)' || exit 1 +$VALGRIND ldbsearch$EXEEXT '(cn=*test_multi)' || exit 1 +$VALGRIND ldbsearch$EXEEXT '(cn=test_multi*)' || exit 1 +$VALGRIND ldbsearch$EXEEXT '(cn=test*multi*test*multi)' || exit 1 +$VALGRIND ldbsearch$EXEEXT '(cn=test*multi*test*multi*multi_*)' || exit 1 echo "Starting ldbtest indexed" -$VALGRIND ldbtest --num-records 100 --num-searches 500 || exit 1 +$VALGRIND ldbtest$EXEEXT --num-records 100 --num-searches 500 || exit 1 echo "Testing one level search" -count=`$VALGRIND ldbsearch -b 'ou=Groups,o=University of Michigan,c=TEST' -s one 'objectclass=*' none |grep '^dn' | wc -l` +count=`$VALGRIND ldbsearch$EXEEXT -b 'ou=Groups,o=University of Michigan,c=TEST' -s one 'objectclass=*' none |grep '^dn' | wc -l` if [ $count != 3 ]; then echo returned $count records - expected 3 exit 1 @@ -83,8 +83,8 @@ fi echo "Testing binary file attribute value" mkdir -p tests/tmp cp $LDBDIR/tests/samba4.png tests/tmp/samba4.png -$VALGRIND ldbmodify $LDBDIR/tests/photo.ldif || exit 1 -count=`$VALGRIND ldbsearch '(cn=Hampster Ursula)' jpegPhoto | grep '^dn' | wc -l` +$VALGRIND ldbmodify$EXEEXT $LDBDIR/tests/photo.ldif || exit 1 +count=`$VALGRIND ldbsearch$EXEEXT '(cn=Hampster Ursula)' jpegPhoto | grep '^dn' | wc -l` if [ $count != 1 ]; then echo returned $count records - expected 1 exit 1 @@ -94,13 +94,13 @@ rm -f tests/tmp/samba4.png echo "*TODO* Testing UTF8 upper lower case searches !!" echo "Testing compare" -count=`$VALGRIND ldbsearch '(cn>=t)' cn | grep '^dn' | wc -l` +count=`$VALGRIND ldbsearch$EXEEXT '(cn>=t)' cn | grep '^dn' | wc -l` if [ $count != 2 ]; then echo returned $count records - expected 2 echo "this fails on openLdap ..." fi -count=`$VALGRIND ldbsearch '(cn<=t)' cn | grep '^dn' | wc -l` +count=`$VALGRIND ldbsearch$EXEEXT '(cn<=t)' cn | grep '^dn' | wc -l` if [ $count != 13 ]; then echo returned $count records - expected 13 echo "this fails on openLdap ..." @@ -111,7 +111,7 @@ checkcount() { scope=$2 basedn=$3 expression="$4" - n=`bin/ldbsearch -s "$scope" -b "$basedn" "$expression" | grep '^dn' | wc -l` + n=`$VALGRIND ldbsearch$EXEEXT -s "$scope" -b "$basedn" "$expression" | grep '^dn' | wc -l` if [ $n != $count ]; then echo "Got $n but expected $count for $expression" bin/ldbsearch "$expression" diff --git a/source4/lib/ldb/tests/test-tdb-features.sh b/source4/lib/ldb/tests/test-tdb-features.sh index fc0959c54a..d4248366ca 100644 --- a/source4/lib/ldb/tests/test-tdb-features.sh +++ b/source4/lib/ldb/tests/test-tdb-features.sh @@ -7,17 +7,17 @@ mv $LDB_URL $LDB_URL.2 checkcount() { count=$1 expression="$2" - n=`bin/ldbsearch "$expression" | grep '^dn' | wc -l` + n=`$VALGRIND ldbsearch$EXEEXT "$expression" | grep '^dn' | wc -l` if [ $n != $count ]; then echo "Got $n but expected $count for $expression" - $VALGRIND bin/ldbsearch "$expression" + $VALGRIND ldbsearch$EXEEXT "$expression" exit 1 fi echo "OK: $count $expression" } echo "Testing case sensitive search" -cat <<EOF | $VALGRIND bin/ldbadd || exit 1 +cat <<EOF | $VALGRIND ldbadd$EXEEXT || exit 1 dn: cn=t1,cn=TEST objectClass: testclass test: foo @@ -27,20 +27,20 @@ checkcount 0 '(test=FOO)' checkcount 0 '(test=FO*)' echo "Making case insensitive" -cat <<EOF | $VALGRIND bin/ldbmodify || exit 1 +cat <<EOF | $VALGRIND ldbmodify$EXEEXT || exit 1 dn: @ATTRIBUTES changetype: add add: test test: CASE_INSENSITIVE EOF -echo $ldif | $VALGRIND bin/ldbmodify || exit 1 +echo $ldif | $VALGRIND ldbmodify$EXEEXT || exit 1 checkcount 1 '(test=foo)' checkcount 1 '(test=FOO)' checkcount 1 '(test=fo*)' echo "adding i" -cat <<EOF | $VALGRIND bin/ldbmodify || exit 1 +cat <<EOF | $VALGRIND ldbmodify$EXEEXT || exit 1 dn: cn=t1,cn=TEST changetype: modify add: i @@ -50,7 +50,7 @@ checkcount 1 '(i=0x100)' checkcount 0 '(i=256)' echo "marking i as INTEGER" -cat <<EOF | $VALGRIND bin/ldbmodify || exit 1 +cat <<EOF | $VALGRIND ldbmodify$EXEEXT || exit 1 dn: @ATTRIBUTES changetype: modify add: i @@ -60,7 +60,7 @@ checkcount 1 '(i=0x100)' checkcount 1 '(i=256)' echo "adding j" -cat <<EOF | $VALGRIND bin/ldbmodify || exit 1 +cat <<EOF | $VALGRIND ldbmodify$EXEEXT || exit 1 dn: cn=t1,cn=TEST changetype: modify add: j @@ -70,7 +70,7 @@ checkcount 1 '(j=0x100)' checkcount 0 '(j=256)' echo "Adding wildcard attribute" -cat <<EOF | $VALGRIND bin/ldbmodify || exit 1 +cat <<EOF | $VALGRIND ldbmodify$EXEEXT || exit 1 dn: @ATTRIBUTES changetype: modify add: * @@ -84,7 +84,7 @@ checkcount 0 '(objectClass=otherclass)' checkcount 1 '(objectClass=testclass)' echo "Adding index" -cat <<EOF | $VALGRIND bin/ldbadd || exit 1 +cat <<EOF | $VALGRIND ldbadd$EXEEXT || exit 1 dn: @INDEXLIST @IDXATTR: i @IDXATTR: test @@ -97,7 +97,7 @@ checkcount 1 '(test=FOO)' checkcount 1 '(test=*f*o)' echo "making test case sensitive" -cat <<EOF | $VALGRIND bin/ldbmodify || exit 1 +cat <<EOF | $VALGRIND ldbmodify$EXEEXT || exit 1 dn: @ATTRIBUTES changetype: modify replace: test @@ -111,17 +111,17 @@ checkone() { count=$1 base="$2" expression="$3" - n=`bin/ldbsearch -s one -b "$base" "$expression" | grep '^dn' | wc -l` + n=`$VALGRIND ldbsearch$EXEEXT -s one -b "$base" "$expression" | grep '^dn' | wc -l` if [ $n != $count ]; then echo "Got $n but expected $count for $expression" - $VALGRIND bin/ldbsearch -s one -b "$base" "$expression" + $VALGRIND ldbsearch$EXEEXT -s one -b "$base" "$expression" exit 1 fi echo "OK: $count $expression" } echo "Removing wildcard attribute" -cat <<EOF | $VALGRIND bin/ldbmodify || exit 1 +cat <<EOF | $VALGRIND ldbmodify$EXEEXT || exit 1 dn: @ATTRIBUTES changetype: modify delete: * @@ -129,7 +129,7 @@ delete: * EOF echo "Adding one level indexes" -cat <<EOF | $VALGRIND bin/ldbmodify || exit 1 +cat <<EOF | $VALGRIND ldbmodify$EXEEXT || exit 1 dn: @INDEXLIST changetype: modify add: @IDXONE @@ -137,14 +137,14 @@ add: @IDXONE EOF echo "Testing one level indexed search" -cat <<EOF | $VALGRIND bin/ldbadd || exit 1 +cat <<EOF | $VALGRIND ldbadd$EXEEXT || exit 1 dn: cn=one,cn=t1,cn=TEST objectClass: oneclass cn: one test: one EOF checkone 1 "cn=t1,cn=TEST" '(test=one)' -cat <<EOF | $VALGRIND bin/ldbadd || exit 1 +cat <<EOF | $VALGRIND ldbadd$EXEEXT || exit 1 dn: cn=two,cn=t1,cn=TEST objectClass: oneclass cn: two diff --git a/source4/lib/ldb/tests/test-tdb.sh b/source4/lib/ldb/tests/test-tdb.sh index 7c4f5205b4..1c35451962 100755 --- a/source4/lib/ldb/tests/test-tdb.sh +++ b/source4/lib/ldb/tests/test-tdb.sh @@ -17,12 +17,12 @@ if [ -z "$LDBDIR" ]; then export LDBDIR fi -cat <<EOF | $VALGRIND ldbadd || exit 1 +cat <<EOF | $VALGRIND ldbadd$EXEEXT || exit 1 dn: @MODULES @LIST: rdn_name EOF -$VALGRIND ldbadd $LDBDIR/tests/init.ldif || exit 1 +$VALGRIND ldbadd$EXEEXT $LDBDIR/tests/init.ldif || exit 1 . $LDBDIR/tests/test-generic.sh diff --git a/source4/lib/ldb/tools/cmdline.c b/source4/lib/ldb/tools/cmdline.c index 765d8b9edf..3dce9b187b 100644 --- a/source4/lib/ldb/tools/cmdline.c +++ b/source4/lib/ldb/tools/cmdline.c @@ -21,7 +21,7 @@ License along with this library; if not, see <http://www.gnu.org/licenses/>. */ -#include "ldb_includes.h" +#include "ldb.h" #include "tools/cmdline.h" #if (_SAMBA_BUILD_ >= 4) @@ -91,7 +91,7 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, ret = talloc_zero(ldb, struct ldb_cmdline); if (ret == NULL) { - ldb_oom(ldb); + fprintf(stderr, "Out of memory!\n"); goto failed; } @@ -139,7 +139,7 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, options.options = talloc_realloc(ret, options.options, const char *, num_options+3); if (options.options == NULL) { - ldb_oom(ldb); + fprintf(stderr, "Out of memory!\n"); goto failed; } options.options[num_options] = poptGetOptArg(pc); @@ -156,7 +156,7 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, options.controls = talloc_array(ret, char *, cc + 1); if (options.controls == NULL) { - ldb_oom(ldb); + fprintf(stderr, "Out of memory!\n"); goto failed; } for (p = cs, cc = 0; p != NULL; cc++) { diff --git a/source4/lib/ldb/tools/ldbadd.c b/source4/lib/ldb/tools/ldbadd.c index f32a4fa9bc..be02334797 100644 --- a/source4/lib/ldb/tools/ldbadd.c +++ b/source4/lib/ldb/tools/ldbadd.c @@ -31,7 +31,7 @@ * Author: Andrew Tridgell */ -#include "ldb_includes.h" +#include "ldb.h" #include "tools/cmdline.h" static int failures; diff --git a/source4/lib/ldb/tools/ldbdel.c b/source4/lib/ldb/tools/ldbdel.c index 22d4aa6976..232f51681a 100644 --- a/source4/lib/ldb/tools/ldbdel.c +++ b/source4/lib/ldb/tools/ldbdel.c @@ -31,7 +31,7 @@ * Author: Andrew Tridgell */ -#include "ldb_includes.h" +#include "ldb.h" #include "tools/cmdline.h" static int ldb_delete_recursive(struct ldb_context *ldb, struct ldb_dn *dn) diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c index 1a684c5c2d..3a915f8bea 100644 --- a/source4/lib/ldb/tools/ldbedit.c +++ b/source4/lib/ldb/tools/ldbedit.c @@ -31,7 +31,7 @@ * Author: Andrew Tridgell */ -#include "ldb_includes.h" +#include "ldb.h" #include "tools/cmdline.h" static struct ldb_cmdline *options; diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c index 6e355a10cf..c3f55c6096 100644 --- a/source4/lib/ldb/tools/ldbmodify.c +++ b/source4/lib/ldb/tools/ldbmodify.c @@ -31,7 +31,7 @@ * Author: Andrew Tridgell */ -#include "ldb_includes.h" +#include "ldb.h" #include "tools/cmdline.h" static int failures; diff --git a/source4/lib/ldb/tools/ldbrename.c b/source4/lib/ldb/tools/ldbrename.c index a5feb7a091..01ed3d9835 100644 --- a/source4/lib/ldb/tools/ldbrename.c +++ b/source4/lib/ldb/tools/ldbrename.c @@ -33,7 +33,7 @@ * Author: Stefan Metzmacher */ -#include "ldb_includes.h" +#include "ldb.h" #include "tools/cmdline.h" static void usage(void) diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c index ceabd5cd78..35d4ac7002 100644 --- a/source4/lib/ldb/tools/ldbsearch.c +++ b/source4/lib/ldb/tools/ldbsearch.c @@ -31,7 +31,7 @@ * Author: Andrew Tridgell */ -#include "ldb_includes.h" +#include "ldb.h" #include "tools/cmdline.h" static void usage(void) diff --git a/source4/lib/ldb/tools/ldbtest.c b/source4/lib/ldb/tools/ldbtest.c index f3d6d621a9..edaa9fb85c 100644 --- a/source4/lib/ldb/tools/ldbtest.c +++ b/source4/lib/ldb/tools/ldbtest.c @@ -31,7 +31,7 @@ * Author: Andrew Tridgell */ -#include "ldb_includes.h" +#include "ldb.h" #include "tools/cmdline.h" static struct timeval tp1,tp2; diff --git a/source4/lib/messaging/irpc.h b/source4/lib/messaging/irpc.h index fa91a147c6..3c518828ab 100644 --- a/source4/lib/messaging/irpc.h +++ b/source4/lib/messaging/irpc.h @@ -30,7 +30,7 @@ */ struct irpc_message { struct server_id from; - void *private; + void *private_data; struct irpc_header header; struct ndr_pull *ndr; bool defer_reply; @@ -48,10 +48,10 @@ struct irpc_message { typedef NTSTATUS (*irpc_function_t)(struct irpc_message *, void *r); /* register a server function with the irpc messaging system */ -#define IRPC_REGISTER(msg_ctx, pipename, funcname, function, private) \ +#define IRPC_REGISTER(msg_ctx, pipename, funcname, function, private_data) \ irpc_register(msg_ctx, &ndr_table_ ## pipename, \ NDR_ ## funcname, \ - (irpc_function_t)function, private) + (irpc_function_t)function, private_data) /* make a irpc call */ #define IRPC_CALL(msg_ctx, server_id, pipename, funcname, ptr, ctx) \ @@ -76,22 +76,22 @@ struct irpc_request { TALLOC_CTX *mem_ctx; struct { void (*fn)(struct irpc_request *); - void *private; + void *private_data; } async; }; struct loadparm_context; -typedef void (*msg_callback_t)(struct messaging_context *msg, void *private, +typedef void (*msg_callback_t)(struct messaging_context *msg, void *private_data, uint32_t msg_type, struct server_id server_id, DATA_BLOB *data); NTSTATUS messaging_send(struct messaging_context *msg, struct server_id server, uint32_t msg_type, DATA_BLOB *data); -NTSTATUS messaging_register(struct messaging_context *msg, void *private, +NTSTATUS messaging_register(struct messaging_context *msg, void *private_data, uint32_t msg_type, msg_callback_t fn); -NTSTATUS messaging_register_tmp(struct messaging_context *msg, void *private, +NTSTATUS messaging_register_tmp(struct messaging_context *msg, void *private_data, msg_callback_t fn, uint32_t *msg_type); struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, const char *dir, @@ -104,14 +104,14 @@ struct messaging_context *messaging_client_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev); NTSTATUS messaging_send_ptr(struct messaging_context *msg, struct server_id server, uint32_t msg_type, void *ptr); -void messaging_deregister(struct messaging_context *msg, uint32_t msg_type, void *private); +void messaging_deregister(struct messaging_context *msg, uint32_t msg_type, void *private_data); NTSTATUS irpc_register(struct messaging_context *msg_ctx, const struct ndr_interface_table *table, - int call, irpc_function_t fn, void *private); + int call, irpc_function_t fn, void *private_data); struct irpc_request *irpc_call_send(struct messaging_context *msg_ctx, struct server_id server_id, const struct ndr_interface_table *table, diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c index decad7b5a8..cfceeffac7 100644 --- a/source4/lib/messaging/messaging.c +++ b/source4/lib/messaging/messaging.c @@ -64,7 +64,7 @@ struct messaging_context { struct dispatch_fn { struct dispatch_fn *next, *prev; uint32_t msg_type; - void *private; + void *private_data; msg_callback_t fn; }; @@ -94,7 +94,7 @@ static void irpc_handler(struct messaging_context *, void *, /* A useful function for testing the message system. */ -static void ping_message(struct messaging_context *msg, void *private, +static void ping_message(struct messaging_context *msg, void *private_data, uint32_t msg_type, struct server_id src, DATA_BLOB *data) { DEBUG(1,("INFO: Received PING message from server %u.%u [%.*s]\n", @@ -109,7 +109,7 @@ static void ping_message(struct messaging_context *msg, void *private, static NTSTATUS irpc_uptime(struct irpc_message *msg, struct irpc_uptime *r) { - struct messaging_context *ctx = talloc_get_type(msg->private, struct messaging_context); + struct messaging_context *ctx = talloc_get_type(msg->private_data, struct messaging_context); *r->out.start_time = timeval_to_nttime(&ctx->start_time); return NT_STATUS_OK; } @@ -149,7 +149,7 @@ static void messaging_dispatch(struct messaging_context *msg, struct messaging_r next = d->next; data.data = rec->packet.data + sizeof(*rec->header); data.length = rec->header->length; - d->fn(msg, d->private, d->msg_type, rec->header->from, &data); + d->fn(msg, d->private_data, d->msg_type, rec->header->from, &data); } rec->header->length = 0; } @@ -217,9 +217,9 @@ static NTSTATUS try_send(struct messaging_rec *rec) retry backed off messages */ static void msg_retry_timer(struct tevent_context *ev, struct tevent_timer *te, - struct timeval t, void *private) + struct timeval t, void *private_data) { - struct messaging_context *msg = talloc_get_type(private, + struct messaging_context *msg = talloc_get_type(private_data, struct messaging_context); msg->retry_te = NULL; @@ -339,9 +339,9 @@ static void messaging_recv_handler(struct messaging_context *msg) handle a socket event */ static void messaging_handler(struct tevent_context *ev, struct tevent_fd *fde, - uint16_t flags, void *private) + uint16_t flags, void *private_data) { - struct messaging_context *msg = talloc_get_type(private, + struct messaging_context *msg = talloc_get_type(private_data, struct messaging_context); if (flags & EVENT_FD_WRITE) { messaging_send_handler(msg); @@ -355,7 +355,7 @@ static void messaging_handler(struct tevent_context *ev, struct tevent_fd *fde, /* Register a dispatch function for a particular message type. */ -NTSTATUS messaging_register(struct messaging_context *msg, void *private, +NTSTATUS messaging_register(struct messaging_context *msg, void *private_data, uint32_t msg_type, msg_callback_t fn) { struct dispatch_fn *d; @@ -376,7 +376,7 @@ NTSTATUS messaging_register(struct messaging_context *msg, void *private, d = talloc_zero(msg->dispatch, struct dispatch_fn); NT_STATUS_HAVE_NO_MEMORY(d); d->msg_type = msg_type; - d->private = private; + d->private_data = private_data; d->fn = fn; DLIST_ADD(msg->dispatch[msg_type], d); @@ -388,7 +388,7 @@ NTSTATUS messaging_register(struct messaging_context *msg, void *private, register a temporary message handler. The msg_type is allocated above MSG_TMP_BASE */ -NTSTATUS messaging_register_tmp(struct messaging_context *msg, void *private, +NTSTATUS messaging_register_tmp(struct messaging_context *msg, void *private_data, msg_callback_t fn, uint32_t *msg_type) { struct dispatch_fn *d; @@ -396,7 +396,7 @@ NTSTATUS messaging_register_tmp(struct messaging_context *msg, void *private, d = talloc_zero(msg->dispatch, struct dispatch_fn); NT_STATUS_HAVE_NO_MEMORY(d); - d->private = private; + d->private_data = private_data; d->fn = fn; id = idr_get_new_above(msg->dispatch_tree, d, MSG_TMP_BASE, UINT16_MAX); @@ -414,7 +414,7 @@ NTSTATUS messaging_register_tmp(struct messaging_context *msg, void *private, /* De-register the function for a particular message type. */ -void messaging_deregister(struct messaging_context *msg, uint32_t msg_type, void *private) +void messaging_deregister(struct messaging_context *msg, uint32_t msg_type, void *private_data) { struct dispatch_fn *d, *next; @@ -429,7 +429,7 @@ void messaging_deregister(struct messaging_context *msg, uint32_t msg_type, void for (d = msg->dispatch[msg_type]; d; d = next) { next = d->next; - if (d->private == private) { + if (d->private_data == private_data) { DLIST_REMOVE(msg->dispatch[msg_type], d); talloc_free(d); } @@ -631,7 +631,7 @@ struct irpc_list { const struct ndr_interface_table *table; int callnum; irpc_function_t fn; - void *private; + void *private_data; }; @@ -640,7 +640,7 @@ struct irpc_list { */ NTSTATUS irpc_register(struct messaging_context *msg_ctx, const struct ndr_interface_table *table, - int callnum, irpc_function_t fn, void *private) + int callnum, irpc_function_t fn, void *private_data) { struct irpc_list *irpc; @@ -659,7 +659,7 @@ NTSTATUS irpc_register(struct messaging_context *msg_ctx, irpc->table = table; irpc->callnum = callnum; irpc->fn = fn; - irpc->private = private; + irpc->private_data = private_data; irpc->uuid = irpc->table->syntax_id.uuid; return NT_STATUS_OK; @@ -768,7 +768,7 @@ static void irpc_handler_request(struct messaging_context *msg_ctx, if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) goto failed; /* make the call */ - m->private = i->private; + m->private_data= i->private_data; m->defer_reply = false; m->msg_ctx = msg_ctx; m->irpc = i; @@ -793,7 +793,7 @@ failed: /* handle an incoming irpc message */ -static void irpc_handler(struct messaging_context *msg_ctx, void *private, +static void irpc_handler(struct messaging_context *msg_ctx, void *private_data, uint32_t msg_type, struct server_id src, DATA_BLOB *packet) { struct irpc_message *m; @@ -844,9 +844,9 @@ static int irpc_destructor(struct irpc_request *irpc) timeout a irpc request */ static void irpc_timeout(struct tevent_context *ev, struct tevent_timer *te, - struct timeval t, void *private) + struct timeval t, void *private_data) { - struct irpc_request *irpc = talloc_get_type(private, struct irpc_request); + struct irpc_request *irpc = talloc_get_type(private_data, struct irpc_request); irpc->status = NT_STATUS_IO_TIMEOUT; irpc->done = true; if (irpc->async.fn) { diff --git a/source4/lib/messaging/pymessaging.c b/source4/lib/messaging/pymessaging.c index 535da4526c..96981895b6 100644 --- a/source4/lib/messaging/pymessaging.c +++ b/source4/lib/messaging/pymessaging.c @@ -159,11 +159,11 @@ static PyObject *py_messaging_send(PyObject *self, PyObject *args, PyObject *kwa Py_RETURN_NONE; } -static void py_msg_callback_wrapper(struct messaging_context *msg, void *private, +static void py_msg_callback_wrapper(struct messaging_context *msg, void *private_data, uint32_t msg_type, struct server_id server_id, DATA_BLOB *data) { - PyObject *callback = (PyObject *)private; + PyObject *callback = (PyObject *)private_data; PyObject_CallFunction(callback, discard_const_p(char, "i(iii)s#"), msg_type, server_id.id, server_id.id2, server_id.node, diff --git a/source4/lib/messaging/tests/irpc.c b/source4/lib/messaging/tests/irpc.c index d45bcb6bf7..3eb23e0f7d 100644 --- a/source4/lib/messaging/tests/irpc.c +++ b/source4/lib/messaging/tests/irpc.c @@ -54,9 +54,9 @@ static NTSTATUS irpc_AddOne(struct irpc_message *irpc, struct echo_AddOne *r) a deferred reply to echodata */ static void deferred_echodata(struct tevent_context *ev, struct tevent_timer *te, - struct timeval t, void *private) + struct timeval t, void *private_data) { - struct irpc_message *irpc = talloc_get_type(private, struct irpc_message); + struct irpc_message *irpc = talloc_get_type(private_data, struct irpc_message); struct echo_EchoData *r = irpc->data; r->out.out_data = talloc_memdup(r, r->in.in_data, r->in.len); if (r->out.out_data == NULL) { @@ -87,7 +87,7 @@ static bool test_addone(struct torture_context *test, const void *_data, struct echo_AddOne r; NTSTATUS status; const struct irpc_test_data *data = (const struct irpc_test_data *)_data; - uint32_t value = (uint32_t)_value; + uint32_t value = *(const uint32_t *)_value; /* make the call */ r.in.in_data = value; @@ -145,7 +145,7 @@ static bool test_echodata(struct torture_context *tctx, static void irpc_callback(struct irpc_request *irpc) { struct echo_AddOne *r = (struct echo_AddOne *)irpc->r; - int *pong_count = (int *)irpc->async.private; + int *pong_count = (int *)irpc->async.private_data; NTSTATUS status = irpc_call_recv(irpc); if (!NT_STATUS_IS_OK(status)) { printf("irpc call failed - %s\n", nt_errstr(status)); @@ -186,7 +186,7 @@ static bool test_speed(struct torture_context *tctx, torture_assert(tctx, irpc != NULL, "AddOne send failed"); irpc->async.fn = irpc_callback; - irpc->async.private = &pong_count; + irpc->async.private_data = &pong_count; ping_count++; @@ -261,7 +261,7 @@ struct torture_suite *torture_local_irpc(TALLOC_CTX *mem_ctx) for (i = 0; i < 5; i++) { torture_tcase_add_test_const(tcase, "addone", test_addone, - (void *)values[i]); + (void *)&values[i]); } torture_tcase_add_test_const(tcase, "echodata", test_echodata, NULL); diff --git a/source4/lib/messaging/tests/messaging.c b/source4/lib/messaging/tests/messaging.c index 838de55d83..f61132caac 100644 --- a/source4/lib/messaging/tests/messaging.c +++ b/source4/lib/messaging/tests/messaging.c @@ -29,7 +29,7 @@ static uint32_t msg_pong; -static void ping_message(struct messaging_context *msg, void *private, +static void ping_message(struct messaging_context *msg, void *private_data, uint32_t msg_type, struct server_id src, DATA_BLOB *data) { NTSTATUS status; @@ -39,17 +39,17 @@ static void ping_message(struct messaging_context *msg, void *private, } } -static void pong_message(struct messaging_context *msg, void *private, +static void pong_message(struct messaging_context *msg, void *private_data, uint32_t msg_type, struct server_id src, DATA_BLOB *data) { - int *count = private; + int *count = (int *)private_data; (*count)++; } -static void exit_message(struct messaging_context *msg, void *private, +static void exit_message(struct messaging_context *msg, void *private_data, uint32_t msg_type, struct server_id src, DATA_BLOB *data) { - talloc_free(private); + talloc_free(private_data); exit(0); } diff --git a/source4/lib/registry/config.mk b/source4/lib/registry/config.mk index 6528127b0b..a566042cf2 100644 --- a/source4/lib/registry/config.mk +++ b/source4/lib/registry/config.mk @@ -105,6 +105,6 @@ $(eval $(call proto_header_template,$(libregistrysrcdir)/tests/proto.h,$(torture [PYTHON::py_registry] LIBRARY_REALNAME = samba/registry.$(SHLIBEXT) -PUBLIC_DEPENDENCIES = registry PYTALLOC swig_credentials param +PUBLIC_DEPENDENCIES = registry PYTALLOC pycredentials param py_registry_OBJ_FILES = $(libregistrysrcdir)/pyregistry.o diff --git a/source4/lib/registry/tools/regshell.c b/source4/lib/registry/tools/regshell.c index 8939f21269..0fc06d1219 100644 --- a/source4/lib/registry/tools/regshell.c +++ b/source4/lib/registry/tools/regshell.c @@ -159,12 +159,12 @@ static WERROR cmd_set(struct regshell_context *ctx, int argc, char **argv) static WERROR cmd_ck(struct regshell_context *ctx, int argc, char **argv) { - struct registry_key *new = NULL; + struct registry_key *nkey = NULL; WERROR error; if(argc == 2) { error = reg_open_key(ctx->registry, ctx->current, argv[1], - &new); + &nkey); if(!W_ERROR_IS_OK(error)) { DEBUG(0, ("Error opening specified key: %s\n", win_errstr(error))); @@ -172,7 +172,7 @@ static WERROR cmd_ck(struct regshell_context *ctx, int argc, char **argv) } ctx->path = talloc_asprintf(ctx, "%s\\%s", ctx->path, argv[1]); - ctx->current = new; + ctx->current = nkey; } printf("New path is: %s\n", ctx->path); diff --git a/source4/lib/socket/config.m4 b/source4/lib/socket/config.m4 index 9c0072dd8b..fa987a1f46 100644 --- a/source4/lib/socket/config.m4 +++ b/source4/lib/socket/config.m4 @@ -1,6 +1,5 @@ AC_CHECK_FUNCS(writev) AC_CHECK_FUNCS(readv) -AC_CHECK_FUNCS(gethostbyname2) ############################################ # check for unix domain sockets diff --git a/source4/lib/socket/connect.c b/source4/lib/socket/connect.c index be15aa987b..b943de8c14 100644 --- a/source4/lib/socket/connect.c +++ b/source4/lib/socket/connect.c @@ -36,7 +36,7 @@ struct connect_state { static void socket_connect_handler(struct tevent_context *ev, struct tevent_fd *fde, - uint16_t flags, void *private); + uint16_t flags, void *private_data); /* call the real socket_connect() call, and setup event handler @@ -118,10 +118,10 @@ struct composite_context *socket_connect_send(struct socket_context *sock, */ static void socket_connect_handler(struct tevent_context *ev, struct tevent_fd *fde, - uint16_t flags, void *private) + uint16_t flags, void *private_data) { struct composite_context *result = - talloc_get_type(private, struct composite_context); + talloc_get_type(private_data, struct composite_context); struct connect_state *state = talloc_get_type(result->private_data, struct connect_state); diff --git a/source4/lib/socket/socket_ip.c b/source4/lib/socket/socket_ip.c index bca0aab924..cdb75fe021 100644 --- a/source4/lib/socket/socket_ip.c +++ b/source4/lib/socket/socket_ip.c @@ -549,19 +549,36 @@ _PUBLIC_ const struct socket_ops *socket_ipv4_ops(enum socket_type type) static struct in6_addr interpret_addr6(const char *name) { - struct hostent *he; - - if (name == NULL) return in6addr_any; + char addr[INET6_ADDRSTRLEN]; + struct in6_addr dest6; + const char *sp = name; + char *p = strchr_m(sp, '%'); + int ret; + + if (sp == NULL) return in6addr_any; - if (strcasecmp(name, "localhost") == 0) { - name = "::1"; + if (strcasecmp(sp, "localhost") == 0) { + sp = "::1"; } - he = gethostbyname2(name, PF_INET6); + /* + * Cope with link-local. + * This is IP:v6:addr%ifname. + */ + + if (p && (p > sp) && (if_nametoindex(p+1) != 0)) { + strlcpy(addr, sp, + MIN(PTR_DIFF(p,sp)+1, + sizeof(addr))); + sp = addr; + } - if (he == NULL) return in6addr_any; + ret = inet_pton(AF_INET6, sp, &dest6); + if (ret > 0) { + return dest6; + } - return *((struct in6_addr *)he->h_addr); + return in6addr_any; } static NTSTATUS ipv6_init(struct socket_context *sock) diff --git a/source4/lib/stream/packet.c b/source4/lib/stream/packet.c index 7882059faf..f614e9490a 100644 --- a/source4/lib/stream/packet.c +++ b/source4/lib/stream/packet.c @@ -37,7 +37,7 @@ struct packet_context { struct socket_context *sock; struct tevent_context *ev; size_t packet_size; - void *private; + void *private_data; struct tevent_fd *fde; bool serialise; int processing; @@ -105,9 +105,9 @@ _PUBLIC_ void packet_set_error_handler(struct packet_context *pc, packet_error_h /* set the private pointer passed to the callback functions */ -_PUBLIC_ void packet_set_private(struct packet_context *pc, void *private) +_PUBLIC_ void packet_set_private(struct packet_context *pc, void *private_data) { - pc->private = private; + pc->private_data = private_data; } /* @@ -184,15 +184,15 @@ static void packet_error(struct packet_context *pc, NTSTATUS status) { pc->sock = NULL; if (pc->error_handler) { - pc->error_handler(pc->private, status); + pc->error_handler(pc->private_data, status); return; } /* default error handler is to free the callers private pointer */ if (!NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { DEBUG(0,("packet_error on %s - %s\n", - talloc_get_name(pc->private), nt_errstr(status))); + talloc_get_name(pc->private_data), nt_errstr(status))); } - talloc_free(pc->private); + talloc_free(pc->private_data); return; } @@ -210,9 +210,9 @@ static void packet_eof(struct packet_context *pc) used to put packets on event boundaries */ static void packet_next_event(struct tevent_context *ev, struct tevent_timer *te, - struct timeval t, void *private) + struct timeval t, void *private_data) { - struct packet_context *pc = talloc_get_type(private, struct packet_context); + struct packet_context *pc = talloc_get_type(private_data, struct packet_context); if (pc->num_read != 0 && pc->packet_size != 0 && pc->packet_size <= pc->num_read) { packet_recv(pc); @@ -330,7 +330,7 @@ next_partial: /* see if its a full request */ blob = pc->partial; blob.length = pc->num_read; - status = pc->full_request(pc->private, blob, &pc->packet_size); + status = pc->full_request(pc->private_data, blob, &pc->packet_size); if (NT_STATUS_IS_ERR(status)) { packet_error(pc, status); return; @@ -375,7 +375,7 @@ next_partial: pc->busy = true; - status = pc->callback(pc->private, blob); + status = pc->callback(pc->private_data, blob); pc->busy = false; @@ -409,7 +409,7 @@ next_partial: blob = pc->partial; blob.length = pc->num_read; - status = pc->full_request(pc->private, blob, &pc->packet_size); + status = pc->full_request(pc->private_data, blob, &pc->packet_size); if (NT_STATUS_IS_ERR(status)) { packet_error(pc, status); return; @@ -495,7 +495,7 @@ _PUBLIC_ void packet_queue_run(struct packet_context *pc) */ _PUBLIC_ NTSTATUS packet_send_callback(struct packet_context *pc, DATA_BLOB blob, packet_send_callback_fn_t send_callback, - void *private) + void *private_data) { struct send_element *el; el = talloc(pc, struct send_element); @@ -505,7 +505,7 @@ _PUBLIC_ NTSTATUS packet_send_callback(struct packet_context *pc, DATA_BLOB blob el->blob = blob; el->nsent = 0; el->send_callback = send_callback; - el->send_callback_private = private; + el->send_callback_private = private_data; /* if we aren't going to free the packet then we must reference it to ensure it doesn't disappear before going out */ @@ -517,7 +517,7 @@ _PUBLIC_ NTSTATUS packet_send_callback(struct packet_context *pc, DATA_BLOB blob talloc_steal(el, blob.data); } - if (private && !talloc_reference(el, private)) { + if (private_data && !talloc_reference(el, private_data)) { return NT_STATUS_NO_MEMORY; } @@ -538,7 +538,7 @@ _PUBLIC_ NTSTATUS packet_send(struct packet_context *pc, DATA_BLOB blob) /* a full request checker for NBT formatted packets (first 3 bytes are length) */ -_PUBLIC_ NTSTATUS packet_full_request_nbt(void *private, DATA_BLOB blob, size_t *size) +_PUBLIC_ NTSTATUS packet_full_request_nbt(void *private_data, DATA_BLOB blob, size_t *size) { if (blob.length < 4) { return STATUS_MORE_ENTRIES; @@ -555,7 +555,7 @@ _PUBLIC_ NTSTATUS packet_full_request_nbt(void *private, DATA_BLOB blob, size_t work out if a packet is complete for protocols that use a 32 bit network byte order length */ -_PUBLIC_ NTSTATUS packet_full_request_u32(void *private, DATA_BLOB blob, size_t *size) +_PUBLIC_ NTSTATUS packet_full_request_u32(void *private_data, DATA_BLOB blob, size_t *size) { if (blob.length < 4) { return STATUS_MORE_ENTRIES; diff --git a/source4/lib/stream/packet.h b/source4/lib/stream/packet.h index c9bd9d4767..3c2fb0a683 100644 --- a/source4/lib/stream/packet.h +++ b/source4/lib/stream/packet.h @@ -24,20 +24,20 @@ struct packet_context; struct tevent_context; struct tevent_fd; -typedef NTSTATUS (*packet_full_request_fn_t)(void *private, +typedef NTSTATUS (*packet_full_request_fn_t)(void *private_data, DATA_BLOB blob, size_t *packet_size); -typedef NTSTATUS (*packet_callback_fn_t)(void *private, DATA_BLOB blob); +typedef NTSTATUS (*packet_callback_fn_t)(void *private_data, DATA_BLOB blob); /* Used to notify that a packet has been sent, and is on the wire */ -typedef void (*packet_send_callback_fn_t)(void *private); -typedef void (*packet_error_handler_fn_t)(void *private, NTSTATUS status); +typedef void (*packet_send_callback_fn_t)(void *private_data); +typedef void (*packet_error_handler_fn_t)(void *private_data, NTSTATUS status); struct packet_context *packet_init(TALLOC_CTX *mem_ctx); void packet_set_callback(struct packet_context *pc, packet_callback_fn_t callback); void packet_set_error_handler(struct packet_context *pc, packet_error_handler_fn_t handler); -void packet_set_private(struct packet_context *pc, void *private); +void packet_set_private(struct packet_context *pc, void *private_data); void packet_set_full_request(struct packet_context *pc, packet_full_request_fn_t callback); void packet_set_socket(struct packet_context *pc, struct socket_context *sock); void packet_set_event_context(struct packet_context *pc, struct tevent_context *ev); @@ -51,13 +51,13 @@ void packet_recv_enable(struct packet_context *pc); NTSTATUS packet_send(struct packet_context *pc, DATA_BLOB blob); NTSTATUS packet_send_callback(struct packet_context *pc, DATA_BLOB blob, packet_send_callback_fn_t send_callback, - void *private); + void *private_data); void packet_queue_run(struct packet_context *pc); /* pre-canned handlers */ -NTSTATUS packet_full_request_nbt(void *private, DATA_BLOB blob, size_t *size); -NTSTATUS packet_full_request_u32(void *private, DATA_BLOB blob, size_t *size); +NTSTATUS packet_full_request_nbt(void *private_data, DATA_BLOB blob, size_t *size); +NTSTATUS packet_full_request_u32(void *private_data, DATA_BLOB blob, size_t *size); |