summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/ldb_tdb
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2004-10-20 19:28:02 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:02:20 -0500
commita9bd40549767c19207f3ec520a3e4346beeabef4 (patch)
tree055d67a79bdd2cb9098284fabdbf8a9cba6e95a9 /source4/lib/ldb/ldb_tdb
parent8d48ca63db0ec8dc47a386bd1fa38be2827755f3 (diff)
downloadsamba-a9bd40549767c19207f3ec520a3e4346beeabef4.tar.gz
samba-a9bd40549767c19207f3ec520a3e4346beeabef4.tar.bz2
samba-a9bd40549767c19207f3ec520a3e4346beeabef4.zip
r3093: - implment ldb_rename() and ldbrename
- add tests for ldbrename - disable all tests which regenerate the index (this is broken for me...the process hangs, tridge we need to discuss that) - link only the needed stuff to the ldb tools - build ldbtest inside samba metze (This used to be commit 18552f4786c24e0019cc87726ef4c05365fe586e)
Diffstat (limited to 'source4/lib/ldb/ldb_tdb')
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
index e36770f88b..934ec68958 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -2,6 +2,8 @@
ldb database library
Copyright (C) Andrew Tridgell 2004
+ Copyright (C) Stefan Metzmacher 2004
+
** NOTE! The following LGPL license applies to the ldb
** library. This does NOT imply that all of Samba is released
@@ -30,6 +32,7 @@
* Description: core functions for tdb backend
*
* Author: Andrew Tridgell
+ * Author: Stefan Metzmacher
*/
#include "includes.h"
@@ -582,6 +585,60 @@ static int ltdb_modify(struct ldb_context *ldb, const struct ldb_message *msg)
}
/*
+ rename a record
+*/
+static int ltdb_rename(struct ldb_context *ldb, const char *olddn, const char *newdn)
+{
+ struct ltdb_private *ltdb = ldb->private_data;
+ int ret;
+ struct ldb_message msg;
+ const char *error_str;
+
+ ltdb->last_err_string = NULL;
+
+ if (ltdb_lock(ldb) != 0) {
+ return -1;
+ }
+
+ /* in case any attribute of the message was indexed, we need
+ to fetch the old record */
+ ret = ltdb_search_dn1(ldb, olddn, &msg);
+ if (ret != 1) {
+ /* not finding the old record is an error */
+ goto failed;
+ }
+
+ ldb_free(ldb, msg.dn);
+ msg.dn = ldb_strdup(ldb,newdn);
+ if (!msg.dn) {
+ ltdb_search_dn1_free(ldb, &msg);
+ goto failed;
+ }
+
+ ret = ltdb_add(ldb, &msg);
+ if (ret == -1) {
+ ltdb_search_dn1_free(ldb, &msg);
+ goto failed;
+ }
+ ltdb_search_dn1_free(ldb, &msg);
+
+ ret = ltdb_delete(ldb, olddn);
+ error_str = ltdb->last_err_string;
+ if (ret == -1) {
+ ltdb_delete(ldb, newdn);
+ }
+
+ ltdb->last_err_string = error_str;
+
+ ltdb_unlock(ldb);
+
+ return ret;
+failed:
+ ltdb_unlock(ldb);
+ return -1;
+}
+
+/*
close database
*/
static int ltdb_close(struct ldb_context *ldb)
@@ -621,6 +678,7 @@ static const struct ldb_backend_ops ltdb_ops = {
ltdb_add,
ltdb_modify,
ltdb_delete,
+ ltdb_rename,
ltdb_errstring,
ltdb_cache_free
};