s3-rpc_server: Replace RPC_SERVICE_MODE_DAEMON checks
[idra/samba.git] / source3 / rpc_server / rpc_service_setup.c
1 /*
2  *  Unix SMB/CIFS implementation.
3  *
4  *  SMBD RPC service callbacks
5  *
6  *  Copyright (c) 2011      Andreas Schneider <asn@samba.org>
7  *
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.
12  *
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.
17  *
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/>.
20  */
21
22 #include "includes.h"
23 #include "ntdomain.h"
24
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
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"
47
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"
55
56 static bool rpc_setup_epmapper(struct tevent_context *ev_ctx,
57                                struct messaging_context *msg_ctx)
58 {
59         enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
60         enum rpc_daemon_type_e epm_type = rpc_epmapper_daemon();
61         NTSTATUS status;
62
63         if (epm_mode != RPC_SERVICE_MODE_DISABLED &&
64             epm_type != RPC_DAEMON_DISABLED) {
65                 status = rpc_epmapper_init(NULL);
66                 if (!NT_STATUS_IS_OK(status)) {
67                         return false;
68                 }
69         }
70
71         return true;
72 }
73
74 static bool rpc_setup_winreg(struct tevent_context *ev_ctx,
75                              struct messaging_context *msg_ctx,
76                              const struct dcerpc_binding_vector *v)
77 {
78         const struct ndr_interface_table *t = &ndr_table_winreg;
79         const char *pipe_name = "winreg";
80         struct dcerpc_binding_vector *v2;
81         enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
82         NTSTATUS status;
83         bool ok;
84
85         status = rpc_winreg_init(NULL);
86         if (!NT_STATUS_IS_OK(status)) {
87                 return false;
88         }
89
90         if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
91                 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
92                 if (v2 == NULL) {
93                         return false;
94                 }
95
96                 status = dcerpc_binding_vector_replace_iface(t, v2);
97                 if (!NT_STATUS_IS_OK(status)) {
98                         return false;
99                 }
100
101                 status = dcerpc_binding_vector_add_np_default(t, v2);
102                 if (!NT_STATUS_IS_OK(status)) {
103                         return false;
104                 }
105
106                 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
107                                                  msg_ctx,
108                                                  pipe_name,
109                                                  NULL);
110                 if (!ok) {
111                         return false;
112                 }
113
114                 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
115                 if (!NT_STATUS_IS_OK(status)) {
116                         return false;
117                 }
118
119                 status = rpc_ep_register(ev_ctx,
120                                          msg_ctx,
121                                          t,
122                                          v2);
123                 if (!NT_STATUS_IS_OK(status)) {
124                         return false;
125                 }
126         }
127
128         return true;
129 }
130
131 static bool rpc_setup_srvsvc(struct tevent_context *ev_ctx,
132                              struct messaging_context *msg_ctx,
133                              const struct dcerpc_binding_vector *v)
134 {
135         const struct ndr_interface_table *t = &ndr_table_srvsvc;
136         const char *pipe_name = "srvsvc";
137         struct dcerpc_binding_vector *v2;
138         enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
139         NTSTATUS status;
140         bool ok;
141
142         status = rpc_srvsvc_init(NULL);
143         if (!NT_STATUS_IS_OK(status)) {
144                 return false;
145         }
146
147         if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
148                 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
149                 if (v2 == NULL) {
150                         return false;
151                 }
152
153                 status = dcerpc_binding_vector_replace_iface(t, v2);
154                 if (!NT_STATUS_IS_OK(status)) {
155                         return false;
156                 }
157
158                 status = dcerpc_binding_vector_add_np_default(t, v2);
159                 if (!NT_STATUS_IS_OK(status)) {
160                         return false;
161                 }
162
163                 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
164                                                  msg_ctx,
165                                                  pipe_name,
166                                                  NULL);
167                 if (!ok) {
168                         return false;
169                 }
170
171                 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
172                 if (!NT_STATUS_IS_OK(status)) {
173                         return false;
174                 }
175
176                 status = rpc_ep_register(ev_ctx,
177                                          msg_ctx,
178                                          t,
179                                          v2);
180                 if (!NT_STATUS_IS_OK(status)) {
181                         return false;
182                 }
183         }
184
185         return true;
186 }
187
188 static bool rpc_setup_lsarpc(struct tevent_context *ev_ctx,
189                              struct messaging_context *msg_ctx,
190                              const struct dcerpc_binding_vector *v)
191 {
192         const struct ndr_interface_table *t = &ndr_table_lsarpc;
193         const char *pipe_name = "lsarpc";
194         struct dcerpc_binding_vector *v2;
195         enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
196         enum rpc_service_mode_e lsarpc_mode = rpc_lsarpc_mode();
197         enum rpc_daemon_type_e lsasd_type = rpc_lsasd_daemon();
198         NTSTATUS status;
199         bool ok;
200
201         status = rpc_lsarpc_init(NULL);
202         if (!NT_STATUS_IS_OK(status)) {
203                 return false;
204         }
205
206         if (lsarpc_mode == RPC_SERVICE_MODE_EMBEDDED &&
207             lsasd_type != RPC_DAEMON_DISABLED &&
208             epm_mode != RPC_SERVICE_MODE_DISABLED) {
209                 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
210                 if (v2 == NULL) {
211                         return false;
212                 }
213
214                 status = dcerpc_binding_vector_replace_iface(t, v2);
215                 if (!NT_STATUS_IS_OK(status)) {
216                         return false;
217                 }
218
219                 status = dcerpc_binding_vector_add_np_default(t, v2);
220                 if (!NT_STATUS_IS_OK(status)) {
221                         return false;
222                 }
223
224                 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
225                                                  msg_ctx,
226                                                  pipe_name,
227                                                  NULL);
228                 if (!ok) {
229                         return false;
230                 }
231
232                 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
233                 if (!NT_STATUS_IS_OK(status)) {
234                         return false;
235                 }
236
237                 status = rpc_ep_register(ev_ctx,
238                                          msg_ctx,
239                                          t,
240                                          v2);
241                 if (!NT_STATUS_IS_OK(status)) {
242                         return false;
243                 }
244         }
245
246         return true;
247 }
248
249 static bool rpc_setup_samr(struct tevent_context *ev_ctx,
250                            struct messaging_context *msg_ctx,
251                            const struct dcerpc_binding_vector *v)
252 {
253         const struct ndr_interface_table *t = &ndr_table_samr;
254         const char *pipe_name = "samr";
255         struct dcerpc_binding_vector *v2;
256         enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
257         enum rpc_service_mode_e samr_mode = rpc_samr_mode();
258         enum rpc_daemon_type_e lsasd_type = rpc_lsasd_daemon();
259         NTSTATUS status;
260         bool ok;
261
262         status = rpc_samr_init(NULL);
263         if (!NT_STATUS_IS_OK(status)) {
264                 return false;
265         }
266
267         if (samr_mode == RPC_SERVICE_MODE_EMBEDDED &&
268             lsasd_type != RPC_DAEMON_DISABLED &&
269             epm_mode != RPC_SERVICE_MODE_DISABLED) {
270                 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
271                 if (v2 == NULL) {
272                         return false;
273                 }
274
275                 status = dcerpc_binding_vector_replace_iface(t, v2);
276                 if (!NT_STATUS_IS_OK(status)) {
277                         return false;
278                 }
279
280                 status = dcerpc_binding_vector_add_np_default(t, v2);
281                 if (!NT_STATUS_IS_OK(status)) {
282                         return false;
283                 }
284
285                 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
286                                                  msg_ctx,
287                                                  pipe_name,
288                                                  NULL);
289                 if (!ok) {
290                         return false;
291                 }
292
293                 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
294                 if (!NT_STATUS_IS_OK(status)) {
295                         return false;
296                 }
297
298                 status = rpc_ep_register(ev_ctx,
299                                          msg_ctx,
300                                          t,
301                                          v2);
302                 if (!NT_STATUS_IS_OK(status)) {
303                         return false;
304                 }
305         }
306
307         return true;
308 }
309
310 static bool rpc_setup_netlogon(struct tevent_context *ev_ctx,
311                                struct messaging_context *msg_ctx,
312                                const struct dcerpc_binding_vector *v)
313 {
314         const struct ndr_interface_table *t = &ndr_table_netlogon;
315         const char *pipe_name = "netlogon";
316         struct dcerpc_binding_vector *v2;
317         enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
318         enum rpc_service_mode_e netlogon_mode = rpc_netlogon_mode();
319         enum rpc_daemon_type_e lsasd_type = rpc_lsasd_daemon();
320         NTSTATUS status;
321         bool ok;
322
323         status = rpc_netlogon_init(NULL);
324         if (!NT_STATUS_IS_OK(status)) {
325                 return false;
326         }
327
328         if (netlogon_mode == RPC_SERVICE_MODE_EMBEDDED &&
329             lsasd_type != RPC_DAEMON_DISABLED &&
330             epm_mode != RPC_SERVICE_MODE_DISABLED) {
331                 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
332                 if (v2 == NULL) {
333                         return false;
334                 }
335
336                 status = dcerpc_binding_vector_replace_iface(t, v2);
337                 if (!NT_STATUS_IS_OK(status)) {
338                         return false;
339                 }
340
341                 status = dcerpc_binding_vector_add_np_default(t, v2);
342                 if (!NT_STATUS_IS_OK(status)) {
343                         return false;
344                 }
345
346                 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
347                                                  msg_ctx,
348                                                  pipe_name,
349                                                  NULL);
350                 if (!ok) {
351                         return false;
352                 }
353
354                 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
355                 if (!NT_STATUS_IS_OK(status)) {
356                         return false;
357                 }
358
359                 status = rpc_ep_register(ev_ctx,
360                                          msg_ctx,
361                                          t,
362                                          v2);
363                 if (!NT_STATUS_IS_OK(status)) {
364                         return false;
365                 }
366         }
367
368         return true;
369 }
370
371 static bool rpc_setup_netdfs(struct tevent_context *ev_ctx,
372                              struct messaging_context *msg_ctx,
373                              const struct dcerpc_binding_vector *v)
374 {
375         const struct ndr_interface_table *t = &ndr_table_netdfs;
376         const char *pipe_name = "netdfs";
377         struct dcerpc_binding_vector *v2;
378         enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
379         NTSTATUS status;
380         bool ok;
381
382         status = rpc_netdfs_init(NULL);
383         if (!NT_STATUS_IS_OK(status)) {
384                 return false;
385         }
386
387         if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
388                 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
389                 if (v2 == NULL) {
390                         return false;
391                 }
392
393                 status = dcerpc_binding_vector_replace_iface(t, v2);
394                 if (!NT_STATUS_IS_OK(status)) {
395                         return false;
396                 }
397
398                 status = dcerpc_binding_vector_add_np_default(t, v2);
399                 if (!NT_STATUS_IS_OK(status)) {
400                         return false;
401                 }
402
403                 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
404                                                  msg_ctx,
405                                                  pipe_name,
406                                                  NULL);
407                 if (!ok) {
408                         return false;
409                 }
410
411                 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
412                 if (!NT_STATUS_IS_OK(status)) {
413                         return false;
414                 }
415
416                 status = rpc_ep_register(ev_ctx,
417                                          msg_ctx,
418                                          t,
419                                          v2);
420                 if (!NT_STATUS_IS_OK(status)) {
421                         return false;
422                 }
423         }
424
425         return true;
426 }
427
428 #ifdef DEVELOPER
429 static bool rpc_setup_rpcecho(struct tevent_context *ev_ctx,
430                               struct messaging_context *msg_ctx,
431                               const struct dcerpc_binding_vector *v)
432 {
433         const struct ndr_interface_table *t = &ndr_table_rpcecho;
434         const char *pipe_name = "rpcecho";
435         struct dcerpc_binding_vector *v2;
436         enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
437         NTSTATUS status;
438         bool ok;
439
440         status = rpc_rpcecho_init(NULL);
441         if (!NT_STATUS_IS_OK(status)) {
442                 return false;
443         }
444
445         if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
446                 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
447                 if (v2 == NULL) {
448                         return false;
449                 }
450
451                 status = dcerpc_binding_vector_replace_iface(t, v2);
452                 if (!NT_STATUS_IS_OK(status)) {
453                         return false;
454                 }
455
456                 status = dcerpc_binding_vector_add_np_default(t, v2);
457                 if (!NT_STATUS_IS_OK(status)) {
458                         return false;
459                 }
460
461                 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
462                                                  msg_ctx,
463                                                  pipe_name,
464                                                  NULL);
465                 if (!ok) {
466                         return false;
467                 }
468
469                 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
470                 if (!NT_STATUS_IS_OK(status)) {
471                         return false;
472                 }
473
474                 status = rpc_ep_register(ev_ctx,
475                                          msg_ctx,
476                                          t,
477                                          v2);
478                 if (!NT_STATUS_IS_OK(status)) {
479                         return false;
480                 }
481         }
482
483         return true;
484 }
485 #endif
486
487 static bool rpc_setup_dssetup(struct tevent_context *ev_ctx,
488                               struct messaging_context *msg_ctx,
489                               const struct dcerpc_binding_vector *v)
490 {
491         const struct ndr_interface_table *t = &ndr_table_dssetup;
492         const char *pipe_name = "dssetup";
493         struct dcerpc_binding_vector *v2;
494         enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
495         NTSTATUS status;
496         bool ok;
497
498         status = rpc_dssetup_init(NULL);
499         if (!NT_STATUS_IS_OK(status)) {
500                 return false;
501         }
502
503         if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
504                 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
505                 if (v2 == NULL) {
506                         return false;
507                 }
508
509                 status = dcerpc_binding_vector_replace_iface(t, v2);
510                 if (!NT_STATUS_IS_OK(status)) {
511                         return false;
512                 }
513
514                 status = dcerpc_binding_vector_add_np_default(t, v2);
515                 if (!NT_STATUS_IS_OK(status)) {
516                         return false;
517                 }
518
519                 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
520                                                  msg_ctx,
521                                                  pipe_name,
522                                                  NULL);
523                 if (!ok) {
524                         return false;
525                 }
526
527                 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
528                 if (!NT_STATUS_IS_OK(status)) {
529                         return false;
530                 }
531
532                 status = rpc_ep_register(ev_ctx,
533                                          msg_ctx,
534                                          t,
535                                          v2);
536                 if (!NT_STATUS_IS_OK(status)) {
537                         return false;
538                 }
539         }
540
541         return true;
542 }
543
544 static bool rpc_setup_wkssvc(struct tevent_context *ev_ctx,
545                              struct messaging_context *msg_ctx,
546                              const struct dcerpc_binding_vector *v)
547 {
548         const struct ndr_interface_table *t = &ndr_table_wkssvc;
549         const char *pipe_name = "wkssvc";
550         struct dcerpc_binding_vector *v2;
551         enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
552         NTSTATUS status;
553         bool ok;
554
555         status = rpc_wkssvc_init(NULL);
556         if (!NT_STATUS_IS_OK(status)) {
557                 return false;
558         }
559
560         if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
561                 v2 = dcerpc_binding_vector_dup(talloc_tos(), v);
562                 if (v2 == NULL) {
563                         return false;
564                 }
565
566                 status = dcerpc_binding_vector_replace_iface(t, v2);
567                 if (!NT_STATUS_IS_OK(status)) {
568                         return false;
569                 }
570
571                 status = dcerpc_binding_vector_add_np_default(t, v2);
572                 if (!NT_STATUS_IS_OK(status)) {
573                         return false;
574                 }
575
576                 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
577                                                  msg_ctx,
578                                                  pipe_name,
579                                                  NULL);
580                 if (!ok) {
581                         return false;
582                 }
583
584                 status = dcerpc_binding_vector_add_unix(t, v2, pipe_name);
585                 if (!NT_STATUS_IS_OK(status)) {
586                         return false;
587                 }
588
589                 status = rpc_ep_register(ev_ctx,
590                                          msg_ctx,
591                                          t,
592                                          v2);
593                 if (!NT_STATUS_IS_OK(status)) {
594                         return false;
595                 }
596         }
597
598         return true;
599 }
600
601 static bool spoolss_init_cb(void *ptr)
602 {
603         struct messaging_context *msg_ctx =
604                 talloc_get_type_abort(ptr, struct messaging_context);
605         bool ok;
606
607         /*
608          * Migrate the printers first.
609          */
610         ok = nt_printing_tdb_migrate(msg_ctx);
611         if (!ok) {
612                 return false;
613         }
614
615         return true;
616 }
617
618 static bool spoolss_shutdown_cb(void *ptr)
619 {
620         srv_spoolss_cleanup();
621
622         return true;
623 }
624
625 static bool rpc_setup_spoolss(struct tevent_context *ev_ctx,
626                               struct messaging_context *msg_ctx)
627 {
628         const struct ndr_interface_table *t = &ndr_table_spoolss;
629         struct rpc_srv_callbacks spoolss_cb;
630         struct dcerpc_binding_vector *v;
631         enum rpc_service_mode_e spoolss_mode = rpc_spoolss_mode();
632         enum rpc_daemon_type_e spoolss_type = rpc_spoolss_daemon();
633         NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
634
635         if (_lp_disable_spoolss() ||
636             spoolss_type == RPC_DAEMON_DISABLED ||
637             spoolss_mode == RPC_SERVICE_MODE_DISABLED) {
638                 return true;
639         }
640
641         if (spoolss_type == RPC_DAEMON_EMBEDDED) {
642                 spoolss_cb.init         = spoolss_init_cb;
643                 spoolss_cb.shutdown     = spoolss_shutdown_cb;
644                 spoolss_cb.private_data = msg_ctx;
645
646                 status = rpc_spoolss_init(&spoolss_cb);
647         } else if (spoolss_type == RPC_DAEMON_FORK) {
648                 status = rpc_spoolss_init(NULL);
649         }
650         if (!NT_STATUS_IS_OK(status)) {
651                 return false;
652         }
653
654         if (spoolss_type == RPC_DAEMON_EMBEDDED) {
655                 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
656
657                 if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
658                         status = dcerpc_binding_vector_new(talloc_tos(), &v);
659                         if (!NT_STATUS_IS_OK(status)) {
660                                 return false;
661                         }
662
663                         status = dcerpc_binding_vector_add_np_default(t, v);
664                         if (!NT_STATUS_IS_OK(status)) {
665                                 return false;
666                         }
667
668                         status = rpc_ep_register(ev_ctx,
669                                                  msg_ctx,
670                                                  t,
671                                                  v);
672                         if (!NT_STATUS_IS_OK(status)) {
673                                 return false;
674                         }
675                 }
676         }
677
678         return true;
679 }
680
681 static bool svcctl_init_cb(void *ptr)
682 {
683         struct messaging_context *msg_ctx =
684                 talloc_get_type_abort(ptr, struct messaging_context);
685         bool ok;
686
687         /* initialize the control hooks */
688         init_service_op_table();
689
690         ok = svcctl_init_winreg(msg_ctx);
691         if (!ok) {
692                 return false;
693         }
694
695         return true;
696 }
697
698 static bool svcctl_shutdown_cb(void *ptr)
699 {
700         shutdown_service_op_table();
701
702         return true;
703 }
704
705 static bool rpc_setup_svcctl(struct tevent_context *ev_ctx,
706                              struct messaging_context *msg_ctx)
707 {
708         const struct ndr_interface_table *t = &ndr_table_svcctl;
709         const char *pipe_name = "svcctl";
710         struct dcerpc_binding_vector *v;
711         enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
712         struct rpc_srv_callbacks svcctl_cb;
713         NTSTATUS status;
714         bool ok;
715
716         svcctl_cb.init         = svcctl_init_cb;
717         svcctl_cb.shutdown     = svcctl_shutdown_cb;
718         svcctl_cb.private_data = msg_ctx;
719
720         status = rpc_svcctl_init(&svcctl_cb);
721         if (!NT_STATUS_IS_OK(status)) {
722                 return false;
723         }
724
725         if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
726                 status = dcerpc_binding_vector_new(talloc_tos(), &v);
727                 if (!NT_STATUS_IS_OK(status)) {
728                         return false;
729                 }
730
731                 status = dcerpc_binding_vector_add_np_default(t, v);
732                 if (!NT_STATUS_IS_OK(status)) {
733                         return false;
734                 }
735
736                 ok = setup_dcerpc_ncalrpc_socket(ev_ctx,
737                                                  msg_ctx,
738                                                  pipe_name,
739                                                  NULL);
740                 if (!ok) {
741                         return false;
742                 }
743
744                 status = dcerpc_binding_vector_add_unix(t, v, pipe_name);
745                 if (!NT_STATUS_IS_OK(status)) {
746                         return false;
747                 }
748
749                 status = rpc_ep_register(ev_ctx,
750                                          msg_ctx,
751                                          t,
752                                          v);
753                 if (!NT_STATUS_IS_OK(status)) {
754                         return false;
755                 }
756         }
757
758         return true;
759 }
760
761 static bool rpc_setup_ntsvcs(struct tevent_context *ev_ctx,
762                              struct messaging_context *msg_ctx)
763 {
764         const struct ndr_interface_table *t = &ndr_table_ntsvcs;
765         struct dcerpc_binding_vector *v;
766         enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
767         NTSTATUS status;
768
769         status = rpc_ntsvcs_init(NULL);
770         if (!NT_STATUS_IS_OK(status)) {
771                 return false;
772         }
773
774         if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
775                 status = dcerpc_binding_vector_new(talloc_tos(), &v);
776                 if (!NT_STATUS_IS_OK(status)) {
777                         return false;
778                 }
779
780                 status = dcerpc_binding_vector_add_np_default(t, v);
781                 if (!NT_STATUS_IS_OK(status)) {
782                         return false;
783                 }
784
785                 status = rpc_ep_register(ev_ctx,
786                                          msg_ctx,
787                                          t,
788                                          v);
789                 if (!NT_STATUS_IS_OK(status)) {
790                         return false;
791                 }
792         }
793
794         return true;
795 }
796
797 static bool eventlog_init_cb(void *ptr)
798 {
799         struct messaging_context *msg_ctx =
800                 talloc_get_type_abort(ptr, struct messaging_context);
801         bool ok;
802
803         ok = eventlog_init_winreg(msg_ctx);
804         if (!ok) {
805                 return false;
806         }
807
808         return true;
809 }
810
811 static bool rpc_setup_eventlog(struct tevent_context *ev_ctx,
812                                struct messaging_context *msg_ctx)
813 {
814         const struct ndr_interface_table *t = &ndr_table_eventlog;
815         struct rpc_srv_callbacks eventlog_cb;
816         struct dcerpc_binding_vector *v;
817         enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
818         NTSTATUS status;
819
820         eventlog_cb.init         = eventlog_init_cb;
821         eventlog_cb.shutdown     = NULL;
822         eventlog_cb.private_data = msg_ctx;
823
824         status = rpc_eventlog_init(&eventlog_cb);
825         if (!NT_STATUS_IS_OK(status)) {
826                 return false;
827         }
828
829         if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
830                 status = dcerpc_binding_vector_new(talloc_tos(), &v);
831                 if (!NT_STATUS_IS_OK(status)) {
832                         return false;
833                 }
834
835                 status = dcerpc_binding_vector_add_np_default(t, v);
836                 if (!NT_STATUS_IS_OK(status)) {
837                         return false;
838                 }
839
840                 status = rpc_ep_register(ev_ctx,
841                                          msg_ctx,
842                                          t,
843                                          v);
844                 if (!NT_STATUS_IS_OK(status)) {
845                         return false;
846                 }
847         }
848
849         return true;
850 }
851
852 static bool rpc_setup_initshutdown(struct tevent_context *ev_ctx,
853                                    struct messaging_context *msg_ctx)
854 {
855         const struct ndr_interface_table *t = &ndr_table_initshutdown;
856         struct dcerpc_binding_vector *v;
857         enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
858         NTSTATUS status;
859
860         status = rpc_initshutdown_init(NULL);
861         if (!NT_STATUS_IS_OK(status)) {
862                 return false;
863         }
864
865         if (epm_mode != RPC_SERVICE_MODE_DISABLED) {
866                 status = dcerpc_binding_vector_new(talloc_tos(), &v);
867                 if (!NT_STATUS_IS_OK(status)) {
868                         return false;
869                 }
870
871                 status = dcerpc_binding_vector_add_np_default(t, v);
872                 if (!NT_STATUS_IS_OK(status)) {
873                         return false;
874                 }
875
876                 status = rpc_ep_register(ev_ctx,
877                                          msg_ctx,
878                                          t,
879                                          v);
880                 if (!NT_STATUS_IS_OK(status)) {
881                         return false;
882                 }
883         }
884
885         return true;
886 }
887
888 bool dcesrv_ep_setup(struct tevent_context *ev_ctx,
889                      struct messaging_context *msg_ctx)
890 {
891         enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
892         struct dcerpc_binding_vector *v;
893         const char *rpcsrv_type;
894         TALLOC_CTX *tmp_ctx;
895         NTSTATUS status;
896         bool ok;
897
898         tmp_ctx = talloc_stackframe();
899         if (tmp_ctx == NULL) {
900                 return false;
901         }
902
903         status = dcerpc_binding_vector_new(tmp_ctx,
904                                            &v);
905         if (!NT_STATUS_IS_OK(status)) {
906                 ok = false;
907                 goto done;
908         }
909
910         ok = rpc_setup_epmapper(ev_ctx, msg_ctx);
911         if (!ok) {
912                 goto done;
913         }
914
915         rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
916                                            "rpc_server",
917                                            "tcpip",
918                                            "no");
919
920         if ((strcasecmp_m(rpcsrv_type, "yes") == 0 ||
921              strcasecmp_m(rpcsrv_type, "true") == 0)
922             && epm_mode != RPC_SERVICE_MODE_DISABLED) {
923                 status = rpc_setup_tcpip_sockets(ev_ctx,
924                                                  msg_ctx,
925                                                  &ndr_table_winreg,
926                                                  v,
927                                                  0);
928                 if (!NT_STATUS_IS_OK(status)) {
929                         ok = false;
930                         goto done;
931                 }
932         }
933
934         ok = rpc_setup_winreg(ev_ctx, msg_ctx, v);
935         if (!ok) {
936                 goto done;
937         }
938
939         ok = rpc_setup_srvsvc(ev_ctx, msg_ctx, v);
940         if (!ok) {
941                 goto done;
942         }
943
944         ok = rpc_setup_lsarpc(ev_ctx, msg_ctx, v);
945         if (!ok) {
946                 goto done;
947         }
948
949         ok = rpc_setup_samr(ev_ctx, msg_ctx, v);
950         if (!ok) {
951                 goto done;
952         }
953
954         ok = rpc_setup_netlogon(ev_ctx, msg_ctx, v);
955         if (!ok) {
956                 goto done;
957         }
958
959         ok = rpc_setup_netdfs(ev_ctx, msg_ctx, v);
960         if (!ok) {
961                 goto done;
962         }
963
964 #ifdef DEVELOPER
965         ok = rpc_setup_rpcecho(ev_ctx, msg_ctx, v);
966         if (!ok) {
967                 goto done;
968         }
969 #endif
970
971         ok = rpc_setup_dssetup(ev_ctx, msg_ctx, v);
972         if (!ok) {
973                 goto done;
974         }
975
976         ok = rpc_setup_wkssvc(ev_ctx, msg_ctx, v);
977         if (!ok) {
978                 goto done;
979         }
980
981         ok = rpc_setup_spoolss(ev_ctx, msg_ctx);
982         if (!ok) {
983                 goto done;
984         }
985
986         ok = rpc_setup_svcctl(ev_ctx, msg_ctx);
987         if (!ok) {
988                 goto done;
989         }
990
991         ok = rpc_setup_ntsvcs(ev_ctx, msg_ctx);
992         if (!ok) {
993                 goto done;
994         }
995
996         ok = rpc_setup_eventlog(ev_ctx, msg_ctx);
997         if (!ok) {
998                 goto done;
999         }
1000
1001         ok = rpc_setup_initshutdown(ev_ctx, msg_ctx);
1002         if (!ok) {
1003                 goto done;
1004         }
1005
1006 done:
1007         talloc_free(tmp_ctx);
1008         return ok;
1009 }
1010
1011 /* vim: set ts=8 sw=8 noet cindent ft=c.doxygen: */