summaryrefslogtreecommitdiff
path: root/lib/tdb2/tdb1_open.c
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2011-09-14 07:34:13 +0930
committerRusty Russell <rusty@rustcorp.com.au>2011-09-14 07:34:13 +0930
commit61b1bd1dca145a0417907793579352c66b016c23 (patch)
tree913e709da52d81b38afb6f91e917e5e25db3f451 /lib/tdb2/tdb1_open.c
parentebb3017cf08cc4dad3217db6cea404069b494b47 (diff)
downloadsamba-61b1bd1dca145a0417907793579352c66b016c23.tar.gz
samba-61b1bd1dca145a0417907793579352c66b016c23.tar.bz2
samba-61b1bd1dca145a0417907793579352c66b016c23.zip
tdb2: approximate INCOMPATIBLE_HASH flag with tdb1_incompatible_hash()
Rather than leak TDB_INCOMPATIBLE_HASH through to the TDB2 API, we make it that if they use the tdb1_incompatible_hash function as their hash, then we treat it as if they had specified the TDB_INCOMPATIBLE_HASH flag (ie. we mark the header so it's unusable by tdb < 1.2.6). This precludes the possibility of using TDB_INCOMPATIBLE_HASH with a custom hash function: that used to allow the user to ensure that old TDB versions couldn't open the TDB file (and recent ones check the header to ensure they're using the right hash). But that's a small loss. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (Imported from CCAN commit 3004f7e89a5978064b4fb29c1027e6d0d39e9418)
Diffstat (limited to 'lib/tdb2/tdb1_open.c')
-rw-r--r--lib/tdb2/tdb1_open.c47
1 files changed, 24 insertions, 23 deletions
diff --git a/lib/tdb2/tdb1_open.c b/lib/tdb2/tdb1_open.c
index 30c11956ac..f53a32b5be 100644
--- a/lib/tdb2/tdb1_open.c
+++ b/lib/tdb2/tdb1_open.c
@@ -72,7 +72,7 @@ static int tdb1_new_database(struct tdb1_context *tdb, int hash_size)
/* Make sure older tdbs (which don't check the magic hash fields)
* will refuse to open this TDB. */
- if (tdb->flags & TDB1_INCOMPATIBLE_HASH)
+ if (tdb->hash_fn == tdb1_incompatible_hash)
newdb->rwlocks = TDB1_HASH_RWLOCK_MAGIC;
if (tdb->flags & TDB1_INTERNAL) {
@@ -135,25 +135,28 @@ struct tdb1_context *tdb1_open(const char *name, int hash_size, int tdb1_flags,
return tdb1_open_ex(name, hash_size, tdb1_flags, open_flags, mode, NULL, NULL);
}
-static bool check_header_hash(struct tdb1_context *tdb,
- bool default_hash, uint32_t *m1, uint32_t *m2)
+static bool hash_correct(struct tdb1_context *tdb,
+ uint32_t *m1, uint32_t *m2)
{
tdb1_header_hash(tdb, m1, m2);
- if (tdb->header.magic1_hash == *m1 &&
- tdb->header.magic2_hash == *m2) {
- return true;
- }
+ return (tdb->header.magic1_hash == *m1 &&
+ tdb->header.magic2_hash == *m2);
+}
- /* If they explicitly set a hash, always respect it. */
- if (!default_hash)
- return false;
+static bool check_header_hash(struct tdb1_context *tdb,
+ uint32_t *m1, uint32_t *m2)
+{
+ if (hash_correct(tdb, m1, m2))
+ return true;
- /* Otherwise, try the other inbuilt hash. */
+ /* If they use one inbuilt, try the other inbuilt hash. */
if (tdb->hash_fn == tdb1_old_hash)
- tdb->hash_fn = tdb1_jenkins_hash;
- else
+ tdb->hash_fn = tdb1_incompatible_hash;
+ else if (tdb->hash_fn == tdb1_incompatible_hash)
tdb->hash_fn = tdb1_old_hash;
- return check_header_hash(tdb, false, m1, m2);
+ else
+ return false;
+ return hash_correct(tdb, m1, m2);
}
struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flags,
@@ -216,15 +219,13 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
if (hash_fn) {
tdb->hash_fn = hash_fn;
- hash_alg = "the user defined";
+ if (hash_fn == tdb1_incompatible_hash)
+ hash_alg = "tdb1_incompatible_hash";
+ else
+ hash_alg = "the user defined";
} else {
- /* This controls what we use when creating a tdb. */
- if (tdb->flags & TDB1_INCOMPATIBLE_HASH) {
- tdb->hash_fn = tdb1_jenkins_hash;
- } else {
- tdb->hash_fn = tdb1_old_hash;
- }
- hash_alg = "either default";
+ tdb->hash_fn = tdb1_old_hash;
+ hash_alg = "default";
}
/* cache the page size */
@@ -353,7 +354,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
if ((tdb->header.magic1_hash == 0) && (tdb->header.magic2_hash == 0)) {
/* older TDB without magic hash references */
tdb->hash_fn = tdb1_old_hash;
- } else if (!check_header_hash(tdb, !hash_fn, &magic1, &magic2)) {
+ } else if (!check_header_hash(tdb, &magic1, &magic2)) {
tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_USE_ERROR,
"tdb1_open_ex: "
"%s was not created with %s hash function we are using\n"