summaryrefslogtreecommitdiff
path: root/lib/tdb2
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2011-09-14 07:48:13 +0930
committerRusty Russell <rusty@rustcorp.com.au>2011-09-14 07:48:13 +0930
commit333a23fa995faf1735e5234272f56b792d91a877 (patch)
tree3e636d7e0662190ef26020c3ba4df37bed69a35b /lib/tdb2
parent6e16e29d532d7542c210fd725bf61df1e7a97795 (diff)
downloadsamba-333a23fa995faf1735e5234272f56b792d91a877.tar.gz
samba-333a23fa995faf1735e5234272f56b792d91a877.tar.bz2
samba-333a23fa995faf1735e5234272f56b792d91a877.zip
tdb2: disallow SEED attribute with TDB_VERSION1.
It also only makes sense with O_CREAT. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (Imported from CCAN commit fc44729c471bcdc7ab0410448d991a65e74cec3d)
Diffstat (limited to 'lib/tdb2')
-rw-r--r--lib/tdb2/open.c26
-rw-r--r--lib/tdb2/test/failtest_helper.h2
2 files changed, 27 insertions, 1 deletions
diff --git a/lib/tdb2/open.c b/lib/tdb2/open.c
index b17e91c251..bad365756b 100644
--- a/lib/tdb2/open.c
+++ b/lib/tdb2/open.c
@@ -259,6 +259,13 @@ enum TDB_ERROR tdb_get_attribute(struct tdb_context *tdb,
attr->hash.data = tdb->hash_data;
break;
case TDB_ATTRIBUTE_SEED:
+ if (tdb->flags & TDB_VERSION1)
+ return tdb->last_error
+ = tdb_logerr(tdb, TDB_ERR_EINVAL,
+ TDB_LOG_USE_ERROR,
+ "tdb_get_attribute:"
+ " cannot get TDB_ATTRIBUTE_SEED"
+ " on TDB1 tdb.");
attr->seed.seed = tdb->hash_seed;
break;
case TDB_ATTRIBUTE_OPENHOOK:
@@ -431,6 +438,25 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
}
}
+ if (seed) {
+ if (tdb_flags & TDB_VERSION1) {
+ ecode = tdb_logerr(tdb, TDB_ERR_EINVAL,
+ TDB_LOG_USE_ERROR,
+ "tdb_open:"
+ " cannot set TDB_ATTRIBUTE_SEED"
+ " on TDB1 tdb.");
+ goto fail;
+ } else if (!(tdb_flags & TDB_INTERNAL)
+ && !(open_flags & O_CREAT)) {
+ ecode = tdb_logerr(tdb, TDB_ERR_EINVAL,
+ TDB_LOG_USE_ERROR,
+ "tdb_open:"
+ " cannot set TDB_ATTRIBUTE_SEED"
+ " without O_CREAT.");
+ goto fail;
+ }
+ }
+
if ((open_flags & O_ACCMODE) == O_WRONLY) {
ecode = tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR,
"tdb_open: can't open tdb %s write-only",
diff --git a/lib/tdb2/test/failtest_helper.h b/lib/tdb2/test/failtest_helper.h
index 37acbdd832..403ff64758 100644
--- a/lib/tdb2/test/failtest_helper.h
+++ b/lib/tdb2/test/failtest_helper.h
@@ -4,7 +4,7 @@
#include <stdbool.h>
/* FIXME: Check these! */
-#define INITIAL_TDB_MALLOC "open.c", 360, FAILTEST_MALLOC
+#define INITIAL_TDB_MALLOC "open.c", 367, FAILTEST_MALLOC
#define URANDOM_OPEN "open.c", 61, FAILTEST_OPEN
#define URANDOM_READ "open.c", 41, FAILTEST_READ