From 4109236cfdd9cec68acd67d46f2155f27d1549b6 Mon Sep 17 00:00:00 2001 From: Volker Lendecke <vl@samba.org> Date: Wed, 2 May 2018 15:26:05 +0200 Subject: [PATCH] winbindd: Introduce "bool_dispatch_table" This is meant to replace the synchronous "dispatch_table". The current dispatch_table assumes that every synchronous function does the request_ok or request_error itself. This mixes two concerns: Doing the work and shipping the reply to the winbind client. This new dispatch table will make it possible to centralize shipping the reply to the client. At a later stage this will enable easier statistics on how long request processing took precisely. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> --- source3/winbindd/winbindd.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c index 76d644b1ba6..f9bea96bf97 100644 --- a/source3/winbindd/winbindd.c +++ b/source3/winbindd/winbindd.c @@ -554,6 +554,13 @@ static struct winbindd_dispatch_table { { WINBINDD_NUM_CMDS, NULL, "NONE" } }; +static struct winbindd_bool_dispatch_table { + enum winbindd_cmd cmd; + bool (*fn)(struct winbindd_cli_state *state); + const char *cmd_name; +} bool_dispatch_table[] = { +}; + struct winbindd_async_dispatch_table { enum winbindd_cmd cmd; const char *cmd_name; @@ -658,6 +665,8 @@ static void process_request(struct winbindd_cli_state *state) { struct winbindd_dispatch_table *table = dispatch_table; struct winbindd_async_dispatch_table *atable; + size_t i; + bool ok; state->mem_ctx = talloc_named(state, 0, "winbind request"); if (state->mem_ctx == NULL) @@ -725,14 +734,32 @@ static void process_request(struct winbindd_cli_state *state) table->winbindd_cmd_name )); state->cmd_name = table->winbindd_cmd_name; table->fn(state); + return; + } + } + + for (i=0; i<ARRAY_SIZE(bool_dispatch_table); i++) { + if (bool_dispatch_table[i].cmd == state->request->cmd) { break; } } - if (!table->fn) { + if (i == ARRAY_SIZE(bool_dispatch_table)) { DEBUG(10,("process_request: unknown request fn number %d\n", (int)state->request->cmd )); request_error(state); + return; + } + + DBG_DEBUG("process_request: request fn %s\n", + bool_dispatch_table[i].cmd_name); + + ok = bool_dispatch_table[i].fn(state); + + if (ok) { + request_ok(state); + } else { + request_error(state); } }