lib: Make g_lock_lock_send use TDB_DATA
authorVolker Lendecke <vl@samba.org>
Sun, 3 Dec 2017 19:47:02 +0000 (20:47 +0100)
committerRalph Boehme <slow@samba.org>
Thu, 8 Feb 2018 09:01:50 +0000 (10:01 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
libcli/auth/netlogon_creds_cli.c
source3/include/g_lock.h
source3/lib/g_lock.c
source3/torture/test_g_lock.c

index cb3d6a9eeb4a8a6fa56602a138ddccd7e05e34b7..f51ad3dda26f718539055f201bf1556e3a552f91 100644 (file)
@@ -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);
index e6d4de14cf37c143856fc1e31c3e6542f1b903d8..2748eedafc1eb6e39e4ae7a5e4bbbb047bc72e02 100644 (file)
@@ -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,
index 4c42fb07bf5806cae7c7270bc0c741e87407305b..69b6efcf55217dd173e59674547a4c895dba2352 100644 (file)
@@ -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;
        }
index 718c196bfe69bb078abcf434c8ea81aad05d3027..6767dd552306b0b0640392ba1466fd714f1d95b5 100644 (file)
@@ -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;