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/>.
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 "rpc_server/rpc_ep_setup.h"
49 #include "rpc_server/rpc_ep_register.h"
50 #include "rpc_server/rpc_server.h"
51 #include "rpc_server/epmapper/srv_epmapper.h"
53 struct dcesrv_ep_context {
54 struct tevent_context *ev_ctx;
55 struct messaging_context *msg_ctx;
58 static uint16_t _open_sockets(struct tevent_context *ev_ctx,
59 struct messaging_context *msg_ctx,
60 struct ndr_syntax_id syntax_id,
63 uint32_t num_ifs = iface_count();
67 if (lp_interfaces() && lp_bind_interfaces_only()) {
69 * We have been given an interfaces line, and been told to only
70 * bind to those interfaces. Create a socket per interface and
74 /* Now open a listen socket for each of the interfaces. */
75 for(i = 0; i < num_ifs; i++) {
76 const struct sockaddr_storage *ifss =
77 iface_n_sockaddr_storage(i);
79 p = setup_dcerpc_ncacn_tcpip_socket(ev_ctx,
89 const char *sock_addr = lp_socket_address();
93 if (strequal(sock_addr, "0.0.0.0") ||
94 strequal(sock_addr, "::")) {
96 sock_addr = "::,0.0.0.0";
98 sock_addr = "0.0.0.0";
102 for (sock_ptr = sock_addr;
103 next_token_talloc(talloc_tos(), &sock_ptr, &sock_tok, " \t,");
105 struct sockaddr_storage ss;
107 /* open an incoming socket */
108 if (!interpret_string_addr(&ss,
110 AI_NUMERICHOST|AI_PASSIVE)) {
114 p = setup_dcerpc_ncacn_tcpip_socket(ev_ctx,
128 static bool epmapper_init_cb(void *ptr)
130 struct dcesrv_ep_context *ep_ctx =
131 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
134 port = _open_sockets(ep_ctx->ev_ctx,
136 ndr_table_epmapper.syntax_id,
145 static bool epmapper_shutdown_cb(void *ptr)
147 srv_epmapper_cleanup();
152 static bool winreg_init_cb(void *ptr)
154 struct dcesrv_ep_context *ep_ctx =
155 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
156 struct ndr_syntax_id abstract_syntax = ndr_table_winreg.syntax_id;
157 const char *pipe_name = "winreg";
158 const char *rpcsrv_type;
161 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
166 if (strcasecmp_m(rpcsrv_type, "embedded") == 0 ||
167 strcasecmp_m(rpcsrv_type, "daemon") == 0) {
171 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
178 port = _open_sockets(ep_ctx->ev_ctx,
186 status = rpc_ep_register(ep_ctx->ev_ctx,
191 if (!NT_STATUS_IS_OK(status)) {
199 static bool srvsvc_init_cb(void *ptr)
201 struct dcesrv_ep_context *ep_ctx =
202 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
203 struct ndr_syntax_id abstract_syntax = ndr_table_srvsvc.syntax_id;
204 const char *pipe_name = "srvsvc";
205 const char *rpcsrv_type;
208 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
213 if (strcasecmp_m(rpcsrv_type, "embedded") == 0 ||
214 strcasecmp_m(rpcsrv_type, "daemon") == 0) {
218 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
226 port = _open_sockets(ep_ctx->ev_ctx,
234 status = rpc_ep_register(ep_ctx->ev_ctx,
239 if (!NT_STATUS_IS_OK(status)) {
247 static bool lsarpc_init_cb(void *ptr)
249 struct dcesrv_ep_context *ep_ctx =
250 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
251 struct ndr_syntax_id abstract_syntax = ndr_table_lsarpc.syntax_id;
252 const char *pipe_name = "lsarpc";
253 const char *rpcsrv_type;
256 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
261 if (strcasecmp_m(rpcsrv_type, "embedded") == 0 ||
262 strcasecmp_m(rpcsrv_type, "daemon") == 0) {
266 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
274 port = _open_sockets(ep_ctx->ev_ctx,
282 status = rpc_ep_register(ep_ctx->ev_ctx,
287 if (!NT_STATUS_IS_OK(status)) {
295 static bool samr_init_cb(void *ptr)
297 struct dcesrv_ep_context *ep_ctx =
298 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
299 struct ndr_syntax_id abstract_syntax = ndr_table_samr.syntax_id;
300 const char *pipe_name = "samr";
301 const char *rpcsrv_type;
304 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
309 if (strcasecmp_m(rpcsrv_type, "embedded") == 0 ||
310 strcasecmp_m(rpcsrv_type, "daemon") == 0) {
314 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
322 port = _open_sockets(ep_ctx->ev_ctx,
330 status = rpc_ep_register(ep_ctx->ev_ctx,
335 if (!NT_STATUS_IS_OK(status)) {
343 static bool netlogon_init_cb(void *ptr)
345 struct dcesrv_ep_context *ep_ctx =
346 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
347 struct ndr_syntax_id abstract_syntax = ndr_table_netlogon.syntax_id;
348 const char *pipe_name = "netlogon";
349 const char *rpcsrv_type;
352 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
357 if (strcasecmp_m(rpcsrv_type, "embedded") == 0 ||
358 strcasecmp_m(rpcsrv_type, "daemon") == 0) {
362 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
370 port = _open_sockets(ep_ctx->ev_ctx,
378 status = rpc_ep_register(ep_ctx->ev_ctx,
383 if (!NT_STATUS_IS_OK(status)) {
391 static bool spoolss_init_cb(void *ptr)
393 struct dcesrv_ep_context *ep_ctx =
394 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
395 const char *rpcsrv_type;
398 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
404 * Migrate the printers first.
406 ok = nt_printing_tdb_migrate(ep_ctx->msg_ctx);
411 if (strcasecmp_m(rpcsrv_type, "embedded") == 0 ||
412 strcasecmp_m(rpcsrv_type, "daemon") == 0) {
415 status = rpc_ep_register(ep_ctx->ev_ctx,
420 if (!NT_STATUS_IS_OK(status)) {
428 static bool spoolss_shutdown_cb(void *ptr)
430 srv_spoolss_cleanup();
435 static bool svcctl_init_cb(void *ptr)
437 struct dcesrv_ep_context *ep_ctx =
438 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
439 const char *rpcsrv_type;
442 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
447 ok = svcctl_init_winreg(ep_ctx->msg_ctx);
452 /* initialize the control hooks */
453 init_service_op_table();
455 if (strcasecmp_m(rpcsrv_type, "embedded") == 0 ||
456 strcasecmp_m(rpcsrv_type, "daemon") == 0) {
459 status = rpc_ep_register(ep_ctx->ev_ctx,
464 if (!NT_STATUS_IS_OK(status)) {
472 static bool svcctl_shutdown_cb(void *ptr)
474 shutdown_service_op_table();
479 static bool ntsvcs_init_cb(void *ptr)
481 struct dcesrv_ep_context *ep_ctx =
482 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
483 const char *rpcsrv_type;
485 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
490 if (strcasecmp_m(rpcsrv_type, "embedded") == 0 ||
491 strcasecmp_m(rpcsrv_type, "daemon") == 0) {
494 status = rpc_ep_register(ep_ctx->ev_ctx,
499 if (!NT_STATUS_IS_OK(status)) {
507 static bool eventlog_init_cb(void *ptr)
509 struct dcesrv_ep_context *ep_ctx =
510 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
511 const char *rpcsrv_type;
514 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
519 ok = eventlog_init_winreg(ep_ctx->msg_ctx);
524 if (strcasecmp_m(rpcsrv_type, "embedded") == 0 ||
525 strcasecmp_m(rpcsrv_type, "daemon") == 0) {
528 status = rpc_ep_register(ep_ctx->ev_ctx,
533 if (!NT_STATUS_IS_OK(status)) {
541 static bool initshutdown_init_cb(void *ptr)
543 struct dcesrv_ep_context *ep_ctx =
544 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
545 const char *rpcsrv_type;
547 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
552 if (strcasecmp_m(rpcsrv_type, "embedded") == 0 ||
553 strcasecmp_m(rpcsrv_type, "daemon") == 0) {
556 status = rpc_ep_register(ep_ctx->ev_ctx,
558 &ndr_table_initshutdown,
561 if (!NT_STATUS_IS_OK(status)) {
570 static bool rpcecho_init_cb(void *ptr) {
571 struct dcesrv_ep_context *ep_ctx =
572 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
573 const char *rpcsrv_type;
576 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
581 if (strcasecmp_m(rpcsrv_type, "embedded") == 0 ||
582 strcasecmp_m(rpcsrv_type, "daemon") == 0) {
585 port = _open_sockets(ep_ctx->ev_ctx,
587 ndr_table_rpcecho.syntax_id,
593 status = rpc_ep_register(ep_ctx->ev_ctx,
598 if (!NT_STATUS_IS_OK(status)) {
608 static bool netdfs_init_cb(void *ptr)
610 struct dcesrv_ep_context *ep_ctx =
611 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
612 struct ndr_syntax_id abstract_syntax = ndr_table_netdfs.syntax_id;
613 const char *pipe_name = "netdfs";
614 const char *rpcsrv_type;
617 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
621 if (strcasecmp_m(rpcsrv_type, "embedded") == 0 ||
622 strcasecmp_m(rpcsrv_type, "daemon") == 0) {
626 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
634 port = _open_sockets(ep_ctx->ev_ctx,
642 status = rpc_ep_register(ep_ctx->ev_ctx,
647 if (!NT_STATUS_IS_OK(status)) {
655 static bool dssetup_init_cb(void *ptr)
657 struct dcesrv_ep_context *ep_ctx =
658 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
659 struct ndr_syntax_id abstract_syntax = ndr_table_dssetup.syntax_id;
660 const char *pipe_name = "dssetup";
661 const char *rpcsrv_type;
664 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
669 if (strcasecmp_m(rpcsrv_type, "embedded") == 0 ||
670 strcasecmp_m(rpcsrv_type, "daemon") == 0) {
674 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
682 port = _open_sockets(ep_ctx->ev_ctx,
690 status = rpc_ep_register(ep_ctx->ev_ctx,
695 if (!NT_STATUS_IS_OK(status)) {
703 static bool wkssvc_init_cb(void *ptr)
705 struct dcesrv_ep_context *ep_ctx =
706 talloc_get_type_abort(ptr, struct dcesrv_ep_context);
707 struct ndr_syntax_id abstract_syntax = ndr_table_wkssvc.syntax_id;
708 const char *pipe_name = "wkssvc";
709 const char *rpcsrv_type;
712 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
716 if (strcasecmp_m(rpcsrv_type, "embedded") == 0 ||
717 strcasecmp_m(rpcsrv_type, "daemon") == 0) {
721 ok = setup_dcerpc_ncalrpc_socket(ep_ctx->ev_ctx,
729 port = _open_sockets(ep_ctx->ev_ctx,
737 status = rpc_ep_register(ep_ctx->ev_ctx,
742 if (!NT_STATUS_IS_OK(status)) {
750 bool dcesrv_ep_setup(struct tevent_context *ev_ctx,
751 struct messaging_context *msg_ctx)
753 struct dcesrv_ep_context *ep_ctx;
755 struct rpc_srv_callbacks epmapper_cb;
757 struct rpc_srv_callbacks winreg_cb;
758 struct rpc_srv_callbacks srvsvc_cb;
760 struct rpc_srv_callbacks lsarpc_cb;
761 struct rpc_srv_callbacks samr_cb;
762 struct rpc_srv_callbacks netlogon_cb;
764 struct rpc_srv_callbacks spoolss_cb;
765 struct rpc_srv_callbacks svcctl_cb;
766 struct rpc_srv_callbacks ntsvcs_cb;
767 struct rpc_srv_callbacks eventlog_cb;
768 struct rpc_srv_callbacks initshutdown_cb;
769 struct rpc_srv_callbacks netdfs_cb;
771 struct rpc_srv_callbacks rpcecho_cb;
773 struct rpc_srv_callbacks dssetup_cb;
774 struct rpc_srv_callbacks wkssvc_cb;
776 const char *rpcsrv_type;
778 ep_ctx = talloc(ev_ctx, struct dcesrv_ep_context);
779 if (ep_ctx == NULL) {
783 ep_ctx->ev_ctx = ev_ctx;
784 ep_ctx->msg_ctx = msg_ctx;
786 /* start endpoint mapper only if enabled */
787 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
791 if (strcasecmp_m(rpcsrv_type, "embedded") == 0) {
792 epmapper_cb.init = epmapper_init_cb;
793 epmapper_cb.shutdown = epmapper_shutdown_cb;
794 epmapper_cb.private_data = ep_ctx;
796 if (!NT_STATUS_IS_OK(rpc_epmapper_init(&epmapper_cb))) {
799 } else if (strcasecmp_m(rpcsrv_type, "daemon") == 0) {
800 if (!NT_STATUS_IS_OK(rpc_epmapper_init(NULL))) {
805 winreg_cb.init = winreg_init_cb;
806 winreg_cb.shutdown = NULL;
807 winreg_cb.private_data = ep_ctx;
808 if (!NT_STATUS_IS_OK(rpc_winreg_init(&winreg_cb))) {
812 srvsvc_cb.init = srvsvc_init_cb;
813 srvsvc_cb.shutdown = NULL;
814 srvsvc_cb.private_data = ep_ctx;
815 if (!NT_STATUS_IS_OK(rpc_srvsvc_init(&srvsvc_cb))) {
820 lsarpc_cb.init = lsarpc_init_cb;
821 lsarpc_cb.shutdown = NULL;
822 lsarpc_cb.private_data = ep_ctx;
823 if (!NT_STATUS_IS_OK(rpc_lsarpc_init(&lsarpc_cb))) {
827 samr_cb.init = samr_init_cb;
828 samr_cb.shutdown = NULL;
829 samr_cb.private_data = ep_ctx;
830 if (!NT_STATUS_IS_OK(rpc_samr_init(&samr_cb))) {
834 netlogon_cb.init = netlogon_init_cb;
835 netlogon_cb.shutdown = NULL;
836 netlogon_cb.private_data = ep_ctx;
837 if (!NT_STATUS_IS_OK(rpc_netlogon_init(&netlogon_cb))) {
841 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
845 if (strcasecmp_m(rpcsrv_type, "embedded") == 0) {
846 spoolss_cb.init = spoolss_init_cb;
847 spoolss_cb.shutdown = spoolss_shutdown_cb;
848 spoolss_cb.private_data = ep_ctx;
849 if (!NT_STATUS_IS_OK(rpc_spoolss_init(&spoolss_cb))) {
852 } else if (strcasecmp_m(rpcsrv_type, "daemon") == 0 ||
853 strcasecmp_m(rpcsrv_type, "external") == 0) {
854 if (!NT_STATUS_IS_OK(rpc_spoolss_init(NULL))) {
859 svcctl_cb.init = svcctl_init_cb;
860 svcctl_cb.shutdown = svcctl_shutdown_cb;
861 svcctl_cb.private_data = ep_ctx;
862 if (!NT_STATUS_IS_OK(rpc_svcctl_init(&svcctl_cb))) {
866 ntsvcs_cb.init = ntsvcs_init_cb;
867 ntsvcs_cb.shutdown = NULL;
868 ntsvcs_cb.private_data = ep_ctx;
869 if (!NT_STATUS_IS_OK(rpc_ntsvcs_init(&ntsvcs_cb))) {
873 eventlog_cb.init = eventlog_init_cb;
874 eventlog_cb.shutdown = NULL;
875 eventlog_cb.private_data = ep_ctx;
876 if (!NT_STATUS_IS_OK(rpc_eventlog_init(&eventlog_cb))) {
880 initshutdown_cb.init = initshutdown_init_cb;
881 initshutdown_cb.shutdown = NULL;
882 initshutdown_cb.private_data = ep_ctx;
883 if (!NT_STATUS_IS_OK(rpc_initshutdown_init(&initshutdown_cb))) {
887 netdfs_cb.init = netdfs_init_cb;
888 netdfs_cb.shutdown = NULL;
889 netdfs_cb.private_data = ep_ctx;
890 if (!NT_STATUS_IS_OK(rpc_netdfs_init(&netdfs_cb))) {
895 rpcecho_cb.init = rpcecho_init_cb;
896 rpcecho_cb.shutdown = NULL;
897 rpcecho_cb.private_data = ep_ctx;
898 if (!NT_STATUS_IS_OK(rpc_rpcecho_init(&rpcecho_cb))) {
903 dssetup_cb.init = dssetup_init_cb;
904 dssetup_cb.shutdown = NULL;
905 dssetup_cb.private_data = ep_ctx;
906 if (!NT_STATUS_IS_OK(rpc_dssetup_init(&dssetup_cb))) {
910 wkssvc_cb.init = wkssvc_init_cb;
911 wkssvc_cb.shutdown = NULL;
912 wkssvc_cb.private_data = ep_ctx;
913 if (!NT_STATUS_IS_OK(rpc_wkssvc_init(&wkssvc_cb))) {
920 /* vim: set ts=8 sw=8 noet cindent ft=c.doxygen: */