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 "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/rpc_config.h"
54 #include "rpc_server/epmapper/srv_epmapper.h"
56 /* Common routine for embedded RPC servers */
57 static bool rpc_setup_embedded(struct tevent_context *ev_ctx,
58 struct messaging_context *msg_ctx,
59 const struct dcerpc_binding_vector *v,
60 const struct ndr_interface_table *t,
61 const char *pipe_name)
63 struct dcerpc_binding_vector *v2;
64 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
68 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
70 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
74 status = dcerpc_binding_vector_replace_iface(t, v2);
75 if (!NT_STATUS_IS_OK(status)) {
80 status = dcerpc_binding_vector_new(talloc_tos(), &v2);
81 if (!NT_STATUS_IS_OK(status)) {
86 status = dcerpc_binding_vector_add_np_default(t, v2);
87 if (!NT_STATUS_IS_OK(status)) {
92 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
100 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
101 if (!NT_STATUS_IS_OK(status)) {
106 status = rpc_ep_register(ev_ctx,
110 if (!NT_STATUS_IS_OK(status)) {
118 static bool rpc_setup_winreg(struct tevent_context *ev_ctx,
119 struct messaging_context *msg_ctx,
120 const struct dcerpc_binding_vector *v)
122 const struct ndr_interface_table *t = &ndr_table_winreg;
123 const char *pipe_name = "winreg";
125 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
126 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
130 status = rpc_winreg_init(NULL);
131 if (!NT_STATUS_IS_OK(status)) {
135 return rpc_setup_embedded(ev_ctx, msg_ctx, v, t, pipe_name);
138 static bool rpc_setup_srvsvc(struct tevent_context *ev_ctx,
139 struct messaging_context *msg_ctx,
140 const struct dcerpc_binding_vector *v)
142 const struct ndr_interface_table *t = &ndr_table_srvsvc;
143 const char *pipe_name = "srvsvc";
145 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
146 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
150 status = rpc_srvsvc_init(NULL);
151 if (!NT_STATUS_IS_OK(status)) {
155 return rpc_setup_embedded(ev_ctx, msg_ctx, v, t, pipe_name);
158 static bool rpc_setup_lsarpc(struct tevent_context *ev_ctx,
159 struct messaging_context *msg_ctx,
160 const struct dcerpc_binding_vector *v)
162 const struct ndr_interface_table *t = &ndr_table_lsarpc;
163 const char *pipe_name = "lsarpc";
164 enum rpc_daemon_type_e lsasd_type = rpc_lsasd_daemon();
166 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
167 if (service_mode != RPC_SERVICE_MODE_EMBEDDED || lsasd_type != RPC_DAEMON_EMBEDDED) {
171 status = rpc_lsarpc_init(NULL);
172 if (!NT_STATUS_IS_OK(status)) {
176 return rpc_setup_embedded(ev_ctx, msg_ctx, v, t, pipe_name);
179 static bool rpc_setup_samr(struct tevent_context *ev_ctx,
180 struct messaging_context *msg_ctx,
181 const struct dcerpc_binding_vector *v)
183 const struct ndr_interface_table *t = &ndr_table_samr;
184 const char *pipe_name = "samr";
185 enum rpc_daemon_type_e lsasd_type = rpc_lsasd_daemon();
187 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
188 if (service_mode != RPC_SERVICE_MODE_EMBEDDED || lsasd_type != RPC_DAEMON_EMBEDDED) {
192 status = rpc_samr_init(NULL);
193 if (!NT_STATUS_IS_OK(status)) {
197 return rpc_setup_embedded(ev_ctx, msg_ctx, v, t, pipe_name);
200 static bool rpc_setup_netlogon(struct tevent_context *ev_ctx,
201 struct messaging_context *msg_ctx,
202 const struct dcerpc_binding_vector *v)
204 const struct ndr_interface_table *t = &ndr_table_netlogon;
205 const char *pipe_name = "netlogon";
206 enum rpc_daemon_type_e lsasd_type = rpc_lsasd_daemon();
208 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
209 if (service_mode != RPC_SERVICE_MODE_EMBEDDED || lsasd_type != RPC_DAEMON_EMBEDDED) {
213 status = rpc_netlogon_init(NULL);
214 if (!NT_STATUS_IS_OK(status)) {
218 return rpc_setup_embedded(ev_ctx, msg_ctx, v, t, pipe_name);
221 static bool rpc_setup_netdfs(struct tevent_context *ev_ctx,
222 struct messaging_context *msg_ctx,
223 const struct dcerpc_binding_vector *v)
225 const struct ndr_interface_table *t = &ndr_table_netdfs;
226 const char *pipe_name = "netdfs";
228 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
229 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
233 status = rpc_netdfs_init(NULL);
234 if (!NT_STATUS_IS_OK(status)) {
238 return rpc_setup_embedded(ev_ctx, msg_ctx, v, t, pipe_name);
242 static bool rpc_setup_rpcecho(struct tevent_context *ev_ctx,
243 struct messaging_context *msg_ctx,
244 const struct dcerpc_binding_vector *v)
246 const struct ndr_interface_table *t = &ndr_table_rpcecho;
247 const char *pipe_name = "rpcecho";
249 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
250 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
254 status = rpc_rpcecho_init(NULL);
255 if (!NT_STATUS_IS_OK(status)) {
259 return rpc_setup_embedded(ev_ctx, msg_ctx, v, t, pipe_name);
263 static bool rpc_setup_dssetup(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_dssetup;
268 const char *pipe_name = "dssetup";
270 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
271 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
275 status = rpc_dssetup_init(NULL);
276 if (!NT_STATUS_IS_OK(status)) {
280 return rpc_setup_embedded(ev_ctx, msg_ctx, v, t, pipe_name);
283 static bool rpc_setup_wkssvc(struct tevent_context *ev_ctx,
284 struct messaging_context *msg_ctx,
285 const struct dcerpc_binding_vector *v)
287 const struct ndr_interface_table *t = &ndr_table_wkssvc;
288 const char *pipe_name = "wkssvc";
290 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
291 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
295 status = rpc_wkssvc_init(NULL);
296 if (!NT_STATUS_IS_OK(status)) {
300 return rpc_setup_embedded(ev_ctx, msg_ctx, v, t, pipe_name);
303 static bool spoolss_init_cb(void *ptr)
305 struct messaging_context *msg_ctx =
306 talloc_get_type_abort(ptr, struct messaging_context);
310 * Migrate the printers first.
312 ok = nt_printing_tdb_migrate(msg_ctx);
320 static bool spoolss_shutdown_cb(void *ptr)
322 srv_spoolss_cleanup();
327 static bool rpc_setup_spoolss(struct tevent_context *ev_ctx,
328 struct messaging_context *msg_ctx)
330 const struct ndr_interface_table *t = &ndr_table_spoolss;
331 struct rpc_srv_callbacks spoolss_cb;
332 enum rpc_daemon_type_e spoolss_type = rpc_spoolss_daemon();
333 NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
334 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
336 if (_lp_disable_spoolss()) {
340 if (service_mode != RPC_SERVICE_MODE_EMBEDDED || spoolss_type != RPC_DAEMON_EMBEDDED) {
344 spoolss_cb.init = spoolss_init_cb;
345 spoolss_cb.shutdown = spoolss_shutdown_cb;
346 spoolss_cb.private_data = msg_ctx;
348 status = rpc_spoolss_init(&spoolss_cb);
349 if (!NT_STATUS_IS_OK(status)) {
353 return rpc_setup_embedded(ev_ctx, msg_ctx, NULL, t, NULL);
356 static bool svcctl_init_cb(void *ptr)
358 struct messaging_context *msg_ctx =
359 talloc_get_type_abort(ptr, struct messaging_context);
362 /* initialize the control hooks */
363 init_service_op_table();
365 ok = svcctl_init_winreg(msg_ctx);
373 static bool svcctl_shutdown_cb(void *ptr)
375 shutdown_service_op_table();
380 static bool rpc_setup_svcctl(struct tevent_context *ev_ctx,
381 struct messaging_context *msg_ctx)
383 const struct ndr_interface_table *t = &ndr_table_svcctl;
384 const char *pipe_name = "svcctl";
385 struct rpc_srv_callbacks svcctl_cb;
387 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
388 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
392 svcctl_cb.init = svcctl_init_cb;
393 svcctl_cb.shutdown = svcctl_shutdown_cb;
394 svcctl_cb.private_data = msg_ctx;
396 status = rpc_svcctl_init(&svcctl_cb);
397 if (!NT_STATUS_IS_OK(status)) {
401 return rpc_setup_embedded(ev_ctx, msg_ctx, NULL, t, pipe_name);
404 static bool rpc_setup_ntsvcs(struct tevent_context *ev_ctx,
405 struct messaging_context *msg_ctx)
407 const struct ndr_interface_table *t = &ndr_table_ntsvcs;
409 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
410 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
414 status = rpc_ntsvcs_init(NULL);
415 if (!NT_STATUS_IS_OK(status)) {
419 return rpc_setup_embedded(ev_ctx, msg_ctx, NULL, t, NULL);
424 static bool eventlog_init_cb(void *ptr)
426 struct messaging_context *msg_ctx =
427 talloc_get_type_abort(ptr, struct messaging_context);
430 ok = eventlog_init_winreg(msg_ctx);
438 static bool rpc_setup_eventlog(struct tevent_context *ev_ctx,
439 struct messaging_context *msg_ctx)
441 const struct ndr_interface_table *t = &ndr_table_eventlog;
442 struct rpc_srv_callbacks eventlog_cb;
444 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
445 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
449 eventlog_cb.init = eventlog_init_cb;
450 eventlog_cb.shutdown = NULL;
451 eventlog_cb.private_data = msg_ctx;
453 status = rpc_eventlog_init(&eventlog_cb);
454 if (!NT_STATUS_IS_OK(status)) {
458 return rpc_setup_embedded(ev_ctx, msg_ctx, NULL, t, NULL);
461 static bool rpc_setup_initshutdown(struct tevent_context *ev_ctx,
462 struct messaging_context *msg_ctx)
464 const struct ndr_interface_table *t = &ndr_table_initshutdown;
466 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
467 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
471 status = rpc_initshutdown_init(NULL);
472 if (!NT_STATUS_IS_OK(status)) {
476 return rpc_setup_embedded(ev_ctx, msg_ctx, NULL, t, NULL);
479 bool dcesrv_ep_setup(struct tevent_context *ev_ctx,
480 struct messaging_context *msg_ctx)
482 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
483 struct dcerpc_binding_vector *v;
484 const char *rpcsrv_type;
489 tmp_ctx = talloc_stackframe();
490 if (tmp_ctx == NULL) {
494 status = dcerpc_binding_vector_new(tmp_ctx,
496 if (!NT_STATUS_IS_OK(status)) {
501 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
506 if ((strcasecmp_m(rpcsrv_type, "yes") == 0 ||
507 strcasecmp_m(rpcsrv_type, "true") == 0)
508 && epm_mode != RPC_SERVICE_MODE_DISABLED) {
509 status = rpc_setup_tcpip_sockets(ev_ctx,
514 if (!NT_STATUS_IS_OK(status)) {
520 ok = rpc_setup_winreg(ev_ctx, msg_ctx, v);
525 ok = rpc_setup_srvsvc(ev_ctx, msg_ctx, v);
530 ok = rpc_setup_lsarpc(ev_ctx, msg_ctx, v);
535 ok = rpc_setup_samr(ev_ctx, msg_ctx, v);
540 ok = rpc_setup_netlogon(ev_ctx, msg_ctx, v);
545 ok = rpc_setup_netdfs(ev_ctx, msg_ctx, v);
551 ok = rpc_setup_rpcecho(ev_ctx, msg_ctx, v);
557 ok = rpc_setup_dssetup(ev_ctx, msg_ctx, v);
562 ok = rpc_setup_wkssvc(ev_ctx, msg_ctx, v);
567 ok = rpc_setup_spoolss(ev_ctx, msg_ctx);
572 ok = rpc_setup_svcctl(ev_ctx, msg_ctx);
577 ok = rpc_setup_ntsvcs(ev_ctx, msg_ctx);
582 ok = rpc_setup_eventlog(ev_ctx, msg_ctx);
587 ok = rpc_setup_initshutdown(ev_ctx, msg_ctx);
593 talloc_free(tmp_ctx);
597 /* vim: set ts=8 sw=8 noet cindent ft=c.doxygen: */