2 Unix SMB/Netbios implementation.
3 Generic infrastructure for RPC Daemons
4 Copyright (C) Simo Sorce 2011
5 Copyright (C) Andreas Schneider 2011
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.
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.
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/>.
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"
29 #define DBGC_CLASS DBGC_RPC_SRV
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,
37 static struct dcesrv_context *global_dcesrv_ctx = NULL;
39 struct dcesrv_context *global_dcesrv_context(void)
43 if (global_dcesrv_ctx == NULL) {
44 struct loadparm_context *lp_ctx = NULL;
46 DBG_INFO("Initializing DCE/RPC server context\n");
48 lp_ctx = loadparm_init_s3(NULL, loadparm_s3_helpers());
50 smb_panic("No memory");
54 * Note we MUST use the NULL context here, not the
55 * autofree context, to avoid side effects in forked
58 status = dcesrv_init_context(global_event_context(),
62 if (!NT_STATUS_IS_OK(status)) {
63 smb_panic("Failed to init DCE/RPC context");
66 talloc_steal(global_dcesrv_ctx, lp_ctx);
69 return global_dcesrv_ctx;
72 void global_dcesrv_context_free(void)
74 TALLOC_FREE(global_dcesrv_ctx);
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
82 struct rpc_service_defaults {
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" },
97 enum rpc_service_mode_e rpc_service_mode(const char *name)
99 const char *pipe_name = name;
100 const char *rpcsrv_type;
101 enum rpc_service_mode_e state;
103 enum server_role server_role = lp_server_role();
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";
113 def = lp_parm_const_string(GLOBAL_SECTION_SNUM,
114 "rpc_server", "default", 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;
122 /* if the default is unspecified then use 'embedded' */
129 * Only enable the netlogon server by default if we are a
130 * classic/NT4 domain controller
132 if (strcasecmp_m(name, "netlogon") == 0) {
133 switch (server_role) {
134 case ROLE_STANDALONE:
135 case ROLE_DOMAIN_MEMBER:
143 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
144 "rpc_server", pipe_name, def);
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;
151 state = RPC_SERVICE_MODE_DISABLED;
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
163 struct rpc_daemon_defaults {
165 const char *def_type;
166 } rpc_daemon_defaults[] = {
167 { "epmd", "disabled" },
168 /* { "spoolssd", "embedded" }, */
169 /* { "lsasd", "embedded" }, */
170 { "fssd", "disabled" },
175 enum rpc_daemon_type_e rpc_daemon_type(const char *name)
177 const char *rpcsrv_type;
178 enum rpc_daemon_type_e type;
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;
189 rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
190 "rpc_daemon", name, def);
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;
197 type = RPC_DAEMON_DISABLED;