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/>.
28 #include "librpc/rpc/dcerpc_ep.h"
29 #include "../librpc/gen_ndr/srv_epmapper.h"
30 #include "rpc_server/rpc_server.h"
31 #include "rpc_server/rpc_sock_helper.h"
32 #include "rpc_server/epmapper/srv_epmapper.h"
34 #define DAEMON_NAME "epmd"
36 void start_epmd(struct tevent_context
*ev_ctx
,
37 struct messaging_context
*msg_ctx
);
39 static void epmd_reopen_logs(void)
41 char *lfile
= lp_logfile();
44 if (lfile
== NULL
|| lfile
[0] == '\0') {
45 rc
= asprintf(&lfile
, "%s/log.%s", get_dyn_LOGFILEBASE(), DAEMON_NAME
);
47 lp_set_logfile(lfile
);
51 if (strstr(lfile
, DAEMON_NAME
) == NULL
) {
52 rc
= asprintf(&lfile
, "%s.%s", lp_logfile(), DAEMON_NAME
);
54 lp_set_logfile(lfile
);
63 static void epmd_smb_conf_updated(struct messaging_context
*msg
,
66 struct server_id server_id
,
69 DEBUG(10, ("Got message saying smb.conf was updated. Reloading.\n"));
70 change_to_root_user();
74 static void epmd_sig_term_handler(struct tevent_context
*ev
,
75 struct tevent_signal
*se
,
81 rpc_epmapper_shutdown();
83 exit_server_cleanly("termination signal");
86 static void epmd_setup_sig_term_handler(struct tevent_context
*ev_ctx
)
88 struct tevent_signal
*se
;
90 se
= tevent_add_signal(ev_ctx
,
93 epmd_sig_term_handler
,
96 exit_server("failed to setup SIGTERM handler");
100 static void epmd_sig_hup_handler(struct tevent_context
*ev
,
101 struct tevent_signal
*se
,
107 change_to_root_user();
109 DEBUG(1,("Reloading printers after SIGHUP\n"));
113 static void epmd_setup_sig_hup_handler(struct tevent_context
*ev_ctx
,
114 struct messaging_context
*msg_ctx
)
116 struct tevent_signal
*se
;
118 se
= tevent_add_signal(ev_ctx
,
121 epmd_sig_hup_handler
,
124 exit_server("failed to setup SIGHUP handler");
128 static bool epmapper_shutdown_cb(void *ptr
) {
129 srv_epmapper_cleanup();
134 void start_epmd(struct tevent_context
*ev_ctx
,
135 struct messaging_context
*msg_ctx
)
137 struct rpc_srv_callbacks epmapper_cb
;
143 epmapper_cb
.init
= NULL
;
144 epmapper_cb
.shutdown
= epmapper_shutdown_cb
;
145 epmapper_cb
.private_data
= NULL
;
147 DEBUG(1, ("Forking Endpoint Mapper Daemon\n"));
152 DEBUG(0, ("Failed to fork Endpoint Mapper [%s], aborting ...\n",
163 close_low_fds(false);
165 status
= reinit_after_fork(msg_ctx
,
169 if (!NT_STATUS_IS_OK(status
)) {
170 DEBUG(0,("reinit_after_fork() failed\n"));
171 smb_panic("reinit_after_fork() failed");
176 epmd_setup_sig_term_handler(ev_ctx
);
177 epmd_setup_sig_hup_handler(ev_ctx
, msg_ctx
);
179 ok
= serverid_register(procid_self(),
181 FLAG_MSG_PRINT_GENERAL
);
183 DEBUG(0, ("Failed to register serverid in epmd!\n"));
187 messaging_register(msg_ctx
,
189 MSG_SMB_CONF_UPDATED
,
190 epmd_smb_conf_updated
);
192 status
= rpc_epmapper_init(&epmapper_cb
);
193 if (!NT_STATUS_IS_OK(status
)) {
194 DEBUG(0, ("Failed to register epmd rpc inteface! (%s)\n",
199 status
= rpc_setup_tcpip_sockets(ev_ctx
,
204 if (!NT_STATUS_IS_OK(status
)) {
205 DEBUG(0, ("Failed to open epmd tcpip sockets!\n"));
209 ok
= setup_dcerpc_ncalrpc_socket(ev_ctx
,
212 srv_epmapper_delete_endpoints
);
214 DEBUG(0, ("Failed to open epmd ncalrpc pipe!\n"));
218 ok
= setup_named_pipe_socket("epmapper", ev_ctx
, msg_ctx
);
220 DEBUG(0, ("Failed to open epmd named pipe!\n"));
224 DEBUG(1, ("Endpoint Mapper Daemon Started (%d)\n", getpid()));
227 rc
= tevent_loop_wait(ev_ctx
);
229 /* should not be reached */
230 DEBUG(0,("background_queue: tevent_loop_wait() exited with %d - %s\n",
231 rc
, (rc
== 0) ? "out of events" : strerror(errno
)));
236 /* vim: set ts=8 sw=8 noet cindent ft=c.doxygen: */