summaryrefslogtreecommitdiff
path: root/source3/tdb
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2003-07-16 16:51:51 +0000
committerGerald Carter <jerry@samba.org>2003-07-16 16:51:51 +0000
commit4c8863ab087413d1e62f018c40cb39bcab6dfcf1 (patch)
treedbcfa10d590759fa4307cf723c379f6b8523e4c4 /source3/tdb
parent2da3330555bcd6f8d5edf879f38f0068b70ebee5 (diff)
downloadsamba-4c8863ab087413d1e62f018c40cb39bcab6dfcf1.tar.gz
samba-4c8863ab087413d1e62f018c40cb39bcab6dfcf1.tar.bz2
samba-4c8863ab087413d1e62f018c40cb39bcab6dfcf1.zip
adding command for moving a record from one tdb to another
(This used to be commit d0d85dd49c41c55e086714a45990d5cd6c36fa10)
Diffstat (limited to 'source3/tdb')
-rw-r--r--source3/tdb/tdbtool.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/source3/tdb/tdbtool.c b/source3/tdb/tdbtool.c
index 7369fe8d80..92009dcef4 100644
--- a/source3/tdb/tdbtool.c
+++ b/source3/tdb/tdbtool.c
@@ -118,6 +118,7 @@ static void help(void)
" erase : erase the database\n"
" dump : dump the database as strings\n"
" insert key data : insert a record\n"
+" move key file : move a record to a destination tdb\n"
" store key data : store a record (replace)\n"
" show key : show a record by key\n"
" delete key : delete a record by key\n"
@@ -291,6 +292,57 @@ static void delete_tdb(void)
}
}
+static void move_rec(void)
+{
+ char *k = get_token(1);
+ char *file = get_token(0);
+ TDB_DATA key, dbuf;
+ TDB_CONTEXT *dst_tdb;
+
+ if (!k) {
+ help();
+ return;
+ }
+
+ if ( !file ) {
+ terror("need destination tdb name");
+ return;
+ }
+
+ key.dptr = k;
+ key.dsize = strlen(k)+1;
+
+ dbuf = tdb_fetch(tdb, key);
+ if (!dbuf.dptr) {
+ /* maybe it is non-NULL terminated key? */
+ key.dsize = strlen(k);
+ dbuf = tdb_fetch(tdb, key);
+
+ if ( !dbuf.dptr ) {
+ terror("fetch failed");
+ return;
+ }
+ }
+
+ print_rec(tdb, key, dbuf, NULL);
+
+ dst_tdb = tdb_open(file, 0, 0, O_RDWR, 0600);
+ if ( !dst_tdb ) {
+ terror("unable to open destination tdb");
+ return;
+ }
+
+ if ( tdb_store( dst_tdb, key, dbuf, TDB_REPLACE ) == -1 ) {
+ terror("failed to move record");
+ }
+ else
+ printf("record moved\n");
+
+ tdb_close( dst_tdb );
+
+ return;
+}
+
#if 0
static int print_conn_key(TDB_DATA key)
{
@@ -465,6 +517,9 @@ int main(int argc, char *argv[])
} else if (strcmp(tok,"dump") == 0) {
bIterate = 0;
tdb_traverse(tdb, print_rec, NULL);
+ } else if (strcmp(tok,"move") == 0) {
+ bIterate = 0;
+ move_rec();
} else if (strcmp(tok,"list") == 0) {
tdb_dump_all(tdb);
} else if (strcmp(tok, "free") == 0) {