s3-rpc_server: Remove unused _rpc_ep_register.
[Samba/gebeck_regimport.git] / source3 / rpc_server / rpc_ep_setup.c
blob3731915a60e55aedc10d1284eff8013b700c9083
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"
24 #include "../librpc/gen_ndr/srv_epmapper.h"
25 #include "../librpc/gen_ndr/srv_srvsvc.h"
26 #include "../librpc/gen_ndr/srv_winreg.h"
27 #include "../librpc/gen_ndr/srv_dfs.h"
28 #include "../librpc/gen_ndr/srv_dssetup.h"
29 #include "../librpc/gen_ndr/srv_echo.h"
30 #include "../librpc/gen_ndr/srv_eventlog.h"
31 #include "../librpc/gen_ndr/srv_initshutdown.h"
32 #include "../librpc/gen_ndr/srv_lsa.h"
33 #include "../librpc/gen_ndr/srv_netlogon.h"
34 #include "../librpc/gen_ndr/srv_ntsvcs.h"
35 #include "../librpc/gen_ndr/srv_samr.h"
36 #include "../librpc/gen_ndr/srv_spoolss.h"
37 #include "../librpc/gen_ndr/srv_svcctl.h"
38 #include "../librpc/gen_ndr/srv_wkssvc.h"
40 #include "printing/nt_printing_migrate.h"
41 #include "rpc_server/eventlog/srv_eventlog_reg.h"
42 #include "rpc_server/svcctl/srv_svcctl_reg.h"
44 #include "librpc/rpc/dcerpc_ep.h"
46 #include "rpc_server/rpc_ep_setup.h"
47 #include "rpc_server/rpc_server.h"
49 struct dcesrv_ep_context {
50 struct tevent_context *ev_ctx;
51 struct messaging_context *msg_ctx;
54 static uint16_t _open_sockets(struct tevent_context *ev_ctx,
55 struct messaging_context *msg_ctx,
56 struct ndr_syntax_id syntax_id,
57 uint16_t port)
59 uint32_t num_ifs = iface_count();
60 uint32_t i;
61 uint16_t p = 0;
63 if (lp_interfaces() && lp_bind_interfaces_only()) {
65 * We have been given an interfaces line, and been told to only
66 * bind to those interfaces. Create a socket per interface and
67 * bind to only these.
70 /* Now open a listen socket for each of the interfaces. */
71 for(i = 0; i < num_ifs; i++) {
72 const struct sockaddr_storage *ifss =
73 iface_n_sockaddr_storage(i);
75 p = setup_dcerpc_ncacn_tcpip_socket(ev_ctx,
76 msg_ctx,
77 syntax_id,
78 ifss,
79 port);
80 if (p == 0) {
81 return 0;
83 port = p;
85 } else {
86 const char *sock_addr = lp_socket_address();
87 const char *sock_ptr;
88 char *sock_tok;
90 if (strequal(sock_addr, "0.0.0.0") ||
91 strequal(sock_addr, "::")) {
92 #if HAVE_IPV6
93 sock_addr = "::";
94 #else
95 sock_addr = "0.0.0.0";
96 #endif
99 for (sock_ptr = sock_addr;
100 next_token_talloc(talloc_tos(), &sock_ptr, &sock_tok, " \t,");
102 struct sockaddr_storage ss;
104 /* open an incoming socket */
105 if (!interpret_string_addr(&ss,
106 sock_tok,
107 AI_NUMERICHOST|AI_PASSIVE)) {
108 continue;
111 p = setup_dcerpc_ncacn_tcpip_socket(ev_ctx,
112 msg_ctx,
113 syntax_id,
114 &ss,
115 port);
116 if (p == 0) {
117 return 0;
119 port = p;
123 return p;
126 static NTSTATUS _rpc_ep_unregister(const struct ndr_interface_table *iface)
128 struct dcerpc_binding_vector *v = NULL;
129 NTSTATUS status;
131 status = dcerpc_binding_vector_create(talloc_tos(),
132 iface,
134 NULL,
135 &v);
136 if (!NT_STATUS_IS_OK(status)) {
137 return status;
140 status = dcerpc_ep_unregister(iface,
142 &iface->syntax_id.uuid);
143 if (!NT_STATUS_IS_OK(status)) {
144 return status;
147 return status;
150 static void rpc_ep_setup_register_loop(struct tevent_req *subreq);
151 static NTSTATUS rpc_ep_setup_try_register(struct tevent_context *ev_ctx,
152 struct messaging_context *msg_ctx,
153 const struct ndr_interface_table *iface,
154 const char *name,
155 uint16_t port);
157 struct rpc_ep_regsiter_state {
158 uint32_t wait_time;
160 struct tevent_context *ev_ctx;
161 struct messaging_context *msg_ctx;
163 const struct ndr_interface_table *iface;
165 const char *ncalrpc;
166 uint16_t port;
169 static NTSTATUS rpc_ep_setup_register(struct tevent_context *ev_ctx,
170 struct messaging_context *msg_ctx,
171 const struct ndr_interface_table *iface,
172 const char *ncalrpc,
173 uint16_t port)
175 struct rpc_ep_regsiter_state *state;
176 struct tevent_req *req;
178 state = talloc(ev_ctx, struct rpc_ep_regsiter_state);
179 if (state == NULL) {
180 return NT_STATUS_NO_MEMORY;
183 state->wait_time = 1;
184 state->ev_ctx = ev_ctx;
185 state->msg_ctx = msg_ctx;
186 state->iface = iface;
187 state->ncalrpc = talloc_strdup(state, ncalrpc);
188 state->port = port;
190 req = tevent_wakeup_send(state, ev_ctx, timeval_current_ofs(1, 0));
191 if (tevent_req_nomem(state, req)) {
192 talloc_free(state);
193 return NT_STATUS_NO_MEMORY;
196 tevent_req_set_callback(req, rpc_ep_setup_register_loop, state);
198 return NT_STATUS_OK;
201 static void rpc_ep_setup_register_loop(struct tevent_req *req)
203 struct rpc_ep_regsiter_state *state =
204 tevent_req_callback_data(req, struct rpc_ep_regsiter_state);
205 NTSTATUS status;
206 bool ok;
208 ok = tevent_wakeup_recv(req);
209 TALLOC_FREE(req);
210 if (!ok) {
211 return;
214 status = rpc_ep_setup_try_register(state->ev_ctx,
215 state->msg_ctx,
216 state->iface,
217 state->ncalrpc,
218 state->port);
219 if (NT_STATUS_IS_OK(status)) {
220 talloc_free(state);
221 return;
224 state->wait_time = state->wait_time * 2;
225 if (state->wait_time > 16) {
226 talloc_free(state);
227 return;
230 req = tevent_wakeup_send(state,
231 state->ev_ctx,
232 timeval_current_ofs(state->wait_time, 0));
233 if (tevent_req_nomem(state, req)) {
234 talloc_free(state);
235 return;
238 tevent_req_set_callback(req, rpc_ep_setup_register_loop, state);
239 return;
242 static NTSTATUS rpc_ep_setup_try_register(struct tevent_context *ev_ctx,
243 struct messaging_context *msg_ctx,
244 const struct ndr_interface_table *iface,
245 const char *name,
246 uint16_t port)
248 struct dcerpc_binding_vector *v = NULL;
249 NTSTATUS status;
251 status = dcerpc_binding_vector_create(talloc_tos(),
252 iface,
253 port,
254 name,
255 &v);
256 if (!NT_STATUS_IS_OK(status)) {
257 return status;
260 status = dcerpc_ep_register(iface,
262 &iface->syntax_id.uuid,
263 name);
264 if (!NT_STATUS_IS_OK(status)) {
265 return status;
268 return status;
271 static bool epmapper_init_cb(void *ptr)
273 struct dcesrv_ep_context *ep_ctx =
274 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
275 uint16_t port;
277 port = _open_sockets(ep_ctx->ev_ctx,
278 ep_ctx->msg_ctx,
279 ndr_table_epmapper.syntax_id,
280 135);
281 if (port == 135) {
282 return true;
285 return false;
288 static bool winreg_init_cb(void *ptr)
290 struct dcesrv_ep_context *ep_ctx =
291 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
292 struct ndr_syntax_id abstract_syntax = ndr_table_winreg.syntax_id;
293 const char *pipe_name = "winreg";
294 const char *rpcsrv_type;
295 uint16_t port;
297 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
298 "rpc_server",
299 "epmapper",
300 "none");
302 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
303 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
304 NTSTATUS status;
305 bool ok;
307 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
308 ep_ctx->msg_ctx,
309 abstract_syntax,
310 pipe_name);
311 if (!ok) {
312 return false;
314 port = _open_sockets(ep_ctx->ev_ctx,
315 ep_ctx->msg_ctx,
316 abstract_syntax,
318 if (port == 0) {
319 return false;
322 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
323 ep_ctx->msg_ctx,
324 &ndr_table_winreg,
325 pipe_name,
326 port);
327 if (!NT_STATUS_IS_OK(status)) {
328 return false;
332 return true;
335 static bool winreg_shutdown_cb(void *ptr)
337 const char *rpcsrv_type;
339 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
340 "rpc_server",
341 "epmapper",
342 "none");
344 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
345 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
346 NTSTATUS status;
348 status = _rpc_ep_unregister(&ndr_table_winreg);
349 if (!NT_STATUS_IS_OK(status)) {
350 return false;
354 return true;
357 static bool srvsvc_init_cb(void *ptr)
359 struct dcesrv_ep_context *ep_ctx =
360 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
361 struct ndr_syntax_id abstract_syntax = ndr_table_srvsvc.syntax_id;
362 const char *pipe_name = "srvsvc";
363 const char *rpcsrv_type;
364 uint16_t port;
366 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
367 "rpc_server",
368 "epmapper",
369 "none");
371 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
372 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
373 NTSTATUS status;
374 bool ok;
376 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
377 ep_ctx->msg_ctx,
378 abstract_syntax,
379 pipe_name);
380 if (!ok) {
381 return false;
384 port = _open_sockets(ep_ctx->ev_ctx,
385 ep_ctx->msg_ctx,
386 abstract_syntax,
388 if (port == 0) {
389 return false;
392 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
393 ep_ctx->msg_ctx,
394 &ndr_table_srvsvc,
395 pipe_name,
396 port);
397 if (!NT_STATUS_IS_OK(status)) {
398 return false;
402 return true;
405 static bool srvsvc_shutdown_cb(void *ptr)
407 const char *rpcsrv_type;
409 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
410 "rpc_server",
411 "epmapper",
412 "none");
414 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
415 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
416 NTSTATUS status;
418 status =_rpc_ep_unregister(&ndr_table_srvsvc);
419 if (!NT_STATUS_IS_OK(status)) {
420 return false;
424 return true;
427 static bool lsarpc_init_cb(void *ptr)
429 struct dcesrv_ep_context *ep_ctx =
430 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
431 struct ndr_syntax_id abstract_syntax = ndr_table_lsarpc.syntax_id;
432 const char *pipe_name = "lsarpc";
433 const char *rpcsrv_type;
434 uint16_t port;
436 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
437 "rpc_server",
438 "epmapper",
439 "none");
441 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
442 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
443 NTSTATUS status;
444 bool ok;
446 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
447 ep_ctx->msg_ctx,
448 abstract_syntax,
449 pipe_name);
450 if (!ok) {
451 return false;
454 port = _open_sockets(ep_ctx->ev_ctx,
455 ep_ctx->msg_ctx,
456 abstract_syntax,
458 if (port == 0) {
459 return false;
462 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
463 ep_ctx->msg_ctx,
464 &ndr_table_lsarpc,
465 pipe_name,
466 port);
467 if (!NT_STATUS_IS_OK(status)) {
468 return false;
472 return true;
475 static bool lsarpc_shutdown_cb(void *ptr)
477 const char *rpcsrv_type;
479 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
480 "rpc_server",
481 "epmapper",
482 "none");
484 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
485 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
486 NTSTATUS status;
488 status = _rpc_ep_unregister(&ndr_table_lsarpc);
489 if (!NT_STATUS_IS_OK(status)) {
490 return false;
494 return true;
497 static bool samr_init_cb(void *ptr)
499 struct dcesrv_ep_context *ep_ctx =
500 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
501 struct ndr_syntax_id abstract_syntax = ndr_table_samr.syntax_id;
502 const char *pipe_name = "samr";
503 const char *rpcsrv_type;
504 uint16_t port;
506 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
507 "rpc_server",
508 "epmapper",
509 "none");
511 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
512 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
513 NTSTATUS status;
514 bool ok;
516 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
517 ep_ctx->msg_ctx,
518 abstract_syntax,
519 pipe_name);
520 if (!ok) {
521 return false;
524 port = _open_sockets(ep_ctx->ev_ctx,
525 ep_ctx->msg_ctx,
526 abstract_syntax,
528 if (port == 0) {
529 return false;
532 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
533 ep_ctx->msg_ctx,
534 &ndr_table_samr,
535 pipe_name,
536 port);
537 if (!NT_STATUS_IS_OK(status)) {
538 return false;
542 return true;
545 static bool samr_shutdown_cb(void *ptr)
547 const char *rpcsrv_type;
549 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
550 "rpc_server",
551 "epmapper",
552 "none");
554 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
555 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
556 NTSTATUS status;
558 status = _rpc_ep_unregister(&ndr_table_samr);
559 if (!NT_STATUS_IS_OK(status)) {
560 return false;
564 return true;
567 static bool netlogon_init_cb(void *ptr)
569 struct dcesrv_ep_context *ep_ctx =
570 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
571 struct ndr_syntax_id abstract_syntax = ndr_table_netlogon.syntax_id;
572 const char *pipe_name = "netlogon";
573 const char *rpcsrv_type;
574 uint16_t port;
576 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
577 "rpc_server",
578 "epmapper",
579 "none");
581 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
582 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
583 NTSTATUS status;
584 bool ok;
586 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
587 ep_ctx->msg_ctx,
588 abstract_syntax,
589 pipe_name);
590 if (!ok) {
591 return false;
594 port = _open_sockets(ep_ctx->ev_ctx,
595 ep_ctx->msg_ctx,
596 abstract_syntax,
598 if (port == 0) {
599 return false;
602 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
603 ep_ctx->msg_ctx,
604 &ndr_table_netlogon,
605 pipe_name,
606 port);
607 if (!NT_STATUS_IS_OK(status)) {
608 return false;
612 return true;
615 static bool netlogon_shutdown_cb(void *ptr)
617 const char *rpcsrv_type;
619 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
620 "rpc_server",
621 "epmapper",
622 "none");
624 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
625 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
626 NTSTATUS status;
628 status = _rpc_ep_unregister(&ndr_table_netlogon);
629 if (!NT_STATUS_IS_OK(status)) {
630 return false;
634 return true;
637 static bool spoolss_init_cb(void *ptr)
639 struct dcesrv_ep_context *ep_ctx =
640 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
641 const char *rpcsrv_type;
642 bool ok;
644 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
645 "rpc_server",
646 "epmapper",
647 "none");
650 * Migrate the printers first.
652 ok = nt_printing_tdb_migrate(ep_ctx->msg_ctx);
653 if (!ok) {
654 return false;
657 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
658 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
659 NTSTATUS status;
661 status =rpc_ep_setup_register(ep_ctx->ev_ctx,
662 ep_ctx->msg_ctx,
663 &ndr_table_spoolss,
664 "spoolss",
666 if (!NT_STATUS_IS_OK(status)) {
667 return false;
671 return true;
674 static bool spoolss_shutdown_cb(void *ptr)
676 const char *rpcsrv_type;
678 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
679 "rpc_server",
680 "epmapper",
681 "none");
683 srv_spoolss_cleanup();
685 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
686 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
687 NTSTATUS status;
689 status = _rpc_ep_unregister(&ndr_table_spoolss);
690 if (!NT_STATUS_IS_OK(status)) {
691 return false;
695 return true;
698 static bool svcctl_init_cb(void *ptr)
700 struct dcesrv_ep_context *ep_ctx =
701 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
702 const char *rpcsrv_type;
703 bool ok;
705 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
706 "rpc_server",
707 "epmapper",
708 "none");
710 ok = svcctl_init_winreg(ep_ctx->msg_ctx);
711 if (!ok) {
712 return false;
715 /* initialize the control hooks */
716 init_service_op_table();
718 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
719 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
720 NTSTATUS status;
722 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
723 ep_ctx->msg_ctx,
724 &ndr_table_svcctl,
725 "svcctl",
727 if (!NT_STATUS_IS_OK(status)) {
728 return false;
732 return true;
735 static bool svcctl_shutdown_cb(void *ptr)
737 const char *rpcsrv_type;
739 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
740 "rpc_server",
741 "epmapper",
742 "none");
743 shutdown_service_op_table();
745 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
746 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
747 NTSTATUS status;
749 status = _rpc_ep_unregister(&ndr_table_svcctl);
750 if (!NT_STATUS_IS_OK(status)) {
751 return false;
755 return true;
758 static bool ntsvcs_init_cb(void *ptr)
760 struct dcesrv_ep_context *ep_ctx =
761 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
762 const char *rpcsrv_type;
764 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
765 "rpc_server",
766 "epmapper",
767 "none");
769 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
770 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
771 NTSTATUS status;
773 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
774 ep_ctx->msg_ctx,
775 &ndr_table_ntsvcs,
776 "ntsvcs",
778 if (!NT_STATUS_IS_OK(status)) {
779 return false;
783 return true;
786 static bool ntsvcs_shutdown_cb(void *ptr)
788 const char *rpcsrv_type;
790 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
791 "rpc_server",
792 "epmapper",
793 "none");
795 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
796 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
797 NTSTATUS status;
799 status = _rpc_ep_unregister(&ndr_table_ntsvcs);
800 if (!NT_STATUS_IS_OK(status)) {
801 return false;
805 return true;
808 static bool eventlog_init_cb(void *ptr)
810 struct dcesrv_ep_context *ep_ctx =
811 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
812 const char *rpcsrv_type;
813 bool ok;
815 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
816 "rpc_server",
817 "epmapper",
818 "none");
820 ok = eventlog_init_winreg(ep_ctx->msg_ctx);
821 if (!ok) {
822 return false;
825 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
826 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
827 NTSTATUS status;
829 status =rpc_ep_setup_register(ep_ctx->ev_ctx,
830 ep_ctx->msg_ctx,
831 &ndr_table_eventlog,
832 "eventlog",
834 if (!NT_STATUS_IS_OK(status)) {
835 return false;
839 return true;
842 static bool eventlog_shutdown_cb(void *ptr)
844 const char *rpcsrv_type;
846 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
847 "rpc_server",
848 "epmapper",
849 "none");
851 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
852 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
853 NTSTATUS status;
855 status = _rpc_ep_unregister(&ndr_table_eventlog);
856 if (!NT_STATUS_IS_OK(status)) {
857 return false;
861 return true;
864 static bool initshutdown_init_cb(void *ptr)
866 struct dcesrv_ep_context *ep_ctx =
867 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
868 const char *rpcsrv_type;
870 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
871 "rpc_server",
872 "epmapper",
873 "none");
875 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
876 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
877 NTSTATUS status;
879 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
880 ep_ctx->msg_ctx,
881 &ndr_table_initshutdown,
882 "initshutdown",
884 if (!NT_STATUS_IS_OK(status)) {
885 return false;
889 return true;
892 static bool initshutdown_shutdown_cb(void *ptr)
894 const char *rpcsrv_type;
896 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
897 "rpc_server",
898 "epmapper",
899 "none");
901 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
902 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
903 NTSTATUS status;
905 status = _rpc_ep_unregister(&ndr_table_initshutdown);
906 if (!NT_STATUS_IS_OK(status)) {
907 return false;
911 return true;
914 #ifdef DEVELOPER
915 static bool rpcecho_init_cb(void *ptr) {
916 struct dcesrv_ep_context *ep_ctx =
917 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
918 const char *rpcsrv_type;
919 uint16_t port;
921 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
922 "rpc_server",
923 "epmapper",
924 "none");
926 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
927 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
928 NTSTATUS status;
930 port = _open_sockets(ep_ctx->ev_ctx,
931 ep_ctx->msg_ctx,
932 ndr_table_rpcecho.syntax_id,
934 if (port == 0) {
935 return false;
938 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
939 ep_ctx->msg_ctx,
940 &ndr_table_rpcecho,
941 "rpcecho",
942 port);
943 if (!NT_STATUS_IS_OK(status)) {
944 return false;
948 return true;
951 static bool rpcecho_shutdown_cb(void *ptr)
953 const char *rpcsrv_type;
955 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
956 "rpc_server",
957 "epmapper",
958 "none");
960 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
961 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
962 NTSTATUS status;
964 status = _rpc_ep_unregister(&ndr_table_rpcecho);
965 if (!NT_STATUS_IS_OK(status)) {
966 return false;
970 return true;
972 #endif
974 static bool netdfs_init_cb(void *ptr)
976 struct dcesrv_ep_context *ep_ctx =
977 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
978 struct ndr_syntax_id abstract_syntax = ndr_table_netdfs.syntax_id;
979 const char *pipe_name = "netdfs";
980 const char *rpcsrv_type;
981 uint16_t port;
983 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
984 "rpc_server",
985 "epmapper",
986 "none");
987 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
988 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
989 NTSTATUS status;
990 bool ok;
992 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
993 ep_ctx->msg_ctx,
994 abstract_syntax,
995 pipe_name);
996 if (!ok) {
997 return false;
1000 port = _open_sockets(ep_ctx->ev_ctx,
1001 ep_ctx->msg_ctx,
1002 abstract_syntax,
1004 if (port == 0) {
1005 return false;
1008 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
1009 ep_ctx->msg_ctx,
1010 &ndr_table_netdfs,
1011 pipe_name,
1012 port);
1013 if (!NT_STATUS_IS_OK(status)) {
1014 return false;
1018 return true;
1021 static bool netdfs_shutdown_cb(void *ptr) {
1022 const char *rpcsrv_type;
1024 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
1025 "rpc_server",
1026 "epmapper",
1027 "none");
1029 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
1030 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
1031 NTSTATUS status;
1033 status = _rpc_ep_unregister(&ndr_table_netdfs);
1034 if (!NT_STATUS_IS_OK(status)) {
1035 return false;
1039 return true;
1042 static bool dssetup_init_cb(void *ptr)
1044 struct dcesrv_ep_context *ep_ctx =
1045 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
1046 struct ndr_syntax_id abstract_syntax = ndr_table_dssetup.syntax_id;
1047 const char *pipe_name = "dssetup";
1048 const char *rpcsrv_type;
1049 uint16_t port;
1051 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
1052 "rpc_server",
1053 "epmapper",
1054 "none");
1056 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
1057 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
1058 NTSTATUS status;
1059 bool ok;
1061 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
1062 ep_ctx->msg_ctx,
1063 abstract_syntax,
1064 pipe_name);
1065 if (!ok) {
1066 return false;
1069 port = _open_sockets(ep_ctx->ev_ctx,
1070 ep_ctx->msg_ctx,
1071 abstract_syntax,
1073 if (port == 0) {
1074 return false;
1077 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
1078 ep_ctx->msg_ctx,
1079 &ndr_table_dssetup,
1080 "dssetup",
1081 port);
1082 if (!NT_STATUS_IS_OK(status)) {
1083 return false;
1087 return true;
1090 static bool dssetup_shutdown_cb(void *ptr) {
1091 const char *rpcsrv_type;
1093 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
1094 "rpc_server",
1095 "epmapper",
1096 "none");
1098 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
1099 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
1100 NTSTATUS status;
1102 status = _rpc_ep_unregister(&ndr_table_dssetup);
1103 if (!NT_STATUS_IS_OK(status)) {
1104 return false;
1108 return true;
1111 static bool wkssvc_init_cb(void *ptr)
1113 struct dcesrv_ep_context *ep_ctx =
1114 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
1115 struct ndr_syntax_id abstract_syntax = ndr_table_wkssvc.syntax_id;
1116 const char *pipe_name = "wkssvc";
1117 const char *rpcsrv_type;
1118 uint16_t port;
1120 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
1121 "rpc_server",
1122 "epmapper",
1123 "none");
1124 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
1125 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
1126 NTSTATUS status;
1127 bool ok;
1129 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
1130 ep_ctx->msg_ctx,
1131 abstract_syntax,
1132 pipe_name);
1133 if (!ok) {
1134 return false;
1137 port = _open_sockets(ep_ctx->ev_ctx,
1138 ep_ctx->msg_ctx,
1139 abstract_syntax,
1141 if (port == 0) {
1142 return false;
1145 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
1146 ep_ctx->msg_ctx,
1147 &ndr_table_wkssvc,
1148 "wkssvc",
1149 port);
1150 if (!NT_STATUS_IS_OK(status)) {
1151 return false;
1155 return true;
1158 static bool wkssvc_shutdown_cb(void *ptr) {
1159 return NT_STATUS_IS_OK(_rpc_ep_unregister(&ndr_table_wkssvc));
1162 bool dcesrv_ep_setup(struct tevent_context *ev_ctx,
1163 struct messaging_context *msg_ctx)
1165 struct dcesrv_ep_context *ep_ctx;
1167 struct rpc_srv_callbacks epmapper_cb;
1169 struct rpc_srv_callbacks winreg_cb;
1170 struct rpc_srv_callbacks srvsvc_cb;
1172 struct rpc_srv_callbacks lsarpc_cb;
1173 struct rpc_srv_callbacks samr_cb;
1174 struct rpc_srv_callbacks netlogon_cb;
1176 struct rpc_srv_callbacks spoolss_cb;
1177 struct rpc_srv_callbacks svcctl_cb;
1178 struct rpc_srv_callbacks ntsvcs_cb;
1179 struct rpc_srv_callbacks eventlog_cb;
1180 struct rpc_srv_callbacks initshutdown_cb;
1181 struct rpc_srv_callbacks netdfs_cb;
1182 #ifdef DEVELOPER
1183 struct rpc_srv_callbacks rpcecho_cb;
1184 #endif
1185 struct rpc_srv_callbacks dssetup_cb;
1186 struct rpc_srv_callbacks wkssvc_cb;
1188 const char *rpcsrv_type;
1190 ep_ctx = talloc(ev_ctx, struct dcesrv_ep_context);
1191 if (ep_ctx == NULL) {
1192 return false;
1195 ep_ctx->ev_ctx = ev_ctx;
1196 ep_ctx->msg_ctx = msg_ctx;
1198 /* start endpoint mapper only if enabled */
1199 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
1200 "rpc_server",
1201 "epmapper",
1202 "none");
1203 if (StrCaseCmp(rpcsrv_type, "embedded") == 0) {
1204 epmapper_cb.init = epmapper_init_cb;
1205 epmapper_cb.shutdown = NULL;
1206 epmapper_cb.private_data = ep_ctx;
1208 if (!NT_STATUS_IS_OK(rpc_epmapper_init(&epmapper_cb))) {
1209 return false;
1213 winreg_cb.init = winreg_init_cb;
1214 winreg_cb.shutdown = winreg_shutdown_cb;
1215 winreg_cb.private_data = ep_ctx;
1216 if (!NT_STATUS_IS_OK(rpc_winreg_init(&winreg_cb))) {
1217 return false;
1220 srvsvc_cb.init = srvsvc_init_cb;
1221 srvsvc_cb.shutdown = srvsvc_shutdown_cb;
1222 srvsvc_cb.private_data = ep_ctx;
1223 if (!NT_STATUS_IS_OK(rpc_srvsvc_init(&srvsvc_cb))) {
1224 return false;
1228 lsarpc_cb.init = lsarpc_init_cb;
1229 lsarpc_cb.shutdown = lsarpc_shutdown_cb;
1230 lsarpc_cb.private_data = ep_ctx;
1231 if (!NT_STATUS_IS_OK(rpc_lsarpc_init(&lsarpc_cb))) {
1232 return false;
1235 samr_cb.init = samr_init_cb;
1236 samr_cb.shutdown = samr_shutdown_cb;
1237 samr_cb.private_data = ep_ctx;
1238 if (!NT_STATUS_IS_OK(rpc_samr_init(&samr_cb))) {
1239 return false;
1242 netlogon_cb.init = netlogon_init_cb;
1243 netlogon_cb.shutdown = netlogon_shutdown_cb;
1244 netlogon_cb.private_data = ep_ctx;
1245 if (!NT_STATUS_IS_OK(rpc_netlogon_init(&netlogon_cb))) {
1246 return false;
1249 spoolss_cb.init = spoolss_init_cb;
1250 spoolss_cb.shutdown = spoolss_shutdown_cb;
1251 spoolss_cb.private_data = ep_ctx;
1252 if (!NT_STATUS_IS_OK(rpc_spoolss_init(&spoolss_cb))) {
1253 return false;
1257 svcctl_cb.init = svcctl_init_cb;
1258 svcctl_cb.shutdown = svcctl_shutdown_cb;
1259 svcctl_cb.private_data = ep_ctx;
1260 if (!NT_STATUS_IS_OK(rpc_svcctl_init(&svcctl_cb))) {
1261 return false;
1264 ntsvcs_cb.init = ntsvcs_init_cb;
1265 ntsvcs_cb.shutdown = ntsvcs_shutdown_cb;
1266 ntsvcs_cb.private_data = ep_ctx;
1267 if (!NT_STATUS_IS_OK(rpc_ntsvcs_init(&ntsvcs_cb))) {
1268 return false;
1271 eventlog_cb.init = eventlog_init_cb;
1272 eventlog_cb.shutdown = eventlog_shutdown_cb;
1273 eventlog_cb.private_data = ep_ctx;
1274 if (!NT_STATUS_IS_OK(rpc_eventlog_init(&eventlog_cb))) {
1275 return false;
1278 initshutdown_cb.init = initshutdown_init_cb;
1279 initshutdown_cb.shutdown = initshutdown_shutdown_cb;
1280 initshutdown_cb.private_data = ep_ctx;
1281 if (!NT_STATUS_IS_OK(rpc_initshutdown_init(&initshutdown_cb))) {
1282 return false;
1285 netdfs_cb.init = netdfs_init_cb;
1286 netdfs_cb.shutdown = netdfs_shutdown_cb;
1287 netdfs_cb.private_data = ep_ctx;
1288 if (!NT_STATUS_IS_OK(rpc_netdfs_init(&netdfs_cb))) {
1289 return false;
1291 #ifdef DEVELOPER
1293 rpcecho_cb.init = rpcecho_init_cb;
1294 rpcecho_cb.shutdown = rpcecho_shutdown_cb;
1295 rpcecho_cb.private_data = ep_ctx;
1296 if (!NT_STATUS_IS_OK(rpc_rpcecho_init(&rpcecho_cb))) {
1297 return false;
1299 #endif
1301 dssetup_cb.init = dssetup_init_cb;
1302 dssetup_cb.shutdown = dssetup_shutdown_cb;
1303 dssetup_cb.private_data = ep_ctx;
1304 if (!NT_STATUS_IS_OK(rpc_dssetup_init(&dssetup_cb))) {
1305 return false;
1308 wkssvc_cb.init = wkssvc_init_cb;
1309 wkssvc_cb.shutdown = wkssvc_shutdown_cb;
1310 wkssvc_cb.private_data = ep_ctx;
1311 if (!NT_STATUS_IS_OK(rpc_wkssvc_init(&wkssvc_cb))) {
1312 return false;
1315 return true;
1318 /* vim: set ts=8 sw=8 noet cindent ft=c.doxygen: */