summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2009-08-28 11:56:34 +0930
committerAndrew Tridgell <tridge@samba.org>2009-08-28 13:43:05 +1000
commit398d0c2929026fccb3409316720a4dcad225ab05 (patch)
treea6f0afcf5b6bbc61f8adb5d841f003461068518e /lib
parent4279879c9847ca069527e11ca934b8906009cad8 (diff)
downloadsamba-398d0c2929026fccb3409316720a4dcad225ab05.tar.gz
samba-398d0c2929026fccb3409316720a4dcad225ab05.tar.bz2
samba-398d0c2929026fccb3409316720a4dcad225ab05.zip
lib/tdb: don't overwrite TDBs with different version numbers.
In future, this may happen, and we don't want to clobber them. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib')
-rw-r--r--lib/tdb/common/open.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/tdb/common/open.c b/lib/tdb/common/open.c
index 2e6a707497..141e6fe517 100644
--- a/lib/tdb/common/open.c
+++ b/lib/tdb/common/open.c
@@ -240,17 +240,19 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
errno = 0;
if (read(tdb->fd, &tdb->header, sizeof(tdb->header)) != sizeof(tdb->header)
- || strcmp(tdb->header.magic_food, TDB_MAGIC_FOOD) != 0
- || (tdb->header.version != TDB_VERSION
- && !(rev = (tdb->header.version==TDB_BYTEREV(TDB_VERSION))))) {
- /* its not a valid database - possibly initialise it */
+ || strcmp(tdb->header.magic_food, TDB_MAGIC_FOOD) != 0) {
if (!(open_flags & O_CREAT) || tdb_new_database(tdb, hash_size) == -1) {
if (errno == 0) {
- errno = EIO; /* ie bad format or something */
+ errno = EIO; /* ie bad format or something */
}
goto fail;
}
rev = (tdb->flags & TDB_CONVERT);
+ } else if (tdb->header.version != TDB_VERSION
+ && !(rev = (tdb->header.version==TDB_BYTEREV(TDB_VERSION)))) {
+ /* wrong version */
+ errno = EIO;
+ goto fail;
}
vp = (unsigned char *)&tdb->header.version;
vertest = (((uint32_t)vp[0]) << 24) | (((uint32_t)vp[1]) << 16) |