ldb_mdb: Don't allow modify operations on a read only db
authorGary Lockyer <gary@catalyst.net.nz>
Tue, 6 Mar 2018 23:05:34 +0000 (12:05 +1300)
committerStefan Metzmacher <metze@samba.org>
Thu, 12 Apr 2018 14:27:16 +0000 (16:27 +0200)
Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
lib/ldb/ldb_mdb/ldb_mdb.c

index 8c2fa66087deaf5da7fbadc82fefe0cd294190e0..5169e51e76a1410ee36866e09188892885801b45 100644 (file)
@@ -160,6 +160,10 @@ static int lmdb_store(struct ltdb_private *ltdb,
        MDB_txn *txn = NULL;
        MDB_dbi dbi = 0;
 
+       if (ltdb->read_only) {
+               return LDB_ERR_UNWILLING_TO_PERFORM;
+       }
+
        txn = lmdb_trans_get_tx(lmdb_private_trans_head(lmdb));
        if (txn == NULL) {
                ldb_debug(lmdb->ldb, LDB_DEBUG_FATAL, "No transaction");
@@ -215,6 +219,10 @@ static int lmdb_delete(struct ltdb_private *ltdb, struct ldb_val key)
        MDB_txn *txn = NULL;
        MDB_dbi dbi = 0;
 
+       if (ltdb->read_only) {
+               return LDB_ERR_UNWILLING_TO_PERFORM;
+       }
+
        txn = lmdb_trans_get_tx(lmdb_private_trans_head(lmdb));
        if (txn == NULL) {
                ldb_debug(lmdb->ldb, LDB_DEBUG_FATAL, "No transaction");
@@ -469,6 +477,11 @@ static int lmdb_transaction_start(struct ltdb_private *ltdb)
        struct lmdb_trans *ltx_head;
        MDB_txn *tx_parent;
 
+       /* Do not take out the transaction lock on a read-only DB */
+       if (ltdb->read_only) {
+               return LDB_ERR_UNWILLING_TO_PERFORM;
+       }
+
        ltx = talloc_zero(lmdb, struct lmdb_trans);
        if (ltx == NULL) {
                return ldb_oom(lmdb->ldb);