From 01ec4a72de56ade54bbbc92e0a408771390c5c12 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 22 Jun 2012 09:44:41 +0930 Subject: ntdb: make database read-only during ntdb_parse() callback. Since we have a readlock, any write will grab a write lock: if it happens to be on the same bucket, we'll fail. For that reason, enforce read-only so every write operation fails (even for NTDB_NOLOCK or NTDB_INTERNAL dbs), and document it! Signed-off-by: Rusty Russell --- lib/ntdb/lock.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lib/ntdb/lock.c') diff --git a/lib/ntdb/lock.c b/lib/ntdb/lock.c index f6a811a3fa..4517e25568 100644 --- a/lib/ntdb/lock.c +++ b/lib/ntdb/lock.c @@ -188,15 +188,15 @@ static enum NTDB_ERROR ntdb_brlock(struct ntdb_context *ntdb, { int ret; - if (ntdb->flags & NTDB_NOLOCK) { - return NTDB_SUCCESS; - } - if (rw_type == F_WRLCK && (ntdb->flags & NTDB_RDONLY)) { return ntdb_logerr(ntdb, NTDB_ERR_RDONLY, NTDB_LOG_USE_ERROR, "Write lock attempted on read-only database"); } + if (ntdb->flags & NTDB_NOLOCK) { + return NTDB_SUCCESS; + } + /* A 32 bit system cannot open a 64-bit file, but it could have * expanded since then: check here. */ if ((size_t)(offset + len) != offset + len) { @@ -533,8 +533,9 @@ enum NTDB_ERROR ntdb_allrecord_lock(struct ntdb_context *ntdb, int ltype, enum NTDB_ERROR ecode; ntdb_bool_err berr; - if (ntdb->flags & NTDB_NOLOCK) + if (ntdb->flags & NTDB_NOLOCK) { return NTDB_SUCCESS; + } if (!check_lock_pid(ntdb, "ntdb_allrecord_lock", true)) { return NTDB_ERR_LOCK; -- cgit