From 03b0f279ed7d1ed7083e0c2301af94ff39f0e8a4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 17 Jun 2005 02:47:26 +0000 Subject: r7667: added a ldb ildap backend, using our internal ldap client library. Next step is to remove the check for the ldap libraries in configure (This used to be commit 74841dbb2a86bb1c584b5c26c4cd24a818a65a34) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 401 ++++++++++++++++++++++++++++++++++ 1 file changed, 401 insertions(+) create mode 100644 source4/lib/ldb/ldb_ildap/ldb_ildap.c (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c new file mode 100644 index 0000000000..c35d9de6b1 --- /dev/null +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -0,0 +1,401 @@ +/* + ldb database library - ildap backend + + Copyright (C) Andrew Tridgell 2005 + + ** 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 2 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, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* + This is a ldb backend for the internal ldap client library in + Samba4. By using this backend we are independent of a system ldap + library +*/ + + +#include "includes.h" +#include "ldb/include/ldb.h" +#include "ldb/include/ldb_private.h" +#include "libcli/ldap/ldap.h" +#include "libcli/ldap/ldap_client.h" + +struct ildb_private { + const char *basedn; + struct ldap_connection *ldap; + NTSTATUS last_rc; +}; + +/* + rename a record +*/ +static int ildb_rename(struct ldb_module *module, const char *olddn, const char *newdn) +{ + struct ildb_private *ildb = module->private_data; + int ret = 0; + char *newrdn, *p; + const char *parentdn = ""; + + /* ignore ltdb specials */ + if (olddn[0] == '@' ||newdn[0] == '@') { + return 0; + } + + newrdn = talloc_strdup(ildb, newdn); + if (!newrdn) { + return -1; + } + + p = strchr(newrdn, ','); + if (p) { + *p++ = '\0'; + parentdn = p; + } + + ildb->last_rc = ildap_rename(ildb->ldap, olddn, newrdn, parentdn, True); + if (!NT_STATUS_IS_OK(ildb->last_rc)) { + ret = -1; + } + + talloc_free(newrdn); + + return ret; +} + +/* + delete a record +*/ +static int ildb_delete(struct ldb_module *module, const char *dn) +{ + struct ildb_private *ildb = module->private_data; + int ret = 0; + + /* ignore ltdb specials */ + if (dn[0] == '@') { + return 0; + } + + ildb->last_rc = ildap_delete(ildb->ldap, dn); + if (!NT_STATUS_IS_OK(ildb->last_rc)) { + ret = -1; + } + + return ret; +} + + +/* + search for matching records +*/ +static int ildb_search(struct ldb_module *module, const char *base, + enum ldb_scope scope, const char *expression, + const char * const *attrs, struct ldb_message ***res) +{ + struct ildb_private *ildb = module->private_data; + int count, i; + struct ldap_message **ldapres, *msg; + + if (base == NULL) { + base = ""; + } + + if (expression == NULL || expression[0] == '\0') { + expression = "objectClass=*"; + } + + ildb->last_rc = ildap_search(ildb->ldap, base, scope, expression, attrs, + 0, &ldapres); + if (!NT_STATUS_IS_OK(ildb->last_rc)) { + return -1; + } + + count = ildap_count_entries(ildb->ldap, ldapres); + if (count == -1 || count == 0) { + talloc_free(ldapres); + return count; + } + + (*res) = talloc_array(ildb, struct ldb_message *, count+1); + if (! *res) { + talloc_free(ldapres); + return -1; + } + + (*res)[0] = NULL; + + /* loop over all messages */ + for (i=0;ir.SearchResultEntry; + + (*res)[i] = talloc(*res, struct ldb_message); + if (!(*res)[i]) { + goto failed; + } + (*res)[i+1] = NULL; + + (*res)[i]->dn = talloc_steal((*res)[i], search->dn); + (*res)[i]->num_elements = search->num_attributes; + (*res)[i]->elements = talloc_steal((*res)[i], search->attributes); + (*res)[i]->private_data = NULL; + } + + talloc_free(ldapres); + + return count; + +failed: + if (*res) talloc_free(*res); + return -1; +} + + +/* + search for matching records using a ldb_parse_tree +*/ +static int ildb_search_bytree(struct ldb_module *module, const char *base, + enum ldb_scope scope, struct ldb_parse_tree *tree, + const char * const *attrs, struct ldb_message ***res) +{ + struct ildb_private *ildb = module->private_data; + char *expression; + int ret; + + expression = ldb_filter_from_tree(ildb, tree); + if (expression == NULL) { + return -1; + } + ret = ildb_search(module, base, scope, expression, attrs, res); + talloc_free(expression); + return ret; +} + + +/* + convert a ldb_message structure to a list of ldap_mod structures + ready for ildap_add() or ildap_modify() +*/ +static struct ldap_mod **ildb_msg_to_mods(struct ldb_context *ldb, + const struct ldb_message *msg, int use_flags) +{ + struct ldap_mod **mods; + unsigned int i; + int num_mods = 0; + + /* allocate maximum number of elements needed */ + mods = talloc_array(ldb, struct ldap_mod *, msg->num_elements+1); + if (!mods) { + errno = ENOMEM; + return NULL; + } + mods[0] = NULL; + + for (i=0;inum_elements;i++) { + const struct ldb_message_element *el = &msg->elements[i]; + + mods[num_mods] = talloc(ldb, struct ldap_mod); + if (!mods[num_mods]) { + goto failed; + } + mods[num_mods+1] = NULL; + mods[num_mods]->type = 0; + mods[num_mods]->attrib = *el; + if (use_flags) { + switch (el->flags & LDB_FLAG_MOD_MASK) { + case LDB_FLAG_MOD_ADD: + mods[num_mods]->type = LDAP_MODIFY_ADD; + break; + case LDB_FLAG_MOD_DELETE: + mods[num_mods]->type = LDAP_MODIFY_DELETE; + break; + case LDB_FLAG_MOD_REPLACE: + mods[num_mods]->type = LDAP_MODIFY_REPLACE; + break; + } + } + num_mods++; + } + + return mods; + +failed: + talloc_free(mods); + return NULL; +} + + +/* + add a record +*/ +static int ildb_add(struct ldb_module *module, const struct ldb_message *msg) +{ + struct ldb_context *ldb = module->ldb; + struct ildb_private *ildb = module->private_data; + struct ldap_mod **mods; + int ret = 0; + + /* ignore ltdb specials */ + if (msg->dn[0] == '@') { + return 0; + } + + mods = ildb_msg_to_mods(ldb, msg, 0); + + ildb->last_rc = ildap_add(ildb->ldap, msg->dn, mods); + if (!NT_STATUS_IS_OK(ildb->last_rc)) { + ret = -1; + } + + talloc_free(mods); + + return ret; +} + + +/* + modify a record +*/ +static int ildb_modify(struct ldb_module *module, const struct ldb_message *msg) +{ + struct ldb_context *ldb = module->ldb; + struct ildb_private *ildb = module->private_data; + struct ldap_mod **mods; + int ret = 0; + + /* ignore ltdb specials */ + if (msg->dn[0] == '@') { + return 0; + } + + mods = ildb_msg_to_mods(ldb, msg, 1); + + ildb->last_rc = ildap_modify(ildb->ldap, msg->dn, mods); + if (!NT_STATUS_IS_OK(ildb->last_rc)) { + ret = -1; + } + + talloc_free(mods); + + return ret; +} + +static int ildb_lock(struct ldb_module *module, const char *lockname) +{ + int ret = 0; + + if (lockname == NULL) { + return -1; + } + + /* TODO implement a local locking mechanism here */ + + return ret; +} + +static int ildb_unlock(struct ldb_module *module, const char *lockname) +{ + int ret = 0; + + if (lockname == NULL) { + return -1; + } + + /* TODO implement a local unlocking mechanism here */ + + return ret; +} + +/* + return extended error information +*/ +static const char *ildb_errstring(struct ldb_module *module) +{ + struct ildb_private *ildb = module->private_data; + return ldap_errstr(ildb->ldap, ildb->last_rc); +} + + +static const struct ldb_module_ops ildb_ops = { + .name = "ldap", + .search = ildb_search, + .search_bytree = ildb_search_bytree, + .add_record = ildb_add, + .modify_record = ildb_modify, + .delete_record = ildb_delete, + .rename_record = ildb_rename, + .named_lock = ildb_lock, + .named_unlock = ildb_unlock, + .errstring = ildb_errstring +}; + + +/* + connect to the database +*/ +struct ldb_context *ildb_connect(const char *url, + unsigned int flags, + const char *options[]) +{ + struct ldb_context *ldb = NULL; + struct ildb_private *ildb = NULL; + NTSTATUS status; + + ldb = talloc(NULL, struct ldb_context); + if (!ldb) { + errno = ENOMEM; + goto failed; + } + + ldb->debug_ops.debug = NULL; + + ildb = talloc(ldb, struct ildb_private); + if (!ildb) { + errno = ENOMEM; + goto failed; + } + + ildb->ldap = ldap_new_connection(ildb, NULL); + if (!ildb->ldap) { + errno = ENOMEM; + goto failed; + } + + status = ldap_connect(ildb->ldap, url); + if (!NT_STATUS_IS_OK(status)) { + goto failed; + } + + ldb->modules = talloc(ldb, struct ldb_module); + if (!ldb->modules) { + errno = ENOMEM; + goto failed; + } + ldb->modules->ldb = ldb; + ldb->modules->prev = ldb->modules->next = NULL; + ldb->modules->private_data = ildb; + ldb->modules->ops = &ildb_ops; + + return ldb; + +failed: + talloc_free(ldb); + return NULL; +} + -- cgit From ed3d8091ce2b2014350a2f7f22202dde6846a130 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 18 Jun 2005 07:42:21 +0000 Subject: r7709: - convert ldb to use popt, so that it can interact with the samba cmdline credentials code (which will be done soon) - added a ldb_init() call, and changed ldb_connect() to take a ldb context. This allows for much better error handling in ldb_connect(), and also made the popt conversion easier - fixed up all the existing backends with the new syntax - improved error handling in *_connect() - fixed a crash bug in the new case_fold_required() code - ensured that ltdb_rename() and all ltdb_search() paths get the read lock - added a ldb_oom() macro to make it easier to report out of memory situations in ldb code (This used to be commit f648fdf187669d6d87d01dd4e786b03cd420f220) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index c35d9de6b1..aa0efee481 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -349,42 +349,34 @@ static const struct ldb_module_ops ildb_ops = { /* connect to the database */ -struct ldb_context *ildb_connect(const char *url, - unsigned int flags, - const char *options[]) +int ildb_connect(struct ldb_context *ldb, const char *url, + unsigned int flags, const char *options[]) { - struct ldb_context *ldb = NULL; struct ildb_private *ildb = NULL; NTSTATUS status; - ldb = talloc(NULL, struct ldb_context); - if (!ldb) { - errno = ENOMEM; - goto failed; - } - - ldb->debug_ops.debug = NULL; - ildb = talloc(ldb, struct ildb_private); if (!ildb) { - errno = ENOMEM; + ldb_oom(ldb); goto failed; } ildb->ldap = ldap_new_connection(ildb, NULL); if (!ildb->ldap) { - errno = ENOMEM; + ldb_oom(ldb); goto failed; } status = ldap_connect(ildb->ldap, url); if (!NT_STATUS_IS_OK(status)) { + ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to connect to ldap URL '%s' - %s\n", + url, ldap_errstr(ildb->ldap, status)); goto failed; } ldb->modules = talloc(ldb, struct ldb_module); if (!ldb->modules) { - errno = ENOMEM; + ldb_oom(ldb); goto failed; } ldb->modules->ldb = ldb; @@ -392,10 +384,10 @@ struct ldb_context *ildb_connect(const char *url, ldb->modules->private_data = ildb; ldb->modules->ops = &ildb_ops; - return ldb; + return 0; failed: - talloc_free(ldb); - return NULL; + talloc_free(ildb); + return -1; } -- cgit From f40e69da2633771a42ec2b74fca63bd0b0a37e4a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 18 Jun 2005 09:01:09 +0000 Subject: r7714: enable samba credentials handling in ldb tools. So you can now do a encrypted ldbedit against w2k3 (This used to be commit 6277c3923e7d9c26753424b1e77ac62f8e0729a4) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index aa0efee481..9cccec0313 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -34,6 +34,7 @@ #include "ldb/include/ldb_private.h" #include "libcli/ldap/ldap.h" #include "libcli/ldap/ldap_client.h" +#include "lib/cmdline/popt_common.h" struct ildb_private { const char *basedn; @@ -110,6 +111,10 @@ static int ildb_search(struct ldb_module *module, const char *base, int count, i; struct ldap_message **ldapres, *msg; + if (scope == LDB_SCOPE_DEFAULT) { + scope = LDB_SCOPE_SUBTREE; + } + if (base == NULL) { base = ""; } @@ -384,6 +389,15 @@ int ildb_connect(struct ldb_context *ldb, const char *url, ldb->modules->private_data = ildb; ldb->modules->ops = &ildb_ops; + if (cmdline_credentials->username_obtained > CRED_GUESSED) { + status = ldap_bind_sasl(ildb->ldap, cmdline_credentials); + if (!NT_STATUS_IS_OK(status)) { + ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to bind - %s\n", + ldap_errstr(ildb->ldap, status)); + goto failed; + } + } + return 0; failed: -- cgit From 97318cdb45f1022ca2beebbf24ab11af80c07dc2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 18 Jun 2005 09:48:17 +0000 Subject: r7719: make the ildap ldb backend use the defaultNamingContext if the basedn is not specified, so: ldbsearch ldap://hostname '(objectclass=user)' works without knowing the domain name (This used to be commit f6c2c5190737ca11f55a147f5295ccca505fb58b) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 9cccec0313..3f63af482f 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -37,9 +37,9 @@ #include "lib/cmdline/popt_common.h" struct ildb_private { - const char *basedn; struct ldap_connection *ldap; NTSTATUS last_rc; + struct ldb_message *rootDSE; }; /* @@ -100,6 +100,8 @@ static int ildb_delete(struct ldb_module *module, const char *dn) } +static void ildb_rootdse(struct ldb_module *module); + /* search for matching records */ @@ -116,7 +118,13 @@ static int ildb_search(struct ldb_module *module, const char *base, } if (base == NULL) { - base = ""; + if (ildb->rootDSE == NULL) { + ildb_rootdse(module); + } + if (ildb->rootDSE != NULL) { + base = ldb_msg_find_string(ildb->rootDSE, + "defaultNamingContext", ""); + } } if (expression == NULL || expression[0] == '\0') { @@ -351,6 +359,22 @@ static const struct ldb_module_ops ildb_ops = { }; +/* + fetch the rootDSE +*/ +static void ildb_rootdse(struct ldb_module *module) +{ + struct ildb_private *ildb = module->private_data; + struct ldb_message **res = NULL; + int ret; + ret = ildb_search(module, "", LDB_SCOPE_BASE, "dn=dc=rootDSE", NULL, &res); + if (ret == 1) { + ildb->rootDSE = talloc_steal(ildb, res[0]); + } + talloc_free(res); +} + + /* connect to the database */ @@ -366,6 +390,8 @@ int ildb_connect(struct ldb_context *ldb, const char *url, goto failed; } + ildb->rootDSE = NULL; + ildb->ldap = ldap_new_connection(ildb, NULL); if (!ildb->ldap) { ldb_oom(ldb); -- cgit From bf75ae41556a67739cd089a7e3182cf2a994448c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 18 Jun 2005 13:18:43 +0000 Subject: r7726: - removed some unused variables - handle ldb_errstring() calls on failed connect (This used to be commit 8698a20fcc6a04ccbe533afd742e7a5df94423ee) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 3f63af482f..6560485be5 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -340,7 +340,11 @@ static int ildb_unlock(struct ldb_module *module, const char *lockname) */ static const char *ildb_errstring(struct ldb_module *module) { - struct ildb_private *ildb = module->private_data; + struct ildb_private *ildb = talloc_get_type(module->private_data, + struct ildb_private); + if (ildb == NULL) { + return "ildap not connected"; + } return ldap_errstr(ildb->ldap, ildb->last_rc); } @@ -427,6 +431,9 @@ int ildb_connect(struct ldb_context *ldb, const char *url, return 0; failed: + if (ldb->modules) { + ldb->modules->private_data = NULL; + } talloc_free(ildb); return -1; } -- cgit From 7267cb3312f148be8cd00eb76b8e137cd4b2a314 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 19 Jun 2005 10:37:45 +0000 Subject: r7749: some bug fixes from testing with socket:testnonblock - fixed some infinite loops in asn1.c - ensure asn1 callers know if an error is end of buffer or bad data - handle npending 0 in ldap server (This used to be commit f22c3b84c8912ccd36e676a782b58f1841be8875) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 6560485be5..eefe80c919 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -124,6 +124,8 @@ static int ildb_search(struct ldb_module *module, const char *base, if (ildb->rootDSE != NULL) { base = ldb_msg_find_string(ildb->rootDSE, "defaultNamingContext", ""); + } else { + base = ""; } } -- cgit From bd7a474b1967423711ff93c0080ce0f89270e3f9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 20 Jun 2005 04:56:43 +0000 Subject: r7776: add a method for getting arbitrary opaque data into a ldb context, for use by backends. Currently only EventContext is used in this way. (This used to be commit 9fa21b245843371f7777682ee4e5b98e2925b4d0) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index eefe80c919..b51139aa6f 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -398,7 +398,7 @@ int ildb_connect(struct ldb_context *ldb, const char *url, ildb->rootDSE = NULL; - ildb->ldap = ldap_new_connection(ildb, NULL); + ildb->ldap = ldap_new_connection(ildb, ldb_get_opaque(ldb, "EventContext")); if (!ildb->ldap) { ldb_oom(ldb); goto failed; @@ -421,7 +421,8 @@ int ildb_connect(struct ldb_context *ldb, const char *url, ldb->modules->private_data = ildb; ldb->modules->ops = &ildb_ops; - if (cmdline_credentials->username_obtained > CRED_GUESSED) { + if (cmdline_credentials != NULL && + cmdline_credentials->username_obtained > CRED_GUESSED) { status = ldap_bind_sasl(ildb->ldap, cmdline_credentials); if (!NT_STATUS_IS_OK(status)) { ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to bind - %s\n", -- cgit From 3e4c4cff2177af33efdb15f03a1bbcb639505cee Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Thu, 18 Aug 2005 15:02:01 +0000 Subject: r9391: Convert all the code to use struct ldb_dn to ohandle ldap like distinguished names Provide more functions to handle DNs in this form (This used to be commit 692e35b7797e39533dd2a1c4b63d9da30f1eb5ba) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 111 +++++++++++++++++++++++++--------- 1 file changed, 82 insertions(+), 29 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index b51139aa6f..bb89fc910e 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -45,57 +45,77 @@ struct ildb_private { /* rename a record */ -static int ildb_rename(struct ldb_module *module, const char *olddn, const char *newdn) +static int ildb_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn) { + TALLOC_CTX *local_ctx; struct ildb_private *ildb = module->private_data; int ret = 0; - char *newrdn, *p; - const char *parentdn = ""; + char *old_dn; + char *newrdn, *parentdn; /* ignore ltdb specials */ - if (olddn[0] == '@' ||newdn[0] == '@') { + if (ldb_dn_is_special(olddn) || ldb_dn_is_special(newdn)) { return 0; } - newrdn = talloc_strdup(ildb, newdn); - if (!newrdn) { + local_ctx = talloc_named(ildb, 0, "ildb_rename local context"); + if (local_ctx == NULL) { return -1; } - p = strchr(newrdn, ','); - if (p) { - *p++ = '\0'; - parentdn = p; + old_dn = ldb_dn_linearize(local_ctx, olddn); + if (old_dn == NULL) { + goto failed; + } + + newrdn = talloc_asprintf(local_ctx, "%s=%s", + newdn->components[0].name, + ldb_dn_escape_value(ildb, newdn->components[0].value)); + if (newrdn == NULL) { + goto failed; + } + + parentdn = ldb_dn_linearize(local_ctx, ldb_dn_get_parent(ildb, newdn)); + if (parentdn == NULL) { + goto failed; } - ildb->last_rc = ildap_rename(ildb->ldap, olddn, newrdn, parentdn, True); + ildb->last_rc = ildap_rename(ildb->ldap, old_dn, newrdn, parentdn, True); if (!NT_STATUS_IS_OK(ildb->last_rc)) { ret = -1; } - talloc_free(newrdn); - + talloc_free(local_ctx); return ret; + +failed: + talloc_free(local_ctx); + return -1; } /* delete a record */ -static int ildb_delete(struct ldb_module *module, const char *dn) +static int ildb_delete(struct ldb_module *module, const struct ldb_dn *dn) { struct ildb_private *ildb = module->private_data; + char *del_dn; int ret = 0; /* ignore ltdb specials */ - if (dn[0] == '@') { + if (ldb_dn_is_special(dn)) { return 0; } - ildb->last_rc = ildap_delete(ildb->ldap, dn); + del_dn = ldb_dn_linearize(ildb, dn); + + ildb->last_rc = ildap_delete(ildb->ldap, del_dn); if (!NT_STATUS_IS_OK(ildb->last_rc)) { ret = -1; } + talloc_free(del_dn); + return ret; } @@ -105,13 +125,14 @@ static void ildb_rootdse(struct ldb_module *module); /* search for matching records */ -static int ildb_search(struct ldb_module *module, const char *base, +static int ildb_search(struct ldb_module *module, const struct ldb_dn *base, enum ldb_scope scope, const char *expression, const char * const *attrs, struct ldb_message ***res) { struct ildb_private *ildb = module->private_data; int count, i; struct ldap_message **ldapres, *msg; + char *search_base; if (scope == LDB_SCOPE_DEFAULT) { scope = LDB_SCOPE_SUBTREE; @@ -122,19 +143,26 @@ static int ildb_search(struct ldb_module *module, const char *base, ildb_rootdse(module); } if (ildb->rootDSE != NULL) { - base = ldb_msg_find_string(ildb->rootDSE, - "defaultNamingContext", ""); + search_base = talloc_strdup(ildb, + ldb_msg_find_string(ildb->rootDSE, + "defaultNamingContext", "")); } else { - base = ""; + search_base = talloc_strdup(ildb, ""); } + } else { + search_base = ldb_dn_linearize(ildb, base); + } + if (search_base == NULL) { + return -1; } if (expression == NULL || expression[0] == '\0') { expression = "objectClass=*"; } - ildb->last_rc = ildap_search(ildb->ldap, base, scope, expression, attrs, + ildb->last_rc = ildap_search(ildb->ldap, search_base, scope, expression, attrs, 0, &ldapres); + talloc_free(search_base); if (!NT_STATUS_IS_OK(ildb->last_rc)) { return -1; } @@ -166,7 +194,10 @@ static int ildb_search(struct ldb_module *module, const char *base, } (*res)[i+1] = NULL; - (*res)[i]->dn = talloc_steal((*res)[i], search->dn); + (*res)[i]->dn = ldb_dn_explode((*res)[i], search->dn); + if ((*res)[i]->dn == NULL) { + goto failed; + } (*res)[i]->num_elements = search->num_attributes; (*res)[i]->elements = talloc_steal((*res)[i], search->attributes); (*res)[i]->private_data = NULL; @@ -185,7 +216,7 @@ failed: /* search for matching records using a ldb_parse_tree */ -static int ildb_search_bytree(struct ldb_module *module, const char *base, +static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, enum ldb_scope scope, struct ldb_parse_tree *tree, const char * const *attrs, struct ldb_message ***res) { @@ -264,16 +295,26 @@ static int ildb_add(struct ldb_module *module, const struct ldb_message *msg) struct ldb_context *ldb = module->ldb; struct ildb_private *ildb = module->private_data; struct ldap_mod **mods; + char *dn; int ret = 0; /* ignore ltdb specials */ - if (msg->dn[0] == '@') { + if (ldb_dn_is_special(msg->dn)) { return 0; } mods = ildb_msg_to_mods(ldb, msg, 0); + if (mods == NULL) { + return -1; + } - ildb->last_rc = ildap_add(ildb->ldap, msg->dn, mods); + dn = ldb_dn_linearize(mods, msg->dn); + if (dn == NULL) { + talloc_free(mods); + return -1; + } + + ildb->last_rc = ildap_add(ildb->ldap, dn, mods); if (!NT_STATUS_IS_OK(ildb->last_rc)) { ret = -1; } @@ -292,16 +333,26 @@ static int ildb_modify(struct ldb_module *module, const struct ldb_message *msg) struct ldb_context *ldb = module->ldb; struct ildb_private *ildb = module->private_data; struct ldap_mod **mods; + char *dn; int ret = 0; /* ignore ltdb specials */ - if (msg->dn[0] == '@') { + if (ldb_dn_is_special(msg->dn)) { return 0; } mods = ildb_msg_to_mods(ldb, msg, 1); + if (mods == NULL) { + return -1; + } + + dn = ldb_dn_linearize(mods, msg->dn); + if (dn == NULL) { + talloc_free(mods); + return -1; + } - ildb->last_rc = ildap_modify(ildb->ldap, msg->dn, mods); + ildb->last_rc = ildap_modify(ildb->ldap, dn, mods); if (!NT_STATUS_IS_OK(ildb->last_rc)) { ret = -1; } @@ -372,12 +423,14 @@ static void ildb_rootdse(struct ldb_module *module) { struct ildb_private *ildb = module->private_data; struct ldb_message **res = NULL; + struct ldb_dn *empty_dn = ldb_dn_new(ildb); int ret; - ret = ildb_search(module, "", LDB_SCOPE_BASE, "dn=dc=rootDSE", NULL, &res); + ret = ildb_search(module, empty_dn, LDB_SCOPE_BASE, "dn=dc=rootDSE", NULL, &res); if (ret == 1) { ildb->rootDSE = talloc_steal(ildb, res[0]); } - talloc_free(res); + if (ret != -1) talloc_free(res); + talloc_free(empty_dn); } -- cgit From 24186a80eb4887b5fb3e72e4b877b456cbe8e35f Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 29 Aug 2005 04:30:22 +0000 Subject: r9728: A *major* update to the credentials system, to incorporate the Kerberos CCACHE into the system. This again allows the use of the system ccache when no username is specified, and brings more code in common between gensec_krb5 and gensec_gssapi. It also has a side-effect that may (or may not) be expected: If there is a ccache, even if it is not used (perhaps the remote server didn't want kerberos), it will change the default username. Andrew Bartlett (This used to be commit 6202267f6ec1446d6bd11d1d37d05a977bc8d315) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index bb89fc910e..3d47863067 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -474,8 +474,7 @@ int ildb_connect(struct ldb_context *ldb, const char *url, ldb->modules->private_data = ildb; ldb->modules->ops = &ildb_ops; - if (cmdline_credentials != NULL && - cmdline_credentials->username_obtained > CRED_GUESSED) { + if (cmdline_credentials != NULL && cli_credentials_authentication_requested(cmdline_credentials)) { status = ldap_bind_sasl(ildb->ldap, cmdline_credentials); if (!NT_STATUS_IS_OK(status)) { ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to bind - %s\n", -- cgit From 8919d6bf9a88ce9ac43dae61989c33082c984b66 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 17 Sep 2005 19:25:50 +0000 Subject: r10299: remove the public (un)lock functions and introduce a transaction based private ldb API ldb_sqlite3 is already working with this model and ldb_tdb will do as soon as tridge finishes the tdb transaction code. currently the transactions are always implicit and wrap any single ldb API call except searching, the transaction functions are currently not made public on purpose. Simo. (This used to be commit 1da4ac2cdcb7e54076f85242a93784260dced918) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 42 +++++++++++++---------------------- 1 file changed, 15 insertions(+), 27 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 3d47863067..d4239c0f72 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -362,30 +362,18 @@ static int ildb_modify(struct ldb_module *module, const struct ldb_message *msg) return ret; } -static int ildb_lock(struct ldb_module *module, const char *lockname) +static int ildb_start_trans(struct ldb_module *module) { - int ret = 0; - - if (lockname == NULL) { - return -1; - } - /* TODO implement a local locking mechanism here */ - return ret; + return 0; } -static int ildb_unlock(struct ldb_module *module, const char *lockname) +static int ildb_end_trans(struct ldb_module *module, int status) { - int ret = 0; - - if (lockname == NULL) { - return -1; - } - - /* TODO implement a local unlocking mechanism here */ + /* TODO implement a local transaction mechanism here */ - return ret; + return status; } /* @@ -403,16 +391,16 @@ static const char *ildb_errstring(struct ldb_module *module) static const struct ldb_module_ops ildb_ops = { - .name = "ldap", - .search = ildb_search, - .search_bytree = ildb_search_bytree, - .add_record = ildb_add, - .modify_record = ildb_modify, - .delete_record = ildb_delete, - .rename_record = ildb_rename, - .named_lock = ildb_lock, - .named_unlock = ildb_unlock, - .errstring = ildb_errstring + .name = "ldap", + .search = ildb_search, + .search_bytree = ildb_search_bytree, + .add_record = ildb_add, + .modify_record = ildb_modify, + .delete_record = ildb_delete, + .rename_record = ildb_rename, + .start_transaction = ildb_start_trans, + .end_transaction = ildb_end_trans, + .errstring = ildb_errstring }; -- cgit From 16aff2a184f7fab64d718b356056070e305e99e9 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 18 Sep 2005 18:49:06 +0000 Subject: r10305: start implementing better error handling changed the prioivate modules API error string are now not spread over all modules but are kept in a single place. This allows a better control of memory and error reporting. (This used to be commit 3fc676ac1d6f59d08bedbbd9377986154cf84ce4) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index d4239c0f72..be51a65c58 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -82,6 +82,7 @@ static int ildb_rename(struct ldb_module *module, const struct ldb_dn *olddn, co ildb->last_rc = ildap_rename(ildb->ldap, old_dn, newrdn, parentdn, True); if (!NT_STATUS_IS_OK(ildb->last_rc)) { + ldb_set_errstring(module, talloc_strdup(module, ldap_errstr(ildb->ldap, ildb->last_rc))); ret = -1; } @@ -111,6 +112,7 @@ static int ildb_delete(struct ldb_module *module, const struct ldb_dn *dn) ildb->last_rc = ildap_delete(ildb->ldap, del_dn); if (!NT_STATUS_IS_OK(ildb->last_rc)) { + ldb_set_errstring(module, talloc_strdup(module, ldap_errstr(ildb->ldap, ildb->last_rc))); ret = -1; } @@ -316,6 +318,7 @@ static int ildb_add(struct ldb_module *module, const struct ldb_message *msg) ildb->last_rc = ildap_add(ildb->ldap, dn, mods); if (!NT_STATUS_IS_OK(ildb->last_rc)) { + ldb_set_errstring(module, talloc_strdup(module, ldap_errstr(ildb->ldap, ildb->last_rc))); ret = -1; } @@ -354,6 +357,7 @@ static int ildb_modify(struct ldb_module *module, const struct ldb_message *msg) ildb->last_rc = ildap_modify(ildb->ldap, dn, mods); if (!NT_STATUS_IS_OK(ildb->last_rc)) { + ldb_set_errstring(module, talloc_strdup(module, ldap_errstr(ildb->ldap, ildb->last_rc))); ret = -1; } @@ -376,20 +380,6 @@ static int ildb_end_trans(struct ldb_module *module, int status) return status; } -/* - return extended error information -*/ -static const char *ildb_errstring(struct ldb_module *module) -{ - struct ildb_private *ildb = talloc_get_type(module->private_data, - struct ildb_private); - if (ildb == NULL) { - return "ildap not connected"; - } - return ldap_errstr(ildb->ldap, ildb->last_rc); -} - - static const struct ldb_module_ops ildb_ops = { .name = "ldap", .search = ildb_search, @@ -399,8 +389,7 @@ static const struct ldb_module_ops ildb_ops = { .delete_record = ildb_delete, .rename_record = ildb_rename, .start_transaction = ildb_start_trans, - .end_transaction = ildb_end_trans, - .errstring = ildb_errstring + .end_transaction = ildb_end_trans }; -- cgit From 63b43dd12fb579aaaccedd07aaa630cb1cd7aa88 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 24 Sep 2005 15:42:15 +0000 Subject: r10477: expose transactions outside ldb and change the API once more do not autostart transactions on ldb operations if a transaction is already in place test transactions on winsdb all my tests passes so far tridge please confirm this is ok for you (This used to be commit c2bb2a36bdbe0ec7519697a9a9ba7526a0defac2) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index be51a65c58..ffb812acd0 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -373,11 +373,18 @@ static int ildb_start_trans(struct ldb_module *module) return 0; } -static int ildb_end_trans(struct ldb_module *module, int status) +static int ildb_end_trans(struct ldb_module *module) { /* TODO implement a local transaction mechanism here */ - return status; + return 0; +} + +static int ildb_del_trans(struct ldb_module *module) +{ + /* TODO implement a local locking mechanism here */ + + return 0; } static const struct ldb_module_ops ildb_ops = { @@ -389,7 +396,8 @@ static const struct ldb_module_ops ildb_ops = { .delete_record = ildb_delete, .rename_record = ildb_rename, .start_transaction = ildb_start_trans, - .end_transaction = ildb_end_trans + .end_transaction = ildb_end_trans, + .del_transaction = ildb_del_trans }; -- cgit From 588abdba90c9abae3c8ecf5eb45764bbc447b229 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 30 Sep 2005 03:42:07 +0000 Subject: r10641: fixed the error handling on search errors in the ildap backend (This used to be commit e80d42933fe3cbc18cb229e47fffb9ca8068aca5) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index ffb812acd0..499ce054d0 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -166,6 +166,7 @@ static int ildb_search(struct ldb_module *module, const struct ldb_dn *base, 0, &ldapres); talloc_free(search_base); if (!NT_STATUS_IS_OK(ildb->last_rc)) { + ldb_set_errstring(module, talloc_strdup(module, ldap_errstr(ildb->ldap, ildb->last_rc))); return -1; } -- cgit From a788d01b871a7e5813ac3934bcb0ba33fe711aa2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 30 Sep 2005 23:46:41 +0000 Subject: r10666: - reverse the ildap ldb backend so tree based searches go through directly, and expression based searches are converted to trees. This makes for less conversions. - allow the caller to supply a set of credentials via the ldb opaque name 'credentials'. I will be using this in my ldb proxy module. (This used to be commit af24f3d7faac6ef74feef73a23345d8c484da07c) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 50 ++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 22 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 499ce054d0..5ea49a8216 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -125,11 +125,11 @@ static int ildb_delete(struct ldb_module *module, const struct ldb_dn *dn) static void ildb_rootdse(struct ldb_module *module); /* - search for matching records + search for matching records using a ldb_parse_tree */ -static int ildb_search(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, const char *expression, - const char * const *attrs, struct ldb_message ***res) +static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, + enum ldb_scope scope, struct ldb_parse_tree *tree, + const char * const *attrs, struct ldb_message ***res) { struct ildb_private *ildb = module->private_data; int count, i; @@ -158,12 +158,8 @@ static int ildb_search(struct ldb_module *module, const struct ldb_dn *base, return -1; } - if (expression == NULL || expression[0] == '\0') { - expression = "objectClass=*"; - } - - ildb->last_rc = ildap_search(ildb->ldap, search_base, scope, expression, attrs, - 0, &ldapres); + ildb->last_rc = ildap_search_bytree(ildb->ldap, search_base, scope, tree, attrs, + 0, &ldapres); talloc_free(search_base); if (!NT_STATUS_IS_OK(ildb->last_rc)) { ldb_set_errstring(module, talloc_strdup(module, ldap_errstr(ildb->ldap, ildb->last_rc))); @@ -217,22 +213,25 @@ failed: /* - search for matching records using a ldb_parse_tree + search for matching records */ -static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const *attrs, struct ldb_message ***res) +static int ildb_search(struct ldb_module *module, const struct ldb_dn *base, + enum ldb_scope scope, const char *expression, + const char * const *attrs, struct ldb_message ***res) { struct ildb_private *ildb = module->private_data; - char *expression; int ret; + struct ldb_parse_tree *tree; - expression = ldb_filter_from_tree(ildb, tree); - if (expression == NULL) { - return -1; + if (expression == NULL || expression[0] == '\0') { + expression = "objectClass=*"; } - ret = ildb_search(module, base, scope, expression, attrs, res); - talloc_free(expression); + + tree = ldb_parse_tree(ildb, expression); + + ret = ildb_search_bytree(module, base, scope, tree, attrs, res); + + talloc_free(tree); return ret; } @@ -428,6 +427,7 @@ int ildb_connect(struct ldb_context *ldb, const char *url, { struct ildb_private *ildb = NULL; NTSTATUS status; + struct cli_credentials *creds; ildb = talloc(ldb, struct ildb_private); if (!ildb) { @@ -460,8 +460,14 @@ int ildb_connect(struct ldb_context *ldb, const char *url, ldb->modules->private_data = ildb; ldb->modules->ops = &ildb_ops; - if (cmdline_credentials != NULL && cli_credentials_authentication_requested(cmdline_credentials)) { - status = ldap_bind_sasl(ildb->ldap, cmdline_credentials); + /* caller can optionally setup credentials using the opaque token 'credentials' */ + creds = ldb_get_opaque(ldb, "credentials"); + if (creds == NULL) { + creds = cmdline_credentials; + } + + if (creds != NULL && cli_credentials_authentication_requested(creds)) { + status = ldap_bind_sasl(ildb->ldap, creds); if (!NT_STATUS_IS_OK(status)) { ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to bind - %s\n", ldap_errstr(ildb->ldap, status)); -- cgit From 63d4cb48029e8bd607604e40bbbc46d20d917d80 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 4 Oct 2005 05:41:05 +0000 Subject: r10708: a bit more error checking in the idap ldb backend (This used to be commit 63ebaad393e38b28c8f97f33e2b22f2445733405) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 5ea49a8216..4ff8723d44 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -155,6 +155,11 @@ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba search_base = ldb_dn_linearize(ildb, base); } if (search_base == NULL) { + ldb_set_errstring(module, talloc_asprintf(module, "Unable to determine baseDN")); + return -1; + } + if (tree == NULL) { + ldb_set_errstring(module, talloc_asprintf(module, "Invalid expression parse tree")); return -1; } -- cgit From 5fd031c97daaa1bf09a7ad80550753acd434075f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Oct 2005 05:24:46 +0000 Subject: r10753: don't require every ldb module to implement both a search_bytree() and a search() function, instead each module now only implements the bytree method, and the expression based search is handled generically by the modules code. This makes for more consistency and less code duplication. fixed the tdb backend to handle BASE searches much more efficiently. They now always only lookup one record, regardless of the search expression (This used to be commit 7e44f9153c5578624e2fca04cdc0a00af0fd9eb4) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 4ff8723d44..ad316bb0a2 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -217,30 +217,6 @@ failed: } -/* - search for matching records -*/ -static int ildb_search(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, const char *expression, - const char * const *attrs, struct ldb_message ***res) -{ - struct ildb_private *ildb = module->private_data; - int ret; - struct ldb_parse_tree *tree; - - if (expression == NULL || expression[0] == '\0') { - expression = "objectClass=*"; - } - - tree = ldb_parse_tree(ildb, expression); - - ret = ildb_search_bytree(module, base, scope, tree, attrs, res); - - talloc_free(tree); - return ret; -} - - /* convert a ldb_message structure to a list of ldap_mod structures ready for ildap_add() or ildap_modify() @@ -394,7 +370,6 @@ static int ildb_del_trans(struct ldb_module *module) static const struct ldb_module_ops ildb_ops = { .name = "ldap", - .search = ildb_search, .search_bytree = ildb_search_bytree, .add_record = ildb_add, .modify_record = ildb_modify, @@ -415,7 +390,9 @@ static void ildb_rootdse(struct ldb_module *module) struct ldb_message **res = NULL; struct ldb_dn *empty_dn = ldb_dn_new(ildb); int ret; - ret = ildb_search(module, empty_dn, LDB_SCOPE_BASE, "dn=dc=rootDSE", NULL, &res); + ret = ildb_search_bytree(module, empty_dn, LDB_SCOPE_BASE, + ldb_parse_tree(empty_dn, "dn=dc=rootDSE"), + NULL, &res); if (ret == 1) { ildb->rootDSE = talloc_steal(ildb, res[0]); } -- cgit From 375fe21ad686e8f8eaec9dd075bc37fef464b13e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 31 Oct 2005 02:13:02 +0000 Subject: r11403: improved the error handling in the ildap ldb backend. Now passes through all ldap errors except on search. Search errors are only available via ldb_errstring() until we decide how to fix ldb_search(). (This used to be commit c192bcb79dda44b5b7a3bc257ba92addf769c8d9) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 90 +++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 37 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index ad316bb0a2..5fc326b425 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -32,16 +32,34 @@ #include "includes.h" #include "ldb/include/ldb.h" #include "ldb/include/ldb_private.h" +#include "ldb/include/ldb_errors.h" #include "libcli/ldap/ldap.h" #include "libcli/ldap/ldap_client.h" #include "lib/cmdline/popt_common.h" struct ildb_private { struct ldap_connection *ldap; - NTSTATUS last_rc; struct ldb_message *rootDSE; + struct ldb_context *ldb; }; + +/* + map an ildap NTSTATUS to a ldb error code +*/ +static int ildb_map_error(struct ildb_private *ildb, NTSTATUS status) +{ + if (NT_STATUS_IS_OK(status)) { + return LDB_SUCCESS; + } + talloc_free(ildb->ldb->err_string); + ildb->ldb->err_string = talloc_strdup(ildb, ldap_errstr(ildb->ldap, status)); + if (NT_STATUS_IS_LDAP(status)) { + return NT_STATUS_LDAP_CODE(status); + } + return LDB_ERR_OPERATIONS_ERROR; +} + /* rename a record */ @@ -52,19 +70,22 @@ static int ildb_rename(struct ldb_module *module, const struct ldb_dn *olddn, co int ret = 0; char *old_dn; char *newrdn, *parentdn; + NTSTATUS status; /* ignore ltdb specials */ if (ldb_dn_is_special(olddn) || ldb_dn_is_special(newdn)) { - return 0; + return LDB_SUCCESS; } local_ctx = talloc_named(ildb, 0, "ildb_rename local context"); if (local_ctx == NULL) { - return -1; + ret = LDB_ERR_OPERATIONS_ERROR; + goto failed; } old_dn = ldb_dn_linearize(local_ctx, olddn); if (old_dn == NULL) { + ret = LDB_ERR_INVALID_DN_SYNTAX; goto failed; } @@ -72,26 +93,22 @@ static int ildb_rename(struct ldb_module *module, const struct ldb_dn *olddn, co newdn->components[0].name, ldb_dn_escape_value(ildb, newdn->components[0].value)); if (newrdn == NULL) { + ret = LDB_ERR_OPERATIONS_ERROR; goto failed; } parentdn = ldb_dn_linearize(local_ctx, ldb_dn_get_parent(ildb, newdn)); if (parentdn == NULL) { + ret = LDB_ERR_INVALID_DN_SYNTAX; goto failed; } - ildb->last_rc = ildap_rename(ildb->ldap, old_dn, newrdn, parentdn, True); - if (!NT_STATUS_IS_OK(ildb->last_rc)) { - ldb_set_errstring(module, talloc_strdup(module, ldap_errstr(ildb->ldap, ildb->last_rc))); - ret = -1; - } - - talloc_free(local_ctx); - return ret; + status = ildap_rename(ildb->ldap, old_dn, newrdn, parentdn, True); + ret = ildb_map_error(ildb, status); failed: talloc_free(local_ctx); - return -1; + return ret; } /* @@ -102,20 +119,21 @@ static int ildb_delete(struct ldb_module *module, const struct ldb_dn *dn) struct ildb_private *ildb = module->private_data; char *del_dn; int ret = 0; + NTSTATUS status; /* ignore ltdb specials */ if (ldb_dn_is_special(dn)) { - return 0; + return LDB_SUCCESS; } del_dn = ldb_dn_linearize(ildb, dn); - - ildb->last_rc = ildap_delete(ildb->ldap, del_dn); - if (!NT_STATUS_IS_OK(ildb->last_rc)) { - ldb_set_errstring(module, talloc_strdup(module, ldap_errstr(ildb->ldap, ildb->last_rc))); - ret = -1; + if (del_dn == NULL) { + return LDB_ERR_INVALID_DN_SYNTAX; } + status = ildap_delete(ildb->ldap, del_dn); + ret = ildb_map_error(ildb, status); + talloc_free(del_dn); return ret; @@ -135,6 +153,7 @@ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba int count, i; struct ldap_message **ldapres, *msg; char *search_base; + NTSTATUS status; if (scope == LDB_SCOPE_DEFAULT) { scope = LDB_SCOPE_SUBTREE; @@ -163,11 +182,11 @@ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba return -1; } - ildb->last_rc = ildap_search_bytree(ildb->ldap, search_base, scope, tree, attrs, + status = ildap_search_bytree(ildb->ldap, search_base, scope, tree, attrs, 0, &ldapres); talloc_free(search_base); - if (!NT_STATUS_IS_OK(ildb->last_rc)) { - ldb_set_errstring(module, talloc_strdup(module, ldap_errstr(ildb->ldap, ildb->last_rc))); + if (!NT_STATUS_IS_OK(status)) { + ildb_map_error(ildb, status); return -1; } @@ -280,28 +299,26 @@ static int ildb_add(struct ldb_module *module, const struct ldb_message *msg) struct ldap_mod **mods; char *dn; int ret = 0; + NTSTATUS status; /* ignore ltdb specials */ if (ldb_dn_is_special(msg->dn)) { - return 0; + return LDB_SUCCESS; } mods = ildb_msg_to_mods(ldb, msg, 0); if (mods == NULL) { - return -1; + return LDB_ERR_OPERATIONS_ERROR; } dn = ldb_dn_linearize(mods, msg->dn); if (dn == NULL) { talloc_free(mods); - return -1; + return LDB_ERR_INVALID_DN_SYNTAX; } - ildb->last_rc = ildap_add(ildb->ldap, dn, mods); - if (!NT_STATUS_IS_OK(ildb->last_rc)) { - ldb_set_errstring(module, talloc_strdup(module, ldap_errstr(ildb->ldap, ildb->last_rc))); - ret = -1; - } + status = ildap_add(ildb->ldap, dn, mods); + ret = ildb_map_error(ildb, status); talloc_free(mods); @@ -319,28 +336,26 @@ static int ildb_modify(struct ldb_module *module, const struct ldb_message *msg) struct ldap_mod **mods; char *dn; int ret = 0; + NTSTATUS status; /* ignore ltdb specials */ if (ldb_dn_is_special(msg->dn)) { - return 0; + return LDB_SUCCESS; } mods = ildb_msg_to_mods(ldb, msg, 1); if (mods == NULL) { - return -1; + return LDB_ERR_OPERATIONS_ERROR; } dn = ldb_dn_linearize(mods, msg->dn); if (dn == NULL) { talloc_free(mods); - return -1; + return LDB_ERR_INVALID_DN_SYNTAX; } - ildb->last_rc = ildap_modify(ildb->ldap, dn, mods); - if (!NT_STATUS_IS_OK(ildb->last_rc)) { - ldb_set_errstring(module, talloc_strdup(module, ldap_errstr(ildb->ldap, ildb->last_rc))); - ret = -1; - } + status = ildap_modify(ildb->ldap, dn, mods); + ret = ildb_map_error(ildb, status); talloc_free(mods); @@ -418,6 +433,7 @@ int ildb_connect(struct ldb_context *ldb, const char *url, } ildb->rootDSE = NULL; + ildb->ldb = ldb; ildb->ldap = ldap_new_connection(ildb, ldb_get_opaque(ldb, "EventContext")); if (!ildb->ldap) { -- cgit From df9af348761989a8a1f257a29e9209aed4bfb373 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 5 Nov 2005 11:13:22 +0000 Subject: r11522: Add support for delegated credentials and machine account credentials to ldb, based on the sessionInfo we now pass around. Andrew Bartlett (This used to be commit 84e16e4ea7240409f15efd9f64344f9e0cec8111) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 5fc326b425..06ff79b9a0 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -36,6 +36,7 @@ #include "libcli/ldap/ldap.h" #include "libcli/ldap/ldap_client.h" #include "lib/cmdline/popt_common.h" +#include "auth/auth.h" struct ildb_private { struct ldap_connection *ldap; @@ -459,9 +460,14 @@ int ildb_connect(struct ldb_context *ldb, const char *url, ldb->modules->ops = &ildb_ops; /* caller can optionally setup credentials using the opaque token 'credentials' */ - creds = ldb_get_opaque(ldb, "credentials"); + creds = talloc_get_type(ldb_get_opaque(ldb, "credentials"), struct cli_credentials); if (creds == NULL) { - creds = cmdline_credentials; + struct auth_session_info *session_info = talloc_get_type(ldb_get_opaque(ldb, "sessionInfo"), struct auth_session_info); + if (session_info && session_info->credentials) { + creds = session_info->credentials; + } else { + creds = cmdline_credentials; + } } if (creds != NULL && cli_credentials_authentication_requested(creds)) { -- cgit From 5c9590587197dcb95007fdc54318187d5716c7c6 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 8 Nov 2005 00:11:45 +0000 Subject: r11567: Ldb API change patch. This patch changes the way lsb_search is called and the meaning of the returned integer. The last argument of ldb_search is changed from struct ldb_message to struct ldb_result which contains a pointer to a struct ldb_message list and a count of the number of messages. The return is not the count of messages anymore but instead it is an ldb error value. I tryed to keep the patch as tiny as possible bu as you can guess I had to change a good amount of places. I also tried to double check all my changes being sure that the calling functions would still behave as before. But this patch is big enough that I fear some bug may have been introduced anyway even if it passes the test suite. So if you are currently working on any file being touched please give it a deep look and blame me for any error. Simo. (This used to be commit 22c8c97e6fb466b41859e090e959d7f1134be780) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 99 +++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 29 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 06ff79b9a0..cc9b5e65db 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -148,7 +148,7 @@ static void ildb_rootdse(struct ldb_module *module); */ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const *attrs, struct ldb_message ***res) + const char * const *attrs, struct ldb_result **res) { struct ildb_private *ildb = module->private_data; int count, i; @@ -176,34 +176,46 @@ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba } if (search_base == NULL) { ldb_set_errstring(module, talloc_asprintf(module, "Unable to determine baseDN")); - return -1; + return LDB_ERR_OTHER; } if (tree == NULL) { ldb_set_errstring(module, talloc_asprintf(module, "Invalid expression parse tree")); - return -1; + return LDB_ERR_OTHER; } + (*res) = talloc(ildb, struct ldb_result); + if (! *res) { + return LDB_ERR_OTHER; + } + (*res)->count = 0; + (*res)->msgs = NULL; + status = ildap_search_bytree(ildb->ldap, search_base, scope, tree, attrs, 0, &ldapres); talloc_free(search_base); if (!NT_STATUS_IS_OK(status)) { ildb_map_error(ildb, status); - return -1; + return LDB_ERR_OTHER; } count = ildap_count_entries(ildb->ldap, ldapres); - if (count == -1 || count == 0) { + if (count == -1) { talloc_free(ldapres); - return count; + return LDB_ERR_OTHER; } - (*res) = talloc_array(ildb, struct ldb_message *, count+1); - if (! *res) { + if (count == 0) { talloc_free(ldapres); - return -1; + return LDB_SUCCESS; + } + + (*res)->msgs = talloc_array(*res, struct ldb_message *, count + 1); + if (! (*res)->msgs) { + talloc_free(ldapres); + return LDB_ERR_OTHER; } - (*res)[0] = NULL; + (*res)->msgs[0] = NULL; /* loop over all messages */ for (i=0;ir.SearchResultEntry; - (*res)[i] = talloc(*res, struct ldb_message); - if (!(*res)[i]) { + (*res)->msgs[i] = talloc(*res, struct ldb_message); + if (!(*res)->msgs[i]) { goto failed; } - (*res)[i+1] = NULL; + (*res)->msgs[i+1] = NULL; - (*res)[i]->dn = ldb_dn_explode((*res)[i], search->dn); - if ((*res)[i]->dn == NULL) { + (*res)->msgs[i]->dn = ldb_dn_explode((*res)->msgs[i], search->dn); + if ((*res)->msgs[i]->dn == NULL) { goto failed; } - (*res)[i]->num_elements = search->num_attributes; - (*res)[i]->elements = talloc_steal((*res)[i], search->attributes); - (*res)[i]->private_data = NULL; + (*res)->msgs[i]->num_elements = search->num_attributes; + (*res)->msgs[i]->elements = talloc_steal((*res)->msgs[i], search->attributes); + (*res)->msgs[i]->private_data = NULL; } talloc_free(ldapres); - return count; + (*res)->count = count; + return LDB_SUCCESS; failed: if (*res) talloc_free(*res); - return -1; + return LDB_ERR_OTHER; } @@ -384,13 +397,41 @@ static int ildb_del_trans(struct ldb_module *module) return 0; } +static int ildb_request(struct ldb_module *module, struct ldb_request *req) +{ + switch (req->operation) { + + case LDB_REQ_SEARCH: + return ildb_search_bytree(module, + req->op.search.base, + req->op.search.scope, + req->op.search.tree, + req->op.search.attrs, + req->op.search.res); + + case LDB_REQ_ADD: + return ildb_add(module, req->op.add.message); + + case LDB_REQ_MODIFY: + return ildb_modify(module, req->op.mod.message); + + case LDB_REQ_DELETE: + return ildb_delete(module, req->op.del.dn); + + case LDB_REQ_RENAME: + return ildb_rename(module, + req->op.rename.olddn, + req->op.rename.newdn); + + default: + return -1; + + } +} + static const struct ldb_module_ops ildb_ops = { .name = "ldap", - .search_bytree = ildb_search_bytree, - .add_record = ildb_add, - .modify_record = ildb_modify, - .delete_record = ildb_delete, - .rename_record = ildb_rename, + .request = ildb_request, .start_transaction = ildb_start_trans, .end_transaction = ildb_end_trans, .del_transaction = ildb_del_trans @@ -403,16 +444,16 @@ static const struct ldb_module_ops ildb_ops = { static void ildb_rootdse(struct ldb_module *module) { struct ildb_private *ildb = module->private_data; - struct ldb_message **res = NULL; + struct ldb_result *res = NULL; struct ldb_dn *empty_dn = ldb_dn_new(ildb); int ret; ret = ildb_search_bytree(module, empty_dn, LDB_SCOPE_BASE, ldb_parse_tree(empty_dn, "dn=dc=rootDSE"), NULL, &res); - if (ret == 1) { - ildb->rootDSE = talloc_steal(ildb, res[0]); + if (ret == LDB_SUCCESS && res->count == 1) { + ildb->rootDSE = talloc_steal(ildb, res->msgs[0]); } - if (ret != -1) talloc_free(res); + if (ret == LDB_SUCCESS) talloc_free(res); talloc_free(empty_dn); } -- cgit From 6eabad9c9d977c1c5c6ecf7494a0be42ad113d23 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 29 Nov 2005 12:34:03 +0000 Subject: r11958: - fixed memory leaks in the ldb_result handling in ldb operations - removed an unnecessary level of pointer in ldb_search structure (This used to be commit b8d4afb14a18dfd8bac79882a035e74d3ed312bd) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index cc9b5e65db..e195ec24aa 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -407,7 +407,7 @@ static int ildb_request(struct ldb_module *module, struct ldb_request *req) req->op.search.scope, req->op.search.tree, req->op.search.attrs, - req->op.search.res); + &req->op.search.res); case LDB_REQ_ADD: return ildb_add(module, req->op.add.message); -- cgit From a1827a1deba04e0b4b2a508dc4e4e66603a46d16 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 14 Dec 2005 07:22:25 +0000 Subject: r12227: I realised that I wasn't yet seeing authenticated LDAP for the ldb backend. The idea is that every time we open an LDB, we can provide a session_info and/or credentials. This would allow any ldb to be remote to LDAP. We should also support provisioning to a authenticated ldap server. (They are separate so we can say authenticate as foo for remote, but here we just want a token of SYSTEM). Andrew Bartlett (This used to be commit ae2f3a64ee0b07575624120db45299c65204210b) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index e195ec24aa..582513df6f 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -224,7 +224,7 @@ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba msg = ldapres[i]; search = &msg->r.SearchResultEntry; - (*res)->msgs[i] = talloc(*res, struct ldb_message); + (*res)->msgs[i] = talloc((*res)->msgs, struct ldb_message); if (!(*res)->msgs[i]) { goto failed; } @@ -504,10 +504,8 @@ int ildb_connect(struct ldb_context *ldb, const char *url, creds = talloc_get_type(ldb_get_opaque(ldb, "credentials"), struct cli_credentials); if (creds == NULL) { struct auth_session_info *session_info = talloc_get_type(ldb_get_opaque(ldb, "sessionInfo"), struct auth_session_info); - if (session_info && session_info->credentials) { + if (session_info) { creds = session_info->credentials; - } else { - creds = cmdline_credentials; } } -- cgit From 97b54b007e0f8a44074fa570b06b7ff9d4f2489b Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sun, 18 Dec 2005 05:01:15 +0000 Subject: r12310: Link simple bind support in our internal LDAP libs to LDB and the command line processing system. This is a little ugly at the moment, but works. What I cannot manage to get to work is the extraction and propogation of command line credentials into the js interface to ldb. Andrew Bartlett (This used to be commit f34ede763e7f80507d06224d114cf6b5ac7c8f7d) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 582513df6f..0802469079 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -510,11 +510,22 @@ int ildb_connect(struct ldb_context *ldb, const char *url, } if (creds != NULL && cli_credentials_authentication_requested(creds)) { - status = ldap_bind_sasl(ildb->ldap, creds); - if (!NT_STATUS_IS_OK(status)) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to bind - %s\n", - ldap_errstr(ildb->ldap, status)); - goto failed; + const char *bind_dn = cli_credentials_get_bind_dn(creds); + if (bind_dn) { + const char *password = cli_credentials_get_password(creds); + status = ldap_bind_simple(ildb->ldap, bind_dn, password); + if (!NT_STATUS_IS_OK(status)) { + ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to bind - %s\n", + ldap_errstr(ildb->ldap, status)); + goto failed; + } + } else { + status = ldap_bind_sasl(ildb->ldap, creds); + if (!NT_STATUS_IS_OK(status)) { + ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to bind - %s\n", + ldap_errstr(ildb->ldap, status)); + goto failed; + } } } -- cgit From c908d0b2aa111659e57a73efb8c33c413965c846 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 6 Jan 2006 04:01:23 +0000 Subject: r12733: Merge ldap/ldb controls into main tree There's still lot of work to do but the patch is stable enough to be pushed into the main samba4 tree. Simo. (This used to be commit 77125feaff252cab44d26593093a9c211c846ce8) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 0802469079..ff00a61163 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -148,11 +148,14 @@ static void ildb_rootdse(struct ldb_module *module); */ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const *attrs, struct ldb_result **res) + const char * const *attrs, + struct ldb_control **control_req, + struct ldb_result **res) { struct ildb_private *ildb = module->private_data; int count, i; struct ldap_message **ldapres, *msg; + struct ldap_Control **controls = NULL; char *search_base; NTSTATUS status; @@ -189,9 +192,12 @@ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba } (*res)->count = 0; (*res)->msgs = NULL; + (*res)->controls = NULL; - status = ildap_search_bytree(ildb->ldap, search_base, scope, tree, attrs, - 0, &ldapres); + status = ildap_search_bytree(ildb->ldap, search_base, scope, tree, attrs, 0, + (struct ldap_Control **)control_req, + &controls, + &ldapres); talloc_free(search_base); if (!NT_STATUS_IS_OK(status)) { ildb_map_error(ildb, status); @@ -230,7 +236,7 @@ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba } (*res)->msgs[i+1] = NULL; - (*res)->msgs[i]->dn = ldb_dn_explode((*res)->msgs[i], search->dn); + (*res)->msgs[i]->dn = ldb_dn_explode_or_special((*res)->msgs[i], search->dn); if ((*res)->msgs[i]->dn == NULL) { goto failed; } @@ -242,6 +248,11 @@ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba talloc_free(ldapres); (*res)->count = count; + + if (controls) { + (*res)->controls = (struct ldb_control **)talloc_steal(*res, controls); + } + return LDB_SUCCESS; failed: @@ -407,6 +418,7 @@ static int ildb_request(struct ldb_module *module, struct ldb_request *req) req->op.search.scope, req->op.search.tree, req->op.search.attrs, + req->controls, &req->op.search.res); case LDB_REQ_ADD: @@ -449,7 +461,7 @@ static void ildb_rootdse(struct ldb_module *module) int ret; ret = ildb_search_bytree(module, empty_dn, LDB_SCOPE_BASE, ldb_parse_tree(empty_dn, "dn=dc=rootDSE"), - NULL, &res); + NULL, NULL, &res); if (ret == LDB_SUCCESS && res->count == 1) { ildb->rootDSE = talloc_steal(ildb, res->msgs[0]); } -- cgit From dbef4d76de92c3388f4e1819a76d6febf90be290 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 6 Jan 2006 16:12:45 +0000 Subject: r12743: Remove the ugly way we had to make a second stage init and introduce a second_stage_init private function for modules that need a second stage init. Simo. (This used to be commit 5e8b365fa2d93801a5de1d9ea76ce9d5546bd248) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index ff00a61163..2837296b68 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -441,12 +441,18 @@ static int ildb_request(struct ldb_module *module, struct ldb_request *req) } } +static int ildb_init_2(struct ldb_module *module) +{ + return LDB_SUCCESS; +} + static const struct ldb_module_ops ildb_ops = { .name = "ldap", .request = ildb_request, .start_transaction = ildb_start_trans, .end_transaction = ildb_end_trans, - .del_transaction = ildb_del_trans + .del_transaction = ildb_del_trans, + .second_stage_init = ildb_init_2 }; -- cgit From 4d1c5a023cf6680474bd8d8be73f576d155cfe81 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 10 Jan 2006 16:48:32 +0000 Subject: r12829: fix ldb headers, to not include '<...>' files in .c files this helps in getting symbol -fvisibility=hidden (GCC 4 feature) working later. metze (This used to be commit 380938e97f31c7860aed1e73cc0110c6e17b472e) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 2837296b68..a6a5822c9e 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -30,9 +30,8 @@ #include "includes.h" -#include "ldb/include/ldb.h" -#include "ldb/include/ldb_private.h" -#include "ldb/include/ldb_errors.h" +#include "ldb/include/includes.h" + #include "libcli/ldap/ldap.h" #include "libcli/ldap/ldap_client.h" #include "lib/cmdline/popt_common.h" -- cgit From 00fe70e5b917769418f68eaa255d3a06a9a08ce7 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 22 Feb 2006 01:31:35 +0000 Subject: r13609: Get in the initial work on making ldb async Currently only ldb_ildap is async, the plan is to first make all backend support the async calls, and then remove the sync functions from backends and keep the only in the API. Modules will need to be transformed along the way. Simo (This used to be commit 1e2c13b2d52de7c534493dd79a2c0596a3e8c1f5) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 912 +++++++++++++++++++++++++--------- 1 file changed, 688 insertions(+), 224 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index a6a5822c9e..33d3954a73 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -2,6 +2,7 @@ ldb database library - ildap backend Copyright (C) Andrew Tridgell 2005 + Copyright (C) Simo Sorce 2006 ** NOTE! The following LGPL license applies to the ldb ** library. This does NOT imply that all of Samba is released @@ -32,6 +33,7 @@ #include "includes.h" #include "ldb/include/includes.h" +#include "lib/events/events.h" #include "libcli/ldap/ldap.h" #include "libcli/ldap/ldap_client.h" #include "lib/cmdline/popt_common.h" @@ -43,6 +45,66 @@ struct ildb_private { struct ldb_context *ldb; }; +struct ildb_async_context { + struct ldb_module *module; + struct ldap_request *req; + void *context; + int (*callback)(struct ldb_context *, void *, struct ldb_async_result *); +}; + +/* + convert a ldb_message structure to a list of ldap_mod structures + ready for ildap_add() or ildap_modify() +*/ +static struct ldap_mod **ildb_msg_to_mods(void *mem_ctx, int *num_mods, + const struct ldb_message *msg, int use_flags) +{ + struct ldap_mod **mods; + unsigned int i; + int n = 0; + + /* allocate maximum number of elements needed */ + mods = talloc_array(mem_ctx, struct ldap_mod *, msg->num_elements+1); + if (!mods) { + errno = ENOMEM; + return NULL; + } + mods[0] = NULL; + + for (i = 0; i < msg->num_elements; i++) { + const struct ldb_message_element *el = &msg->elements[i]; + + mods[n] = talloc(mods, struct ldap_mod); + if (!mods[n]) { + goto failed; + } + mods[n + 1] = NULL; + mods[n]->type = 0; + mods[n]->attrib = *el; + if (use_flags) { + switch (el->flags & LDB_FLAG_MOD_MASK) { + case LDB_FLAG_MOD_ADD: + mods[n]->type = LDAP_MODIFY_ADD; + break; + case LDB_FLAG_MOD_DELETE: + mods[n]->type = LDAP_MODIFY_DELETE; + break; + case LDB_FLAG_MOD_REPLACE: + mods[n]->type = LDAP_MODIFY_REPLACE; + break; + } + } + n++; + } + + *num_mods = n; + return mods; + +failed: + talloc_free(mods); + return NULL; +} + /* map an ildap NTSTATUS to a ldb error code @@ -60,330 +122,661 @@ static int ildb_map_error(struct ildb_private *ildb, NTSTATUS status) return LDB_ERR_OPERATIONS_ERROR; } -/* - rename a record -*/ -static int ildb_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn) +static void ildb_request_timeout(struct event_context *ev, struct timed_event *te, + struct timeval t, void *private_data) { - TALLOC_CTX *local_ctx; - struct ildb_private *ildb = module->private_data; - int ret = 0; - char *old_dn; - char *newrdn, *parentdn; - NTSTATUS status; + struct ldb_async_handle *handle = talloc_get_type(private_data, struct ldb_async_handle); + struct ildb_async_context *ac = talloc_get_type(handle->private_data, struct ildb_async_context); - /* ignore ltdb specials */ - if (ldb_dn_is_special(olddn) || ldb_dn_is_special(newdn)) { - return LDB_SUCCESS; + if (ac->req->state == LDAP_REQUEST_PENDING) { + DLIST_REMOVE(ac->req->conn->pending, ac->req); } - local_ctx = talloc_named(ildb, 0, "ildb_rename local context"); - if (local_ctx == NULL) { - ret = LDB_ERR_OPERATIONS_ERROR; - goto failed; - } + handle->status = LDB_ERR_OPERATIONS_ERROR; - old_dn = ldb_dn_linearize(local_ctx, olddn); - if (old_dn == NULL) { - ret = LDB_ERR_INVALID_DN_SYNTAX; - goto failed; - } + return; +} - newrdn = talloc_asprintf(local_ctx, "%s=%s", - newdn->components[0].name, - ldb_dn_escape_value(ildb, newdn->components[0].value)); - if (newrdn == NULL) { - ret = LDB_ERR_OPERATIONS_ERROR; - goto failed; - } +static void ildb_async_callback(struct ldap_request *req) +{ + struct ldb_async_handle *handle = talloc_get_type(req->async.private_data, struct ldb_async_handle); + struct ildb_async_context *ac = talloc_get_type(handle->private_data, struct ildb_async_context); + struct ildb_private *ildb = ac->module->private_data; + NTSTATUS status; + int i; - parentdn = ldb_dn_linearize(local_ctx, ldb_dn_get_parent(ildb, newdn)); - if (parentdn == NULL) { - ret = LDB_ERR_INVALID_DN_SYNTAX; - goto failed; + handle->status = LDB_SUCCESS; + + if (!NT_STATUS_IS_OK(req->status)) { + handle->status = ildb_map_error(ildb, req->status); + return; } - status = ildap_rename(ildb->ldap, old_dn, newrdn, parentdn, True); - ret = ildb_map_error(ildb, status); + if (req->num_replies < 1) { + handle->status = LDB_ERR_OPERATIONS_ERROR; + return; + } + + switch (req->type) { -failed: - talloc_free(local_ctx); - return ret; + case LDAP_TAG_ModifyRequest: + if (req->replies[0]->type != LDAP_TAG_ModifyResponse) { + handle->status = LDB_ERR_PROTOCOL_ERROR; + return; + } + status = ldap_check_response(req->conn, &req->replies[0]->r.GeneralResult); + handle->status = ildb_map_error(ildb, status); + handle->state = LDB_ASYNC_DONE; + break; + + case LDAP_TAG_AddRequest: + if (req->replies[0]->type != LDAP_TAG_AddResponse) { + handle->status = LDB_ERR_PROTOCOL_ERROR; + return; + } + status = ldap_check_response(req->conn, &req->replies[0]->r.GeneralResult); + handle->status = ildb_map_error(ildb, status); + handle->state = LDB_ASYNC_DONE; + break; + + case LDAP_TAG_DelRequest: + if (req->replies[0]->type != LDAP_TAG_DelResponse) { + handle->status = LDB_ERR_PROTOCOL_ERROR; + return; + } + status = ldap_check_response(req->conn, &req->replies[0]->r.GeneralResult); + handle->status = ildb_map_error(ildb, status); + handle->state = LDB_ASYNC_DONE; + break; + + case LDAP_TAG_ModifyDNRequest: + if (req->replies[0]->type != LDAP_TAG_ModifyDNResponse) { + handle->status = LDB_ERR_PROTOCOL_ERROR; + return; + } + status = ldap_check_response(req->conn, &req->replies[0]->r.GeneralResult); + handle->status = ildb_map_error(ildb, status); + handle->state = LDB_ASYNC_DONE; + break; + + case LDAP_TAG_SearchRequest: + /* loop over all messages */ + for (i = 0; i < req->num_replies; i++) { + struct ldap_SearchResEntry *search; + struct ldb_async_result *ares = NULL; + struct ldap_message *msg; + int ret; + + ares = talloc_zero(ac, struct ldb_async_result); + if (!ares) { + handle->status = LDB_ERR_OPERATIONS_ERROR; + return; + } + + msg = req->replies[i]; + switch (msg->type) { + + case LDAP_TAG_SearchResultDone: + + status = ldap_check_response(req->conn, &msg->r.GeneralResult); + if (!NT_STATUS_IS_OK(status)) { + ldb_debug(ac->module->ldb, LDB_DEBUG_ERROR, "Error: %s\n" ,ldap_errstr(req->conn, status)); + handle->status = ildb_map_error(ildb, status); + return; + } + + if (msg->controls) { + ares->controls = talloc_steal(ares, msg->controls); + } + if (msg->r.SearchResultDone.resultcode) { + if (msg->r.SearchResultDone.errormessage) { + ldb_set_errstring(ac->module, talloc_strdup(ac->module, msg->r.SearchResultDone.errormessage)); + } + } + + handle->status = msg->r.SearchResultDone.resultcode; + handle->state = LDB_ASYNC_DONE; + ares->type = LDB_REPLY_DONE; + break; + + case LDAP_TAG_SearchResultEntry: + + + ares->message = ldb_msg_new(ares); + if (!ares->message) { + handle->status = LDB_ERR_OPERATIONS_ERROR;; + return; + } + + search = &(msg->r.SearchResultEntry); + + ares->message->dn = ldb_dn_explode_or_special(ares->message, search->dn); + if (ares->message->dn == NULL) { + handle->status = LDB_ERR_OPERATIONS_ERROR; + return; + } + ares->message->num_elements = search->num_attributes; + ares->message->elements = talloc_steal(ares->message, search->attributes); + + handle->status = LDB_SUCCESS; + handle->state = LDB_ASYNC_PENDING; + ares->type = LDB_REPLY_ENTRY; + break; + + case LDAP_TAG_SearchResultReference: + + ares->referral = talloc_strdup(ares, msg->r.SearchResultReference.referral); + + handle->status = LDB_SUCCESS; + handle->state = LDB_ASYNC_PENDING; + ares->type = LDB_REPLY_REFERRAL; + break; + + default: + /* TAG not handled, fail ! */ + handle->status = LDB_ERR_PROTOCOL_ERROR; + return; + } + + ret = ac->callback(ac->module->ldb, ac->context, ares); + if (ret) { + handle->status = ret; + } + } + + talloc_free(req->replies); + req->replies = NULL; + req->num_replies = 0; + + break; + + default: + handle->status = LDB_ERR_PROTOCOL_ERROR; + return; + } } -/* - delete a record -*/ -static int ildb_delete(struct ldb_module *module, const struct ldb_dn *dn) +static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg, + void *context, + int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), + int timeout, + struct ldb_async_handle **handle) { struct ildb_private *ildb = module->private_data; - char *del_dn; - int ret = 0; - NTSTATUS status; + struct ildb_async_context *ildb_ac; + struct ldb_async_handle *h; + struct ldap_request *req; - /* ignore ltdb specials */ - if (ldb_dn_is_special(dn)) { - return LDB_SUCCESS; + h = talloc_zero(ildb->ldap, struct ldb_async_handle); + if (h == NULL) { + ldb_set_errstring(module, talloc_asprintf(module, "Out of Memory")); + return LDB_ERR_OPERATIONS_ERROR; } - - del_dn = ldb_dn_linearize(ildb, dn); - if (del_dn == NULL) { - return LDB_ERR_INVALID_DN_SYNTAX; + + ildb_ac = talloc(h, struct ildb_async_context); + if (ildb_ac == NULL) { + ldb_set_errstring(module, talloc_asprintf(module, "Out of Memory")); + talloc_free(h); + return LDB_ERR_OPERATIONS_ERROR; } - status = ildap_delete(ildb->ldap, del_dn); - ret = ildb_map_error(ildb, status); + h->private_data = (void *)ildb_ac; - talloc_free(del_dn); + req = ldap_request_send(ildb->ldap, msg); + if (req == NULL) { + ldb_set_errstring(module, talloc_asprintf(module, "async send request failed")); + return LDB_ERR_OPERATIONS_ERROR; + } - return ret; -} + ildb_ac->req = talloc_steal(ildb_ac, req); + ildb_ac->module = module; + ildb_ac->context = context; + ildb_ac->callback = callback; + req->async.fn = ildb_async_callback; + req->async.private_data = (void *)h; -static void ildb_rootdse(struct ldb_module *module); + talloc_free(req->time_event); + req->time_event = NULL; + if (timeout) { + req->time_event = event_add_timed(req->conn->event.event_ctx, h, + timeval_current_ofs(timeout, 0), + ildb_request_timeout, ildb_ac); + } + + *handle = h; + + return LDB_SUCCESS; + +} /* - search for matching records using a ldb_parse_tree -*/ -static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, + search for matching records using an asynchronous function + */ +static int ildb_search_async(struct ldb_module *module, const struct ldb_dn *base, enum ldb_scope scope, struct ldb_parse_tree *tree, const char * const *attrs, struct ldb_control **control_req, - struct ldb_result **res) + void *context, + int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), + int timeout, + struct ldb_async_handle **handle) { struct ildb_private *ildb = module->private_data; - int count, i; - struct ldap_message **ldapres, *msg; - struct ldap_Control **controls = NULL; - char *search_base; - NTSTATUS status; + struct ldap_message *msg; + int n; - if (scope == LDB_SCOPE_DEFAULT) { - scope = LDB_SCOPE_SUBTREE; + *handle = NULL; + + if (!callback || !context) { + ldb_set_errstring(module, talloc_asprintf(module, "Async interface called with NULL callback function or NULL context")); + return LDB_ERR_OPERATIONS_ERROR; } + if (tree == NULL) { + ldb_set_errstring(module, talloc_asprintf(module, "Invalid expression parse tree")); + return LDB_ERR_OPERATIONS_ERROR; + } + + msg = new_ldap_message(ildb); + if (msg == NULL) { + ldb_set_errstring(module, talloc_asprintf(module, "Out of Memory")); + return LDB_ERR_OPERATIONS_ERROR; + } + + msg->type = LDAP_TAG_SearchRequest; + if (base == NULL) { - if (ildb->rootDSE == NULL) { - ildb_rootdse(module); - } if (ildb->rootDSE != NULL) { - search_base = talloc_strdup(ildb, - ldb_msg_find_string(ildb->rootDSE, - "defaultNamingContext", "")); + msg->r.SearchRequest.basedn = + talloc_strdup(msg, ldb_msg_find_string(ildb->rootDSE, "defaultNamingContext", "")); } else { - search_base = talloc_strdup(ildb, ""); + msg->r.SearchRequest.basedn = talloc_strdup(msg, ""); } } else { - search_base = ldb_dn_linearize(ildb, base); + msg->r.SearchRequest.basedn = ldb_dn_linearize(msg, base); } - if (search_base == NULL) { + if (msg->r.SearchRequest.basedn == NULL) { ldb_set_errstring(module, talloc_asprintf(module, "Unable to determine baseDN")); - return LDB_ERR_OTHER; + talloc_free(msg); + return LDB_ERR_OPERATIONS_ERROR; } - if (tree == NULL) { - ldb_set_errstring(module, talloc_asprintf(module, "Invalid expression parse tree")); - return LDB_ERR_OTHER; + + if (scope == LDB_SCOPE_DEFAULT) { + msg->r.SearchRequest.scope = LDB_SCOPE_SUBTREE; + } else { + msg->r.SearchRequest.scope = scope; } + + msg->r.SearchRequest.deref = LDAP_DEREFERENCE_NEVER; + msg->r.SearchRequest.timelimit = 0; + msg->r.SearchRequest.sizelimit = 0; + msg->r.SearchRequest.attributesonly = 0; + msg->r.SearchRequest.tree = tree; + + for (n = 0; attrs && attrs[n]; n++) /* noop */ ; + msg->r.SearchRequest.num_attributes = n; + msg->r.SearchRequest.attributes = discard_const(attrs); + msg->controls = control_req; - (*res) = talloc(ildb, struct ldb_result); - if (! *res) { - return LDB_ERR_OTHER; + return ildb_request_send(module, msg, context, callback, timeout, handle); +} + +struct ildb_sync_context { + struct ldb_result *res; + int status; + int done; +}; + +static int ildb_search_sync_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) +{ + struct ldb_result *res; + int n; + + if (!context) { + ldb_set_errstring(ldb->modules, talloc_asprintf(ldb, "NULL Context in callback")); + return LDB_ERR_OPERATIONS_ERROR; + } + + res = *((struct ldb_result **)context); + + if (!res || !ares) { + goto error; } - (*res)->count = 0; - (*res)->msgs = NULL; - (*res)->controls = NULL; - status = ildap_search_bytree(ildb->ldap, search_base, scope, tree, attrs, 0, - (struct ldap_Control **)control_req, - &controls, - &ldapres); - talloc_free(search_base); - if (!NT_STATUS_IS_OK(status)) { - ildb_map_error(ildb, status); - return LDB_ERR_OTHER; + if (ares->type == LDB_REPLY_ENTRY) { + res->msgs = talloc_realloc(res, res->msgs, struct ldb_message *, res->count + 2); + if (! res->msgs) { + goto error; + } + + res->msgs[res->count + 1] = NULL; + + res->msgs[res->count] = talloc_steal(res->msgs, ares->message); + if (! res->msgs[res->count]) { + goto error; + } + + res->count++; } - count = ildap_count_entries(ildb->ldap, ldapres); - if (count == -1) { - talloc_free(ldapres); - return LDB_ERR_OTHER; + if (ares->type == LDB_REPLY_REFERRAL) { + if (res->refs) { + for (n = 0; res->refs[n]; n++) /*noop*/ ; + } else { + n = 0; + } + + res->refs = talloc_realloc(res, res->refs, char *, n + 2); + if (! res->refs) { + goto error; + } + + res->refs[n] = talloc_steal(res->refs, ares->referral); + res->refs[n + 1] = NULL; } - if (count == 0) { - talloc_free(ldapres); - return LDB_SUCCESS; + if (ares->type == LDB_REPLY_DONE) { + if (ares->controls) { + res->controls = talloc_steal(res, ares->controls); + if (! res->controls) { + goto error; + } + } } - (*res)->msgs = talloc_array(*res, struct ldb_message *, count + 1); - if (! (*res)->msgs) { - talloc_free(ldapres); - return LDB_ERR_OTHER; + talloc_free(ares); + return LDB_SUCCESS; + +error: + talloc_free(ares); + talloc_free(res); + *((struct ldb_result **)context) = NULL; + return LDB_ERR_OPERATIONS_ERROR; +} + +/* + search for matching records using a synchronous function + */ +static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, + enum ldb_scope scope, struct ldb_parse_tree *tree, + const char * const *attrs, + struct ldb_control **control_req, + struct ldb_result **res) +{ + struct ildb_private *ildb = module->private_data; + struct ldb_async_handle *handle; + int ret; + + *res = talloc_zero(ildb, struct ldb_result); + if (! *res) { + return LDB_ERR_OPERATIONS_ERROR; } - (*res)->msgs[0] = NULL; + ret = ildb_search_async(module, base, scope, tree, attrs, control_req, + res, &ildb_search_sync_callback, ildb->ldap->timeout, &handle); - /* loop over all messages */ - for (i=0;ir.SearchResultEntry; + return ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); +} - (*res)->msgs[i] = talloc((*res)->msgs, struct ldb_message); - if (!(*res)->msgs[i]) { - goto failed; - } - (*res)->msgs[i+1] = NULL; +/* + add a record +*/ +static int ildb_add_async(struct ldb_module *module, const struct ldb_message *ldb_msg, + void *context, + int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), + int timeout, + struct ldb_async_handle **handle) +{ + struct ildb_private *ildb = module->private_data; + struct ldap_message *msg; + struct ldap_mod **mods; + int i,n; - (*res)->msgs[i]->dn = ldb_dn_explode_or_special((*res)->msgs[i], search->dn); - if ((*res)->msgs[i]->dn == NULL) { - goto failed; - } - (*res)->msgs[i]->num_elements = search->num_attributes; - (*res)->msgs[i]->elements = talloc_steal((*res)->msgs[i], search->attributes); - (*res)->msgs[i]->private_data = NULL; + *handle = NULL; + + /* ignore ltdb specials */ + if (ldb_dn_is_special(ldb_msg->dn)) { + return LDB_SUCCESS; } - talloc_free(ldapres); + msg = new_ldap_message(ildb->ldap); + if (msg == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } - (*res)->count = count; + msg->type = LDAP_TAG_AddRequest; - if (controls) { - (*res)->controls = (struct ldb_control **)talloc_steal(*res, controls); + msg->r.AddRequest.dn = ldb_dn_linearize(msg, ldb_msg->dn); + if (msg->r.AddRequest.dn == NULL) { + talloc_free(msg); + return LDB_ERR_INVALID_DN_SYNTAX; } - return LDB_SUCCESS; + mods = ildb_msg_to_mods(msg, &n, ldb_msg, 0); + if (mods == NULL) { + talloc_free(msg); + return LDB_ERR_OPERATIONS_ERROR; + } -failed: - if (*res) talloc_free(*res); - return LDB_ERR_OTHER; + msg->r.AddRequest.num_attributes = n; + msg->r.AddRequest.attributes = talloc_array(msg, struct ldb_message_element, n); + if (msg->r.AddRequest.attributes == NULL) { + talloc_free(msg); + return LDB_ERR_OPERATIONS_ERROR; + } + + for (i = 0; i < n; i++) { + msg->r.AddRequest.attributes[i] = mods[i]->attrib; + } + + return ildb_request_send(module, msg, context, callback, timeout, handle); } +static int ildb_add(struct ldb_module *module, const struct ldb_message *msg) +{ + struct ildb_private *ildb = module->private_data; + struct ldb_async_handle *handle; + int ret; + + ret = ildb_add_async(module, msg, + NULL, NULL, ildb->ldap->timeout, &handle); + + if (ret != LDB_SUCCESS) + return ret; + + return ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); +} /* - convert a ldb_message structure to a list of ldap_mod structures - ready for ildap_add() or ildap_modify() + modify a record */ -static struct ldap_mod **ildb_msg_to_mods(struct ldb_context *ldb, - const struct ldb_message *msg, int use_flags) +static int ildb_modify_async(struct ldb_module *module, const struct ldb_message *ldb_msg, + void *context, + int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), + int timeout, + struct ldb_async_handle **handle) { + struct ildb_private *ildb = module->private_data; + struct ldap_message *msg; struct ldap_mod **mods; - unsigned int i; - int num_mods = 0; + int i,n; - /* allocate maximum number of elements needed */ - mods = talloc_array(ldb, struct ldap_mod *, msg->num_elements+1); - if (!mods) { - errno = ENOMEM; - return NULL; + *handle = NULL; + + /* ignore ltdb specials */ + if (ldb_dn_is_special(ldb_msg->dn)) { + return LDB_SUCCESS; } - mods[0] = NULL; - for (i=0;inum_elements;i++) { - const struct ldb_message_element *el = &msg->elements[i]; + msg = new_ldap_message(ildb->ldap); + if (msg == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } - mods[num_mods] = talloc(ldb, struct ldap_mod); - if (!mods[num_mods]) { - goto failed; - } - mods[num_mods+1] = NULL; - mods[num_mods]->type = 0; - mods[num_mods]->attrib = *el; - if (use_flags) { - switch (el->flags & LDB_FLAG_MOD_MASK) { - case LDB_FLAG_MOD_ADD: - mods[num_mods]->type = LDAP_MODIFY_ADD; - break; - case LDB_FLAG_MOD_DELETE: - mods[num_mods]->type = LDAP_MODIFY_DELETE; - break; - case LDB_FLAG_MOD_REPLACE: - mods[num_mods]->type = LDAP_MODIFY_REPLACE; - break; - } - } - num_mods++; + msg->type = LDAP_TAG_ModifyRequest; + + msg->r.ModifyRequest.dn = ldb_dn_linearize(msg, ldb_msg->dn); + if (msg->r.ModifyRequest.dn == NULL) { + talloc_free(msg); + return LDB_ERR_INVALID_DN_SYNTAX; } - return mods; + mods = ildb_msg_to_mods(msg, &n, ldb_msg, 1); + if (mods == NULL) { + talloc_free(msg); + return LDB_ERR_OPERATIONS_ERROR; + } -failed: - talloc_free(mods); - return NULL; + msg->r.ModifyRequest.num_mods = n; + msg->r.ModifyRequest.mods = talloc_array(msg, struct ldap_mod, n); + if (msg->r.ModifyRequest.mods == NULL) { + talloc_free(msg); + return LDB_ERR_OPERATIONS_ERROR; + } + + for (i = 0; i < n; i++) { + msg->r.ModifyRequest.mods[i] = *mods[i]; + } + + return ildb_request_send(module, msg, context, callback, timeout, handle); } +static int ildb_modify(struct ldb_module *module, const struct ldb_message *msg) +{ + struct ildb_private *ildb = module->private_data; + struct ldb_async_handle *handle; + int ret; + + ret = ildb_modify_async(module, msg, + NULL, NULL, ildb->ldap->timeout, &handle); + + if (ret != LDB_SUCCESS) + return ret; + + return ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); +} /* - add a record + delete a record */ -static int ildb_add(struct ldb_module *module, const struct ldb_message *msg) +static int ildb_delete_async(struct ldb_module *module, const struct ldb_dn *dn, + void *context, + int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), + int timeout, + struct ldb_async_handle **handle) { - struct ldb_context *ldb = module->ldb; struct ildb_private *ildb = module->private_data; - struct ldap_mod **mods; - char *dn; - int ret = 0; - NTSTATUS status; + struct ldap_message *msg; + + *handle = NULL; /* ignore ltdb specials */ - if (ldb_dn_is_special(msg->dn)) { + if (ldb_dn_is_special(dn)) { return LDB_SUCCESS; } - mods = ildb_msg_to_mods(ldb, msg, 0); - if (mods == NULL) { + msg = new_ldap_message(ildb->ldap); + if (msg == NULL) { return LDB_ERR_OPERATIONS_ERROR; } - dn = ldb_dn_linearize(mods, msg->dn); - if (dn == NULL) { - talloc_free(mods); + msg->type = LDAP_TAG_DelRequest; + + msg->r.DelRequest.dn = ldb_dn_linearize(msg, dn); + if (msg->r.DelRequest.dn == NULL) { + talloc_free(msg); return LDB_ERR_INVALID_DN_SYNTAX; } - status = ildap_add(ildb->ldap, dn, mods); - ret = ildb_map_error(ildb, status); + return ildb_request_send(module, msg, context, callback, timeout, handle); +} - talloc_free(mods); +static int ildb_delete(struct ldb_module *module, const struct ldb_dn *dn) +{ + struct ildb_private *ildb = module->private_data; + struct ldb_async_handle *handle; + int ret; - return ret; -} + ret = ildb_delete_async(module, dn, + NULL, NULL, ildb->ldap->timeout, &handle); + if (ret != LDB_SUCCESS) + return ret; + + return ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); +} /* - modify a record + rename a record */ -static int ildb_modify(struct ldb_module *module, const struct ldb_message *msg) +static int ildb_rename_async(struct ldb_module *module, + const struct ldb_dn *olddn, const struct ldb_dn *newdn, + void *context, + int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), + int timeout, + struct ldb_async_handle **handle) { - struct ldb_context *ldb = module->ldb; struct ildb_private *ildb = module->private_data; - struct ldap_mod **mods; - char *dn; - int ret = 0; - NTSTATUS status; + struct ldap_message *msg; + + *handle = NULL; /* ignore ltdb specials */ - if (ldb_dn_is_special(msg->dn)) { + if (ldb_dn_is_special(olddn) || ldb_dn_is_special(newdn)) { return LDB_SUCCESS; } - mods = ildb_msg_to_mods(ldb, msg, 1); - if (mods == NULL) { + msg = new_ldap_message(ildb->ldap); + if (msg == NULL) { return LDB_ERR_OPERATIONS_ERROR; } - dn = ldb_dn_linearize(mods, msg->dn); - if (dn == NULL) { - talloc_free(mods); + msg->type = LDAP_TAG_ModifyDNRequest; + msg->r.ModifyDNRequest.dn = ldb_dn_linearize(msg, olddn); + if (msg->r.ModifyDNRequest.dn == NULL) { + talloc_free(msg); return LDB_ERR_INVALID_DN_SYNTAX; } - status = ildap_modify(ildb->ldap, dn, mods); - ret = ildb_map_error(ildb, status); + msg->r.ModifyDNRequest.newrdn = + talloc_asprintf(msg, "%s=%s", + newdn->components[0].name, + ldb_dn_escape_value(msg, newdn->components[0].value)); + if (msg->r.ModifyDNRequest.newrdn == NULL) { + talloc_free(msg); + return LDB_ERR_OPERATIONS_ERROR; + } - talloc_free(mods); + msg->r.ModifyDNRequest.newsuperior = + ldb_dn_linearize(msg, + ldb_dn_get_parent(msg, newdn)); + if (msg->r.ModifyDNRequest.newsuperior == NULL) { + talloc_free(msg); + return LDB_ERR_INVALID_DN_SYNTAX; + } + + msg->r.ModifyDNRequest.deleteolddn = True; + + return ildb_request_send(module, msg, context, callback, timeout, handle); +} + +static int ildb_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn) +{ + struct ildb_private *ildb = module->private_data; + struct ldb_async_handle *handle; + int ret; + + ret = ildb_rename_async(module, olddn, newdn, + NULL, NULL, ildb->ldap->timeout, &handle); - return ret; + if (ret != LDB_SUCCESS) + return ret; + + return ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); } static int ildb_start_trans(struct ldb_module *module) @@ -434,14 +827,75 @@ static int ildb_request(struct ldb_module *module, struct ldb_request *req) req->op.rename.olddn, req->op.rename.newdn); + case LDB_ASYNC_SEARCH: + return ildb_search_async(module, + req->op.search.base, + req->op.search.scope, + req->op.search.tree, + req->op.search.attrs, + req->controls, + req->async.context, + req->async.callback, + req->async.timeout, + &req->async.handle); + + case LDB_ASYNC_ADD: + return ildb_add_async(module, + req->op.add.message, + req->async.context, + req->async.callback, + req->async.timeout, + &req->async.handle); + + case LDB_ASYNC_MODIFY: + return ildb_modify_async(module, + req->op.mod.message, + req->async.context, + req->async.callback, + req->async.timeout, + &req->async.handle); + + case LDB_ASYNC_DELETE: + return ildb_delete_async(module, + req->op.del.dn, + req->async.context, + req->async.callback, + req->async.timeout, + &req->async.handle); + + case LDB_ASYNC_RENAME: + return ildb_rename_async(module, + req->op.rename.olddn, + req->op.rename.newdn, + req->async.context, + req->async.callback, + req->async.timeout, + &req->async.handle); + default: return -1; } } +/* + fetch the rootDSE for later use +*/ static int ildb_init_2(struct ldb_module *module) { + struct ildb_private *ildb = module->private_data; + struct ldb_result *res = NULL; + struct ldb_dn *empty_dn = ldb_dn_new(ildb); + int ret; + ret = ildb_search_bytree(module, empty_dn, LDB_SCOPE_BASE, + ldb_parse_tree(empty_dn, "dn=dc=rootDSE"), + NULL, NULL, &res); + if (ret == LDB_SUCCESS && res->count == 1) { + ildb->rootDSE = talloc_steal(ildb, res->msgs[0]); + } + if (ret == LDB_SUCCESS) talloc_free(res); + talloc_free(empty_dn); + return LDB_SUCCESS; } @@ -455,25 +909,33 @@ static const struct ldb_module_ops ildb_ops = { }; -/* - fetch the rootDSE -*/ -static void ildb_rootdse(struct ldb_module *module) +static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type) { - struct ildb_private *ildb = module->private_data; - struct ldb_result *res = NULL; - struct ldb_dn *empty_dn = ldb_dn_new(ildb); - int ret; - ret = ildb_search_bytree(module, empty_dn, LDB_SCOPE_BASE, - ldb_parse_tree(empty_dn, "dn=dc=rootDSE"), - NULL, NULL, &res); - if (ret == LDB_SUCCESS && res->count == 1) { - ildb->rootDSE = talloc_steal(ildb, res->msgs[0]); + struct ildb_async_context *ac = talloc_get_type(handle->private_data, struct ildb_async_context); + + if (!ac) { + return LDB_ERR_OPERATIONS_ERROR; } - if (ret == LDB_SUCCESS) talloc_free(res); - talloc_free(empty_dn); -} + switch(type) { + case LDB_WAIT_NONE: + if (event_loop_once(ac->req->conn->event.event_ctx) != 0) { + return LDB_ERR_OTHER; + } + break; + case LDB_WAIT_ALL: + while (handle->status == LDB_SUCCESS && handle->state != LDB_ASYNC_DONE) { + if (event_loop_once(ac->req->conn->event.event_ctx) != 0) { + return LDB_ERR_OTHER; + } + } + break; + default: + return LDB_ERR_OPERATIONS_ERROR; + } + + return handle->status; +} /* connect to the database @@ -546,6 +1008,8 @@ int ildb_connect(struct ldb_context *ldb, const char *url, } } + ldb->async_wait = &ildb_async_wait; + return 0; failed: -- cgit From d590dea10b3abf93fcc8138189291e8b66bae7d7 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 22 Feb 2006 05:21:43 +0000 Subject: r13615: Make ldb_set_errstring get ldb instead of module as parameter. The module was just used to get to the ldb so it was meningless. Also add LDB_WAIT_ONCE e relative code in ldb_ildap.c (This used to be commit d5b467b7c132b0bd4d23918ba7bf3370b1afcce8) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 33d3954a73..de32c10ba4 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -230,7 +230,7 @@ static void ildb_async_callback(struct ldap_request *req) } if (msg->r.SearchResultDone.resultcode) { if (msg->r.SearchResultDone.errormessage) { - ldb_set_errstring(ac->module, talloc_strdup(ac->module, msg->r.SearchResultDone.errormessage)); + ldb_set_errstring(ac->module->ldb, talloc_strdup(ac->module, msg->r.SearchResultDone.errormessage)); } } @@ -309,13 +309,13 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg h = talloc_zero(ildb->ldap, struct ldb_async_handle); if (h == NULL) { - ldb_set_errstring(module, talloc_asprintf(module, "Out of Memory")); + ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); return LDB_ERR_OPERATIONS_ERROR; } ildb_ac = talloc(h, struct ildb_async_context); if (ildb_ac == NULL) { - ldb_set_errstring(module, talloc_asprintf(module, "Out of Memory")); + ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); talloc_free(h); return LDB_ERR_OPERATIONS_ERROR; } @@ -324,7 +324,7 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg req = ldap_request_send(ildb->ldap, msg); if (req == NULL) { - ldb_set_errstring(module, talloc_asprintf(module, "async send request failed")); + ldb_set_errstring(module->ldb, talloc_asprintf(module, "async send request failed")); return LDB_ERR_OPERATIONS_ERROR; } @@ -369,18 +369,18 @@ static int ildb_search_async(struct ldb_module *module, const struct ldb_dn *bas *handle = NULL; if (!callback || !context) { - ldb_set_errstring(module, talloc_asprintf(module, "Async interface called with NULL callback function or NULL context")); + ldb_set_errstring(module->ldb, talloc_asprintf(module, "Async interface called with NULL callback function or NULL context")); return LDB_ERR_OPERATIONS_ERROR; } if (tree == NULL) { - ldb_set_errstring(module, talloc_asprintf(module, "Invalid expression parse tree")); + ldb_set_errstring(module->ldb, talloc_asprintf(module, "Invalid expression parse tree")); return LDB_ERR_OPERATIONS_ERROR; } msg = new_ldap_message(ildb); if (msg == NULL) { - ldb_set_errstring(module, talloc_asprintf(module, "Out of Memory")); + ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); return LDB_ERR_OPERATIONS_ERROR; } @@ -397,7 +397,7 @@ static int ildb_search_async(struct ldb_module *module, const struct ldb_dn *bas msg->r.SearchRequest.basedn = ldb_dn_linearize(msg, base); } if (msg->r.SearchRequest.basedn == NULL) { - ldb_set_errstring(module, talloc_asprintf(module, "Unable to determine baseDN")); + ldb_set_errstring(module->ldb, talloc_asprintf(module, "Unable to determine baseDN")); talloc_free(msg); return LDB_ERR_OPERATIONS_ERROR; } @@ -434,7 +434,7 @@ static int ildb_search_sync_callback(struct ldb_context *ldb, void *context, str int n; if (!context) { - ldb_set_errstring(ldb->modules, talloc_asprintf(ldb, "NULL Context in callback")); + ldb_set_errstring(ldb, talloc_asprintf(ldb, "NULL Context in callback")); return LDB_ERR_OPERATIONS_ERROR; } @@ -923,6 +923,14 @@ static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_ return LDB_ERR_OTHER; } break; + case LDB_WAIT_ONCE: + handle->state = LDB_ASYNC_INIT; + while (handle->status == LDB_SUCCESS && handle->state == LDB_ASYNC_INIT) { + if (event_loop_once(ac->req->conn->event.event_ctx) != 0) { + return LDB_ERR_OTHER; + } + } + break; case LDB_WAIT_ALL: while (handle->status == LDB_SUCCESS && handle->state != LDB_ASYNC_DONE) { if (event_loop_once(ac->req->conn->event.event_ctx) != 0) { -- cgit From af99fe6b011b70a1770ab9b70fd7e0cac20b1ac0 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 28 Feb 2006 04:37:47 +0000 Subject: r13743: Generic fixes and improvements (This used to be commit c5eb27e5f7b23e5aa7e0fb1e11abfc760b499e85) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 139 +++++++++++++++++++--------------- 1 file changed, 80 insertions(+), 59 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index de32c10ba4..a5f4ab67fd 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -24,10 +24,22 @@ */ /* - This is a ldb backend for the internal ldap client library in - Samba4. By using this backend we are independent of a system ldap - library -*/ + * Name: ldb_ildap + * + * Component: ldb ildap backend + * + * Description: This is a ldb backend for the internal ldap + * client library in Samba4. By using this backend we are + * independent of a system ldap library + * + * Author: Andrew Tridgell + * + * Modifications: + * + * - description: make the module use asyncronous calls + * date: Feb 2006 + * author: Simo Sorce + */ #include "includes.h" @@ -141,7 +153,7 @@ static void ildb_async_callback(struct ldap_request *req) { struct ldb_async_handle *handle = talloc_get_type(req->async.private_data, struct ldb_async_handle); struct ildb_async_context *ac = talloc_get_type(handle->private_data, struct ildb_async_context); - struct ildb_private *ildb = ac->module->private_data; + struct ildb_private *ildb = talloc_get_type(ac->module->private_data, struct ildb_private); NTSTATUS status; int i; @@ -166,6 +178,10 @@ static void ildb_async_callback(struct ldap_request *req) } status = ldap_check_response(req->conn, &req->replies[0]->r.GeneralResult); handle->status = ildb_map_error(ildb, status); + if (ac->callback && handle->status == LDB_SUCCESS) { + /* FIXME: build a corresponding ares to pass on */ + handle->status = ac->callback(ac->module->ldb, ac->context, NULL); + } handle->state = LDB_ASYNC_DONE; break; @@ -176,6 +192,10 @@ static void ildb_async_callback(struct ldap_request *req) } status = ldap_check_response(req->conn, &req->replies[0]->r.GeneralResult); handle->status = ildb_map_error(ildb, status); + if (ac->callback && handle->status == LDB_SUCCESS) { + /* FIXME: build a corresponding ares to pass on */ + handle->status = ac->callback(ac->module->ldb, ac->context, NULL); + } handle->state = LDB_ASYNC_DONE; break; @@ -186,6 +206,10 @@ static void ildb_async_callback(struct ldap_request *req) } status = ldap_check_response(req->conn, &req->replies[0]->r.GeneralResult); handle->status = ildb_map_error(ildb, status); + if (ac->callback && handle->status == LDB_SUCCESS) { + /* FIXME: build a corresponding ares to pass on */ + handle->status = ac->callback(ac->module->ldb, ac->context, NULL); + } handle->state = LDB_ASYNC_DONE; break; @@ -196,6 +220,10 @@ static void ildb_async_callback(struct ldap_request *req) } status = ldap_check_response(req->conn, &req->replies[0]->r.GeneralResult); handle->status = ildb_map_error(ildb, status); + if (ac->callback && handle->status == LDB_SUCCESS) { + /* FIXME: build a corresponding ares to pass on */ + handle->status = ac->callback(ac->module->ldb, ac->context, NULL); + } handle->state = LDB_ASYNC_DONE; break; @@ -302,7 +330,7 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg int timeout, struct ldb_async_handle **handle) { - struct ildb_private *ildb = module->private_data; + struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ildb_async_context *ildb_ac; struct ldb_async_handle *h; struct ldap_request *req; @@ -362,7 +390,7 @@ static int ildb_search_async(struct ldb_module *module, const struct ldb_dn *bas int timeout, struct ldb_async_handle **handle) { - struct ildb_private *ildb = module->private_data; + struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldap_message *msg; int n; @@ -422,12 +450,6 @@ static int ildb_search_async(struct ldb_module *module, const struct ldb_dn *bas return ildb_request_send(module, msg, context, callback, timeout, handle); } -struct ildb_sync_context { - struct ldb_result *res; - int status; - int done; -}; - static int ildb_search_sync_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) { struct ldb_result *res; @@ -476,12 +498,10 @@ static int ildb_search_sync_callback(struct ldb_context *ldb, void *context, str res->refs[n + 1] = NULL; } - if (ares->type == LDB_REPLY_DONE) { - if (ares->controls) { - res->controls = talloc_steal(res, ares->controls); - if (! res->controls) { - goto error; - } + if (ares->controls) { + res->controls = talloc_steal(res, ares->controls); + if (! res->controls) { + goto error; } } @@ -504,7 +524,7 @@ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba struct ldb_control **control_req, struct ldb_result **res) { - struct ildb_private *ildb = module->private_data; + struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldb_async_handle *handle; int ret; @@ -531,7 +551,7 @@ static int ildb_add_async(struct ldb_module *module, const struct ldb_message *l int timeout, struct ldb_async_handle **handle) { - struct ildb_private *ildb = module->private_data; + struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldap_message *msg; struct ldap_mod **mods; int i,n; @@ -578,7 +598,7 @@ static int ildb_add_async(struct ldb_module *module, const struct ldb_message *l static int ildb_add(struct ldb_module *module, const struct ldb_message *msg) { - struct ildb_private *ildb = module->private_data; + struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldb_async_handle *handle; int ret; @@ -600,7 +620,7 @@ static int ildb_modify_async(struct ldb_module *module, const struct ldb_message int timeout, struct ldb_async_handle **handle) { - struct ildb_private *ildb = module->private_data; + struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldap_message *msg; struct ldap_mod **mods; int i,n; @@ -647,7 +667,7 @@ static int ildb_modify_async(struct ldb_module *module, const struct ldb_message static int ildb_modify(struct ldb_module *module, const struct ldb_message *msg) { - struct ildb_private *ildb = module->private_data; + struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldb_async_handle *handle; int ret; @@ -669,7 +689,7 @@ static int ildb_delete_async(struct ldb_module *module, const struct ldb_dn *dn, int timeout, struct ldb_async_handle **handle) { - struct ildb_private *ildb = module->private_data; + struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldap_message *msg; *handle = NULL; @@ -697,7 +717,7 @@ static int ildb_delete_async(struct ldb_module *module, const struct ldb_dn *dn, static int ildb_delete(struct ldb_module *module, const struct ldb_dn *dn) { - struct ildb_private *ildb = module->private_data; + struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldb_async_handle *handle; int ret; @@ -720,7 +740,7 @@ static int ildb_rename_async(struct ldb_module *module, int timeout, struct ldb_async_handle **handle) { - struct ildb_private *ildb = module->private_data; + struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldap_message *msg; *handle = NULL; @@ -766,7 +786,7 @@ static int ildb_rename_async(struct ldb_module *module, static int ildb_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn) { - struct ildb_private *ildb = module->private_data; + struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldb_async_handle *handle; int ret; @@ -878,36 +898,6 @@ static int ildb_request(struct ldb_module *module, struct ldb_request *req) } } -/* - fetch the rootDSE for later use -*/ -static int ildb_init_2(struct ldb_module *module) -{ - struct ildb_private *ildb = module->private_data; - struct ldb_result *res = NULL; - struct ldb_dn *empty_dn = ldb_dn_new(ildb); - int ret; - ret = ildb_search_bytree(module, empty_dn, LDB_SCOPE_BASE, - ldb_parse_tree(empty_dn, "dn=dc=rootDSE"), - NULL, NULL, &res); - if (ret == LDB_SUCCESS && res->count == 1) { - ildb->rootDSE = talloc_steal(ildb, res->msgs[0]); - } - if (ret == LDB_SUCCESS) talloc_free(res); - talloc_free(empty_dn); - - return LDB_SUCCESS; -} - -static const struct ldb_module_ops ildb_ops = { - .name = "ldap", - .request = ildb_request, - .start_transaction = ildb_start_trans, - .end_transaction = ildb_end_trans, - .del_transaction = ildb_del_trans, - .second_stage_init = ildb_init_2 -}; - static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type) { @@ -917,6 +907,8 @@ static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_ return LDB_ERR_OPERATIONS_ERROR; } + handle->state = LDB_ASYNC_INIT; + switch(type) { case LDB_WAIT_NONE: if (event_loop_once(ac->req->conn->event.event_ctx) != 0) { @@ -924,7 +916,6 @@ static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_ } break; case LDB_WAIT_ONCE: - handle->state = LDB_ASYNC_INIT; while (handle->status == LDB_SUCCESS && handle->state == LDB_ASYNC_INIT) { if (event_loop_once(ac->req->conn->event.event_ctx) != 0) { return LDB_ERR_OTHER; @@ -945,6 +936,36 @@ static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_ return handle->status; } +/* + fetch the rootDSE for later use +*/ +static int ildb_init_2(struct ldb_module *module) +{ + struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); + struct ldb_result *res = NULL; + struct ldb_dn *empty_dn = ldb_dn_new(ildb); + int ret; + ret = ildb_search_bytree(module, empty_dn, LDB_SCOPE_BASE, + ldb_parse_tree(empty_dn, "dn=dc=rootDSE"), + NULL, NULL, &res); + if (ret == LDB_SUCCESS && res->count == 1) { + ildb->rootDSE = talloc_steal(ildb, res->msgs[0]); + } + if (ret == LDB_SUCCESS) talloc_free(res); + talloc_free(empty_dn); + + return LDB_SUCCESS; +} + +static const struct ldb_module_ops ildb_ops = { + .name = "ldap", + .request = ildb_request, + .start_transaction = ildb_start_trans, + .end_transaction = ildb_end_trans, + .del_transaction = ildb_del_trans, + .second_stage_init = ildb_init_2 +}; + /* connect to the database */ -- cgit From 26af14c39b88b0e7eb53657b89be65d865804688 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 2 Mar 2006 16:32:53 +0000 Subject: r13786: [merge] Add registration functions for LDB modules Applications that use LDB modules will now have to run ldb_global_init() before they can use LDB. The next step will be adding support for loading LDB modules from .so files. This will also allow us to use one LDB without difference between the standalone and the Samba-specific build (This used to be commit 52a235650514039bf8ffee99a784bbc1b6ae6b92) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index a5f4ab67fd..69053cc110 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -898,7 +898,6 @@ static int ildb_request(struct ldb_module *module, struct ldb_request *req) } } - static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type) { struct ildb_async_context *ac = talloc_get_type(handle->private_data, struct ildb_async_context); @@ -939,7 +938,7 @@ static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_ /* fetch the rootDSE for later use */ -static int ildb_init_2(struct ldb_module *module) +static int ildb_init(struct ldb_module *module) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldb_result *res = NULL; @@ -963,7 +962,7 @@ static const struct ldb_module_ops ildb_ops = { .start_transaction = ildb_start_trans, .end_transaction = ildb_end_trans, .del_transaction = ildb_del_trans, - .second_stage_init = ildb_init_2 + .init_context = ildb_init }; /* -- cgit From 6ef61825541131e16a03975cdbd344e2bbebf810 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 3 Mar 2006 17:44:03 +0000 Subject: r13818: Make ldb_tdb 'fake' async. Simo. (This used to be commit 0db616ef59ed51cac7e0bfaea8a799d5aa42ef16) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 69053cc110..a3af7dedba 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -539,7 +539,10 @@ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba if (ret != LDB_SUCCESS) return ret; - return ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + + talloc_free(handle); + return ret; } /* @@ -608,7 +611,10 @@ static int ildb_add(struct ldb_module *module, const struct ldb_message *msg) if (ret != LDB_SUCCESS) return ret; - return ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + + talloc_free(handle); + return ret; } /* @@ -677,7 +683,10 @@ static int ildb_modify(struct ldb_module *module, const struct ldb_message *msg) if (ret != LDB_SUCCESS) return ret; - return ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + + talloc_free(handle); + return ret; } /* @@ -727,7 +736,10 @@ static int ildb_delete(struct ldb_module *module, const struct ldb_dn *dn) if (ret != LDB_SUCCESS) return ret; - return ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + + talloc_free(handle); + return ret; } /* @@ -796,7 +808,10 @@ static int ildb_rename(struct ldb_module *module, const struct ldb_dn *olddn, co if (ret != LDB_SUCCESS) return ret; - return ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + + talloc_free(handle); + return ret; } static int ildb_start_trans(struct ldb_module *module) -- cgit From 509814bd037a3c73fea4ab92b531c25964f34dfa Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 3 Mar 2006 20:01:19 +0000 Subject: r13823: make async_wait part of the modules ops (This used to be commit b4202cf030d5f154f0f94f5f501ecd648ba5c48f) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index a3af7dedba..869aec01cd 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -913,7 +913,7 @@ static int ildb_request(struct ldb_module *module, struct ldb_request *req) } } -static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type) +static int ildb_async_wait(struct ldb_module *module, struct ldb_async_handle *handle, enum ldb_async_wait_type type) { struct ildb_async_context *ac = talloc_get_type(handle->private_data, struct ildb_async_context); @@ -977,6 +977,7 @@ static const struct ldb_module_ops ildb_ops = { .start_transaction = ildb_start_trans, .end_transaction = ildb_end_trans, .del_transaction = ildb_del_trans, + .async_wait = ildb_async_wait, .init_context = ildb_init }; @@ -1051,8 +1052,6 @@ int ildb_connect(struct ldb_context *ldb, const char *url, } } - ldb->async_wait = &ildb_async_wait; - return 0; failed: -- cgit From 8edf29e8ef4d886321a6e8ec3902065641d34f40 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 3 Mar 2006 22:52:57 +0000 Subject: r13827: Minor enhancements or cosmetic changes (This used to be commit 7ef63abae12f65835a82f9931ad1f5ea75e5f3f6) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 869aec01cd..3467e65bf9 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -536,12 +536,15 @@ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba ret = ildb_search_async(module, base, scope, tree, attrs, control_req, res, &ildb_search_sync_callback, ildb->ldap->timeout, &handle); - if (ret != LDB_SUCCESS) - return ret; + if (ret == LDB_SUCCESS) { + ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + talloc_free(handle); + } - ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + if (ret != LDB_SUCCESS) { + talloc_free(*res); + } - talloc_free(handle); return ret; } -- cgit From 5d0aa16dfcf3047a52d3dd7e12ffb704a9725e83 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 5 Mar 2006 16:05:26 +0000 Subject: r13839: Use registration mechanism for backends as well (in the same sense my previous patch added it for modules). This is the next step towards LDB backends and modules as run-time loadable .so files. (This used to be commit fb2f70de4f6c4a9b13ad590cb4d3a9c858cede49) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 3467e65bf9..ab37ab7570 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -987,7 +987,7 @@ static const struct ldb_module_ops ildb_ops = { /* connect to the database */ -int ildb_connect(struct ldb_context *ldb, const char *url, +static int ildb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[]) { struct ildb_private *ildb = NULL; @@ -1065,3 +1065,7 @@ failed: return -1; } +int ldb_ildap_init(void) +{ + return ldb_register_backend("ldap", ildb_connect); +} -- cgit From 7b82c4beb93375f79b6c06fc86bb31873baa187b Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 7 Mar 2006 21:08:09 +0000 Subject: r13992: change the way ldb_async_wait() works. I think I should change the name of this function to ldb_async_process(), any opinions ? (This used to be commit 3347322d1327cfa975ee9dccd4f2774e6e14fbcb) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index ab37ab7570..45323b5550 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -341,6 +341,8 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg return LDB_ERR_OPERATIONS_ERROR; } + h->module = module; + ildb_ac = talloc(h, struct ildb_async_context); if (ildb_ac == NULL) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); @@ -916,7 +918,7 @@ static int ildb_request(struct ldb_module *module, struct ldb_request *req) } } -static int ildb_async_wait(struct ldb_module *module, struct ldb_async_handle *handle, enum ldb_async_wait_type type) +static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type) { struct ildb_async_context *ac = talloc_get_type(handle->private_data, struct ildb_async_context); -- cgit From 257598424e63c2cfa118b5ea84b7dc719d1dc5aa Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 7 Mar 2006 21:16:35 +0000 Subject: r13996: simplify ldb_async_wait() some more (This used to be commit ef1b3e6368179fe86ae07b8d00e4668090175551) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 45323b5550..f309262a55 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -539,7 +539,7 @@ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba res, &ildb_search_sync_callback, ildb->ldap->timeout, &handle); if (ret == LDB_SUCCESS) { - ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + ret = ldb_async_wait(handle, LDB_WAIT_ALL); talloc_free(handle); } @@ -616,7 +616,7 @@ static int ildb_add(struct ldb_module *module, const struct ldb_message *msg) if (ret != LDB_SUCCESS) return ret; - ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + ret = ldb_async_wait(handle, LDB_WAIT_ALL); talloc_free(handle); return ret; @@ -688,7 +688,7 @@ static int ildb_modify(struct ldb_module *module, const struct ldb_message *msg) if (ret != LDB_SUCCESS) return ret; - ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + ret = ldb_async_wait(handle, LDB_WAIT_ALL); talloc_free(handle); return ret; @@ -741,7 +741,7 @@ static int ildb_delete(struct ldb_module *module, const struct ldb_dn *dn) if (ret != LDB_SUCCESS) return ret; - ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + ret = ldb_async_wait(handle, LDB_WAIT_ALL); talloc_free(handle); return ret; @@ -813,7 +813,7 @@ static int ildb_rename(struct ldb_module *module, const struct ldb_dn *olddn, co if (ret != LDB_SUCCESS) return ret; - ret = ldb_async_wait(module->ldb, handle, LDB_WAIT_ALL); + ret = ldb_async_wait(handle, LDB_WAIT_ALL); talloc_free(handle); return ret; -- cgit From 3baf0606040419988f1a08c0da7f546c5904d8ca Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 10 Mar 2006 15:27:16 +0000 Subject: r14161: return early if we know the job is already finished (This used to be commit 09f6f552d73f782dc8d62cefad9c5f584b7b07d2) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index f309262a55..ceb9c4aafb 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -352,6 +352,9 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg h->private_data = (void *)ildb_ac; + h->state = LDB_ASYNC_INIT; + h->status = LDB_SUCCESS; + req = ldap_request_send(ildb->ldap, msg); if (req == NULL) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "async send request failed")); @@ -922,6 +925,10 @@ static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_ { struct ildb_async_context *ac = talloc_get_type(handle->private_data, struct ildb_async_context); + if (handle->state == LDB_ASYNC_DONE) { + return handle->status; + } + if (!ac) { return LDB_ERR_OPERATIONS_ERROR; } -- cgit From 6e74d8356578c42c8081498094f2c834c6d439b4 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 10 Mar 2006 15:50:47 +0000 Subject: r14163: Remove LDB_WAIT_ONCE, we can hardly guarante we get anything if not waiting for all, keeping this value may just lead to false expectations. You either make blocking call waiting for ALL results transforming this in a sync call, or either you loop expecting from 0 to all results being returned at any time on any of these loops. It should be clear also that when you may receive results at any time as soon as you call ldb_request. Your callback may have received all results even before calling ldb_async_wait the first time. Simo. (This used to be commit 6f041068b50caf919cd971812bdb8e3e810565fb) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index ceb9c4aafb..de07fa9a95 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -941,13 +941,6 @@ static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_ return LDB_ERR_OTHER; } break; - case LDB_WAIT_ONCE: - while (handle->status == LDB_SUCCESS && handle->state == LDB_ASYNC_INIT) { - if (event_loop_once(ac->req->conn->event.event_ctx) != 0) { - return LDB_ERR_OTHER; - } - } - break; case LDB_WAIT_ALL: while (handle->status == LDB_SUCCESS && handle->state != LDB_ASYNC_DONE) { if (event_loop_once(ac->req->conn->event.event_ctx) != 0) { -- cgit From 99dfc7e4d41634742978a7dcc249e698ab5bb71b Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 12 Mar 2006 00:04:27 +0000 Subject: r14227: We are passing the wrong pointer here (This used to be commit 22c1b3635596e881d1a1e8fa5e55ab996ff001d5) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index de07fa9a95..2b43193864 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -374,7 +374,7 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg if (timeout) { req->time_event = event_add_timed(req->conn->event.event_ctx, h, timeval_current_ofs(timeout, 0), - ildb_request_timeout, ildb_ac); + ildb_request_timeout, h); } *handle = h; -- cgit From bb1909e15e7a9f3cd79da2ce8b8ef90f1a557376 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 20 Mar 2006 21:44:59 +0000 Subject: r14592: Add support for loading shared modules to LDB. (This used to be commit f10fae23f0685b2d9c6174596e1c66d799f02c52) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 2b43193864..3c6101bb1a 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -1069,5 +1069,7 @@ failed: int ldb_ildap_init(void) { - return ldb_register_backend("ldap", ildb_connect); + return ldb_register_backend("ldap", ildb_connect) + + ldb_register_backend("ldapi", ildb_connect) + + ldb_register_backend("ldaps", ildb_connect); } -- cgit From f7312bf37367ab9576842ac06de0f170455d08a8 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 25 Apr 2006 12:34:58 +0000 Subject: r15242: allow to use LDB_FLG_RECONNECT (This used to be commit cdd14c2a277c6f2fb2aee21f91462d8ebe78693c) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 3c6101bb1a..cc5416fc5a 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -1011,6 +1011,10 @@ static int ildb_connect(struct ldb_context *ldb, const char *url, goto failed; } + if (flags == LDB_FLG_RECONNECT) { + ldap_set_reconn_params(ildb->ldap, 10); + } + status = ldap_connect(ildb->ldap, url); if (!NT_STATUS_IS_OK(status)) { ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to connect to ldap URL '%s' - %s\n", -- cgit From ddb43d8eeaef4c542bf98d99e76385209dfa54cc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 14 May 2006 00:07:03 +0000 Subject: r15592: Remove unused header (This used to be commit 7d3cbfb15768f95c7af6628eba578cae28ae2025) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index cc5416fc5a..ab302dd16d 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -48,7 +48,6 @@ #include "lib/events/events.h" #include "libcli/ldap/ldap.h" #include "libcli/ldap/ldap_client.h" -#include "lib/cmdline/popt_common.h" #include "auth/auth.h" struct ildb_private { -- cgit From 90a5e19e03842b77fd7811965fb2603e552261bc Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 28 May 2006 02:10:44 +0000 Subject: r15913: Error passing in the async code is not in agood shape Start enhancing it and fix some problems with incorrect evalutaion of the codes Implement rdn rename (async only) (This used to be commit 6af1d738b9668d4f0eb6194ac0f84af9e73f8c2e) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index ab302dd16d..0fa7af25ec 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -951,7 +951,7 @@ static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_ return LDB_ERR_OPERATIONS_ERROR; } - return handle->status; + return LDB_SUCCESS; } /* -- cgit From 3a4d7eb2c08a06fac89c34d132f1c32751ce7ad5 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 29 May 2006 01:30:02 +0000 Subject: r15927: Optimize ldb module traverse while keeping the API intact. I was sick of jumping inot each module for each request, even the ones not handle by that module. (This used to be commit 7d65105e885a28584e8555453b90232c43a92bf7) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 287 ++++++++++++++++++---------------- 1 file changed, 151 insertions(+), 136 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 0fa7af25ec..1454b565e0 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -385,27 +385,20 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg /* search for matching records using an asynchronous function */ -static int ildb_search_async(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const *attrs, - struct ldb_control **control_req, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - int timeout, - struct ldb_async_handle **handle) +static int ildb_search_async(struct ldb_module *module, struct ldb_request *req) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldap_message *msg; int n; - *handle = NULL; + req->async.handle = NULL; - if (!callback || !context) { + if (!req->async.callback || !req->async.context) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "Async interface called with NULL callback function or NULL context")); return LDB_ERR_OPERATIONS_ERROR; } - if (tree == NULL) { + if (req->op.search.tree == NULL) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "Invalid expression parse tree")); return LDB_ERR_OPERATIONS_ERROR; } @@ -418,7 +411,7 @@ static int ildb_search_async(struct ldb_module *module, const struct ldb_dn *bas msg->type = LDAP_TAG_SearchRequest; - if (base == NULL) { + if (req->op.search.base == NULL) { if (ildb->rootDSE != NULL) { msg->r.SearchRequest.basedn = talloc_strdup(msg, ldb_msg_find_string(ildb->rootDSE, "defaultNamingContext", "")); @@ -426,7 +419,7 @@ static int ildb_search_async(struct ldb_module *module, const struct ldb_dn *bas msg->r.SearchRequest.basedn = talloc_strdup(msg, ""); } } else { - msg->r.SearchRequest.basedn = ldb_dn_linearize(msg, base); + msg->r.SearchRequest.basedn = ldb_dn_linearize(msg, req->op.search.base); } if (msg->r.SearchRequest.basedn == NULL) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "Unable to determine baseDN")); @@ -434,24 +427,24 @@ static int ildb_search_async(struct ldb_module *module, const struct ldb_dn *bas return LDB_ERR_OPERATIONS_ERROR; } - if (scope == LDB_SCOPE_DEFAULT) { + if (req->op.search.scope == LDB_SCOPE_DEFAULT) { msg->r.SearchRequest.scope = LDB_SCOPE_SUBTREE; } else { - msg->r.SearchRequest.scope = scope; + msg->r.SearchRequest.scope = req->op.search.scope; } msg->r.SearchRequest.deref = LDAP_DEREFERENCE_NEVER; msg->r.SearchRequest.timelimit = 0; msg->r.SearchRequest.sizelimit = 0; msg->r.SearchRequest.attributesonly = 0; - msg->r.SearchRequest.tree = tree; + msg->r.SearchRequest.tree = req->op.search.tree; - for (n = 0; attrs && attrs[n]; n++) /* noop */ ; + for (n = 0; req->op.search.attrs && req->op.search.attrs[n]; n++) /* noop */ ; msg->r.SearchRequest.num_attributes = n; - msg->r.SearchRequest.attributes = discard_const(attrs); - msg->controls = control_req; + msg->r.SearchRequest.attributes = discard_const(req->op.search.attrs); + msg->controls = req->controls; - return ildb_request_send(module, msg, context, callback, timeout, handle); + return ildb_request_send(module, msg, req->async.context, req->async.callback, req->async.timeout, &(req->async.handle)); } static int ildb_search_sync_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) @@ -529,7 +522,7 @@ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba struct ldb_result **res) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; *res = talloc_zero(ildb, struct ldb_result); @@ -537,12 +530,26 @@ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba return LDB_ERR_OPERATIONS_ERROR; } - ret = ildb_search_async(module, base, scope, tree, attrs, control_req, - res, &ildb_search_sync_callback, ildb->ldap->timeout, &handle); + req = talloc_zero(ildb, struct ldb_request); + if (! req) { + return LDB_ERR_OPERATIONS_ERROR; + } + + req->operation = LDB_ASYNC_SEARCH; + req->op.search.base = base; + req->op.search.scope = scope; + req->op.search.tree = tree; + req->op.search.attrs = attrs; + req->controls = control_req; + req->async.context = (void *)res; + req->async.callback = ildb_search_sync_callback; + req->async.timeout = ildb->ldap->timeout; + + ret = ildb_search_async(module, req); if (ret == LDB_SUCCESS) { - ret = ldb_async_wait(handle, LDB_WAIT_ALL); - talloc_free(handle); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); + talloc_free(req); } if (ret != LDB_SUCCESS) { @@ -555,21 +562,17 @@ static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *ba /* add a record */ -static int ildb_add_async(struct ldb_module *module, const struct ldb_message *ldb_msg, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - int timeout, - struct ldb_async_handle **handle) +static int ildb_add_async(struct ldb_module *module, struct ldb_request *req) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldap_message *msg; struct ldap_mod **mods; int i,n; - *handle = NULL; + req->async.handle = NULL; /* ignore ltdb specials */ - if (ldb_dn_is_special(ldb_msg->dn)) { + if (ldb_dn_is_special(req->op.add.message->dn)) { return LDB_SUCCESS; } @@ -580,13 +583,13 @@ static int ildb_add_async(struct ldb_module *module, const struct ldb_message *l msg->type = LDAP_TAG_AddRequest; - msg->r.AddRequest.dn = ldb_dn_linearize(msg, ldb_msg->dn); + msg->r.AddRequest.dn = ldb_dn_linearize(msg, req->op.add.message->dn); if (msg->r.AddRequest.dn == NULL) { talloc_free(msg); return LDB_ERR_INVALID_DN_SYNTAX; } - mods = ildb_msg_to_mods(msg, &n, ldb_msg, 0); + mods = ildb_msg_to_mods(msg, &n, req->op.add.message, 0); if (mods == NULL) { talloc_free(msg); return LDB_ERR_OPERATIONS_ERROR; @@ -603,45 +606,54 @@ static int ildb_add_async(struct ldb_module *module, const struct ldb_message *l msg->r.AddRequest.attributes[i] = mods[i]->attrib; } - return ildb_request_send(module, msg, context, callback, timeout, handle); + return ildb_request_send(module, msg, req->async.context, req->async.callback, req->async.timeout, &(req->async.handle)); } static int ildb_add(struct ldb_module *module, const struct ldb_message *msg) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; - ret = ildb_add_async(module, msg, - NULL, NULL, ildb->ldap->timeout, &handle); + req = talloc_zero(ildb, struct ldb_request); + if (! req) { + return LDB_ERR_OPERATIONS_ERROR; + } + + req->operation = LDB_ASYNC_ADD; + req->op.add.message = msg; + req->controls = NULL; + req->async.context = NULL; + req->async.callback = NULL; + req->async.timeout = ildb->ldap->timeout; + + ret = ildb_add_async(module, req); - if (ret != LDB_SUCCESS) + if (ret != LDB_SUCCESS) { + talloc_free(req); return ret; + } - ret = ldb_async_wait(handle, LDB_WAIT_ALL); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - talloc_free(handle); + talloc_free(req); return ret; } /* modify a record */ -static int ildb_modify_async(struct ldb_module *module, const struct ldb_message *ldb_msg, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - int timeout, - struct ldb_async_handle **handle) +static int ildb_modify_async(struct ldb_module *module, struct ldb_request *req) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldap_message *msg; struct ldap_mod **mods; int i,n; - *handle = NULL; + req->async.handle = NULL; /* ignore ltdb specials */ - if (ldb_dn_is_special(ldb_msg->dn)) { + if (ldb_dn_is_special(req->op.mod.message->dn)) { return LDB_SUCCESS; } @@ -652,13 +664,13 @@ static int ildb_modify_async(struct ldb_module *module, const struct ldb_message msg->type = LDAP_TAG_ModifyRequest; - msg->r.ModifyRequest.dn = ldb_dn_linearize(msg, ldb_msg->dn); + msg->r.ModifyRequest.dn = ldb_dn_linearize(msg, req->op.mod.message->dn); if (msg->r.ModifyRequest.dn == NULL) { talloc_free(msg); return LDB_ERR_INVALID_DN_SYNTAX; } - mods = ildb_msg_to_mods(msg, &n, ldb_msg, 1); + mods = ildb_msg_to_mods(msg, &n, req->op.mod.message, 1); if (mods == NULL) { talloc_free(msg); return LDB_ERR_OPERATIONS_ERROR; @@ -675,43 +687,56 @@ static int ildb_modify_async(struct ldb_module *module, const struct ldb_message msg->r.ModifyRequest.mods[i] = *mods[i]; } - return ildb_request_send(module, msg, context, callback, timeout, handle); + return ildb_request_send(module, msg, + req->async.context, + req->async.callback, + req->async.timeout, + &(req->async.handle)); } static int ildb_modify(struct ldb_module *module, const struct ldb_message *msg) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; - ret = ildb_modify_async(module, msg, - NULL, NULL, ildb->ldap->timeout, &handle); + req = talloc_zero(ildb, struct ldb_request); + if (! req) { + return LDB_ERR_OPERATIONS_ERROR; + } + + req->operation = LDB_ASYNC_MODIFY; + req->op.mod.message = msg; + req->controls = NULL; + req->async.context = NULL; + req->async.callback = NULL; + req->async.timeout = ildb->ldap->timeout; + + ret = ildb_modify_async(module, req); - if (ret != LDB_SUCCESS) + if (ret != LDB_SUCCESS) { + talloc_free(req); return ret; + } - ret = ldb_async_wait(handle, LDB_WAIT_ALL); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - talloc_free(handle); + talloc_free(req); return ret; } /* delete a record */ -static int ildb_delete_async(struct ldb_module *module, const struct ldb_dn *dn, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - int timeout, - struct ldb_async_handle **handle) +static int ildb_delete_async(struct ldb_module *module, struct ldb_request *req) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldap_message *msg; - *handle = NULL; + req->async.handle = NULL; /* ignore ltdb specials */ - if (ldb_dn_is_special(dn)) { + if (ldb_dn_is_special(req->op.del.dn)) { return LDB_SUCCESS; } @@ -722,50 +747,62 @@ static int ildb_delete_async(struct ldb_module *module, const struct ldb_dn *dn, msg->type = LDAP_TAG_DelRequest; - msg->r.DelRequest.dn = ldb_dn_linearize(msg, dn); + msg->r.DelRequest.dn = ldb_dn_linearize(msg, req->op.del.dn); if (msg->r.DelRequest.dn == NULL) { talloc_free(msg); return LDB_ERR_INVALID_DN_SYNTAX; } - return ildb_request_send(module, msg, context, callback, timeout, handle); + return ildb_request_send(module, msg, + req->async.context, + req->async.callback, + req->async.timeout, + &(req->async.handle)); } static int ildb_delete(struct ldb_module *module, const struct ldb_dn *dn) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; - ret = ildb_delete_async(module, dn, - NULL, NULL, ildb->ldap->timeout, &handle); + req = talloc_zero(ildb, struct ldb_request); + if (! req) { + return LDB_ERR_OPERATIONS_ERROR; + } - if (ret != LDB_SUCCESS) + req->operation = LDB_ASYNC_DELETE; + req->op.del.dn = dn; + req->controls = NULL; + req->async.context = NULL; + req->async.callback = NULL; + req->async.timeout = ildb->ldap->timeout; + + ret = ildb_delete_async(module, req); + + if (ret != LDB_SUCCESS) { + talloc_free(req); return ret; + } - ret = ldb_async_wait(handle, LDB_WAIT_ALL); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - talloc_free(handle); + talloc_free(req); return ret; } /* rename a record */ -static int ildb_rename_async(struct ldb_module *module, - const struct ldb_dn *olddn, const struct ldb_dn *newdn, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), - int timeout, - struct ldb_async_handle **handle) +static int ildb_rename_async(struct ldb_module *module, struct ldb_request *req) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldap_message *msg; - *handle = NULL; + req->async.handle = NULL; /* ignore ltdb specials */ - if (ldb_dn_is_special(olddn) || ldb_dn_is_special(newdn)) { + if (ldb_dn_is_special(req->op.rename.olddn) || ldb_dn_is_special(req->op.rename.newdn)) { return LDB_SUCCESS; } @@ -775,7 +812,7 @@ static int ildb_rename_async(struct ldb_module *module, } msg->type = LDAP_TAG_ModifyDNRequest; - msg->r.ModifyDNRequest.dn = ldb_dn_linearize(msg, olddn); + msg->r.ModifyDNRequest.dn = ldb_dn_linearize(msg, req->op.rename.olddn); if (msg->r.ModifyDNRequest.dn == NULL) { talloc_free(msg); return LDB_ERR_INVALID_DN_SYNTAX; @@ -783,8 +820,8 @@ static int ildb_rename_async(struct ldb_module *module, msg->r.ModifyDNRequest.newrdn = talloc_asprintf(msg, "%s=%s", - newdn->components[0].name, - ldb_dn_escape_value(msg, newdn->components[0].value)); + req->op.rename.newdn->components[0].name, + ldb_dn_escape_value(msg, req->op.rename.newdn->components[0].value)); if (msg->r.ModifyDNRequest.newrdn == NULL) { talloc_free(msg); return LDB_ERR_OPERATIONS_ERROR; @@ -792,7 +829,7 @@ static int ildb_rename_async(struct ldb_module *module, msg->r.ModifyDNRequest.newsuperior = ldb_dn_linearize(msg, - ldb_dn_get_parent(msg, newdn)); + ldb_dn_get_parent(msg, req->op.rename.newdn)); if (msg->r.ModifyDNRequest.newsuperior == NULL) { talloc_free(msg); return LDB_ERR_INVALID_DN_SYNTAX; @@ -800,24 +837,42 @@ static int ildb_rename_async(struct ldb_module *module, msg->r.ModifyDNRequest.deleteolddn = True; - return ildb_request_send(module, msg, context, callback, timeout, handle); + return ildb_request_send(module, msg, + req->async.context, + req->async.callback, + req->async.timeout, + &(req->async.handle)); } static int ildb_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); - struct ldb_async_handle *handle; + struct ldb_request *req; int ret; - ret = ildb_rename_async(module, olddn, newdn, - NULL, NULL, ildb->ldap->timeout, &handle); + req = talloc_zero(ildb, struct ldb_request); + if (! req) { + return LDB_ERR_OPERATIONS_ERROR; + } + + req->operation = LDB_ASYNC_RENAME; + req->op.rename.olddn = olddn; + req->op.rename.newdn = newdn; + req->controls = NULL; + req->async.context = NULL; + req->async.callback = NULL; + req->async.timeout = ildb->ldap->timeout; - if (ret != LDB_SUCCESS) + ret = ildb_rename_async(module, req); + + if (ret != LDB_SUCCESS) { + talloc_free(req); return ret; + } - ret = ldb_async_wait(handle, LDB_WAIT_ALL); + ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - talloc_free(handle); + talloc_free(req); return ret; } @@ -869,51 +924,6 @@ static int ildb_request(struct ldb_module *module, struct ldb_request *req) req->op.rename.olddn, req->op.rename.newdn); - case LDB_ASYNC_SEARCH: - return ildb_search_async(module, - req->op.search.base, - req->op.search.scope, - req->op.search.tree, - req->op.search.attrs, - req->controls, - req->async.context, - req->async.callback, - req->async.timeout, - &req->async.handle); - - case LDB_ASYNC_ADD: - return ildb_add_async(module, - req->op.add.message, - req->async.context, - req->async.callback, - req->async.timeout, - &req->async.handle); - - case LDB_ASYNC_MODIFY: - return ildb_modify_async(module, - req->op.mod.message, - req->async.context, - req->async.callback, - req->async.timeout, - &req->async.handle); - - case LDB_ASYNC_DELETE: - return ildb_delete_async(module, - req->op.del.dn, - req->async.context, - req->async.callback, - req->async.timeout, - &req->async.handle); - - case LDB_ASYNC_RENAME: - return ildb_rename_async(module, - req->op.rename.olddn, - req->op.rename.newdn, - req->async.context, - req->async.callback, - req->async.timeout, - &req->async.handle); - default: return -1; @@ -977,6 +987,11 @@ static int ildb_init(struct ldb_module *module) static const struct ldb_module_ops ildb_ops = { .name = "ldap", + .search = ildb_search_async, + .add = ildb_add_async, + .modify = ildb_modify_async, + .del = ildb_delete_async, + .rename = ildb_rename_async, .request = ildb_request, .start_transaction = ildb_start_trans, .end_transaction = ildb_end_trans, -- cgit From 0c7b82e5f6063de4114de21cf854ac67346e31f6 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 29 May 2006 23:46:43 +0000 Subject: r15942: Remove the sync internal ldb calls altogether. This means that some modules have been disabled as well as they have not been ported to the async interface One of them is the ugly objectclass module. I hope that the change in samldb module will make the MMC happy without the need of this crappy module, we need proper handling in a decent schema module. proxy and ldb_map have also been disabled ldb_sqlite3 need to be ported as well (currenlty just broken). (This used to be commit 51083de795bdcbf649de926e86969adc20239b6d) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 363 +++++++--------------------------- 1 file changed, 72 insertions(+), 291 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 1454b565e0..3bb431e34f 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -148,7 +148,7 @@ static void ildb_request_timeout(struct event_context *ev, struct timed_event *t return; } -static void ildb_async_callback(struct ldap_request *req) +static void ildb_callback(struct ldap_request *req) { struct ldb_async_handle *handle = talloc_get_type(req->async.private_data, struct ldb_async_handle); struct ildb_async_context *ac = talloc_get_type(handle->private_data, struct ildb_async_context); @@ -365,7 +365,7 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg ildb_ac->context = context; ildb_ac->callback = callback; - req->async.fn = ildb_async_callback; + req->async.fn = ildb_callback; req->async.private_data = (void *)h; talloc_free(req->time_event); @@ -385,7 +385,7 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg /* search for matching records using an asynchronous function */ -static int ildb_search_async(struct ldb_module *module, struct ldb_request *req) +static int ildb_search(struct ldb_module *module, struct ldb_request *req) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldap_message *msg; @@ -447,122 +447,10 @@ static int ildb_search_async(struct ldb_module *module, struct ldb_request *req) return ildb_request_send(module, msg, req->async.context, req->async.callback, req->async.timeout, &(req->async.handle)); } -static int ildb_search_sync_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) -{ - struct ldb_result *res; - int n; - - if (!context) { - ldb_set_errstring(ldb, talloc_asprintf(ldb, "NULL Context in callback")); - return LDB_ERR_OPERATIONS_ERROR; - } - - res = *((struct ldb_result **)context); - - if (!res || !ares) { - goto error; - } - - if (ares->type == LDB_REPLY_ENTRY) { - res->msgs = talloc_realloc(res, res->msgs, struct ldb_message *, res->count + 2); - if (! res->msgs) { - goto error; - } - - res->msgs[res->count + 1] = NULL; - - res->msgs[res->count] = talloc_steal(res->msgs, ares->message); - if (! res->msgs[res->count]) { - goto error; - } - - res->count++; - } - - if (ares->type == LDB_REPLY_REFERRAL) { - if (res->refs) { - for (n = 0; res->refs[n]; n++) /*noop*/ ; - } else { - n = 0; - } - - res->refs = talloc_realloc(res, res->refs, char *, n + 2); - if (! res->refs) { - goto error; - } - - res->refs[n] = talloc_steal(res->refs, ares->referral); - res->refs[n + 1] = NULL; - } - - if (ares->controls) { - res->controls = talloc_steal(res, ares->controls); - if (! res->controls) { - goto error; - } - } - - talloc_free(ares); - return LDB_SUCCESS; - -error: - talloc_free(ares); - talloc_free(res); - *((struct ldb_result **)context) = NULL; - return LDB_ERR_OPERATIONS_ERROR; -} - -/* - search for matching records using a synchronous function - */ -static int ildb_search_bytree(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const *attrs, - struct ldb_control **control_req, - struct ldb_result **res) -{ - struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); - struct ldb_request *req; - int ret; - - *res = talloc_zero(ildb, struct ldb_result); - if (! *res) { - return LDB_ERR_OPERATIONS_ERROR; - } - - req = talloc_zero(ildb, struct ldb_request); - if (! req) { - return LDB_ERR_OPERATIONS_ERROR; - } - - req->operation = LDB_ASYNC_SEARCH; - req->op.search.base = base; - req->op.search.scope = scope; - req->op.search.tree = tree; - req->op.search.attrs = attrs; - req->controls = control_req; - req->async.context = (void *)res; - req->async.callback = ildb_search_sync_callback; - req->async.timeout = ildb->ldap->timeout; - - ret = ildb_search_async(module, req); - - if (ret == LDB_SUCCESS) { - ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - talloc_free(req); - } - - if (ret != LDB_SUCCESS) { - talloc_free(*res); - } - - return ret; -} - /* add a record */ -static int ildb_add_async(struct ldb_module *module, struct ldb_request *req) +static int ildb_add(struct ldb_module *module, struct ldb_request *req) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldap_message *msg; @@ -609,41 +497,10 @@ static int ildb_add_async(struct ldb_module *module, struct ldb_request *req) return ildb_request_send(module, msg, req->async.context, req->async.callback, req->async.timeout, &(req->async.handle)); } -static int ildb_add(struct ldb_module *module, const struct ldb_message *msg) -{ - struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); - struct ldb_request *req; - int ret; - - req = talloc_zero(ildb, struct ldb_request); - if (! req) { - return LDB_ERR_OPERATIONS_ERROR; - } - - req->operation = LDB_ASYNC_ADD; - req->op.add.message = msg; - req->controls = NULL; - req->async.context = NULL; - req->async.callback = NULL; - req->async.timeout = ildb->ldap->timeout; - - ret = ildb_add_async(module, req); - - if (ret != LDB_SUCCESS) { - talloc_free(req); - return ret; - } - - ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - - talloc_free(req); - return ret; -} - /* modify a record */ -static int ildb_modify_async(struct ldb_module *module, struct ldb_request *req) +static int ildb_modify(struct ldb_module *module, struct ldb_request *req) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldap_message *msg; @@ -694,41 +551,10 @@ static int ildb_modify_async(struct ldb_module *module, struct ldb_request *req) &(req->async.handle)); } -static int ildb_modify(struct ldb_module *module, const struct ldb_message *msg) -{ - struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); - struct ldb_request *req; - int ret; - - req = talloc_zero(ildb, struct ldb_request); - if (! req) { - return LDB_ERR_OPERATIONS_ERROR; - } - - req->operation = LDB_ASYNC_MODIFY; - req->op.mod.message = msg; - req->controls = NULL; - req->async.context = NULL; - req->async.callback = NULL; - req->async.timeout = ildb->ldap->timeout; - - ret = ildb_modify_async(module, req); - - if (ret != LDB_SUCCESS) { - talloc_free(req); - return ret; - } - - ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - - talloc_free(req); - return ret; -} - /* delete a record */ -static int ildb_delete_async(struct ldb_module *module, struct ldb_request *req) +static int ildb_delete(struct ldb_module *module, struct ldb_request *req) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldap_message *msg; @@ -760,41 +586,10 @@ static int ildb_delete_async(struct ldb_module *module, struct ldb_request *req) &(req->async.handle)); } -static int ildb_delete(struct ldb_module *module, const struct ldb_dn *dn) -{ - struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); - struct ldb_request *req; - int ret; - - req = talloc_zero(ildb, struct ldb_request); - if (! req) { - return LDB_ERR_OPERATIONS_ERROR; - } - - req->operation = LDB_ASYNC_DELETE; - req->op.del.dn = dn; - req->controls = NULL; - req->async.context = NULL; - req->async.callback = NULL; - req->async.timeout = ildb->ldap->timeout; - - ret = ildb_delete_async(module, req); - - if (ret != LDB_SUCCESS) { - talloc_free(req); - return ret; - } - - ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - - talloc_free(req); - return ret; -} - /* rename a record */ -static int ildb_rename_async(struct ldb_module *module, struct ldb_request *req) +static int ildb_rename(struct ldb_module *module, struct ldb_request *req) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldap_message *msg; @@ -844,90 +639,30 @@ static int ildb_rename_async(struct ldb_module *module, struct ldb_request *req) &(req->async.handle)); } -static int ildb_rename(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn) -{ - struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); - struct ldb_request *req; - int ret; - - req = talloc_zero(ildb, struct ldb_request); - if (! req) { - return LDB_ERR_OPERATIONS_ERROR; - } - - req->operation = LDB_ASYNC_RENAME; - req->op.rename.olddn = olddn; - req->op.rename.newdn = newdn; - req->controls = NULL; - req->async.context = NULL; - req->async.callback = NULL; - req->async.timeout = ildb->ldap->timeout; - - ret = ildb_rename_async(module, req); - - if (ret != LDB_SUCCESS) { - talloc_free(req); - return ret; - } - - ret = ldb_async_wait(req->async.handle, LDB_WAIT_ALL); - - talloc_free(req); - return ret; -} - static int ildb_start_trans(struct ldb_module *module) { /* TODO implement a local locking mechanism here */ - return 0; + return LDB_SUCCESS; } static int ildb_end_trans(struct ldb_module *module) { /* TODO implement a local transaction mechanism here */ - return 0; + return LDB_SUCCESS; } static int ildb_del_trans(struct ldb_module *module) { /* TODO implement a local locking mechanism here */ - return 0; + return LDB_SUCCESS; } static int ildb_request(struct ldb_module *module, struct ldb_request *req) { - switch (req->operation) { - - case LDB_REQ_SEARCH: - return ildb_search_bytree(module, - req->op.search.base, - req->op.search.scope, - req->op.search.tree, - req->op.search.attrs, - req->controls, - &req->op.search.res); - - case LDB_REQ_ADD: - return ildb_add(module, req->op.add.message); - - case LDB_REQ_MODIFY: - return ildb_modify(module, req->op.mod.message); - - case LDB_REQ_DELETE: - return ildb_delete(module, req->op.del.dn); - - case LDB_REQ_RENAME: - return ildb_rename(module, - req->op.rename.olddn, - req->op.rename.newdn); - - default: - return -1; - - } + return LDB_ERR_OPERATIONS_ERROR; } static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type) @@ -964,34 +699,80 @@ static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_ return LDB_SUCCESS; } +static int ildb_rootdse_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) +{ + struct ildb_private *ildb; + + if (!context || !ares) { + ldb_set_errstring(ldb, talloc_asprintf(ldb, "NULL Context or Result in callback")); + goto error; + } + + ildb = talloc_get_type(context, struct ildb_private); + + if (ildb->rootDSE != NULL) { + /* what ? more than one rootdse entry ?! */ + goto error; + } + + /* we are interested only in the single reply (rootdse) we receive here */ + if (ares->type == LDB_REPLY_ENTRY) { + ildb->rootDSE = talloc_steal(ildb, ares->message); + } + + talloc_free(ares); + return LDB_SUCCESS; + +error: + talloc_free(ares); + return LDB_ERR_OPERATIONS_ERROR; +} + /* fetch the rootDSE for later use */ static int ildb_init(struct ldb_module *module) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); - struct ldb_result *res = NULL; - struct ldb_dn *empty_dn = ldb_dn_new(ildb); + struct ldb_request *req; int ret; - ret = ildb_search_bytree(module, empty_dn, LDB_SCOPE_BASE, - ldb_parse_tree(empty_dn, "dn=dc=rootDSE"), - NULL, NULL, &res); - if (ret == LDB_SUCCESS && res->count == 1) { - ildb->rootDSE = talloc_steal(ildb, res->msgs[0]); + + req = talloc(ildb, struct ldb_request); + if (req == NULL) { + return LDB_ERR_OPERATIONS_ERROR; } - if (ret == LDB_SUCCESS) talloc_free(res); - talloc_free(empty_dn); - return LDB_SUCCESS; + ildb->rootDSE = NULL; + + req->operation = LDB_ASYNC_SEARCH; + req->op.search.base = ldb_dn_new(req); + req->op.search.scope = LDB_SCOPE_BASE; + req->op.search.tree = ldb_parse_tree(req, "dn=dc=rootDSE"); + req->op.search.attrs = NULL; + req->controls = NULL; + req->async.context = ildb; + req->async.callback = ildb_rootdse_callback; + req->async.timeout = 60; + + ret = ildb_search(module, req); + if (ret != LDB_SUCCESS) { + talloc_free(req); + return ret; + } + + ret = ildb_async_wait(req->async.handle, LDB_WAIT_ALL); + + talloc_free(req); + return ret; } static const struct ldb_module_ops ildb_ops = { .name = "ldap", - .search = ildb_search_async, - .add = ildb_add_async, - .modify = ildb_modify_async, - .del = ildb_delete_async, - .rename = ildb_rename_async, + .search = ildb_search, + .add = ildb_add, + .modify = ildb_modify, + .del = ildb_delete, + .rename = ildb_rename, .request = ildb_request, .start_transaction = ildb_start_trans, .end_transaction = ildb_end_trans, -- cgit From 2d19dca9c80a5e3990296dde67163fce36ac883d Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 30 May 2006 00:33:52 +0000 Subject: r15944: rename LDB_ASYNC_ADD -> LDB_ADD, LDB_ASYNC_MODIFY -> LDB_MODIFY, etc... (This used to be commit 55d97ef88f377ef1dbf7b1774a15cf9035e2f320) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 3bb431e34f..1772a091a3 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -744,7 +744,7 @@ static int ildb_init(struct ldb_module *module) ildb->rootDSE = NULL; - req->operation = LDB_ASYNC_SEARCH; + req->operation = LDB_SEARCH; req->op.search.base = ldb_dn_new(req); req->op.search.scope = LDB_SCOPE_BASE; req->op.search.tree = ldb_parse_tree(req, "dn=dc=rootDSE"); -- cgit From a6c4541fdf19f0a5505d23142dbb1fa6af855c6c Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 30 May 2006 19:09:34 +0000 Subject: r15963: fix warnings metze (This used to be commit 11b49a440567eb3fa3391c15f5486c63141f1b97) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 1772a091a3..8929428494 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -271,7 +271,7 @@ static void ildb_callback(struct ldap_request *req) ares->message = ldb_msg_new(ares); if (!ares->message) { - handle->status = LDB_ERR_OPERATIONS_ERROR;; + handle->status = LDB_ERR_OPERATIONS_ERROR; return; } @@ -437,7 +437,7 @@ static int ildb_search(struct ldb_module *module, struct ldb_request *req) msg->r.SearchRequest.timelimit = 0; msg->r.SearchRequest.sizelimit = 0; msg->r.SearchRequest.attributesonly = 0; - msg->r.SearchRequest.tree = req->op.search.tree; + msg->r.SearchRequest.tree = discard_const(req->op.search.tree); for (n = 0; req->op.search.attrs && req->op.search.attrs[n]; n++) /* noop */ ; msg->r.SearchRequest.num_attributes = n; -- cgit From 5cc28a03659f6b2ae554284800d108a6a70a1041 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 30 May 2006 19:41:29 +0000 Subject: r15964: fix error handling in ldb_ildap backend metze (This used to be commit 54e5aeff87b859960dfc5e4b6e3ab026ce5470ff) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 8929428494..003c6c011e 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -696,7 +696,7 @@ static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_ return LDB_ERR_OPERATIONS_ERROR; } - return LDB_SUCCESS; + return handle->status; } static int ildb_rootdse_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) @@ -710,14 +710,21 @@ static int ildb_rootdse_callback(struct ldb_context *ldb, void *context, struct ildb = talloc_get_type(context, struct ildb_private); - if (ildb->rootDSE != NULL) { - /* what ? more than one rootdse entry ?! */ - goto error; - } - /* we are interested only in the single reply (rootdse) we receive here */ - if (ares->type == LDB_REPLY_ENTRY) { + switch (ares->type) { + case LDB_REPLY_ENTRY: + if (ildb->rootDSE != NULL) { + /* what ? more than one rootdse entry ?! */ + goto error; + } ildb->rootDSE = talloc_steal(ildb, ares->message); + break; + + case LDB_REPLY_REFERRAL: + goto error; + + case LDB_REPLY_DONE: + break; } talloc_free(ares); -- cgit From ca5accf224dc3ef998235603797b519866b57b1c Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 4 Jun 2006 05:28:13 +0000 Subject: r16036: Add a couple of new functions to corretly deal with timeouts. Check timeouts are correctly verified. Some minor fixed and removal of unused code. (This used to be commit b52e5d6a0cb1a32e62759eaa49ce3e4cc804cc92) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 003c6c011e..4fc34ccdcf 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -143,7 +143,7 @@ static void ildb_request_timeout(struct event_context *ev, struct timed_event *t DLIST_REMOVE(ac->req->conn->pending, ac->req); } - handle->status = LDB_ERR_OPERATIONS_ERROR; + handle->status = LDB_ERR_TIME_LIMIT_EXCEEDED; return; } @@ -759,7 +759,7 @@ static int ildb_init(struct ldb_module *module) req->controls = NULL; req->async.context = ildb; req->async.callback = ildb_rootdse_callback; - req->async.timeout = 60; + ldb_set_timeout(module->ldb, req, 60); ret = ildb_search(module, req); if (ret != LDB_SUCCESS) { -- cgit From 247af0d569594512a24e83156e257b8d4d356883 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 7 Jun 2006 21:03:38 +0000 Subject: r16083: Make it possible to initialise a backend module, without it setting up the whole ldb structure. Because the sequence number was a fn pointer on the main ldb context, turn it into a full request (currently sync). Andrew Bartlett (This used to be commit fbe7d0ca9031e292b2d2fae263233c973982980a) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 4fc34ccdcf..340f89e48f 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -792,7 +792,8 @@ static const struct ldb_module_ops ildb_ops = { connect to the database */ static int ildb_connect(struct ldb_context *ldb, const char *url, - unsigned int flags, const char *options[]) + unsigned int flags, const char *options[], + struct ldb_module **module) { struct ildb_private *ildb = NULL; NTSTATUS status; @@ -824,15 +825,17 @@ static int ildb_connect(struct ldb_context *ldb, const char *url, goto failed; } - ldb->modules = talloc(ldb, struct ldb_module); - if (!ldb->modules) { + + *module = talloc(ldb, struct ldb_module); + if (!module) { ldb_oom(ldb); - goto failed; + talloc_free(ildb); + return -1; } - ldb->modules->ldb = ldb; - ldb->modules->prev = ldb->modules->next = NULL; - ldb->modules->private_data = ildb; - ldb->modules->ops = &ildb_ops; + (*module)->ldb = ldb; + (*module)->prev = ldb->modules->next = NULL; + (*module)->private_data = ildb; + (*module)->ops = &ildb_ops; /* caller can optionally setup credentials using the opaque token 'credentials' */ creds = talloc_get_type(ldb_get_opaque(ldb, "credentials"), struct cli_credentials); -- cgit From d912d6fcef28fad1c6e1c04a3a2eb4ed9e1a4ca3 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 8 Jun 2006 01:02:14 +0000 Subject: r16087: Fix silly cut-and-paste typo that cost me much of my afternoon... This only affects my new partitions module, which I will post soon, but should be fixed anyway. Andrew Bartlett (This used to be commit 8912c4e057eb3962321245cf49b92999afcc64fc) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 340f89e48f..9251451549 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -833,7 +833,7 @@ static int ildb_connect(struct ldb_context *ldb, const char *url, return -1; } (*module)->ldb = ldb; - (*module)->prev = ldb->modules->next = NULL; + (*module)->prev = (*module)->next = NULL; (*module)->private_data = ildb; (*module)->ops = &ildb_ops; @@ -869,9 +869,6 @@ static int ildb_connect(struct ldb_context *ldb, const char *url, return 0; failed: - if (ldb->modules) { - ldb->modules->private_data = NULL; - } talloc_free(ildb); return -1; } -- cgit From c93817b36d3ff7f44cb7b3e1d1a29e37ec12affe Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 22 Jul 2006 16:56:33 +0000 Subject: r17185: Oh, I wanted to do this for sooo long time. Finally acknowledge that ldb is inherently async and does not have a dual personality anymore Rename all ldb_async_XXX functions to ldb_XXX except for ldb_async_result, it is now ldb_reply to reflect the real function of this structure. Simo. (This used to be commit 25fc7354049d62efeba17681ef1cdd326bc3f2ef) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 38 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 9251451549..3410d68c5e 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -56,11 +56,11 @@ struct ildb_private { struct ldb_context *ldb; }; -struct ildb_async_context { +struct ildb_context { struct ldb_module *module; struct ldap_request *req; void *context; - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *); + int (*callback)(struct ldb_context *, void *, struct ldb_reply *); }; /* @@ -136,8 +136,8 @@ static int ildb_map_error(struct ildb_private *ildb, NTSTATUS status) static void ildb_request_timeout(struct event_context *ev, struct timed_event *te, struct timeval t, void *private_data) { - struct ldb_async_handle *handle = talloc_get_type(private_data, struct ldb_async_handle); - struct ildb_async_context *ac = talloc_get_type(handle->private_data, struct ildb_async_context); + struct ldb_handle *handle = talloc_get_type(private_data, struct ldb_handle); + struct ildb_context *ac = talloc_get_type(handle->private_data, struct ildb_context); if (ac->req->state == LDAP_REQUEST_PENDING) { DLIST_REMOVE(ac->req->conn->pending, ac->req); @@ -150,8 +150,8 @@ static void ildb_request_timeout(struct event_context *ev, struct timed_event *t static void ildb_callback(struct ldap_request *req) { - struct ldb_async_handle *handle = talloc_get_type(req->async.private_data, struct ldb_async_handle); - struct ildb_async_context *ac = talloc_get_type(handle->private_data, struct ildb_async_context); + struct ldb_handle *handle = talloc_get_type(req->async.private_data, struct ldb_handle); + struct ildb_context *ac = talloc_get_type(handle->private_data, struct ildb_context); struct ildb_private *ildb = talloc_get_type(ac->module->private_data, struct ildb_private); NTSTATUS status; int i; @@ -230,11 +230,11 @@ static void ildb_callback(struct ldap_request *req) /* loop over all messages */ for (i = 0; i < req->num_replies; i++) { struct ldap_SearchResEntry *search; - struct ldb_async_result *ares = NULL; + struct ldb_reply *ares = NULL; struct ldap_message *msg; int ret; - ares = talloc_zero(ac, struct ldb_async_result); + ares = talloc_zero(ac, struct ldb_reply); if (!ares) { handle->status = LDB_ERR_OPERATIONS_ERROR; return; @@ -325,16 +325,16 @@ static void ildb_callback(struct ldap_request *req) static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg, void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_async_result *), + int (*callback)(struct ldb_context *, void *, struct ldb_reply *), int timeout, - struct ldb_async_handle **handle) + struct ldb_handle **handle) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); - struct ildb_async_context *ildb_ac; - struct ldb_async_handle *h; + struct ildb_context *ildb_ac; + struct ldb_handle *h; struct ldap_request *req; - h = talloc_zero(ildb->ldap, struct ldb_async_handle); + h = talloc_zero(ildb->ldap, struct ldb_handle); if (h == NULL) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); return LDB_ERR_OPERATIONS_ERROR; @@ -342,7 +342,7 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg h->module = module; - ildb_ac = talloc(h, struct ildb_async_context); + ildb_ac = talloc(h, struct ildb_context); if (ildb_ac == NULL) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); talloc_free(h); @@ -665,9 +665,9 @@ static int ildb_request(struct ldb_module *module, struct ldb_request *req) return LDB_ERR_OPERATIONS_ERROR; } -static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type) +static int ildb_wait(struct ldb_handle *handle, enum ldb_wait_type type) { - struct ildb_async_context *ac = talloc_get_type(handle->private_data, struct ildb_async_context); + struct ildb_context *ac = talloc_get_type(handle->private_data, struct ildb_context); if (handle->state == LDB_ASYNC_DONE) { return handle->status; @@ -699,7 +699,7 @@ static int ildb_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_ return handle->status; } -static int ildb_rootdse_callback(struct ldb_context *ldb, void *context, struct ldb_async_result *ares) +static int ildb_rootdse_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares) { struct ildb_private *ildb; @@ -767,7 +767,7 @@ static int ildb_init(struct ldb_module *module) return ret; } - ret = ildb_async_wait(req->async.handle, LDB_WAIT_ALL); + ret = ildb_wait(req->async.handle, LDB_WAIT_ALL); talloc_free(req); return ret; @@ -784,7 +784,7 @@ static const struct ldb_module_ops ildb_ops = { .start_transaction = ildb_start_trans, .end_transaction = ildb_end_trans, .del_transaction = ildb_del_trans, - .async_wait = ildb_async_wait, + .wait = ildb_wait, .init_context = ildb_init }; -- cgit From 49f68caed20d2a7d1850e493005bdf85929d6365 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 22 Jul 2006 17:21:59 +0000 Subject: r17186: "async" word abuse clean-up part 2 (This used to be commit c6aa60c7e69abf1f83efc150b1c3ed02751c45fc) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 40 ++++++++++++----------------------- 1 file changed, 14 insertions(+), 26 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 3410d68c5e..ae92ede8ce 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -391,9 +391,9 @@ static int ildb_search(struct ldb_module *module, struct ldb_request *req) struct ldap_message *msg; int n; - req->async.handle = NULL; + req->handle = NULL; - if (!req->async.callback || !req->async.context) { + if (!req->callback || !req->context) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "Async interface called with NULL callback function or NULL context")); return LDB_ERR_OPERATIONS_ERROR; } @@ -444,7 +444,7 @@ static int ildb_search(struct ldb_module *module, struct ldb_request *req) msg->r.SearchRequest.attributes = discard_const(req->op.search.attrs); msg->controls = req->controls; - return ildb_request_send(module, msg, req->async.context, req->async.callback, req->async.timeout, &(req->async.handle)); + return ildb_request_send(module, msg, req->context, req->callback, req->timeout, &(req->handle)); } /* @@ -457,7 +457,7 @@ static int ildb_add(struct ldb_module *module, struct ldb_request *req) struct ldap_mod **mods; int i,n; - req->async.handle = NULL; + req->handle = NULL; /* ignore ltdb specials */ if (ldb_dn_is_special(req->op.add.message->dn)) { @@ -494,7 +494,7 @@ static int ildb_add(struct ldb_module *module, struct ldb_request *req) msg->r.AddRequest.attributes[i] = mods[i]->attrib; } - return ildb_request_send(module, msg, req->async.context, req->async.callback, req->async.timeout, &(req->async.handle)); + return ildb_request_send(module, msg, req->context, req->callback, req->timeout, &(req->handle)); } /* @@ -507,7 +507,7 @@ static int ildb_modify(struct ldb_module *module, struct ldb_request *req) struct ldap_mod **mods; int i,n; - req->async.handle = NULL; + req->handle = NULL; /* ignore ltdb specials */ if (ldb_dn_is_special(req->op.mod.message->dn)) { @@ -544,11 +544,7 @@ static int ildb_modify(struct ldb_module *module, struct ldb_request *req) msg->r.ModifyRequest.mods[i] = *mods[i]; } - return ildb_request_send(module, msg, - req->async.context, - req->async.callback, - req->async.timeout, - &(req->async.handle)); + return ildb_request_send(module, msg, req->context, req->callback, req->timeout, &(req->handle)); } /* @@ -559,7 +555,7 @@ static int ildb_delete(struct ldb_module *module, struct ldb_request *req) struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldap_message *msg; - req->async.handle = NULL; + req->handle = NULL; /* ignore ltdb specials */ if (ldb_dn_is_special(req->op.del.dn)) { @@ -579,11 +575,7 @@ static int ildb_delete(struct ldb_module *module, struct ldb_request *req) return LDB_ERR_INVALID_DN_SYNTAX; } - return ildb_request_send(module, msg, - req->async.context, - req->async.callback, - req->async.timeout, - &(req->async.handle)); + return ildb_request_send(module, msg, req->context, req->callback, req->timeout, &(req->handle)); } /* @@ -594,7 +586,7 @@ static int ildb_rename(struct ldb_module *module, struct ldb_request *req) struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ldap_message *msg; - req->async.handle = NULL; + req->handle = NULL; /* ignore ltdb specials */ if (ldb_dn_is_special(req->op.rename.olddn) || ldb_dn_is_special(req->op.rename.newdn)) { @@ -632,11 +624,7 @@ static int ildb_rename(struct ldb_module *module, struct ldb_request *req) msg->r.ModifyDNRequest.deleteolddn = True; - return ildb_request_send(module, msg, - req->async.context, - req->async.callback, - req->async.timeout, - &(req->async.handle)); + return ildb_request_send(module, msg, req->context, req->callback, req->timeout, &(req->handle)); } static int ildb_start_trans(struct ldb_module *module) @@ -757,8 +745,8 @@ static int ildb_init(struct ldb_module *module) req->op.search.tree = ldb_parse_tree(req, "dn=dc=rootDSE"); req->op.search.attrs = NULL; req->controls = NULL; - req->async.context = ildb; - req->async.callback = ildb_rootdse_callback; + req->context = ildb; + req->callback = ildb_rootdse_callback; ldb_set_timeout(module->ldb, req, 60); ret = ildb_search(module, req); @@ -767,7 +755,7 @@ static int ildb_init(struct ldb_module *module) return ret; } - ret = ildb_wait(req->async.handle, LDB_WAIT_ALL); + ret = ildb_wait(req->handle, LDB_WAIT_ALL); talloc_free(req); return ret; -- cgit From 2d65c9ada5ca3f5d263707947d73106e180a9920 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 29 Jul 2006 01:22:22 +0000 Subject: r17300: Try to fix some segfaults in ldb_ildap module, when the remote server drops the connection. The reconnect code needs to be hooked in here. Andrew Bartlett (This used to be commit 778debedea77ac81cc05f00f27bb96a58cbebcd8) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index ae92ede8ce..a4427b8b95 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -360,6 +360,11 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg return LDB_ERR_OPERATIONS_ERROR; } + if (!req->conn) { + ldb_set_errstring(module->ldb, talloc_asprintf(module, "connection to remote LDAP server dropped?")); + return LDB_ERR_OPERATIONS_ERROR; + } + ildb_ac->req = talloc_steal(ildb_ac, req); ildb_ac->module = module; ildb_ac->context = context; @@ -802,7 +807,7 @@ static int ildb_connect(struct ldb_context *ldb, const char *url, goto failed; } - if (flags == LDB_FLG_RECONNECT) { + if (flags & LDB_FLG_RECONNECT) { ldap_set_reconn_params(ildb->ldap, 10); } -- cgit From b94b9d8c3d7b99294eb48437894d8c6901e9dc70 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 1 Aug 2006 02:25:05 +0000 Subject: r17349: We can't just return sucess here, modules below us expect the async reply rules to be followed. Add code to do a fake async callback on the skipped records. Andrew Bartlett (This used to be commit 26bc7dbed978f92e814d9803366eac7d7f4ded3e) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 76 ++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 20 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index a4427b8b95..f6ddbf4931 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -323,21 +323,18 @@ static void ildb_callback(struct ldap_request *req) } } -static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_reply *), - int timeout, - struct ldb_handle **handle) +static struct ldb_handle *init_ildb_handle(struct ldb_module *module, + void *context, + int (*callback)(struct ldb_context *, void *, struct ldb_reply *)) { struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ildb_context *ildb_ac; struct ldb_handle *h; - struct ldap_request *req; h = talloc_zero(ildb->ldap, struct ldb_handle); if (h == NULL) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); - return LDB_ERR_OPERATIONS_ERROR; + return NULL; } h->module = module; @@ -346,7 +343,7 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg if (ildb_ac == NULL) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); talloc_free(h); - return LDB_ERR_OPERATIONS_ERROR; + return NULL; } h->private_data = (void *)ildb_ac; @@ -354,6 +351,30 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg h->state = LDB_ASYNC_INIT; h->status = LDB_SUCCESS; + ildb_ac->module = module; + ildb_ac->context = context; + ildb_ac->callback = callback; + + return h; +} + +static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg, + void *context, + int (*callback)(struct ldb_context *, void *, struct ldb_reply *), + int timeout, + struct ldb_handle **handle) +{ + struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); + struct ldb_handle *h = init_ildb_handle(module, context, callback); + struct ildb_context *ildb_ac; + struct ldap_request *req; + + if (!h) { + return LDB_ERR_OPERATIONS_ERROR; + } + + ildb_ac = talloc_get_type(h->private_data, struct ildb_context); + req = ldap_request_send(ildb->ldap, msg); if (req == NULL) { ldb_set_errstring(module->ldb, talloc_asprintf(module, "async send request failed")); @@ -366,13 +387,6 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg } ildb_ac->req = talloc_steal(ildb_ac, req); - ildb_ac->module = module; - ildb_ac->context = context; - ildb_ac->callback = callback; - - req->async.fn = ildb_callback; - req->async.private_data = (void *)h; - talloc_free(req->time_event); req->time_event = NULL; if (timeout) { @@ -381,10 +395,32 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg ildb_request_timeout, h); } - *handle = h; + req->async.fn = ildb_callback; + req->async.private_data = (void *)h; + *handle = h; return LDB_SUCCESS; +} +static int ildb_request_noop(struct ldb_module *module, struct ldb_request *req) +{ + struct ldb_handle *h = init_ildb_handle(module, req->context, req->callback); + struct ildb_context *ildb_ac; + int ret = LDB_SUCCESS; + + if (!h) { + return LDB_ERR_OPERATIONS_ERROR; + } + + ildb_ac = talloc_get_type(h->private_data, struct ildb_context); + + req->handle = h; + + if (ildb_ac->callback) { + ret = ildb_ac->callback(module->ldb, ildb_ac->context, NULL); + } + req->handle->state = LDB_ASYNC_DONE; + return ret; } /* @@ -466,7 +502,7 @@ static int ildb_add(struct ldb_module *module, struct ldb_request *req) /* ignore ltdb specials */ if (ldb_dn_is_special(req->op.add.message->dn)) { - return LDB_SUCCESS; + return ildb_request_noop(module, req); } msg = new_ldap_message(ildb->ldap); @@ -516,7 +552,7 @@ static int ildb_modify(struct ldb_module *module, struct ldb_request *req) /* ignore ltdb specials */ if (ldb_dn_is_special(req->op.mod.message->dn)) { - return LDB_SUCCESS; + return ildb_request_noop(module, req); } msg = new_ldap_message(ildb->ldap); @@ -564,7 +600,7 @@ static int ildb_delete(struct ldb_module *module, struct ldb_request *req) /* ignore ltdb specials */ if (ldb_dn_is_special(req->op.del.dn)) { - return LDB_SUCCESS; + return ildb_request_noop(module, req); } msg = new_ldap_message(ildb->ldap); @@ -595,7 +631,7 @@ static int ildb_rename(struct ldb_module *module, struct ldb_request *req) /* ignore ltdb specials */ if (ldb_dn_is_special(req->op.rename.olddn) || ldb_dn_is_special(req->op.rename.newdn)) { - return LDB_SUCCESS; + return ildb_request_noop(module, req); } msg = new_ldap_message(ildb->ldap); -- cgit From faed8175063b16df94d5332581baf1af0562bb09 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 13 Aug 2006 07:33:57 +0000 Subject: r17514: Simplify the way to set ldb errors and add another helper function to set them. (This used to be commit 260868bae56194fcb98d55afc22fc66d96a303df) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index f6ddbf4931..c71f1be9ba 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -257,7 +257,7 @@ static void ildb_callback(struct ldap_request *req) } if (msg->r.SearchResultDone.resultcode) { if (msg->r.SearchResultDone.errormessage) { - ldb_set_errstring(ac->module->ldb, talloc_strdup(ac->module, msg->r.SearchResultDone.errormessage)); + ldb_set_errstring(ac->module->ldb, msg->r.SearchResultDone.errormessage); } } @@ -333,7 +333,7 @@ static struct ldb_handle *init_ildb_handle(struct ldb_module *module, h = talloc_zero(ildb->ldap, struct ldb_handle); if (h == NULL) { - ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); + ldb_set_errstring(module->ldb, "Out of Memory"); return NULL; } @@ -341,7 +341,7 @@ static struct ldb_handle *init_ildb_handle(struct ldb_module *module, ildb_ac = talloc(h, struct ildb_context); if (ildb_ac == NULL) { - ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); + ldb_set_errstring(module->ldb, "Out of Memory"); talloc_free(h); return NULL; } @@ -377,12 +377,12 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg req = ldap_request_send(ildb->ldap, msg); if (req == NULL) { - ldb_set_errstring(module->ldb, talloc_asprintf(module, "async send request failed")); + ldb_set_errstring(module->ldb, "async send request failed"); return LDB_ERR_OPERATIONS_ERROR; } if (!req->conn) { - ldb_set_errstring(module->ldb, talloc_asprintf(module, "connection to remote LDAP server dropped?")); + ldb_set_errstring(module->ldb, "connection to remote LDAP server dropped?"); return LDB_ERR_OPERATIONS_ERROR; } @@ -435,18 +435,18 @@ static int ildb_search(struct ldb_module *module, struct ldb_request *req) req->handle = NULL; if (!req->callback || !req->context) { - ldb_set_errstring(module->ldb, talloc_asprintf(module, "Async interface called with NULL callback function or NULL context")); + ldb_set_errstring(module->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, talloc_asprintf(module, "Invalid expression parse tree")); + ldb_set_errstring(module->ldb, "Invalid expression parse tree"); return LDB_ERR_OPERATIONS_ERROR; } msg = new_ldap_message(ildb); if (msg == NULL) { - ldb_set_errstring(module->ldb, talloc_asprintf(module, "Out of Memory")); + ldb_set_errstring(module->ldb, "Out of Memory"); return LDB_ERR_OPERATIONS_ERROR; } @@ -463,7 +463,7 @@ static int ildb_search(struct ldb_module *module, struct ldb_request *req) msg->r.SearchRequest.basedn = ldb_dn_linearize(msg, req->op.search.base); } if (msg->r.SearchRequest.basedn == NULL) { - ldb_set_errstring(module->ldb, talloc_asprintf(module, "Unable to determine baseDN")); + ldb_set_errstring(module->ldb, "Unable to determine baseDN"); talloc_free(msg); return LDB_ERR_OPERATIONS_ERROR; } @@ -733,7 +733,7 @@ static int ildb_rootdse_callback(struct ldb_context *ldb, void *context, struct struct ildb_private *ildb; if (!context || !ares) { - ldb_set_errstring(ldb, talloc_asprintf(ldb, "NULL Context or Result in callback")); + ldb_set_errstring(ldb, "NULL Context or Result in callback"); goto error; } @@ -783,7 +783,7 @@ static int ildb_init(struct ldb_module *module) req->operation = LDB_SEARCH; req->op.search.base = ldb_dn_new(req); req->op.search.scope = LDB_SCOPE_BASE; - req->op.search.tree = ldb_parse_tree(req, "dn=dc=rootDSE"); + req->op.search.tree = ldb_parse_tree(req, "(objectClass=*)"); req->op.search.attrs = NULL; req->controls = NULL; req->context = ildb; -- cgit From a23b63a8e54db7d0ec98ad95cdca11dd4d039e17 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 13 Aug 2006 08:00:36 +0000 Subject: r17516: Change helper function names to make more clear what they are meant to do (This used to be commit ad75cf869550af66119d0293503024d41d834e02) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index c71f1be9ba..99e3f3e322 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -455,7 +455,7 @@ static int ildb_search(struct ldb_module *module, struct ldb_request *req) if (req->op.search.base == NULL) { if (ildb->rootDSE != NULL) { msg->r.SearchRequest.basedn = - talloc_strdup(msg, ldb_msg_find_string(ildb->rootDSE, "defaultNamingContext", "")); + talloc_strdup(msg, ldb_msg_find_attr_as_string(ildb->rootDSE, "defaultNamingContext", "")); } else { msg->r.SearchRequest.basedn = talloc_strdup(msg, ""); } -- cgit From fb36e279e79ae54c1622c316780e20fb9aaf1a85 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 25 Aug 2006 06:45:47 +0000 Subject: r17822: the ildap ldb backend doesn't need the auto rootDSE logic any more (This used to be commit c670837cc0dd04834a283bde0471c702a34c66c9) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 86 +---------------------------------- 1 file changed, 2 insertions(+), 84 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 99e3f3e322..b22dd517d2 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -52,7 +52,6 @@ struct ildb_private { struct ldap_connection *ldap; - struct ldb_message *rootDSE; struct ldb_context *ldb; }; @@ -453,12 +452,7 @@ static int ildb_search(struct ldb_module *module, struct ldb_request *req) msg->type = LDAP_TAG_SearchRequest; if (req->op.search.base == NULL) { - if (ildb->rootDSE != NULL) { - msg->r.SearchRequest.basedn = - talloc_strdup(msg, ldb_msg_find_attr_as_string(ildb->rootDSE, "defaultNamingContext", "")); - } else { - msg->r.SearchRequest.basedn = talloc_strdup(msg, ""); - } + msg->r.SearchRequest.basedn = talloc_strdup(msg, ""); } else { msg->r.SearchRequest.basedn = ldb_dn_linearize(msg, req->op.search.base); } @@ -728,80 +722,6 @@ static int ildb_wait(struct ldb_handle *handle, enum ldb_wait_type type) return handle->status; } -static int ildb_rootdse_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares) -{ - struct ildb_private *ildb; - - if (!context || !ares) { - ldb_set_errstring(ldb, "NULL Context or Result in callback"); - goto error; - } - - ildb = talloc_get_type(context, struct ildb_private); - - /* we are interested only in the single reply (rootdse) we receive here */ - switch (ares->type) { - case LDB_REPLY_ENTRY: - if (ildb->rootDSE != NULL) { - /* what ? more than one rootdse entry ?! */ - goto error; - } - ildb->rootDSE = talloc_steal(ildb, ares->message); - break; - - case LDB_REPLY_REFERRAL: - goto error; - - case LDB_REPLY_DONE: - break; - } - - talloc_free(ares); - return LDB_SUCCESS; - -error: - talloc_free(ares); - return LDB_ERR_OPERATIONS_ERROR; -} - -/* - fetch the rootDSE for later use -*/ -static int ildb_init(struct ldb_module *module) -{ - struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); - struct ldb_request *req; - int ret; - - req = talloc(ildb, struct ldb_request); - if (req == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - - ildb->rootDSE = NULL; - - req->operation = LDB_SEARCH; - req->op.search.base = ldb_dn_new(req); - req->op.search.scope = LDB_SCOPE_BASE; - req->op.search.tree = ldb_parse_tree(req, "(objectClass=*)"); - req->op.search.attrs = NULL; - req->controls = NULL; - req->context = ildb; - req->callback = ildb_rootdse_callback; - ldb_set_timeout(module->ldb, req, 60); - - ret = ildb_search(module, req); - if (ret != LDB_SUCCESS) { - talloc_free(req); - return ret; - } - - ret = ildb_wait(req->handle, LDB_WAIT_ALL); - - talloc_free(req); - return ret; -} - static const struct ldb_module_ops ildb_ops = { .name = "ldap", .search = ildb_search, @@ -813,8 +733,7 @@ static const struct ldb_module_ops ildb_ops = { .start_transaction = ildb_start_trans, .end_transaction = ildb_end_trans, .del_transaction = ildb_del_trans, - .wait = ildb_wait, - .init_context = ildb_init + .wait = ildb_wait }; /* @@ -834,7 +753,6 @@ static int ildb_connect(struct ldb_context *ldb, const char *url, goto failed; } - ildb->rootDSE = NULL; ildb->ldb = ldb; ildb->ldap = ldap_new_connection(ildb, ldb_get_opaque(ldb, "EventContext")); -- cgit From e91cee468eceb6ff8843bafc7fbb22a21b52a00c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 9 Sep 2006 12:57:45 +0000 Subject: r18309: FreeBSD 6.1 has a symbol ldap_new_connection() in the system ldap library. Even though we don't like to that library, it gets loaded via nss-ldap, which means nss-ldap calls into the samba ldap lib with the wrong parameters, and crashes. We really need to use a completely different namespace in libcli/ldap/ (This used to be commit c440e0eed9afae5fe69995a7416971e7c8560779) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index b22dd517d2..f521425312 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -755,7 +755,7 @@ static int ildb_connect(struct ldb_context *ldb, const char *url, ildb->ldb = ldb; - ildb->ldap = ldap_new_connection(ildb, ldb_get_opaque(ldb, "EventContext")); + ildb->ldap = ldap4_new_connection(ildb, ldb_get_opaque(ldb, "EventContext")); if (!ildb->ldap) { ldb_oom(ldb); goto failed; -- cgit From 33c4fea4cdf7d5418423a81e53ce7b051500f287 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 12 Sep 2006 00:41:49 +0000 Subject: r18410: Reduce noise in the ldb_ildap backend. We regularly search for things that don't exist, and this is not a cause for panic. Andrew Bartlett (This used to be commit c89e416d288d16de43ae93102ecfec588900e6c0) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index f521425312..0f6391d7eb 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -124,8 +124,7 @@ static int ildb_map_error(struct ildb_private *ildb, NTSTATUS status) if (NT_STATUS_IS_OK(status)) { return LDB_SUCCESS; } - talloc_free(ildb->ldb->err_string); - ildb->ldb->err_string = talloc_strdup(ildb, ldap_errstr(ildb->ldap, status)); + ldb_set_errstring(ildb->ldb, ldap_errstr(ildb->ldap, status)); if (NT_STATUS_IS_LDAP(status)) { return NT_STATUS_LDAP_CODE(status); } @@ -246,7 +245,6 @@ static void ildb_callback(struct ldap_request *req) status = ldap_check_response(req->conn, &msg->r.GeneralResult); if (!NT_STATUS_IS_OK(status)) { - ldb_debug(ac->module->ldb, LDB_DEBUG_ERROR, "Error: %s\n" ,ldap_errstr(req->conn, status)); handle->status = ildb_map_error(ildb, status); return; } -- cgit From 7f63cebd331793d059b1dbfd2f7d7ce38105c4fe Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Sep 2006 00:10:38 +0000 Subject: r18436: converted ldb to use talloc_move() instead of talloc_steal() when appropriate. Note that I also removed the error checks that were being done on the result of talloc_steal(). They are pointless as talloc_steal() doesn't have any failure modes that wouldn't cause a segv anyway, and they tend to clutter the code (This used to be commit c0d9e7d473b8e3eb2524a9fc29cf88680f994b36) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 0f6391d7eb..b826a31b40 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -249,9 +249,7 @@ static void ildb_callback(struct ldap_request *req) return; } - if (msg->controls) { - ares->controls = talloc_steal(ares, msg->controls); - } + ares->controls = talloc_move(ares, msg->controls); if (msg->r.SearchResultDone.resultcode) { if (msg->r.SearchResultDone.errormessage) { ldb_set_errstring(ac->module->ldb, msg->r.SearchResultDone.errormessage); @@ -280,7 +278,7 @@ static void ildb_callback(struct ldap_request *req) return; } ares->message->num_elements = search->num_attributes; - ares->message->elements = talloc_steal(ares->message, search->attributes); + ares->message->elements = talloc_move(ares->message, search->attributes); handle->status = LDB_SUCCESS; handle->state = LDB_ASYNC_PENDING; @@ -383,7 +381,7 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg return LDB_ERR_OPERATIONS_ERROR; } - ildb_ac->req = talloc_steal(ildb_ac, req); + ildb_ac->req = talloc_move(ildb_ac, req); talloc_free(req->time_event); req->time_event = NULL; if (timeout) { -- cgit From 24fe49a3d10633fa9be5547e89d10be1d5f9ccb1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Sep 2006 02:03:20 +0000 Subject: r18438: I should have examined these uses of talloc_move() more carefully. Most of them are OK, but a couple were not. (This used to be commit b0de2838829d9750817c31f28c11c6b2be6e7b64) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index b826a31b40..49a8e8627a 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -381,7 +381,6 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg return LDB_ERR_OPERATIONS_ERROR; } - ildb_ac->req = talloc_move(ildb_ac, req); talloc_free(req->time_event); req->time_event = NULL; if (timeout) { @@ -392,6 +391,7 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg req->async.fn = ildb_callback; req->async.private_data = (void *)h; + ildb_ac->req = talloc_move(ildb_ac, req); *handle = h; return LDB_SUCCESS; -- cgit From 05cdd9ccafeeb384792b9ce7ca044bcec1bfc839 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Sep 2006 02:33:51 +0000 Subject: r18439: 2nd try at a talloc_move() api. This type with the ** ptr interface exposed. Unfortunately this generates a large number of type punning warnings. We'll have to find some magic to hide those. (This used to be commit 254cbf09dee5a1e20c47e47a298f1a8d172b41b9) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 49a8e8627a..5b69ac06c9 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -249,7 +249,7 @@ static void ildb_callback(struct ldap_request *req) return; } - ares->controls = talloc_move(ares, msg->controls); + ares->controls = talloc_move(ares, &msg->controls); if (msg->r.SearchResultDone.resultcode) { if (msg->r.SearchResultDone.errormessage) { ldb_set_errstring(ac->module->ldb, msg->r.SearchResultDone.errormessage); @@ -278,7 +278,8 @@ static void ildb_callback(struct ldap_request *req) return; } ares->message->num_elements = search->num_attributes; - ares->message->elements = talloc_move(ares->message, search->attributes); + ares->message->elements = talloc_move(ares->message, + &search->attributes); handle->status = LDB_SUCCESS; handle->state = LDB_ASYNC_PENDING; @@ -391,7 +392,7 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg req->async.fn = ildb_callback; req->async.private_data = (void *)h; - ildb_ac->req = talloc_move(ildb_ac, req); + ildb_ac->req = talloc_move(ildb_ac, &req); *handle = h; return LDB_SUCCESS; -- cgit From e36ea2e8ebe44079dd3989694f0235e77caf4fe2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 17 Oct 2006 01:21:02 +0000 Subject: r19362: - don't need to store the baseinfo message after cache load - set better names on talloc structures in ldb modules, making leaks easier to track down (This used to be commit 3bf76db42dc6dde5d71083216dba819869b31c75) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 5b69ac06c9..3843d2b825 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -776,6 +776,7 @@ static int ildb_connect(struct ldb_context *ldb, const char *url, talloc_free(ildb); return -1; } + talloc_set_name_const(*module, "ldb_ildap backend"); (*module)->ldb = ldb; (*module)->prev = (*module)->next = NULL; (*module)->private_data = ildb; -- cgit From b7774527faf095f612eb1de48efacec6bd710a87 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 1 Nov 2006 23:31:26 +0000 Subject: r19531: Make struct ldb_dn opaque and local to ldb_dn.c (This used to be commit 889fb983ba1cf8a11424a8b3dc3a5ef76e780082) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 3843d2b825..5a3ccd6977 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -639,8 +639,8 @@ static int ildb_rename(struct ldb_module *module, struct ldb_request *req) msg->r.ModifyDNRequest.newrdn = talloc_asprintf(msg, "%s=%s", - req->op.rename.newdn->components[0].name, - ldb_dn_escape_value(msg, req->op.rename.newdn->components[0].value)); + ldb_dn_get_rdn_name(req->op.rename.newdn), + ldb_dn_escape_value(msg, *ldb_dn_get_rdn_val(req->op.rename.newdn))); if (msg->r.ModifyDNRequest.newrdn == NULL) { talloc_free(msg); return LDB_ERR_OPERATIONS_ERROR; -- cgit From 13dbee3ffea6065a826f010e50c9b4eb2c6ad109 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 7 Nov 2006 00:48:36 +0000 Subject: r19598: Ahead of a merge to current lorikeet-heimdal: Break up auth/auth.h not to include the world. Add credentials_krb5.h with the kerberos dependent prototypes. Andrew Bartlett (This used to be commit 2b569c42e0fbb596ea82484d0e1cb22e193037b9) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 5a3ccd6977..51ae031cf9 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -49,6 +49,7 @@ #include "libcli/ldap/ldap.h" #include "libcli/ldap/ldap_client.h" #include "auth/auth.h" +#include "auth/credentials/credentials.h" struct ildb_private { struct ldap_connection *ldap; -- cgit From 4889eb9f7aae9349e426d0f6d2217adff67eaebd Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 22 Nov 2006 00:59:34 +0000 Subject: r19831: Big ldb_dn optimization and interfaces enhancement patch This patch changes a lot of the code in ldb_dn.c, and also removes and add a number of manipulation functions around. The aim is to avoid validating a dn if not necessary as the validation code is necessarily slow. This is mainly to speed up internal operations where input is not user generated and so we can assume the DNs need no validation. The code is designed to keep the data as a string if possible. The code is not yet 100% perfect, but pass all the tests so far. A memleak is certainly present, I'll work on that next. Simo. (This used to be commit a580c871d3784602a9cce32d33419e63c8236e63) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 51ae031cf9..a4abd4d151 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -273,8 +273,8 @@ static void ildb_callback(struct ldap_request *req) search = &(msg->r.SearchResultEntry); - ares->message->dn = ldb_dn_explode_or_special(ares->message, search->dn); - if (ares->message->dn == NULL) { + ares->message->dn = ldb_dn_new(ares->message, ac->module->ldb, search->dn); + if ( ! ldb_dn_validate(ares->message->dn)) { handle->status = LDB_ERR_OPERATIONS_ERROR; return; } -- cgit From a9e31b33b55a873c2f01db5e348560176adf863d Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 22 Nov 2006 02:05:19 +0000 Subject: r19832: better prototypes for the linearization functions: - ldb_dn_get_linearized returns a const string - ldb_dn_alloc_linearized allocs astring with the linearized dn (This used to be commit 3929c086d5d0b3f08b1c4f2f3f9602c3f4a9a4bd) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index a4abd4d151..567fe4bd5f 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -452,7 +452,7 @@ static int ildb_search(struct ldb_module *module, struct ldb_request *req) if (req->op.search.base == NULL) { msg->r.SearchRequest.basedn = talloc_strdup(msg, ""); } else { - msg->r.SearchRequest.basedn = ldb_dn_linearize(msg, req->op.search.base); + msg->r.SearchRequest.basedn = ldb_dn_alloc_linearized(msg, req->op.search.base); } if (msg->r.SearchRequest.basedn == NULL) { ldb_set_errstring(module->ldb, "Unable to determine baseDN"); @@ -504,7 +504,7 @@ static int ildb_add(struct ldb_module *module, struct ldb_request *req) msg->type = LDAP_TAG_AddRequest; - msg->r.AddRequest.dn = ldb_dn_linearize(msg, req->op.add.message->dn); + msg->r.AddRequest.dn = ldb_dn_alloc_linearized(msg, req->op.add.message->dn); if (msg->r.AddRequest.dn == NULL) { talloc_free(msg); return LDB_ERR_INVALID_DN_SYNTAX; @@ -554,7 +554,7 @@ static int ildb_modify(struct ldb_module *module, struct ldb_request *req) msg->type = LDAP_TAG_ModifyRequest; - msg->r.ModifyRequest.dn = ldb_dn_linearize(msg, req->op.mod.message->dn); + msg->r.ModifyRequest.dn = ldb_dn_alloc_linearized(msg, req->op.mod.message->dn); if (msg->r.ModifyRequest.dn == NULL) { talloc_free(msg); return LDB_ERR_INVALID_DN_SYNTAX; @@ -602,7 +602,7 @@ static int ildb_delete(struct ldb_module *module, struct ldb_request *req) msg->type = LDAP_TAG_DelRequest; - msg->r.DelRequest.dn = ldb_dn_linearize(msg, req->op.del.dn); + msg->r.DelRequest.dn = ldb_dn_alloc_linearized(msg, req->op.del.dn); if (msg->r.DelRequest.dn == NULL) { talloc_free(msg); return LDB_ERR_INVALID_DN_SYNTAX; @@ -632,7 +632,7 @@ static int ildb_rename(struct ldb_module *module, struct ldb_request *req) } msg->type = LDAP_TAG_ModifyDNRequest; - msg->r.ModifyDNRequest.dn = ldb_dn_linearize(msg, req->op.rename.olddn); + msg->r.ModifyDNRequest.dn = ldb_dn_alloc_linearized(msg, req->op.rename.olddn); if (msg->r.ModifyDNRequest.dn == NULL) { talloc_free(msg); return LDB_ERR_INVALID_DN_SYNTAX; @@ -648,8 +648,7 @@ static int ildb_rename(struct ldb_module *module, struct ldb_request *req) } msg->r.ModifyDNRequest.newsuperior = - ldb_dn_linearize(msg, - ldb_dn_get_parent(msg, req->op.rename.newdn)); + ldb_dn_alloc_linearized(msg, ldb_dn_get_parent(msg, req->op.rename.newdn)); if (msg->r.ModifyDNRequest.newsuperior == NULL) { talloc_free(msg); return LDB_ERR_INVALID_DN_SYNTAX; -- cgit From ddfb73568aac22f7d98264fe5faec532f2500905 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 12 Dec 2006 16:56:53 +0000 Subject: r20120: fix the talloc hierachy and make ildb a child of module metze (This used to be commit b85d5cb7a4931d1d43a0ec73f1de1519c720f1af) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 41 ++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 567fe4bd5f..9a0157e517 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -54,6 +54,7 @@ struct ildb_private { struct ldap_connection *ldap; struct ldb_context *ldb; + struct ldb_module *module; }; struct ildb_context { @@ -738,20 +739,32 @@ static const struct ldb_module_ops ildb_ops = { */ static int ildb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[], - struct ldb_module **module) + struct ldb_module **_module) { - struct ildb_private *ildb = NULL; + struct ldb_module *module; + struct ildb_private *ildb; NTSTATUS status; struct cli_credentials *creds; - ildb = talloc(ldb, struct ildb_private); + 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->private_data = NULL; + module->ops = &ildb_ops; + + ildb = talloc(module, struct ildb_private); if (!ildb) { ldb_oom(ldb); goto failed; } - - ildb->ldb = ldb; - + module->private_data = ildb; + ildb->ldb = ldb; + ildb->module = module; ildb->ldap = ldap4_new_connection(ildb, ldb_get_opaque(ldb, "EventContext")); if (!ildb->ldap) { ldb_oom(ldb); @@ -769,19 +782,6 @@ static int ildb_connect(struct ldb_context *ldb, const char *url, goto failed; } - - *module = talloc(ldb, struct ldb_module); - if (!module) { - ldb_oom(ldb); - talloc_free(ildb); - return -1; - } - talloc_set_name_const(*module, "ldb_ildap backend"); - (*module)->ldb = ldb; - (*module)->prev = (*module)->next = NULL; - (*module)->private_data = ildb; - (*module)->ops = &ildb_ops; - /* caller can optionally setup credentials using the opaque token 'credentials' */ creds = talloc_get_type(ldb_get_opaque(ldb, "credentials"), struct cli_credentials); if (creds == NULL) { @@ -811,10 +811,11 @@ static int ildb_connect(struct ldb_context *ldb, const char *url, } } + *_module = module; return 0; failed: - talloc_free(ildb); + talloc_free(module); return -1; } -- cgit From e13088f2b79a408e8f73de6d7f55eeacffda11a2 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 12 Dec 2006 17:14:58 +0000 Subject: r20121: pass down the ldb_request struct to ildb_request_send(), also pass ildb instead of module, to avoid multiple talloc_get_type() calls metze (This used to be commit 03029d4fed86b1ca5fb19a408312607d8790d110) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 9a0157e517..90cad04a10 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -356,14 +356,9 @@ static struct ldb_handle *init_ildb_handle(struct ldb_module *module, return h; } -static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_reply *), - int timeout, - struct ldb_handle **handle) +static int ildb_request_send(struct ildb_private *ildb, struct ldap_message *msg, struct ldb_request *r) { - struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); - struct ldb_handle *h = init_ildb_handle(module, context, callback); + struct ldb_handle *h = init_ildb_handle(ildb->module, r->context, r->callback); struct ildb_context *ildb_ac; struct ldap_request *req; @@ -375,28 +370,28 @@ static int ildb_request_send(struct ldb_module *module, struct ldap_message *msg req = ldap_request_send(ildb->ldap, msg); if (req == NULL) { - ldb_set_errstring(module->ldb, "async send request failed"); + ldb_set_errstring(ildb->module->ldb, "async send request failed"); return LDB_ERR_OPERATIONS_ERROR; } if (!req->conn) { - ldb_set_errstring(module->ldb, "connection to remote LDAP server dropped?"); + ldb_set_errstring(ildb->module->ldb, "connection to remote LDAP server dropped?"); return LDB_ERR_OPERATIONS_ERROR; } talloc_free(req->time_event); req->time_event = NULL; - if (timeout) { + if (r->timeout) { req->time_event = event_add_timed(req->conn->event.event_ctx, h, - timeval_current_ofs(timeout, 0), + timeval_current_ofs(r->timeout, 0), ildb_request_timeout, h); } req->async.fn = ildb_callback; - req->async.private_data = (void *)h; + req->async.private_data = h; ildb_ac->req = talloc_move(ildb_ac, &req); - *handle = h; + r->handle = h; return LDB_SUCCESS; } @@ -478,7 +473,7 @@ static int ildb_search(struct ldb_module *module, struct ldb_request *req) msg->r.SearchRequest.attributes = discard_const(req->op.search.attrs); msg->controls = req->controls; - return ildb_request_send(module, msg, req->context, req->callback, req->timeout, &(req->handle)); + return ildb_request_send(ildb, msg, req); } /* @@ -528,7 +523,7 @@ static int ildb_add(struct ldb_module *module, struct ldb_request *req) msg->r.AddRequest.attributes[i] = mods[i]->attrib; } - return ildb_request_send(module, msg, req->context, req->callback, req->timeout, &(req->handle)); + return ildb_request_send(ildb, msg, req); } /* @@ -578,7 +573,7 @@ static int ildb_modify(struct ldb_module *module, struct ldb_request *req) msg->r.ModifyRequest.mods[i] = *mods[i]; } - return ildb_request_send(module, msg, req->context, req->callback, req->timeout, &(req->handle)); + return ildb_request_send(ildb, msg, req); } /* @@ -609,7 +604,7 @@ static int ildb_delete(struct ldb_module *module, struct ldb_request *req) return LDB_ERR_INVALID_DN_SYNTAX; } - return ildb_request_send(module, msg, req->context, req->callback, req->timeout, &(req->handle)); + return ildb_request_send(ildb, msg, req); } /* @@ -657,7 +652,7 @@ static int ildb_rename(struct ldb_module *module, struct ldb_request *req) msg->r.ModifyDNRequest.deleteolddn = True; - return ildb_request_send(module, msg, req->context, req->callback, req->timeout, &(req->handle)); + return ildb_request_send(ildb, msg, req); } static int ildb_start_trans(struct ldb_module *module) -- cgit From a2976633ffe5858cf1fc55afa57e2e7503fdc8ad Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 12 Dec 2006 17:20:38 +0000 Subject: r20122: pass ildb to ildb_request_noop() metze (This used to be commit cf9aade216930980bf47ea8b97db976c4907cbca) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 90cad04a10..7285bad00b 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -395,9 +395,9 @@ static int ildb_request_send(struct ildb_private *ildb, struct ldap_message *msg return LDB_SUCCESS; } -static int ildb_request_noop(struct ldb_module *module, struct ldb_request *req) +static int ildb_request_noop(struct ildb_private *ildb, struct ldb_request *req) { - struct ldb_handle *h = init_ildb_handle(module, req->context, req->callback); + struct ldb_handle *h = init_ildb_handle(ildb->module, req->context, req->callback); struct ildb_context *ildb_ac; int ret = LDB_SUCCESS; @@ -406,11 +406,11 @@ static int ildb_request_noop(struct ldb_module *module, struct ldb_request *req) } ildb_ac = talloc_get_type(h->private_data, struct ildb_context); - + req->handle = h; if (ildb_ac->callback) { - ret = ildb_ac->callback(module->ldb, ildb_ac->context, NULL); + ret = ildb_ac->callback(ildb->module->ldb, ildb_ac->context, NULL); } req->handle->state = LDB_ASYNC_DONE; return ret; @@ -490,7 +490,7 @@ static int ildb_add(struct ldb_module *module, struct ldb_request *req) /* ignore ltdb specials */ if (ldb_dn_is_special(req->op.add.message->dn)) { - return ildb_request_noop(module, req); + return ildb_request_noop(ildb, req); } msg = new_ldap_message(ildb->ldap); @@ -540,7 +540,7 @@ static int ildb_modify(struct ldb_module *module, struct ldb_request *req) /* ignore ltdb specials */ if (ldb_dn_is_special(req->op.mod.message->dn)) { - return ildb_request_noop(module, req); + return ildb_request_noop(ildb, req); } msg = new_ldap_message(ildb->ldap); @@ -588,7 +588,7 @@ static int ildb_delete(struct ldb_module *module, struct ldb_request *req) /* ignore ltdb specials */ if (ldb_dn_is_special(req->op.del.dn)) { - return ildb_request_noop(module, req); + return ildb_request_noop(ildb, req); } msg = new_ldap_message(ildb->ldap); @@ -619,7 +619,7 @@ static int ildb_rename(struct ldb_module *module, struct ldb_request *req) /* ignore ltdb specials */ if (ldb_dn_is_special(req->op.rename.olddn) || ldb_dn_is_special(req->op.rename.newdn)) { - return ildb_request_noop(module, req); + return ildb_request_noop(ildb, req); } msg = new_ldap_message(ildb->ldap); -- cgit From 21327c43201cfe96d7950bc19be041b924cad82f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 12 Dec 2006 17:37:41 +0000 Subject: r20123: - avoid some more talloc_get_type() calls - pass down ldb_request metze (This used to be commit b0b9e83fed0145bac6058d11e9b1b2c57d091649) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 52 ++++++++++++++++------------------- 1 file changed, 23 insertions(+), 29 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 7285bad00b..6028920e55 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -59,6 +59,8 @@ struct ildb_private { struct ildb_context { struct ldb_module *module; + struct ildb_private *ildb; + struct ldb_handle *handle; struct ldap_request *req; void *context; int (*callback)(struct ldb_context *, void *, struct ldb_reply *); @@ -321,53 +323,51 @@ static void ildb_callback(struct ldap_request *req) } } -static struct ldb_handle *init_ildb_handle(struct ldb_module *module, - void *context, - int (*callback)(struct ldb_context *, void *, struct ldb_reply *)) +static struct ildb_context *init_ildb_handle(struct ildb_private *ildb, + struct ldb_request *req) { - struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); struct ildb_context *ildb_ac; struct ldb_handle *h; h = talloc_zero(ildb->ldap, struct ldb_handle); if (h == NULL) { - ldb_set_errstring(module->ldb, "Out of Memory"); + ldb_set_errstring(ildb->module->ldb, "Out of Memory"); return NULL; } - h->module = module; + h->module = ildb->module; ildb_ac = talloc(h, struct ildb_context); if (ildb_ac == NULL) { - ldb_set_errstring(module->ldb, "Out of Memory"); + ldb_set_errstring(ildb->module->ldb, "Out of Memory"); talloc_free(h); return NULL; } - h->private_data = (void *)ildb_ac; + h->private_data = ildb_ac; h->state = LDB_ASYNC_INIT; h->status = LDB_SUCCESS; - ildb_ac->module = module; - ildb_ac->context = context; - ildb_ac->callback = callback; + ildb_ac->module = ildb->module; + ildb_ac->ildb = ildb; + ildb_ac->handle = h; + ildb_ac->context = req->context; + ildb_ac->callback = req->callback; - return h; + req->handle = h; + return ildb_ac; } static int ildb_request_send(struct ildb_private *ildb, struct ldap_message *msg, struct ldb_request *r) { - struct ldb_handle *h = init_ildb_handle(ildb->module, r->context, r->callback); - struct ildb_context *ildb_ac; + struct ildb_context *ildb_ac = init_ildb_handle(ildb, r); struct ldap_request *req; - if (!h) { + if (!ildb_ac) { return LDB_ERR_OPERATIONS_ERROR; } - ildb_ac = talloc_get_type(h->private_data, struct ildb_context); - req = ldap_request_send(ildb->ldap, msg); if (req == NULL) { ldb_set_errstring(ildb->module->ldb, "async send request failed"); @@ -382,37 +382,31 @@ static int ildb_request_send(struct ildb_private *ildb, struct ldap_message *msg talloc_free(req->time_event); req->time_event = NULL; if (r->timeout) { - req->time_event = event_add_timed(req->conn->event.event_ctx, h, + req->time_event = event_add_timed(req->conn->event.event_ctx, ildb_ac->handle, timeval_current_ofs(r->timeout, 0), - ildb_request_timeout, h); + ildb_request_timeout, ildb_ac->handle); } req->async.fn = ildb_callback; - req->async.private_data = h; + req->async.private_data = ildb_ac->handle; ildb_ac->req = talloc_move(ildb_ac, &req); - r->handle = h; return LDB_SUCCESS; } static int ildb_request_noop(struct ildb_private *ildb, struct ldb_request *req) { - struct ldb_handle *h = init_ildb_handle(ildb->module, req->context, req->callback); - struct ildb_context *ildb_ac; + struct ildb_context *ildb_ac = init_ildb_handle(ildb, req); int ret = LDB_SUCCESS; - if (!h) { + if (!ildb_ac) { return LDB_ERR_OPERATIONS_ERROR; } - ildb_ac = talloc_get_type(h->private_data, struct ildb_context); - - req->handle = h; - if (ildb_ac->callback) { ret = ildb_ac->callback(ildb->module->ldb, ildb_ac->context, NULL); } - req->handle->state = LDB_ASYNC_DONE; + ildb_ac->handle->state = LDB_ASYNC_DONE; return ret; } -- cgit From 2986313a68355069ee26b2a2527459e737d3bc29 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 12 Dec 2006 18:14:31 +0000 Subject: r20125: fix some ugly mem leaks in the ldb_ildb backend metze (This used to be commit db85b7840c1022665d410516d9a8989474d67a0f) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 6028920e55..2e45eef195 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -329,7 +329,7 @@ static struct ildb_context *init_ildb_handle(struct ildb_private *ildb, struct ildb_context *ildb_ac; struct ldb_handle *h; - h = talloc_zero(ildb->ldap, struct ldb_handle); + h = talloc_zero(req, struct ldb_handle); if (h == NULL) { ldb_set_errstring(ildb->module->ldb, "Out of Memory"); return NULL; @@ -373,6 +373,7 @@ static int ildb_request_send(struct ildb_private *ildb, struct ldap_message *msg ldb_set_errstring(ildb->module->ldb, "async send request failed"); return LDB_ERR_OPERATIONS_ERROR; } + ildb_ac->req = talloc_steal(ildb_ac, req); if (!req->conn) { ldb_set_errstring(ildb->module->ldb, "connection to remote LDAP server dropped?"); @@ -389,7 +390,6 @@ static int ildb_request_send(struct ildb_private *ildb, struct ldap_message *msg req->async.fn = ildb_callback; req->async.private_data = ildb_ac->handle; - ildb_ac->req = talloc_move(ildb_ac, &req); return LDB_SUCCESS; } @@ -431,7 +431,7 @@ static int ildb_search(struct ldb_module *module, struct ldb_request *req) return LDB_ERR_OPERATIONS_ERROR; } - msg = new_ldap_message(ildb); + msg = new_ldap_message(req); if (msg == NULL) { ldb_set_errstring(module->ldb, "Out of Memory"); return LDB_ERR_OPERATIONS_ERROR; @@ -487,7 +487,7 @@ static int ildb_add(struct ldb_module *module, struct ldb_request *req) return ildb_request_noop(ildb, req); } - msg = new_ldap_message(ildb->ldap); + msg = new_ldap_message(req); if (msg == NULL) { return LDB_ERR_OPERATIONS_ERROR; } @@ -537,7 +537,7 @@ static int ildb_modify(struct ldb_module *module, struct ldb_request *req) return ildb_request_noop(ildb, req); } - msg = new_ldap_message(ildb->ldap); + msg = new_ldap_message(req); if (msg == NULL) { return LDB_ERR_OPERATIONS_ERROR; } @@ -585,7 +585,7 @@ static int ildb_delete(struct ldb_module *module, struct ldb_request *req) return ildb_request_noop(ildb, req); } - msg = new_ldap_message(ildb->ldap); + msg = new_ldap_message(req); if (msg == NULL) { return LDB_ERR_OPERATIONS_ERROR; } @@ -616,7 +616,7 @@ static int ildb_rename(struct ldb_module *module, struct ldb_request *req) return ildb_request_noop(ildb, req); } - msg = new_ldap_message(ildb->ldap); + msg = new_ldap_message(req); if (msg == NULL) { return LDB_ERR_OPERATIONS_ERROR; } -- cgit From 8cdacd9f820aa06e0bde24f1ea8ccc7fdd83c031 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 12 Dec 2006 18:52:25 +0000 Subject: r20128: get rid of more talloc_get_type() calls metze (This used to be commit cb89f0b8d5a64433374887bcd44e04ad63e4857e) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 2e45eef195..4f30d2b1c1 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -138,8 +138,8 @@ static int ildb_map_error(struct ildb_private *ildb, NTSTATUS status) static void ildb_request_timeout(struct event_context *ev, struct timed_event *te, struct timeval t, void *private_data) { - struct ldb_handle *handle = talloc_get_type(private_data, struct ldb_handle); - struct ildb_context *ac = talloc_get_type(handle->private_data, struct ildb_context); + struct ildb_context *ac = talloc_get_type(private_data, struct ildb_context); + struct ldb_handle *handle = ac->handle; if (ac->req->state == LDAP_REQUEST_PENDING) { DLIST_REMOVE(ac->req->conn->pending, ac->req); @@ -152,9 +152,9 @@ static void ildb_request_timeout(struct event_context *ev, struct timed_event *t static void ildb_callback(struct ldap_request *req) { - struct ldb_handle *handle = talloc_get_type(req->async.private_data, struct ldb_handle); - struct ildb_context *ac = talloc_get_type(handle->private_data, struct ildb_context); - struct ildb_private *ildb = talloc_get_type(ac->module->private_data, struct ildb_private); + struct ildb_context *ac = talloc_get_type(req->async.private_data, struct ildb_context); + struct ldb_handle *handle = ac->handle; + struct ildb_private *ildb = ac->ildb; NTSTATUS status; int i; @@ -383,13 +383,13 @@ static int ildb_request_send(struct ildb_private *ildb, struct ldap_message *msg talloc_free(req->time_event); req->time_event = NULL; if (r->timeout) { - req->time_event = event_add_timed(req->conn->event.event_ctx, ildb_ac->handle, + req->time_event = event_add_timed(req->conn->event.event_ctx, ildb_ac, timeval_current_ofs(r->timeout, 0), - ildb_request_timeout, ildb_ac->handle); + ildb_request_timeout, ildb_ac); } req->async.fn = ildb_callback; - req->async.private_data = ildb_ac->handle; + req->async.private_data = ildb_ac; return LDB_SUCCESS; } -- cgit From 1a82770112c29069e85e0bddb4e6e0bb39d506fb Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 12 Dec 2006 18:58:21 +0000 Subject: r20129: remove unused structure elements metze (This used to be commit 53805a8562c59116e458dedd695e061eabf78620) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 4f30d2b1c1..bff54ded2d 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -53,12 +53,10 @@ struct ildb_private { struct ldap_connection *ldap; - struct ldb_context *ldb; struct ldb_module *module; }; struct ildb_context { - struct ldb_module *module; struct ildb_private *ildb; struct ldb_handle *handle; struct ldap_request *req; @@ -128,7 +126,7 @@ static int ildb_map_error(struct ildb_private *ildb, NTSTATUS status) if (NT_STATUS_IS_OK(status)) { return LDB_SUCCESS; } - ldb_set_errstring(ildb->ldb, ldap_errstr(ildb->ldap, status)); + ldb_set_errstring(ildb->module->ldb, ldap_errstr(ildb->ldap, status)); if (NT_STATUS_IS_LDAP(status)) { return NT_STATUS_LDAP_CODE(status); } @@ -181,7 +179,7 @@ static void ildb_callback(struct ldap_request *req) handle->status = ildb_map_error(ildb, status); if (ac->callback && handle->status == LDB_SUCCESS) { /* FIXME: build a corresponding ares to pass on */ - handle->status = ac->callback(ac->module->ldb, ac->context, NULL); + handle->status = ac->callback(ac->ildb->module->ldb, ac->context, NULL); } handle->state = LDB_ASYNC_DONE; break; @@ -195,7 +193,7 @@ static void ildb_callback(struct ldap_request *req) handle->status = ildb_map_error(ildb, status); if (ac->callback && handle->status == LDB_SUCCESS) { /* FIXME: build a corresponding ares to pass on */ - handle->status = ac->callback(ac->module->ldb, ac->context, NULL); + handle->status = ac->callback(ac->ildb->module->ldb, ac->context, NULL); } handle->state = LDB_ASYNC_DONE; break; @@ -209,7 +207,7 @@ static void ildb_callback(struct ldap_request *req) handle->status = ildb_map_error(ildb, status); if (ac->callback && handle->status == LDB_SUCCESS) { /* FIXME: build a corresponding ares to pass on */ - handle->status = ac->callback(ac->module->ldb, ac->context, NULL); + handle->status = ac->callback(ac->ildb->module->ldb, ac->context, NULL); } handle->state = LDB_ASYNC_DONE; break; @@ -223,7 +221,7 @@ static void ildb_callback(struct ldap_request *req) handle->status = ildb_map_error(ildb, status); if (ac->callback && handle->status == LDB_SUCCESS) { /* FIXME: build a corresponding ares to pass on */ - handle->status = ac->callback(ac->module->ldb, ac->context, NULL); + handle->status = ac->callback(ac->ildb->module->ldb, ac->context, NULL); } handle->state = LDB_ASYNC_DONE; break; @@ -256,7 +254,7 @@ static void ildb_callback(struct ldap_request *req) ares->controls = talloc_move(ares, &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(ac->ildb->module->ldb, msg->r.SearchResultDone.errormessage); } } @@ -276,7 +274,7 @@ static void ildb_callback(struct ldap_request *req) search = &(msg->r.SearchResultEntry); - ares->message->dn = ldb_dn_new(ares->message, ac->module->ldb, search->dn); + ares->message->dn = ldb_dn_new(ares->message, ac->ildb->module->ldb, search->dn); if ( ! ldb_dn_validate(ares->message->dn)) { handle->status = LDB_ERR_OPERATIONS_ERROR; return; @@ -305,7 +303,7 @@ static void ildb_callback(struct ldap_request *req) return; } - ret = ac->callback(ac->module->ldb, ac->context, ares); + ret = ac->callback(ac->ildb->module->ldb, ac->context, ares); if (ret) { handle->status = ret; } @@ -349,7 +347,6 @@ static struct ildb_context *init_ildb_handle(struct ildb_private *ildb, h->state = LDB_ASYNC_INIT; h->status = LDB_SUCCESS; - ildb_ac->module = ildb->module; ildb_ac->ildb = ildb; ildb_ac->handle = h; ildb_ac->context = req->context; @@ -752,7 +749,6 @@ static int ildb_connect(struct ldb_context *ldb, const char *url, goto failed; } module->private_data = ildb; - ildb->ldb = ldb; ildb->module = module; ildb->ldap = ldap4_new_connection(ildb, ldb_get_opaque(ldb, "EventContext")); if (!ildb->ldap) { -- cgit From 3370f2f2d7e5296e8f54f721003c07fac111d1ad Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 8 Mar 2007 06:23:39 +0000 Subject: r21761: - Give more detail on LDAP client library failures (make it clear where the error is from) - Make default error string more consistant Andrew Bartlett (This used to be commit 7f115579d20a3112efd11444fafcbf78698fc9a1) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index bff54ded2d..f5642f8303 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -123,10 +123,16 @@ failed: */ static int ildb_map_error(struct ildb_private *ildb, NTSTATUS status) { + TALLOC_CTX *mem_ctx = talloc_new(ildb); if (NT_STATUS_IS_OK(status)) { return LDB_SUCCESS; } - ldb_set_errstring(ildb->module->ldb, ldap_errstr(ildb->ldap, status)); + if (!mem_ctx) { + ldb_oom(ildb->module->ldb); + return LDB_ERR_OPERATIONS_ERROR; + } + ldb_set_errstring(ildb->module->ldb, ldap_errstr(ildb->ldap, mem_ctx, status)); + talloc_free(mem_ctx); if (NT_STATUS_IS_LDAP(status)) { return NT_STATUS_LDAP_CODE(status); } @@ -763,7 +769,7 @@ static int ildb_connect(struct ldb_context *ldb, const char *url, status = ldap_connect(ildb->ldap, url); if (!NT_STATUS_IS_OK(status)) { ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to connect to ldap URL '%s' - %s\n", - url, ldap_errstr(ildb->ldap, status)); + url, ldap_errstr(ildb->ldap, module, status)); goto failed; } @@ -783,14 +789,14 @@ static int ildb_connect(struct ldb_context *ldb, const char *url, status = ldap_bind_simple(ildb->ldap, bind_dn, password); if (!NT_STATUS_IS_OK(status)) { ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to bind - %s\n", - ldap_errstr(ildb->ldap, status)); + ldap_errstr(ildb->ldap, module, status)); goto failed; } } else { status = ldap_bind_sasl(ildb->ldap, creds); if (!NT_STATUS_IS_OK(status)) { ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to bind - %s\n", - ldap_errstr(ildb->ldap, status)); + ldap_errstr(ildb->ldap, module, status)); goto failed; } } -- cgit From 52fb06edc25e8538c413df1aaabba18c859a00cf Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 5 May 2007 18:50:56 +0000 Subject: r22681: Fix standalone ldb build when parent directory name != ldb. (This used to be commit 1093875d59f1ea9b8bd82277d4f9d8366e584952) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index f5642f8303..cf380303bc 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -43,7 +43,7 @@ #include "includes.h" -#include "ldb/include/includes.h" +#include "ldb_includes.h" #include "lib/events/events.h" #include "libcli/ldap/ldap.h" -- cgit From b8d69a7ea2505b706ff7c74d7c97bc89d82dfa07 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:46:15 +0000 Subject: r23795: more v2->v3 conversion (This used to be commit 84b468b2f8f2dffda89593f816e8bc6a8b6d42ac) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index cf380303bc..f9d229b9f2 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -11,7 +11,7 @@ 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 2 of the License, or (at your option) any later version. + 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 -- cgit From 6c973f4e8ccbcb6c9275f8a54e26abb19df7e15a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 03:42:26 +0000 Subject: r23798: updated old Temple Place FSF addresses to new URL (This used to be commit 40c0919aaa9c1b14bbaebb95ecce53eb0380fdbb) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index f9d229b9f2..440686c65e 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -19,8 +19,7 @@ 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, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + License along with this library; if not, see . */ /* -- cgit From 719a4ae0d32ab9ba817fd01f2b8f4cba220a8c60 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 5 Oct 2007 18:03:01 +0000 Subject: r25522: Convert to standard bool types. (This used to be commit 5e814287ba475e12f8cc934fdd09b199dcdfdb86) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 440686c65e..7b9023958c 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -646,7 +646,7 @@ static int ildb_rename(struct ldb_module *module, struct ldb_request *req) return LDB_ERR_INVALID_DN_SYNTAX; } - msg->r.ModifyDNRequest.deleteolddn = True; + msg->r.ModifyDNRequest.deleteolddn = true; return ildb_request_send(ildb, msg, req); } -- cgit From a72c5053c587f0ed6113ef514fe3739cb81e7abf Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Dec 2007 23:32:43 +0100 Subject: r26353: Remove use of global_loadparm. (This used to be commit 17637e4490e42db6cdef619286c4d5a0982e9d1a) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 7b9023958c..0c0ee629bf 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -49,6 +49,7 @@ #include "libcli/ldap/ldap_client.h" #include "auth/auth.h" #include "auth/credentials/credentials.h" +#include "param/param.h" struct ildb_private { struct ldap_connection *ldap; @@ -792,7 +793,7 @@ static int ildb_connect(struct ldb_context *ldb, const char *url, goto failed; } } else { - status = ldap_bind_sasl(ildb->ldap, creds); + status = ldap_bind_sasl(ildb->ldap, creds, global_loadparm); if (!NT_STATUS_IS_OK(status)) { ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to bind - %s\n", ldap_errstr(ildb->ldap, module, status)); -- cgit From b65dba2245bf382c47d65c95ac9b1efa43918fc0 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 10 Dec 2007 04:33:16 +0100 Subject: r26355: Eliminate global_loadparm in more places. (This used to be commit 5d589a0d94bd76a9b4c9fc748854e8098ea43c4d) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 0c0ee629bf..a834e912d4 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -756,7 +756,8 @@ static int ildb_connect(struct ldb_context *ldb, const char *url, } module->private_data = ildb; ildb->module = module; - ildb->ldap = ldap4_new_connection(ildb, ldb_get_opaque(ldb, "EventContext")); + ildb->ldap = ldap4_new_connection(ildb, ldb_get_opaque(ldb, "loadparm"), + ldb_get_opaque(ldb, "EventContext")); if (!ildb->ldap) { ldb_oom(ldb); goto failed; @@ -793,7 +794,7 @@ static int ildb_connect(struct ldb_context *ldb, const char *url, goto failed; } } else { - status = ldap_bind_sasl(ildb->ldap, creds, global_loadparm); + status = ldap_bind_sasl(ildb->ldap, creds, ldb_get_opaque(ldb, "loadparm")); if (!NT_STATUS_IS_OK(status)) { ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to bind - %s\n", ldap_errstr(ildb->ldap, module, status)); -- cgit From e3661a6181a7fbeffb02745adda509c01779d5ca Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 20 Feb 2008 01:56:55 +0100 Subject: Use function-based initialization for ildap backend. (This used to be commit 46e5027f56722fbe19af36aad1ab03ea1c862f43) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index a834e912d4..8ad6830c43 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -811,9 +811,6 @@ failed: return -1; } -int ldb_ildap_init(void) -{ - return ldb_register_backend("ldap", ildb_connect) + - ldb_register_backend("ldapi", ildb_connect) + - ldb_register_backend("ldaps", ildb_connect); -} +ldb_connect_fn ldb_ldap_connect = ildb_connect; +ldb_connect_fn ldb_ldapi_connect = ildb_connect; +ldb_connect_fn ldb_ldaps_connect = ildb_connect; -- cgit From 995788536e5ba7b3a0e67e377a9769b279d0b8ae Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 20 Feb 2008 02:57:07 +0100 Subject: Remove more function-based inits. (This used to be commit b1a7810f3e70f9a831d9b8e85d531e448072adaf) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 8ad6830c43..fb7100e3c1 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -811,6 +811,18 @@ failed: return -1; } -ldb_connect_fn ldb_ldap_connect = ildb_connect; -ldb_connect_fn ldb_ldapi_connect = ildb_connect; -ldb_connect_fn ldb_ldaps_connect = ildb_connect; +const struct ldb_backend_ops ldb_ldap_backend_ops { + .name = "ldap", + .connect_fn = ildb_connect +}; + +const struct ldb_backend_ops ldb_ildap_backend_ops { + .name = "ildap", + .connect_fn = ildb_connect +}; + +const struct ldb_backend_ops ldb_ldaps_backend_ops { + .name = "ldaps", + .connect_fn = ildb_connect +}; + -- cgit From 39a817d310964f8e9a63cfb096b3ad24fa03bd5e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 20 Feb 2008 04:33:43 +0100 Subject: Fix use of some modules (needed _PUBLIC_). (This used to be commit ce332130ea77159832da23bab760fa26921719e2) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index fb7100e3c1..995b584f51 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -811,17 +811,17 @@ failed: return -1; } -const struct ldb_backend_ops ldb_ldap_backend_ops { +_PUBLIC_ const struct ldb_backend_ops ldb_ldap_backend_ops = { .name = "ldap", .connect_fn = ildb_connect }; -const struct ldb_backend_ops ldb_ildap_backend_ops { +_PUBLIC_ const struct ldb_backend_ops ldb_ildap_backend_ops = { .name = "ildap", .connect_fn = ildb_connect }; -const struct ldb_backend_ops ldb_ldaps_backend_ops { +_PUBLIC_ const struct ldb_backend_ops ldb_ldaps_backend_ops = { .name = "ldaps", .connect_fn = ildb_connect }; -- cgit From 836ec12b55ebb30b986b127e16341383e24e9331 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 29 Feb 2008 01:06:05 +0100 Subject: Fix ldapi support. (This used to be commit 9499f8eea534cf93f96af17941e9195aadc0a756) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 995b584f51..79958a86eb 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -816,8 +816,8 @@ _PUBLIC_ const struct ldb_backend_ops ldb_ldap_backend_ops = { .connect_fn = ildb_connect }; -_PUBLIC_ const struct ldb_backend_ops ldb_ildap_backend_ops = { - .name = "ildap", +_PUBLIC_ const struct ldb_backend_ops ldb_ldapi_backend_ops = { + .name = "ldapi", .connect_fn = ildb_connect }; -- cgit From 4e83011f72ba3df387512755a17760b42a7bf2f2 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 21 Apr 2008 17:58:23 -0400 Subject: Remove more event_context_init() uses from function calls within deep down the code. Make sure we pass around the event_context where we need it instead. All test but a few python ones fail. Jelmer promised to fix them. (This used to be commit 3045d391626fba169aa26be52174883e18d323e9) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 79958a86eb..6b50b2f5eb 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -737,6 +737,7 @@ static int ildb_connect(struct ldb_context *ldb, const char *url, struct ildb_private *ildb; NTSTATUS status; struct cli_credentials *creds; + struct event_context *event_ctx; module = talloc(ldb, struct ldb_module); if (!module) { @@ -756,8 +757,19 @@ static int ildb_connect(struct ldb_context *ldb, const char *url, } module->private_data = ildb; ildb->module = module; - ildb->ldap = ldap4_new_connection(ildb, ldb_get_opaque(ldb, "loadparm"), - ldb_get_opaque(ldb, "EventContext")); + + event_ctx = ldb_get_opaque(ldb, "EventContext"); + + /* FIXME: We must make the event context an explicit parameter, but we + * need to build the events library separately first. Hack a new event + * context so that CMD line utilities work until we have libevents for + * standalone builds ready */ + if (event_ctx == NULL) { + event_ctx = event_context_init(NULL); + } + + ildb->ldap = ldap4_new_connection(ildb, ldb_get_opaque(ldb, "loadparm"), + event_ctx); if (!ildb->ldap) { ldb_oom(ldb); goto failed; -- cgit From 2daf2897d5c70c0efbeba9b827c62700b9a9537c Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 14 Jun 2008 13:00:53 -0400 Subject: Use a custom init function for samba4 that sets a samba4 specific debug function. By default do not debug, this is the most appropriate action for a library as we cannot assume what stderr is use for in the main app. The main app is responsible to set ev_debug_stderr if they so desire. (This used to be commit e566a2f308ac6fb4b526a744f7059b565670aea5) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 6b50b2f5eb..478df3662d 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -758,12 +758,12 @@ static int ildb_connect(struct ldb_context *ldb, const char *url, module->private_data = ildb; ildb->module = module; - event_ctx = ldb_get_opaque(ldb, "EventContext"); + event_ctx = ldb_get_event_context(ldb); /* FIXME: We must make the event context an explicit parameter, but we * need to build the events library separately first. Hack a new event - * context so that CMD line utilities work until we have libevents for - * standalone builds ready */ + * context so that CMD line utilities work until we have them all + * converted */ if (event_ctx == NULL) { event_ctx = event_context_init(NULL); } -- cgit From 1a7823823eab04baacee140ebd45b380dcee9cef Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 15 Jun 2008 11:11:14 -0400 Subject: Now that we pass down the event context, start removing calls to event_context_init() where possible (This used to be commit 412f7a98dd809306ac9f35003fce554e1e1252e7) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index 478df3662d..d1677032f0 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -760,14 +760,6 @@ static int ildb_connect(struct ldb_context *ldb, const char *url, event_ctx = ldb_get_event_context(ldb); - /* FIXME: We must make the event context an explicit parameter, but we - * need to build the events library separately first. Hack a new event - * context so that CMD line utilities work until we have them all - * converted */ - if (event_ctx == NULL) { - event_ctx = event_context_init(NULL); - } - ildb->ldap = ldap4_new_connection(ildb, ldb_get_opaque(ldb, "loadparm"), event_ctx); if (!ildb->ldap) { -- cgit From 5aec74c676c6cfd60ebf590a1b0a6d1000b8e33a Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 15 Jun 2008 11:15:12 -0400 Subject: Cleanup. Remove trailing spaces and try to fit 80 column where possible. (This used to be commit b32a040c2f0eb28d68837bde727437ca118d1b18) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 52 +++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 23 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index d1677032f0..f0a34b6223 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -1,13 +1,13 @@ -/* +/* ldb database library - ildap backend Copyright (C) Andrew Tridgell 2005 - Copyright (C) Simo Sorce 2006 + 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 @@ -69,7 +69,8 @@ struct ildb_context { ready for ildap_add() or ildap_modify() */ static struct ldap_mod **ildb_msg_to_mods(void *mem_ctx, int *num_mods, - const struct ldb_message *msg, int use_flags) + const struct ldb_message *msg, + int use_flags) { struct ldap_mod **mods; unsigned int i; @@ -131,7 +132,8 @@ static int ildb_map_error(struct ildb_private *ildb, NTSTATUS status) ldb_oom(ildb->module->ldb); return LDB_ERR_OPERATIONS_ERROR; } - ldb_set_errstring(ildb->module->ldb, ldap_errstr(ildb->ldap, mem_ctx, status)); + ldb_set_errstring(ildb->module->ldb, + ldap_errstr(ildb->ldap, mem_ctx, status)); talloc_free(mem_ctx); if (NT_STATUS_IS_LDAP(status)) { return NT_STATUS_LDAP_CODE(status); @@ -139,12 +141,15 @@ static int ildb_map_error(struct ildb_private *ildb, NTSTATUS status) return LDB_ERR_OPERATIONS_ERROR; } -static void ildb_request_timeout(struct event_context *ev, struct timed_event *te, +static void ildb_request_timeout(struct event_context *ev, + struct timed_event *te, struct timeval t, void *private_data) { - struct ildb_context *ac = talloc_get_type(private_data, struct ildb_context); + struct ildb_context *ac; struct ldb_handle *handle = ac->handle; + ac = talloc_get_type(private_data, struct ildb_context); + if (ac->req->state == LDAP_REQUEST_PENDING) { DLIST_REMOVE(ac->req->conn->pending, ac->req); } @@ -156,12 +161,13 @@ static void ildb_request_timeout(struct event_context *ev, struct timed_event *t static void ildb_callback(struct ldap_request *req) { - struct ildb_context *ac = talloc_get_type(req->async.private_data, struct ildb_context); + struct ildb_context *ac; struct ldb_handle *handle = ac->handle; struct ildb_private *ildb = ac->ildb; NTSTATUS status; int i; + ac =talloc_get_type(req->async.private_data, struct ildb_context); handle->status = LDB_SUCCESS; if (!NT_STATUS_IS_OK(req->status)) { @@ -172,8 +178,8 @@ static void ildb_callback(struct ldap_request *req) if (req->num_replies < 1) { handle->status = LDB_ERR_OPERATIONS_ERROR; return; - } - + } + switch (req->type) { case LDAP_TAG_ModifyRequest: @@ -256,7 +262,7 @@ static void ildb_callback(struct ldap_request *req) handle->status = ildb_map_error(ildb, status); return; } - + ares->controls = talloc_move(ares, &msg->controls); if (msg->r.SearchResultDone.resultcode) { if (msg->r.SearchResultDone.errormessage) { @@ -279,7 +285,7 @@ static void ildb_callback(struct ldap_request *req) } search = &(msg->r.SearchResultEntry); - + ares->message->dn = ldb_dn_new(ares->message, ac->ildb->module->ldb, search->dn); if ( ! ldb_dn_validate(ares->message->dn)) { handle->status = LDB_ERR_OPERATIONS_ERROR; @@ -297,7 +303,7 @@ static void ildb_callback(struct ldap_request *req) case LDAP_TAG_SearchResultReference: ares->referral = talloc_strdup(ares, msg->r.SearchResultReference.referral); - + handle->status = LDB_SUCCESS; handle->state = LDB_ASYNC_PENDING; ares->type = LDB_REPLY_REFERRAL; @@ -320,7 +326,7 @@ static void ildb_callback(struct ldap_request *req) req->num_replies = 0; break; - + default: handle->status = LDB_ERR_PROTOCOL_ERROR; return; @@ -368,7 +374,7 @@ static int ildb_request_send(struct ildb_private *ildb, struct ldap_message *msg struct ldap_request *req; if (!ildb_ac) { - return LDB_ERR_OPERATIONS_ERROR; + return LDB_ERR_OPERATIONS_ERROR; } req = ldap_request_send(ildb->ldap, msg); @@ -403,7 +409,7 @@ static int ildb_request_noop(struct ildb_private *ildb, struct ldb_request *req) int ret = LDB_SUCCESS; if (!ildb_ac) { - return LDB_ERR_OPERATIONS_ERROR; + return LDB_ERR_OPERATIONS_ERROR; } if (ildb_ac->callback) { @@ -428,7 +434,7 @@ static int ildb_search(struct ldb_module *module, struct ldb_request *req) ldb_set_errstring(module->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"); return LDB_ERR_OPERATIONS_ERROR; @@ -458,13 +464,13 @@ static int ildb_search(struct ldb_module *module, struct ldb_request *req) } else { msg->r.SearchRequest.scope = req->op.search.scope; } - + msg->r.SearchRequest.deref = LDAP_DEREFERENCE_NEVER; msg->r.SearchRequest.timelimit = 0; msg->r.SearchRequest.sizelimit = 0; msg->r.SearchRequest.attributesonly = 0; msg->r.SearchRequest.tree = discard_const(req->op.search.tree); - + for (n = 0; req->op.search.attrs && req->op.search.attrs[n]; n++) /* noop */ ; msg->r.SearchRequest.num_attributes = n; msg->r.SearchRequest.attributes = discard_const(req->op.search.attrs); @@ -594,7 +600,7 @@ static int ildb_delete(struct ldb_module *module, struct ldb_request *req) } msg->type = LDAP_TAG_DelRequest; - + msg->r.DelRequest.dn = ldb_dn_alloc_linearized(msg, req->op.del.dn); if (msg->r.DelRequest.dn == NULL) { talloc_free(msg); @@ -631,7 +637,7 @@ static int ildb_rename(struct ldb_module *module, struct ldb_request *req) return LDB_ERR_INVALID_DN_SYNTAX; } - msg->r.ModifyDNRequest.newrdn = + msg->r.ModifyDNRequest.newrdn = talloc_asprintf(msg, "%s=%s", ldb_dn_get_rdn_name(req->op.rename.newdn), ldb_dn_escape_value(msg, *ldb_dn_get_rdn_val(req->op.rename.newdn))); @@ -708,7 +714,7 @@ static int ildb_wait(struct ldb_handle *handle, enum ldb_wait_type type) default: return LDB_ERR_OPERATIONS_ERROR; } - + return handle->status; } @@ -729,7 +735,7 @@ static const struct ldb_module_ops ildb_ops = { /* connect to the database */ -static int ildb_connect(struct ldb_context *ldb, const char *url, +static int ildb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[], struct ldb_module **_module) { -- cgit From 78d9e9be0c170360f8ef926bce4c4233798aae28 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 15 Jun 2008 11:15:12 -0400 Subject: Fix cleanup. (This used to be commit acbe365e34571218fe312f52edec98f4fe5b76be) --- source4/lib/ldb/ldb_ildap/ldb_ildap.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source4/lib/ldb/ldb_ildap/ldb_ildap.c') diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c index f0a34b6223..5ad671ea2e 100644 --- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c +++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c @@ -146,7 +146,10 @@ static void ildb_request_timeout(struct event_context *ev, struct timeval t, void *private_data) { struct ildb_context *ac; - struct ldb_handle *handle = ac->handle; + struct ldb_handle *handle; + + ac = talloc_get_type(private_data, struct ildb_context); + handle = ac->handle; ac = talloc_get_type(private_data, struct ildb_context); @@ -162,12 +165,14 @@ static void ildb_request_timeout(struct event_context *ev, static void ildb_callback(struct ldap_request *req) { struct ildb_context *ac; - struct ldb_handle *handle = ac->handle; - struct ildb_private *ildb = ac->ildb; + struct ldb_handle *handle; + struct ildb_private *ildb; NTSTATUS status; int i; - ac =talloc_get_type(req->async.private_data, struct ildb_context); + ac = talloc_get_type(req->async.private_data, struct ildb_context); + ildb = ac->ildb; + handle = ac->handle; handle->status = LDB_SUCCESS; if (!NT_STATUS_IS_OK(req->status)) { -- cgit