s3:vfs: Correctly check if OFD locks should be enabled or not
[Samba.git] / source3 / rpc_server / rpc_service_setup.c
blob9c755e672c837a67a7f1b05a315d2a08c82aa900
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"
23 #include "ntdomain.h"
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/rpc_modules.h"
55 #include "rpc_server/epmapper/srv_epmapper.h"
57 static_decl_rpc;
59 /* Common routine for embedded RPC servers */
60 bool rpc_setup_embedded(struct tevent_context *ev_ctx,
61 struct messaging_context *msg_ctx,
62 const struct ndr_interface_table *t,
63 const char *pipe_name)
65 struct dcerpc_binding_vector *v;
66 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
67 NTSTATUS status;
69 /* Registration of ncacn_np services is problematic. The
70 * ev_ctx passed in here is passed down to all children of the
71 * smbd process, and if the end point mapper ever goes away,
72 * they will all attempt to re-register. But we want to test
73 * the code for now, so it is enabled in on environment in
74 * make test */
75 if (epm_mode != RPC_SERVICE_MODE_DISABLED &&
76 (lp_parm_bool(-1, "rpc_server", "register_embedded_np", false))) {
77 status = dcerpc_binding_vector_new(talloc_tos(), &v);
78 if (!NT_STATUS_IS_OK(status)) {
79 return false;
82 status = dcerpc_binding_vector_add_np_default(t, v);
83 if (!NT_STATUS_IS_OK(status)) {
84 return false;
87 status = rpc_ep_register(ev_ctx,
88 msg_ctx,
90 v);
91 if (!NT_STATUS_IS_OK(status)) {
92 return false;
96 return true;
99 static bool rpc_setup_winreg(struct tevent_context *ev_ctx,
100 struct messaging_context *msg_ctx)
102 const struct ndr_interface_table *t = &ndr_table_winreg;
103 const char *pipe_name = "winreg";
104 NTSTATUS status;
105 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
106 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
107 return true;
110 status = rpc_winreg_init(NULL);
111 if (!NT_STATUS_IS_OK(status)) {
112 return false;
115 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
118 static bool rpc_setup_srvsvc(struct tevent_context *ev_ctx,
119 struct messaging_context *msg_ctx)
121 const struct ndr_interface_table *t = &ndr_table_srvsvc;
122 const char *pipe_name = "srvsvc";
123 NTSTATUS status;
124 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
125 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
126 return true;
129 status = rpc_srvsvc_init(NULL);
130 if (!NT_STATUS_IS_OK(status)) {
131 return false;
134 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
137 static bool rpc_setup_lsarpc(struct tevent_context *ev_ctx,
138 struct messaging_context *msg_ctx)
140 const struct ndr_interface_table *t = &ndr_table_lsarpc;
141 const char *pipe_name = "lsarpc";
142 enum rpc_daemon_type_e lsasd_type = rpc_lsasd_daemon();
143 NTSTATUS status;
144 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
145 if (service_mode != RPC_SERVICE_MODE_EMBEDDED || lsasd_type != RPC_DAEMON_EMBEDDED) {
146 return true;
149 status = rpc_lsarpc_init(NULL);
150 if (!NT_STATUS_IS_OK(status)) {
151 return false;
154 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
157 static bool rpc_setup_samr(struct tevent_context *ev_ctx,
158 struct messaging_context *msg_ctx)
160 const struct ndr_interface_table *t = &ndr_table_samr;
161 const char *pipe_name = "samr";
162 enum rpc_daemon_type_e lsasd_type = rpc_lsasd_daemon();
163 NTSTATUS status;
164 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
165 if (service_mode != RPC_SERVICE_MODE_EMBEDDED || lsasd_type != RPC_DAEMON_EMBEDDED) {
166 return true;
169 status = rpc_samr_init(NULL);
170 if (!NT_STATUS_IS_OK(status)) {
171 return false;
174 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
177 static bool rpc_setup_netlogon(struct tevent_context *ev_ctx,
178 struct messaging_context *msg_ctx)
180 const struct ndr_interface_table *t = &ndr_table_netlogon;
181 const char *pipe_name = "netlogon";
182 enum rpc_daemon_type_e lsasd_type = rpc_lsasd_daemon();
183 NTSTATUS status;
184 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
185 if (service_mode != RPC_SERVICE_MODE_EMBEDDED || lsasd_type != RPC_DAEMON_EMBEDDED) {
186 return true;
189 status = rpc_netlogon_init(NULL);
190 if (!NT_STATUS_IS_OK(status)) {
191 return false;
194 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
197 static bool rpc_setup_netdfs(struct tevent_context *ev_ctx,
198 struct messaging_context *msg_ctx)
200 const struct ndr_interface_table *t = &ndr_table_netdfs;
201 const char *pipe_name = "netdfs";
202 NTSTATUS status;
203 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
204 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
205 return true;
208 status = rpc_netdfs_init(NULL);
209 if (!NT_STATUS_IS_OK(status)) {
210 return false;
213 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
216 #ifdef DEVELOPER
217 static bool rpc_setup_rpcecho(struct tevent_context *ev_ctx,
218 struct messaging_context *msg_ctx)
220 const struct ndr_interface_table *t = &ndr_table_rpcecho;
221 const char *pipe_name = "rpcecho";
222 NTSTATUS status;
223 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
224 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
225 return true;
228 status = rpc_rpcecho_init(NULL);
229 if (!NT_STATUS_IS_OK(status)) {
230 return false;
233 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
235 #endif
237 static bool rpc_setup_dssetup(struct tevent_context *ev_ctx,
238 struct messaging_context *msg_ctx)
240 const struct ndr_interface_table *t = &ndr_table_dssetup;
241 const char *pipe_name = "dssetup";
242 NTSTATUS status;
243 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
244 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
245 return true;
248 status = rpc_dssetup_init(NULL);
249 if (!NT_STATUS_IS_OK(status)) {
250 return false;
253 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
256 static bool rpc_setup_wkssvc(struct tevent_context *ev_ctx,
257 struct messaging_context *msg_ctx)
259 const struct ndr_interface_table *t = &ndr_table_wkssvc;
260 const char *pipe_name = "wkssvc";
261 NTSTATUS status;
262 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
263 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
264 return true;
267 status = rpc_wkssvc_init(NULL);
268 if (!NT_STATUS_IS_OK(status)) {
269 return false;
272 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
275 static bool spoolss_init_cb(void *ptr)
277 struct messaging_context *msg_ctx =
278 talloc_get_type_abort(ptr, struct messaging_context);
279 bool ok;
282 * Migrate the printers first.
284 ok = nt_printing_tdb_migrate(msg_ctx);
285 if (!ok) {
286 return false;
289 return true;
292 static bool spoolss_shutdown_cb(void *ptr)
294 srv_spoolss_cleanup();
296 return true;
299 static bool rpc_setup_spoolss(struct tevent_context *ev_ctx,
300 struct messaging_context *msg_ctx)
302 const struct ndr_interface_table *t = &ndr_table_spoolss;
303 struct rpc_srv_callbacks spoolss_cb;
304 enum rpc_daemon_type_e spoolss_type = rpc_spoolss_daemon();
305 NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
306 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
308 if (lp__disable_spoolss()) {
309 return true;
312 if (service_mode != RPC_SERVICE_MODE_EMBEDDED || spoolss_type != RPC_DAEMON_EMBEDDED) {
313 return true;
316 spoolss_cb.init = spoolss_init_cb;
317 spoolss_cb.shutdown = spoolss_shutdown_cb;
318 spoolss_cb.private_data = msg_ctx;
320 status = rpc_spoolss_init(&spoolss_cb);
321 if (!NT_STATUS_IS_OK(status)) {
322 return false;
325 return rpc_setup_embedded(ev_ctx, msg_ctx, t, NULL);
328 static bool svcctl_init_cb(void *ptr)
330 struct messaging_context *msg_ctx =
331 talloc_get_type_abort(ptr, struct messaging_context);
332 bool ok;
334 /* initialize the control hooks */
335 init_service_op_table();
337 ok = svcctl_init_winreg(msg_ctx);
338 if (!ok) {
339 return false;
342 return true;
345 static bool svcctl_shutdown_cb(void *ptr)
347 shutdown_service_op_table();
349 return true;
352 static bool rpc_setup_svcctl(struct tevent_context *ev_ctx,
353 struct messaging_context *msg_ctx)
355 const struct ndr_interface_table *t = &ndr_table_svcctl;
356 const char *pipe_name = "svcctl";
357 struct rpc_srv_callbacks svcctl_cb;
358 NTSTATUS status;
359 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
360 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
361 return true;
364 svcctl_cb.init = svcctl_init_cb;
365 svcctl_cb.shutdown = svcctl_shutdown_cb;
366 svcctl_cb.private_data = msg_ctx;
368 status = rpc_svcctl_init(&svcctl_cb);
369 if (!NT_STATUS_IS_OK(status)) {
370 return false;
373 return rpc_setup_embedded(ev_ctx, msg_ctx, t, pipe_name);
376 static bool rpc_setup_ntsvcs(struct tevent_context *ev_ctx,
377 struct messaging_context *msg_ctx)
379 const struct ndr_interface_table *t = &ndr_table_ntsvcs;
380 NTSTATUS status;
381 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
382 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
383 return true;
386 status = rpc_ntsvcs_init(NULL);
387 if (!NT_STATUS_IS_OK(status)) {
388 return false;
391 return rpc_setup_embedded(ev_ctx, msg_ctx, t, NULL);
394 static bool eventlog_init_cb(void *ptr)
396 struct messaging_context *msg_ctx =
397 talloc_get_type_abort(ptr, struct messaging_context);
398 bool ok;
400 ok = eventlog_init_winreg(msg_ctx);
401 if (!ok) {
402 return false;
405 return true;
408 static bool rpc_setup_eventlog(struct tevent_context *ev_ctx,
409 struct messaging_context *msg_ctx)
411 const struct ndr_interface_table *t = &ndr_table_eventlog;
412 struct rpc_srv_callbacks eventlog_cb;
413 NTSTATUS status;
414 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
415 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
416 return true;
419 eventlog_cb.init = eventlog_init_cb;
420 eventlog_cb.shutdown = NULL;
421 eventlog_cb.private_data = msg_ctx;
423 status = rpc_eventlog_init(&eventlog_cb);
424 if (!NT_STATUS_IS_OK(status)) {
425 return false;
428 return rpc_setup_embedded(ev_ctx, msg_ctx, t, NULL);
431 static bool rpc_setup_initshutdown(struct tevent_context *ev_ctx,
432 struct messaging_context *msg_ctx)
434 const struct ndr_interface_table *t = &ndr_table_initshutdown;
435 NTSTATUS status;
436 enum rpc_service_mode_e service_mode = rpc_service_mode(t->name);
437 if (service_mode != RPC_SERVICE_MODE_EMBEDDED) {
438 return true;
441 status = rpc_initshutdown_init(NULL);
442 if (!NT_STATUS_IS_OK(status)) {
443 return false;
446 return rpc_setup_embedded(ev_ctx, msg_ctx, t, NULL);
449 bool dcesrv_ep_setup(struct tevent_context *ev_ctx,
450 struct messaging_context *msg_ctx)
452 TALLOC_CTX *tmp_ctx;
453 bool ok;
454 init_module_fn *mod_init_fns = NULL;
456 tmp_ctx = talloc_stackframe();
457 if (tmp_ctx == NULL) {
458 return false;
461 ok = rpc_setup_winreg(ev_ctx, msg_ctx);
462 if (!ok) {
463 goto done;
466 ok = rpc_setup_srvsvc(ev_ctx, msg_ctx);
467 if (!ok) {
468 goto done;
471 ok = rpc_setup_lsarpc(ev_ctx, msg_ctx);
472 if (!ok) {
473 goto done;
476 ok = rpc_setup_samr(ev_ctx, msg_ctx);
477 if (!ok) {
478 goto done;
481 ok = rpc_setup_netlogon(ev_ctx, msg_ctx);
482 if (!ok) {
483 goto done;
486 ok = rpc_setup_netdfs(ev_ctx, msg_ctx);
487 if (!ok) {
488 goto done;
491 #ifdef DEVELOPER
492 ok = rpc_setup_rpcecho(ev_ctx, msg_ctx);
493 if (!ok) {
494 goto done;
496 #endif
498 ok = rpc_setup_dssetup(ev_ctx, msg_ctx);
499 if (!ok) {
500 goto done;
503 ok = rpc_setup_wkssvc(ev_ctx, msg_ctx);
504 if (!ok) {
505 goto done;
508 ok = rpc_setup_spoolss(ev_ctx, msg_ctx);
509 if (!ok) {
510 goto done;
513 ok = rpc_setup_svcctl(ev_ctx, msg_ctx);
514 if (!ok) {
515 goto done;
518 ok = rpc_setup_ntsvcs(ev_ctx, msg_ctx);
519 if (!ok) {
520 goto done;
523 ok = rpc_setup_eventlog(ev_ctx, msg_ctx);
524 if (!ok) {
525 goto done;
528 ok = rpc_setup_initshutdown(ev_ctx, msg_ctx);
529 if (!ok) {
530 goto done;
533 /* Initialize static subsystems */
534 static_init_rpc(NULL);
536 /* Initialize shared modules */
537 mod_init_fns = load_samba_modules(tmp_ctx, "rpc");
538 if ((mod_init_fns == NULL) && (errno != ENOENT)) {
540 * ENOENT means the directory doesn't exist which can happen if
541 * all modules are static. So ENOENT is ok, everything else is
542 * not ok.
544 DBG_ERR("Loading shared RPC modules failed [%s]\n",
545 strerror(errno));
546 ok = false;
547 goto done;
550 ok = run_init_functions(NULL, mod_init_fns);
551 if (!ok) {
552 DBG_ERR("Initializing shared RPC modules failed\n");
553 goto done;
556 ok = setup_rpc_modules(ev_ctx, msg_ctx);
557 if (!ok) {
558 DBG_ERR("Shared RPC modules setup failed\n");
559 goto done;
562 done:
563 talloc_free(tmp_ctx);
564 return ok;
567 /* vim: set ts=8 sw=8 noet cindent ft=c.doxygen: */