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"
-#include "ldb/ldb_tdb/ldb_tdb.h"
+#include "ldb_tdb.h"
/*
add one element to a message
el.name = "distinguishedName";
el.num_values = 1;
el.values = &val;
- val.data = (uint8_t *)ldb_dn_linearize(msg, msg->dn);
+ val.data = (uint8_t *)ldb_dn_alloc_linearized(msg, msg->dn);
val.length = strlen((char *)val.data);
ret = msg_add_element(msg, &el, 1);
}
for (i=0;i<msg->num_elements;i++) {
- const struct ldb_attrib_handler *h;
- h = ldb_attrib_handler(ldb, msg->elements[i].name);
- if (h->flags & LDB_ATTR_FLAG_HIDDEN) {
+ const struct ldb_schema_attribute *a;
+ a = ldb_schema_attribute_by_name(ldb, msg->elements[i].name);
+ if (a->flags & LDB_ATTR_FLAG_HIDDEN) {
continue;
}
if (msg_add_element(ret, &msg->elements[i],
search the database for a single simple dn, returning all attributes
in a single message
- return 1 on success, 0 on record-not-found and -1 on error
+ return LDB_ERR_NO_SUCH_OBJECT on record-not-found
+ and LDB_SUCCESS on success
*/
-int ltdb_search_dn1(struct ldb_module *module, const struct ldb_dn *dn, struct ldb_message *msg)
+int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_message *msg)
{
- struct ltdb_private *ltdb = module->private_data;
+ struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data;
int ret;
TDB_DATA tdb_key, tdb_data;
/* form the key */
tdb_key = ltdb_key(module, dn);
if (!tdb_key.dptr) {
- return -1;
+ return LDB_ERR_OPERATIONS_ERROR;
}
tdb_data = tdb_fetch(ltdb->tdb, tdb_key);
talloc_free(tdb_key.dptr);
if (!tdb_data.dptr) {
- return 0;
+ return LDB_ERR_NO_SUCH_OBJECT;
}
msg->num_elements = 0;
ret = ltdb_unpack_data(module, &tdb_data, msg);
free(tdb_data.dptr);
if (ret == -1) {
- return -1;
+ return LDB_ERR_OPERATIONS_ERROR;
}
if (!msg->dn) {
msg->dn = ldb_dn_copy(msg, dn);
}
if (!msg->dn) {
- return -1;
+ return LDB_ERR_OPERATIONS_ERROR;
}
- return 1;
+ return LDB_SUCCESS;
}
-/* the lock key for search locking. Note that this is not a DN, its
- just an arbitrary key to give to tdb. Also note that as we and
- using transactions for all write operations and transactions take
- care of their own locks, we don't need to do any locking anywhere
- other than in ldb_search() */
-#define LDBLOCK "INT_LDBLOCK"
-
/*
lock the database for read - use by ltdb_search
*/
static int ltdb_lock_read(struct ldb_module *module)
{
- struct ltdb_private *ltdb = module->private_data;
- TDB_DATA key;
-
- key.dptr = discard_const(LDBLOCK);
- key.dsize = strlen(LDBLOCK);
-
- return tdb_chainlock_read(ltdb->tdb, key);
+ struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data;
+ return tdb_lockall_read(ltdb->tdb);
}
/*
*/
static int ltdb_unlock_read(struct ldb_module *module)
{
- struct ltdb_private *ltdb = module->private_data;
- TDB_DATA key;
-
- key.dptr = discard_const(LDBLOCK);
- key.dsize = strlen(LDBLOCK);
-
- return tdb_chainunlock_read(ltdb->tdb, key);
+ struct ltdb_private *ltdb = (struct ltdb_private *)module->private_data;
+ return tdb_unlockall_read(ltdb->tdb);
}
/*
(*res) = res2;
- (*res)[*count] = talloc_steal(*res, msg2);
+ (*res)[*count] = talloc_move(*res, &msg2);
(*res)[(*count)+1] = NULL;
(*count)++;
*/
static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state)
{
- struct ldb_async_handle *handle = talloc_get_type(state, struct ldb_async_handle);
- struct ltdb_async_context *ac = talloc_get_type(handle->private_data, struct ltdb_async_context);
- struct ldb_async_result *ares = NULL;
+ struct ldb_handle *handle = talloc_get_type(state, struct ldb_handle);
+ struct ltdb_context *ac = talloc_get_type(handle->private_data, struct ltdb_context);
+ struct ldb_reply *ares = NULL;
int ret;
if (key.dsize < 4 ||
return 0;
}
- ares = talloc_zero(ac, struct ldb_async_result);
+ ares = talloc_zero(ac, struct ldb_reply);
if (!ares) {
handle->status = LDB_ERR_OPERATIONS_ERROR;
handle->state = LDB_ASYNC_DONE;
}
if (!ares->message->dn) {
- ares->message->dn = ldb_dn_explode(ares->message, (char *)key.dptr + 3);
+ ares->message->dn = ldb_dn_new(ares->message, ac->module->ldb, (char *)key.dptr + 3);
if (ares->message->dn == NULL) {
handle->status = LDB_ERR_OPERATIONS_ERROR;
handle->state = LDB_ASYNC_DONE;
search the database with a LDAP-like expression.
this is the "full search" non-indexed variant
*/
-static int ltdb_search_full(struct ldb_async_handle *handle)
+static int ltdb_search_full(struct ldb_handle *handle)
{
- struct ltdb_async_context *ac = talloc_get_type(handle->private_data, struct ltdb_async_context);
+ struct ltdb_context *ac = talloc_get_type(handle->private_data, struct ltdb_context);
struct ltdb_private *ltdb = talloc_get_type(ac->module->private_data, struct ltdb_private);
int ret;
int ltdb_search(struct ldb_module *module, struct ldb_request *req)
{
struct ltdb_private *ltdb = talloc_get_type(module->private_data, struct ltdb_private);
- struct ltdb_async_context *ltdb_ac;
+ struct ltdb_context *ltdb_ac;
+ struct ldb_reply *ares;
int ret;
- if ((req->op.search.base == NULL || req->op.search.base->comp_num == 0) &&
+ if ((( ! ldb_dn_is_valid(req->op.search.base)) || ldb_dn_is_null(req->op.search.base)) &&
(req->op.search.scope == LDB_SCOPE_BASE || req->op.search.scope == LDB_SCOPE_ONELEVEL))
return LDB_ERR_OPERATIONS_ERROR;
return LDB_ERR_OPERATIONS_ERROR;
}
- req->async.handle = init_ltdb_handle(ltdb, module, req->async.context, req->async.callback);
- if (req->async.handle == NULL) {
+ req->handle = init_ltdb_handle(ltdb, module, req);
+ if (req->handle == NULL) {
ltdb_unlock_read(module);
return LDB_ERR_OPERATIONS_ERROR;
}
-
- ltdb_ac = talloc_get_type(req->async.handle->private_data, struct ltdb_async_context);
+ ltdb_ac = talloc_get_type(req->handle->private_data, struct ltdb_context);
ltdb_ac->tree = req->op.search.tree;
ltdb_ac->scope = req->op.search.scope;
ltdb_ac->base = req->op.search.base;
ltdb_ac->attrs = req->op.search.attrs;
- ret = ltdb_search_indexed(req->async.handle);
- if (ret == -1) {
- ret = ltdb_search_full(req->async.handle);
+ ret = ltdb_search_indexed(req->handle);
+ if (ret == LDB_ERR_OPERATIONS_ERROR) {
+ ret = ltdb_search_full(req->handle);
}
if (ret != LDB_SUCCESS) {
- ldb_set_errstring(module->ldb, talloc_strdup(module->ldb, "Indexed and full searches both failed!\n"));
- req->async.handle->state = LDB_ASYNC_DONE;
- req->async.handle->status = ret;
+ ldb_set_errstring(module->ldb, "Indexed and full searches both failed!\n");
+ req->handle->state = LDB_ASYNC_DONE;
+ req->handle->status = ret;
+ }
+
+ /* Finally send an LDB_REPLY_DONE packet when searching is finished */
+
+ ares = talloc_zero(req, struct ldb_reply);
+ if (!ares) {
+ ltdb_unlock_read(module);
+ return LDB_ERR_OPERATIONS_ERROR;
}
+ req->handle->state = LDB_ASYNC_DONE;
+ ares->type = LDB_REPLY_DONE;
+
+ ret = req->callback(module->ldb, req->context, ares);
+ req->handle->status = ret;
+
ltdb_unlock_read(module);
return LDB_SUCCESS;