s4-torture: add test for clusapi_QueryValue.
[Samba.git] / source3 / rpc_server / rpc_service_setup.c
blobee995a805d161e9e1c73283f00ca49746b15564a
1 /*
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/>.
22 #include "includes.h"
23 #include "ntdomain.h"
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"
41 #include "../librpc/gen_ndr/srv_mdssvc.h"
43 #include "printing/nt_printing_migrate_internal.h"
44 #include "rpc_server/eventlog/srv_eventlog_reg.h"
45 #include "rpc_server/svcctl/srv_svcctl_reg.h"
46 #include "rpc_server/spoolss/srv_spoolss_nt.h"
47 #include "rpc_server/svcctl/srv_svcctl_nt.h"
48 #include "rpc_server/mdssvc/srv_mdssvc_nt.h"
50 #include "librpc/rpc/dcerpc_ep.h"
51 #include "rpc_server/rpc_sock_helper.h"
52 #include "rpc_server/rpc_service_setup.h"
53 #include "rpc_server/rpc_ep_register.h"
54 #include "rpc_server/rpc_server.h"
55 #include "rpc_server/rpc_config.h"
56 #include "rpc_server/epmapper/srv_epmapper.h"
58 /* Common routine for embedded RPC servers */
59 static bool rpc_setup_embedded(struct tevent_context *ev_ctx,
60 struct messaging_context *msg_ctx,
61 const struct ndr_interface_table *t,
62 const char *pipe_name)
64 struct dcerpc_binding_vector *v;
65 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
66 NTSTATUS status;
68 /* Registration of ncacn_np services is problematic. The
69 * ev_ctx passed in here is passed down to all children of the
70 * smbd process, and if the end point mapper ever goes away,
71 * they will all attempt to re-register. But we want to test
72 * the code for now, so it is enabled in on environment in
73 * make test */
74 if (epm_mode != RPC_SERVICE_MODE_DISABLED &&
75 (lp_parm_bool(-1, "rpc_server", "register_embedded_np", false))) {
76 status = dcerpc_binding_vector_new(talloc_tos(), &v);
77 if (!NT_STATUS_IS_OK(status)) {
78 return false;
81 status = dcerpc_binding_vector_add_np_default(t, v);
82 if (!NT_STATUS_IS_OK(status)) {
83 return false;
86 status = rpc_ep_register(ev_ctx,
87 msg_ctx,
89 v);
90 if (!NT_STATUS_IS_OK(status)) {
91 return false;
95 return true;
98 static bool rpc_setup_winreg(struct tevent_context *ev_ctx,
99 struct messaging_context *msg_ctx)
101 const struct ndr_interface_table *t = &ndr_table_winreg;
102 const char *pipe_name = "winreg";
103 NTSTATUS status;
104 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
105 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
106 return true;
109 status = rpc_winreg_init(NULL);
110 if (!NT_STATUS_IS_OK(status)) {
111 return false;
114 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
117 static bool rpc_setup_srvsvc(struct tevent_context *ev_ctx,
118 struct messaging_context *msg_ctx)
120 const struct ndr_interface_table *t = &ndr_table_srvsvc;
121 const char *pipe_name = "srvsvc";
122 NTSTATUS status;
123 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
124 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
125 return true;
128 status = rpc_srvsvc_init(NULL);
129 if (!NT_STATUS_IS_OK(status)) {
130 return false;
133 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
136 static bool rpc_setup_lsarpc(struct tevent_context *ev_ctx,
137 struct messaging_context *msg_ctx)
139 const struct ndr_interface_table *t = &ndr_table_lsarpc;
140 const char *pipe_name = "lsarpc";
141 enum rpc_daemon_type_e lsasd_type = rpc_lsasd_daemon();
142 NTSTATUS status;
143 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
144 if (service_mode != RPC_SERVICE_MODE_EMBEDDED || lsasd_type != RPC_DAEMON_EMBEDDED) {
145 return true;
148 status = rpc_lsarpc_init(NULL);
149 if (!NT_STATUS_IS_OK(status)) {
150 return false;
153 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
156 static bool rpc_setup_samr(struct tevent_context *ev_ctx,
157 struct messaging_context *msg_ctx)
159 const struct ndr_interface_table *t = &ndr_table_samr;
160 const char *pipe_name = "samr";
161 enum rpc_daemon_type_e lsasd_type = rpc_lsasd_daemon();
162 NTSTATUS status;
163 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
164 if (service_mode != RPC_SERVICE_MODE_EMBEDDED || lsasd_type != RPC_DAEMON_EMBEDDED) {
165 return true;
168 status = rpc_samr_init(NULL);
169 if (!NT_STATUS_IS_OK(status)) {
170 return false;
173 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
176 static bool rpc_setup_netlogon(struct tevent_context *ev_ctx,
177 struct messaging_context *msg_ctx)
179 const struct ndr_interface_table *t = &ndr_table_netlogon;
180 const char *pipe_name = "netlogon";
181 enum rpc_daemon_type_e lsasd_type = rpc_lsasd_daemon();
182 NTSTATUS status;
183 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
184 if (service_mode != RPC_SERVICE_MODE_EMBEDDED || lsasd_type != RPC_DAEMON_EMBEDDED) {
185 return true;
188 status = rpc_netlogon_init(NULL);
189 if (!NT_STATUS_IS_OK(status)) {
190 return false;
193 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
196 static bool rpc_setup_netdfs(struct tevent_context *ev_ctx,
197 struct messaging_context *msg_ctx)
199 const struct ndr_interface_table *t = &ndr_table_netdfs;
200 const char *pipe_name = "netdfs";
201 NTSTATUS status;
202 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
203 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
204 return true;
207 status = rpc_netdfs_init(NULL);
208 if (!NT_STATUS_IS_OK(status)) {
209 return false;
212 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
215 #ifdef DEVELOPER
216 static bool rpc_setup_rpcecho(struct tevent_context *ev_ctx,
217 struct messaging_context *msg_ctx)
219 const struct ndr_interface_table *t = &ndr_table_rpcecho;
220 const char *pipe_name = "rpcecho";
221 NTSTATUS status;
222 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
223 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
224 return true;
227 status = rpc_rpcecho_init(NULL);
228 if (!NT_STATUS_IS_OK(status)) {
229 return false;
232 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
234 #endif
236 static bool rpc_setup_dssetup(struct tevent_context *ev_ctx,
237 struct messaging_context *msg_ctx)
239 const struct ndr_interface_table *t = &ndr_table_dssetup;
240 const char *pipe_name = "dssetup";
241 NTSTATUS status;
242 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
243 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
244 return true;
247 status = rpc_dssetup_init(NULL);
248 if (!NT_STATUS_IS_OK(status)) {
249 return false;
252 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
255 static bool rpc_setup_wkssvc(struct tevent_context *ev_ctx,
256 struct messaging_context *msg_ctx)
258 const struct ndr_interface_table *t = &ndr_table_wkssvc;
259 const char *pipe_name = "wkssvc";
260 NTSTATUS status;
261 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
262 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
263 return true;
266 status = rpc_wkssvc_init(NULL);
267 if (!NT_STATUS_IS_OK(status)) {
268 return false;
271 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
274 static bool spoolss_init_cb(void *ptr)
276 struct messaging_context *msg_ctx =
277 talloc_get_type_abort(ptr, struct messaging_context);
278 bool ok;
281 * Migrate the printers first.
283 ok = nt_printing_tdb_migrate(msg_ctx);
284 if (!ok) {
285 return false;
288 return true;
291 static bool spoolss_shutdown_cb(void *ptr)
293 srv_spoolss_cleanup();
295 return true;
298 static bool rpc_setup_spoolss(struct tevent_context *ev_ctx,
299 struct messaging_context *msg_ctx)
301 const struct ndr_interface_table *t = &ndr_table_spoolss;
302 struct rpc_srv_callbacks spoolss_cb;
303 enum rpc_daemon_type_e spoolss_type = rpc_spoolss_daemon();
304 NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
305 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
307 if (lp__disable_spoolss()) {
308 return true;
311 if (service_mode != RPC_SERVICE_MODE_EMBEDDED || spoolss_type != RPC_DAEMON_EMBEDDED) {
312 return true;
315 spoolss_cb.init = spoolss_init_cb;
316 spoolss_cb.shutdown = spoolss_shutdown_cb;
317 spoolss_cb.private_data = msg_ctx;
319 status = rpc_spoolss_init(&spoolss_cb);
320 if (!NT_STATUS_IS_OK(status)) {
321 return false;
324 return rpc_setup_embedded(ev_ctx, msg_ctx, t, NULL);
327 static bool svcctl_init_cb(void *ptr)
329 struct messaging_context *msg_ctx =
330 talloc_get_type_abort(ptr, struct messaging_context);
331 bool ok;
333 /* initialize the control hooks */
334 init_service_op_table();
336 ok = svcctl_init_winreg(msg_ctx);
337 if (!ok) {
338 return false;
341 return true;
344 static bool svcctl_shutdown_cb(void *ptr)
346 shutdown_service_op_table();
348 return true;
351 static bool rpc_setup_svcctl(struct tevent_context *ev_ctx,
352 struct messaging_context *msg_ctx)
354 const struct ndr_interface_table *t = &ndr_table_svcctl;
355 const char *pipe_name = "svcctl";
356 struct rpc_srv_callbacks svcctl_cb;
357 NTSTATUS status;
358 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
359 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
360 return true;
363 svcctl_cb.init = svcctl_init_cb;
364 svcctl_cb.shutdown = svcctl_shutdown_cb;
365 svcctl_cb.private_data = msg_ctx;
367 status = rpc_svcctl_init(&svcctl_cb);
368 if (!NT_STATUS_IS_OK(status)) {
369 return false;
372 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
375 static bool rpc_setup_ntsvcs(struct tevent_context *ev_ctx,
376 struct messaging_context *msg_ctx)
378 const struct ndr_interface_table *t = &ndr_table_ntsvcs;
379 NTSTATUS status;
380 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
381 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
382 return true;
385 status = rpc_ntsvcs_init(NULL);
386 if (!NT_STATUS_IS_OK(status)) {
387 return false;
390 return rpc_setup_embedded(ev_ctx, msg_ctx, t, NULL);
393 static bool eventlog_init_cb(void *ptr)
395 struct messaging_context *msg_ctx =
396 talloc_get_type_abort(ptr, struct messaging_context);
397 bool ok;
399 ok = eventlog_init_winreg(msg_ctx);
400 if (!ok) {
401 return false;
404 return true;
407 static bool rpc_setup_eventlog(struct tevent_context *ev_ctx,
408 struct messaging_context *msg_ctx)
410 const struct ndr_interface_table *t = &ndr_table_eventlog;
411 struct rpc_srv_callbacks eventlog_cb;
412 NTSTATUS status;
413 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
414 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
415 return true;
418 eventlog_cb.init = eventlog_init_cb;
419 eventlog_cb.shutdown = NULL;
420 eventlog_cb.private_data = msg_ctx;
422 status = rpc_eventlog_init(&eventlog_cb);
423 if (!NT_STATUS_IS_OK(status)) {
424 return false;
427 return rpc_setup_embedded(ev_ctx, msg_ctx, t, NULL);
430 static bool rpc_setup_initshutdown(struct tevent_context *ev_ctx,
431 struct messaging_context *msg_ctx)
433 const struct ndr_interface_table *t = &ndr_table_initshutdown;
434 NTSTATUS status;
435 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
436 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
437 return true;
440 status = rpc_initshutdown_init(NULL);
441 if (!NT_STATUS_IS_OK(status)) {
442 return false;
445 return rpc_setup_embedded(ev_ctx, msg_ctx, t, NULL);
448 #ifdef WITH_SPOTLIGHT
449 static bool mdssvc_init_cb(void *ptr)
451 struct messaging_context *msg_ctx =
452 talloc_get_type_abort(ptr, struct messaging_context);
453 bool ok;
455 ok = init_service_mdssvc(msg_ctx);
456 if (!ok) {
457 return false;
460 return true;
463 static bool mdssvc_shutdown_cb(void *ptr)
465 shutdown_service_mdssvc();
467 return true;
470 static bool rpc_setup_mdssvc(struct tevent_context *ev_ctx,
471 struct messaging_context *msg_ctx)
473 const struct ndr_interface_table *t = &ndr_table_mdssvc;
474 const char *pipe_name = "mdssvc";
475 struct rpc_srv_callbacks mdssvc_cb;
476 NTSTATUS status;
477 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
478 enum rpc_daemon_type_e mdssvc_type = rpc_mdssd_daemon();
480 if (service_mode != RPC_SERVICE_MODE_EMBEDDED
481 || mdssvc_type != RPC_DAEMON_EMBEDDED) {
482 return true;
485 mdssvc_cb.init = mdssvc_init_cb;
486 mdssvc_cb.shutdown = mdssvc_shutdown_cb;
487 mdssvc_cb.private_data = msg_ctx;
489 status = rpc_mdssvc_init(&mdssvc_cb);
490 if (!NT_STATUS_IS_OK(status)) {
491 return false;
494 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
496 #endif
498 bool dcesrv_ep_setup(struct tevent_context *ev_ctx,
499 struct messaging_context *msg_ctx)
501 TALLOC_CTX *tmp_ctx;
502 bool ok;
504 tmp_ctx = talloc_stackframe();
505 if (tmp_ctx == NULL) {
506 return false;
509 ok = rpc_setup_winreg(ev_ctx, msg_ctx);
510 if (!ok) {
511 goto done;
514 ok = rpc_setup_srvsvc(ev_ctx, msg_ctx);
515 if (!ok) {
516 goto done;
519 ok = rpc_setup_lsarpc(ev_ctx, msg_ctx);
520 if (!ok) {
521 goto done;
524 ok = rpc_setup_samr(ev_ctx, msg_ctx);
525 if (!ok) {
526 goto done;
529 ok = rpc_setup_netlogon(ev_ctx, msg_ctx);
530 if (!ok) {
531 goto done;
534 ok = rpc_setup_netdfs(ev_ctx, msg_ctx);
535 if (!ok) {
536 goto done;
539 #ifdef DEVELOPER
540 ok = rpc_setup_rpcecho(ev_ctx, msg_ctx);
541 if (!ok) {
542 goto done;
544 #endif
546 ok = rpc_setup_dssetup(ev_ctx, msg_ctx);
547 if (!ok) {
548 goto done;
551 ok = rpc_setup_wkssvc(ev_ctx, msg_ctx);
552 if (!ok) {
553 goto done;
556 ok = rpc_setup_spoolss(ev_ctx, msg_ctx);
557 if (!ok) {
558 goto done;
561 ok = rpc_setup_svcctl(ev_ctx, msg_ctx);
562 if (!ok) {
563 goto done;
566 ok = rpc_setup_ntsvcs(ev_ctx, msg_ctx);
567 if (!ok) {
568 goto done;
571 ok = rpc_setup_eventlog(ev_ctx, msg_ctx);
572 if (!ok) {
573 goto done;
576 ok = rpc_setup_initshutdown(ev_ctx, msg_ctx);
577 if (!ok) {
578 goto done;
581 #ifdef WITH_SPOTLIGHT
582 ok = rpc_setup_mdssvc(ev_ctx, msg_ctx);
583 if (!ok) {
584 goto done;
586 #endif
588 done:
589 talloc_free(tmp_ctx);
590 return ok;
593 /* vim: set ts=8 sw=8 noet cindent ft=c.doxygen: */