2 * Unix SMB/CIFS implementation.
4 * SMBD RPC service callbacks
6 * Copyright (c) 2011 Andreas Schneider <asn@samba.org>
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.
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.
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/>.
25 #include "../librpc/gen_ndr/ndr_epmapper_c.h"
26 #include "../librpc/gen_ndr/srv_epmapper.h"
27 #include "../librpc/gen_ndr/srv_srvsvc.h"
28 #include "../librpc/gen_ndr/srv_winreg.h"
29 #include "../librpc/gen_ndr/srv_dfs.h"
30 #include "../librpc/gen_ndr/srv_dssetup.h"
31 #include "../librpc/gen_ndr/srv_echo.h"
32 #include "../librpc/gen_ndr/srv_eventlog.h"
33 #include "../librpc/gen_ndr/srv_initshutdown.h"
34 #include "../librpc/gen_ndr/srv_lsa.h"
35 #include "../librpc/gen_ndr/srv_netlogon.h"
36 #include "../librpc/gen_ndr/srv_ntsvcs.h"
37 #include "../librpc/gen_ndr/srv_samr.h"
38 #include "../librpc/gen_ndr/srv_spoolss.h"
39 #include "../librpc/gen_ndr/srv_svcctl.h"
40 #include "../librpc/gen_ndr/srv_wkssvc.h"
42 #include "printing/nt_printing_migrate_internal.h"
43 #include "rpc_server/eventlog/srv_eventlog_reg.h"
44 #include "rpc_server/svcctl/srv_svcctl_reg.h"
45 #include "rpc_server/spoolss/srv_spoolss_nt.h"
46 #include "rpc_server/svcctl/srv_svcctl_nt.h"
48 #include "librpc/rpc/dcerpc_ep.h"
49 #include "rpc_server/rpc_sock_helper.h"
50 #include "rpc_server/rpc_service_setup.h"
51 #include "rpc_server/rpc_ep_register.h"
52 #include "rpc_server/rpc_server.h"
53 #include "rpc_server/rpc_config.h"
54 #include "rpc_server/rpc_modules.h"
55 #include "rpc_server/epmapper/srv_epmapper.h"
59 /* Common routine for embedded RPC servers */
60 bool rpc_setup_embedded(struct tevent_context *ev_ctx,
61 struct messaging_context *msg_ctx,
62 const struct ndr_interface_table *t,
63 const char *pipe_name)
65 struct dcerpc_binding_vector *v;
66 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
69 /* Registration of ncacn_np services is problematic. The
70 * ev_ctx passed in here is passed down to all children of the
71 * smbd process, and if the end point mapper ever goes away,
72 * they will all attempt to re-register. But we want to test
73 * the code for now, so it is enabled in on environment in
75 if (epm_mode != RPC_SERVICE_MODE_DISABLED &&
76 (lp_parm_bool(-1, "rpc_server", "register_embedded_np", false))) {
77 status = dcerpc_binding_vector_new(talloc_tos(), &v);
78 if (!NT_STATUS_IS_OK(status)) {
82 status = dcerpc_binding_vector_add_np_default(t, v);
83 if (!NT_STATUS_IS_OK(status)) {
87 status = rpc_ep_register(ev_ctx,
91 if (!NT_STATUS_IS_OK(status)) {
99 static bool rpc_setup_winreg(struct tevent_context *ev_ctx,
100 struct messaging_context *msg_ctx)
102 const struct ndr_interface_table *t = &ndr_table_winreg;
103 const char *pipe_name = "winreg";
105 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
106 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
110 status = rpc_winreg_init(NULL);
111 if (!NT_STATUS_IS_OK(status)) {
115 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
118 static bool rpc_setup_srvsvc(struct tevent_context *ev_ctx,
119 struct messaging_context *msg_ctx)
121 const struct ndr_interface_table *t = &ndr_table_srvsvc;
122 const char *pipe_name = "srvsvc";
124 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
125 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
129 status = rpc_srvsvc_init(NULL);
130 if (!NT_STATUS_IS_OK(status)) {
134 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
137 static bool rpc_setup_lsarpc(struct tevent_context *ev_ctx,
138 struct messaging_context *msg_ctx)
140 const struct ndr_interface_table *t = &ndr_table_lsarpc;
141 const char *pipe_name = "lsarpc";
142 enum rpc_daemon_type_e lsasd_type = rpc_lsasd_daemon();
144 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
145 if (service_mode != RPC_SERVICE_MODE_EMBEDDED || lsasd_type != RPC_DAEMON_EMBEDDED) {
149 status = rpc_lsarpc_init(NULL);
150 if (!NT_STATUS_IS_OK(status)) {
154 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
157 static bool rpc_setup_samr(struct tevent_context *ev_ctx,
158 struct messaging_context *msg_ctx)
160 const struct ndr_interface_table *t = &ndr_table_samr;
161 const char *pipe_name = "samr";
162 enum rpc_daemon_type_e lsasd_type = rpc_lsasd_daemon();
164 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
165 if (service_mode != RPC_SERVICE_MODE_EMBEDDED || lsasd_type != RPC_DAEMON_EMBEDDED) {
169 status = rpc_samr_init(NULL);
170 if (!NT_STATUS_IS_OK(status)) {
174 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
177 static bool rpc_setup_netlogon(struct tevent_context *ev_ctx,
178 struct messaging_context *msg_ctx)
180 const struct ndr_interface_table *t = &ndr_table_netlogon;
181 const char *pipe_name = "netlogon";
182 enum rpc_daemon_type_e lsasd_type = rpc_lsasd_daemon();
184 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
185 if (service_mode != RPC_SERVICE_MODE_EMBEDDED || lsasd_type != RPC_DAEMON_EMBEDDED) {
189 status = rpc_netlogon_init(NULL);
190 if (!NT_STATUS_IS_OK(status)) {
194 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
197 static bool rpc_setup_netdfs(struct tevent_context *ev_ctx,
198 struct messaging_context *msg_ctx)
200 const struct ndr_interface_table *t = &ndr_table_netdfs;
201 const char *pipe_name = "netdfs";
203 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
204 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
208 status = rpc_netdfs_init(NULL);
209 if (!NT_STATUS_IS_OK(status)) {
213 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
217 static bool rpc_setup_rpcecho(struct tevent_context *ev_ctx,
218 struct messaging_context *msg_ctx)
220 const struct ndr_interface_table *t = &ndr_table_rpcecho;
221 const char *pipe_name = "rpcecho";
223 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
224 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
228 status = rpc_rpcecho_init(NULL);
229 if (!NT_STATUS_IS_OK(status)) {
233 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
237 static bool rpc_setup_dssetup(struct tevent_context *ev_ctx,
238 struct messaging_context *msg_ctx)
240 const struct ndr_interface_table *t = &ndr_table_dssetup;
241 const char *pipe_name = "dssetup";
243 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
244 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
248 status = rpc_dssetup_init(NULL);
249 if (!NT_STATUS_IS_OK(status)) {
253 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
256 static bool rpc_setup_wkssvc(struct tevent_context *ev_ctx,
257 struct messaging_context *msg_ctx)
259 const struct ndr_interface_table *t = &ndr_table_wkssvc;
260 const char *pipe_name = "wkssvc";
262 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
263 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
267 status = rpc_wkssvc_init(NULL);
268 if (!NT_STATUS_IS_OK(status)) {
272 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
275 static bool spoolss_init_cb(void *ptr)
277 struct messaging_context *msg_ctx =
278 talloc_get_type_abort(ptr, struct messaging_context);
282 * Migrate the printers first.
284 ok = nt_printing_tdb_migrate(msg_ctx);
292 static bool spoolss_shutdown_cb(void *ptr)
294 srv_spoolss_cleanup();
299 static bool rpc_setup_spoolss(struct tevent_context *ev_ctx,
300 struct messaging_context *msg_ctx)
302 const struct ndr_interface_table *t = &ndr_table_spoolss;
303 struct rpc_srv_callbacks spoolss_cb;
304 enum rpc_daemon_type_e spoolss_type = rpc_spoolss_daemon();
305 NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
306 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
308 if (lp__disable_spoolss()) {
312 if (service_mode != RPC_SERVICE_MODE_EMBEDDED || spoolss_type != RPC_DAEMON_EMBEDDED) {
316 spoolss_cb.init = spoolss_init_cb;
317 spoolss_cb.shutdown = spoolss_shutdown_cb;
318 spoolss_cb.private_data = msg_ctx;
320 status = rpc_spoolss_init(&spoolss_cb);
321 if (!NT_STATUS_IS_OK(status)) {
325 return rpc_setup_embedded(ev_ctx, msg_ctx, t, NULL);
328 static bool svcctl_init_cb(void *ptr)
330 struct messaging_context *msg_ctx =
331 talloc_get_type_abort(ptr, struct messaging_context);
334 /* initialize the control hooks */
335 init_service_op_table();
337 ok = svcctl_init_winreg(msg_ctx);
345 static bool svcctl_shutdown_cb(void *ptr)
347 shutdown_service_op_table();
352 static bool rpc_setup_svcctl(struct tevent_context *ev_ctx,
353 struct messaging_context *msg_ctx)
355 const struct ndr_interface_table *t = &ndr_table_svcctl;
356 const char *pipe_name = "svcctl";
357 struct rpc_srv_callbacks svcctl_cb;
359 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
360 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
364 svcctl_cb.init = svcctl_init_cb;
365 svcctl_cb.shutdown = svcctl_shutdown_cb;
366 svcctl_cb.private_data = msg_ctx;
368 status = rpc_svcctl_init(&svcctl_cb);
369 if (!NT_STATUS_IS_OK(status)) {
373 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
376 static bool rpc_setup_ntsvcs(struct tevent_context *ev_ctx,
377 struct messaging_context *msg_ctx)
379 const struct ndr_interface_table *t = &ndr_table_ntsvcs;
381 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
382 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
386 status = rpc_ntsvcs_init(NULL);
387 if (!NT_STATUS_IS_OK(status)) {
391 return rpc_setup_embedded(ev_ctx, msg_ctx, t, NULL);
394 static bool eventlog_init_cb(void *ptr)
396 struct messaging_context *msg_ctx =
397 talloc_get_type_abort(ptr, struct messaging_context);
400 ok = eventlog_init_winreg(msg_ctx);
408 static bool rpc_setup_eventlog(struct tevent_context *ev_ctx,
409 struct messaging_context *msg_ctx)
411 const struct ndr_interface_table *t = &ndr_table_eventlog;
412 struct rpc_srv_callbacks eventlog_cb;
414 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
415 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
419 eventlog_cb.init = eventlog_init_cb;
420 eventlog_cb.shutdown = NULL;
421 eventlog_cb.private_data = msg_ctx;
423 status = rpc_eventlog_init(&eventlog_cb);
424 if (!NT_STATUS_IS_OK(status)) {
428 return rpc_setup_embedded(ev_ctx, msg_ctx, t, NULL);
431 static bool rpc_setup_initshutdown(struct tevent_context *ev_ctx,
432 struct messaging_context *msg_ctx)
434 const struct ndr_interface_table *t = &ndr_table_initshutdown;
436 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
437 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
441 status = rpc_initshutdown_init(NULL);
442 if (!NT_STATUS_IS_OK(status)) {
446 return rpc_setup_embedded(ev_ctx, msg_ctx, t, NULL);
449 bool dcesrv_ep_setup(struct tevent_context *ev_ctx,
450 struct messaging_context *msg_ctx)
454 init_module_fn *mod_init_fns = NULL;
456 tmp_ctx = talloc_stackframe();
457 if (tmp_ctx == NULL) {
461 ok = rpc_setup_winreg(ev_ctx, msg_ctx);
466 ok = rpc_setup_srvsvc(ev_ctx, msg_ctx);
471 ok = rpc_setup_lsarpc(ev_ctx, msg_ctx);
476 ok = rpc_setup_samr(ev_ctx, msg_ctx);
481 ok = rpc_setup_netlogon(ev_ctx, msg_ctx);
486 ok = rpc_setup_netdfs(ev_ctx, msg_ctx);
492 ok = rpc_setup_rpcecho(ev_ctx, msg_ctx);
498 ok = rpc_setup_dssetup(ev_ctx, msg_ctx);
503 ok = rpc_setup_wkssvc(ev_ctx, msg_ctx);
508 ok = rpc_setup_spoolss(ev_ctx, msg_ctx);
513 ok = rpc_setup_svcctl(ev_ctx, msg_ctx);
518 ok = rpc_setup_ntsvcs(ev_ctx, msg_ctx);
523 ok = rpc_setup_eventlog(ev_ctx, msg_ctx);
528 ok = rpc_setup_initshutdown(ev_ctx, msg_ctx);
533 /* Initialize static subsystems */
536 /* Initialize shared modules */
537 mod_init_fns = load_samba_modules(tmp_ctx, "rpc");
538 if ((mod_init_fns == NULL) && (errno != ENOENT)) {
540 * ENOENT means the directory doesn't exist which can happen if
541 * all modules are static. So ENOENT is ok, everything else is
544 DBG_ERR("Loading shared RPC modules failed [%s]\n",
550 ok = run_init_functions(mod_init_fns);
552 DBG_ERR("Initializing shared RPC modules failed\n");
556 ok = setup_rpc_modules(ev_ctx, msg_ctx);
558 DBG_ERR("Shared RPC modules setup failed\n");
563 talloc_free(tmp_ctx);
567 /* vim: set ts=8 sw=8 noet cindent ft=c.doxygen: */