Line data Source code
1 : /*
2 : * Unix SMB/CIFS implementation.
3 : *
4 : * SMBD RPC modules
5 : *
6 : * Copyright (c) 2015 Ralph Boehme <slow@samba.org>
7 : *
8 : * This program is free software; you can redistribute it and/or modify
9 : * it under the terms of the GNU General Public License as published by
10 : * the Free Software Foundation; either version 3 of the License, or
11 : * (at your option) any later version.
12 : *
13 : * This program is distributed in the hope that it will be useful,
14 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 : * GNU General Public License for more details.
17 : *
18 : * You should have received a copy of the GNU General Public License
19 : * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 : */
21 :
22 : #include "includes.h"
23 : #include "rpc_server/rpc_modules.h"
24 :
25 : #undef DBGC_CLASS
26 : #define DBGC_CLASS DBGC_RPC_SRV
27 :
28 : static struct rpc_module *rpc_modules;
29 :
30 : struct rpc_module {
31 : struct rpc_module *prev, *next;
32 : char *name;
33 : struct rpc_module_fns *fns;
34 : };
35 :
36 60 : static struct rpc_module *find_rpc_module(const char *name)
37 : {
38 60 : struct rpc_module *module = NULL;
39 :
40 60 : for (module = rpc_modules; module != NULL; module = module->next) {
41 0 : if (strequal(module->name, name)) {
42 0 : return module;
43 : }
44 : }
45 :
46 58 : return NULL;
47 : }
48 :
49 60 : NTSTATUS register_rpc_module(struct rpc_module_fns *fns,
50 : const char *name)
51 : {
52 60 : struct rpc_module *module = find_rpc_module(name);
53 :
54 60 : if (module != NULL) {
55 0 : DBG_ERR("RPC module %s already loaded!\n", name);
56 0 : return NT_STATUS_OBJECT_NAME_COLLISION;
57 : }
58 :
59 60 : module = SMB_XMALLOC_P(struct rpc_module);
60 60 : module->name = smb_xstrdup(name);
61 60 : module->fns = fns;
62 :
63 60 : DLIST_ADD(rpc_modules, module);
64 60 : DBG_NOTICE("Successfully added RPC module '%s'\n", name);
65 :
66 60 : return NT_STATUS_OK;
67 : }
68 :
69 0 : bool setup_rpc_module(struct tevent_context *ev_ctx,
70 : struct messaging_context *msg_ctx,
71 : const char *name)
72 : {
73 : bool ok;
74 0 : struct rpc_module *module = find_rpc_module(name);
75 :
76 0 : if (module == NULL) {
77 0 : return false;
78 : }
79 :
80 0 : ok = module->fns->setup(ev_ctx, msg_ctx);
81 0 : if (!ok) {
82 0 : DBG_ERR("calling setup for %s failed\n", name);
83 : }
84 :
85 0 : return true;
86 : }
87 :
88 60 : bool setup_rpc_modules(struct tevent_context *ev_ctx,
89 : struct messaging_context *msg_ctx)
90 : {
91 : bool ok;
92 60 : struct rpc_module *module = rpc_modules;
93 :
94 120 : for (module = rpc_modules; module; module = module->next) {
95 60 : ok = module->fns->setup(ev_ctx, msg_ctx);
96 60 : if (!ok) {
97 0 : DBG_ERR("calling setup for %s failed\n", module->name);
98 : }
99 : }
100 :
101 60 : return true;
102 : }
|