rec.dptr = (uint8_t *)&list2;
rec.dsize = sizeof(void *);
+
+ /*
+ * This is not a store into the main DB, but into an in-memory
+ * TDB, so we don't need a guard on ltdb->read_only
+ */
ret = tdb_store(ltdb->idxptr->itdb, key, rec, TDB_INSERT);
if (ret != 0) {
return ltdb_err_map(tdb_error(ltdb->idxptr->itdb));
int ret;
struct ltdb_reindex_context ctx;
+ /*
+ * Only triggered after a modification, but make clear we do
+ * not re-index a read-only DB
+ */
+ if (ltdb->read_only) {
+ return LDB_ERR_UNWILLING_TO_PERFORM;
+ }
+
if (ltdb_cache_reload(module) != 0) {
return LDB_ERR_OPERATIONS_ERROR;
}
struct ldb_val ldb_data;
int ret = LDB_SUCCESS;
+ if (ltdb->read_only) {
+ return LDB_ERR_UNWILLING_TO_PERFORM;
+ }
+
tdb_key = ltdb_key(module, msg->dn);
if (tdb_key.dptr == NULL) {
return LDB_ERR_OTHER;
TDB_DATA tdb_key;
int ret;
+ if (ltdb->read_only) {
+ return LDB_ERR_UNWILLING_TO_PERFORM;
+ }
+
tdb_key = ltdb_key(module, dn);
if (!tdb_key.dptr) {
return LDB_ERR_OTHER;
void *data = ldb_module_get_private(module);
struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
+ /* Do not take out the transaction lock on a read-only DB */
+ if (ltdb->read_only) {
+ return LDB_ERR_UNWILLING_TO_PERFORM;
+ }
+
if (tdb_transaction_start(ltdb->tdb) != 0) {
return ltdb_err_map(tdb_error(ltdb->tdb));
}
tdb_flags |= TDB_NOMMAP;
}
+ ltdb = talloc_zero(ldb, struct ltdb_private);
+ if (!ltdb) {
+ ldb_oom(ldb);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+
if (flags & LDB_FLG_RDONLY) {
- open_flags = O_RDONLY;
+ /*
+ * This is weird, but because we can only have one tdb
+ * in this process, and the other one could be
+ * read-write, we can't use the tdb readonly. Plus a
+ * read only tdb prohibits the all-record lock.
+ */
+ open_flags = O_RDWR;
+
+ ltdb->read_only = true;
+
} else if (flags & LDB_FLG_DONT_CREATE_DB) {
+ /*
+ * This is used by ldbsearch to prevent creation of the database
+ * if the name is wrong
+ */
open_flags = O_RDWR;
} else {
+ /*
+ * This is the normal case
+ */
open_flags = O_CREAT | O_RDWR;
}
- ltdb = talloc_zero(ldb, struct ltdb_private);
- if (!ltdb) {
- ldb_oom(ldb);
- return LDB_ERR_OPERATIONS_ERROR;
- }
-
/* note that we use quite a large default hash size */
ltdb->tdb = ltdb_wrap_open(ltdb, path, 10000,
tdb_flags, open_flags,