From 3bc87a20e9c6af358749c0b9d17e03a281086d3e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 3 Dec 2017 20:47:02 +0100 Subject: [PATCH] lib: Make g_lock_lock_send use TDB_DATA Signed-off-by: Volker Lendecke Reviewed-by: Ralph Boehme --- libcli/auth/netlogon_creds_cli.c | 4 ++-- source3/include/g_lock.h | 2 +- source3/lib/g_lock.c | 15 +++++++-------- source3/torture/test_g_lock.c | 4 +++- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/libcli/auth/netlogon_creds_cli.c b/libcli/auth/netlogon_creds_cli.c index cb3d6a9eeb4..f51ad3dda26 100644 --- a/libcli/auth/netlogon_creds_cli.c +++ b/libcli/auth/netlogon_creds_cli.c @@ -765,7 +765,7 @@ struct tevent_req *netlogon_creds_cli_lock_send(TALLOC_CTX *mem_ctx, subreq = g_lock_lock_send(state, ev, context->db.g_ctx, - context->db.key_name, + string_term_tdb_data(context->db.key_name), G_LOCK_WRITE); if (tevent_req_nomem(subreq, req)) { return tevent_req_post(req, ev); @@ -978,7 +978,7 @@ struct tevent_req *netlogon_creds_cli_lck_send( subreq = g_lock_lock_send(state, ev, context->db.g_ctx, - context->db.key_name, + string_term_tdb_data(context->db.key_name), gtype); if (tevent_req_nomem(subreq, req)) { return tevent_req_post(req, ev); diff --git a/source3/include/g_lock.h b/source3/include/g_lock.h index e6d4de14cf3..2748eedafc1 100644 --- a/source3/include/g_lock.h +++ b/source3/include/g_lock.h @@ -41,7 +41,7 @@ struct g_lock_ctx *g_lock_ctx_init(TALLOC_CTX *mem_ctx, struct tevent_req *g_lock_lock_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct g_lock_ctx *ctx, - const char *name, + TDB_DATA key, enum g_lock_type type); NTSTATUS g_lock_lock_recv(struct tevent_req *req); NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, const char *name, diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c index 4c42fb07bf5..69b6efcf552 100644 --- a/source3/lib/g_lock.c +++ b/source3/lib/g_lock.c @@ -311,7 +311,7 @@ done: struct g_lock_lock_state { struct tevent_context *ev; struct g_lock_ctx *ctx; - const char *name; + TDB_DATA key; enum g_lock_type type; }; @@ -343,7 +343,7 @@ static void g_lock_lock_fn(struct db_record *rec, void *private_data) struct tevent_req *g_lock_lock_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct g_lock_ctx *ctx, - const char *name, + TDB_DATA key, enum g_lock_type type) { struct tevent_req *req; @@ -357,15 +357,14 @@ struct tevent_req *g_lock_lock_send(TALLOC_CTX *mem_ctx, } state->ev = ev; state->ctx = ctx; - state->name = name; + state->key = key; state->type = type; fn_state = (struct g_lock_lock_fn_state) { .state = state, .self = messaging_server_id(ctx->msg) }; - status = dbwrap_do_locked(ctx->db, string_term_tdb_data(name), - g_lock_lock_fn, &fn_state); + status = dbwrap_do_locked(ctx->db, key, g_lock_lock_fn, &fn_state); if (tevent_req_nterror(req, status)) { DBG_DEBUG("dbwrap_do_locked failed: %s\n", nt_errstr(status)); @@ -418,8 +417,7 @@ static void g_lock_lock_retry(struct tevent_req *subreq) .state = state, .self = messaging_server_id(state->ctx->msg) }; - status = dbwrap_do_locked(state->ctx->db, - string_term_tdb_data(state->name), + status = dbwrap_do_locked(state->ctx->db, state->key, g_lock_lock_fn, &fn_state); if (tevent_req_nterror(req, status)) { DBG_DEBUG("dbwrap_do_locked failed: %s\n", @@ -467,7 +465,8 @@ NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, const char *name, if (ev == NULL) { goto fail; } - req = g_lock_lock_send(frame, ev, ctx, name, type); + req = g_lock_lock_send(frame, ev, ctx, string_term_tdb_data(name), + type); if (req == NULL) { goto fail; } diff --git a/source3/torture/test_g_lock.c b/source3/torture/test_g_lock.c index 718c196bfe6..6767dd55230 100644 --- a/source3/torture/test_g_lock.c +++ b/source3/torture/test_g_lock.c @@ -24,6 +24,7 @@ #include "messages.h" #include "lib/util/server_id.h" #include "lib/util/sys_rw.h" +#include "lib/util/util_tdb.h" static bool get_g_lock_ctx(TALLOC_CTX *mem_ctx, struct tevent_context **ev, @@ -504,7 +505,8 @@ bool run_g_lock4(int dummy) goto fail; } - req = g_lock_lock_send(ev, ev, ctx, lockname, G_LOCK_WRITE); + req = g_lock_lock_send(ev, ev, ctx, string_term_tdb_data(lockname), + G_LOCK_WRITE); if (req == NULL) { fprintf(stderr, "g_lock_lock send failed\n"); goto fail;