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