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
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 <http://www.gnu.org/licenses/>.
*/
/*
* Author: Andrew Tridgell
*/
-#include "includes.h"
-#include "ldb/include/includes.h"
+#include "ldb_includes.h"
/*
initialise a ldb context
ldb_set_utf8_default(ldb);
ldb_set_create_perms(ldb, 0666);
+ ldb_set_modules_dir(ldb, LDB_MODULESDIR);
return ldb;
}
-static struct ldb_backend {
+struct ldb_backend {
const char *name;
ldb_connect_fn connect_fn;
struct ldb_backend *prev, *next;
fn = ldb_find_backend(backend);
if (fn == NULL) {
- if (ldb_try_load_dso(ldb, backend) == 0) {
+ int (*init_fn) (void);
+
+ init_fn = ldb_dso_load_symbol(ldb, backend,
+ "init_module");
+ if (init_fn != NULL && init_fn() == 0) {
fn = ldb_find_backend(backend);
}
}
int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[])
{
int ret;
-
+ const char *url2;
/* We seem to need to do this here, or else some utilities don't get ldb backends */
ldb_global_init();
ldb->flags = flags;
+ url2 = talloc_strdup(ldb, url);
+ if (!url2) {
+ ldb_oom(ldb);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+ ret = ldb_set_opaque(ldb, "ldb_url", talloc_strdup(ldb, url2));
+ if (ret != LDB_SUCCESS) {
+ return ret;
+ }
+
ret = ldb_connect_backend(ldb, url, options, &ldb->modules);
if (ret != LDB_SUCCESS) {
return ret;
void ldb_asprintf_errstring(struct ldb_context *ldb, const char *format, ...)
{
va_list ap;
+ char *old_string = NULL;
if (ldb->err_string) {
- talloc_free(ldb->err_string);
+ old_string = ldb->err_string;
}
va_start(ap, format);
ldb->err_string = talloc_vasprintf(ldb, format, ap);
va_end(ap);
+ talloc_free(old_string);
}
void ldb_reset_err_string(struct ldb_context *ldb)
int ldb_wait(struct ldb_handle *handle, enum ldb_wait_type type)
{
+ int ret;
if (!handle) {
return LDB_SUCCESS;
}
- return handle->module->ops->wait(handle, type);
+ ret = handle->module->ops->wait(handle, type);
+ if (!ldb_errstring(handle->module->ldb)) {
+ /* Set a default error string, to place the blame somewhere */
+ ldb_asprintf_errstring(handle->module->ldb, "error waiting on module %s: %s (%d)", handle->module->ops->name, ldb_strerror(ret), ret);
+ }
+ return ret;
}
/* set the specified timeout or, if timeout is 0 set the default timeout */
if (ret == LDB_SUCCESS) {
talloc_steal(mem_ctx, res);
*result = res;
- } else {
- talloc_free(res);
}
talloc_free(expression);