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/ntdb.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/ntdb/ntdb.c') diff --git a/lib/ntdb/ntdb.c b/lib/ntdb/ntdb.c index 6c75915899..5d56b33b5a 100644 --- a/lib/ntdb/ntdb.c +++ b/lib/ntdb/ntdb.c @@ -500,10 +500,23 @@ _PUBLIC_ enum NTDB_ERROR ntdb_parse_record_(struct ntdb_context *ntdb, if (!off) { ecode = NTDB_ERR_NOEXIST; } else { + unsigned int old_flags; NTDB_DATA d = ntdb_mkdata(keyp + key.dsize, rec_data_length(&rec)); + /* + * Make sure they don't try to write db, since they + * have read lock! They can if they've done + * ntdb_lockall(): if it was ntdb_lockall_read, that'll + * stop them doing a write operation anyway. + */ + old_flags = ntdb->flags; + if (!ntdb->file->allrecord_lock.count && + !(ntdb->flags & NTDB_NOLOCK)) { + ntdb->flags |= NTDB_RDONLY; + } ecode = parse(key, d, data); + ntdb->flags = old_flags; ntdb_access_release(ntdb, keyp); } -- cgit