Change to using TDB_INCOMPATIBLE_HASH (the jenkins hash) on all
authorJeremy Allison <jra@samba.org>
Mon, 27 Sep 2010 12:46:07 +0000 (05:46 -0700)
committerJeremy Allison <jra@samba.org>
Tue, 28 Sep 2010 00:18:54 +0000 (17:18 -0700)
TDB_CLEAR_IF_FIRST tdb's. For tdb's like gencache where we open
without CLEAR_IF_FIRST and then with CLEAR_IF_FIRST if corrupt
this is still safe to use as if opening an existing tdb the new
hash will be ignored - it's only used on creating a new tdb not
opening an old one.

Jeremy.

18 files changed:
source3/lib/conn_tdb.c
source3/lib/g_lock.c
source3/lib/gencache.c
source3/lib/messages_local.c
source3/lib/serverid.c
source3/lib/sessionid_tdb.c
source3/libsmb/samlogon_cache.c
source3/libsmb/smb_share_modes.c
source3/libsmb/unexpected.c
source3/locking/brlock.c
source3/locking/locking.c
source3/nmbd/nmbd_winsserver.c
source3/printing/printer_list.c
source3/smbd/notify_internal.c
source3/utils/dbwrap_torture.c
source3/utils/smbcontrol.c
source3/utils/status.c
source3/winbindd/winbindd_cache.c

index 75841cce65779b5536fe056f5054ad53985e4227..e4c5e720144e7a2c19e2ab7fcc8c5dbd3a1eba8e 100644 (file)
@@ -33,7 +33,7 @@ static struct db_context *connections_db_ctx(bool rw)
        open_flags = rw ? (O_RDWR|O_CREAT) : O_RDONLY;
 
        db_ctx = db_open(NULL, lock_path("connections.tdb"), 0,
-                        TDB_CLEAR_IF_FIRST|TDB_DEFAULT, open_flags, 0644);
+                        TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH|TDB_DEFAULT, open_flags, 0644);
        return db_ctx;
 }
 
index edb77869cc0b784fb9274d2f8b0b8fdadd50ea88..2c065029e7af3463693c7294457bfe76026ef5e4 100644 (file)
@@ -53,7 +53,7 @@ struct g_lock_ctx *g_lock_ctx_init(TALLOC_CTX *mem_ctx,
        result->msg = msg;
 
        result->db = db_open(result, lock_path("g_lock.tdb"), 0,
-                            TDB_CLEAR_IF_FIRST, O_RDWR|O_CREAT, 0700);
+                            TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDWR|O_CREAT, 0700);
        if (result->db == NULL) {
                DEBUG(1, ("g_lock_init: Could not open g_lock.tdb"));
                TALLOC_FREE(result);
index a78e60a15315efe302cd86b772c6e49365350d17..8d2ddb23871d55497a93ba92a8adc0d3bbbf0730 100644 (file)
@@ -65,7 +65,7 @@ static bool gencache_init(void)
        DEBUG(5, ("Opening cache file at %s\n", cache_fname));
 
 again:
-       cache = tdb_open_log(cache_fname, 0, TDB_DEFAULT, open_flags, 0644);
+       cache = tdb_open_log(cache_fname, 0, TDB_DEFAULT|TDB_INCOMPATIBLE_HASH, open_flags, 0644);
        if (cache) {
                int ret;
                ret = tdb_check(cache, NULL, NULL);
@@ -80,7 +80,7 @@ again:
                        first_try = false;
                        DEBUG(0, ("gencache_init: tdb_check(%s) failed - retry after CLEAR_IF_FIRST\n",
                                  cache_fname));
-                       cache = tdb_open_log(cache_fname, 0, TDB_CLEAR_IF_FIRST, open_flags, 0644);
+                       cache = tdb_open_log(cache_fname, 0, TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, open_flags, 0644);
                        if (cache) {
                                tdb_close(cache);
                                cache = NULL;
@@ -91,7 +91,7 @@ again:
 
        if (!cache && (errno == EACCES)) {
                open_flags = O_RDONLY;
-               cache = tdb_open_log(cache_fname, 0, TDB_DEFAULT, open_flags,
+               cache = tdb_open_log(cache_fname, 0, TDB_DEFAULT|TDB_INCOMPATIBLE_HASH, open_flags,
                                     0644);
                if (cache) {
                        DEBUG(5, ("gencache_init: Opening cache file %s read-only.\n", cache_fname));
@@ -107,7 +107,7 @@ again:
 
        DEBUG(5, ("Opening cache file at %s\n", cache_fname));
 
-       cache_notrans = tdb_open_log(cache_fname, 0, TDB_CLEAR_IF_FIRST,
+       cache_notrans = tdb_open_log(cache_fname, 0, TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
                                     open_flags, 0644);
        if (cache_notrans == NULL) {
                DEBUG(5, ("Opening %s failed: %s\n", cache_fname,
index 542d49e2dd7c1fa3bdf9c7ea207ae1f293231d7f..bad577cc356331dc95e7a6860eeb1dcb73ec1537 100644 (file)
@@ -103,7 +103,7 @@ NTSTATUS messaging_tdb_init(struct messaging_context *msg_ctx,
        ctx->msg_ctx = msg_ctx;
 
        ctx->tdb = tdb_wrap_open(ctx, lock_path("messages.tdb"), 0,
-                                TDB_CLEAR_IF_FIRST|TDB_DEFAULT|TDB_VOLATILE,
+                                TDB_CLEAR_IF_FIRST|TDB_DEFAULT|TDB_VOLATILE|TDB_INCOMPATIBLE_HASH,
                                 O_RDWR|O_CREAT,0600);
 
        if (!ctx->tdb) {
@@ -144,7 +144,7 @@ bool messaging_tdb_parent_init(TALLOC_CTX *mem_ctx)
         */
 
        db = tdb_wrap_open(mem_ctx, lock_path("messages.tdb"), 0,
-                          TDB_CLEAR_IF_FIRST|TDB_DEFAULT|TDB_VOLATILE,
+                          TDB_CLEAR_IF_FIRST|TDB_DEFAULT|TDB_VOLATILE|TDB_INCOMPATIBLE_HASH,
                           O_RDWR|O_CREAT,0600);
        if (db == NULL) {
                DEBUG(1, ("could not open messaging.tdb: %s\n",
index f0c61aeb82a030383f4d06414003a962321ace24..dd02e51a219f60033ff1535ff67d04b5510e1b7e 100644 (file)
@@ -44,7 +44,7 @@ bool serverid_parent_init(TALLOC_CTX *mem_ctx)
         */
 
        db = tdb_wrap_open(mem_ctx, lock_path("serverid.tdb"),
-                          0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST, O_RDWR|O_CREAT,
+                          0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDWR|O_CREAT,
                           0644);
        if (db == NULL) {
                DEBUG(1, ("could not open serverid.tdb: %s\n",
@@ -62,7 +62,7 @@ static struct db_context *serverid_db(void)
                return db;
        }
        db = db_open(NULL, lock_path("serverid.tdb"), 0,
-                    TDB_DEFAULT|TDB_CLEAR_IF_FIRST, O_RDWR|O_CREAT, 0644);
+                    TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDWR|O_CREAT, 0644);
        return db;
 }
 
index 1515728bd941ef2da0aaae7d51c4fc7b6a497916..fe67681d189802b14c8ec7f8bfae225227877098 100644 (file)
@@ -29,7 +29,7 @@ static struct db_context *session_db_ctx(void)
        }
 
        session_db_ctx_ptr = db_open(NULL, lock_path("sessionid.tdb"), 0,
-                                    TDB_CLEAR_IF_FIRST|TDB_DEFAULT,
+                                    TDB_CLEAR_IF_FIRST|TDB_DEFAULT|TDB_INCOMPATIBLE_HASH,
                                     O_RDWR | O_CREAT, 0644);
        return session_db_ctx_ptr;
 }
index 7f096ece76f1909dbaf2c1a816fc4b7c65285cfd..45354f1c77e4a086f6f0582796b1adf14d0fbc5b 100644 (file)
@@ -45,7 +45,7 @@ bool netsamlogon_cache_init(void)
 
        path = cache_path(NETSAMLOGON_TDB);
 again:
-       tdb = tdb_open_log(path, 0, TDB_DEFAULT,
+       tdb = tdb_open_log(path, 0, TDB_DEFAULT|TDB_INCOMPATIBLE_HASH,
                           O_RDWR | O_CREAT, 0600);
        if (tdb == NULL) {
                DEBUG(0,("tdb_open_log('%s') - failed\n", path));
@@ -69,7 +69,7 @@ clear:
        first_try = false;
 
        DEBUG(0,("retry after CLEAR_IF_FIRST for '%s'\n", path));
-       tdb = tdb_open_log(path, 0, TDB_CLEAR_IF_FIRST,
+       tdb = tdb_open_log(path, 0, TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
                           O_RDWR | O_CREAT, 0600);
        if (tdb) {
                tdb_close(tdb);
index 177e0114b3de25d5011bd61e7f1accf31edce1f0..9f985501b6f930d2573616fb9ef7b3018fe74d30 100644 (file)
@@ -67,7 +67,7 @@ struct smbdb_ctx *smb_share_mode_db_open(const char *db_path)
        memset(smb_db, '\0', sizeof(struct smbdb_ctx));
 
        smb_db->smb_tdb = tdb_open(db_path,
-                               0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST,
+                               0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
                                O_RDWR|O_CREAT,
                                0644);
 
index 1ac45ec84b20f58178f6711330d64643f7e550da..17ebcd22ab3a4e8c9e60b08542eb85b032f5aa37 100644 (file)
@@ -47,7 +47,7 @@ void unexpected_packet(struct packet_struct *p)
        if (!tdbd) {
                tdbd = tdb_wrap_open(talloc_autofree_context(),
                                     lock_path("unexpected.tdb"), 0,
-                                    TDB_CLEAR_IF_FIRST|TDB_DEFAULT,
+                                    TDB_CLEAR_IF_FIRST|TDB_DEFAULT|TDB_INCOMPATIBLE_HASH,
                                     O_RDWR | O_CREAT, 0644);
                if (!tdbd) {
                        DEBUG(0,("Failed to open unexpected.tdb\n"));
index 408917ef2ec74675f67633d5780d79ac178a9d23..3cb94871cc24e4ee4e6832d84821f12be0340f4a 100644 (file)
@@ -273,7 +273,7 @@ void brl_init(bool read_only)
                return;
        }
 
-       tdb_flags = TDB_DEFAULT|TDB_VOLATILE|TDB_CLEAR_IF_FIRST;
+       tdb_flags = TDB_DEFAULT|TDB_VOLATILE|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH;
 
        if (!lp_clustering()) {
                /*
index 89bd19a7105c2e25556b0314356baa64115dc966..ed07d7a25a6be0c03e450c5d9059a27892068757 100644 (file)
@@ -437,7 +437,7 @@ static bool locking_init_internal(bool read_only)
 
        lock_db = db_open(NULL, lock_path("locking.tdb"),
                          lp_open_files_db_hash_size(),
-                         TDB_DEFAULT|TDB_VOLATILE|TDB_CLEAR_IF_FIRST,
+                         TDB_DEFAULT|TDB_VOLATILE|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
                          read_only?O_RDONLY:O_RDWR|O_CREAT, 0644);
 
        if (!lock_db) {
index 5f3a9c39bf3744e653964543d66b4ec71ebbd9e6..d4580e41c50f619a2c6124dffb7c098ea4998582 100644 (file)
@@ -604,7 +604,8 @@ bool initialise_wins(void)
        }
 
        /* Open the wins.tdb. */
-       wins_tdb = tdb_open_log(state_path("wins.tdb"), 0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST, O_CREAT|O_RDWR, 0600);
+       wins_tdb = tdb_open_log(state_path("wins.tdb"), 0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
+                       O_CREAT|O_RDWR, 0600);
        if (!wins_tdb) {
                DEBUG(0,("initialise_wins: failed to open wins.tdb. Error was %s\n",
                        strerror(errno) ));
index f52dfcffa5ff9764f0a5ec44cb68e3d9c0c56df7..667ff70a052c3ec4bf9537ffd26df8050f72ef63 100644 (file)
@@ -36,7 +36,7 @@ static struct db_context *get_printer_list_db(void)
                return db;
        }
        db = db_open(talloc_autofree_context(), PL_DB_NAME(), 0,
-                    TDB_DEFAULT|TDB_CLEAR_IF_FIRST,
+                    TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
                     O_RDWR|O_CREAT, 0644);
        return db;
 }
index 1dc10bbab5f86083ac807f86a38b0d978e3d7376..acb438b1189d403c43e278e758295a7509831309 100644 (file)
@@ -95,7 +95,7 @@ struct notify_context *notify_init(TALLOC_CTX *mem_ctx, struct server_id server,
        }
 
        notify->db_recursive = db_open(notify, lock_path("notify.tdb"),
-                                      0, TDB_SEQNUM|TDB_CLEAR_IF_FIRST,
+                                      0, TDB_SEQNUM|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
                                       O_RDWR|O_CREAT, 0644);
        if (notify->db_recursive == NULL) {
                talloc_free(notify);
@@ -103,7 +103,7 @@ struct notify_context *notify_init(TALLOC_CTX *mem_ctx, struct server_id server,
        }
 
        notify->db_onelevel = db_open(notify, lock_path("notify_onelevel.tdb"),
-                                     0, TDB_CLEAR_IF_FIRST,
+                                     0, TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
                                      O_RDWR|O_CREAT, 0644);
        if (notify->db_onelevel == NULL) {
                talloc_free(notify);
@@ -145,14 +145,14 @@ bool notify_internal_parent_init(TALLOC_CTX *mem_ctx)
         */
 
        db1 = tdb_wrap_open(mem_ctx, lock_path("notify.tdb"),
-                           0, TDB_SEQNUM|TDB_CLEAR_IF_FIRST,
+                           0, TDB_SEQNUM|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
                           O_RDWR|O_CREAT, 0644);
        if (db1 == NULL) {
                DEBUG(1, ("could not open notify.tdb: %s\n", strerror(errno)));
                return false;
        }
        db2 = tdb_wrap_open(mem_ctx, lock_path("notify_onelevel.tdb"),
-                           0, TDB_CLEAR_IF_FIRST, O_RDWR|O_CREAT, 0644);
+                           0, TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDWR|O_CREAT, 0644);
        if (db2 == NULL) {
                DEBUG(1, ("could not open notify_onelevel.tdb: %s\n",
                          strerror(errno)));
index 1fdad0eb29b541433caa9baef2f2269665a3faa9..2d9761bac4a599d23e4ca1c8ffd68ff42ad53d99 100644 (file)
@@ -302,7 +302,7 @@ int main(int argc, const char *argv[])
        }
 
        if (no_trans) {
-               tdb_flags |= TDB_CLEAR_IF_FIRST;
+               tdb_flags |= TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH;
        }
 
        db = db_open(mem_ctx, db_name, 0, tdb_flags,  O_RDWR | O_CREAT, 0644);
index 7b5f8aaa55dde7e32107e43611fa56015126602d..f8b359d99f0c9e1d7c153a67bb93d94717f1c711 100644 (file)
@@ -918,7 +918,8 @@ static bool do_winbind_offline(struct messaging_context *msg_ctx,
 
        tdb = tdb_open_log(cache_path("winbindd_cache.tdb"),
                                WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE,
-                               TDB_DEFAULT /* TDB_CLEAR_IF_FIRST */, O_RDWR|O_CREAT, 0600);
+                               TDB_DEFAULT|TDB_INCOMPATIBLE_HASH /* TDB_CLEAR_IF_FIRST */,
+                               O_RDWR|O_CREAT, 0600);
 
        if (!tdb) {
                fprintf(stderr, "Cannot open the tdb %s for writing.\n",
index 12595236e77a56504ace5201d272879f9384f9d7..053efab5929cb7323f1937186f28f93ed9c018f0 100644 (file)
@@ -449,7 +449,7 @@ static int traverse_sessionid(const char *key, struct sessionid *session,
                int result;
                struct db_context *db;
                db = db_open(NULL, lock_path("locking.tdb"), 0,
-                            TDB_CLEAR_IF_FIRST, O_RDONLY, 0);
+                            TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDONLY, 0);
 
                if (!db) {
                        d_printf("%s not initialised\n",
index f7ab726e4995680426422a7396dd9f3170b21ea3..81317464efb4b08ebab74d09bbb2e2b9b47c890c 100644 (file)
@@ -3072,7 +3072,8 @@ bool init_wcache(void)
        /* when working offline we must not clear the cache on restart */
        wcache->tdb = tdb_open_log(cache_path("winbindd_cache.tdb"),
                                WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE, 
-                               lp_winbind_offline_logon() ? TDB_DEFAULT : (TDB_DEFAULT | TDB_CLEAR_IF_FIRST), 
+                               TDB_INCOMPATIBLE_HASH |
+                                       (lp_winbind_offline_logon() ? TDB_DEFAULT : (TDB_DEFAULT | TDB_CLEAR_IF_FIRST)),
                                O_RDWR|O_CREAT, 0600);
 
        if (wcache->tdb == NULL) {
@@ -3244,7 +3245,8 @@ void wcache_flush_cache(void)
        /* when working offline we must not clear the cache on restart */
        wcache->tdb = tdb_open_log(cache_path("winbindd_cache.tdb"),
                                WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE, 
-                               lp_winbind_offline_logon() ? TDB_DEFAULT : (TDB_DEFAULT | TDB_CLEAR_IF_FIRST), 
+                               TDB_INCOMPATIBLE_HASH |
+                               (lp_winbind_offline_logon() ? TDB_DEFAULT : (TDB_DEFAULT | TDB_CLEAR_IF_FIRST)),
                                O_RDWR|O_CREAT, 0600);
 
        if (!wcache->tdb) {
@@ -4062,6 +4064,7 @@ int winbindd_validate_cache(void)
 
        tdb = tdb_open_log(tdb_path, 
                           WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE,
+                          TDB_INCOMPATIBLE_HASH |
                           ( lp_winbind_offline_logon() 
                             ? TDB_DEFAULT 
                             : TDB_DEFAULT | TDB_CLEAR_IF_FIRST ),