2 * File Server Shadow-Copy Daemon
4 * Copyright (C) David Disseldorp 2012-2015
7 * Copyright (c) 2011 Andreas Schneider <asn@samba.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * 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_fsrvp.h"
30 #include "rpc_server/rpc_server.h"
31 #include "rpc_server/rpc_sock_helper.h"
32 #include "rpc_server/fss/srv_fss_agent.h"
33 #include "rpc_server/fssd.h"
36 #define DBGC_CLASS DBGC_RPC_SRV
38 #define DAEMON_NAME "fssd"
40 void start_fssd(struct tevent_context
*ev_ctx
,
41 struct messaging_context
*msg_ctx
);
43 static void fssd_reopen_logs(void)
45 const struct loadparm_substitution
*lp_sub
=
46 loadparm_s3_global_substitution();
47 char *lfile
= lp_logfile(NULL
, 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", lp_logfile(NULL
, lp_sub
), DAEMON_NAME
);
60 lp_set_logfile(lfile
);
69 static void fssd_smb_conf_updated(struct messaging_context
*msg
,
72 struct server_id server_id
,
75 DEBUG(10, ("Got message saying smb.conf was updated. Reloading.\n"));
76 change_to_root_user();
80 static void fssd_sig_term_handler(struct tevent_context
*ev
,
81 struct tevent_signal
*se
,
87 exit_server_cleanly("termination signal");
90 static void fssd_setup_sig_term_handler(struct tevent_context
*ev_ctx
)
92 struct tevent_signal
*se
;
94 se
= tevent_add_signal(ev_ctx
,
97 fssd_sig_term_handler
,
100 exit_server("failed to setup SIGTERM handler");
104 static void fssd_sig_hup_handler(struct tevent_context
*ev
,
105 struct tevent_signal
*se
,
111 change_to_root_user();
113 DEBUG(1,("reopening logs after SIGHUP\n"));
117 static void fssd_setup_sig_hup_handler(struct tevent_context
*ev_ctx
,
118 struct messaging_context
*msg_ctx
)
120 struct tevent_signal
*se
;
122 se
= tevent_add_signal(ev_ctx
,
125 fssd_sig_hup_handler
,
128 exit_server("failed to setup SIGHUP handler");
132 static bool fss_shutdown_cb(void *ptr
)
138 static bool fss_init_cb(void *ptr
)
141 struct messaging_context
*msg_ctx
;
143 msg_ctx
= talloc_get_type_abort(ptr
, struct messaging_context
);
144 status
= srv_fssa_start(msg_ctx
);
145 return NT_STATUS_IS_OK(status
);
148 void start_fssd(struct tevent_context
*ev_ctx
,
149 struct messaging_context
*msg_ctx
)
151 struct rpc_srv_callbacks fss_cb
;
156 fss_cb
.init
= fss_init_cb
;
157 fss_cb
.shutdown
= fss_shutdown_cb
;
158 fss_cb
.private_data
= msg_ctx
;
160 DEBUG(1, ("Forking File Server Shadow-copy Daemon\n"));
165 DEBUG(0, ("failed to fork file server shadow-copy daemon [%s], "
166 "aborting ...\n", strerror(errno
)));
176 status
= smbd_reinit_after_fork(msg_ctx
, ev_ctx
, true, NULL
);
177 if (!NT_STATUS_IS_OK(status
)) {
178 DEBUG(0,("reinit_after_fork() failed\n"));
179 smb_panic("reinit_after_fork() failed");
184 fssd_setup_sig_term_handler(ev_ctx
);
185 fssd_setup_sig_hup_handler(ev_ctx
, msg_ctx
);
187 messaging_register(msg_ctx
,
189 MSG_SMB_CONF_UPDATED
,
190 fssd_smb_conf_updated
);
192 status
= rpc_FileServerVssAgent_init(&fss_cb
);
193 if (!NT_STATUS_IS_OK(status
)) {
194 DEBUG(0, ("Failed to register fssd rpc interface! (%s)\n",
199 /* case is normalized by smbd on connection */
200 status
= dcesrv_setup_ncacn_np_socket("fssagentrpc", ev_ctx
, msg_ctx
);
201 if (!NT_STATUS_IS_OK(status
)) {
202 DEBUG(0, ("Failed to open fssd named pipe!\n"));
206 DEBUG(1, ("File Server Shadow-copy Daemon Started (%d)\n",
210 rc
= tevent_loop_wait(ev_ctx
);
212 /* should not be reached */
213 DEBUG(0,("tevent_loop_wait() exited with %d - %s\n",
214 rc
, (rc
== 0) ? "out of events" : strerror(errno
)));