s3-rpc_server: enforce packet level authentication for iremotewinspool server
[samba.git] / source3 / rpc_server / rpc_modules.c
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 static struct rpc_module *rpc_modules;
26
27 struct rpc_module {
28         struct rpc_module *prev, *next;
29         char *name;
30         struct rpc_module_fns *fns;
31 };
32
33 static struct rpc_module *find_rpc_module(const char *name)
34 {
35         struct rpc_module *module = NULL;
36
37         for (module = rpc_modules; module != NULL; module = module->next) {
38                 if (strequal(module->name, name)) {
39                         return module;
40                 }
41         }
42
43         return NULL;
44 }
45
46 NTSTATUS register_rpc_module(struct rpc_module_fns *fns,
47                              const char *name)
48 {
49         struct rpc_module *module = find_rpc_module(name);
50
51         if (module != NULL) {
52                 DBG_ERR("RPC module %s already loaded!\n", name);
53                 return NT_STATUS_OBJECT_NAME_COLLISION;
54         }
55
56         module = SMB_XMALLOC_P(struct rpc_module);
57         module->name = smb_xstrdup(name);
58         module->fns = fns;
59
60         DLIST_ADD(rpc_modules, module);
61         DBG_NOTICE("Successfully added RPC module '%s'\n", name);
62
63         return NT_STATUS_OK;
64 }
65
66 bool setup_rpc_module(struct tevent_context *ev_ctx,
67                       struct messaging_context *msg_ctx,
68                       const char *name)
69 {
70         bool ok;
71         struct rpc_module *module = find_rpc_module(name);
72
73         if (module == NULL) {
74                 return false;
75         }
76
77         ok = module->fns->setup(ev_ctx, msg_ctx);
78         if (!ok) {
79                 DBG_ERR("calling setup for %s failed\n", name);
80         }
81
82         return true;
83 }
84
85 bool setup_rpc_modules(struct tevent_context *ev_ctx,
86                        struct messaging_context *msg_ctx)
87 {
88         bool ok;
89         struct rpc_module *module = rpc_modules;
90
91         for (module = rpc_modules; module; module = module->next) {
92                 ok = module->fns->setup(ev_ctx, msg_ctx);
93                 if (!ok) {
94                         DBG_ERR("calling setup for %s failed\n", module->name);
95                 }
96         }
97
98         return true;
99 }
100
101 bool init_rpc_module(const char *name,
102                      const struct rpc_srv_callbacks *rpc_srv_cb)
103 {
104         struct rpc_module *module = find_rpc_module(name);
105         NTSTATUS status;
106
107         if (module == NULL) {
108                 return false;
109         }
110
111         status = module->fns->init(rpc_srv_cb);
112         if (!NT_STATUS_IS_OK(status)) {
113                 DBG_ERR("calling init for %s failed %s\n",
114                         name, nt_errstr(status));
115                 return false;
116         }
117
118         return true;
119 }
120
121 bool shutdown_rpc_module(const char *name)
122 {
123         struct rpc_module *module = find_rpc_module(name);
124         NTSTATUS status;
125
126         if (module == NULL) {
127                 return false;
128         }
129
130         status = module->fns->shutdown();
131         if (!NT_STATUS_IS_OK(status)) {
132                 DBG_ERR("calling shutdown for %s failed %s\n",
133                         name, nt_errstr(status));
134                 return false;
135         }
136
137         return true;
138 }