mirror of
https://github.com/samba-team/samba.git
synced 2025-08-26 01:49:31 +03:00
s3-dbwrap: Add dbwrap_db_id
This returns a blob uniquely identifying the database
This commit is contained in:
@ -351,3 +351,8 @@ 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)
|
||||
{
|
||||
db->id(db, id, idlen);
|
||||
}
|
||||
|
@ -62,6 +62,7 @@ int dbwrap_get_flags(struct db_context *db);
|
||||
int dbwrap_transaction_start(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);
|
||||
|
||||
|
||||
/* The following definitions come from lib/dbwrap_util.c */
|
||||
|
@ -1490,6 +1490,16 @@ static int db_ctdb_get_flags(struct db_context *db)
|
||||
return tdb_get_flags(ctx->wtdb->tdb);
|
||||
}
|
||||
|
||||
static void db_ctdb_id(struct db_context *db, const 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);
|
||||
}
|
||||
|
||||
struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
|
||||
const char *name,
|
||||
int hash_size, int tdb_flags,
|
||||
@ -1599,6 +1609,7 @@ struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
|
||||
result->transaction_start = db_ctdb_transaction_start;
|
||||
result->transaction_commit = db_ctdb_transaction_commit;
|
||||
result->transaction_cancel = db_ctdb_transaction_cancel;
|
||||
result->id = db_ctdb_id;
|
||||
|
||||
DEBUG(3,("db_open_ctdb: opened database '%s' with dbid 0x%x\n",
|
||||
name, db_ctdb->db_id));
|
||||
|
@ -58,6 +58,7 @@ struct db_context {
|
||||
void *private_data);
|
||||
int (*exists)(struct db_context *db,TDB_DATA key);
|
||||
int (*wipe)(struct db_context *db);
|
||||
void (*id)(struct db_context *db, const uint8_t **id, size_t *idlen);
|
||||
void *private_data;
|
||||
enum dbwrap_lock_order lock_order;
|
||||
bool persistent;
|
||||
|
@ -408,6 +408,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)
|
||||
{
|
||||
*id = (uint8_t *)db;
|
||||
*idlen = sizeof(db);
|
||||
}
|
||||
|
||||
struct db_context *db_open_rbt(TALLOC_CTX *mem_ctx)
|
||||
{
|
||||
struct db_context *result;
|
||||
@ -437,6 +443,7 @@ struct db_context *db_open_rbt(TALLOC_CTX *mem_ctx)
|
||||
result->wipe = db_rbt_wipe;
|
||||
result->parse_record = db_rbt_parse_record;
|
||||
result->lock_order = 0;
|
||||
result->id = db_rbt_id;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -23,9 +23,15 @@
|
||||
#include "dbwrap/dbwrap_tdb.h"
|
||||
#include "lib/tdb_wrap/tdb_wrap.h"
|
||||
#include "util_tdb.h"
|
||||
#include "system/filesys.h"
|
||||
|
||||
struct db_tdb_ctx {
|
||||
struct tdb_wrap *wtdb;
|
||||
|
||||
struct {
|
||||
dev_t dev;
|
||||
ino_t ino;
|
||||
} id;
|
||||
};
|
||||
|
||||
static NTSTATUS db_tdb_store(struct db_record *rec, TDB_DATA data, int flag);
|
||||
@ -366,6 +372,14 @@ 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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx,
|
||||
struct loadparm_context *lp_ctx,
|
||||
const char *name,
|
||||
@ -375,6 +389,7 @@ struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx,
|
||||
{
|
||||
struct db_context *result = NULL;
|
||||
struct db_tdb_ctx *db_tdb;
|
||||
struct stat st;
|
||||
|
||||
result = talloc_zero(mem_ctx, struct db_context);
|
||||
if (result == NULL) {
|
||||
@ -396,6 +411,15 @@ struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx,
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ZERO_STRUCT(db_tdb->id);
|
||||
|
||||
if (fstat(tdb_fd(db_tdb->wtdb->tdb), &st) == -1) {
|
||||
DEBUG(3, ("fstat failed: %s\n", strerror(errno)));
|
||||
goto fail;
|
||||
}
|
||||
db_tdb->id.dev = st.st_dev;
|
||||
db_tdb->id.ino = st.st_ino;
|
||||
|
||||
result->fetch_locked = db_tdb_fetch_locked;
|
||||
result->try_fetch_locked = db_tdb_try_fetch_locked;
|
||||
result->traverse = db_tdb_traverse;
|
||||
@ -409,6 +433,7 @@ struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx,
|
||||
result->transaction_cancel = db_tdb_transaction_cancel;
|
||||
result->exists = db_tdb_exists;
|
||||
result->wipe = db_tdb_wipe;
|
||||
result->id = db_tdb_id;
|
||||
return result;
|
||||
|
||||
fail:
|
||||
|
Reference in New Issue
Block a user