[PATCH] Make g_lock use a TDB_DATA key

Volker Lendecke Volker.Lendecke at SerNet.DE
Thu Feb 8 07:55:02 UTC 2018


Hi!

locking.tdb has the problem that we do file system calls while holding
locks on the tdb. This can cause big trouble for clustered
environments. g_lock with its g_lock_write_data can remove this
trouble by forming the basis for locking.tdb: Drop mutexes/fcntl-locks
while doing the file system syscalls. This is step 0 for this:
locking.tdb is unhappy with strings as keys, it needs TDB_DATA. Change
g_lock to use TDB_DATA keys.

Review appreciated!

Thanks, Volker

-- 
Besuchen Sie die verinice.XP 2018 in Berlin,
Anwenderkonferenz für Informationssicherheit
vom 21.-23.03.2018 im Sofitel Kurfürstendamm
Info & Anmeldung hier: http://veriniceXP.org

SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From 55183247a3f16f6146a2ef3b137729141e97c2ff Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 3 Dec 2017 20:47:02 +0100
Subject: [PATCH 1/7] lib: Make g_lock_lock_send use TDB_DATA

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 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;
-- 
2.11.0


From 07fb9383169bbd4da530d1a2bb1d7503cbadb985 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 3 Dec 2017 20:47:02 +0100
Subject: [PATCH 2/7] lib: Make g_lock_lock use TDB_DATA

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/include/g_lock.h         |  2 +-
 source3/lib/dbwrap/dbwrap_ctdb.c |  4 ++--
 source3/lib/g_lock.c             |  8 ++++----
 source3/libsmb/trusts_util.c     |  3 ++-
 source3/smbd/server.c            |  6 +++---
 source3/torture/test_g_lock.c    | 37 ++++++++++++++++++++++---------------
 6 files changed, 34 insertions(+), 26 deletions(-)

diff --git a/source3/include/g_lock.h b/source3/include/g_lock.h
index 2748eedafc1..867e10420e2 100644
--- a/source3/include/g_lock.h
+++ b/source3/include/g_lock.h
@@ -44,7 +44,7 @@ struct tevent_req *g_lock_lock_send(TALLOC_CTX *mem_ctx,
 				    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,
+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, const char *name);
 
diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c
index 25db140583f..ce66c2ad9e4 100644
--- a/source3/lib/dbwrap/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap/dbwrap_ctdb.c
@@ -380,8 +380,8 @@ static int db_ctdb_transaction_start(struct db_context *db)
 	/*
 	 * Wait a day, i.e. forever...
 	 */
-	status = g_lock_lock(ctx->lock_ctx, h->lock_name, G_LOCK_WRITE,
-			     timeval_set(86400, 0));
+	status = g_lock_lock(ctx->lock_ctx, string_term_tdb_data(h->lock_name),
+			     G_LOCK_WRITE, timeval_set(86400, 0));
 	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(0, ("g_lock_lock failed: %s\n", nt_errstr(status)));
 		TALLOC_FREE(h);
diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c
index 69b6efcf552..f1227492045 100644
--- a/source3/lib/g_lock.c
+++ b/source3/lib/g_lock.c
@@ -452,7 +452,7 @@ NTSTATUS g_lock_lock_recv(struct tevent_req *req)
 	return tevent_req_simple_recv_ntstatus(req);
 }
 
-NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, const char *name,
+NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, TDB_DATA key,
 		     enum g_lock_type type, struct timeval timeout)
 {
 	TALLOC_CTX *frame = talloc_stackframe();
@@ -465,8 +465,7 @@ 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, string_term_tdb_data(name),
-			       type);
+	req = g_lock_lock_send(frame, ev, ctx, key, type);
 	if (req == NULL) {
 		goto fail;
 	}
@@ -783,7 +782,8 @@ NTSTATUS g_lock_do(const char *name, enum g_lock_type lock_type,
 		goto done;
 	}
 
-	status = g_lock_lock(g_ctx, name, lock_type, timeout);
+	status = g_lock_lock(g_ctx, string_term_tdb_data(name), lock_type,
+			     timeout);
 	if (!NT_STATUS_IS_OK(status)) {
 		goto done;
 	}
diff --git a/source3/libsmb/trusts_util.c b/source3/libsmb/trusts_util.c
index 27e77e6cc60..05ea07fb080 100644
--- a/source3/libsmb/trusts_util.c
+++ b/source3/libsmb/trusts_util.c
@@ -30,6 +30,7 @@
 #include "libsmb/libsmb.h"
 #include "source3/include/messages.h"
 #include "source3/include/g_lock.h"
+#include "lib/util/util_tdb.h"
 
 /*********************************************************
  Change the domain password on the PDC.
@@ -191,7 +192,7 @@ NTSTATUS trust_pw_change(struct netlogon_creds_cli_context *context,
 
 	g_timeout = timeval_current_ofs(10, 0);
 	status = g_lock_lock(state->g_ctx,
-			     state->g_lock_key,
+			     string_term_tdb_data(state->g_lock_key),
 			     G_LOCK_WRITE, g_timeout);
 	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(1, ("could not get g_lock on [%s]!\n",
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index 79786d68853..cb6bc73de74 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -1480,7 +1480,7 @@ static NTSTATUS smbd_claim_version(struct messaging_context *msg,
 		return NT_STATUS_UNSUCCESSFUL;
 	}
 
-	status = g_lock_lock(ctx, name, G_LOCK_READ,
+	status = g_lock_lock(ctx, string_term_tdb_data(name), G_LOCK_READ,
 			     (struct timeval) { .tv_sec = 60 });
 	if (!NT_STATUS_IS_OK(status)) {
 		DBG_WARNING("g_lock_lock(G_LOCK_READ) failed: %s\n",
@@ -1509,7 +1509,7 @@ static NTSTATUS smbd_claim_version(struct messaging_context *msg,
 		return NT_STATUS_OK;
 	}
 
-	status = g_lock_lock(ctx, name, G_LOCK_WRITE,
+	status = g_lock_lock(ctx, string_term_tdb_data(name), G_LOCK_WRITE,
 			     (struct timeval) { .tv_sec = 60 });
 	if (!NT_STATUS_IS_OK(status)) {
 		DBG_WARNING("g_lock_lock(G_LOCK_WRITE) failed: %s\n",
@@ -1529,7 +1529,7 @@ static NTSTATUS smbd_claim_version(struct messaging_context *msg,
 		return status;
 	}
 
-	status = g_lock_lock(ctx, name, G_LOCK_READ,
+	status = g_lock_lock(ctx, string_term_tdb_data(name), G_LOCK_READ,
 			     (struct timeval) { .tv_sec = 60 });
 	if (!NT_STATUS_IS_OK(status)) {
 		DBG_WARNING("g_lock_lock(G_LOCK_READ) failed: %s\n",
diff --git a/source3/torture/test_g_lock.c b/source3/torture/test_g_lock.c
index 6767dd55230..2dcba1e68e2 100644
--- a/source3/torture/test_g_lock.c
+++ b/source3/torture/test_g_lock.c
@@ -68,7 +68,7 @@ bool run_g_lock1(int dummy)
 		goto fail;
 	}
 
-	status = g_lock_lock(ctx, lockname, G_LOCK_READ,
+	status = g_lock_lock(ctx, string_term_tdb_data(lockname), G_LOCK_READ,
 			     (struct timeval) { .tv_sec = 1 });
 	if (!NT_STATUS_IS_OK(status)) {
 		fprintf(stderr, "g_lock_lock failed: %s\n",
@@ -76,7 +76,7 @@ bool run_g_lock1(int dummy)
 		goto fail;
 	}
 
-	status = g_lock_lock(ctx, lockname, G_LOCK_READ,
+	status = g_lock_lock(ctx, string_term_tdb_data(lockname), G_LOCK_READ,
 			     (struct timeval) { .tv_sec = 1 });
 	if (!NT_STATUS_EQUAL(status, NT_STATUS_WAS_LOCKED)) {
 		fprintf(stderr, "Double lock got %s\n",
@@ -155,7 +155,7 @@ bool run_g_lock2(int dummy)
 		goto fail;
 	}
 
-	status = g_lock_lock(ctx, lockname, G_LOCK_WRITE,
+	status = g_lock_lock(ctx, string_term_tdb_data(lockname), G_LOCK_WRITE,
 			     (struct timeval) { .tv_sec = 1 });
 	if (!NT_STATUS_IS_OK(status)) {
 		fprintf(stderr, "g_lock_lock returned %s\n",
@@ -262,7 +262,7 @@ bool run_g_lock3(int dummy)
 
 	state.self = messaging_server_id(msg);
 
-	status = g_lock_lock(ctx, lockname, G_LOCK_READ,
+	status = g_lock_lock(ctx, string_term_tdb_data(lockname), G_LOCK_READ,
 			     (struct timeval) { .tv_sec = 1 });
 	if (!NT_STATUS_IS_OK(status)) {
 		fprintf(stderr, "g_lock_lock returned %s\n",
@@ -270,7 +270,7 @@ bool run_g_lock3(int dummy)
 		goto fail;
 	}
 
-	status = g_lock_lock(ctx, lockname, G_LOCK_READ,
+	status = g_lock_lock(ctx, string_term_tdb_data(lockname), G_LOCK_READ,
 			     (struct timeval) { .tv_sec = 1 });
 	if (!NT_STATUS_EQUAL(status, NT_STATUS_WAS_LOCKED)) {
 		fprintf(stderr, "g_lock_lock returned %s, expected %s\n",
@@ -291,7 +291,7 @@ bool run_g_lock3(int dummy)
 		goto fail;
 	}
 
-	status = g_lock_lock(ctx, lockname, G_LOCK_WRITE,
+	status = g_lock_lock(ctx, string_term_tdb_data(lockname), G_LOCK_WRITE,
 			     (struct timeval) { .tv_sec = 1 });
 	if (!NT_STATUS_IS_OK(status)) {
 		fprintf(stderr, "g_lock_lock returned %s\n",
@@ -336,7 +336,7 @@ static bool lock4_child(const char *lockname,
 		return false;
 	}
 
-	status = g_lock_lock(ctx, lockname, G_LOCK_WRITE,
+	status = g_lock_lock(ctx, string_term_tdb_data(lockname), G_LOCK_WRITE,
 			     (struct timeval) { .tv_sec = 1 });
 	if (!NT_STATUS_IS_OK(status)) {
 		fprintf(stderr, "child: g_lock_lock returned %s\n",
@@ -489,7 +489,7 @@ bool run_g_lock4(int dummy)
 		return false;
 	}
 
-	status = g_lock_lock(ctx, lockname, G_LOCK_WRITE,
+	status = g_lock_lock(ctx, string_term_tdb_data(lockname), G_LOCK_WRITE,
 			     (struct timeval) { .tv_usec = 1 });
 	if (!NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
 		fprintf(stderr, "g_lock_lock returned %s\n",
@@ -497,7 +497,7 @@ bool run_g_lock4(int dummy)
 		goto fail;
 	}
 
-	status = g_lock_lock(ctx, lockname, G_LOCK_READ,
+	status = g_lock_lock(ctx, string_term_tdb_data(lockname), G_LOCK_READ,
 			     (struct timeval) { .tv_usec = 1 });
 	if (!NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
 		fprintf(stderr, "g_lock_lock returned %s\n",
@@ -623,7 +623,9 @@ bool run_g_lock5(int dummy)
 				fprintf(stderr, "get_g_lock_ctx failed");
 				exit(1);
 			}
-			status = g_lock_lock(ctx, lockname, G_LOCK_READ,
+			status = g_lock_lock(ctx,
+					     string_term_tdb_data(lockname),
+					     G_LOCK_READ,
 					     (struct timeval) { .tv_sec = 1 });
 			if (!NT_STATUS_IS_OK(status)) {
 				fprintf(stderr,
@@ -678,7 +680,8 @@ bool run_g_lock5(int dummy)
 			return false;
 		}
 
-		status = g_lock_lock(ctx, lockname, G_LOCK_READ,
+		status = g_lock_lock(ctx, string_term_tdb_data(lockname),
+				     G_LOCK_READ,
 				     (struct timeval) { .tv_sec = 1 });
 		if (!NT_STATUS_IS_OK(status)) {
 			fprintf(stderr, "g_lock_lock failed %s\n",
@@ -769,7 +772,9 @@ bool run_g_lock6(int dummy)
 				fprintf(stderr, "get_g_lock_ctx failed");
 				exit(1);
 			}
-			status = g_lock_lock(ctx, lockname, G_LOCK_READ,
+			status = g_lock_lock(ctx,
+					     string_term_tdb_data(lockname),
+					     G_LOCK_READ,
 					     (struct timeval) { .tv_sec = 1 });
 			if (!NT_STATUS_IS_OK(status)) {
 				fprintf(stderr,
@@ -825,7 +830,8 @@ bool run_g_lock6(int dummy)
 			return false;
 		}
 
-		status = g_lock_lock(ctx, lockname, G_LOCK_WRITE,
+		status = g_lock_lock(ctx, string_term_tdb_data(lockname),
+				     G_LOCK_WRITE,
 				     (struct timeval) { .tv_sec = 1 });
 		if (!NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
 			fprintf(stderr, "g_lock_lock should have failed with %s - %s\n",
@@ -893,7 +899,7 @@ bool run_g_lock_ping_pong(int dummy)
 
 	snprintf(name, sizeof(name), "ping_pong_%d", i);
 
-	status = g_lock_lock(ctx, name, G_LOCK_WRITE,
+	status = g_lock_lock(ctx, string_term_tdb_data(name), G_LOCK_WRITE,
 			     (struct timeval) { .tv_sec = 60 });
 	if (!NT_STATUS_IS_OK(status)) {
 		fprintf(stderr, "g_lock_lock failed: %s\n",
@@ -905,7 +911,8 @@ bool run_g_lock_ping_pong(int dummy)
 
 		name[10] = '0' + ((i+1) % torture_nprocs);
 
-		status = g_lock_lock(ctx, name, G_LOCK_WRITE,
+		status = g_lock_lock(ctx, string_term_tdb_data(name),
+				     G_LOCK_WRITE,
 				     (struct timeval) { .tv_sec = 60 });
 		if (!NT_STATUS_IS_OK(status)) {
 			fprintf(stderr, "g_lock_lock failed: %s\n",
-- 
2.11.0


From 6550c57dc3ef97c0128fdd7f548251a3f3f8d42e Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 3 Dec 2017 20:47:02 +0100
Subject: [PATCH 3/7] lib: Make g_lock_unlock use TDB_DATA

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 libcli/auth/netlogon_creds_cli.c |  5 +++--
 source3/include/g_lock.h         |  2 +-
 source3/lib/dbwrap/dbwrap_ctdb.c |  3 ++-
 source3/lib/g_lock.c             | 16 +++++++++-------
 source3/libsmb/trusts_util.c     |  3 ++-
 source3/smbd/server.c            |  2 +-
 source3/torture/test_g_lock.c    | 10 +++++-----
 7 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/libcli/auth/netlogon_creds_cli.c b/libcli/auth/netlogon_creds_cli.c
index f51ad3dda26..fdd1195b183 100644
--- a/libcli/auth/netlogon_creds_cli.c
+++ b/libcli/auth/netlogon_creds_cli.c
@@ -93,7 +93,7 @@ static int netlogon_creds_cli_locked_state_destructor(
 
 	if (state->is_glocked) {
 		g_lock_unlock(context->db.g_ctx,
-			      context->db.key_name);
+			      string_term_tdb_data(context->db.key_name));
 	}
 
 	return 0;
@@ -1014,7 +1014,8 @@ static int netlogon_creds_cli_lck_destructor(
 	struct netlogon_creds_cli_context *ctx = lck->context;
 	NTSTATUS status;
 
-	status = g_lock_unlock(ctx->db.g_ctx, ctx->db.key_name);
+	status = g_lock_unlock(ctx->db.g_ctx,
+			       string_term_tdb_data(ctx->db.key_name));
 	if (!NT_STATUS_IS_OK(status)) {
 		DBG_WARNING("g_lock_unlock failed: %s\n", nt_errstr(status));
 		smb_panic("g_lock_unlock failed");
diff --git a/source3/include/g_lock.h b/source3/include/g_lock.h
index 867e10420e2..a1d845f3074 100644
--- a/source3/include/g_lock.h
+++ b/source3/include/g_lock.h
@@ -46,7 +46,7 @@ struct tevent_req *g_lock_lock_send(TALLOC_CTX *mem_ctx,
 NTSTATUS g_lock_lock_recv(struct tevent_req *req);
 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, const char *name);
+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,
 			   const uint8_t *buf, size_t buflen);
diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c
index ce66c2ad9e4..2885f4e7fda 100644
--- a/source3/lib/dbwrap/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap/dbwrap_ctdb.c
@@ -328,7 +328,8 @@ static int db_ctdb_transaction_destructor(struct db_ctdb_transaction_handle *h)
 {
 	NTSTATUS status;
 
-	status = g_lock_unlock(h->ctx->lock_ctx, h->lock_name);
+	status = g_lock_unlock(h->ctx->lock_ctx,
+			       string_term_tdb_data(h->lock_name));
 	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(0, ("g_lock_unlock failed for %s: %s\n", h->lock_name,
 			  nt_errstr(status)));
diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c
index f1227492045..653ec34bb7f 100644
--- a/source3/lib/g_lock.c
+++ b/source3/lib/g_lock.c
@@ -483,7 +483,7 @@ NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, TDB_DATA key,
 }
 
 struct g_lock_unlock_state {
-	const char *name;
+	TDB_DATA key;
 	struct server_id self;
 	NTSTATUS status;
 };
@@ -501,7 +501,10 @@ static void g_lock_unlock_fn(struct db_record *rec,
 
 	ok = g_lock_parse(value.dptr, value.dsize, &lck);
 	if (!ok) {
-		DBG_DEBUG("g_lock_get for %s failed\n", state->name);
+		DBG_DEBUG("g_lock_get for %s failed\n",
+			  hex_encode_talloc(talloc_tos(),
+					    state->key.dptr,
+					    state->key.dsize));
 		state->status = NT_STATUS_FILE_INVALID;
 		return;
 	}
@@ -527,15 +530,14 @@ static void g_lock_unlock_fn(struct db_record *rec,
 	state->status = g_lock_store(rec, &lck, NULL);
 }
 
-NTSTATUS g_lock_unlock(struct g_lock_ctx *ctx, const char *name)
+NTSTATUS g_lock_unlock(struct g_lock_ctx *ctx, TDB_DATA key)
 {
 	struct g_lock_unlock_state state = {
-		.self = messaging_server_id(ctx->msg), .name = name
+		.self = messaging_server_id(ctx->msg), .key = key
 	};
 	NTSTATUS status;
 
-	status = dbwrap_do_locked(ctx->db, string_term_tdb_data(name),
-				  g_lock_unlock_fn, &state);
+	status = dbwrap_do_locked(ctx->db, key, g_lock_unlock_fn, &state);
 	if (!NT_STATUS_IS_OK(status)) {
 		DBG_WARNING("dbwrap_do_locked failed: %s\n",
 			    nt_errstr(status));
@@ -788,7 +790,7 @@ NTSTATUS g_lock_do(const char *name, enum g_lock_type lock_type,
 		goto done;
 	}
 	fn(private_data);
-	g_lock_unlock(g_ctx, name);
+	g_lock_unlock(g_ctx, string_term_tdb_data(name));
 
 done:
 	TALLOC_FREE(g_ctx);
diff --git a/source3/libsmb/trusts_util.c b/source3/libsmb/trusts_util.c
index 05ea07fb080..fd1b3372b36 100644
--- a/source3/libsmb/trusts_util.c
+++ b/source3/libsmb/trusts_util.c
@@ -45,7 +45,8 @@ struct trust_pw_change_state {
 
 static int trust_pw_change_state_destructor(struct trust_pw_change_state *state)
 {
-	g_lock_unlock(state->g_ctx, state->g_lock_key);
+	g_lock_unlock(state->g_ctx,
+		      string_term_tdb_data(state->g_lock_key));
 	return 0;
 }
 
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index cb6bc73de74..1d0e317b5c8 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -1495,7 +1495,7 @@ static NTSTATUS smbd_claim_version(struct messaging_context *msg,
 	if (!NT_STATUS_IS_OK(status) &&
 	    !NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
 		DBG_ERR("Could not read samba_version_string\n");
-		g_lock_unlock(ctx, name);
+		g_lock_unlock(ctx, string_term_tdb_data(name));
 		TALLOC_FREE(ctx);
 		return status;
 	}
diff --git a/source3/torture/test_g_lock.c b/source3/torture/test_g_lock.c
index 2dcba1e68e2..1d3be9cbad0 100644
--- a/source3/torture/test_g_lock.c
+++ b/source3/torture/test_g_lock.c
@@ -84,14 +84,14 @@ bool run_g_lock1(int dummy)
 		goto fail;
 	}
 
-	status = g_lock_unlock(ctx, lockname);
+	status = g_lock_unlock(ctx, string_term_tdb_data(lockname));
 	if (!NT_STATUS_IS_OK(status)) {
 		fprintf(stderr, "g_lock_unlock failed: %s\n",
 			nt_errstr(status));
 		goto fail;
 	}
 
-	status = g_lock_unlock(ctx, lockname);
+	status = g_lock_unlock(ctx, string_term_tdb_data(lockname));
 	if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
 		fprintf(stderr, "g_lock_unlock returned: %s\n",
 			nt_errstr(status));
@@ -170,7 +170,7 @@ bool run_g_lock2(int dummy)
 		goto fail;
 	}
 
-	status = g_lock_unlock(ctx, lockname);
+	status = g_lock_unlock(ctx, string_term_tdb_data(lockname));
 	if (!NT_STATUS_IS_OK(status)) {
 		fprintf(stderr, "g_lock_unlock failed: %s\n",
 			nt_errstr(status));
@@ -688,7 +688,7 @@ bool run_g_lock5(int dummy)
 				nt_errstr(status));
 			return false;
 		}
-		status = g_lock_unlock(ctx, lockname);
+		status = g_lock_unlock(ctx, string_term_tdb_data(lockname));
 		if (!NT_STATUS_IS_OK(status)) {
 			fprintf(stderr, "g_lock_unlock failed %s\n",
 				nt_errstr(status));
@@ -922,7 +922,7 @@ bool run_g_lock_ping_pong(int dummy)
 
 		name[10] = '0' + ((i) % torture_nprocs);
 
-		status = g_lock_unlock(ctx, name);
+		status = g_lock_unlock(ctx, string_term_tdb_data(name));
 		if (!NT_STATUS_IS_OK(status)) {
 			fprintf(stderr, "g_lock_unlock failed: %s\n",
 				nt_errstr(status));
-- 
2.11.0


From 2c29c3a0349d4a23930cdcdc77b5228d4f67a045 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 3 Dec 2017 20:47:02 +0100
Subject: [PATCH 4/7] lib: Make g_lock_write_data use TDB_DATA

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/include/g_lock.h      |  2 +-
 source3/lib/g_lock.c          | 13 ++++++++-----
 source3/smbd/server.c         |  3 ++-
 source3/torture/test_g_lock.c |  6 ++++--
 4 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/source3/include/g_lock.h b/source3/include/g_lock.h
index a1d845f3074..20cee4c1a43 100644
--- a/source3/include/g_lock.h
+++ b/source3/include/g_lock.h
@@ -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,
diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c
index 653ec34bb7f..45a90a20df8 100644
--- a/source3/lib/g_lock.c
+++ b/source3/lib/g_lock.c
@@ -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",
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index 1d0e317b5c8..df92bd4f356 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -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",
diff --git a/source3/torture/test_g_lock.c b/source3/torture/test_g_lock.c
index 1d3be9cbad0..5e12167cdb5 100644
--- a/source3/torture/test_g_lock.c
+++ b/source3/torture/test_g_lock.c
@@ -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));
-- 
2.11.0


From dc22274e483d4bc6d53ab8879c8ca7e3fbf78432 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 3 Dec 2017 20:47:02 +0100
Subject: [PATCH 5/7] lib: Make g_lock_do use TDB_DATA

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/include/g_lock.h     | 2 +-
 source3/lib/g_lock.c         | 7 +++----
 source3/utils/net_g_lock.c   | 3 ++-
 source3/utils/net_registry.c | 5 +++--
 4 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/source3/include/g_lock.h b/source3/include/g_lock.h
index 20cee4c1a43..dcdb8eee73a 100644
--- a/source3/include/g_lock.h
+++ b/source3/include/g_lock.h
@@ -51,7 +51,7 @@ NTSTATUS g_lock_unlock(struct g_lock_ctx *ctx, TDB_DATA key);
 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,
+NTSTATUS g_lock_do(TDB_DATA key, enum g_lock_type lock_type,
 		   struct timeval timeout,
 		   void (*fn)(void *private_data), void *private_data);
 
diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c
index 45a90a20df8..8b634e8bf64 100644
--- a/source3/lib/g_lock.c
+++ b/source3/lib/g_lock.c
@@ -773,7 +773,7 @@ fail:
 	return false;
 }
 
-NTSTATUS g_lock_do(const char *name, enum g_lock_type lock_type,
+NTSTATUS g_lock_do(TDB_DATA key, enum g_lock_type lock_type,
 		   struct timeval timeout,
 		   void (*fn)(void *private_data), void *private_data)
 {
@@ -787,13 +787,12 @@ NTSTATUS g_lock_do(const char *name, enum g_lock_type lock_type,
 		goto done;
 	}
 
-	status = g_lock_lock(g_ctx, string_term_tdb_data(name), lock_type,
-			     timeout);
+	status = g_lock_lock(g_ctx, key, lock_type, timeout);
 	if (!NT_STATUS_IS_OK(status)) {
 		goto done;
 	}
 	fn(private_data);
-	g_lock_unlock(g_ctx, string_term_tdb_data(name));
+	g_lock_unlock(g_ctx, key);
 
 done:
 	TALLOC_FREE(g_ctx);
diff --git a/source3/utils/net_g_lock.c b/source3/utils/net_g_lock.c
index 0ec6846d10b..ad749c28cf7 100644
--- a/source3/utils/net_g_lock.c
+++ b/source3/utils/net_g_lock.c
@@ -22,6 +22,7 @@
 #include "lib/util/server_id.h"
 #include "g_lock.h"
 #include "messages.h"
+#include "lib/util/util_tdb.h"
 
 static bool net_g_lock_init(TALLOC_CTX *mem_ctx,
 			    struct tevent_context **pev,
@@ -90,7 +91,7 @@ static int net_g_lock_do(struct net_context *c, int argc, const char **argv)
 	state.cmd = cmd;
 	state.result = -1;
 
-	status = g_lock_do(name, G_LOCK_WRITE,
+	status = g_lock_do(string_term_tdb_data(name), G_LOCK_WRITE,
 			   timeval_set(timeout / 1000, timeout % 1000),
 			   net_g_lock_do_fn, &state);
 	if (!NT_STATUS_IS_OK(status)) {
diff --git a/source3/utils/net_registry.c b/source3/utils/net_registry.c
index afc99d58873..c67a148ddd0 100644
--- a/source3/utils/net_registry.c
+++ b/source3/utils/net_registry.c
@@ -37,6 +37,7 @@
 #include "../libcli/registry/util_reg.h"
 #include "passdb/machine_sid.h"
 #include "net_registry_check.h"
+#include "lib/util/util_tdb.h"
 
 /*
  *
@@ -643,8 +644,8 @@ static int net_registry_increment(struct net_context *c, int argc,
 		state.increment = strtoul(argv[2], NULL, 10);
 	}
 
-	status = g_lock_do("registry_increment_lock", G_LOCK_WRITE,
-			   timeval_set(600, 0),
+	status = g_lock_do(string_term_tdb_data("registry_increment_lock"),
+			   G_LOCK_WRITE, timeval_set(600, 0),
 			   net_registry_increment_fn, &state);
 	if (!NT_STATUS_IS_OK(status)) {
 		d_fprintf(stderr, _("g_lock_do failed: %s\n"),
-- 
2.11.0


From 1fe683511faf6dab16bcc46d05ad469d5cb91880 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 3 Dec 2017 20:47:02 +0100
Subject: [PATCH 6/7] lib: Make g_lock_dump use TDB_DATA

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/include/g_lock.h      |  2 +-
 source3/lib/g_lock.c          | 13 +++++++------
 source3/smbd/server.c         |  3 ++-
 source3/torture/test_g_lock.c | 18 ++++++++++++------
 source3/utils/net_g_lock.c    |  3 ++-
 5 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/source3/include/g_lock.h b/source3/include/g_lock.h
index dcdb8eee73a..a0d8c251dfd 100644
--- a/source3/include/g_lock.h
+++ b/source3/include/g_lock.h
@@ -58,7 +58,7 @@ NTSTATUS g_lock_do(TDB_DATA key, enum g_lock_type lock_type,
 int g_lock_locks(struct g_lock_ctx *ctx,
 		 int (*fn)(const char *name, void *private_data),
 		 void *private_data);
-NTSTATUS g_lock_dump(struct g_lock_ctx *ctx, const char *name,
+NTSTATUS g_lock_dump(struct g_lock_ctx *ctx, TDB_DATA key,
 		     void (*fn)(const struct g_lock_rec *locks,
 				size_t num_locks,
 				const uint8_t *data,
diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c
index 8b634e8bf64..3988cec2e3c 100644
--- a/source3/lib/g_lock.c
+++ b/source3/lib/g_lock.c
@@ -662,7 +662,7 @@ int g_lock_locks(struct g_lock_ctx *ctx,
 
 struct g_lock_dump_state {
 	TALLOC_CTX *mem_ctx;
-	const char *name;
+	TDB_DATA key;
 	void (*fn)(const struct g_lock_rec *locks,
 		   size_t num_locks,
 		   const uint8_t *data,
@@ -684,7 +684,9 @@ static void g_lock_dump_fn(TDB_DATA key, TDB_DATA data,
 	ok = g_lock_parse(data.dptr, data.dsize, &lck);
 	if (!ok) {
 		DBG_DEBUG("g_lock_parse failed for %s\n",
-			  state->name);
+			  hex_encode_talloc(talloc_tos(),
+					    state->key.dptr,
+					    state->key.dsize));
 		state->status = NT_STATUS_INTERNAL_DB_CORRUPTION;
 		return;
 	}
@@ -708,7 +710,7 @@ static void g_lock_dump_fn(TDB_DATA key, TDB_DATA data,
 	state->status = NT_STATUS_OK;
 }
 
-NTSTATUS g_lock_dump(struct g_lock_ctx *ctx, const char *name,
+NTSTATUS g_lock_dump(struct g_lock_ctx *ctx, TDB_DATA key,
 		     void (*fn)(const struct g_lock_rec *locks,
 				size_t num_locks,
 				const uint8_t *data,
@@ -717,13 +719,12 @@ NTSTATUS g_lock_dump(struct g_lock_ctx *ctx, const char *name,
 		     void *private_data)
 {
 	struct g_lock_dump_state state = {
-		.mem_ctx = ctx, .name = name,
+		.mem_ctx = ctx, .key = key,
 		.fn = fn, .private_data = private_data
 	};
 	NTSTATUS status;
 
-	status = dbwrap_parse_record(ctx->db, string_term_tdb_data(name),
-				     g_lock_dump_fn, &state);
+	status = dbwrap_parse_record(ctx->db, key, g_lock_dump_fn, &state);
 	if (!NT_STATUS_IS_OK(status)) {
 		DBG_DEBUG("dbwrap_parse_record returned %s\n",
 			  nt_errstr(status));
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index df92bd4f356..99baf9d519d 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -1491,7 +1491,8 @@ static NTSTATUS smbd_claim_version(struct messaging_context *msg,
 
 	state = (struct smbd_claim_version_state) { .mem_ctx = ctx };
 
-	status = g_lock_dump(ctx, name, smbd_claim_version_parser, &state);
+	status = g_lock_dump(ctx, string_term_tdb_data(name),
+			     smbd_claim_version_parser, &state);
 	if (!NT_STATUS_IS_OK(status) &&
 	    !NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
 		DBG_ERR("Could not read samba_version_string\n");
diff --git a/source3/torture/test_g_lock.c b/source3/torture/test_g_lock.c
index 5e12167cdb5..43e699fb173 100644
--- a/source3/torture/test_g_lock.c
+++ b/source3/torture/test_g_lock.c
@@ -179,7 +179,8 @@ bool run_g_lock2(int dummy)
 		goto fail;
 	}
 
-	status = g_lock_dump(ctx, lockname, lock2_parser, &state);
+	status = g_lock_dump(ctx, string_term_tdb_data(lockname),
+			     lock2_parser, &state);
 	if (!NT_STATUS_IS_OK(status)) {
 		fprintf(stderr, "g_lock_dump failed: %s\n",
 			nt_errstr(status));
@@ -283,7 +284,8 @@ bool run_g_lock3(int dummy)
 	state.lock_type = G_LOCK_READ;
 	state.ok = false;
 
-	status = g_lock_dump(ctx, lockname, lock3_parser, &state);
+	status = g_lock_dump(ctx, string_term_tdb_data(lockname),
+			     lock3_parser, &state);
 	if (!NT_STATUS_EQUAL(status, NT_STATUS_OK)) {
 		fprintf(stderr, "g_lock_dump returned %s\n",
 			nt_errstr(status));
@@ -304,7 +306,8 @@ bool run_g_lock3(int dummy)
 	state.lock_type = G_LOCK_WRITE;
 	state.ok = false;
 
-	status = g_lock_dump(ctx, lockname, lock3_parser, &state);
+	status = g_lock_dump(ctx, string_term_tdb_data(lockname),
+			     lock3_parser, &state);
 	if (!NT_STATUS_EQUAL(status, NT_STATUS_OK)) {
 		fprintf(stderr, "g_lock_dump returned %s\n",
 			nt_errstr(status));
@@ -537,7 +540,8 @@ bool run_g_lock4(int dummy)
 			.me = messaging_server_id(msg)
 		};
 
-		status = g_lock_dump(ctx, lockname, lock4_check, &state);
+		status = g_lock_dump(ctx, string_term_tdb_data(lockname),
+				     lock4_check, &state);
 		if (!NT_STATUS_IS_OK(status)) {
 			fprintf(stderr, "g_lock_dump failed: %s\n",
 				nt_errstr(status));
@@ -669,7 +673,8 @@ bool run_g_lock5(int dummy)
 	for (i=0; i<nprocs; i++) {
 		struct lock5_parser_state state;
 
-		status = g_lock_dump(ctx, lockname, lock5_parser, &state);
+		status = g_lock_dump(ctx, string_term_tdb_data(lockname),
+				     lock5_parser, &state);
 		if (!NT_STATUS_IS_OK(status)) {
 			fprintf(stderr, "g_lock_dump returned %s\n",
 				nt_errstr(status));
@@ -819,7 +824,8 @@ bool run_g_lock6(int dummy)
 	{
 		struct lock6_parser_state state;
 
-		status = g_lock_dump(ctx, lockname, lock6_parser, &state);
+		status = g_lock_dump(ctx, string_term_tdb_data(lockname),
+				     lock6_parser, &state);
 		if (!NT_STATUS_IS_OK(status)) {
 			fprintf(stderr, "g_lock_dump returned %s\n",
 				nt_errstr(status));
diff --git a/source3/utils/net_g_lock.c b/source3/utils/net_g_lock.c
index ad749c28cf7..2daa0206113 100644
--- a/source3/utils/net_g_lock.c
+++ b/source3/utils/net_g_lock.c
@@ -143,7 +143,8 @@ static int net_g_lock_dump(struct net_context *c, int argc, const char **argv)
 		goto done;
 	}
 
-	(void)g_lock_dump(g_ctx, argv[0], net_g_lock_dump_fn, NULL);
+	(void)g_lock_dump(g_ctx, string_term_tdb_data(argv[0]),
+			  net_g_lock_dump_fn, NULL);
 
 	ret = 0;
 done:
-- 
2.11.0


From 5195af76484261b609fbaf4064c5bfe10c254164 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 3 Dec 2017 20:47:02 +0100
Subject: [PATCH 7/7] lib: Make g_lock_locks use TDB_DATA

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/include/g_lock.h   |  2 +-
 source3/lib/g_lock.c       | 10 +++-------
 source3/utils/net_g_lock.c |  8 ++++++--
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/source3/include/g_lock.h b/source3/include/g_lock.h
index a0d8c251dfd..c3e3a509b80 100644
--- a/source3/include/g_lock.h
+++ b/source3/include/g_lock.h
@@ -56,7 +56,7 @@ NTSTATUS g_lock_do(TDB_DATA key, enum g_lock_type lock_type,
 		   void (*fn)(void *private_data), void *private_data);
 
 int g_lock_locks(struct g_lock_ctx *ctx,
-		 int (*fn)(const char *name, void *private_data),
+		 int (*fn)(TDB_DATA key, void *private_data),
 		 void *private_data);
 NTSTATUS g_lock_dump(struct g_lock_ctx *ctx, TDB_DATA key,
 		     void (*fn)(const struct g_lock_rec *locks,
diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c
index 3988cec2e3c..9ce0e062275 100644
--- a/source3/lib/g_lock.c
+++ b/source3/lib/g_lock.c
@@ -625,7 +625,7 @@ NTSTATUS g_lock_write_data(struct g_lock_ctx *ctx, TDB_DATA key,
 }
 
 struct g_lock_locks_state {
-	int (*fn)(const char *name, void *private_data);
+	int (*fn)(TDB_DATA key, void *private_data);
 	void *private_data;
 };
 
@@ -635,15 +635,11 @@ static int g_lock_locks_fn(struct db_record *rec, void *priv)
 	struct g_lock_locks_state *state = (struct g_lock_locks_state *)priv;
 
 	key = dbwrap_record_get_key(rec);
-	if ((key.dsize == 0) || (key.dptr[key.dsize-1] != 0)) {
-		DEBUG(1, ("invalid key in g_lock.tdb, ignoring\n"));
-		return 0;
-	}
-	return state->fn((char *)key.dptr, state->private_data);
+	return state->fn(key, state->private_data);
 }
 
 int g_lock_locks(struct g_lock_ctx *ctx,
-		 int (*fn)(const char *name, void *private_data),
+		 int (*fn)(TDB_DATA key, void *private_data),
 		 void *private_data)
 {
 	struct g_lock_locks_state state;
diff --git a/source3/utils/net_g_lock.c b/source3/utils/net_g_lock.c
index 2daa0206113..8b839d2e09f 100644
--- a/source3/utils/net_g_lock.c
+++ b/source3/utils/net_g_lock.c
@@ -154,9 +154,13 @@ done:
 	return ret;
 }
 
-static int net_g_lock_locks_fn(const char *name, void *private_data)
+static int net_g_lock_locks_fn(TDB_DATA key, void *private_data)
 {
-	d_printf("%s\n", name);
+	if ((key.dsize == 0) || (key.dptr[key.dsize-1] != 0)) {
+		DEBUG(1, ("invalid key in g_lock.tdb, ignoring\n"));
+		return 0;
+	}
+	d_printf("%s\n", (const char *)key.dptr);
 	return 0;
 }
 
-- 
2.11.0



More information about the samba-technical mailing list