s3-rpc_server: Use rpc_spoolss_mode().
[Samba/gebeck_regimport.git] / source3 / rpc_server / rpc_service_setup.c
blob86a5a7a378fd6946f7019911a2f8765de69e09c1
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"
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/epmapper/srv_epmapper.h"
55 enum rpc_service_mode_e rpc_epmapper_mode(void)
57 const char *rpcsrv_type;
58 enum rpc_service_mode_e state;
60 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
61 "rpc_server",
62 "epmapper",
63 "daemon");
65 if (strcasecmp_m(rpcsrv_type, "external") == 0) {
66 state = RPC_SERVICE_MODE_EXTERNAL;
67 } else if (strcasecmp_m(rpcsrv_type, "daemon") == 0) {
68 state = RPC_SERVICE_MODE_DAEMON;
69 } else {
70 state = RPC_SERVICE_MODE_DISABLED;
73 return state;
76 enum rpc_service_mode_e rpc_spoolss_mode(void)
78 const char *rpcsrv_type;
79 enum rpc_service_mode_e state;
81 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
82 "rpc_server",
83 "spoolss",
84 "embedded");
86 if (strcasecmp_m(rpcsrv_type, "embedded") == 0) {
87 state = RPC_SERVICE_MODE_EMBEDDED;
88 } else if (strcasecmp_m(rpcsrv_type, "external") == 0) {
89 state = RPC_SERVICE_MODE_EXTERNAL;
90 } else if (strcasecmp_m(rpcsrv_type, "daemon") == 0) {
91 state = RPC_SERVICE_MODE_DAEMON;
92 } else {
93 state = RPC_SERVICE_MODE_DISABLED;
96 return state;
99 static bool rpc_setup_epmapper(struct tevent_context *ev_ctx,
100 struct messaging_context *msg_ctx)
102 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
103 NTSTATUS status;
105 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
106 status = rpc_epmapper_init(NULL);
107 if (!NT_STATUS_IS_OK(status)) {
108 return false;
112 return true;
115 static bool rpc_setup_winreg(struct tevent_context *ev_ctx,
116 struct messaging_context *msg_ctx,
117 const struct dcerpc_binding_vector *v)
119 const struct ndr_interface_table *t = &ndr_table_winreg;
120 const char *pipe_name = "winreg";
121 struct dcerpc_binding_vector *v2;
122 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
123 NTSTATUS status;
124 bool ok;
126 status = rpc_winreg_init(NULL);
127 if (!NT_STATUS_IS_OK(status)) {
128 return false;
131 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
132 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
133 if (v2 == NULL) {
134 return false;
137 status = dcerpc_binding_vector_replace_iface(t, v2);
138 if (!NT_STATUS_IS_OK(status)) {
139 return false;
142 status = dcerpc_binding_vector_add_np_default(t, v2);
143 if (!NT_STATUS_IS_OK(status)) {
144 return false;
147 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
148 msg_ctx,
149 pipe_name,
150 NULL);
151 if (!ok) {
152 return false;
155 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
156 if (!NT_STATUS_IS_OK(status)) {
157 return false;
160 status = rpc_ep_register(ev_ctx,
161 msg_ctx,
163 v2);
164 if (!NT_STATUS_IS_OK(status)) {
165 return false;
169 return true;
172 static bool rpc_setup_srvsvc(struct tevent_context *ev_ctx,
173 struct messaging_context *msg_ctx,
174 const struct dcerpc_binding_vector *v)
176 const struct ndr_interface_table *t = &ndr_table_srvsvc;
177 const char *pipe_name = "srvsvc";
178 struct dcerpc_binding_vector *v2;
179 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
180 NTSTATUS status;
181 bool ok;
183 status = rpc_srvsvc_init(NULL);
184 if (!NT_STATUS_IS_OK(status)) {
185 return false;
188 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
189 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
190 if (v2 == NULL) {
191 return false;
194 status = dcerpc_binding_vector_replace_iface(t, v2);
195 if (!NT_STATUS_IS_OK(status)) {
196 return false;
199 status = dcerpc_binding_vector_add_np_default(t, v2);
200 if (!NT_STATUS_IS_OK(status)) {
201 return false;
204 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
205 msg_ctx,
206 pipe_name,
207 NULL);
208 if (!ok) {
209 return false;
212 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
213 if (!NT_STATUS_IS_OK(status)) {
214 return false;
217 status = rpc_ep_register(ev_ctx,
218 msg_ctx,
220 v2);
221 if (!NT_STATUS_IS_OK(status)) {
222 return false;
226 return true;
229 static bool rpc_setup_lsarpc(struct tevent_context *ev_ctx,
230 struct messaging_context *msg_ctx,
231 const struct dcerpc_binding_vector *v)
233 const struct ndr_interface_table *t = &ndr_table_lsarpc;
234 const char *pipe_name = "lsarpc";
235 struct dcerpc_binding_vector *v2;
236 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
237 NTSTATUS status;
238 bool ok;
240 status = rpc_lsarpc_init(NULL);
241 if (!NT_STATUS_IS_OK(status)) {
242 return false;
245 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
246 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
247 if (v2 == NULL) {
248 return false;
251 status = dcerpc_binding_vector_replace_iface(t, v2);
252 if (!NT_STATUS_IS_OK(status)) {
253 return false;
256 status = dcerpc_binding_vector_add_np_default(t, v2);
257 if (!NT_STATUS_IS_OK(status)) {
258 return false;
261 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
262 msg_ctx,
263 pipe_name,
264 NULL);
265 if (!ok) {
266 return false;
269 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
270 if (!NT_STATUS_IS_OK(status)) {
271 return false;
274 status = rpc_ep_register(ev_ctx,
275 msg_ctx,
277 v2);
278 if (!NT_STATUS_IS_OK(status)) {
279 return false;
283 return true;
286 static bool rpc_setup_samr(struct tevent_context *ev_ctx,
287 struct messaging_context *msg_ctx,
288 const struct dcerpc_binding_vector *v)
290 const struct ndr_interface_table *t = &ndr_table_samr;
291 const char *pipe_name = "samr";
292 struct dcerpc_binding_vector *v2;
293 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
294 NTSTATUS status;
295 bool ok;
297 status = rpc_samr_init(NULL);
298 if (!NT_STATUS_IS_OK(status)) {
299 return false;
302 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
303 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
304 if (v2 == NULL) {
305 return false;
308 status = dcerpc_binding_vector_replace_iface(t, v2);
309 if (!NT_STATUS_IS_OK(status)) {
310 return false;
313 status = dcerpc_binding_vector_add_np_default(t, v2);
314 if (!NT_STATUS_IS_OK(status)) {
315 return false;
318 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
319 msg_ctx,
320 pipe_name,
321 NULL);
322 if (!ok) {
323 return false;
326 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
327 if (!NT_STATUS_IS_OK(status)) {
328 return false;
331 status = rpc_ep_register(ev_ctx,
332 msg_ctx,
334 v2);
335 if (!NT_STATUS_IS_OK(status)) {
336 return false;
340 return true;
343 static bool rpc_setup_netlogon(struct tevent_context *ev_ctx,
344 struct messaging_context *msg_ctx,
345 const struct dcerpc_binding_vector *v)
347 const struct ndr_interface_table *t = &ndr_table_netlogon;
348 const char *pipe_name = "netlogon";
349 struct dcerpc_binding_vector *v2;
350 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
351 NTSTATUS status;
352 bool ok;
354 status = rpc_netlogon_init(NULL);
355 if (!NT_STATUS_IS_OK(status)) {
356 return false;
359 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
360 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
361 if (v2 == NULL) {
362 return false;
365 status = dcerpc_binding_vector_replace_iface(t, v2);
366 if (!NT_STATUS_IS_OK(status)) {
367 return false;
370 status = dcerpc_binding_vector_add_np_default(t, v2);
371 if (!NT_STATUS_IS_OK(status)) {
372 return false;
375 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
376 msg_ctx,
377 pipe_name,
378 NULL);
379 if (!ok) {
380 return false;
383 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
384 if (!NT_STATUS_IS_OK(status)) {
385 return false;
388 status = rpc_ep_register(ev_ctx,
389 msg_ctx,
391 v2);
392 if (!NT_STATUS_IS_OK(status)) {
393 return false;
397 return true;
400 static bool rpc_setup_netdfs(struct tevent_context *ev_ctx,
401 struct messaging_context *msg_ctx,
402 const struct dcerpc_binding_vector *v)
404 const struct ndr_interface_table *t = &ndr_table_netdfs;
405 const char *pipe_name = "netdfs";
406 struct dcerpc_binding_vector *v2;
407 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
408 NTSTATUS status;
409 bool ok;
411 status = rpc_netdfs_init(NULL);
412 if (!NT_STATUS_IS_OK(status)) {
413 return false;
416 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
417 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
418 if (v2 == NULL) {
419 return false;
422 status = dcerpc_binding_vector_replace_iface(t, v2);
423 if (!NT_STATUS_IS_OK(status)) {
424 return false;
427 status = dcerpc_binding_vector_add_np_default(t, v2);
428 if (!NT_STATUS_IS_OK(status)) {
429 return false;
432 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
433 msg_ctx,
434 pipe_name,
435 NULL);
436 if (!ok) {
437 return false;
440 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
441 if (!NT_STATUS_IS_OK(status)) {
442 return false;
445 status = rpc_ep_register(ev_ctx,
446 msg_ctx,
448 v2);
449 if (!NT_STATUS_IS_OK(status)) {
450 return false;
454 return true;
457 #ifdef DEVELOPER
458 static bool rpc_setup_rpcecho(struct tevent_context *ev_ctx,
459 struct messaging_context *msg_ctx,
460 const struct dcerpc_binding_vector *v)
462 const struct ndr_interface_table *t = &ndr_table_rpcecho;
463 const char *pipe_name = "rpcecho";
464 struct dcerpc_binding_vector *v2;
465 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
466 NTSTATUS status;
467 bool ok;
469 status = rpc_rpcecho_init(NULL);
470 if (!NT_STATUS_IS_OK(status)) {
471 return false;
474 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
475 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
476 if (v2 == NULL) {
477 return false;
480 status = dcerpc_binding_vector_replace_iface(t, v2);
481 if (!NT_STATUS_IS_OK(status)) {
482 return false;
485 status = dcerpc_binding_vector_add_np_default(t, v2);
486 if (!NT_STATUS_IS_OK(status)) {
487 return false;
490 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
491 msg_ctx,
492 pipe_name,
493 NULL);
494 if (!ok) {
495 return false;
498 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
499 if (!NT_STATUS_IS_OK(status)) {
500 return false;
503 status = rpc_ep_register(ev_ctx,
504 msg_ctx,
506 v2);
507 if (!NT_STATUS_IS_OK(status)) {
508 return false;
512 return true;
514 #endif
516 static bool rpc_setup_dssetup(struct tevent_context *ev_ctx,
517 struct messaging_context *msg_ctx,
518 const struct dcerpc_binding_vector *v)
520 const struct ndr_interface_table *t = &ndr_table_dssetup;
521 const char *pipe_name = "dssetup";
522 struct dcerpc_binding_vector *v2;
523 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
524 NTSTATUS status;
525 bool ok;
527 status = rpc_dssetup_init(NULL);
528 if (!NT_STATUS_IS_OK(status)) {
529 return false;
532 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
533 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
534 if (v2 == NULL) {
535 return false;
538 status = dcerpc_binding_vector_replace_iface(t, v2);
539 if (!NT_STATUS_IS_OK(status)) {
540 return false;
543 status = dcerpc_binding_vector_add_np_default(t, v2);
544 if (!NT_STATUS_IS_OK(status)) {
545 return false;
548 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
549 msg_ctx,
550 pipe_name,
551 NULL);
552 if (!ok) {
553 return false;
556 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
557 if (!NT_STATUS_IS_OK(status)) {
558 return false;
561 status = rpc_ep_register(ev_ctx,
562 msg_ctx,
564 v2);
565 if (!NT_STATUS_IS_OK(status)) {
566 return false;
570 return true;
573 static bool rpc_setup_wkssvc(struct tevent_context *ev_ctx,
574 struct messaging_context *msg_ctx,
575 const struct dcerpc_binding_vector *v)
577 const struct ndr_interface_table *t = &ndr_table_wkssvc;
578 const char *pipe_name = "wkssvc";
579 struct dcerpc_binding_vector *v2;
580 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
581 NTSTATUS status;
582 bool ok;
584 status = rpc_wkssvc_init(NULL);
585 if (!NT_STATUS_IS_OK(status)) {
586 return false;
589 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
590 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
591 if (v2 == NULL) {
592 return false;
595 status = dcerpc_binding_vector_replace_iface(t, v2);
596 if (!NT_STATUS_IS_OK(status)) {
597 return false;
600 status = dcerpc_binding_vector_add_np_default(t, v2);
601 if (!NT_STATUS_IS_OK(status)) {
602 return false;
605 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
606 msg_ctx,
607 pipe_name,
608 NULL);
609 if (!ok) {
610 return false;
613 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
614 if (!NT_STATUS_IS_OK(status)) {
615 return false;
618 status = rpc_ep_register(ev_ctx,
619 msg_ctx,
621 v2);
622 if (!NT_STATUS_IS_OK(status)) {
623 return false;
627 return true;
630 static bool spoolss_init_cb(void *ptr)
632 struct messaging_context *msg_ctx =
633 talloc_get_type_abort(ptr, struct messaging_context);
634 bool ok;
637 * Migrate the printers first.
639 ok = nt_printing_tdb_migrate(msg_ctx);
640 if (!ok) {
641 return false;
644 return true;
647 static bool spoolss_shutdown_cb(void *ptr)
649 srv_spoolss_cleanup();
651 return true;
654 static bool rpc_setup_spoolss(struct tevent_context *ev_ctx,
655 struct messaging_context *msg_ctx)
657 const struct ndr_interface_table *t = &ndr_table_spoolss;
658 struct rpc_srv_callbacks spoolss_cb;
659 struct dcerpc_binding_vector *v;
660 enum rpc_service_mode_e spoolss_mode = rpc_spoolss_mode();
661 NTSTATUS status;
663 if (_lp_disable_spoolss() ||
664 spoolss_mode == RPC_SERVICE_MODE_DISABLED) {
665 return true;
668 if (spoolss_mode == RPC_SERVICE_MODE_EMBEDDED) {
669 spoolss_cb.init = spoolss_init_cb;
670 spoolss_cb.shutdown = spoolss_shutdown_cb;
671 spoolss_cb.private_data = msg_ctx;
673 status = rpc_spoolss_init(&spoolss_cb);
674 } else if (spoolss_mode == RPC_SERVICE_MODE_EXTERNAL ||
675 spoolss_mode == RPC_SERVICE_MODE_DAEMON) {
676 status = rpc_spoolss_init(NULL);
678 if (!NT_STATUS_IS_OK(status)) {
679 return false;
682 if (spoolss_mode == RPC_SERVICE_MODE_EMBEDDED) {
683 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
685 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
686 status = dcerpc_binding_vector_new(talloc_tos(), &v);
687 if (!NT_STATUS_IS_OK(status)) {
688 return false;
691 status = dcerpc_binding_vector_add_np_default(t, v);
692 if (!NT_STATUS_IS_OK(status)) {
693 return false;
696 status = rpc_ep_register(ev_ctx,
697 msg_ctx,
700 if (!NT_STATUS_IS_OK(status)) {
701 return false;
706 return true;
709 static bool svcctl_init_cb(void *ptr)
711 struct messaging_context *msg_ctx =
712 talloc_get_type_abort(ptr, struct messaging_context);
713 bool ok;
715 /* initialize the control hooks */
716 init_service_op_table();
718 ok = svcctl_init_winreg(msg_ctx);
719 if (!ok) {
720 return false;
723 return true;
726 static bool svcctl_shutdown_cb(void *ptr)
728 shutdown_service_op_table();
730 return true;
733 static bool rpc_setup_svcctl(struct tevent_context *ev_ctx,
734 struct messaging_context *msg_ctx)
736 const struct ndr_interface_table *t = &ndr_table_svcctl;
737 const char *pipe_name = "svcctl";
738 struct dcerpc_binding_vector *v;
739 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
740 struct rpc_srv_callbacks svcctl_cb;
741 NTSTATUS status;
742 bool ok;
744 svcctl_cb.init = svcctl_init_cb;
745 svcctl_cb.shutdown = svcctl_shutdown_cb;
746 svcctl_cb.private_data = msg_ctx;
748 status = rpc_svcctl_init(&svcctl_cb);
749 if (!NT_STATUS_IS_OK(status)) {
750 return false;
753 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
754 status = dcerpc_binding_vector_new(talloc_tos(), &v);
755 if (!NT_STATUS_IS_OK(status)) {
756 return false;
759 status = dcerpc_binding_vector_add_np_default(t, v);
760 if (!NT_STATUS_IS_OK(status)) {
761 return false;
764 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
765 msg_ctx,
766 pipe_name,
767 NULL);
768 if (!ok) {
769 return false;
772 status = dcerpc_binding_vector_add_unix(t, v, pipe_name);
773 if (!NT_STATUS_IS_OK(status)) {
774 return false;
777 status = rpc_ep_register(ev_ctx,
778 msg_ctx,
781 if (!NT_STATUS_IS_OK(status)) {
782 return false;
786 return true;
789 static bool rpc_setup_ntsvcs(struct tevent_context *ev_ctx,
790 struct messaging_context *msg_ctx)
792 const struct ndr_interface_table *t = &ndr_table_ntsvcs;
793 struct dcerpc_binding_vector *v;
794 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
795 NTSTATUS status;
797 status = rpc_ntsvcs_init(NULL);
798 if (!NT_STATUS_IS_OK(status)) {
799 return false;
802 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
803 status = dcerpc_binding_vector_new(talloc_tos(), &v);
804 if (!NT_STATUS_IS_OK(status)) {
805 return false;
808 status = dcerpc_binding_vector_add_np_default(t, v);
809 if (!NT_STATUS_IS_OK(status)) {
810 return false;
813 status = rpc_ep_register(ev_ctx,
814 msg_ctx,
817 if (!NT_STATUS_IS_OK(status)) {
818 return false;
822 return true;
825 static bool eventlog_init_cb(void *ptr)
827 struct messaging_context *msg_ctx =
828 talloc_get_type_abort(ptr, struct messaging_context);
829 bool ok;
831 ok = eventlog_init_winreg(msg_ctx);
832 if (!ok) {
833 return false;
836 return true;
839 static bool rpc_setup_eventlog(struct tevent_context *ev_ctx,
840 struct messaging_context *msg_ctx)
842 const struct ndr_interface_table *t = &ndr_table_eventlog;
843 struct rpc_srv_callbacks eventlog_cb;
844 struct dcerpc_binding_vector *v;
845 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
846 NTSTATUS status;
848 eventlog_cb.init = eventlog_init_cb;
849 eventlog_cb.shutdown = NULL;
850 eventlog_cb.private_data = msg_ctx;
852 status = rpc_eventlog_init(&eventlog_cb);
853 if (!NT_STATUS_IS_OK(status)) {
854 return false;
857 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
858 status = dcerpc_binding_vector_new(talloc_tos(), &v);
859 if (!NT_STATUS_IS_OK(status)) {
860 return false;
863 status = dcerpc_binding_vector_add_np_default(t, v);
864 if (!NT_STATUS_IS_OK(status)) {
865 return false;
868 status = rpc_ep_register(ev_ctx,
869 msg_ctx,
872 if (!NT_STATUS_IS_OK(status)) {
873 return false;
877 return true;
880 static bool rpc_setup_initshutdown(struct tevent_context *ev_ctx,
881 struct messaging_context *msg_ctx)
883 const struct ndr_interface_table *t = &ndr_table_initshutdown;
884 struct dcerpc_binding_vector *v;
885 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
886 NTSTATUS status;
888 status = rpc_initshutdown_init(NULL);
889 if (!NT_STATUS_IS_OK(status)) {
890 return false;
893 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
894 status = dcerpc_binding_vector_new(talloc_tos(), &v);
895 if (!NT_STATUS_IS_OK(status)) {
896 return false;
899 status = dcerpc_binding_vector_add_np_default(t, v);
900 if (!NT_STATUS_IS_OK(status)) {
901 return false;
904 status = rpc_ep_register(ev_ctx,
905 msg_ctx,
908 if (!NT_STATUS_IS_OK(status)) {
909 return false;
913 return true;
916 bool dcesrv_ep_setup(struct tevent_context *ev_ctx,
917 struct messaging_context *msg_ctx)
919 struct dcerpc_binding_vector *v;
920 const char *rpcsrv_type;
921 TALLOC_CTX *tmp_ctx;
922 NTSTATUS status;
923 bool ok;
925 tmp_ctx = talloc_stackframe();
926 if (tmp_ctx == NULL) {
927 return false;
930 status = dcerpc_binding_vector_new(tmp_ctx,
931 &v);
932 if (!NT_STATUS_IS_OK(status)) {
933 ok = false;
934 goto done;
937 ok = rpc_setup_epmapper(ev_ctx, msg_ctx);
938 if (!ok) {
939 goto done;
942 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
943 "rpc_server",
944 "tcpip",
945 "no");
947 if (strcasecmp_m(rpcsrv_type, "yes") == 0 ||
948 strcasecmp_m(rpcsrv_type, "true") == 0) {
949 status = rpc_setup_tcpip_sockets(ev_ctx,
950 msg_ctx,
951 &ndr_table_winreg,
954 if (!NT_STATUS_IS_OK(status)) {
955 ok = false;
956 goto done;
960 ok = rpc_setup_winreg(ev_ctx, msg_ctx, v);
961 if (!ok) {
962 goto done;
965 ok = rpc_setup_srvsvc(ev_ctx, msg_ctx, v);
966 if (!ok) {
967 goto done;
970 ok = rpc_setup_lsarpc(ev_ctx, msg_ctx, v);
971 if (!ok) {
972 goto done;
975 ok = rpc_setup_samr(ev_ctx, msg_ctx, v);
976 if (!ok) {
977 goto done;
980 ok = rpc_setup_netlogon(ev_ctx, msg_ctx, v);
981 if (!ok) {
982 goto done;
985 ok = rpc_setup_netdfs(ev_ctx, msg_ctx, v);
986 if (!ok) {
987 goto done;
990 #ifdef DEVELOPER
991 ok = rpc_setup_rpcecho(ev_ctx, msg_ctx, v);
992 if (!ok) {
993 goto done;
995 #endif
997 ok = rpc_setup_dssetup(ev_ctx, msg_ctx, v);
998 if (!ok) {
999 goto done;
1002 ok = rpc_setup_wkssvc(ev_ctx, msg_ctx, v);
1003 if (!ok) {
1004 goto done;
1007 ok = rpc_setup_spoolss(ev_ctx, msg_ctx);
1008 if (!ok) {
1009 goto done;
1012 ok = rpc_setup_svcctl(ev_ctx, msg_ctx);
1013 if (!ok) {
1014 goto done;
1017 ok = rpc_setup_ntsvcs(ev_ctx, msg_ctx);
1018 if (!ok) {
1019 goto done;
1022 ok = rpc_setup_eventlog(ev_ctx, msg_ctx);
1023 if (!ok) {
1024 goto done;
1027 ok = rpc_setup_initshutdown(ev_ctx, msg_ctx);
1028 if (!ok) {
1029 goto done;
1032 done:
1033 talloc_free(tmp_ctx);
1034 return ok;
1037 /* vim: set ts=8 sw=8 noet cindent ft=c.doxygen: */