1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-26 21:57:41 +03:00

lib: Make g_lock_write_data use TDB_DATA

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
This commit is contained in:
Volker Lendecke 2017-12-03 20:47:02 +01:00 committed by Ralph Boehme
parent a104e08171
commit ed3521d172
4 changed files with 15 additions and 9 deletions

View File

@ -48,7 +48,7 @@ NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, TDB_DATA key,
enum g_lock_type lock_type, struct timeval timeout);
NTSTATUS g_lock_unlock(struct g_lock_ctx *ctx, TDB_DATA key);
NTSTATUS g_lock_write_data(struct g_lock_ctx *ctx, const char *name,
NTSTATUS g_lock_write_data(struct g_lock_ctx *ctx, TDB_DATA key,
const uint8_t *buf, size_t buflen);
NTSTATUS g_lock_do(const char *name, enum g_lock_type lock_type,

View File

@ -553,7 +553,7 @@ NTSTATUS g_lock_unlock(struct g_lock_ctx *ctx, TDB_DATA key)
}
struct g_lock_write_data_state {
const char *name;
TDB_DATA key;
struct server_id self;
const uint8_t *data;
size_t datalen;
@ -573,7 +573,10 @@ static void g_lock_write_data_fn(struct db_record *rec,
ok = g_lock_parse(value.dptr, value.dsize, &lck);
if (!ok) {
DBG_DEBUG("g_lock_parse for %s failed\n", state->name);
DBG_DEBUG("g_lock_parse for %s failed\n",
hex_encode_talloc(talloc_tos(),
state->key.dptr,
state->key.dsize));
state->status = NT_STATUS_INTERNAL_DB_CORRUPTION;
return;
}
@ -596,16 +599,16 @@ static void g_lock_write_data_fn(struct db_record *rec,
state->status = g_lock_store(rec, &lck, NULL);
}
NTSTATUS g_lock_write_data(struct g_lock_ctx *ctx, const char *name,
NTSTATUS g_lock_write_data(struct g_lock_ctx *ctx, TDB_DATA key,
const uint8_t *buf, size_t buflen)
{
struct g_lock_write_data_state state = {
.name = name, .self = messaging_server_id(ctx->msg),
.key = key, .self = messaging_server_id(ctx->msg),
.data = buf, .datalen = buflen
};
NTSTATUS status;
status = dbwrap_do_locked(ctx->db, string_term_tdb_data(name),
status = dbwrap_do_locked(ctx->db, key,
g_lock_write_data_fn, &state);
if (!NT_STATUS_IS_OK(status)) {
DBG_WARNING("dbwrap_do_locked failed: %s\n",

View File

@ -1520,7 +1520,8 @@ static NTSTATUS smbd_claim_version(struct messaging_context *msg,
return NT_STATUS_SXS_VERSION_CONFLICT;
}
status = g_lock_write_data(ctx, name, (const uint8_t *)version,
status = g_lock_write_data(ctx, string_term_tdb_data(name),
(const uint8_t *)version,
strlen(version)+1);
if (!NT_STATUS_IS_OK(status)) {
DBG_WARNING("g_lock_write_data failed: %s\n",

View File

@ -148,7 +148,8 @@ bool run_g_lock2(int dummy)
goto fail;
}
status = g_lock_write_data(ctx, lockname, &data, sizeof(data));
status = g_lock_write_data(ctx, string_term_tdb_data(lockname),
&data, sizeof(data));
if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_LOCKED)) {
fprintf(stderr, "unlocked g_lock_write_data returned %s\n",
nt_errstr(status));
@ -163,7 +164,8 @@ bool run_g_lock2(int dummy)
goto fail;
}
status = g_lock_write_data(ctx, lockname, &data, sizeof(data));
status = g_lock_write_data(ctx, string_term_tdb_data(lockname),
&data, sizeof(data));
if (!NT_STATUS_IS_OK(status)) {
fprintf(stderr, "g_lock_write_data failed: %s\n",
nt_errstr(status));