summaryrefslogtreecommitdiff
path: root/source3/tdb
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2000-12-07 17:46:11 +0000
committerJeremy Allison <jra@samba.org>2000-12-07 17:46:11 +0000
commit0d658c35eb9d8ec400ad0302ee11d489bb59bd77 (patch)
tree376abfc6819522969a926a5a8d91f0f7c2b693a8 /source3/tdb
parentc31211167bc2b98f51f8f3cc70bb410250b427aa (diff)
downloadsamba-0d658c35eb9d8ec400ad0302ee11d489bb59bd77.tar.gz
samba-0d658c35eb9d8ec400ad0302ee11d489bb59bd77.tar.bz2
samba-0d658c35eb9d8ec400ad0302ee11d489bb59bd77.zip
Fixed bug with tdb_next_lock failing when reaching then end of a hashchain
and the next hashchain is empty. Jeremy (This used to be commit f3b5e2a172a777e1c3bbf6ac72fe5c7cdb8324b3)
Diffstat (limited to 'source3/tdb')
-rw-r--r--source3/tdb/tdb.c19
-rw-r--r--source3/tdb/tdbtool.c29
2 files changed, 39 insertions, 9 deletions
diff --git a/source3/tdb/tdb.c b/source3/tdb/tdb.c
index 1e66fe1419..20f51402dc 100644
--- a/source3/tdb/tdb.c
+++ b/source3/tdb/tdb.c
@@ -776,9 +776,8 @@ static int tdb_next_lock(TDB_CONTEXT *tdb, struct tdb_traverse_lock *tlock,
struct list_struct *rec)
{
tdb_off next;
- int first = (tlock->off == 0);
- /* No traversal allows if you've called tdb_lockkeys() */
+ /* No traversal allows sf you've called tdb_lockkeys() */
if (tdb->lockedkeys) return TDB_ERRCODE(TDB_ERR_NOLOCK, -1);
/* Lock each chain from the start one. */
@@ -791,15 +790,17 @@ static int tdb_next_lock(TDB_CONTEXT *tdb, struct tdb_traverse_lock *tlock,
&tlock->off) == -1)
goto fail;
} else {
- /* Othereisre unlock the previous record. */
- unlock_record(tdb, tlock->off);
- }
- if (!first) {
- /* Grab next record */
- if (rec_read(tdb, tlock->off, rec) == -1) goto fail;
+ /* Get a copy of previous record, to go to next. */
+ if (rec_read(tdb, tlock->off, rec) == -1) {
+ unlock_record(tdb, tlock->off);
+ goto fail;
+ }
+
tlock->off = rec->next;
- first = 0;
+
+ /* Now unlock the previous record. */
+ unlock_record(tdb, tlock->off);
}
/* Iterate through chain */
diff --git a/source3/tdb/tdbtool.c b/source3/tdb/tdbtool.c
index 0373aee9a7..508adc5d54 100644
--- a/source3/tdb/tdbtool.c
+++ b/source3/tdb/tdbtool.c
@@ -68,6 +68,8 @@ tdbtool:
show key : show a record by key
delete key : delete a record by key
free : print the database freelist
+ first : print the first record
+ next : print the next record
");
}
@@ -221,10 +223,33 @@ static int do_delete_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf,
return tdb_delete(tdb, key);
}
+static void first_record(TDB_CONTEXT *tdb, TDB_DATA *pkey)
+{
+ TDB_DATA dbuf;
+ *pkey = tdb_firstkey(tdb);
+
+ dbuf = tdb_fetch(tdb, *pkey);
+ if (!dbuf.dptr) terror("fetch failed");
+ /* printf("%s : %*.*s\n", k, (int)dbuf.dsize, (int)dbuf.dsize, dbuf.dptr); */
+ print_rec(tdb, *pkey, dbuf, NULL);
+}
+
+static void next_record(TDB_CONTEXT *tdb, TDB_DATA *pkey)
+{
+ TDB_DATA dbuf;
+ *pkey = tdb_nextkey(tdb, *pkey);
+
+ dbuf = tdb_fetch(tdb, *pkey);
+ if (!dbuf.dptr) terror("fetch failed");
+ /* printf("%s : %*.*s\n", k, (int)dbuf.dsize, (int)dbuf.dsize, dbuf.dptr); */
+ print_rec(tdb, *pkey, dbuf, NULL);
+}
+
int main(int argc, char *argv[])
{
char *line;
char *tok;
+ TDB_DATA iterate_kbuf;
if (argv[1]) {
static char tmp[1024];
@@ -276,6 +301,10 @@ int main(int argc, char *argv[])
info_tdb();
} else if (strcmp(tok, "free") == 0) {
tdb_printfreelist(tdb);
+ } else if (strcmp(tok, "first") == 0) {
+ first_record(tdb, &iterate_kbuf);
+ } else if (strcmp(tok, "next") == 0) {
+ next_record(tdb, &iterate_kbuf);
} else {
help();
}