summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/dbwrap/dbwrap.c4
-rw-r--r--lib/dbwrap/dbwrap.h2
-rw-r--r--lib/dbwrap/dbwrap_cache.c7
-rw-r--r--lib/dbwrap/dbwrap_private.h3
-rw-r--r--lib/dbwrap/dbwrap_rbt.c8
-rw-r--r--lib/dbwrap/dbwrap_tdb.c10
-rw-r--r--source3/lib/dbwrap/dbwrap_ctdb.c10
-rw-r--r--source3/lib/dbwrap/dbwrap_watch.c7
8 files changed, 31 insertions, 20 deletions
diff --git a/lib/dbwrap/dbwrap.c b/lib/dbwrap/dbwrap.c
index 3cfb21b3c50..a1b98c3a4fc 100644
--- a/lib/dbwrap/dbwrap.c
+++ b/lib/dbwrap/dbwrap.c
@@ -449,9 +449,9 @@ int dbwrap_transaction_cancel(struct db_context *db)
return db->transaction_cancel(db);
}
-void dbwrap_db_id(struct db_context *db, const uint8_t **id, size_t *idlen)
+size_t dbwrap_db_id(struct db_context *db, uint8_t *id, size_t idlen)
{
- db->id(db, id, idlen);
+ return db->id(db, id, idlen);
}
bool dbwrap_is_persistent(struct db_context *db)
diff --git a/lib/dbwrap/dbwrap.h b/lib/dbwrap/dbwrap.h
index 9787078ac5c..0a5c9181b34 100644
--- a/lib/dbwrap/dbwrap.h
+++ b/lib/dbwrap/dbwrap.h
@@ -87,7 +87,7 @@ int dbwrap_transaction_start(struct db_context *db);
NTSTATUS dbwrap_transaction_start_nonblock(struct db_context *db);
int dbwrap_transaction_commit(struct db_context *db);
int dbwrap_transaction_cancel(struct db_context *db);
-void dbwrap_db_id(struct db_context *db, const uint8_t **id, size_t *idlen);
+size_t dbwrap_db_id(struct db_context *db, uint8_t *id, size_t idlen);
bool dbwrap_is_persistent(struct db_context *db);
const char *dbwrap_name(struct db_context *db);
diff --git a/lib/dbwrap/dbwrap_cache.c b/lib/dbwrap/dbwrap_cache.c
index c317fe00524..e4cee558484 100644
--- a/lib/dbwrap/dbwrap_cache.c
+++ b/lib/dbwrap/dbwrap_cache.c
@@ -179,12 +179,13 @@ static int dbwrap_cache_exists(struct db_context *db, TDB_DATA key)
return dbwrap_exists(ctx->backing, key);
}
-static void dbwrap_cache_id(struct db_context *db, const uint8_t **id,
- size_t *idlen)
+static size_t dbwrap_cache_id(struct db_context *db, uint8_t *id,
+ size_t idlen)
{
struct db_cache_ctx *ctx = talloc_get_type_abort(
db->private_data, struct db_cache_ctx);
- dbwrap_db_id(ctx->backing, id, idlen);
+
+ return dbwrap_db_id(ctx->backing, id, idlen);
}
struct db_context *db_open_cache(TALLOC_CTX *mem_ctx,
diff --git a/lib/dbwrap/dbwrap_private.h b/lib/dbwrap/dbwrap_private.h
index f3c42b9d374..6a528507321 100644
--- a/lib/dbwrap/dbwrap_private.h
+++ b/lib/dbwrap/dbwrap_private.h
@@ -58,7 +58,8 @@ struct db_context {
int (*exists)(struct db_context *db,TDB_DATA key);
int (*wipe)(struct db_context *db);
int (*check)(struct db_context *db);
- void (*id)(struct db_context *db, const uint8_t **id, size_t *idlen);
+ size_t (*id)(struct db_context *db, uint8_t *id, size_t idlen);
+
const char *name;
void *private_data;
enum dbwrap_lock_order lock_order;
diff --git a/lib/dbwrap/dbwrap_rbt.c b/lib/dbwrap/dbwrap_rbt.c
index 03f2f576256..0764a2c723d 100644
--- a/lib/dbwrap/dbwrap_rbt.c
+++ b/lib/dbwrap/dbwrap_rbt.c
@@ -497,10 +497,12 @@ static int db_rbt_trans_dummy(struct db_context *db)
return 0;
}
-static void db_rbt_id(struct db_context *db, const uint8_t **id, size_t *idlen)
+static size_t db_rbt_id(struct db_context *db, uint8_t *id, size_t idlen)
{
- *id = (uint8_t *)db;
- *idlen = sizeof(struct db_context *);
+ if (idlen >= sizeof(struct db_context *)) {
+ memcpy(id, &db, sizeof(struct db_context *));
+ }
+ return sizeof(struct db_context *);
}
struct db_context *db_open_rbt(TALLOC_CTX *mem_ctx)
diff --git a/lib/dbwrap/dbwrap_tdb.c b/lib/dbwrap/dbwrap_tdb.c
index a144ed47bb6..0e5444918fa 100644
--- a/lib/dbwrap/dbwrap_tdb.c
+++ b/lib/dbwrap/dbwrap_tdb.c
@@ -388,12 +388,16 @@ static int db_tdb_transaction_cancel(struct db_context *db)
return 0;
}
-static void db_tdb_id(struct db_context *db, const uint8_t **id, size_t *idlen)
+static size_t db_tdb_id(struct db_context *db, uint8_t *id, size_t idlen)
{
struct db_tdb_ctx *db_ctx =
talloc_get_type_abort(db->private_data, struct db_tdb_ctx);
- *id = (uint8_t *)&db_ctx->id;
- *idlen = sizeof(db_ctx->id);
+
+ if (idlen >= sizeof(db_ctx->id)) {
+ memcpy(id, &db_ctx->id, sizeof(db_ctx->id));
+ }
+
+ return sizeof(db_ctx->id);
}
struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx,
diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c
index f37bfd82596..3b68338841e 100644
--- a/source3/lib/dbwrap/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap/dbwrap_ctdb.c
@@ -1517,14 +1517,16 @@ static int db_ctdb_get_seqnum(struct db_context *db)
return tdb_get_seqnum(ctx->wtdb->tdb);
}
-static void db_ctdb_id(struct db_context *db, const uint8_t **id,
- size_t *idlen)
+static size_t db_ctdb_id(struct db_context *db, uint8_t *id, size_t idlen)
{
struct db_ctdb_ctx *ctx = talloc_get_type_abort(
db->private_data, struct db_ctdb_ctx);
- *id = (uint8_t *)&ctx->db_id;
- *idlen = sizeof(ctx->db_id);
+ if (idlen >= sizeof(ctx->db_id)) {
+ memcpy(id, &ctx->db_id, sizeof(ctx->db_id));
+ }
+
+ return sizeof(ctx->db_id);
}
struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
diff --git a/source3/lib/dbwrap/dbwrap_watch.c b/source3/lib/dbwrap/dbwrap_watch.c
index da1a9cc11e9..11ade1948af 100644
--- a/source3/lib/dbwrap/dbwrap_watch.c
+++ b/source3/lib/dbwrap/dbwrap_watch.c
@@ -50,11 +50,12 @@ static TDB_DATA dbwrap_record_watchers_key(TALLOC_CTX *mem_ctx,
struct db_record *rec,
TDB_DATA *rec_key)
{
- const uint8_t *db_id;
- size_t db_id_len;
+ size_t db_id_len = dbwrap_db_id(db, NULL, 0);
+ uint8_t db_id[db_id_len];
TDB_DATA key, wkey;
- dbwrap_db_id(db, &db_id, &db_id_len);
+ dbwrap_db_id(db, db_id, db_id_len);
+
key = dbwrap_record_get_key(rec);
wkey.dsize = sizeof(uint32_t) + db_id_len + key.dsize;