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/>.
24 #include "../librpc/gen_ndr/ndr_epmapper_c.h"
25 #include "../librpc/gen_ndr/srv_epmapper.h"
26 #include "../librpc/gen_ndr/srv_srvsvc.h"
27 #include "../librpc/gen_ndr/srv_winreg.h"
28 #include "../librpc/gen_ndr/srv_dfs.h"
29 #include "../librpc/gen_ndr/srv_dssetup.h"
30 #include "../librpc/gen_ndr/srv_echo.h"
31 #include "../librpc/gen_ndr/srv_eventlog.h"
32 #include "../librpc/gen_ndr/srv_initshutdown.h"
33 #include "../librpc/gen_ndr/srv_lsa.h"
34 #include "../librpc/gen_ndr/srv_netlogon.h"
35 #include "../librpc/gen_ndr/srv_ntsvcs.h"
36 #include "../librpc/gen_ndr/srv_samr.h"
37 #include "../librpc/gen_ndr/srv_spoolss.h"
38 #include "../librpc/gen_ndr/srv_svcctl.h"
39 #include "../librpc/gen_ndr/srv_wkssvc.h"
41 #include "printing/nt_printing_migrate.h"
42 #include "rpc_server/eventlog/srv_eventlog_reg.h"
43 #include "rpc_server/svcctl/srv_svcctl_reg.h"
45 #include "librpc/rpc/dcerpc_ep.h"
47 #include "rpc_server/rpc_ep_setup.h"
48 #include "rpc_server/rpc_server.h"
49 #include "rpc_server/epmapper/srv_epmapper.h"
51 struct dcesrv_ep_context {
52 struct tevent_context *ev_ctx;
53 struct messaging_context *msg_ctx;
56 static uint16_t _open_sockets(struct tevent_context *ev_ctx,
57 struct messaging_context *msg_ctx,
58 struct ndr_syntax_id syntax_id,
61 uint32_t num_ifs = iface_count();
65 if (lp_interfaces() && lp_bind_interfaces_only()) {
67 * We have been given an interfaces line, and been told to only
68 * bind to those interfaces. Create a socket per interface and
72 /* Now open a listen socket for each of the interfaces. */
73 for(i = 0; i < num_ifs; i++) {
74 const struct sockaddr_storage *ifss =
75 iface_n_sockaddr_storage(i);
77 p = setup_dcerpc_ncacn_tcpip_socket(ev_ctx,
88 const char *sock_addr = lp_socket_address();
92 if (strequal(sock_addr, "0.0.0.0") ||
93 strequal(sock_addr, "::")) {
97 sock_addr = "0.0.0.0";
101 for (sock_ptr = sock_addr;
102 next_token_talloc(talloc_tos(), &sock_ptr, &sock_tok, " \t,");
104 struct sockaddr_storage ss;
106 /* open an incoming socket */
107 if (!interpret_string_addr(&ss,
109 AI_NUMERICHOST|AI_PASSIVE)) {
113 p = setup_dcerpc_ncacn_tcpip_socket(ev_ctx,
128 static NTSTATUS _rpc_ep_unregister(const struct ndr_interface_table *iface)
130 struct dcerpc_binding_vector *v = NULL;
133 status = dcerpc_binding_vector_create(talloc_tos(),
138 if (!NT_STATUS_IS_OK(status)) {
142 status = dcerpc_ep_unregister(iface,
144 &iface->syntax_id.uuid);
145 if (!NT_STATUS_IS_OK(status)) {
152 static void rpc_ep_setup_register_loop(struct tevent_req *subreq);
153 static NTSTATUS rpc_ep_setup_try_register(TALLOC_CTX *mem_ctx,
154 struct tevent_context *ev_ctx,
155 struct messaging_context *msg_ctx,
156 const struct ndr_interface_table *iface,
159 struct dcerpc_binding_handle **pbh);
161 struct rpc_ep_regsiter_state {
162 struct dcerpc_binding_handle *h;
165 struct tevent_context *ev_ctx;
166 struct messaging_context *msg_ctx;
168 const struct ndr_interface_table *iface;
176 static NTSTATUS rpc_ep_setup_register(struct tevent_context *ev_ctx,
177 struct messaging_context *msg_ctx,
178 const struct ndr_interface_table *iface,
182 struct rpc_ep_regsiter_state *state;
183 struct tevent_req *req;
185 state = talloc(ev_ctx, struct rpc_ep_regsiter_state);
187 return NT_STATUS_NO_MEMORY;
190 state->mem_ctx = talloc_named(state,
194 if (state->mem_ctx == NULL) {
196 return NT_STATUS_NO_MEMORY;
199 state->wait_time = 1;
200 state->ev_ctx = ev_ctx;
201 state->msg_ctx = msg_ctx;
202 state->iface = iface;
203 state->ncalrpc = talloc_strdup(state, ncalrpc);
206 req = tevent_wakeup_send(state->mem_ctx,
208 timeval_current_ofs(1, 0));
209 if (tevent_req_nomem(state->mem_ctx, req)) {
211 return NT_STATUS_NO_MEMORY;
214 tevent_req_set_callback(req, rpc_ep_setup_register_loop, state);
219 #define MONITOR_WAIT_TIME 15
220 static void rpc_ep_setup_monitor_loop(struct tevent_req *subreq);
222 static void rpc_ep_setup_register_loop(struct tevent_req *subreq)
224 struct rpc_ep_regsiter_state *state =
225 tevent_req_callback_data(subreq, struct rpc_ep_regsiter_state);
229 ok = tevent_wakeup_recv(subreq);
236 status = rpc_ep_setup_try_register(state->mem_ctx,
243 if (NT_STATUS_IS_OK(status)) {
244 /* endpoint registered, monitor the connnection. */
245 subreq = tevent_wakeup_send(state->mem_ctx,
247 timeval_current_ofs(MONITOR_WAIT_TIME, 0));
248 if (tevent_req_nomem(state->mem_ctx, subreq)) {
253 tevent_req_set_callback(subreq, rpc_ep_setup_monitor_loop, state);
257 state->wait_time = state->wait_time * 2;
258 if (state->wait_time > 16) {
263 subreq = tevent_wakeup_send(state->mem_ctx,
265 timeval_current_ofs(state->wait_time, 0));
266 if (tevent_req_nomem(state->mem_ctx, subreq)) {
271 tevent_req_set_callback(subreq, rpc_ep_setup_register_loop, state);
275 static NTSTATUS rpc_ep_setup_try_register(TALLOC_CTX *mem_ctx,
276 struct tevent_context *ev_ctx,
277 struct messaging_context *msg_ctx,
278 const struct ndr_interface_table *iface,
281 struct dcerpc_binding_handle **pbh)
283 struct dcerpc_binding_vector *v = NULL;
286 status = dcerpc_binding_vector_create(mem_ctx,
291 if (!NT_STATUS_IS_OK(status)) {
295 status = dcerpc_ep_register(mem_ctx,
298 &iface->syntax_id.uuid,
302 if (!NT_STATUS_IS_OK(status)) {
310 * Monitor the connection to the endpoint mapper and if it goes away, try to
311 * register the endpoint.
313 static void rpc_ep_setup_monitor_loop(struct tevent_req *subreq)
315 struct rpc_ep_regsiter_state *state =
316 tevent_req_callback_data(subreq, struct rpc_ep_regsiter_state);
317 struct policy_handle entry_handle;
318 struct dcerpc_binding map_binding;
319 struct epm_twr_p_t towers[10];
320 struct epm_twr_t *map_tower;
321 uint32_t num_towers = 0;
324 uint32_t result = EPMAPPER_STATUS_CANT_PERFORM_OP;
329 ZERO_STRUCT(entry_handle);
331 tmp_ctx = talloc_stackframe();
332 if (tmp_ctx == NULL) {
337 ok = tevent_wakeup_recv(subreq);
344 /* Create map tower */
345 map_binding.transport = NCACN_NP;
346 map_binding.object = state->iface->syntax_id;
347 map_binding.host = "";
348 map_binding.endpoint = "";
350 map_tower = talloc_zero(tmp_ctx, struct epm_twr_t);
351 if (map_tower == NULL) {
352 talloc_free(tmp_ctx);
357 status = dcerpc_binding_build_tower(map_tower, &map_binding,
359 if (!NT_STATUS_IS_OK(status)) {
360 talloc_free(tmp_ctx);
366 status = dcerpc_epm_Map(state->h,
375 if (NT_STATUS_IS_OK(status)) {
378 if (result == EPMAPPER_STATUS_OK ||
379 result == EPMAPPER_STATUS_NO_MORE_ENTRIES) {
382 if (num_towers == 0) {
386 talloc_free(tmp_ctx);
388 subreq = tevent_wakeup_send(state->mem_ctx,
390 timeval_current_ofs(MONITOR_WAIT_TIME, 0));
391 if (tevent_req_nomem(state->mem_ctx, subreq)) {
397 tevent_req_set_callback(subreq, rpc_ep_setup_monitor_loop, state);
399 TALLOC_FREE(state->h);
400 state->wait_time = 1;
402 tevent_req_set_callback(subreq, rpc_ep_setup_register_loop, state);
408 static bool epmapper_init_cb(void *ptr)
410 struct dcesrv_ep_context *ep_ctx =
411 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
414 port = _open_sockets(ep_ctx->ev_ctx,
416 ndr_table_epmapper.syntax_id,
425 static bool epmapper_shutdown_cb(void *ptr)
427 srv_epmapper_cleanup();
432 static bool winreg_init_cb(void *ptr)
434 struct dcesrv_ep_context *ep_ctx =
435 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
436 struct ndr_syntax_id abstract_syntax = ndr_table_winreg.syntax_id;
437 const char *pipe_name = "winreg";
438 const char *rpcsrv_type;
441 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
446 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
447 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
451 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
458 port = _open_sockets(ep_ctx->ev_ctx,
466 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
471 if (!NT_STATUS_IS_OK(status)) {
479 static bool winreg_shutdown_cb(void *ptr)
481 const char *rpcsrv_type;
483 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
488 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
489 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
492 status = _rpc_ep_unregister(&ndr_table_winreg);
493 if (!NT_STATUS_IS_OK(status)) {
501 static bool srvsvc_init_cb(void *ptr)
503 struct dcesrv_ep_context *ep_ctx =
504 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
505 struct ndr_syntax_id abstract_syntax = ndr_table_srvsvc.syntax_id;
506 const char *pipe_name = "srvsvc";
507 const char *rpcsrv_type;
510 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
515 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
516 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
520 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
528 port = _open_sockets(ep_ctx->ev_ctx,
536 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
541 if (!NT_STATUS_IS_OK(status)) {
549 static bool srvsvc_shutdown_cb(void *ptr)
551 const char *rpcsrv_type;
553 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
558 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
559 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
562 status =_rpc_ep_unregister(&ndr_table_srvsvc);
563 if (!NT_STATUS_IS_OK(status)) {
571 static bool lsarpc_init_cb(void *ptr)
573 struct dcesrv_ep_context *ep_ctx =
574 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
575 struct ndr_syntax_id abstract_syntax = ndr_table_lsarpc.syntax_id;
576 const char *pipe_name = "lsarpc";
577 const char *rpcsrv_type;
580 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
585 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
586 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
590 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
598 port = _open_sockets(ep_ctx->ev_ctx,
606 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
611 if (!NT_STATUS_IS_OK(status)) {
619 static bool lsarpc_shutdown_cb(void *ptr)
621 const char *rpcsrv_type;
623 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
628 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
629 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
632 status = _rpc_ep_unregister(&ndr_table_lsarpc);
633 if (!NT_STATUS_IS_OK(status)) {
641 static bool samr_init_cb(void *ptr)
643 struct dcesrv_ep_context *ep_ctx =
644 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
645 struct ndr_syntax_id abstract_syntax = ndr_table_samr.syntax_id;
646 const char *pipe_name = "samr";
647 const char *rpcsrv_type;
650 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
655 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
656 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
660 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
668 port = _open_sockets(ep_ctx->ev_ctx,
676 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
681 if (!NT_STATUS_IS_OK(status)) {
689 static bool samr_shutdown_cb(void *ptr)
691 const char *rpcsrv_type;
693 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
698 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
699 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
702 status = _rpc_ep_unregister(&ndr_table_samr);
703 if (!NT_STATUS_IS_OK(status)) {
711 static bool netlogon_init_cb(void *ptr)
713 struct dcesrv_ep_context *ep_ctx =
714 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
715 struct ndr_syntax_id abstract_syntax = ndr_table_netlogon.syntax_id;
716 const char *pipe_name = "netlogon";
717 const char *rpcsrv_type;
720 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
725 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
726 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
730 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
738 port = _open_sockets(ep_ctx->ev_ctx,
746 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
751 if (!NT_STATUS_IS_OK(status)) {
759 static bool netlogon_shutdown_cb(void *ptr)
761 const char *rpcsrv_type;
763 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
768 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
769 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
772 status = _rpc_ep_unregister(&ndr_table_netlogon);
773 if (!NT_STATUS_IS_OK(status)) {
781 static bool spoolss_init_cb(void *ptr)
783 struct dcesrv_ep_context *ep_ctx =
784 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
785 const char *rpcsrv_type;
788 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
794 * Migrate the printers first.
796 ok = nt_printing_tdb_migrate(ep_ctx->msg_ctx);
801 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
802 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
805 status =rpc_ep_setup_register(ep_ctx->ev_ctx,
810 if (!NT_STATUS_IS_OK(status)) {
818 static bool spoolss_shutdown_cb(void *ptr)
820 const char *rpcsrv_type;
822 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
827 srv_spoolss_cleanup();
829 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
830 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
833 status = _rpc_ep_unregister(&ndr_table_spoolss);
834 if (!NT_STATUS_IS_OK(status)) {
842 static bool svcctl_init_cb(void *ptr)
844 struct dcesrv_ep_context *ep_ctx =
845 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
846 const char *rpcsrv_type;
849 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
854 ok = svcctl_init_winreg(ep_ctx->msg_ctx);
859 /* initialize the control hooks */
860 init_service_op_table();
862 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
863 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
866 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
871 if (!NT_STATUS_IS_OK(status)) {
879 static bool svcctl_shutdown_cb(void *ptr)
881 const char *rpcsrv_type;
883 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
887 shutdown_service_op_table();
889 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
890 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
893 status = _rpc_ep_unregister(&ndr_table_svcctl);
894 if (!NT_STATUS_IS_OK(status)) {
902 static bool ntsvcs_init_cb(void *ptr)
904 struct dcesrv_ep_context *ep_ctx =
905 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
906 const char *rpcsrv_type;
908 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
913 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
914 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
917 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
922 if (!NT_STATUS_IS_OK(status)) {
930 static bool ntsvcs_shutdown_cb(void *ptr)
932 const char *rpcsrv_type;
934 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
939 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
940 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
943 status = _rpc_ep_unregister(&ndr_table_ntsvcs);
944 if (!NT_STATUS_IS_OK(status)) {
952 static bool eventlog_init_cb(void *ptr)
954 struct dcesrv_ep_context *ep_ctx =
955 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
956 const char *rpcsrv_type;
959 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
964 ok = eventlog_init_winreg(ep_ctx->msg_ctx);
969 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
970 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
973 status =rpc_ep_setup_register(ep_ctx->ev_ctx,
978 if (!NT_STATUS_IS_OK(status)) {
986 static bool eventlog_shutdown_cb(void *ptr)
988 const char *rpcsrv_type;
990 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
995 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
996 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
999 status = _rpc_ep_unregister(&ndr_table_eventlog);
1000 if (!NT_STATUS_IS_OK(status)) {
1008 static bool initshutdown_init_cb(void *ptr)
1010 struct dcesrv_ep_context *ep_ctx =
1011 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
1012 const char *rpcsrv_type;
1014 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
1019 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
1020 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
1023 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
1025 &ndr_table_initshutdown,
1028 if (!NT_STATUS_IS_OK(status)) {
1036 static bool initshutdown_shutdown_cb(void *ptr)
1038 const char *rpcsrv_type;
1040 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
1045 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
1046 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
1049 status = _rpc_ep_unregister(&ndr_table_initshutdown);
1050 if (!NT_STATUS_IS_OK(status)) {
1059 static bool rpcecho_init_cb(void *ptr) {
1060 struct dcesrv_ep_context *ep_ctx =
1061 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
1062 const char *rpcsrv_type;
1065 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
1070 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
1071 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
1074 port = _open_sockets(ep_ctx->ev_ctx,
1076 ndr_table_rpcecho.syntax_id,
1082 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
1087 if (!NT_STATUS_IS_OK(status)) {
1095 static bool rpcecho_shutdown_cb(void *ptr)
1097 const char *rpcsrv_type;
1099 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
1104 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
1105 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
1108 status = _rpc_ep_unregister(&ndr_table_rpcecho);
1109 if (!NT_STATUS_IS_OK(status)) {
1118 static bool netdfs_init_cb(void *ptr)
1120 struct dcesrv_ep_context *ep_ctx =
1121 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
1122 struct ndr_syntax_id abstract_syntax = ndr_table_netdfs.syntax_id;
1123 const char *pipe_name = "netdfs";
1124 const char *rpcsrv_type;
1127 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
1131 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
1132 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
1136 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
1144 port = _open_sockets(ep_ctx->ev_ctx,
1152 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
1157 if (!NT_STATUS_IS_OK(status)) {
1165 static bool netdfs_shutdown_cb(void *ptr) {
1166 const char *rpcsrv_type;
1168 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
1173 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
1174 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
1177 status = _rpc_ep_unregister(&ndr_table_netdfs);
1178 if (!NT_STATUS_IS_OK(status)) {
1186 static bool dssetup_init_cb(void *ptr)
1188 struct dcesrv_ep_context *ep_ctx =
1189 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
1190 struct ndr_syntax_id abstract_syntax = ndr_table_dssetup.syntax_id;
1191 const char *pipe_name = "dssetup";
1192 const char *rpcsrv_type;
1195 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
1200 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
1201 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
1205 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
1213 port = _open_sockets(ep_ctx->ev_ctx,
1221 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
1226 if (!NT_STATUS_IS_OK(status)) {
1234 static bool dssetup_shutdown_cb(void *ptr) {
1235 const char *rpcsrv_type;
1237 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
1242 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
1243 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
1246 status = _rpc_ep_unregister(&ndr_table_dssetup);
1247 if (!NT_STATUS_IS_OK(status)) {
1255 static bool wkssvc_init_cb(void *ptr)
1257 struct dcesrv_ep_context *ep_ctx =
1258 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
1259 struct ndr_syntax_id abstract_syntax = ndr_table_wkssvc.syntax_id;
1260 const char *pipe_name = "wkssvc";
1261 const char *rpcsrv_type;
1264 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
1268 if (StrCaseCmp(rpcsrv_type, "embedded") == 0 ||
1269 StrCaseCmp(rpcsrv_type, "daemon") == 0) {
1273 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
1281 port = _open_sockets(ep_ctx->ev_ctx,
1289 status = rpc_ep_setup_register(ep_ctx->ev_ctx,
1294 if (!NT_STATUS_IS_OK(status)) {
1302 static bool wkssvc_shutdown_cb(void *ptr) {
1303 return NT_STATUS_IS_OK(_rpc_ep_unregister(&ndr_table_wkssvc));
1306 bool dcesrv_ep_setup(struct tevent_context *ev_ctx,
1307 struct messaging_context *msg_ctx)
1309 struct dcesrv_ep_context *ep_ctx;
1311 struct rpc_srv_callbacks epmapper_cb;
1313 struct rpc_srv_callbacks winreg_cb;
1314 struct rpc_srv_callbacks srvsvc_cb;
1316 struct rpc_srv_callbacks lsarpc_cb;
1317 struct rpc_srv_callbacks samr_cb;
1318 struct rpc_srv_callbacks netlogon_cb;
1320 struct rpc_srv_callbacks spoolss_cb;
1321 struct rpc_srv_callbacks svcctl_cb;
1322 struct rpc_srv_callbacks ntsvcs_cb;
1323 struct rpc_srv_callbacks eventlog_cb;
1324 struct rpc_srv_callbacks initshutdown_cb;
1325 struct rpc_srv_callbacks netdfs_cb;
1327 struct rpc_srv_callbacks rpcecho_cb;
1329 struct rpc_srv_callbacks dssetup_cb;
1330 struct rpc_srv_callbacks wkssvc_cb;
1332 const char *rpcsrv_type;
1334 ep_ctx = talloc(ev_ctx, struct dcesrv_ep_context);
1335 if (ep_ctx == NULL) {
1339 ep_ctx->ev_ctx = ev_ctx;
1340 ep_ctx->msg_ctx = msg_ctx;
1342 /* start endpoint mapper only if enabled */
1343 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
1347 if (StrCaseCmp(rpcsrv_type, "embedded") == 0) {
1348 epmapper_cb.init = epmapper_init_cb;
1349 epmapper_cb.shutdown = epmapper_shutdown_cb;
1350 epmapper_cb.private_data = ep_ctx;
1352 if (!NT_STATUS_IS_OK(rpc_epmapper_init(&epmapper_cb))) {
1357 winreg_cb.init = winreg_init_cb;
1358 winreg_cb.shutdown = winreg_shutdown_cb;
1359 winreg_cb.private_data = ep_ctx;
1360 if (!NT_STATUS_IS_OK(rpc_winreg_init(&winreg_cb))) {
1364 srvsvc_cb.init = srvsvc_init_cb;
1365 srvsvc_cb.shutdown = srvsvc_shutdown_cb;
1366 srvsvc_cb.private_data = ep_ctx;
1367 if (!NT_STATUS_IS_OK(rpc_srvsvc_init(&srvsvc_cb))) {
1372 lsarpc_cb.init = lsarpc_init_cb;
1373 lsarpc_cb.shutdown = lsarpc_shutdown_cb;
1374 lsarpc_cb.private_data = ep_ctx;
1375 if (!NT_STATUS_IS_OK(rpc_lsarpc_init(&lsarpc_cb))) {
1379 samr_cb.init = samr_init_cb;
1380 samr_cb.shutdown = samr_shutdown_cb;
1381 samr_cb.private_data = ep_ctx;
1382 if (!NT_STATUS_IS_OK(rpc_samr_init(&samr_cb))) {
1386 netlogon_cb.init = netlogon_init_cb;
1387 netlogon_cb.shutdown = netlogon_shutdown_cb;
1388 netlogon_cb.private_data = ep_ctx;
1389 if (!NT_STATUS_IS_OK(rpc_netlogon_init(&netlogon_cb))) {
1393 spoolss_cb.init = spoolss_init_cb;
1394 spoolss_cb.shutdown = spoolss_shutdown_cb;
1395 spoolss_cb.private_data = ep_ctx;
1396 if (!NT_STATUS_IS_OK(rpc_spoolss_init(&spoolss_cb))) {
1401 svcctl_cb.init = svcctl_init_cb;
1402 svcctl_cb.shutdown = svcctl_shutdown_cb;
1403 svcctl_cb.private_data = ep_ctx;
1404 if (!NT_STATUS_IS_OK(rpc_svcctl_init(&svcctl_cb))) {
1408 ntsvcs_cb.init = ntsvcs_init_cb;
1409 ntsvcs_cb.shutdown = ntsvcs_shutdown_cb;
1410 ntsvcs_cb.private_data = ep_ctx;
1411 if (!NT_STATUS_IS_OK(rpc_ntsvcs_init(&ntsvcs_cb))) {
1415 eventlog_cb.init = eventlog_init_cb;
1416 eventlog_cb.shutdown = eventlog_shutdown_cb;
1417 eventlog_cb.private_data = ep_ctx;
1418 if (!NT_STATUS_IS_OK(rpc_eventlog_init(&eventlog_cb))) {
1422 initshutdown_cb.init = initshutdown_init_cb;
1423 initshutdown_cb.shutdown = initshutdown_shutdown_cb;
1424 initshutdown_cb.private_data = ep_ctx;
1425 if (!NT_STATUS_IS_OK(rpc_initshutdown_init(&initshutdown_cb))) {
1429 netdfs_cb.init = netdfs_init_cb;
1430 netdfs_cb.shutdown = netdfs_shutdown_cb;
1431 netdfs_cb.private_data = ep_ctx;
1432 if (!NT_STATUS_IS_OK(rpc_netdfs_init(&netdfs_cb))) {
1437 rpcecho_cb.init = rpcecho_init_cb;
1438 rpcecho_cb.shutdown = rpcecho_shutdown_cb;
1439 rpcecho_cb.private_data = ep_ctx;
1440 if (!NT_STATUS_IS_OK(rpc_rpcecho_init(&rpcecho_cb))) {
1445 dssetup_cb.init = dssetup_init_cb;
1446 dssetup_cb.shutdown = dssetup_shutdown_cb;
1447 dssetup_cb.private_data = ep_ctx;
1448 if (!NT_STATUS_IS_OK(rpc_dssetup_init(&dssetup_cb))) {
1452 wkssvc_cb.init = wkssvc_init_cb;
1453 wkssvc_cb.shutdown = wkssvc_shutdown_cb;
1454 wkssvc_cb.private_data = ep_ctx;
1455 if (!NT_STATUS_IS_OK(rpc_wkssvc_init(&wkssvc_cb))) {
1462 /* vim: set ts=8 sw=8 noet cindent ft=c.doxygen: */