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