summaryrefslogtreecommitdiff
path: root/source3/utils
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2020-12-18 14:57:08 +0100
committerJeremy Allison <jra@samba.org>2021-08-06 17:22:30 +0000
commita1cbb8bc448f9cd1de4afd07fa982d223a176891 (patch)
tree3c62685676851edbb643ac77397d115972bbc3f5 /source3/utils
parent1881240d46850581ece52ca10c4af1a7797ca549 (diff)
downloadsamba-a1cbb8bc448f9cd1de4afd07fa982d223a176891.tar.gz
net: Use dbwrap_do_locked() in wipedbs_delete_records()
Eventually I'd like to get rid of dbwrap_fetch_locked() Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3/utils')
-rw-r--r--source3/utils/net_serverid.c104
1 files changed, 65 insertions, 39 deletions
diff --git a/source3/utils/net_serverid.c b/source3/utils/net_serverid.c
index 92892e5a4fa..45df3b74ce4 100644
--- a/source3/utils/net_serverid.c
+++ b/source3/utils/net_serverid.c
@@ -436,63 +436,89 @@ done:
return status;
}
+struct wipedbs_delete_state {
+ struct wipedbs_record_marker *cur;
+ bool verbose;
+ bool dry_run;
+ size_t total;
+ size_t num;
+};
+
+static void wipedbs_delete_fn(
+ struct db_record *rec, TDB_DATA value, void *private_data)
+{
+ struct db_context *db = dbwrap_record_get_db(rec);
+ struct wipedbs_delete_state *state = private_data;
+ struct wipedbs_record_marker *cur = state->cur;
+ NTSTATUS status = NT_STATUS_OK;
+
+ state->total += 1;
+
+ if (!tdb_data_equal(value, cur->val)) {
+ DBG_ERR("Warning: record <%s> from %s changed,"
+ "skip record!\n",
+ cur->desc, dbwrap_name(db));
+ return;
+ }
+
+ if (state->verbose) {
+ d_printf("deleting %s\n", cur->desc);
+ }
+
+ if (!state->dry_run) {
+ status = dbwrap_record_delete(rec);
+ }
+
+ if (!NT_STATUS_IS_OK(status)) {
+ DBG_ERR("Failed to delete record <%s> from %s: %s\n",
+ cur->desc,
+ dbwrap_name(db),
+ nt_errstr(status));
+ return;
+ }
+
+ state->num += 1;
+}
+
static int wipedbs_delete_records(struct db_context *db,
struct wipedbs_record_marker *records,
bool dry_run, bool verbose, int *count)
{
- struct wipedbs_record_marker *cur;
- struct db_record *rec;
- TDB_DATA val;
- NTSTATUS status;
- unsigned num=0, total=0;
+ struct wipedbs_delete_state state = {
+ .verbose = verbose, .dry_run = dry_run,
+ };
if (db == NULL) {
return 0;
}
- for (cur = records; cur != NULL; cur = cur->next) {
- total++;
- rec = dbwrap_fetch_locked(db, talloc_tos(), cur->key);
- if (rec == NULL) {
- DEBUG(0, ("Failed to fetch record <%s> from %s",
- cur->desc, dbwrap_name(db)));
- continue;
- }
- val = dbwrap_record_get_value(rec);
- if (tdb_data_equal(val, cur->val)) {
- if (dry_run) {
- status = NT_STATUS_OK;
- } else {
- status = dbwrap_record_delete(rec);
- }
- if (NT_STATUS_IS_OK(status)) {
- num ++;
- } else {
- DEBUG(0, ("Failed to delete record <%s> from %s"
- ": %s\n", cur->desc, dbwrap_name(db),
- nt_errstr(status)));
- }
- } else {
- DEBUG(0, ("Warning: record <%s> from %s changed"
- ", skip record!\n",
- cur->desc, dbwrap_name(db)));
- }
- if (verbose) {
- d_printf("deleting %s\n", cur->desc);
+ for (state.cur = records;
+ state.cur != NULL;
+ state.cur = state.cur->next) {
+
+ NTSTATUS status = dbwrap_do_locked(
+ db, state.cur->key, wipedbs_delete_fn, &state);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ DBG_ERR("dbwrap_do_locked failed for record <%s> "
+ "from %s\n",
+ state.cur->desc,
+ dbwrap_name(db));
}
- TALLOC_FREE(rec);
}
if (verbose) {
- d_printf("Deleted %u of %u records from %s\n",
- num, total, dbwrap_name(db));
+ d_printf("Deleted %zu of %zu records from %s\n",
+ state.num,
+ state.total,
+ dbwrap_name(db));
}
if (count) {
- *count += total;
+ *count += state.total;
}
- return total - num;
+ return state.total - state.num;
}
static int wipedbs_traverse_server_data(struct db_record *rec,