2 * Unix SMB/CIFS implementation.
4 * SMBD RPC service callbacks
6 * Copyright (c) 2011 Andreas Schneider <asn@samba.org>
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.
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.
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/>.
27 #include "librpc/rpc/dcerpc_ep.h"
29 #include "librpc/rpc/dcesrv_core.h"
30 #include "librpc/gen_ndr/ndr_epmapper_scompat.h"
32 #include "rpc_server/rpc_server.h"
33 #include "rpc_server/rpc_service_setup.h"
34 #include "rpc_server/rpc_sock_helper.h"
35 #include "rpc_server/epmapper/srv_epmapper.h"
36 #include "rpc_server/epmd.h"
39 #define DBGC_CLASS DBGC_RPC_SRV
41 #define DAEMON_NAME "epmd"
43 static void epmd_reopen_logs(void)
45 const struct loadparm_substitution
*lp_sub
=
46 loadparm_s3_global_substitution();
47 char *lfile
= lp_logfile(talloc_tos(), lp_sub
);
50 if (lfile
== NULL
|| lfile
[0] == '\0') {
51 rc
= asprintf(&lfile
, "%s/log.%s", get_dyn_LOGFILEBASE(), DAEMON_NAME
);
53 lp_set_logfile(lfile
);
57 if (strstr(lfile
, DAEMON_NAME
) == NULL
) {
58 rc
= asprintf(&lfile
, "%s.%s",
59 lp_logfile(talloc_tos(), lp_sub
), DAEMON_NAME
);
61 lp_set_logfile(lfile
);
70 static void epmd_smb_conf_updated(struct messaging_context
*msg
,
73 struct server_id server_id
,
76 DEBUG(10, ("Got message saying smb.conf was updated. Reloading.\n"));
77 change_to_root_user();
81 static void epmd_sig_term_handler(struct tevent_context
*ev
,
82 struct tevent_signal
*se
,
88 exit_server_cleanly("termination signal");
91 static void epmd_setup_sig_term_handler(struct tevent_context
*ev_ctx
)
93 struct tevent_signal
*se
;
95 se
= tevent_add_signal(ev_ctx
,
98 epmd_sig_term_handler
,
101 exit_server("failed to setup SIGTERM handler");
105 static void epmd_sig_hup_handler(struct tevent_context
*ev
,
106 struct tevent_signal
*se
,
112 change_to_root_user();
114 DEBUG(1,("Reloading printers after SIGHUP\n"));
118 static void epmd_setup_sig_hup_handler(struct tevent_context
*ev_ctx
,
119 struct messaging_context
*msg_ctx
)
121 struct tevent_signal
*se
;
123 se
= tevent_add_signal(ev_ctx
,
126 epmd_sig_hup_handler
,
129 exit_server("failed to setup SIGHUP handler");
133 void start_epmd(struct tevent_context
*ev_ctx
,
134 struct messaging_context
*msg_ctx
,
135 struct dcesrv_context
*dce_ctx
)
140 const struct dcesrv_endpoint_server
*ep_server
= NULL
;
141 struct dcesrv_endpoint
*e
= NULL
;
143 DEBUG(1, ("Forking Endpoint Mapper Daemon\n"));
148 DEBUG(0, ("Failed to fork Endpoint Mapper [%s], aborting ...\n",
158 status
= smbd_reinit_after_fork(msg_ctx
, ev_ctx
, true, "epmd");
159 if (!NT_STATUS_IS_OK(status
)) {
160 DEBUG(0,("reinit_after_fork() failed\n"));
161 smb_panic("reinit_after_fork() failed");
166 epmd_setup_sig_term_handler(ev_ctx
);
167 epmd_setup_sig_hup_handler(ev_ctx
, msg_ctx
);
169 messaging_register(msg_ctx
,
171 MSG_SMB_CONF_UPDATED
,
172 epmd_smb_conf_updated
);
174 DBG_INFO("Registering DCE/RPC endpoint servers\n");
176 /* Register the endpoint server in DCERPC core */
177 ep_server
= epmapper_get_ep_server();
178 if (ep_server
== NULL
) {
179 DBG_ERR("Failed to get 'epmapper' endpoint server\n");
183 status
= dcerpc_register_ep_server(ep_server
);
184 if (!NT_STATUS_IS_OK(status
)) {
185 DBG_ERR("Failed to register 'epmapper' endpoint server: %s\n",
190 DBG_INFO("Reinitializing DCE/RPC server context\n");
192 status
= dcesrv_reinit_context(dce_ctx
);
193 if (!NT_STATUS_IS_OK(status
)) {
194 DBG_ERR("Failed to reinit DCE/RPC context: %s\n",
199 DBG_INFO("Initializing DCE/RPC registered endpoint servers\n");
201 status
= dcesrv_init_ep_server(dce_ctx
, "epmapper");
202 if (!NT_STATUS_IS_OK(status
)) {
203 DBG_ERR("Failed to init DCE/RPC endpoint server: %s\n",
208 DBG_INFO("Initializing DCE/RPC connection endpoints\n");
210 for (e
= dce_ctx
->endpoint_list
; e
; e
= e
->next
) {
211 enum dcerpc_transport_t transport
=
212 dcerpc_binding_get_transport(e
->ep_description
);
213 dcerpc_ncacn_termination_fn term_fn
= NULL
;
215 if (transport
== NCACN_HTTP
) {
219 if (transport
== NCALRPC
) {
220 term_fn
= srv_epmapper_delete_endpoints
;
223 status
= dcesrv_setup_endpoint_sockets(ev_ctx
,
228 NULL
); /* termination_data */
229 if (!NT_STATUS_IS_OK(status
)) {
230 char *ep_string
= dcerpc_binding_string(
231 dce_ctx
, e
->ep_description
);
232 DBG_ERR("Failed to setup endpoint '%s': %s\n",
233 ep_string
, nt_errstr(status
));
234 TALLOC_FREE(ep_string
);
239 DEBUG(1, ("Endpoint Mapper Daemon Started (%u)\n", (unsigned int)getpid()));
242 rc
= tevent_loop_wait(ev_ctx
);
244 /* should not be reached */
245 DEBUG(0,("background_queue: tevent_loop_wait() exited with %d - %s\n",
246 rc
, (rc
== 0) ? "out of events" : strerror(errno
)));
251 /* vim: set ts=8 sw=8 noet cindent ft=c.doxygen: */