The branch, master has been updated via 6018a77 s3:rpc_server: make it possible to build mdssvc as a shared module via 593abe5 s3:rpc_server: allow building RPC services as shared modules from 4164111 testprogs/blackbox/subunit: Fix testok
https://git.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 6018a7756f9610ffd392371a3d5e5a433d7528a5 Author: Ralph Boehme <s...@samba.org> Date: Tue Oct 6 13:45:33 2015 +0200 s3:rpc_server: make it possible to build mdssvc as a shared module Allow building mdssvc RPC service as shared module: --with-shared-modules=rpc_mdssvc_module The default is to build it static. Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Guenther Deschner <g...@samba.org> Reviewed-by: Andreas Schneider <a...@samba.org> Autobuild-User(master): Ralph Böhme <s...@samba.org> Autobuild-Date(master): Sun Feb 21 22:28:41 CET 2016 on sn-devel-144 commit 593abe5f6bf3eefba35218214efb31907fa11bd7 Author: Ralph Boehme <s...@samba.org> Date: Sat Oct 24 10:50:43 2015 +0200 s3:rpc_server: allow building RPC services as shared modules This is the general RPC subsystem change, existing modules must be tweaked to support being loaded as a module. The next commit shows how to do this for the Spotlight RPC service. The general syntax is: --with-shared-modules=rpc_NAME_module Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Guenther Deschner <g...@samba.org> Reviewed-by: Andreas Schneider <a...@samba.org> ----------------------------------------------------------------------- Summary of changes: source3/rpc_server/mdssd.c | 40 ++------- source3/rpc_server/mdssvc/srv_mdssvc_nt.c | 66 ++++++++++++++ source3/rpc_server/rpc_modules.c | 138 ++++++++++++++++++++++++++++++ source3/rpc_server/rpc_modules.h | 47 ++++++++++ source3/rpc_server/rpc_service_setup.c | 85 ++++++------------ source3/rpc_server/rpc_service_setup.h | 6 ++ source3/rpc_server/wscript_build | 32 ++++--- source3/wscript | 3 +- 8 files changed, 310 insertions(+), 107 deletions(-) create mode 100644 source3/rpc_server/rpc_modules.c create mode 100644 source3/rpc_server/rpc_modules.h Changeset truncated at 500 lines: diff --git a/source3/rpc_server/mdssd.c b/source3/rpc_server/mdssd.c index f76d13e..e4c12cd 100644 --- a/source3/rpc_server/mdssd.c +++ b/source3/rpc_server/mdssd.c @@ -34,6 +34,7 @@ #include "rpc_server/rpc_server.h" #include "rpc_server/rpc_ep_register.h" #include "rpc_server/rpc_sock_helper.h" +#include "rpc_server/rpc_modules.h" #include "librpc/gen_ndr/srv_mdssvc.h" #include "rpc_server/mdssvc/srv_mdssvc_nt.h" @@ -91,7 +92,7 @@ static void mdssd_sig_term_handler(struct tevent_context *ev, void *siginfo, void *private_data) { - rpc_mdssvc_shutdown(); + shutdown_rpc_module("mdssvc"); DEBUG(0, ("termination signal\n")); exit(0); @@ -228,10 +229,9 @@ static bool mdssd_child_init(struct tevent_context *ev_ctx, messaging_register(msg_ctx, ev_ctx, MSG_PREFORK_PARENT_EVENT, parent_ping); - status = rpc_mdssvc_init(NULL); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(0, ("Failed to intialize RPC: %s\n", - nt_errstr(status))); + ok = init_rpc_module("mdssvc", NULL); + if (!ok) { + DBG_ERR("Failed to de-intialize RPC\n"); return false; } @@ -608,27 +608,6 @@ done: return ok; } -static bool mdssvc_init_cb(void *ptr) -{ - struct messaging_context *msg_ctx = - talloc_get_type_abort(ptr, struct messaging_context); - bool ok; - - ok = init_service_mdssvc(msg_ctx); - if (!ok) { - return false; - } - - return true; -} - -static bool mdssvc_shutdown_cb(void *ptr) -{ - shutdown_service_mdssvc(); - - return true; -} - void start_mdssd(struct tevent_context *ev_ctx, struct messaging_context *msg_ctx) { @@ -638,7 +617,6 @@ void start_mdssd(struct tevent_context *ev_ctx, pid_t pid; int rc; bool ok; - struct rpc_srv_callbacks mdssvc_cb; DEBUG(1, ("Forking Metadata Service Daemon\n")); @@ -720,12 +698,8 @@ void start_mdssd(struct tevent_context *ev_ctx, messaging_register(msg_ctx, ev_ctx, MSG_PREFORK_CHILD_EVENT, child_ping); - mdssvc_cb.init = mdssvc_init_cb; - mdssvc_cb.shutdown = mdssvc_shutdown_cb; - mdssvc_cb.private_data = msg_ctx; - - status = rpc_mdssvc_init(&mdssvc_cb); - if (!NT_STATUS_IS_OK(status)) { + ok = setup_rpc_module(ev_ctx, msg_ctx, "mdssvc"); + if (!ok) { exit(1); } diff --git a/source3/rpc_server/mdssvc/srv_mdssvc_nt.c b/source3/rpc_server/mdssvc/srv_mdssvc_nt.c index cb0d759..37b13e7 100644 --- a/source3/rpc_server/mdssvc/srv_mdssvc_nt.c +++ b/source3/rpc_server/mdssvc/srv_mdssvc_nt.c @@ -19,6 +19,9 @@ #include "includes.h" #include "ntdomain.h" +#include "rpc_server/rpc_service_setup.h" +#include "rpc_server/rpc_config.h" +#include "rpc_server/rpc_modules.h" #include "rpc_server/mdssvc/srv_mdssvc_nt.h" #include "../librpc/gen_ndr/srv_mdssvc.h" #include "libcli/security/security_token.h" @@ -28,6 +31,69 @@ #undef DBGC_CLASS #define DBGC_CLASS DBGC_RPC_SRV +static bool mdssvc_init_cb(void *ptr) +{ + struct messaging_context *msg_ctx = + talloc_get_type_abort(ptr, struct messaging_context); + bool ok; + + ok = init_service_mdssvc(msg_ctx); + if (!ok) { + return false; + } + + return true; +} + +static bool mdssvc_shutdown_cb(void *ptr) +{ + shutdown_service_mdssvc(); + + return true; +} + +static bool rpc_setup_mdssvc(struct tevent_context *ev_ctx, + struct messaging_context *msg_ctx) +{ + const struct ndr_interface_table *t = &ndr_table_mdssvc; + const char *pipe_name = "mdssvc"; + struct rpc_srv_callbacks mdssvc_cb; + NTSTATUS status; + enum rpc_service_mode_e service_mode = rpc_service_mode(t->name); + enum rpc_daemon_type_e mdssvc_type = rpc_mdssd_daemon(); + + mdssvc_cb.init = mdssvc_init_cb; + mdssvc_cb.shutdown = mdssvc_shutdown_cb; + mdssvc_cb.private_data = msg_ctx; + + status = rpc_mdssvc_init(&mdssvc_cb); + if (!NT_STATUS_IS_OK(status)) { + return false; + } + + if (service_mode != RPC_SERVICE_MODE_EMBEDDED + || mdssvc_type != RPC_DAEMON_EMBEDDED) { + return true; + } + + return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name); +} + +static struct rpc_module_fns rpc_module_mdssvc_fns = { + .setup = rpc_setup_mdssvc, + .init = rpc_mdssvc_init, + .shutdown = rpc_mdssvc_shutdown, +}; + +static_decl_rpc; +NTSTATUS rpc_mdssvc_module_init(void) +{ + DBG_DEBUG("Registering mdsvc RPC service\n"); + + return register_rpc_module(&rpc_module_mdssvc_fns, "mdssvc"); +} + + bool init_service_mdssvc(struct messaging_context *msg_ctx) { return mds_init(msg_ctx); diff --git a/source3/rpc_server/rpc_modules.c b/source3/rpc_server/rpc_modules.c new file mode 100644 index 0000000..69b5d03 --- /dev/null +++ b/source3/rpc_server/rpc_modules.c @@ -0,0 +1,138 @@ +/* + * Unix SMB/CIFS implementation. + * + * SMBD RPC modules + * + * Copyright (c) 2015 Ralph Boehme <s...@samba.org> + * + * 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 "rpc_server/rpc_modules.h" + +static struct rpc_module *rpc_modules; + +struct rpc_module { + struct rpc_module *prev, *next; + char *name; + struct rpc_module_fns *fns; +}; + +static struct rpc_module *find_rpc_module(const char *name) +{ + struct rpc_module *module = NULL; + + for (module = rpc_modules; module != NULL; module = module->next) { + if (strequal(module->name, name)) { + return module; + } + } + + return NULL; +} + +NTSTATUS register_rpc_module(struct rpc_module_fns *fns, + const char *name) +{ + struct rpc_module *module = find_rpc_module(name); + + if (module != NULL) { + DBG_ERR("RPC module %s already loaded!\n", name); + return NT_STATUS_OBJECT_NAME_COLLISION; + } + + module = SMB_XMALLOC_P(struct rpc_module); + module->name = smb_xstrdup(name); + module->fns = fns; + + DLIST_ADD(rpc_modules, module); + DBG_NOTICE("Successfully added RPC module '%s'\n", name); + + return NT_STATUS_OK; +} + +bool setup_rpc_module(struct tevent_context *ev_ctx, + struct messaging_context *msg_ctx, + const char *name) +{ + bool ok; + struct rpc_module *module = find_rpc_module(name); + + if (module == NULL) { + return false; + } + + ok = module->fns->setup(ev_ctx, msg_ctx); + if (!ok) { + DBG_ERR("calling setup for %s failed\n", name); + } + + return true; +} + +bool setup_rpc_modules(struct tevent_context *ev_ctx, + struct messaging_context *msg_ctx) +{ + bool ok; + struct rpc_module *module = rpc_modules; + + for (module = rpc_modules; module; module = module->next) { + ok = module->fns->setup(ev_ctx, msg_ctx); + if (!ok) { + DBG_ERR("calling setup for %s failed\n", module->name); + } + } + + return true; +} + +bool init_rpc_module(const char *name, + const struct rpc_srv_callbacks *rpc_srv_cb) +{ + struct rpc_module *module = find_rpc_module(name); + NTSTATUS status; + + if (module == NULL) { + return false; + } + + status = module->fns->init(rpc_srv_cb); + if (!NT_STATUS_IS_OK(status)) { + DBG_ERR("calling init for %s failed %s\n", + name, nt_errstr(status)); + return false; + } + + return true; +} + +bool shutdown_rpc_module(const char *name) +{ + struct rpc_module *module = find_rpc_module(name); + NTSTATUS status; + + if (module == NULL) { + return false; + } + + status = module->fns->shutdown(); + if (!NT_STATUS_IS_OK(status)) { + DBG_ERR("calling shutdown for %s failed %s\n", + name, nt_errstr(status)); + return false; + } + + return true; +} diff --git a/source3/rpc_server/rpc_modules.h b/source3/rpc_server/rpc_modules.h new file mode 100644 index 0000000..afac1d9 --- /dev/null +++ b/source3/rpc_server/rpc_modules.h @@ -0,0 +1,47 @@ +/* + * Unix SMB/CIFS implementation. + * + * SMBD RPC modules + * + * Copyright (c) 2015 Ralph Boehme <s...@samba.org> + * + * 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/>. + */ + +#ifndef _RPC_MODULES_H +#define _RPC_MODULES_H + +struct rpc_srv_callbacks; + +struct rpc_module_fns { + bool (*setup)(struct tevent_context *ev_ctx, struct messaging_context *msg_ctx); + NTSTATUS (*init)(const struct rpc_srv_callbacks *rpc_srv_cb); + NTSTATUS (*shutdown)(void); +}; + +NTSTATUS register_rpc_module(struct rpc_module_fns *fns, + const char *name); + +bool setup_rpc_modules(struct tevent_context *ev_ctx, + struct messaging_context *msg_ctx); + +bool setup_rpc_module(struct tevent_context *ev_ctx, + struct messaging_context *msg_ctx, + const char *name); + +bool init_rpc_module(const char *name, + const struct rpc_srv_callbacks *rpc_srv_cb); + +bool shutdown_rpc_module(const char *name); +#endif diff --git a/source3/rpc_server/rpc_service_setup.c b/source3/rpc_server/rpc_service_setup.c index ee995a8..e1625ee 100644 --- a/source3/rpc_server/rpc_service_setup.c +++ b/source3/rpc_server/rpc_service_setup.c @@ -38,14 +38,12 @@ #include "../librpc/gen_ndr/srv_spoolss.h" #include "../librpc/gen_ndr/srv_svcctl.h" #include "../librpc/gen_ndr/srv_wkssvc.h" -#include "../librpc/gen_ndr/srv_mdssvc.h" #include "printing/nt_printing_migrate_internal.h" #include "rpc_server/eventlog/srv_eventlog_reg.h" #include "rpc_server/svcctl/srv_svcctl_reg.h" #include "rpc_server/spoolss/srv_spoolss_nt.h" #include "rpc_server/svcctl/srv_svcctl_nt.h" -#include "rpc_server/mdssvc/srv_mdssvc_nt.h" #include "librpc/rpc/dcerpc_ep.h" #include "rpc_server/rpc_sock_helper.h" @@ -53,13 +51,16 @@ #include "rpc_server/rpc_ep_register.h" #include "rpc_server/rpc_server.h" #include "rpc_server/rpc_config.h" +#include "rpc_server/rpc_modules.h" #include "rpc_server/epmapper/srv_epmapper.h" +static_decl_rpc; + /* Common routine for embedded RPC servers */ -static bool rpc_setup_embedded(struct tevent_context *ev_ctx, - struct messaging_context *msg_ctx, - const struct ndr_interface_table *t, - const char *pipe_name) +bool rpc_setup_embedded(struct tevent_context *ev_ctx, + struct messaging_context *msg_ctx, + const struct ndr_interface_table *t, + const char *pipe_name) { struct dcerpc_binding_vector *v; enum rpc_service_mode_e epm_mode = rpc_epmapper_mode(); @@ -445,61 +446,12 @@ static bool rpc_setup_initshutdown(struct tevent_context *ev_ctx, return rpc_setup_embedded(ev_ctx, msg_ctx, t, NULL); } -#ifdef WITH_SPOTLIGHT -static bool mdssvc_init_cb(void *ptr) -{ - struct messaging_context *msg_ctx = - talloc_get_type_abort(ptr, struct messaging_context); - bool ok; - - ok = init_service_mdssvc(msg_ctx); - if (!ok) { - return false; - } - - return true; -} - -static bool mdssvc_shutdown_cb(void *ptr) -{ - shutdown_service_mdssvc(); - - return true; -} - -static bool rpc_setup_mdssvc(struct tevent_context *ev_ctx, - struct messaging_context *msg_ctx) -{ - const struct ndr_interface_table *t = &ndr_table_mdssvc; - const char *pipe_name = "mdssvc"; - struct rpc_srv_callbacks mdssvc_cb; - NTSTATUS status; - enum rpc_service_mode_e service_mode = rpc_service_mode(t->name); - enum rpc_daemon_type_e mdssvc_type = rpc_mdssd_daemon(); - - if (service_mode != RPC_SERVICE_MODE_EMBEDDED - || mdssvc_type != RPC_DAEMON_EMBEDDED) { - return true; - } - - mdssvc_cb.init = mdssvc_init_cb; - mdssvc_cb.shutdown = mdssvc_shutdown_cb; - mdssvc_cb.private_data = msg_ctx; - - status = rpc_mdssvc_init(&mdssvc_cb); - if (!NT_STATUS_IS_OK(status)) { - return false; - } - - return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name); -} -#endif - bool dcesrv_ep_setup(struct tevent_context *ev_ctx, struct messaging_context *msg_ctx) { TALLOC_CTX *tmp_ctx; bool ok; + init_module_fn *mod_init_fns = NULL; tmp_ctx = talloc_stackframe(); if (tmp_ctx == NULL) { @@ -578,12 +530,27 @@ bool dcesrv_ep_setup(struct tevent_context *ev_ctx, goto done; } -#ifdef WITH_SPOTLIGHT - ok = rpc_setup_mdssvc(ev_ctx, msg_ctx); + /* Initialize static subsystems */ + static_init_rpc; + + /* Initialize shared modules */ + mod_init_fns = load_samba_modules(tmp_ctx, "rpc"); + if (mod_init_fns == NULL) { + DBG_ERR("Loading shared RPC modules failed\n"); + goto done; + } + + ok = run_init_functions(mod_init_fns); if (!ok) { + DBG_ERR("Initializing shared RPC modules failed\n"); + goto done; + } + + ok = setup_rpc_modules(ev_ctx, msg_ctx); + if (!ok) { + DBG_ERR("Shared RPC modules setup failed\n"); goto done; } -#endif done: -- Samba Shared Repository