[PATCHES] introduce dbwrap_purge[_bystring]

Michael Adam obnox at samba.org
Thu Feb 25 16:45:52 UTC 2016


dbwrap_delete* return NT_NSTATUS_NOT_FOUND if the record
to delete does not exist. Sometimes all one wants is that
the record does not exist after the function returns.
So some callers map NT_STATUS_NOT_FOUND to NT_STATUS_OK
after the call.

Attached find a small patchset that introduces new
util functions dbwrap_purge (and dbwrap_purge_bystring)
that do exactly that mapping, and adapts all callers
that do this to use the new functions instead.

There are not so many yet, but I plan to add mode in
patches that are currently in prepration.

Is dbwrap_purge a good name?

One additional patch fixes/improves one
debug message in dbwrap.

Review appreciated!

Thanks - Michael
-------------- next part --------------
From 38f44dd96fde5ca5fec1334fd67e060850196006 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Thu, 25 Feb 2016 16:02:36 +0100
Subject: [PATCH 1/4] dbwrap_util: improve a debug message in
 dbwrap_delete_action()

Signed-off-by: Michael Adam <obnox at samba.org>
---
 lib/dbwrap/dbwrap_util.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/dbwrap/dbwrap_util.c b/lib/dbwrap/dbwrap_util.c
index 901ef56..5118fb7 100644
--- a/lib/dbwrap/dbwrap_util.c
+++ b/lib/dbwrap/dbwrap_util.c
@@ -412,7 +412,8 @@ static NTSTATUS dbwrap_delete_action(struct db_context * db, void *private_data)
 
 	status = dbwrap_record_delete(rec);
 	if (!NT_STATUS_IS_OK(status)) {
-		DEBUG(5, ("delete_rec returned %s\n", nt_errstr(status)));
+		DBG_INFO("dbwrap_record_delete returned %s\n",
+			 nt_errstr(status));
 	}
 
 	talloc_free(rec);
-- 
2.5.0


From eedce186d50af5ae4d7bf19d877ff01e5c5964ba Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Thu, 25 Feb 2016 00:56:14 +0100
Subject: [PATCH 2/4] dbwrap: add dbwrap_purge[_bystring]

Variants of dbrwap_delete[_bysrting] that treats NOT FOUND
as success.

Signed-off-by: Michael Adam <obnox at samba.org>
---
 lib/dbwrap/dbwrap.h      |  2 ++
 lib/dbwrap/dbwrap_util.c | 17 +++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/lib/dbwrap/dbwrap.h b/lib/dbwrap/dbwrap.h
index 5e13a59..2eded04 100644
--- a/lib/dbwrap/dbwrap.h
+++ b/lib/dbwrap/dbwrap.h
@@ -94,6 +94,8 @@ const char *dbwrap_name(struct db_context *db);
 
 /* The following definitions come from lib/dbwrap_util.c  */
 
+NTSTATUS dbwrap_purge(struct db_context *db, TDB_DATA key);
+NTSTATUS dbwrap_purge_bystring(struct db_context *db, const char *key);
 NTSTATUS dbwrap_delete_bystring(struct db_context *db, const char *key);
 NTSTATUS dbwrap_store_bystring(struct db_context *db, const char *key,
 			       TDB_DATA data, int flags);
diff --git a/lib/dbwrap/dbwrap_util.c b/lib/dbwrap/dbwrap_util.c
index 5118fb7..22f910d 100644
--- a/lib/dbwrap/dbwrap_util.c
+++ b/lib/dbwrap/dbwrap_util.c
@@ -528,6 +528,23 @@ NTSTATUS dbwrap_trans_traverse(struct db_context *db,
 	return dbwrap_trans_do(db, dbwrap_trans_traverse_action, &ctx);
 }
 
+NTSTATUS dbwrap_purge(struct db_context *db, TDB_DATA key)
+{
+	NTSTATUS status;
+
+	status = dbwrap_delete(db, key);
+	if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
+		status = NT_STATUS_OK;
+	}
+
+	return status;
+}
+
+NTSTATUS dbwrap_purge_bystring(struct db_context *db, const char *key)
+{
+	return dbwrap_purge(db, string_term_tdb_data(key));
+}
+
 NTSTATUS dbwrap_delete_bystring(struct db_context *db, const char *key)
 {
 	return dbwrap_delete(db, string_term_tdb_data(key));
-- 
2.5.0


From 181ea551ee89c52ee81e03f1a7ac8f041ba0ba6c Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Thu, 25 Feb 2016 00:58:50 +0100
Subject: [PATCH 3/4] s3:registry: use dbwrap_purge_bystring instead of
 dbwrap_delete_bystring

where appropriate

Signed-off-by: Michael Adam <obnox at samba.org>
---
 source3/registry/reg_backend_db.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/source3/registry/reg_backend_db.c b/source3/registry/reg_backend_db.c
index 7b3391d..bdfe7d2 100644
--- a/source3/registry/reg_backend_db.c
+++ b/source3/registry/reg_backend_db.c
@@ -966,12 +966,7 @@ static WERROR regdb_delete_key_with_prefix(struct db_context *db,
 		goto done;
 	}
 
-	werr = ntstatus_to_werror(dbwrap_delete_bystring(db, path));
-
-	/* treat "not found" as ok */
-	if (W_ERROR_EQUAL(werr, WERR_NOT_FOUND)) {
-		werr = WERR_OK;
-	}
+	werr = ntstatus_to_werror(dbwrap_purge_bystring(db, path));
 
 done:
 	talloc_free(mem_ctx);
-- 
2.5.0


From 8bcc9bbaa077da369d259693a8e13eb33715963c Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Thu, 25 Feb 2016 16:15:04 +0100
Subject: [PATCH 4/4] netlogon_creds_cli: use dbwrap_purge instead of
 dbwrap_delete where appropriate

Signed-off-by: Michael Adam <obnox at samba.org>
---
 libcli/auth/netlogon_creds_cli.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/libcli/auth/netlogon_creds_cli.c b/libcli/auth/netlogon_creds_cli.c
index 7c867cf..38b1351 100644
--- a/libcli/auth/netlogon_creds_cli.c
+++ b/libcli/auth/netlogon_creds_cli.c
@@ -1031,11 +1031,8 @@ struct tevent_req *netlogon_creds_cli_auth_send(TALLOC_CTX *mem_ctx,
 		return req;
 	}
 
-	status = dbwrap_delete(state->context->db.ctx,
-			       state->context->db.key_data);
-	if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
-		status = NT_STATUS_OK;
-	}
+	status = dbwrap_purge(state->context->db.ctx,
+			      state->context->db.key_data);
 	if (tevent_req_nterror(req, status)) {
 		return tevent_req_post(req, ev);
 	}
@@ -1065,11 +1062,8 @@ static void netlogon_creds_cli_auth_locked(struct tevent_req *subreq)
 	}
 	state->locked_state->is_glocked = true;
 
-	status = dbwrap_delete(state->context->db.ctx,
-			       state->context->db.key_data);
-	if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
-		status = NT_STATUS_OK;
-	}
+	status = dbwrap_purge(state->context->db.ctx,
+			      state->context->db.key_data);
 	if (tevent_req_nterror(req, status)) {
 		return;
 	}
-- 
2.5.0

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20160225/13995da4/signature.sig>


More information about the samba-technical mailing list