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"
41 #include "../librpc/gen_ndr/srv_mdssvc.h"
43 #include "printing/nt_printing_migrate_internal.h"
44 #include "rpc_server/eventlog/srv_eventlog_reg.h"
45 #include "rpc_server/svcctl/srv_svcctl_reg.h"
46 #include "rpc_server/spoolss/srv_spoolss_nt.h"
47 #include "rpc_server/svcctl/srv_svcctl_nt.h"
48 #include "rpc_server/mdssvc/srv_mdssvc_nt.h"
50 #include "librpc/rpc/dcerpc_ep.h"
51 #include "rpc_server/rpc_sock_helper.h"
52 #include "rpc_server/rpc_service_setup.h"
53 #include "rpc_server/rpc_ep_register.h"
54 #include "rpc_server/rpc_server.h"
55 #include "rpc_server/rpc_config.h"
56 #include "rpc_server/epmapper/srv_epmapper.h"
58 /* Common routine for embedded RPC servers */
59 static bool rpc_setup_embedded(struct tevent_context
*ev_ctx
,
60 struct messaging_context
*msg_ctx
,
61 const struct ndr_interface_table
*t
,
62 const char *pipe_name
)
64 struct dcerpc_binding_vector
*v
;
65 enum rpc_service_mode_e epm_mode
= rpc_epmapper_mode();
68 /* Registration of ncacn_np services is problematic. The
69 * ev_ctx passed in here is passed down to all children of the
70 * smbd process, and if the end point mapper ever goes away,
71 * they will all attempt to re-register. But we want to test
72 * the code for now, so it is enabled in on environment in
74 if (epm_mode
!= RPC_SERVICE_MODE_DISABLED
&&
75 (lp_parm_bool(-1, "rpc_server", "register_embedded_np", false))) {
76 status
= dcerpc_binding_vector_new(talloc_tos(), &v
);
77 if (!NT_STATUS_IS_OK(status
)) {
81 status
= dcerpc_binding_vector_add_np_default(t
, v
);
82 if (!NT_STATUS_IS_OK(status
)) {
86 status
= rpc_ep_register(ev_ctx
,
90 if (!NT_STATUS_IS_OK(status
)) {
98 static bool rpc_setup_winreg(struct tevent_context
*ev_ctx
,
99 struct messaging_context
*msg_ctx
)
101 const struct ndr_interface_table
*t
= &ndr_table_winreg
;
102 const char *pipe_name
= "winreg";
104 enum rpc_service_mode_e service_mode
= rpc_service_mode(t
->name
);
105 if (service_mode
!= RPC_SERVICE_MODE_EMBEDDED
) {
109 status
= rpc_winreg_init(NULL
);
110 if (!NT_STATUS_IS_OK(status
)) {
114 return rpc_setup_embedded(ev_ctx
, msg_ctx
, t
, pipe_name
);
117 static bool rpc_setup_srvsvc(struct tevent_context
*ev_ctx
,
118 struct messaging_context
*msg_ctx
)
120 const struct ndr_interface_table
*t
= &ndr_table_srvsvc
;
121 const char *pipe_name
= "srvsvc";
123 enum rpc_service_mode_e service_mode
= rpc_service_mode(t
->name
);
124 if (service_mode
!= RPC_SERVICE_MODE_EMBEDDED
) {
128 status
= rpc_srvsvc_init(NULL
);
129 if (!NT_STATUS_IS_OK(status
)) {
133 return rpc_setup_embedded(ev_ctx
, msg_ctx
, t
, pipe_name
);
136 static bool rpc_setup_lsarpc(struct tevent_context
*ev_ctx
,
137 struct messaging_context
*msg_ctx
)
139 const struct ndr_interface_table
*t
= &ndr_table_lsarpc
;
140 const char *pipe_name
= "lsarpc";
141 enum rpc_daemon_type_e lsasd_type
= rpc_lsasd_daemon();
143 enum rpc_service_mode_e service_mode
= rpc_service_mode(t
->name
);
144 if (service_mode
!= RPC_SERVICE_MODE_EMBEDDED
|| lsasd_type
!= RPC_DAEMON_EMBEDDED
) {
148 status
= rpc_lsarpc_init(NULL
);
149 if (!NT_STATUS_IS_OK(status
)) {
153 return rpc_setup_embedded(ev_ctx
, msg_ctx
, t
, pipe_name
);
156 static bool rpc_setup_samr(struct tevent_context
*ev_ctx
,
157 struct messaging_context
*msg_ctx
)
159 const struct ndr_interface_table
*t
= &ndr_table_samr
;
160 const char *pipe_name
= "samr";
161 enum rpc_daemon_type_e lsasd_type
= rpc_lsasd_daemon();
163 enum rpc_service_mode_e service_mode
= rpc_service_mode(t
->name
);
164 if (service_mode
!= RPC_SERVICE_MODE_EMBEDDED
|| lsasd_type
!= RPC_DAEMON_EMBEDDED
) {
168 status
= rpc_samr_init(NULL
);
169 if (!NT_STATUS_IS_OK(status
)) {
173 return rpc_setup_embedded(ev_ctx
, msg_ctx
, t
, pipe_name
);
176 static bool rpc_setup_netlogon(struct tevent_context
*ev_ctx
,
177 struct messaging_context
*msg_ctx
)
179 const struct ndr_interface_table
*t
= &ndr_table_netlogon
;
180 const char *pipe_name
= "netlogon";
181 enum rpc_daemon_type_e lsasd_type
= rpc_lsasd_daemon();
183 enum rpc_service_mode_e service_mode
= rpc_service_mode(t
->name
);
184 if (service_mode
!= RPC_SERVICE_MODE_EMBEDDED
|| lsasd_type
!= RPC_DAEMON_EMBEDDED
) {
188 status
= rpc_netlogon_init(NULL
);
189 if (!NT_STATUS_IS_OK(status
)) {
193 return rpc_setup_embedded(ev_ctx
, msg_ctx
, t
, pipe_name
);
196 static bool rpc_setup_netdfs(struct tevent_context
*ev_ctx
,
197 struct messaging_context
*msg_ctx
)
199 const struct ndr_interface_table
*t
= &ndr_table_netdfs
;
200 const char *pipe_name
= "netdfs";
202 enum rpc_service_mode_e service_mode
= rpc_service_mode(t
->name
);
203 if (service_mode
!= RPC_SERVICE_MODE_EMBEDDED
) {
207 status
= rpc_netdfs_init(NULL
);
208 if (!NT_STATUS_IS_OK(status
)) {
212 return rpc_setup_embedded(ev_ctx
, msg_ctx
, t
, pipe_name
);
216 static bool rpc_setup_rpcecho(struct tevent_context
*ev_ctx
,
217 struct messaging_context
*msg_ctx
)
219 const struct ndr_interface_table
*t
= &ndr_table_rpcecho
;
220 const char *pipe_name
= "rpcecho";
222 enum rpc_service_mode_e service_mode
= rpc_service_mode(t
->name
);
223 if (service_mode
!= RPC_SERVICE_MODE_EMBEDDED
) {
227 status
= rpc_rpcecho_init(NULL
);
228 if (!NT_STATUS_IS_OK(status
)) {
232 return rpc_setup_embedded(ev_ctx
, msg_ctx
, t
, pipe_name
);
236 static bool rpc_setup_dssetup(struct tevent_context
*ev_ctx
,
237 struct messaging_context
*msg_ctx
)
239 const struct ndr_interface_table
*t
= &ndr_table_dssetup
;
240 const char *pipe_name
= "dssetup";
242 enum rpc_service_mode_e service_mode
= rpc_service_mode(t
->name
);
243 if (service_mode
!= RPC_SERVICE_MODE_EMBEDDED
) {
247 status
= rpc_dssetup_init(NULL
);
248 if (!NT_STATUS_IS_OK(status
)) {
252 return rpc_setup_embedded(ev_ctx
, msg_ctx
, t
, pipe_name
);
255 static bool rpc_setup_wkssvc(struct tevent_context
*ev_ctx
,
256 struct messaging_context
*msg_ctx
)
258 const struct ndr_interface_table
*t
= &ndr_table_wkssvc
;
259 const char *pipe_name
= "wkssvc";
261 enum rpc_service_mode_e service_mode
= rpc_service_mode(t
->name
);
262 if (service_mode
!= RPC_SERVICE_MODE_EMBEDDED
) {
266 status
= rpc_wkssvc_init(NULL
);
267 if (!NT_STATUS_IS_OK(status
)) {
271 return rpc_setup_embedded(ev_ctx
, msg_ctx
, t
, pipe_name
);
274 static bool spoolss_init_cb(void *ptr
)
276 struct messaging_context
*msg_ctx
=
277 talloc_get_type_abort(ptr
, struct messaging_context
);
281 * Migrate the printers first.
283 ok
= nt_printing_tdb_migrate(msg_ctx
);
291 static bool spoolss_shutdown_cb(void *ptr
)
293 srv_spoolss_cleanup();
298 static bool rpc_setup_spoolss(struct tevent_context
*ev_ctx
,
299 struct messaging_context
*msg_ctx
)
301 const struct ndr_interface_table
*t
= &ndr_table_spoolss
;
302 struct rpc_srv_callbacks spoolss_cb
;
303 enum rpc_daemon_type_e spoolss_type
= rpc_spoolss_daemon();
304 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
305 enum rpc_service_mode_e service_mode
= rpc_service_mode(t
->name
);
307 if (lp__disable_spoolss()) {
311 if (service_mode
!= RPC_SERVICE_MODE_EMBEDDED
|| spoolss_type
!= RPC_DAEMON_EMBEDDED
) {
315 spoolss_cb
.init
= spoolss_init_cb
;
316 spoolss_cb
.shutdown
= spoolss_shutdown_cb
;
317 spoolss_cb
.private_data
= msg_ctx
;
319 status
= rpc_spoolss_init(&spoolss_cb
);
320 if (!NT_STATUS_IS_OK(status
)) {
324 return rpc_setup_embedded(ev_ctx
, msg_ctx
, t
, NULL
);
327 static bool svcctl_init_cb(void *ptr
)
329 struct messaging_context
*msg_ctx
=
330 talloc_get_type_abort(ptr
, struct messaging_context
);
333 /* initialize the control hooks */
334 init_service_op_table();
336 ok
= svcctl_init_winreg(msg_ctx
);
344 static bool svcctl_shutdown_cb(void *ptr
)
346 shutdown_service_op_table();
351 static bool rpc_setup_svcctl(struct tevent_context
*ev_ctx
,
352 struct messaging_context
*msg_ctx
)
354 const struct ndr_interface_table
*t
= &ndr_table_svcctl
;
355 const char *pipe_name
= "svcctl";
356 struct rpc_srv_callbacks svcctl_cb
;
358 enum rpc_service_mode_e service_mode
= rpc_service_mode(t
->name
);
359 if (service_mode
!= RPC_SERVICE_MODE_EMBEDDED
) {
363 svcctl_cb
.init
= svcctl_init_cb
;
364 svcctl_cb
.shutdown
= svcctl_shutdown_cb
;
365 svcctl_cb
.private_data
= msg_ctx
;
367 status
= rpc_svcctl_init(&svcctl_cb
);
368 if (!NT_STATUS_IS_OK(status
)) {
372 return rpc_setup_embedded(ev_ctx
, msg_ctx
, t
, pipe_name
);
375 static bool rpc_setup_ntsvcs(struct tevent_context
*ev_ctx
,
376 struct messaging_context
*msg_ctx
)
378 const struct ndr_interface_table
*t
= &ndr_table_ntsvcs
;
380 enum rpc_service_mode_e service_mode
= rpc_service_mode(t
->name
);
381 if (service_mode
!= RPC_SERVICE_MODE_EMBEDDED
) {
385 status
= rpc_ntsvcs_init(NULL
);
386 if (!NT_STATUS_IS_OK(status
)) {
390 return rpc_setup_embedded(ev_ctx
, msg_ctx
, t
, NULL
);
393 static bool eventlog_init_cb(void *ptr
)
395 struct messaging_context
*msg_ctx
=
396 talloc_get_type_abort(ptr
, struct messaging_context
);
399 ok
= eventlog_init_winreg(msg_ctx
);
407 static bool rpc_setup_eventlog(struct tevent_context
*ev_ctx
,
408 struct messaging_context
*msg_ctx
)
410 const struct ndr_interface_table
*t
= &ndr_table_eventlog
;
411 struct rpc_srv_callbacks eventlog_cb
;
413 enum rpc_service_mode_e service_mode
= rpc_service_mode(t
->name
);
414 if (service_mode
!= RPC_SERVICE_MODE_EMBEDDED
) {
418 eventlog_cb
.init
= eventlog_init_cb
;
419 eventlog_cb
.shutdown
= NULL
;
420 eventlog_cb
.private_data
= msg_ctx
;
422 status
= rpc_eventlog_init(&eventlog_cb
);
423 if (!NT_STATUS_IS_OK(status
)) {
427 return rpc_setup_embedded(ev_ctx
, msg_ctx
, t
, NULL
);
430 static bool rpc_setup_initshutdown(struct tevent_context
*ev_ctx
,
431 struct messaging_context
*msg_ctx
)
433 const struct ndr_interface_table
*t
= &ndr_table_initshutdown
;
435 enum rpc_service_mode_e service_mode
= rpc_service_mode(t
->name
);
436 if (service_mode
!= RPC_SERVICE_MODE_EMBEDDED
) {
440 status
= rpc_initshutdown_init(NULL
);
441 if (!NT_STATUS_IS_OK(status
)) {
445 return rpc_setup_embedded(ev_ctx
, msg_ctx
, t
, NULL
);
448 #ifdef WITH_SPOTLIGHT
449 static bool mdssvc_init_cb(void *ptr
)
451 struct messaging_context
*msg_ctx
=
452 talloc_get_type_abort(ptr
, struct messaging_context
);
455 ok
= init_service_mdssvc(msg_ctx
);
463 static bool mdssvc_shutdown_cb(void *ptr
)
465 shutdown_service_mdssvc();
470 static bool rpc_setup_mdssvc(struct tevent_context
*ev_ctx
,
471 struct messaging_context
*msg_ctx
)
473 const struct ndr_interface_table
*t
= &ndr_table_mdssvc
;
474 const char *pipe_name
= "mdssvc";
475 struct rpc_srv_callbacks mdssvc_cb
;
477 enum rpc_service_mode_e service_mode
= rpc_service_mode(t
->name
);
478 enum rpc_daemon_type_e mdssvc_type
= rpc_mdssd_daemon();
480 if (service_mode
!= RPC_SERVICE_MODE_EMBEDDED
481 || mdssvc_type
!= RPC_DAEMON_EMBEDDED
) {
485 mdssvc_cb
.init
= mdssvc_init_cb
;
486 mdssvc_cb
.shutdown
= mdssvc_shutdown_cb
;
487 mdssvc_cb
.private_data
= msg_ctx
;
489 status
= rpc_mdssvc_init(&mdssvc_cb
);
490 if (!NT_STATUS_IS_OK(status
)) {
494 return rpc_setup_embedded(ev_ctx
, msg_ctx
, t
, pipe_name
);
498 bool dcesrv_ep_setup(struct tevent_context
*ev_ctx
,
499 struct messaging_context
*msg_ctx
)
504 tmp_ctx
= talloc_stackframe();
505 if (tmp_ctx
== NULL
) {
509 ok
= rpc_setup_winreg(ev_ctx
, msg_ctx
);
514 ok
= rpc_setup_srvsvc(ev_ctx
, msg_ctx
);
519 ok
= rpc_setup_lsarpc(ev_ctx
, msg_ctx
);
524 ok
= rpc_setup_samr(ev_ctx
, msg_ctx
);
529 ok
= rpc_setup_netlogon(ev_ctx
, msg_ctx
);
534 ok
= rpc_setup_netdfs(ev_ctx
, msg_ctx
);
540 ok
= rpc_setup_rpcecho(ev_ctx
, msg_ctx
);
546 ok
= rpc_setup_dssetup(ev_ctx
, msg_ctx
);
551 ok
= rpc_setup_wkssvc(ev_ctx
, msg_ctx
);
556 ok
= rpc_setup_spoolss(ev_ctx
, msg_ctx
);
561 ok
= rpc_setup_svcctl(ev_ctx
, msg_ctx
);
566 ok
= rpc_setup_ntsvcs(ev_ctx
, msg_ctx
);
571 ok
= rpc_setup_eventlog(ev_ctx
, msg_ctx
);
576 ok
= rpc_setup_initshutdown(ev_ctx
, msg_ctx
);
581 #ifdef WITH_SPOTLIGHT
582 ok
= rpc_setup_mdssvc(ev_ctx
, msg_ctx
);
589 talloc_free(tmp_ctx
);
593 /* vim: set ts=8 sw=8 noet cindent ft=c.doxygen: */