The branch, master has been updated
       via  b210e7a dbwrap: use DBWRAP_LOCK_ORDER_VALID() in db_open()
       via  c7961ee dbwrap: completely check validity of lock order in 
dbwrap_check_lock_order()
       via  9914017 dbwrap: add a comment explaining the supported lock orders
       via  5e5a31b dbwrap: add DBWRAP_LOCK_ORDER_VALID()
       via  8dbb582 dbwrap: add DBWRAP_LOCK_ORDER_MIN
       via  24e434d dbwrap: move definition of DBWRAP_LOCK_ORDER_MAX to the 
private header.
       via  44c6643 dbwrap: explicitly use DBWRAP_LOCK_ORDER_NONE in tdb->ntdb 
conversion
       via  31c2336 s4:cluster: use DBWRAP_LOCK_ODER_NONE for 
local_db_tmp_open()
       via  85235d0 libcli: use DBWRAP_LOCK_ORDER_NONE when opening 
schannel_store.tdb
       via  4eb57bd dbwrap: introduce DBWRAP_LOCK_ORDER_NONE for lock order "0".
       via  7e766a0 dbwrap: add dbwrap_flags argument to dbwrap_local_open()
       via  e4fbaad dbwrap: add a dbwrap_flags argument to db_open_ntdb()
       via  bbf0903 dbwrap: add a dbwrap_flags argument to db_open_tdb()
       via  906abe5 s3:registry: introduce REG_DBWRAP_FLAGS to use for all 
db_open calls
       via  020fab3 s3:rpc_client: optimize the netlogon_creds_cli.tdb for 
read-only access
       via  a20c977 dbwrap_open: add 'dbwrap_optimize_readonly:* = yes' option
       via  a97b588 dbwrap_ctdb: implement DBWRAP_FLAG_OPTIMIZE_READONLY_ACCESS
       via  56bd404 dbwrap: add DBWRAP_FLAG_OPTIMIZE_READONLY_ACCESS
       via  6def1c3 dbwrap: add a dbwrap_flags argument to db_open_ctdb()
       via  cf0cb0a dbwrap: add a dbwrap_flags argument to db_open()
       via  229dcfd dbwrap: add flags DBWRAP_FLAG_NONE
      from  353fdc5 .gitignore: Ignore tag files from GNU Global tool

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit b210e7aade5bc6445df22e4cd4b9b906cb40c236
Author: Michael Adam <ob...@samba.org>
Date:   Tue Jan 28 11:58:05 2014 +0100

    dbwrap: use DBWRAP_LOCK_ORDER_VALID() in db_open()
    
    instead of the hand written test.
    
    Signed-off-by: Michael Adam <ob...@samba.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>
    
    Autobuild-User(master): Stefan Metzmacher <me...@samba.org>
    Autobuild-Date(master): Fri Feb  7 18:05:51 CET 2014 on sn-devel-104

commit c7961ee4953dbcc8c45790d3c92fe3172e924f47
Author: Michael Adam <ob...@samba.org>
Date:   Mon Jan 27 17:34:31 2014 +0100

    dbwrap: completely check validity of lock order in dbwrap_check_lock_order()
    
    This is currently not strictly necessay, because the
    only caller catches the DBWRAP_LOCK_ORDER_NONE case,
    and maximum is already checked,  but this seems too dangerous to me.
    
    Use the new DBWRAP_LOCK_ORDER_VALID() macro.
    
    Signed-off-by: Michael Adam <ob...@samba.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

commit 99140170a587102493e9f073145ba941987d01d3
Author: Michael Adam <ob...@samba.org>
Date:   Tue Jan 28 11:44:21 2014 +0100

    dbwrap: add a comment explaining the supported lock orders
    
    Signed-off-by: Michael Adam <ob...@samba.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

commit 5e5a31bfb2de9ffa9829db1002118773a22ac9e4
Author: Michael Adam <ob...@samba.org>
Date:   Tue Jan 28 11:54:06 2014 +0100

    dbwrap: add DBWRAP_LOCK_ORDER_VALID()
    
    Signed-off-by: Michael Adam <ob...@samba.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

commit 8dbb58285b6590203d3c510c22cb6936fd642e5f
Author: Michael Adam <ob...@samba.org>
Date:   Tue Jan 28 12:04:38 2014 +0100

    dbwrap: add DBWRAP_LOCK_ORDER_MIN
    
    Signed-off-by: Michael Adam <ob...@samba.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

commit 24e434d1aec880d1292d003cbcf6f869e3d35526
Author: Michael Adam <ob...@samba.org>
Date:   Tue Jan 28 11:52:36 2014 +0100

    dbwrap: move definition of DBWRAP_LOCK_ORDER_MAX to the private header.
    
    This is only needed internally.
    
    Signed-off-by: Michael Adam <ob...@samba.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

commit 44c66435bafc786f8a4c10e3652c7de168f642b1
Author: Michael Adam <ob...@samba.org>
Date:   Tue Jan 28 12:42:31 2014 +0100

    dbwrap: explicitly use DBWRAP_LOCK_ORDER_NONE in tdb->ntdb conversion
    
    Make lack of lock order checking more visible.
    
    Signed-off-by: Michael Adam <ob...@samba.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

commit 31c233651972c94b66d7cebf42ebcdcb43c39036
Author: Michael Adam <ob...@samba.org>
Date:   Mon Jan 27 17:26:50 2014 +0100

    s4:cluster: use DBWRAP_LOCK_ODER_NONE for local_db_tmp_open()
    
    Make lack of lock oder checking more visible.
    
    Signed-off-by: Michael Adam <ob...@samba.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

commit 85235d03c1030a8bd510232a068da7f933ceb268
Author: Michael Adam <ob...@samba.org>
Date:   Mon Jan 27 17:25:54 2014 +0100

    libcli: use DBWRAP_LOCK_ORDER_NONE when opening schannel_store.tdb
    
    Make lack of lock order checking more visible.
    
    Signed-off-by: Michael Adam <ob...@samba.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

commit 4eb57bd6e7e9cdb6de5cb7510267a71917cfe393
Author: Michael Adam <ob...@samba.org>
Date:   Mon Jan 27 17:20:56 2014 +0100

    dbwrap: introduce DBWRAP_LOCK_ORDER_NONE for lock order "0".
    
    Ther are still some databases which are opened (locally) with
    lock oder 0, which means don't do lock oder checking,
    thereby circumventing this deadlock-prevention mechanism.
    
    Add a symbolic constant for this "0" to make this circumvention
    more explicit.
    
    Signed-off-by: Michael Adam <ob...@samba.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

commit 7e766a0a8ade1f018015684c22bda82595a33d38
Author: Michael Adam <ob...@samba.org>
Date:   Mon Jan 27 16:38:25 2014 +0100

    dbwrap: add dbwrap_flags argument to dbwrap_local_open()
    
    To be consistent with db_open() and prepare for future
    possible extensions.
    
    Signed-off-by: Michael Adam <ob...@samba.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

commit e4fbaadb5cadaa584f455d624eafe706703cda1a
Author: Michael Adam <ob...@samba.org>
Date:   Tue Jan 28 12:37:36 2014 +0100

    dbwrap: add a dbwrap_flags argument to db_open_ntdb()
    
    for consistency and to perpare for possible future
    flags that the ntdb backend might be aware of.
    
    Signed-off-by: Michael Adam <ob...@samba.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

commit bbf0903d6bf60afc38b75332e36d81868c05d22c
Author: Michael Adam <ob...@samba.org>
Date:   Tue Jan 28 12:33:42 2014 +0100

    dbwrap: add a dbwrap_flags argument to db_open_tdb()
    
    ...for consistency and in preparation of future flags
    that the tdb backend might be aware of.
    
    Signed-off-by: Michael Adam <ob...@samba.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

commit 906abe55cbc6f0e2daed93975411d4fc1ece5d3a
Author: Michael Adam <ob...@samba.org>
Date:   Mon Jan 27 16:19:52 2014 +0100

    s3:registry: introduce REG_DBWRAP_FLAGS to use for all db_open calls
    
    This is in accordance with the use of REG_TDB_FLAGS.
    
    Signed-off-by: Michael Adam <ob...@samba.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

commit 020fab300d2f4f19301eff19ad810c71f77bbb78
Author: Michael Adam <ob...@samba.org>
Date:   Mon Jan 27 16:21:14 2014 +0100

    s3:rpc_client: optimize the netlogon_creds_cli.tdb for read-only access
    
    Usually a record in this DB will be written once and then read
    many times by winbindd processes on multiple nodes (when run in
    a cluster). In order not to introduce a big performance penalty
    with the increased correctness achieved by storing the netlogon
    creds, in a cluster setup, we should activate ctdb's read only
    record copies on this db.
    
    Signed-off-by: Michael Adam <ob...@samba.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

commit a20c977c7a58a0c09d01bfa046c00fcd3f1462de
Author: Stefan Metzmacher <me...@samba.org>
Date:   Tue Jan 28 21:31:17 2014 +0100

    dbwrap_open: add 'dbwrap_optimize_readonly:* = yes' option
    
    Signed-off-by: Stefan Metzmacher <me...@samba.org>
    Reviewed-by: Michael Adam <ob...@samba.org>

commit a97b588b63f437d25c4344c76014326dbf0cbdb0
Author: Stefan Metzmacher <me...@samba.org>
Date:   Tue Jan 28 21:24:22 2014 +0100

    dbwrap_ctdb: implement DBWRAP_FLAG_OPTIMIZE_READONLY_ACCESS
    
    For non-persistent databases we try to use CTDB_CONTROL_SET_DB_READONLY
    in order to make use of readonly records.
    
    Pair-Programmed-With: Michael Adam <ob...@samba.org>
    
    Signed-off-by: Stefan Metzmacher <me...@samba.org>
    Signed-off-by: Michael Adam <ob...@samba.org>

commit 56bd4040889dfe492ff820497b7a6d76624a6048
Author: Michael Adam <ob...@samba.org>
Date:   Tue Jan 28 11:31:44 2014 +0100

    dbwrap: add DBWRAP_FLAG_OPTIMIZE_READONLY_ACCESS
    
    Signed-off-by: Michael Adam <ob...@samba.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

commit 6def1c3f6e145abcc81ea69505133bbe128eacac
Author: Michael Adam <ob...@samba.org>
Date:   Tue Jan 28 12:53:24 2014 +0100

    dbwrap: add a dbwrap_flags argument to db_open_ctdb()
    
    This is in preparation of directly supporting ctdb read only
    record copies when opening a ctdb database from samba.
    
    Signed-off-by: Michael Adam <ob...@samba.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

commit cf0cb0add9ed47b8974272237fee0e1a4ba7bf68
Author: Michael Adam <ob...@samba.org>
Date:   Mon Jan 27 14:49:12 2014 +0100

    dbwrap: add a dbwrap_flags argument to db_open()
    
    This is in preparation to support handing flags to backends,
    in particular activating read only record support for ctdb
    databases. For a start, this does nothing but adding the
    parameter, and all databases use DBWRAP_FLAG_NONE.
    
    Signed-off-by: Michael Adam <ob...@samba.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

commit 229dcfd3501e4743d5d9aea5c9f7a97d7612a499
Author: Michael Adam <ob...@samba.org>
Date:   Mon Jan 27 13:38:51 2014 +0100

    dbwrap: add flags DBWRAP_FLAG_NONE
    
    This is in preparation of adding a dbwrap_flags argument to db_open
    and firends.
    
    Signed-off-by: Michael Adam <ob...@samba.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

-----------------------------------------------------------------------

Summary of changes:
 auth/credentials/credentials_secrets.c   |    3 +-
 lib/dbwrap/dbwrap.c                      |    4 +-
 lib/dbwrap/dbwrap.h                      |   12 +++++++-
 lib/dbwrap/dbwrap_local_open.c           |   14 ++++++---
 lib/dbwrap/dbwrap_ntdb.c                 |    3 +-
 lib/dbwrap/dbwrap_ntdb.h                 |    3 +-
 lib/dbwrap/dbwrap_private.h              |    7 +++++
 lib/dbwrap/dbwrap_tdb.c                  |    3 +-
 lib/dbwrap/dbwrap_tdb.h                  |    3 +-
 libcli/auth/netlogon_creds_cli.c         |    3 +-
 libcli/auth/schannel_state_tdb.c         |    3 +-
 source3/groupdb/mapping_tdb.c            |    2 +-
 source3/lib/dbwrap/dbwrap_ctdb.c         |   27 +++++++++++++++++-
 source3/lib/dbwrap/dbwrap_ctdb.h         |    3 +-
 source3/lib/dbwrap/dbwrap_open.c         |   42 +++++++++++++++++++++--------
 source3/lib/dbwrap/dbwrap_open.h         |    3 +-
 source3/lib/dbwrap/dbwrap_watch.c        |    3 +-
 source3/lib/g_lock.c                     |    3 +-
 source3/lib/serverid.c                   |    3 +-
 source3/lib/sharesec.c                   |    2 +-
 source3/locking/brlock.c                 |    2 +-
 source3/locking/share_mode_lock.c        |    2 +-
 source3/modules/vfs_acl_tdb.c            |    2 +-
 source3/modules/vfs_xattr_tdb.c          |    2 +-
 source3/passdb/account_pol.c             |    4 +-
 source3/passdb/pdb_tdb.c                 |    6 ++--
 source3/passdb/secrets.c                 |    2 +-
 source3/printing/printer_list.c          |    3 +-
 source3/registry/reg_backend_db.c        |    6 ++--
 source3/registry/reg_db.h                |    1 +
 source3/rpc_client/cli_netlogon.c        |    3 +-
 source3/smbd/notify_internal.c           |    4 +-
 source3/smbd/smbXsrv_open.c              |    3 +-
 source3/smbd/smbXsrv_session.c           |    3 +-
 source3/smbd/smbXsrv_tcon.c              |    3 +-
 source3/smbd/smbXsrv_version.c           |    3 +-
 source3/torture/test_dbwrap_ctdb.c       |    2 +-
 source3/torture/test_dbwrap_watch.c      |    3 +-
 source3/torture/test_idmap_tdb_common.c  |    2 +-
 source3/torture/torture.c                |    3 +-
 source3/utils/dbwrap_tool.c              |    2 +-
 source3/utils/dbwrap_torture.c           |    2 +-
 source3/utils/net_idmap.c                |    8 +++---
 source3/utils/net_idmap_check.c          |    2 +-
 source3/utils/net_registry_check.c       |    4 +-
 source3/utils/status.c                   |    2 +-
 source3/winbindd/idmap_autorid_tdb.c     |    2 +-
 source3/winbindd/idmap_tdb.c             |    2 +-
 source3/winbindd/idmap_tdb2.c            |    2 +-
 source4/cluster/local.c                  |    2 +-
 source4/ntvfs/posix/python/pyxattr_tdb.c |    6 +++-
 51 files changed, 161 insertions(+), 78 deletions(-)


Changeset truncated at 500 lines:

diff --git a/auth/credentials/credentials_secrets.c 
b/auth/credentials/credentials_secrets.c
index 6c1cded..9fad104 100644
--- a/auth/credentials/credentials_secrets.c
+++ b/auth/credentials/credentials_secrets.c
@@ -255,7 +255,8 @@ _PUBLIC_ NTSTATUS 
cli_credentials_set_machine_account(struct cli_credentials *cr
                
        db_ctx = dbwrap_local_open(cred, lp_ctx, secrets_tdb, 0,
                                   TDB_DEFAULT, O_RDWR, 0600,
-                                  DBWRAP_LOCK_ORDER_1);
+                                  DBWRAP_LOCK_ORDER_1,
+                                  DBWRAP_FLAG_NONE);
        /* Bleh, nasty recursion issues: We are setting a machine
         * account here, so we don't want the 'pending' flag around
         * any more */
diff --git a/lib/dbwrap/dbwrap.c b/lib/dbwrap/dbwrap.c
index 8270b63..d75c714 100644
--- a/lib/dbwrap/dbwrap.c
+++ b/lib/dbwrap/dbwrap.c
@@ -167,7 +167,7 @@ static struct dbwrap_lock_order_state 
*dbwrap_check_lock_order(
        static struct db_context *locked_dbs[DBWRAP_LOCK_ORDER_MAX];
        struct dbwrap_lock_order_state *state = NULL;
 
-       if (db->lock_order > DBWRAP_LOCK_ORDER_MAX) {
+       if (!DBWRAP_LOCK_ORDER_VALID(db->lock_order)) {
                DEBUG(0,("Invalid lock order %d of %s\n",
                         (int)db->lock_order, db->name));
                smb_panic("invalid lock_order\n");
@@ -212,7 +212,7 @@ static struct db_record *dbwrap_fetch_locked_internal(
        struct db_record *rec;
        struct dbwrap_lock_order_state *lock_order = NULL;
 
-       if (db->lock_order != 0) {
+       if (db->lock_order != DBWRAP_LOCK_ORDER_NONE) {
                lock_order = dbwrap_check_lock_order(db, mem_ctx);
                if (lock_order == NULL) {
                        return NULL;
diff --git a/lib/dbwrap/dbwrap.h b/lib/dbwrap/dbwrap.h
index 8bf3286..d289243 100644
--- a/lib/dbwrap/dbwrap.h
+++ b/lib/dbwrap/dbwrap.h
@@ -26,11 +26,18 @@ struct db_record;
 struct db_context;
 
 enum dbwrap_lock_order {
+       DBWRAP_LOCK_ORDER_NONE = 0, /* Don't check lock orders for this db. */
+       /*
+        * We only allow orders 1, 2, 3:
+        * These are the orders that CTDB currently supports.
+        */
        DBWRAP_LOCK_ORDER_1 = 1,
        DBWRAP_LOCK_ORDER_2 = 2,
        DBWRAP_LOCK_ORDER_3 = 3
 };
-#define DBWRAP_LOCK_ORDER_MAX DBWRAP_LOCK_ORDER_3
+
+#define DBWRAP_FLAG_NONE                     0x0000000000000000ULL
+#define DBWRAP_FLAG_OPTIMIZE_READONLY_ACCESS 0x0000000000000001ULL
 
 /* The following definitions come from lib/dbwrap.c  */
 
@@ -157,6 +164,7 @@ struct db_context *dbwrap_local_open(TALLOC_CTX *mem_ctx,
                                     const char *name,
                                     int hash_size, int tdb_flags,
                                     int open_flags, mode_t mode,
-                                    enum dbwrap_lock_order lock_order);
+                                    enum dbwrap_lock_order lock_order,
+                                    uint64_t dbwrap_flags);
 
 #endif /* __DBWRAP_H__ */
diff --git a/lib/dbwrap/dbwrap_local_open.c b/lib/dbwrap/dbwrap_local_open.c
index 56048af..6e40139 100644
--- a/lib/dbwrap/dbwrap_local_open.c
+++ b/lib/dbwrap/dbwrap_local_open.c
@@ -103,7 +103,8 @@ static bool tdb_to_ntdb(TALLOC_CTX *ctx, struct 
loadparm_context *lp_ctx,
                return false;
        }
        tdb = db_open_tdb(ctx, lp_ctx, tdbname, 0,
-                         TDB_DEFAULT, O_RDONLY, 0, 0);
+                         TDB_DEFAULT, O_RDONLY, 0, DBWRAP_LOCK_ORDER_NONE,
+                         DBWRAP_FLAG_NONE);
        if (!tdb) {
                DEBUG(0, ("tdb_to_ntdb: could not open %s: %s\n",
                          tdbname, strerror(errno)));
@@ -111,7 +112,8 @@ static bool tdb_to_ntdb(TALLOC_CTX *ctx, struct 
loadparm_context *lp_ctx,
        }
        ntdb = db_open_ntdb(ctx, lp_ctx, ntdbname, dbwrap_hash_size(tdb),
                            TDB_DEFAULT, O_RDWR|O_CREAT|O_EXCL,
-                           st.st_mode & 0777, 0);
+                           st.st_mode & 0777, DBWRAP_LOCK_ORDER_NONE,
+                           DBWRAP_FLAG_NONE);
        if (!ntdb) {
                DEBUG(0, ("tdb_to_ntdb: could not create %s: %s\n",
                          ntdbname, strerror(errno)));
@@ -160,7 +162,8 @@ struct db_context *dbwrap_local_open(TALLOC_CTX *mem_ctx,
                                     const char *name,
                                     int hash_size, int tdb_flags,
                                     int open_flags, mode_t mode,
-                                    enum dbwrap_lock_order lock_order)
+                                    enum dbwrap_lock_order lock_order,
+                                    uint64_t dbwrap_flags)
 {
        TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
        const char *ntdbname, *tdbname;
@@ -204,7 +207,8 @@ struct db_context *dbwrap_local_open(TALLOC_CTX *mem_ctx,
                        }
                }
                db = db_open_ntdb(mem_ctx, lp_ctx, ntdbname, hash_size,
-                                 ntdb_flags, open_flags, mode, lock_order);
+                                 ntdb_flags, open_flags, mode, lock_order,
+                                 dbwrap_flags);
        } else {
                if (!streq(ntdbname, tdbname) && file_exist(ntdbname)) {
                        DEBUG(0, ("Refusing to open '%s' when '%s' exists\n",
@@ -213,7 +217,7 @@ struct db_context *dbwrap_local_open(TALLOC_CTX *mem_ctx,
                }
                db = db_open_tdb(mem_ctx, lp_ctx, tdbname, hash_size,
                                 tdb_flags, open_flags, mode,
-                                lock_order);
+                                lock_order, dbwrap_flags);
        }
 out:
        talloc_free(tmp_ctx);
diff --git a/lib/dbwrap/dbwrap_ntdb.c b/lib/dbwrap/dbwrap_ntdb.c
index 48fe39e..5be5414 100644
--- a/lib/dbwrap/dbwrap_ntdb.c
+++ b/lib/dbwrap/dbwrap_ntdb.c
@@ -502,7 +502,8 @@ struct db_context *db_open_ntdb(TALLOC_CTX *mem_ctx,
                                const char *ntdbname,
                                int hash_size, int ntdb_flags,
                                int open_flags, mode_t mode,
-                               enum dbwrap_lock_order lock_order)
+                               enum dbwrap_lock_order lock_order,
+                               uint64_t dbwrap_flags)
 {
        struct db_context *result = NULL;
        struct db_ntdb_ctx *db_ntdb;
diff --git a/lib/dbwrap/dbwrap_ntdb.h b/lib/dbwrap/dbwrap_ntdb.h
index b00a567..a1da1bc 100644
--- a/lib/dbwrap/dbwrap_ntdb.h
+++ b/lib/dbwrap/dbwrap_ntdb.h
@@ -30,6 +30,7 @@ struct db_context *db_open_ntdb(TALLOC_CTX *mem_ctx,
                                const char *name,
                                int hash_size, int ntdb_flags,
                                int open_flags, mode_t mode,
-                               enum dbwrap_lock_order lock_order);
+                               enum dbwrap_lock_order lock_order,
+                               uint64_t dbwrap_flags);
 
 #endif /* __DBWRAP_NTDB_H__ */
diff --git a/lib/dbwrap/dbwrap_private.h b/lib/dbwrap/dbwrap_private.h
index da904f0..a6bad04 100644
--- a/lib/dbwrap/dbwrap_private.h
+++ b/lib/dbwrap/dbwrap_private.h
@@ -69,5 +69,12 @@ struct db_context {
        void *stored_callback_private_data;
 };
 
+#define DBWRAP_LOCK_ORDER_MIN DBWRAP_LOCK_ORDER_1
+#define DBWRAP_LOCK_ORDER_MAX DBWRAP_LOCK_ORDER_3
+
+#define DBWRAP_LOCK_ORDER_VALID(order) \
+       (((order) >= DBWRAP_LOCK_ORDER_MIN) && \
+        ((order) <= DBWRAP_LOCK_ORDER_MAX))
+
 #endif /* __DBWRAP_PRIVATE_H__ */
 
diff --git a/lib/dbwrap/dbwrap_tdb.c b/lib/dbwrap/dbwrap_tdb.c
index 3f21192..1b061e3 100644
--- a/lib/dbwrap/dbwrap_tdb.c
+++ b/lib/dbwrap/dbwrap_tdb.c
@@ -401,7 +401,8 @@ struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx,
                               const char *name,
                               int hash_size, int tdb_flags,
                               int open_flags, mode_t mode,
-                              enum dbwrap_lock_order lock_order)
+                              enum dbwrap_lock_order lock_order,
+                              uint64_t dbrwap_flags)
 {
        struct db_context *result = NULL;
        struct db_tdb_ctx *db_tdb;
diff --git a/lib/dbwrap/dbwrap_tdb.h b/lib/dbwrap/dbwrap_tdb.h
index 6a6da45..93ee09c 100644
--- a/lib/dbwrap/dbwrap_tdb.h
+++ b/lib/dbwrap/dbwrap_tdb.h
@@ -29,7 +29,8 @@ struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx,
                               const char *name,
                               int hash_size, int tdb_flags,
                               int open_flags, mode_t mode,
-                              enum dbwrap_lock_order lock_order);
+                              enum dbwrap_lock_order lock_order,
+                              uint64_t dbwrap_flags);
 
 
 #endif /* __DBWRAP_TDB_H__ */
diff --git a/libcli/auth/netlogon_creds_cli.c b/libcli/auth/netlogon_creds_cli.c
index 88893ad..d73335d 100644
--- a/libcli/auth/netlogon_creds_cli.c
+++ b/libcli/auth/netlogon_creds_cli.c
@@ -227,7 +227,8 @@ NTSTATUS netlogon_creds_cli_open_global_db(struct 
loadparm_context *lp_ctx)
                                      fname, 0,
                                      TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
                                      O_RDWR|O_CREAT,
-                                     0600, DBWRAP_LOCK_ORDER_2);
+                                     0600, DBWRAP_LOCK_ORDER_2,
+                                     DBWRAP_FLAG_NONE);
        if (global_db == NULL) {
                DEBUG(0,("netlogon_creds_cli_open_global_db: Failed to open %s 
- %s\n",
                         fname, strerror(errno)));
diff --git a/libcli/auth/schannel_state_tdb.c b/libcli/auth/schannel_state_tdb.c
index 6669b46..2d3481d 100644
--- a/libcli/auth/schannel_state_tdb.c
+++ b/libcli/auth/schannel_state_tdb.c
@@ -49,7 +49,8 @@ struct db_context *open_schannel_session_store(TALLOC_CTX 
*mem_ctx,
 
        db_sc = dbwrap_local_open(mem_ctx, lp_ctx, fname, 0,
                                  TDB_CLEAR_IF_FIRST|TDB_NOSYNC, O_RDWR|O_CREAT,
-                                 0600, 0);
+                                 0600, DBWRAP_LOCK_ORDER_NONE,
+                                 DBWRAP_FLAG_NONE);
 
        if (!db_sc) {
                DEBUG(0,("open_schannel_session_store: Failed to open %s - 
%s\n",
diff --git a/source3/groupdb/mapping_tdb.c b/source3/groupdb/mapping_tdb.c
index 3cb1024..cc397d9 100644
--- a/source3/groupdb/mapping_tdb.c
+++ b/source3/groupdb/mapping_tdb.c
@@ -54,7 +54,7 @@ static bool init_group_mapping(void)
 
        db = db_open(NULL, state_path("group_mapping.tdb"), 0,
                     TDB_DEFAULT, O_RDWR|O_CREAT, 0600,
-                    DBWRAP_LOCK_ORDER_1);
+                    DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
        if (db == NULL) {
                DEBUG(0, ("Failed to open group mapping database: %s\n",
                          strerror(errno)));
diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c
index 98a9138..87e644d 100644
--- a/source3/lib/dbwrap/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap/dbwrap_ctdb.c
@@ -1569,7 +1569,8 @@ struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
                                const char *name,
                                int hash_size, int tdb_flags,
                                int open_flags, mode_t mode,
-                               enum dbwrap_lock_order lock_order)
+                               enum dbwrap_lock_order lock_order,
+                               uint64_t dbwrap_flags)
 {
        struct db_context *result;
        struct db_ctdb_ctx *db_ctdb;
@@ -1648,6 +1649,27 @@ struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
                return NULL;
        }
 
+#ifdef HAVE_CTDB_WANT_READONLY_DECL
+       if (!result->persistent &&
+           (dbwrap_flags & DBWRAP_FLAG_OPTIMIZE_READONLY_ACCESS))
+       {
+               TDB_DATA indata;
+
+               indata = make_tdb_data((uint8_t *)&db_ctdb->db_id,
+                                      sizeof(db_ctdb->db_id));
+
+               status = ctdbd_control_local(
+                       conn, CTDB_CONTROL_SET_DB_READONLY, 0, 0, indata,
+                       NULL, NULL, &cstatus);
+               if (!NT_STATUS_IS_OK(status) || (cstatus != 0)) {
+                       DEBUG(1, ("CTDB_CONTROL_SET_DB_READONLY failed: "
+                                 "%s, %d\n", nt_errstr(status), cstatus));
+                       TALLOC_FREE(result);
+                       return NULL;
+               }
+       }
+#endif
+
        lp_ctx = loadparm_init_s3(db_path, loadparm_s3_helpers());
 
        db_ctdb->wtdb = tdb_wrap_open(db_ctdb, db_path, hash_size, tdb_flags,
@@ -1703,7 +1725,8 @@ struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
                                const char *name,
                                int hash_size, int tdb_flags,
                                int open_flags, mode_t mode,
-                               enum dbwrap_lock_order lock_order)
+                               enum dbwrap_lock_order lock_order,
+                               uint64_t dbwrap_flags)
 {
        DEBUG(3, ("db_open_ctdb: no cluster support!\n"));
        errno = ENOSYS;
diff --git a/source3/lib/dbwrap/dbwrap_ctdb.h b/source3/lib/dbwrap/dbwrap_ctdb.h
index bfbe3bd..3196b91 100644
--- a/source3/lib/dbwrap/dbwrap_ctdb.h
+++ b/source3/lib/dbwrap/dbwrap_ctdb.h
@@ -31,6 +31,7 @@ struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
                                const char *name,
                                int hash_size, int tdb_flags,
                                int open_flags, mode_t mode,
-                               enum dbwrap_lock_order lock_order);
+                               enum dbwrap_lock_order lock_order,
+                               uint64_t dbwrap_flags);
 
 #endif /* __DBWRAP_CTDB_H__ */
diff --git a/source3/lib/dbwrap/dbwrap_open.c b/source3/lib/dbwrap/dbwrap_open.c
index 515b4bf..3c8756b 100644
--- a/source3/lib/dbwrap/dbwrap_open.c
+++ b/source3/lib/dbwrap/dbwrap_open.c
@@ -60,26 +60,44 @@ struct db_context *db_open(TALLOC_CTX *mem_ctx,
                           const char *name,
                           int hash_size, int tdb_flags,
                           int open_flags, mode_t mode,
-                          enum dbwrap_lock_order lock_order)
+                          enum dbwrap_lock_order lock_order,
+                          uint64_t dbwrap_flags)
 {
        struct db_context *result = NULL;
 #ifdef CLUSTER_SUPPORT
        const char *sockname;
 #endif
 
-       switch (lock_order) {
-       case DBWRAP_LOCK_ORDER_1:
-       case DBWRAP_LOCK_ORDER_2:
-       case DBWRAP_LOCK_ORDER_3:
-               break;
-       default:
-               /*
-                * Only allow the 3 levels ctdb gives us.
-                */
+       if (!DBWRAP_LOCK_ORDER_VALID(lock_order)) {
                errno = EINVAL;
                return NULL;
        }
 
+       if (tdb_flags & TDB_CLEAR_IF_FIRST) {
+               const char *base;
+               bool try_readonly = false;
+
+               base = strrchr_m(name, '/');
+               if (base != NULL) {
+                       base += 1;
+               } else {
+                       base = name;
+               }
+
+               if (dbwrap_flags & DBWRAP_FLAG_OPTIMIZE_READONLY_ACCESS) {
+                       try_readonly = true;
+               }
+
+               try_readonly = lp_parm_bool(-1, "dbwrap_optimize_readonly", 
"*", try_readonly);
+               try_readonly = lp_parm_bool(-1, "dbwrap_optimize_readonly", 
base, try_readonly);
+
+               if (try_readonly) {
+                       dbwrap_flags |= DBWRAP_FLAG_OPTIMIZE_READONLY_ACCESS;
+               } else {
+                       dbwrap_flags &= ~DBWRAP_FLAG_OPTIMIZE_READONLY_ACCESS;
+               }
+       }
+
 #ifdef CLUSTER_SUPPORT
        sockname = lp_ctdbd_socket();
 
@@ -103,7 +121,7 @@ struct db_context *db_open(TALLOC_CTX *mem_ctx,
                if (lp_parm_bool(-1, "ctdb", partname, True)) {
                        result = db_open_ctdb(mem_ctx, partname, hash_size,
                                              tdb_flags, open_flags, mode,
-                                             lock_order);
+                                             lock_order, dbwrap_flags);
                        if (result == NULL) {
                                DEBUG(0,("failed to attach to ctdb %s\n",
                                         partname));
@@ -121,7 +139,7 @@ struct db_context *db_open(TALLOC_CTX *mem_ctx,
                struct loadparm_context *lp_ctx = loadparm_init_s3(mem_ctx, 
loadparm_s3_helpers());
                result = dbwrap_local_open(mem_ctx, lp_ctx, name, hash_size,
                                           tdb_flags, open_flags, mode,
-                                          lock_order);
+                                          lock_order, dbwrap_flags);
                talloc_unlink(mem_ctx, lp_ctx);
        }
        return result;
diff --git a/source3/lib/dbwrap/dbwrap_open.h b/source3/lib/dbwrap/dbwrap_open.h
index 51c7dfd..d14794e 100644
--- a/source3/lib/dbwrap/dbwrap_open.h
+++ b/source3/lib/dbwrap/dbwrap_open.h
@@ -39,6 +39,7 @@ struct db_context *db_open(TALLOC_CTX *mem_ctx,
                           const char *name,
                           int hash_size, int tdb_flags,
                           int open_flags, mode_t mode,
-                          enum dbwrap_lock_order lock_order);
+                          enum dbwrap_lock_order lock_order,
+                          uint64_t dbwrap_flags);
 
 #endif /* __DBWRAP_OPEN_H__ */
diff --git a/source3/lib/dbwrap/dbwrap_watch.c 
b/source3/lib/dbwrap/dbwrap_watch.c
index b586b66..ba4381e 100644
--- a/source3/lib/dbwrap/dbwrap_watch.c
+++ b/source3/lib/dbwrap/dbwrap_watch.c
@@ -33,7 +33,8 @@ static struct db_context *dbwrap_record_watchers_db(void)
                watchers_db = db_open(
                        NULL, lock_path("dbwrap_watchers.tdb"), 0,
                        TDB_CLEAR_IF_FIRST | TDB_INCOMPATIBLE_HASH,
-                       O_RDWR|O_CREAT, 0600, DBWRAP_LOCK_ORDER_3);
+                       O_RDWR|O_CREAT, 0600, DBWRAP_LOCK_ORDER_3,
+                       DBWRAP_FLAG_NONE);
        }
        return watchers_db;
 }
diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c
index 8c7a6c2..6813f06 100644
--- a/source3/lib/g_lock.c
+++ b/source3/lib/g_lock.c
@@ -61,7 +61,8 @@ struct g_lock_ctx *g_lock_ctx_init(TALLOC_CTX *mem_ctx,
        result->db = db_open(result, lock_path("g_lock.tdb"), 0,
                             TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
                             O_RDWR|O_CREAT, 0600,
-                            DBWRAP_LOCK_ORDER_2);
+                            DBWRAP_LOCK_ORDER_2,
+                            DBWRAP_FLAG_NONE);
        if (result->db == NULL) {
                DEBUG(1, ("g_lock_init: Could not open g_lock.tdb\n"));
                TALLOC_FREE(result);
diff --git a/source3/lib/serverid.c b/source3/lib/serverid.c
index cb49520..4259887 100644
--- a/source3/lib/serverid.c
+++ b/source3/lib/serverid.c
@@ -77,7 +77,8 @@ static struct db_context *serverid_db(void)
        }
        db = db_open(NULL, lock_path("serverid.tdb"), 0,
                     TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
-                    O_RDWR|O_CREAT, 0644, DBWRAP_LOCK_ORDER_2);
+                    O_RDWR|O_CREAT, 0644, DBWRAP_LOCK_ORDER_2,
+                    DBWRAP_FLAG_NONE);
        return db;
 }
 
diff --git a/source3/lib/sharesec.c b/source3/lib/sharesec.c
index c7a8e51..095c851 100644
--- a/source3/lib/sharesec.c
+++ b/source3/lib/sharesec.c
@@ -149,7 +149,7 @@ bool share_info_db_init(void)
 
        share_db = db_open(NULL, state_path("share_info.tdb"), 0,
                           TDB_DEFAULT, O_RDWR|O_CREAT, 0600,
-                          DBWRAP_LOCK_ORDER_1);
+                          DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
        if (share_db == NULL) {
                DEBUG(0,("Failed to open share info database %s (%s)\n",
                        state_path("share_info.tdb"), strerror(errno) ));
diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c
index e1f0c15..a516b60 100644
--- a/source3/locking/brlock.c
+++ b/source3/locking/brlock.c
@@ -328,7 +328,7 @@ void brl_init(bool read_only)
        brlock_db = db_open(NULL, lock_path("brlock.tdb"),
                            SMB_OPEN_DATABASE_TDB_HASH_SIZE, tdb_flags,
                            read_only?O_RDONLY:(O_RDWR|O_CREAT), 0644,
-                           DBWRAP_LOCK_ORDER_2);
+                           DBWRAP_LOCK_ORDER_2, DBWRAP_FLAG_NONE);
        if (!brlock_db) {
                DEBUG(0,("Failed to open byte range locking database %s\n",
                        lock_path("brlock.tdb")));
diff --git a/source3/locking/share_mode_lock.c 
b/source3/locking/share_mode_lock.c
index 20756bf..5d0874c 100644
--- a/source3/locking/share_mode_lock.c
+++ b/source3/locking/share_mode_lock.c
@@ -67,7 +67,7 @@ static bool locking_init_internal(bool read_only)
                          SMB_OPEN_DATABASE_TDB_HASH_SIZE,
                          
TDB_DEFAULT|TDB_VOLATILE|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
                          read_only?O_RDONLY:O_RDWR|O_CREAT, 0644,
-                         DBWRAP_LOCK_ORDER_1);
+                         DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
 
        if (!lock_db) {
                DEBUG(0,("ERROR: Failed to initialise locking database\n"));
diff --git a/source3/modules/vfs_acl_tdb.c b/source3/modules/vfs_acl_tdb.c
index 80839e3..8ee4bd5 100644
--- a/source3/modules/vfs_acl_tdb.c
+++ b/source3/modules/vfs_acl_tdb.c
@@ -60,7 +60,7 @@ static bool acl_tdb_init(void)
 
        become_root();
        acl_db = db_open(NULL, dbname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600,
-                        DBWRAP_LOCK_ORDER_1);
+                        DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
        unbecome_root();
 
        if (acl_db == NULL) {
diff --git a/source3/modules/vfs_xattr_tdb.c b/source3/modules/vfs_xattr_tdb.c
index 43456cf..63a12fd 100644
--- a/source3/modules/vfs_xattr_tdb.c
+++ b/source3/modules/vfs_xattr_tdb.c
@@ -320,7 +320,7 @@ static bool xattr_tdb_init(int snum, TALLOC_CTX *mem_ctx, 
struct db_context **p_
 
        become_root();
        db = db_open(NULL, dbname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600,
-                    DBWRAP_LOCK_ORDER_2);
+                    DBWRAP_LOCK_ORDER_2, DBWRAP_FLAG_NONE);
        unbecome_root();
 
        if (db == NULL) {
diff --git a/source3/passdb/account_pol.c b/source3/passdb/account_pol.c
index 06925e8..5f2c7ab 100644
--- a/source3/passdb/account_pol.c


-- 
Samba Shared Repository

Reply via email to