ldb: add LDB_FLG_DONT_CREATE_DB
authorStefan Metzmacher <metze@samba.org>
Fri, 24 Feb 2017 14:34:33 +0000 (15:34 +0100)
committerStefan Metzmacher <metze@samba.org>
Thu, 9 Mar 2017 15:02:21 +0000 (16:02 +0100)
This avoids creating an new tdb files on ldbsearch
or other callers which use LDB_FLG_DONT_CREATE_DB.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(master): Thu Mar  9 16:02:21 CET 2017 on sn-devel-144

lib/ldb/include/ldb.h
lib/ldb/ldb_tdb/ldb_tdb.c
lib/ldb/tools/cmdline.c

index 397f994671073e68f79c63f626c4d0d345b8c34c..afcf9eb6351fe743a5416fe2c53a6ea7c7327c3e 100644 (file)
@@ -271,6 +271,15 @@ struct ldb_utf8_fns {
 */
 #define LDB_FLG_ENABLE_TRACING 32
 
+/**
+   Flags to tell LDB not to create a new database file:
+
+   Without this flag ldb_tdb (for example) will create a blank file
+   during an invocation of ldb_connect(), even when the caller only
+   wanted read operations, for example in ldbsearch.
+*/
+#define LDB_FLG_DONT_CREATE_DB 64
+
 /*
    structures for ldb_parse_tree handling code
 */
index 707d227c2bbfabbbe2bab7bf42e9ea9885e9da3e..8c4989f6095a48a6209db33cac7eff33750e0d22 100644 (file)
@@ -1565,6 +1565,8 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url,
 
        if (flags & LDB_FLG_RDONLY) {
                open_flags = O_RDONLY;
+       } else if (flags & LDB_FLG_DONT_CREATE_DB) {
+               open_flags = O_RDWR;
        } else {
                open_flags = O_CREAT | O_RDWR;
        }
index 8baa12087172b9dd9b70caac300b340833dd41d4..a2fe97ee6b2841effef9cd86215c997f6823b011 100644 (file)
@@ -280,10 +280,7 @@ static struct ldb_cmdline *ldb_cmdline_process_internal(struct ldb_context *ldb,
        }
 
        if (search) {
-               /*
-                * For now we're not adding LDB_FLG_RDONLY,
-                * as that would result in no tdb locking.
-                */
+               flags |= LDB_FLG_DONT_CREATE_DB;
 
                if (options.show_binary) {
                        flags |= LDB_FLG_SHOW_BINARY;