The branch, master has been updated via 8109857 winbindd: Remove an unused function prototype via 8f215b8 winbindd: Make "request_error()" static to winbindd.c via 70ce35d winbindd: Make "request_ok()" static to winbindd.c via 0e4e2a0 winbindd: Remove the "old" non-bool dispatch table via 4051b70 winbindd: Make DOMAIN_INFO a proper async request via 7b11e91 winbindd: winbindd_list_trusted_domains() -> bool_dispatch_table via 4f8ea6d winbindd: winbindd_priv_pipe_dir() -> bool_dispatch_table via a781596 winbindd: winbindd_ccache_save() -> bool_dispatch_table via a180f40 winbindd: winbindd_ccache_ntlm_auth() -> bool_dispatch_table via de162c0 winbindd: winbindd_dc_info() -> bool_dispatch_table via 762d8ab winbindd: winbindd_netbios_name() -> bool_dispatch_table via 05105ea winbindd: winbindd_domain_name() -> bool_dispatch_table via c6b9a0f winbindd: winbindd_ping() -> bool_dispatch_table via 25c365c winbindd: winbindd_info() -> bool_dispatch_table via 214d78a winbindd: winbindd_interface_version() -> bool_dispatch_table via 4109236 winbindd: Introduce "bool_dispatch_table" from 87284da ctdb: Drop configuration file ctdbd.conf
https://git.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 8109857f374250a826a8f260b17e2804f09e95e3 Author: Volker Lendecke <v...@samba.org> Date: Wed May 2 21:19:08 2018 +0200 winbindd: Remove an unused function prototype This has been moved to async in 2009 Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Stefan Metzmacher <me...@samba.org> Autobuild-User(master): Volker Lendecke <v...@samba.org> Autobuild-Date(master): Thu May 17 11:30:18 CEST 2018 on sn-devel-144 commit 8f215b8db6600c2e7e1415374eeb0aaa6fcf6860 Author: Volker Lendecke <v...@samba.org> Date: Wed May 2 21:23:49 2018 +0200 winbindd: Make "request_error()" static to winbindd.c Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Stefan Metzmacher <me...@samba.org> commit 70ce35d528d9118f138de6688f94176d18bf6599 Author: Volker Lendecke <v...@samba.org> Date: Wed May 2 21:22:45 2018 +0200 winbindd: Make "request_ok()" static to winbindd.c Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Stefan Metzmacher <me...@samba.org> commit 0e4e2a088398c6fa3c42b69e009fc40b500c7453 Author: Volker Lendecke <v...@samba.org> Date: Wed May 2 21:20:58 2018 +0200 winbindd: Remove the "old" non-bool dispatch table Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Stefan Metzmacher <me...@samba.org> commit 4051b70450b4d6b693e67e4a772911dad3ec0668 Author: Volker Lendecke <v...@samba.org> Date: Wed May 2 20:47:49 2018 +0200 winbindd: Make DOMAIN_INFO a proper async request This has an async code path hidden inside. Expose that properly. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Stefan Metzmacher <me...@samba.org> commit 7b11e917590ff581143ed8d5e01905aa3fb979bd Author: Volker Lendecke <v...@samba.org> Date: Fri May 4 21:19:06 2018 +0200 winbindd: winbindd_list_trusted_domains() -> bool_dispatch_table Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Stefan Metzmacher <me...@samba.org> commit 4f8ea6da431142ce025a4b9281b8e9189b81f878 Author: Volker Lendecke <v...@samba.org> Date: Wed May 2 20:27:43 2018 +0200 winbindd: winbindd_priv_pipe_dir() -> bool_dispatch_table Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Stefan Metzmacher <me...@samba.org> commit a781596ed663b6a47236684e8688dd3cec0f5f8a Author: Volker Lendecke <v...@samba.org> Date: Wed May 2 20:26:19 2018 +0200 winbindd: winbindd_ccache_save() -> bool_dispatch_table Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Stefan Metzmacher <me...@samba.org> commit a180f401f8af719c728ae49da94fc18df354f77e Author: Volker Lendecke <v...@samba.org> Date: Wed May 2 20:23:54 2018 +0200 winbindd: winbindd_ccache_ntlm_auth() -> bool_dispatch_table Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Stefan Metzmacher <me...@samba.org> commit de162c033c0708bfc76c1e698474b2f7225f25a9 Author: Volker Lendecke <v...@samba.org> Date: Wed May 2 18:27:23 2018 +0200 winbindd: winbindd_dc_info() -> bool_dispatch_table Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Stefan Metzmacher <me...@samba.org> commit 762d8ab7595cffd6fda79fd4efabf388f6bc3d13 Author: Volker Lendecke <v...@samba.org> Date: Wed May 2 18:25:00 2018 +0200 winbindd: winbindd_netbios_name() -> bool_dispatch_table Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Stefan Metzmacher <me...@samba.org> commit 05105ea0f8c5eef4c59e8e65b2b4a1bdaffa5279 Author: Volker Lendecke <v...@samba.org> Date: Wed May 2 16:39:20 2018 +0200 winbindd: winbindd_domain_name() -> bool_dispatch_table Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Stefan Metzmacher <me...@samba.org> commit c6b9a0fd70e0ba010b1febb7da9c810960c1a887 Author: Volker Lendecke <v...@samba.org> Date: Wed May 2 16:38:14 2018 +0200 winbindd: winbindd_ping() -> bool_dispatch_table Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Stefan Metzmacher <me...@samba.org> commit 25c365c637776ef2a1fbab1c2ca46dcb7c21bfff Author: Volker Lendecke <v...@samba.org> Date: Wed May 2 16:36:49 2018 +0200 winbindd: winbindd_info() -> bool_dispatch_table Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Stefan Metzmacher <me...@samba.org> commit 214d78a6fab55eac3a80e06daaf91763da135f49 Author: Volker Lendecke <v...@samba.org> Date: Wed May 2 15:26:55 2018 +0200 winbindd: winbindd_interface_version() -> bool_dispatch_table Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Stefan Metzmacher <me...@samba.org> commit 4109236cfdd9cec68acd67d46f2155f27d1549b6 Author: Volker Lendecke <v...@samba.org> Date: Wed May 2 15:26:05 2018 +0200 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 <v...@samba.org> Reviewed-by: Stefan Metzmacher <me...@samba.org> ----------------------------------------------------------------------- Summary of changes: source3/winbindd/winbindd.c | 93 ++++++++++-------- source3/winbindd/winbindd_ccache_access.c | 33 +++---- source3/winbindd/winbindd_domain_info.c | 129 +++++++++++++++++++++++++ source3/winbindd/winbindd_misc.c | 151 +++++------------------------- source3/winbindd/winbindd_proto.h | 32 ++++--- source3/winbindd/wscript_build | 1 + 6 files changed, 234 insertions(+), 205 deletions(-) create mode 100644 source3/winbindd/winbindd_domain_info.c Changeset truncated at 500 lines: diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c index 76d644b..34607ca 100644 --- a/source3/winbindd/winbindd.c +++ b/source3/winbindd/winbindd.c @@ -54,6 +54,8 @@ static bool client_is_idle(struct winbindd_cli_state *state); static void remove_client(struct winbindd_cli_state *state); static void winbindd_setup_max_fds(void); +static void request_ok(struct winbindd_cli_state *state); +static void request_error(struct winbindd_cli_state *state); static bool opt_nocache = False; static bool interactive = False; @@ -521,37 +523,41 @@ static void winbind_msg_validate_cache(struct messaging_context *msg_ctx, _exit(0); } -static struct winbindd_dispatch_table { +static struct winbindd_bool_dispatch_table { enum winbindd_cmd cmd; - void (*fn)(struct winbindd_cli_state *state); - const char *winbindd_cmd_name; -} dispatch_table[] = { - - /* Enumeration functions */ - - { WINBINDD_LIST_TRUSTDOM, winbindd_list_trusted_domains, - "LIST_TRUSTDOM" }, - - /* Miscellaneous */ - - { WINBINDD_INFO, winbindd_info, "INFO" }, - { WINBINDD_PING, winbindd_ping, "PING" }, - { WINBINDD_INTERFACE_VERSION, winbindd_interface_version, + bool (*fn)(struct winbindd_cli_state *state); + const char *cmd_name; +} bool_dispatch_table[] = { + { WINBINDD_INTERFACE_VERSION, + winbindd_interface_version, "INTERFACE_VERSION" }, - { WINBINDD_DOMAIN_NAME, winbindd_domain_name, "DOMAIN_NAME" }, - { WINBINDD_DOMAIN_INFO, winbindd_domain_info, "DOMAIN_INFO" }, - { WINBINDD_DC_INFO, winbindd_dc_info, "DC_INFO" }, - { WINBINDD_NETBIOS_NAME, winbindd_netbios_name, "NETBIOS_NAME" }, - { WINBINDD_PRIV_PIPE_DIR, winbindd_priv_pipe_dir, + { WINBINDD_INFO, + winbindd_info, + "INFO" }, + { WINBINDD_PING, + winbindd_ping, + "PING" }, + { WINBINDD_DOMAIN_NAME, + winbindd_domain_name, + "DOMAIN_NAME" }, + { WINBINDD_NETBIOS_NAME, + winbindd_netbios_name, + "NETBIOS_NAME" }, + { WINBINDD_DC_INFO, + winbindd_dc_info, + "DC_INFO" }, + { WINBINDD_CCACHE_NTLMAUTH, + winbindd_ccache_ntlm_auth, + "NTLMAUTH" }, + { WINBINDD_CCACHE_SAVE, + winbindd_ccache_save, + "CCACHE_SAVE" }, + { WINBINDD_PRIV_PIPE_DIR, + winbindd_priv_pipe_dir, "WINBINDD_PRIV_PIPE_DIR" }, - - /* Credential cache access */ - { WINBINDD_CCACHE_NTLMAUTH, winbindd_ccache_ntlm_auth, "NTLMAUTH" }, - { WINBINDD_CCACHE_SAVE, winbindd_ccache_save, "CCACHE_SAVE" }, - - /* End of list */ - - { WINBINDD_NUM_CMDS, NULL, "NONE" } + { WINBINDD_LIST_TRUSTDOM, + winbindd_list_trusted_domains, + "LIST_TRUSTDOM" }, }; struct winbindd_async_dispatch_table { @@ -635,6 +641,8 @@ static struct winbindd_async_dispatch_table async_nonpriv_table[] = { winbindd_wins_byip_send, winbindd_wins_byip_recv }, { WINBINDD_WINS_BYNAME, "WINS_BYNAME", winbindd_wins_byname_send, winbindd_wins_byname_recv }, + { WINBINDD_DOMAIN_INFO, "DOMAIN_INFO", + winbindd_domain_info_send, winbindd_domain_info_recv }, { 0, NULL, NULL, NULL } }; @@ -656,8 +664,9 @@ static void wb_request_done(struct tevent_req *req); 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) @@ -719,20 +728,28 @@ static void process_request(struct winbindd_cli_state *state) state->response->result = WINBINDD_PENDING; state->response->length = sizeof(struct winbindd_response); - for (table = dispatch_table; table->fn; table++) { - if (state->request->cmd == table->cmd) { - DEBUG(10,("process_request: request fn %s\n", - table->winbindd_cmd_name )); - state->cmd_name = table->winbindd_cmd_name; - table->fn(state); + 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); } } @@ -842,14 +859,14 @@ static void winbind_client_response_written(struct tevent_req *req) state->io_req = req; } -void request_error(struct winbindd_cli_state *state) +static void request_error(struct winbindd_cli_state *state) { SMB_ASSERT(state->response->result == WINBINDD_PENDING); state->response->result = WINBINDD_ERROR; request_finished(state); } -void request_ok(struct winbindd_cli_state *state) +static void request_ok(struct winbindd_cli_state *state) { SMB_ASSERT(state->response->result == WINBINDD_PENDING); state->response->result = WINBINDD_OK; diff --git a/source3/winbindd/winbindd_ccache_access.c b/source3/winbindd/winbindd_ccache_access.c index ddeaf1d..b3a8c89 100644 --- a/source3/winbindd/winbindd_ccache_access.c +++ b/source3/winbindd/winbindd_ccache_access.c @@ -180,7 +180,7 @@ static bool check_client_uid(struct winbindd_cli_state *state, uid_t uid) return True; } -void winbindd_ccache_ntlm_auth(struct winbindd_cli_state *state) +bool winbindd_ccache_ntlm_auth(struct winbindd_cli_state *state) { struct winbindd_domain *domain; fstring name_namespace, name_domain, name_user; @@ -206,8 +206,7 @@ void winbindd_ccache_ntlm_auth(struct winbindd_cli_state *state) if (!ok) { DEBUG(5,("winbindd_ccache_ntlm_auth: cannot parse domain and user from name [%s]\n", state->request->data.ccache_ntlm_auth.user)); - request_error(state); - return; + return false; } domain = find_auth_domain(state->request->flags, name_domain); @@ -215,13 +214,11 @@ void winbindd_ccache_ntlm_auth(struct winbindd_cli_state *state) if (domain == NULL) { DEBUG(5,("winbindd_ccache_ntlm_auth: can't get domain [%s]\n", name_domain)); - request_error(state); - return; + return false; } if (!check_client_uid(state, state->request->data.ccache_ntlm_auth.uid)) { - request_error(state); - return; + return false; } /* validate blob lengths */ @@ -309,14 +306,10 @@ void winbindd_ccache_ntlm_auth(struct winbindd_cli_state *state) data_blob_free(&auth); process_result: - if (!NT_STATUS_IS_OK(result)) { - request_error(state); - return; - } - request_ok(state); + return NT_STATUS_IS_OK(result); } -void winbindd_ccache_save(struct winbindd_cli_state *state) +bool winbindd_ccache_save(struct winbindd_cli_state *state) { struct winbindd_domain *domain; fstring name_namespace, name_domain, name_user; @@ -343,8 +336,7 @@ void winbindd_ccache_save(struct winbindd_cli_state *state) DEBUG(5,("winbindd_ccache_save: cannot parse domain and user " "from name [%s]\n", state->request->data.ccache_save.user)); - request_error(state); - return; + return false; } /* @@ -360,13 +352,11 @@ void winbindd_ccache_save(struct winbindd_cli_state *state) if (domain == NULL) { DEBUG(5, ("winbindd_ccache_save: can't get domain [%s]\n", name_domain)); - request_error(state); - return; + return false; } if (!check_client_uid(state, state->request->data.ccache_save.uid)) { - request_error(state); - return; + return false; } status = winbindd_add_memory_creds( @@ -377,8 +367,7 @@ void winbindd_ccache_save(struct winbindd_cli_state *state) if (!NT_STATUS_IS_OK(status)) { DEBUG(1, ("winbindd_add_memory_creds failed %s\n", nt_errstr(status))); - request_error(state); - return; + return false; } - request_ok(state); + return true; } diff --git a/source3/winbindd/winbindd_domain_info.c b/source3/winbindd/winbindd_domain_info.c new file mode 100644 index 0000000..126691a --- /dev/null +++ b/source3/winbindd/winbindd_domain_info.c @@ -0,0 +1,129 @@ +/* + * Unix SMB/CIFS implementation. + * async implementation of WINBINDD_DOMAIN_INFO + * Copyright (C) Volker Lendecke 2018 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "includes.h" +#include "winbindd.h" + +struct winbindd_domain_info_state { + struct winbindd_domain *domain; + struct winbindd_request ping_request; +}; + +static void winbindd_domain_info_done(struct tevent_req *subreq); + +struct tevent_req *winbindd_domain_info_send( + TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct winbindd_cli_state *cli, + struct winbindd_request *request) +{ + struct tevent_req *req, *subreq; + struct winbindd_domain_info_state *state; + + req = tevent_req_create(mem_ctx, &state, + struct winbindd_domain_info_state); + if (req == NULL) { + return NULL; + } + + DEBUG(3, ("[%5lu]: domain_info [%s]\n", (unsigned long)cli->pid, + cli->request->domain_name)); + + state->domain = find_domain_from_name_noinit( + cli->request->domain_name); + + if (state->domain == NULL) { + DEBUG(3, ("Did not find domain [%s]\n", + cli->request->domain_name)); + tevent_req_nterror(req, NT_STATUS_NO_SUCH_DOMAIN); + return tevent_req_post(req, ev); + } + + if (state->domain->initialized) { + tevent_req_done(req); + return tevent_req_post(req, ev); + } + + state->ping_request.cmd = WINBINDD_PING; + + /* + * Send a ping down. This implicitly initializes the domain. + */ + + subreq = wb_domain_request_send(state, server_event_context(), + state->domain, &state->ping_request); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, winbindd_domain_info_done, req); + + return req; +} + +static void winbindd_domain_info_done(struct tevent_req *subreq) +{ + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct winbindd_domain_info_state *state = tevent_req_data( + req, struct winbindd_domain_info_state); + struct winbindd_response *response; + int ret, err; + + ret = wb_domain_request_recv(subreq, state, &response, &err); + TALLOC_FREE(subreq); + if (ret == -1) { + DBG_DEBUG("wb_domain_request failed: %s\n", strerror(err)); + tevent_req_nterror(req, map_nt_error_from_unix(err)); + return; + } + + if (!state->domain->initialized) { + DBG_INFO("wb_domain_request did not initialize domain %s\n", + state->domain->name); + tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR); + return; + } + + tevent_req_done(req); +} + +NTSTATUS winbindd_domain_info_recv(struct tevent_req *req, + struct winbindd_response *response) +{ + struct winbindd_domain_info_state *state = tevent_req_data( + req, struct winbindd_domain_info_state); + struct winbindd_domain *domain = state->domain; + NTSTATUS status; + + if (tevent_req_is_nterror(req, &status)) { + DBG_DEBUG("winbindd_domain_info failed: %s\n", + nt_errstr(status)); + return status; + } + + fstrcpy(response->data.domain_info.name, domain->name); + fstrcpy(response->data.domain_info.alt_name, domain->alt_name); + sid_to_fstring(response->data.domain_info.sid, &domain->sid); + + response->data.domain_info.native_mode = domain->native_mode; + response->data.domain_info.active_directory = domain->active_directory; + response->data.domain_info.primary = domain->primary; + + return NT_STATUS_OK; +} diff --git a/source3/winbindd/winbindd_misc.c b/source3/winbindd/winbindd_misc.c index c101269..46273a9 100644 --- a/source3/winbindd/winbindd_misc.c +++ b/source3/winbindd/winbindd_misc.c @@ -203,25 +203,24 @@ static bool trust_is_transitive(struct winbindd_tdc_domain *domain) return transitive; } -void winbindd_list_trusted_domains(struct winbindd_cli_state *state) +bool winbindd_list_trusted_domains(struct winbindd_cli_state *state) { struct winbindd_tdc_domain *dom_list = NULL; size_t num_domains = 0; int extra_data_len = 0; char *extra_data = NULL; int i = 0; + bool ret = false; DEBUG(3, ("[%5lu]: list trusted domains\n", (unsigned long)state->pid)); if( !wcache_tdc_fetch_list( &dom_list, &num_domains )) { - request_error(state); goto done; } extra_data = talloc_strdup(state->mem_ctx, ""); if (extra_data == NULL) { - request_error(state); goto done; } @@ -269,9 +268,10 @@ void winbindd_list_trusted_domains(struct winbindd_cli_state *state) state->response->length += extra_data_len; } - request_ok(state); + ret = true; done: TALLOC_FREE( dom_list ); + return ret; } enum winbindd_result winbindd_dual_list_trusted_domains(struct winbindd_domain *domain, @@ -346,113 +346,7 @@ enum winbindd_result winbindd_dual_list_trusted_domains(struct winbindd_domain * return WINBINDD_OK; } -struct domain_info_state { - struct winbindd_domain *domain; - struct winbindd_cli_state *cli; - struct winbindd_request ping_request; -}; - -static void domain_info_done(struct tevent_req *req); - -void winbindd_domain_info(struct winbindd_cli_state *cli) -{ - struct domain_info_state *state; - struct winbindd_domain *domain; - struct tevent_req *req; - - DEBUG(3, ("[%5lu]: domain_info [%s]\n", (unsigned long)cli->pid, - cli->request->domain_name)); - - domain = find_domain_from_name_noinit(cli->request->domain_name); - - if (domain == NULL) { - DEBUG(3, ("Did not find domain [%s]\n", - cli->request->domain_name)); - request_error(cli); - return; - } - - if (domain->initialized) { - fstrcpy(cli->response->data.domain_info.name, - domain->name); - fstrcpy(cli->response->data.domain_info.alt_name, - domain->alt_name); - sid_to_fstring(cli->response->data.domain_info.sid, - &domain->sid); - cli->response->data.domain_info.native_mode = - domain->native_mode; - cli->response->data.domain_info.active_directory = - domain->active_directory; - cli->response->data.domain_info.primary = - domain->primary; - request_ok(cli); - return; - } - - state = talloc_zero(cli->mem_ctx, struct domain_info_state); - if (state == NULL) { - DEBUG(0, ("talloc failed\n")); - request_error(cli); - return; - } - - state->cli = cli; - state->domain = domain; - state->ping_request.cmd = WINBINDD_PING; - - /* - * Send a ping down. This implicitly initializes the domain. - */ - - req = wb_domain_request_send(state, server_event_context(), - domain, &state->ping_request); - if (req == NULL) { - DEBUG(3, ("wb_domain_request_send failed\n")); - request_error(cli); - return; - } - tevent_req_set_callback(req, domain_info_done, state); -} - -- Samba Shared Repository