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