s3-rpc_server: Use rpc_epmapper_mode().
[Samba/gebeck_regimport.git] / source3 / rpc_server / rpc_service_setup.c
blob0eeb17f4446579075070ddc75a1a67e13e1b75aa
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 "disabled");
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 static bool rpc_setup_epmapper(struct tevent_context *ev_ctx,
77 struct messaging_context *msg_ctx)
79 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
80 NTSTATUS status;
82 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
83 status = rpc_epmapper_init(NULL);
84 if (!NT_STATUS_IS_OK(status)) {
85 return false;
89 return true;
92 static bool rpc_setup_winreg(struct tevent_context *ev_ctx,
93 struct messaging_context *msg_ctx,
94 const struct dcerpc_binding_vector *v)
96 const struct ndr_interface_table *t = &ndr_table_winreg;
97 const char *pipe_name = "winreg";
98 struct dcerpc_binding_vector *v2;
99 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
100 NTSTATUS status;
101 bool ok;
103 status = rpc_winreg_init(NULL);
104 if (!NT_STATUS_IS_OK(status)) {
105 return false;
108 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
109 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
110 if (v2 == NULL) {
111 return false;
114 status = dcerpc_binding_vector_replace_iface(t, v2);
115 if (!NT_STATUS_IS_OK(status)) {
116 return false;
119 status = dcerpc_binding_vector_add_np_default(t, v2);
120 if (!NT_STATUS_IS_OK(status)) {
121 return false;
124 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
125 msg_ctx,
126 pipe_name,
127 NULL);
128 if (!ok) {
129 return false;
132 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
133 if (!NT_STATUS_IS_OK(status)) {
134 return false;
137 status = rpc_ep_register(ev_ctx,
138 msg_ctx,
140 v2);
141 if (!NT_STATUS_IS_OK(status)) {
142 return false;
146 return true;
149 static bool rpc_setup_srvsvc(struct tevent_context *ev_ctx,
150 struct messaging_context *msg_ctx,
151 const struct dcerpc_binding_vector *v)
153 const struct ndr_interface_table *t = &ndr_table_srvsvc;
154 const char *pipe_name = "srvsvc";
155 struct dcerpc_binding_vector *v2;
156 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
157 NTSTATUS status;
158 bool ok;
160 status = rpc_srvsvc_init(NULL);
161 if (!NT_STATUS_IS_OK(status)) {
162 return false;
165 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
166 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
167 if (v2 == NULL) {
168 return false;
171 status = dcerpc_binding_vector_replace_iface(t, v2);
172 if (!NT_STATUS_IS_OK(status)) {
173 return false;
176 status = dcerpc_binding_vector_add_np_default(t, v2);
177 if (!NT_STATUS_IS_OK(status)) {
178 return false;
181 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
182 msg_ctx,
183 pipe_name,
184 NULL);
185 if (!ok) {
186 return false;
189 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
190 if (!NT_STATUS_IS_OK(status)) {
191 return false;
194 status = rpc_ep_register(ev_ctx,
195 msg_ctx,
197 v2);
198 if (!NT_STATUS_IS_OK(status)) {
199 return false;
203 return true;
206 static bool rpc_setup_lsarpc(struct tevent_context *ev_ctx,
207 struct messaging_context *msg_ctx,
208 const struct dcerpc_binding_vector *v)
210 const struct ndr_interface_table *t = &ndr_table_lsarpc;
211 const char *pipe_name = "lsarpc";
212 struct dcerpc_binding_vector *v2;
213 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
214 NTSTATUS status;
215 bool ok;
217 status = rpc_lsarpc_init(NULL);
218 if (!NT_STATUS_IS_OK(status)) {
219 return false;
222 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
223 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
224 if (v2 == NULL) {
225 return false;
228 status = dcerpc_binding_vector_replace_iface(t, v2);
229 if (!NT_STATUS_IS_OK(status)) {
230 return false;
233 status = dcerpc_binding_vector_add_np_default(t, v2);
234 if (!NT_STATUS_IS_OK(status)) {
235 return false;
238 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
239 msg_ctx,
240 pipe_name,
241 NULL);
242 if (!ok) {
243 return false;
246 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
247 if (!NT_STATUS_IS_OK(status)) {
248 return false;
251 status = rpc_ep_register(ev_ctx,
252 msg_ctx,
254 v2);
255 if (!NT_STATUS_IS_OK(status)) {
256 return false;
260 return true;
263 static bool rpc_setup_samr(struct tevent_context *ev_ctx,
264 struct messaging_context *msg_ctx,
265 const struct dcerpc_binding_vector *v)
267 const struct ndr_interface_table *t = &ndr_table_samr;
268 const char *pipe_name = "samr";
269 struct dcerpc_binding_vector *v2;
270 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
271 NTSTATUS status;
272 bool ok;
274 status = rpc_samr_init(NULL);
275 if (!NT_STATUS_IS_OK(status)) {
276 return false;
279 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
280 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
281 if (v2 == NULL) {
282 return false;
285 status = dcerpc_binding_vector_replace_iface(t, v2);
286 if (!NT_STATUS_IS_OK(status)) {
287 return false;
290 status = dcerpc_binding_vector_add_np_default(t, v2);
291 if (!NT_STATUS_IS_OK(status)) {
292 return false;
295 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
296 msg_ctx,
297 pipe_name,
298 NULL);
299 if (!ok) {
300 return false;
303 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
304 if (!NT_STATUS_IS_OK(status)) {
305 return false;
308 status = rpc_ep_register(ev_ctx,
309 msg_ctx,
311 v2);
312 if (!NT_STATUS_IS_OK(status)) {
313 return false;
317 return true;
320 static bool rpc_setup_netlogon(struct tevent_context *ev_ctx,
321 struct messaging_context *msg_ctx,
322 const struct dcerpc_binding_vector *v)
324 const struct ndr_interface_table *t = &ndr_table_netlogon;
325 const char *pipe_name = "netlogon";
326 struct dcerpc_binding_vector *v2;
327 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
328 NTSTATUS status;
329 bool ok;
331 status = rpc_netlogon_init(NULL);
332 if (!NT_STATUS_IS_OK(status)) {
333 return false;
336 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
337 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
338 if (v2 == NULL) {
339 return false;
342 status = dcerpc_binding_vector_replace_iface(t, v2);
343 if (!NT_STATUS_IS_OK(status)) {
344 return false;
347 status = dcerpc_binding_vector_add_np_default(t, v2);
348 if (!NT_STATUS_IS_OK(status)) {
349 return false;
352 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
353 msg_ctx,
354 pipe_name,
355 NULL);
356 if (!ok) {
357 return false;
360 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
361 if (!NT_STATUS_IS_OK(status)) {
362 return false;
365 status = rpc_ep_register(ev_ctx,
366 msg_ctx,
368 v2);
369 if (!NT_STATUS_IS_OK(status)) {
370 return false;
374 return true;
377 static bool rpc_setup_netdfs(struct tevent_context *ev_ctx,
378 struct messaging_context *msg_ctx,
379 const struct dcerpc_binding_vector *v)
381 const struct ndr_interface_table *t = &ndr_table_netdfs;
382 const char *pipe_name = "netdfs";
383 struct dcerpc_binding_vector *v2;
384 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
385 NTSTATUS status;
386 bool ok;
388 status = rpc_netdfs_init(NULL);
389 if (!NT_STATUS_IS_OK(status)) {
390 return false;
393 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
394 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
395 if (v2 == NULL) {
396 return false;
399 status = dcerpc_binding_vector_replace_iface(t, v2);
400 if (!NT_STATUS_IS_OK(status)) {
401 return false;
404 status = dcerpc_binding_vector_add_np_default(t, v2);
405 if (!NT_STATUS_IS_OK(status)) {
406 return false;
409 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
410 msg_ctx,
411 pipe_name,
412 NULL);
413 if (!ok) {
414 return false;
417 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
418 if (!NT_STATUS_IS_OK(status)) {
419 return false;
422 status = rpc_ep_register(ev_ctx,
423 msg_ctx,
425 v2);
426 if (!NT_STATUS_IS_OK(status)) {
427 return false;
431 return true;
434 #ifdef DEVELOPER
435 static bool rpc_setup_rpcecho(struct tevent_context *ev_ctx,
436 struct messaging_context *msg_ctx,
437 const struct dcerpc_binding_vector *v)
439 const struct ndr_interface_table *t = &ndr_table_rpcecho;
440 const char *pipe_name = "rpcecho";
441 struct dcerpc_binding_vector *v2;
442 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
443 NTSTATUS status;
444 bool ok;
446 status = rpc_rpcecho_init(NULL);
447 if (!NT_STATUS_IS_OK(status)) {
448 return false;
451 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
452 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
453 if (v2 == NULL) {
454 return false;
457 status = dcerpc_binding_vector_replace_iface(t, v2);
458 if (!NT_STATUS_IS_OK(status)) {
459 return false;
462 status = dcerpc_binding_vector_add_np_default(t, v2);
463 if (!NT_STATUS_IS_OK(status)) {
464 return false;
467 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
468 msg_ctx,
469 pipe_name,
470 NULL);
471 if (!ok) {
472 return false;
475 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
476 if (!NT_STATUS_IS_OK(status)) {
477 return false;
480 status = rpc_ep_register(ev_ctx,
481 msg_ctx,
483 v2);
484 if (!NT_STATUS_IS_OK(status)) {
485 return false;
489 return true;
491 #endif
493 static bool rpc_setup_dssetup(struct tevent_context *ev_ctx,
494 struct messaging_context *msg_ctx,
495 const struct dcerpc_binding_vector *v)
497 const struct ndr_interface_table *t = &ndr_table_dssetup;
498 const char *pipe_name = "dssetup";
499 struct dcerpc_binding_vector *v2;
500 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
501 NTSTATUS status;
502 bool ok;
504 status = rpc_dssetup_init(NULL);
505 if (!NT_STATUS_IS_OK(status)) {
506 return false;
509 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
510 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
511 if (v2 == NULL) {
512 return false;
515 status = dcerpc_binding_vector_replace_iface(t, v2);
516 if (!NT_STATUS_IS_OK(status)) {
517 return false;
520 status = dcerpc_binding_vector_add_np_default(t, v2);
521 if (!NT_STATUS_IS_OK(status)) {
522 return false;
525 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
526 msg_ctx,
527 pipe_name,
528 NULL);
529 if (!ok) {
530 return false;
533 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
534 if (!NT_STATUS_IS_OK(status)) {
535 return false;
538 status = rpc_ep_register(ev_ctx,
539 msg_ctx,
541 v2);
542 if (!NT_STATUS_IS_OK(status)) {
543 return false;
547 return true;
550 static bool rpc_setup_wkssvc(struct tevent_context *ev_ctx,
551 struct messaging_context *msg_ctx,
552 const struct dcerpc_binding_vector *v)
554 const struct ndr_interface_table *t = &ndr_table_wkssvc;
555 const char *pipe_name = "wkssvc";
556 struct dcerpc_binding_vector *v2;
557 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
558 NTSTATUS status;
559 bool ok;
561 status = rpc_wkssvc_init(NULL);
562 if (!NT_STATUS_IS_OK(status)) {
563 return false;
566 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
567 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
568 if (v2 == NULL) {
569 return false;
572 status = dcerpc_binding_vector_replace_iface(t, v2);
573 if (!NT_STATUS_IS_OK(status)) {
574 return false;
577 status = dcerpc_binding_vector_add_np_default(t, v2);
578 if (!NT_STATUS_IS_OK(status)) {
579 return false;
582 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
583 msg_ctx,
584 pipe_name,
585 NULL);
586 if (!ok) {
587 return false;
590 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
591 if (!NT_STATUS_IS_OK(status)) {
592 return false;
595 status = rpc_ep_register(ev_ctx,
596 msg_ctx,
598 v2);
599 if (!NT_STATUS_IS_OK(status)) {
600 return false;
604 return true;
607 static bool spoolss_init_cb(void *ptr)
609 struct messaging_context *msg_ctx =
610 talloc_get_type_abort(ptr, struct messaging_context);
611 bool ok;
614 * Migrate the printers first.
616 ok = nt_printing_tdb_migrate(msg_ctx);
617 if (!ok) {
618 return false;
621 return true;
624 static bool spoolss_shutdown_cb(void *ptr)
626 srv_spoolss_cleanup();
628 return true;
631 static bool rpc_setup_spoolss(struct tevent_context *ev_ctx,
632 struct messaging_context *msg_ctx)
634 const struct ndr_interface_table *t = &ndr_table_spoolss;
635 struct rpc_srv_callbacks spoolss_cb;
636 const char *rpcsrv_type;
637 struct dcerpc_binding_vector *v;
638 NTSTATUS status;
640 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
641 "rpc_server",
642 "spoolss",
643 "embedded");
645 if (strcasecmp_m(rpcsrv_type, "embedded") == 0) {
646 spoolss_cb.init = spoolss_init_cb;
647 spoolss_cb.shutdown = spoolss_shutdown_cb;
648 spoolss_cb.private_data = msg_ctx;
650 status = rpc_spoolss_init(&spoolss_cb);
651 } else if (strcasecmp_m(rpcsrv_type, "daemon") == 0 ||
652 strcasecmp_m(rpcsrv_type, "external") == 0) {
653 status = rpc_spoolss_init(NULL);
655 if (!NT_STATUS_IS_OK(status)) {
656 return false;
659 if (strcasecmp_m(rpcsrv_type, "embedded")) {
660 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
662 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
663 status = dcerpc_binding_vector_new(talloc_tos(), &v);
664 if (!NT_STATUS_IS_OK(status)) {
665 return false;
668 status = dcerpc_binding_vector_add_np_default(t, v);
669 if (!NT_STATUS_IS_OK(status)) {
670 return false;
673 status = rpc_ep_register(ev_ctx,
674 msg_ctx,
677 if (!NT_STATUS_IS_OK(status)) {
678 return false;
683 return true;
686 static bool svcctl_init_cb(void *ptr)
688 struct messaging_context *msg_ctx =
689 talloc_get_type_abort(ptr, struct messaging_context);
690 bool ok;
692 /* initialize the control hooks */
693 init_service_op_table();
695 ok = svcctl_init_winreg(msg_ctx);
696 if (!ok) {
697 return false;
700 return true;
703 static bool svcctl_shutdown_cb(void *ptr)
705 shutdown_service_op_table();
707 return true;
710 static bool rpc_setup_svcctl(struct tevent_context *ev_ctx,
711 struct messaging_context *msg_ctx)
713 const struct ndr_interface_table *t = &ndr_table_svcctl;
714 const char *pipe_name = "svcctl";
715 struct dcerpc_binding_vector *v;
716 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
717 struct rpc_srv_callbacks svcctl_cb;
718 NTSTATUS status;
719 bool ok;
721 svcctl_cb.init = svcctl_init_cb;
722 svcctl_cb.shutdown = svcctl_shutdown_cb;
723 svcctl_cb.private_data = msg_ctx;
725 status = rpc_svcctl_init(&svcctl_cb);
726 if (!NT_STATUS_IS_OK(status)) {
727 return false;
730 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
731 status = dcerpc_binding_vector_new(talloc_tos(), &v);
732 if (!NT_STATUS_IS_OK(status)) {
733 return false;
736 status = dcerpc_binding_vector_add_np_default(t, v);
737 if (!NT_STATUS_IS_OK(status)) {
738 return false;
741 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
742 msg_ctx,
743 pipe_name,
744 NULL);
745 if (!ok) {
746 return false;
749 status = dcerpc_binding_vector_add_unix(t, v, pipe_name);
750 if (!NT_STATUS_IS_OK(status)) {
751 return false;
754 status = rpc_ep_register(ev_ctx,
755 msg_ctx,
758 if (!NT_STATUS_IS_OK(status)) {
759 return false;
763 return true;
766 static bool rpc_setup_ntsvcs(struct tevent_context *ev_ctx,
767 struct messaging_context *msg_ctx)
769 const struct ndr_interface_table *t = &ndr_table_ntsvcs;
770 struct dcerpc_binding_vector *v;
771 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
772 NTSTATUS status;
774 status = rpc_ntsvcs_init(NULL);
775 if (!NT_STATUS_IS_OK(status)) {
776 return false;
779 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
780 status = dcerpc_binding_vector_new(talloc_tos(), &v);
781 if (!NT_STATUS_IS_OK(status)) {
782 return false;
785 status = dcerpc_binding_vector_add_np_default(t, v);
786 if (!NT_STATUS_IS_OK(status)) {
787 return false;
790 status = rpc_ep_register(ev_ctx,
791 msg_ctx,
794 if (!NT_STATUS_IS_OK(status)) {
795 return false;
799 return true;
802 static bool eventlog_init_cb(void *ptr)
804 struct messaging_context *msg_ctx =
805 talloc_get_type_abort(ptr, struct messaging_context);
806 bool ok;
808 ok = eventlog_init_winreg(msg_ctx);
809 if (!ok) {
810 return false;
813 return true;
816 static bool rpc_setup_eventlog(struct tevent_context *ev_ctx,
817 struct messaging_context *msg_ctx)
819 const struct ndr_interface_table *t = &ndr_table_eventlog;
820 struct rpc_srv_callbacks eventlog_cb;
821 struct dcerpc_binding_vector *v;
822 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
823 NTSTATUS status;
825 eventlog_cb.init = eventlog_init_cb;
826 eventlog_cb.shutdown = NULL;
827 eventlog_cb.private_data = msg_ctx;
829 status = rpc_eventlog_init(&eventlog_cb);
830 if (!NT_STATUS_IS_OK(status)) {
831 return false;
834 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
835 status = dcerpc_binding_vector_new(talloc_tos(), &v);
836 if (!NT_STATUS_IS_OK(status)) {
837 return false;
840 status = dcerpc_binding_vector_add_np_default(t, v);
841 if (!NT_STATUS_IS_OK(status)) {
842 return false;
845 status = rpc_ep_register(ev_ctx,
846 msg_ctx,
849 if (!NT_STATUS_IS_OK(status)) {
850 return false;
854 return true;
857 static bool rpc_setup_initshutdown(struct tevent_context *ev_ctx,
858 struct messaging_context *msg_ctx)
860 const struct ndr_interface_table *t = &ndr_table_initshutdown;
861 struct dcerpc_binding_vector *v;
862 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
863 NTSTATUS status;
865 status = rpc_initshutdown_init(NULL);
866 if (!NT_STATUS_IS_OK(status)) {
867 return false;
870 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
871 status = dcerpc_binding_vector_new(talloc_tos(), &v);
872 if (!NT_STATUS_IS_OK(status)) {
873 return false;
876 status = dcerpc_binding_vector_add_np_default(t, v);
877 if (!NT_STATUS_IS_OK(status)) {
878 return false;
881 status = rpc_ep_register(ev_ctx,
882 msg_ctx,
885 if (!NT_STATUS_IS_OK(status)) {
886 return false;
890 return true;
893 bool dcesrv_ep_setup(struct tevent_context *ev_ctx,
894 struct messaging_context *msg_ctx)
896 struct dcerpc_binding_vector *v;
897 const char *rpcsrv_type;
898 TALLOC_CTX *tmp_ctx;
899 NTSTATUS status;
900 bool ok;
902 tmp_ctx = talloc_stackframe();
903 if (tmp_ctx == NULL) {
904 return false;
907 status = dcerpc_binding_vector_new(tmp_ctx,
908 &v);
909 if (!NT_STATUS_IS_OK(status)) {
910 ok = false;
911 goto done;
914 ok = rpc_setup_epmapper(ev_ctx, msg_ctx);
915 if (!ok) {
916 goto done;
919 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
920 "rpc_server",
921 "tcpip",
922 "no");
924 if (strcasecmp_m(rpcsrv_type, "yes") == 0 ||
925 strcasecmp_m(rpcsrv_type, "true") == 0) {
926 status = rpc_setup_tcpip_sockets(ev_ctx,
927 msg_ctx,
928 &ndr_table_winreg,
931 if (!NT_STATUS_IS_OK(status)) {
932 ok = false;
933 goto done;
937 ok = rpc_setup_winreg(ev_ctx, msg_ctx, v);
938 if (!ok) {
939 goto done;
942 ok = rpc_setup_srvsvc(ev_ctx, msg_ctx, v);
943 if (!ok) {
944 goto done;
947 ok = rpc_setup_lsarpc(ev_ctx, msg_ctx, v);
948 if (!ok) {
949 goto done;
952 ok = rpc_setup_samr(ev_ctx, msg_ctx, v);
953 if (!ok) {
954 goto done;
957 ok = rpc_setup_netlogon(ev_ctx, msg_ctx, v);
958 if (!ok) {
959 goto done;
962 ok = rpc_setup_netdfs(ev_ctx, msg_ctx, v);
963 if (!ok) {
964 goto done;
967 #ifdef DEVELOPER
968 ok = rpc_setup_rpcecho(ev_ctx, msg_ctx, v);
969 if (!ok) {
970 goto done;
972 #endif
974 ok = rpc_setup_dssetup(ev_ctx, msg_ctx, v);
975 if (!ok) {
976 goto done;
979 ok = rpc_setup_wkssvc(ev_ctx, msg_ctx, v);
980 if (!ok) {
981 goto done;
984 ok = rpc_setup_spoolss(ev_ctx, msg_ctx);
985 if (!ok) {
986 goto done;
989 ok = rpc_setup_svcctl(ev_ctx, msg_ctx);
990 if (!ok) {
991 goto done;
994 ok = rpc_setup_ntsvcs(ev_ctx, msg_ctx);
995 if (!ok) {
996 goto done;
999 ok = rpc_setup_eventlog(ev_ctx, msg_ctx);
1000 if (!ok) {
1001 goto done;
1004 ok = rpc_setup_initshutdown(ev_ctx, msg_ctx);
1005 if (!ok) {
1006 goto done;
1009 done:
1010 talloc_free(tmp_ctx);
1011 return ok;
1014 /* vim: set ts=8 sw=8 noet cindent ft=c.doxygen: */