summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/lib/events/events_aio.c6
-rw-r--r--source4/lib/ldb/common/ldb.c231
-rw-r--r--source4/lib/ldb/ldb_ildap/ldb_ildap.c60
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.c149
4 files changed, 263 insertions, 183 deletions
diff --git a/source4/lib/events/events_aio.c b/source4/lib/events/events_aio.c
index 9d13ea96fd..933ce26bf6 100644
--- a/source4/lib/events/events_aio.c
+++ b/source4/lib/events/events_aio.c
@@ -31,7 +31,7 @@
*/
#include "system/filesys.h"
-#include "system/network.h"
+#include "replace.h"
#include "events.h"
#include "events_internal.h"
#include <sys/epoll.h>
@@ -138,7 +138,7 @@ static void epoll_add_event(struct aio_event_context *aio_ev, struct fd_event *f
/* if we don't want events yet, don't add an aio_event */
if (fde->flags == 0) return;
- ZERO_STRUCT(event);
+ memset(&event, 0, sizeof(event));
event.events = epoll_map_flags(fde->flags);
event.data.ptr = fde;
epoll_ctl(aio_ev->epoll_fd, EPOLL_CTL_ADD, fde->fd, &event);
@@ -479,7 +479,7 @@ static int aio_event_loop_once(struct event_context *ev)
struct timeval tval;
tval = common_event_loop_timer_delay(ev);
- if (timeval_is_zero(&tval)) {
+ if (ev_timeval_is_zero(&tval)) {
return 0;
}
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c
index bfce12bdd3..22cd46d13f 100644
--- a/source4/lib/ldb/common/ldb.c
+++ b/source4/lib/ldb/common/ldb.c
@@ -45,6 +45,8 @@ struct ldb_context *ldb_init(TALLOC_CTX *mem_ctx, struct event_context *ev_ctx)
int ret;
ldb = talloc_zero(mem_ctx, struct ldb_context);
+ /* FIXME: Hack a new event context so that CMD line utilities work
+ * until we have them all converted */
if (ev_ctx == NULL) {
ev_ctx = event_context_init(ldb);
}
@@ -71,7 +73,7 @@ static struct backends_list_entry {
struct backends_list_entry *prev, *next;
} *ldb_backends = NULL;
-#ifndef STATIC_LIBLDB_BACKENDS
+#ifndef STATIC_LIBLDB_BACKENDS
#ifdef HAVE_LDB_LDAP
#define LDAP_INIT &ldb_ldap_backend_ops, \
@@ -104,12 +106,14 @@ static ldb_connect_fn ldb_find_backend(const char *url)
int i;
for (i = 0; builtin_backends[i]; i++) {
- if (strncmp(builtin_backends[i]->name, url, strlen(builtin_backends[i]->name)) == 0)
+ if (strncmp(builtin_backends[i]->name, url,
+ strlen(builtin_backends[i]->name)) == 0)
return builtin_backends[i]->connect_fn;
}
for (backend = ldb_backends; backend; backend = backend->next) {
- if (strncmp(backend->ops->name, url, strlen(backend->ops->name)) == 0) {
+ if (strncmp(backend->ops->name, url,
+ strlen(backend->ops->name)) == 0) {
return backend->ops->connect_fn;
}
}
@@ -122,8 +126,17 @@ static ldb_connect_fn ldb_find_backend(const char *url)
*/
int ldb_register_backend(const char *url_prefix, ldb_connect_fn connectfn)
{
- struct ldb_backend_ops *backend = talloc(talloc_autofree_context(), struct ldb_backend_ops);
- struct backends_list_entry *entry = talloc(talloc_autofree_context(), struct backends_list_entry);
+ struct ldb_backend_ops *backend;
+ struct backends_list_entry *entry;
+
+ backend = talloc(talloc_autofree_context(), struct ldb_backend_ops);
+ if (!backend) return LDB_ERR_OPERATIONS_ERROR;
+
+ entry = talloc(talloc_autofree_context(), struct backends_list_entry);
+ if (!entry) {
+ talloc_free(backend);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
if (ldb_find_backend(url_prefix)) {
return LDB_SUCCESS;
@@ -139,8 +152,9 @@ int ldb_register_backend(const char *url_prefix, ldb_connect_fn connectfn)
return LDB_SUCCESS;
}
-/*
- Return the ldb module form of a database. The URL can either be one of the following forms
+/*
+ Return the ldb module form of a database.
+ The URL can either be one of the following forms
ldb://path
ldapi://path
@@ -149,10 +163,12 @@ int ldb_register_backend(const char *url_prefix, ldb_connect_fn connectfn)
the options are passed uninterpreted to the backend, and are
backend specific.
- This allows modules to get at only the backend module, for example where a module
- may wish to direct certain requests at a particular backend.
+ This allows modules to get at only the backend module, for example where a
+ module may wish to direct certain requests at a particular backend.
*/
-int ldb_connect_backend(struct ldb_context *ldb, const char *url, const char *options[],
+int ldb_connect_backend(struct ldb_context *ldb,
+ const char *url,
+ const char *options[],
struct ldb_module **backend_module)
{
int ret;
@@ -194,14 +210,16 @@ int ldb_connect_backend(struct ldb_context *ldb, const char *url, const char *op
talloc_free(backend);
if (fn == NULL) {
- ldb_debug(ldb, LDB_DEBUG_FATAL, "Unable to find backend for '%s'\n", url);
+ ldb_debug(ldb, LDB_DEBUG_FATAL,
+ "Unable to find backend for '%s'\n", url);
return LDB_ERR_OTHER;
}
ret = fn(ldb, url, ldb->flags, options, backend_module);
if (ret != LDB_SUCCESS) {
- ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to connect to '%s'\n", url);
+ ldb_debug(ldb, LDB_DEBUG_ERROR,
+ "Failed to connect to '%s'\n", url);
return ret;
}
return ret;
@@ -227,58 +245,72 @@ void ldb_set_default_dns(struct ldb_context *ldb)
};
tmp_ctx = talloc_new(ldb);
- ret = ldb_search(ldb, ldb_dn_new(tmp_ctx, ldb, NULL), LDB_SCOPE_BASE,
+ ret = ldb_search(ldb, ldb_dn_new(tmp_ctx, ldb, NULL), LDB_SCOPE_BASE,
"(objectClass=*)", attrs, &res);
- if (ret == LDB_SUCCESS) {
- if (res->count == 1) {
- if (!ldb_get_opaque(ldb, "rootDomainNamingContext")) {
- tmp_dn = ldb_msg_find_attr_as_dn(ldb, ldb, res->msgs[0], "rootDomainNamingContext");
- ldb_set_opaque(ldb, "rootDomainNamingContext", tmp_dn);
- }
-
- if (!ldb_get_opaque(ldb, "configurationNamingContext")) {
- tmp_dn = ldb_msg_find_attr_as_dn(ldb, ldb, res->msgs[0], "configurationNamingContext");
- ldb_set_opaque(ldb, "configurationNamingContext", tmp_dn);
- }
-
- if (!ldb_get_opaque(ldb, "schemaNamingContext")) {
- tmp_dn = ldb_msg_find_attr_as_dn(ldb, ldb, res->msgs[0], "schemaNamingContext");
- ldb_set_opaque(ldb, "schemaNamingContext", tmp_dn);
- }
-
- if (!ldb_get_opaque(ldb, "defaultNamingContext")) {
- tmp_dn = ldb_msg_find_attr_as_dn(ldb, ldb, res->msgs[0], "defaultNamingContext");
- ldb_set_opaque(ldb, "defaultNamingContext", tmp_dn);
- }
- }
+ if (ret != LDB_SUCCESS) {
+ talloc_free(tmp_ctx);
+ return;
+ }
+
+ if (res->count != 1) {
talloc_free(res);
+ return;
+ }
+
+ if (!ldb_get_opaque(ldb, "rootDomainNamingContext")) {
+ tmp_dn = ldb_msg_find_attr_as_dn(ldb, ldb, res->msgs[0],
+ "rootDomainNamingContext");
+ ldb_set_opaque(ldb, "rootDomainNamingContext", tmp_dn);
+ }
+
+ if (!ldb_get_opaque(ldb, "configurationNamingContext")) {
+ tmp_dn = ldb_msg_find_attr_as_dn(ldb, ldb, res->msgs[0],
+ "configurationNamingContext");
+ ldb_set_opaque(ldb, "configurationNamingContext", tmp_dn);
+ }
+
+ if (!ldb_get_opaque(ldb, "schemaNamingContext")) {
+ tmp_dn = ldb_msg_find_attr_as_dn(ldb, ldb, res->msgs[0],
+ "schemaNamingContext");
+ ldb_set_opaque(ldb, "schemaNamingContext", tmp_dn);
}
+ if (!ldb_get_opaque(ldb, "defaultNamingContext")) {
+ tmp_dn = ldb_msg_find_attr_as_dn(ldb, ldb, res->msgs[0],
+ "defaultNamingContext");
+ ldb_set_opaque(ldb, "defaultNamingContext", tmp_dn);
+ }
+
+ talloc_free(res);
talloc_free(tmp_ctx);
}
struct ldb_dn *ldb_get_root_basedn(struct ldb_context *ldb)
{
- return talloc_get_type(ldb_get_opaque(ldb, "rootDomainNamingContext"), struct ldb_dn);
+ void *opaque = ldb_get_opaque(ldb, "rootDomainNamingContext");
+ return talloc_get_type(opaque, struct ldb_dn);
}
struct ldb_dn *ldb_get_config_basedn(struct ldb_context *ldb)
{
- return talloc_get_type(ldb_get_opaque(ldb, "configurationNamingContext"), struct ldb_dn);
+ void *opaque = ldb_get_opaque(ldb, "configurationNamingContext");
+ return talloc_get_type(opaque, struct ldb_dn);
}
struct ldb_dn *ldb_get_schema_basedn(struct ldb_context *ldb)
{
- return talloc_get_type(ldb_get_opaque(ldb, "schemaNamingContext"), struct ldb_dn);
+ void *opaque = ldb_get_opaque(ldb, "schemaNamingContext");
+ return talloc_get_type(opaque, struct ldb_dn);
}
struct ldb_dn *ldb_get_default_basedn(struct ldb_context *ldb)
{
- return talloc_get_type(ldb_get_opaque(ldb, "defaultNamingContext"), struct ldb_dn);
+ void *opaque = ldb_get_opaque(ldb, "defaultNamingContext");
+ return talloc_get_type(opaque, struct ldb_dn);
}
-/*
- connect to a database. The URL can either be one of the following forms
+/*
+ connect to a database. The URL can either be one of the following forms
ldb://path
ldapi://path
@@ -287,11 +319,13 @@ struct ldb_dn *ldb_get_default_basedn(struct ldb_context *ldb)
the options are passed uninterpreted to the backend, and are
backend specific
*/
-int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[])
+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 */
+ /* We seem to need to do this here, or else some utilities don't
+ * get ldb backends */
ldb->flags = flags;
@@ -311,7 +345,8 @@ int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, co
}
if (ldb_load_modules(ldb, options) != LDB_SUCCESS) {
- ldb_debug(ldb, LDB_DEBUG_FATAL, "Unable to load modules for %s: %s\n",
+ ldb_debug(ldb, LDB_DEBUG_FATAL,
+ "Unable to load modules for %s: %s\n",
url, ldb_errstring(ldb));
return LDB_ERR_OTHER;
}
@@ -381,9 +416,9 @@ static int ldb_transaction_start_internal(struct ldb_context *ldb)
if (ldb->err_string == NULL) {
/* no error string was setup by the backend */
ldb_asprintf_errstring(ldb,
- "ldb transaction start: %s (%d)",
- ldb_strerror(status),
- status);
+ "ldb transaction start: %s (%d)",
+ ldb_strerror(status),
+ status);
}
}
return status;
@@ -404,10 +439,10 @@ static int ldb_transaction_commit_internal(struct ldb_context *ldb)
if (status != LDB_SUCCESS) {
if (ldb->err_string == NULL) {
/* no error string was setup by the backend */
- ldb_asprintf_errstring(ldb,
- "ldb transaction commit: %s (%d)",
- ldb_strerror(status),
- status);
+ ldb_asprintf_errstring(ldb,
+ "ldb transaction commit: %s (%d)",
+ ldb_strerror(status),
+ status);
}
}
return status;
@@ -426,10 +461,10 @@ static int ldb_transaction_cancel_internal(struct ldb_context *ldb)
if (status != LDB_SUCCESS) {
if (ldb->err_string == NULL) {
/* no error string was setup by the backend */
- ldb_asprintf_errstring(ldb,
- "ldb transaction cancel: %s (%d)",
- ldb_strerror(status),
- status);
+ ldb_asprintf_errstring(ldb,
+ "ldb transaction cancel: %s (%d)",
+ ldb_strerror(status),
+ status);
}
}
return status;
@@ -489,7 +524,8 @@ static int ldb_autotransaction_cancel(struct ldb_context *ldb)
}
/* autostarts a transacion if none active */
-static int ldb_autotransaction_request(struct ldb_context *ldb, struct ldb_request *req)
+static int ldb_autotransaction_request(struct ldb_context *ldb,
+ struct ldb_request *req)
{
int ret;
@@ -526,17 +562,22 @@ int ldb_wait(struct ldb_handle *handle, enum ldb_wait_type 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);
+ 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 */
/* timeout == -1 means no timeout */
-int ldb_set_timeout(struct ldb_context *ldb, struct ldb_request *req, int timeout)
+int ldb_set_timeout(struct ldb_context *ldb,
+ struct ldb_request *req,
+ int timeout)
{
if (req == NULL) return LDB_ERR_OPERATIONS_ERROR;
-
+
if (timeout != 0) {
req->timeout = timeout;
} else {
@@ -548,7 +589,9 @@ int ldb_set_timeout(struct ldb_context *ldb, struct ldb_request *req, int timeou
}
/* calculates the new timeout based on the previous starttime and timeout */
-int ldb_set_timeout_from_prev_req(struct ldb_context *ldb, struct ldb_request *oldreq, struct ldb_request *newreq)
+int ldb_set_timeout_from_prev_req(struct ldb_context *ldb,
+ struct ldb_request *oldreq,
+ struct ldb_request *newreq)
{
time_t now;
@@ -569,7 +612,7 @@ int ldb_set_timeout_from_prev_req(struct ldb_context *ldb, struct ldb_request *o
}
-/*
+/*
set the permissions for new files to be passed to open() in
backends that use local files
*/
@@ -647,15 +690,17 @@ int ldb_request(struct ldb_context *ldb, struct ldb_request *req)
Use talloc_free to free the ldb_message returned in 'res', if successful
*/
-int ldb_search_default_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares)
+int ldb_search_default_callback(struct ldb_context *ldb,
+ void *context,
+ struct ldb_reply *ares)
{
struct ldb_result *res;
int n;
-
+
if (!context) {
ldb_set_errstring(ldb, "NULL Context in callback");
return LDB_ERR_OPERATIONS_ERROR;
- }
+ }
res = talloc_get_type(context, struct ldb_result);
@@ -666,7 +711,9 @@ int ldb_search_default_callback(struct ldb_context *ldb, void *context, struct l
switch (ares->type) {
case LDB_REPLY_ENTRY:
- res->msgs = talloc_realloc(res, res->msgs, struct ldb_message *, res->count + 2);
+ res->msgs = talloc_realloc(res, res->msgs,
+ struct ldb_message *,
+ res->count + 2);
if (! res->msgs) {
goto error;
}
@@ -693,9 +740,10 @@ int ldb_search_default_callback(struct ldb_context *ldb, void *context, struct l
break;
case LDB_REPLY_EXTENDED:
case LDB_REPLY_DONE:
- /* TODO: we should really support controls on entries and referrals too! */
+ /* TODO: we should really support controls on entries
+ * and referrals too! */
res->controls = talloc_move(res, &ares->controls);
- break;
+ break;
}
talloc_free(ares);
return LDB_SUCCESS;
@@ -868,10 +916,12 @@ int ldb_build_rename_req(struct ldb_request **ret_req,
return LDB_SUCCESS;
}
-int ldb_extended_default_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares)
+int ldb_extended_default_callback(struct ldb_context *ldb,
+ void *context,
+ struct ldb_reply *ares)
{
struct ldb_result *res;
-
+
if (!context) {
ldb_set_errstring(ldb, "NULL Context in callback");
return LDB_ERR_OPERATIONS_ERROR;
@@ -890,10 +940,11 @@ int ldb_extended_default_callback(struct ldb_context *ldb, void *context, struct
ldb_set_errstring(ldb, "invalid ares type in callback");
goto error;
case LDB_REPLY_EXTENDED:
- /* TODO: we should really support controls on entries and referrals too! */
+ /* TODO: we should really support controls on entries and
+ * referrals too! */
res->extended = talloc_move(res, &ares->response);
res->controls = talloc_move(res, &ares->controls);
- break;
+ break;
}
talloc_free(ares);
return LDB_SUCCESS;
@@ -934,7 +985,7 @@ int ldb_build_extended_req(struct ldb_request **ret_req,
return LDB_SUCCESS;
}
-int ldb_extended(struct ldb_context *ldb,
+int ldb_extended(struct ldb_context *ldb,
const char *oid,
void *data,
struct ldb_result **_res)
@@ -958,7 +1009,7 @@ int ldb_extended(struct ldb_context *ldb,
ldb_set_timeout(ldb, req, 0); /* use default timeout */
ret = ldb_request(ldb, req);
-
+
if (ret == LDB_SUCCESS) {
ret = ldb_wait(req->handle, LDB_WAIT_ALL);
}
@@ -975,14 +1026,14 @@ done:
}
/*
- note that ldb_search() will automatically replace a NULL 'base' value with the
- defaultNamingContext from the rootDSE if available.
+ note that ldb_search() will automatically replace a NULL 'base' value
+ with the defaultNamingContext from the rootDSE if available.
*/
-int ldb_search(struct ldb_context *ldb,
+int ldb_search(struct ldb_context *ldb,
struct ldb_dn *base,
enum ldb_scope scope,
const char *expression,
- const char * const *attrs,
+ const char * const *attrs,
struct ldb_result **_res)
{
struct ldb_request *req;
@@ -1010,7 +1061,7 @@ int ldb_search(struct ldb_context *ldb,
ldb_set_timeout(ldb, req, 0); /* use default timeout */
ret = ldb_request(ldb, req);
-
+
if (ret == LDB_SUCCESS) {
ret = ldb_wait(req->handle, LDB_WAIT_ALL);
}
@@ -1031,8 +1082,9 @@ done:
takes a memory context where results are allocated
*/
-int ldb_search_exp_fmt(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, struct ldb_result **result,
- struct ldb_dn *base, enum ldb_scope scope, const char * const *attrs,
+int ldb_search_exp_fmt(struct ldb_context *ldb, TALLOC_CTX *mem_ctx,
+ struct ldb_result **result, struct ldb_dn *base,
+ enum ldb_scope scope, const char * const *attrs,
const char *exp_fmt, ...)
{
struct ldb_result *res;
@@ -1064,10 +1116,10 @@ int ldb_search_exp_fmt(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, struct ldb_
}
/*
- add a record to the database. Will fail if a record with the given class and key
- already exists
+ add a record to the database. Will fail if a record with the
+ given class and key already exists
*/
-int ldb_add(struct ldb_context *ldb,
+int ldb_add(struct ldb_context *ldb,
const struct ldb_message *message)
{
struct ldb_request *req;
@@ -1098,7 +1150,7 @@ int ldb_add(struct ldb_context *ldb,
/*
modify the specified attributes of a record
*/
-int ldb_modify(struct ldb_context *ldb,
+int ldb_modify(struct ldb_context *ldb,
const struct ldb_message *message)
{
struct ldb_request *req;
@@ -1155,7 +1207,8 @@ int ldb_delete(struct ldb_context *ldb, struct ldb_dn *dn)
/*
rename a record in the database
*/
-int ldb_rename(struct ldb_context *ldb, struct ldb_dn *olddn, struct ldb_dn *newdn)
+int ldb_rename(struct ldb_context *ldb,
+ struct ldb_dn *olddn, struct ldb_dn *newdn)
{
struct ldb_request *req;
int ret;
@@ -1182,7 +1235,9 @@ int ldb_rename(struct ldb_context *ldb, struct ldb_dn *olddn, struct ldb_dn *new
/*
return the global sequence number
*/
-int ldb_sequence_number(struct ldb_context *ldb, enum ldb_sequence_type type, uint64_t *seq_num)
+int ldb_sequence_number(struct ldb_context *ldb,
+ enum ldb_sequence_type type,
+ uint64_t *seq_num)
{
struct ldb_request *req;
int ret;
@@ -1202,7 +1257,7 @@ int ldb_sequence_number(struct ldb_context *ldb, enum ldb_sequence_type type, ui
req->op.seq_num.type = type;
/* do request and autostart a transaction */
ret = ldb_request(ldb, req);
-
+
if (ret == LDB_SUCCESS) {
*seq_num = req->op.seq_num.seq_num;
}
@@ -1214,7 +1269,7 @@ int ldb_sequence_number(struct ldb_context *ldb, enum ldb_sequence_type type, ui
/*
- return extended error information
+ return extended error information
*/
const char *ldb_errstring(struct ldb_context *ldb)
{
diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c
index 478df3662d..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)
{
@@ -760,14 +766,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) {
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
index 11d6c30710..01d570c89a 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -1,15 +1,15 @@
-/*
+/*
ldb database library
Copyright (C) Andrew Tridgell 2004
Copyright (C) Stefan Metzmacher 2004
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
** 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
@@ -76,7 +76,8 @@ static int ltdb_err_map(enum TDB_ERROR tdb_code)
}
-struct ldb_handle *init_ltdb_handle(struct ltdb_private *ltdb, struct ldb_module *module,
+struct ldb_handle *init_ltdb_handle(struct ltdb_private *ltdb,
+ struct ldb_module *module,
struct ldb_request *req)
{
struct ltdb_context *ac;
@@ -113,7 +114,7 @@ struct ldb_handle *init_ltdb_handle(struct ltdb_private *ltdb, struct ldb_module
form a TDB_DATA for a record key
caller frees
- note that the key for a record can depend on whether the
+ note that the key for a record can depend on whether the
dn refers to a case sensitive index record or not
*/
struct TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn)
@@ -131,8 +132,8 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn)
1) if the dn doesn't start with @ then uppercase the attribute
names and the attributes values of case insensitive attributes
- 2) if the dn starts with @ then leave it alone - the indexing code handles
- the rest
+ 2) if the dn starts with @ then leave it alone -
+ the indexing code handles the rest
*/
dn_folded = ldb_dn_get_casefold(dn);
@@ -166,10 +167,11 @@ failed:
check special dn's have valid attributes
currently only @ATTRIBUTES is checked
*/
-int ltdb_check_special_dn(struct ldb_module *module, const struct ldb_message *msg)
+int ltdb_check_special_dn(struct ldb_module *module,
+ const struct ldb_message *msg)
{
int i, j;
-
+
if (! ldb_dn_is_special(msg->dn) ||
! ldb_dn_check_special(msg->dn, LTDB_ATTRIBUTES)) {
return 0;
@@ -191,7 +193,7 @@ int ltdb_check_special_dn(struct ldb_module *module, const struct ldb_message *m
/*
- we've made a modification to a dn - possibly reindex and
+ we've made a modification to a dn - possibly reindex and
update sequence number
*/
static int ltdb_modified(struct ldb_module *module, struct ldb_dn *dn)
@@ -239,7 +241,7 @@ int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flg
ret = ltdb_err_map(tdb_error(ltdb->tdb));
goto done;
}
-
+
ret = ltdb_index_add(module, msg);
if (ret != LDB_SUCCESS) {
tdb_delete(ltdb->tdb, tdb_key);
@@ -253,15 +255,16 @@ done:
}
-static int ltdb_add_internal(struct ldb_module *module, const struct ldb_message *msg)
+static int ltdb_add_internal(struct ldb_module *module,
+ const struct ldb_message *msg)
{
int ret;
-
+
ret = ltdb_check_special_dn(module, msg);
if (ret != LDB_SUCCESS) {
return ret;
}
-
+
if (ltdb_cache_load(module) != 0) {
return LDB_ERR_OPERATIONS_ERROR;
}
@@ -269,10 +272,12 @@ static int ltdb_add_internal(struct ldb_module *module, const struct ldb_message
ret = ltdb_store(module, msg, TDB_INSERT);
if (ret == LDB_ERR_ENTRY_ALREADY_EXISTS) {
- ldb_asprintf_errstring(module->ldb, "Entry %s already exists", ldb_dn_get_linearized(msg->dn));
+ ldb_asprintf_errstring(module->ldb,
+ "Entry %s already exists",
+ ldb_dn_get_linearized(msg->dn));
return ret;
}
-
+
if (ret == LDB_SUCCESS) {
ret = ltdb_index_one(module, msg, 1);
if (ret != LDB_SUCCESS) {
@@ -293,14 +298,16 @@ static int ltdb_add_internal(struct ldb_module *module, const struct ldb_message
*/
static int ltdb_add(struct ldb_module *module, struct ldb_request *req)
{
- struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private);
+ struct ltdb_private *ltdb;
struct ltdb_context *ltdb_ac;
int tret, ret = LDB_SUCCESS;
+ ltdb = talloc_get_type(module->private_data, struct ltdb_private);
+
if (check_critical_controls(req->controls)) {
return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION;
}
-
+
req->handle = init_ltdb_handle(ltdb, module, req);
if (req->handle == NULL) {
return LDB_ERR_OPERATIONS_ERROR;
@@ -312,7 +319,7 @@ static int ltdb_add(struct ldb_module *module, struct ldb_request *req)
req->handle->status = tret;
goto done;
}
-
+
if (ltdb_ac->callback) {
ret = ltdb_ac->callback(module->ldb, ltdb_ac->context, NULL);
}
@@ -397,14 +404,16 @@ done:
*/
static int ltdb_delete(struct ldb_module *module, struct ldb_request *req)
{
- struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private);
+ struct ltdb_private *ltdb;
struct ltdb_context *ltdb_ac;
int tret, ret = LDB_SUCCESS;
+ ltdb = talloc_get_type(module->private_data, struct ltdb_private);
+
if (check_critical_controls(req->controls)) {
return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION;
}
-
+
req->handle = NULL;
if (ltdb_cache_load(module) != 0) {
@@ -419,7 +428,7 @@ static int ltdb_delete(struct ldb_module *module, struct ldb_request *req)
tret = ltdb_delete_internal(module, req->op.del.dn);
if (tret != LDB_SUCCESS) {
- req->handle->status = tret;
+ req->handle->status = tret;
goto done;
}
@@ -432,9 +441,9 @@ done:
}
/*
- find an element by attribute name. At the moment this does a linear search, it should
- be re-coded to use a binary search once all places that modify records guarantee
- sorted order
+ find an element by attribute name. At the moment this does a linear search,
+ it should be re-coded to use a binary search once all places that modify
+ records guarantee sorted order
return the index of the first matching element if found, otherwise -1
*/
@@ -452,18 +461,19 @@ static int find_element(const struct ldb_message *msg, const char *name)
/*
add an element to an existing record. Assumes a elements array that we
- can call re-alloc on, and assumed that we can re-use the data pointers from the
- passed in additional values. Use with care!
+ can call re-alloc on, and assumed that we can re-use the data pointers from
+ the passed in additional values. Use with care!
returns 0 on success, -1 on failure (and sets errno)
*/
static int msg_add_element(struct ldb_context *ldb,
- struct ldb_message *msg, struct ldb_message_element *el)
+ struct ldb_message *msg,
+ struct ldb_message_element *el)
{
struct ldb_message_element *e2;
unsigned int i;
- e2 = talloc_realloc(msg, msg->elements, struct ldb_message_element,
+ e2 = talloc_realloc(msg, msg->elements, struct ldb_message_element,
msg->num_elements+1);
if (!e2) {
errno = ENOMEM;
@@ -478,7 +488,8 @@ static int msg_add_element(struct ldb_context *ldb,
e2->flags = el->flags;
e2->values = NULL;
if (el->num_values != 0) {
- e2->values = talloc_array(msg->elements, struct ldb_val, el->num_values);
+ e2->values = talloc_array(msg->elements,
+ struct ldb_val, el->num_values);
if (!e2->values) {
errno = ENOMEM;
return -1;
@@ -512,20 +523,21 @@ static int msg_delete_attribute(struct ldb_module *module,
for (i=0;i<msg->num_elements;i++) {
if (ldb_attr_cmp(msg->elements[i].name, name) == 0) {
for (j=0;j<msg->elements[i].num_values;j++) {
- ltdb_index_del_value(module, dn, &msg->elements[i], j);
+ ltdb_index_del_value(module, dn,
+ &msg->elements[i], j);
}
talloc_free(msg->elements[i].values);
if (msg->num_elements > (i+1)) {
- memmove(&msg->elements[i],
- &msg->elements[i+1],
+ memmove(&msg->elements[i],
+ &msg->elements[i+1],
sizeof(struct ldb_message_element)*
(msg->num_elements - (i+1)));
}
msg->num_elements--;
i--;
- msg->elements = talloc_realloc(msg, msg->elements,
- struct ldb_message_element,
- msg->num_elements);
+ msg->elements = talloc_realloc(msg, msg->elements,
+ struct ldb_message_element,
+ msg->num_elements);
}
}
@@ -533,12 +545,12 @@ static int msg_delete_attribute(struct ldb_module *module,
}
/*
- delete all elements matching an attribute name/value
+ delete all elements matching an attribute name/value
return 0 on success, -1 on failure
*/
static int msg_delete_element(struct ldb_module *module,
- struct ldb_message *msg,
+ struct ldb_message *msg,
const char *name,
const struct ldb_val *val)
{
@@ -558,14 +570,17 @@ static int msg_delete_element(struct ldb_module *module,
a = ldb_schema_attribute_by_name(ldb, el->name);
for (i=0;i<el->num_values;i++) {
- if (a->syntax->comparison_fn(ldb, ldb, &el->values[i], val) == 0) {
+ if (a->syntax->comparison_fn(ldb, ldb,
+ &el->values[i], val) == 0) {
if (i<el->num_values-1) {
memmove(&el->values[i], &el->values[i+1],
- sizeof(el->values[i])*(el->num_values-(i+1)));
+ sizeof(el->values[i])*
+ (el->num_values-(i+1)));
}
el->num_values--;
if (el->num_values == 0) {
- return msg_delete_attribute(module, ldb, msg, name);
+ return msg_delete_attribute(module, ldb,
+ msg, name);
}
return 0;
}
@@ -579,10 +594,11 @@ static int msg_delete_element(struct ldb_module *module,
modify a record - internal interface
yuck - this is O(n^2). Luckily n is usually small so we probably
- get away with it, but if we ever have really large attribute lists
+ get away with it, but if we ever have really large attribute lists
then we'll need to look at this again
*/
-int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg)
+int ltdb_modify_internal(struct ldb_module *module,
+ const struct ldb_message *msg)
{
struct ldb_context *ldb = module->ldb;
struct ltdb_private *ltdb =
@@ -734,15 +750,17 @@ int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *ms
}
break;
default:
- ldb_asprintf_errstring(module->ldb, "Invalid ldb_modify flags on %s: 0x%x",
- msg->elements[i].name,
- msg->elements[i].flags & LDB_FLAG_MOD_MASK);
+ ldb_asprintf_errstring(module->ldb,
+ "Invalid ldb_modify flags on %s: 0x%x",
+ msg->elements[i].name,
+ msg->elements[i].flags & LDB_FLAG_MOD_MASK);
ret = LDB_ERR_PROTOCOL_ERROR;
goto failed;
}
}
- /* we've made all the mods - save the modified record back into the database */
+ /* we've made all the mods
+ * save the modified record back into the database */
ret = ltdb_store(module, msg2, TDB_MODIFY);
if (ret != LDB_SUCCESS) {
goto failed;
@@ -768,14 +786,16 @@ failed:
*/
static int ltdb_modify(struct ldb_module *module, struct ldb_request *req)
{
- struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private);
+ struct ltdb_private *ltdb;
struct ltdb_context *ltdb_ac;
int tret, ret = LDB_SUCCESS;
+ ltdb = talloc_get_type(module->private_data, struct ltdb_private);
+
if (check_critical_controls(req->controls)) {
return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION;
}
-
+
req->handle = NULL;
req->handle = init_ltdb_handle(ltdb, module, req);
@@ -789,7 +809,7 @@ static int ltdb_modify(struct ldb_module *module, struct ldb_request *req)
req->handle->status = tret;
goto done;
}
-
+
if (ltdb_cache_load(module) != 0) {
ret = LDB_ERR_OPERATIONS_ERROR;
goto done;
@@ -814,15 +834,17 @@ done:
*/
static int ltdb_rename(struct ldb_module *module, struct ldb_request *req)
{
- struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private);
+ struct ltdb_private *ltdb;
struct ltdb_context *ltdb_ac;
struct ldb_message *msg;
int tret, ret = LDB_SUCCESS;
+ ltdb = talloc_get_type(module->private_data, struct ltdb_private);
+
if (check_critical_controls(req->controls)) {
return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION;
}
-
+
req->handle = NULL;
if (ltdb_cache_load(module) != 0) {
@@ -947,19 +969,22 @@ static int ltdb_wait(struct ldb_handle *handle, enum ldb_wait_type type)
static int ltdb_request(struct ldb_module *module, struct ldb_request *req)
{
- /* check for oustanding critical controls and return an error if found */
+ /* check for oustanding critical controls
+ * and return an error if found */
if (check_critical_controls(req->controls)) {
return LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION;
}
-
- /* search, add, modify, delete, rename are handled by their own, no other op supported */
+
+ /* search, add, modify, delete, rename are handled by their own,
+ * no other op supported */
return LDB_ERR_OPERATIONS_ERROR;
}
/*
return sequenceNumber from @BASEINFO
*/
-static int ltdb_sequence_number(struct ldb_module *module, struct ldb_request *req)
+static int ltdb_sequence_number(struct ldb_module *module,
+ struct ldb_request *req)
{
TALLOC_CTX *tmp_ctx;
struct ldb_message *msg = NULL;
@@ -1031,7 +1056,7 @@ static const struct ldb_module_ops ltdb_ops = {
/*
connect to the database
*/
-static int ltdb_connect(struct ldb_context *ldb, const char *url,
+static int ltdb_connect(struct ldb_context *ldb, const char *url,
unsigned int flags, const char *options[],
struct ldb_module **module)
{
@@ -1042,7 +1067,8 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url,
/* parse the url */
if (strchr(url, ':')) {
if (strncmp(url, "tdb://", 6) != 0) {
- ldb_debug(ldb, LDB_DEBUG_ERROR, "Invalid tdb URL '%s'", url);
+ ldb_debug(ldb, LDB_DEBUG_ERROR,
+ "Invalid tdb URL '%s'", url);
return -1;
}
path = url+6;
@@ -1075,11 +1101,12 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url,
}
/* note that we use quite a large default hash size */
- ltdb->tdb = ltdb_wrap_open(ltdb, path, 10000,
- tdb_flags, open_flags,
+ ltdb->tdb = ltdb_wrap_open(ltdb, path, 10000,
+ tdb_flags, open_flags,
ldb->create_perms, ldb);
if (!ltdb->tdb) {
- ldb_debug(ldb, LDB_DEBUG_ERROR, "Unable to open tdb '%s'\n", path);
+ ldb_debug(ldb, LDB_DEBUG_ERROR,
+ "Unable to open tdb '%s'\n", path);
talloc_free(ltdb);
return -1;
}