rpc_server: Avoid a cast
[vlendec/samba-autobuild/.git] / source3 / rpc_server / rpc_config.c
1 /*
2    Unix SMB/Netbios implementation.
3    Generic infrastructure for RPC Daemons
4    Copyright (C) Simo Sorce 2011
5    Copyright (C) Andreas Schneider 2011
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "includes.h"
22 #include "rpc_server/rpc_config.h"
23 #include "rpc_server/rpc_server.h"
24 #include "lib/param/param.h"
25 #include "librpc/rpc/dcesrv_core.h"
26 #include "lib/global_contexts.h"
27
28 #undef DBGC_CLASS
29 #define DBGC_CLASS DBGC_RPC_SRV
30
31 static struct dcesrv_context_callbacks srv_callbacks = {
32         .log.successful_authz = dcesrv_log_successful_authz,
33         .auth.gensec_prepare = dcesrv_auth_gensec_prepare,
34         .assoc_group.find = dcesrv_assoc_group_find,
35 };
36
37 static struct dcesrv_context *global_dcesrv_ctx = NULL;
38
39 struct dcesrv_context *global_dcesrv_context(void)
40 {
41         NTSTATUS status;
42
43         if (global_dcesrv_ctx == NULL) {
44                 struct loadparm_context *lp_ctx = NULL;
45
46                 DBG_INFO("Initializing DCE/RPC server context\n");
47
48                 lp_ctx = loadparm_init_s3(NULL, loadparm_s3_helpers());
49                 if (lp_ctx == NULL) {
50                         smb_panic("No memory");
51                 }
52
53                 /*
54                  * Note we MUST use the NULL context here, not the
55                  * autofree context, to avoid side effects in forked
56                  * children exiting.
57                  */
58                 status = dcesrv_init_context(global_event_context(),
59                                              lp_ctx,
60                                              &srv_callbacks,
61                                              &global_dcesrv_ctx);
62                 if (!NT_STATUS_IS_OK(status)) {
63                         smb_panic("Failed to init DCE/RPC context");
64                 }
65
66                 talloc_steal(global_dcesrv_ctx, lp_ctx);
67         }
68
69         return global_dcesrv_ctx;
70 }
71
72 void global_dcesrv_context_free(void)
73 {
74         TALLOC_FREE(global_dcesrv_ctx);
75 }
76
77 /* the default is "embedded" so this table
78  * lists only services that are not using
79  * the default in order to keep enumerating it
80  * in rpc_service_mode() as short as possible
81  */
82 struct rpc_service_defaults {
83         const char *name;
84         const char *def_mode;
85 } rpc_service_defaults[] = {
86         { "epmapper", "disabled" },
87         /* { "mdssvc", "embedded" }, */
88         /* { "spoolss", "embedded" }, */
89         /* { "lsarpc", "embedded" }, */
90         /* { "samr", "embedded" }, */
91         /* { "netlogon", "embedded" }, */
92         { "fssagentrpc", "external" },
93
94         { NULL, NULL }
95 };
96
97 enum rpc_service_mode_e rpc_service_mode(const char *name)
98 {
99         const char *pipe_name = name;
100         const char *rpcsrv_type;
101         enum rpc_service_mode_e state;
102         const char *def;
103         enum server_role server_role = lp_server_role();
104         int i;
105
106         /* Handle pipes with multiple names */
107         if (strcmp(pipe_name, "lsass") == 0) {
108                 pipe_name = "lsarpc";
109         } else if (strcmp(pipe_name, "plugplay") == 0) {
110                 pipe_name = "ntsvcs";
111         }
112
113         def = lp_parm_const_string(GLOBAL_SECTION_SNUM,
114                                    "rpc_server", "default", NULL);
115         if (def == NULL) {
116                 for (i = 0; rpc_service_defaults[i].name; i++) {
117                         if (strcasecmp_m(pipe_name, rpc_service_defaults[i].name) == 0) {
118                                 def = rpc_service_defaults[i].def_mode;
119                                 break;
120                         }
121                 }
122                 /* if the default is unspecified then use 'embedded' */
123                 if (def == NULL) {
124                         def = "embedded";
125                 }
126         }
127
128         /*
129          * Only enable the netlogon server by default if we are a
130          * classic/NT4 domain controller
131          */
132         if (strcasecmp_m(name, "netlogon") == 0) {
133                 switch (server_role) {
134                 case ROLE_STANDALONE:
135                 case ROLE_DOMAIN_MEMBER:
136                         def = "disabled";
137                         break;
138                 default:
139                         break;
140                 }
141         }
142
143         rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
144                                            "rpc_server", pipe_name, def);
145
146         if (strcasecmp_m(rpcsrv_type, "embedded") == 0) {
147                 state = RPC_SERVICE_MODE_EMBEDDED;
148         } else if (strcasecmp_m(rpcsrv_type, "external") == 0) {
149                 state = RPC_SERVICE_MODE_EXTERNAL;
150         } else {
151                 state = RPC_SERVICE_MODE_DISABLED;
152         }
153
154         return state;
155 }
156
157
158 /* the default is "embedded" so this table
159  * lists only daemons that are not using
160  * the default in order to keep enumerating it
161  * in rpc_daemon_type() as short as possible
162  */
163 struct rpc_daemon_defaults {
164         const char *name;
165         const char *def_type;
166 } rpc_daemon_defaults[] = {
167         { "epmd", "disabled" },
168         /* { "spoolssd", "embedded" }, */
169         /* { "lsasd", "embedded" }, */
170         { "fssd", "disabled" },
171
172         { NULL, NULL }
173 };
174
175 enum rpc_daemon_type_e rpc_daemon_type(const char *name)
176 {
177         const char *rpcsrv_type;
178         enum rpc_daemon_type_e type;
179         const char *def;
180         int i;
181
182         def = "embedded";
183         for (i = 0; rpc_daemon_defaults[i].name; i++) {
184                 if (strcasecmp_m(name, rpc_daemon_defaults[i].name) == 0) {
185                         def = rpc_daemon_defaults[i].def_type;
186                 }
187         }
188
189         rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
190                                            "rpc_daemon", name, def);
191
192         if (strcasecmp_m(rpcsrv_type, "embedded") == 0) {
193                 type = RPC_DAEMON_EMBEDDED;
194         } else if (strcasecmp_m(rpcsrv_type, "fork") == 0) {
195                 type = RPC_DAEMON_FORK;
196         } else {
197                 type = RPC_DAEMON_DISABLED;
198         }
199
200         return type;
201 }