diff options
-rw-r--r-- | source4/lib/tdb/common/io.c | 4 | ||||
-rw-r--r-- | source4/lib/tdb/common/lock.c | 4 | ||||
-rw-r--r-- | source4/lib/tdb/common/tdb.c | 4 | ||||
-rw-r--r-- | source4/lib/tdb/common/tdb_private.h | 1 | ||||
-rw-r--r-- | source4/lib/tdb/common/transaction.c | 2 | ||||
-rw-r--r-- | source4/lib/tdb/common/traverse.c | 10 |
6 files changed, 13 insertions, 12 deletions
diff --git a/source4/lib/tdb/common/io.c b/source4/lib/tdb/common/io.c index c1f6f55bc4..a276a8c291 100644 --- a/source4/lib/tdb/common/io.c +++ b/source4/lib/tdb/common/io.c @@ -97,7 +97,7 @@ static int tdb_oob(struct tdb_context *tdb, tdb_off_t len, int probe) static int tdb_write(struct tdb_context *tdb, tdb_off_t off, const void *buf, tdb_len_t len) { - if (tdb->read_only) { + if (tdb->read_only || tdb->traverse_read) { tdb->ecode = TDB_ERR_RDONLY; return -1; } @@ -230,7 +230,7 @@ static int tdb_expand_file(struct tdb_context *tdb, tdb_off_t size, tdb_off_t ad { char buf[1024]; - if (tdb->read_only) { + if (tdb->read_only || tdb->traverse_read) { tdb->ecode = TDB_ERR_RDONLY; return -1; } diff --git a/source4/lib/tdb/common/lock.c b/source4/lib/tdb/common/lock.c index 7a76bd3d9b..703cfe9dc5 100644 --- a/source4/lib/tdb/common/lock.c +++ b/source4/lib/tdb/common/lock.c @@ -46,7 +46,7 @@ int tdb_brlock_len(struct tdb_context *tdb, tdb_off_t offset, return 0; } - if ((rw_type == F_WRLCK) && (tdb->read_only)) { + if ((rw_type == F_WRLCK) && (tdb->read_only || tdb->traverse_read)) { tdb->ecode = TDB_ERR_RDONLY; return -1; } @@ -161,7 +161,7 @@ int tdb_lockall(struct tdb_context *tdb) u32 i; /* There are no locks on read-only dbs */ - if (tdb->read_only) + if (tdb->read_only || tdb->traverse_read) return TDB_ERRCODE(TDB_ERR_LOCK, -1); for (i = 0; i < tdb->header.hash_size; i++) if (tdb_lock(tdb, i, F_WRLCK)) diff --git a/source4/lib/tdb/common/tdb.c b/source4/lib/tdb/common/tdb.c index 2e229e88cc..4b0d4a31c5 100644 --- a/source4/lib/tdb/common/tdb.c +++ b/source4/lib/tdb/common/tdb.c @@ -164,7 +164,7 @@ int tdb_do_delete(struct tdb_context *tdb, tdb_off_t rec_ptr, struct list_struct tdb_off_t last_ptr, i; struct list_struct lastrec; - if (tdb->read_only) return -1; + if (tdb->read_only || tdb->traverse_read) return -1; if (tdb_write_lock_record(tdb, rec_ptr) == -1) { /* Someone traversing here: mark it as dead */ @@ -227,7 +227,7 @@ int tdb_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag) char *p = NULL; int ret = 0; - if (tdb->read_only) { + if (tdb->read_only || tdb->traverse_read) { tdb->ecode = TDB_ERR_RDONLY; return -1; } diff --git a/source4/lib/tdb/common/tdb_private.h b/source4/lib/tdb/common/tdb_private.h index 9eeaea4cb0..2b2d6de411 100644 --- a/source4/lib/tdb/common/tdb_private.h +++ b/source4/lib/tdb/common/tdb_private.h @@ -183,6 +183,7 @@ struct tdb_context { int fd; /* open file descriptor for the database */ tdb_len_t map_size; /* how much space has been mapped */ int read_only; /* opened read-only */ + int traverse_read; /* read-only traversal */ struct tdb_lock_type *locked; /* array of chain locks */ enum TDB_ERROR ecode; /* error code for last tdb error */ struct tdb_header header; /* a cached copy of the header */ diff --git a/source4/lib/tdb/common/transaction.c b/source4/lib/tdb/common/transaction.c index 5f281ca4da..a01f8307e9 100644 --- a/source4/lib/tdb/common/transaction.c +++ b/source4/lib/tdb/common/transaction.c @@ -349,7 +349,7 @@ static const struct tdb_methods transaction_methods = { int tdb_transaction_start(struct tdb_context *tdb) { /* some sanity checks */ - if (tdb->read_only || (tdb->flags & TDB_INTERNAL)) { + if (tdb->read_only || (tdb->flags & TDB_INTERNAL) || tdb->traverse_read) { TDB_LOG((tdb, 0, "tdb_transaction_start: cannot start a transaction on a read-only or internal db\n")); tdb->ecode = TDB_ERR_EINVAL; return -1; diff --git a/source4/lib/tdb/common/traverse.c b/source4/lib/tdb/common/traverse.c index f8315f5770..9271b75aa8 100644 --- a/source4/lib/tdb/common/traverse.c +++ b/source4/lib/tdb/common/traverse.c @@ -114,7 +114,7 @@ static int tdb_next_lock(struct tdb_context *tdb, struct tdb_traverse_lock *tloc /* Try to clean dead ones from old traverses */ current = tlock->off; tlock->off = rec->next; - if (!tdb->read_only && + if (!(tdb->read_only || tdb->traverse_read) && tdb_do_delete(tdb, current, rec) != 0) goto fail; } @@ -204,10 +204,10 @@ int tdb_traverse_read(struct tdb_context *tdb, tdb_traverse_func fn, void *private) { struct tdb_traverse_lock tl = { NULL, 0, 0, F_RDLCK }; - int ret, read_only = tdb->read_only; - tdb->read_only = 1; + int ret; + tdb->traverse_read++; ret = tdb_traverse_internal(tdb, fn, private, &tl); - tdb->read_only = read_only; + tdb->traverse_read--; return ret; } @@ -221,7 +221,7 @@ int tdb_traverse(struct tdb_context *tdb, struct tdb_traverse_lock tl = { NULL, 0, 0, F_WRLCK }; int ret; - if (tdb->read_only) { + if (tdb->read_only || tdb->traverse_read) { return tdb_traverse_read(tdb, fn, private); } |