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/>.
29 #include "librpc/rpc/dcerpc_ep.h"
30 #include "../librpc/gen_ndr/srv_fsrvp.h"
31 #include "rpc_server/rpc_server.h"
32 #include "rpc_server/rpc_sock_helper.h"
33 #include "rpc_server/fss/srv_fss_agent.h"
35 #define DAEMON_NAME "fssd"
37 void start_fssd(struct tevent_context
*ev_ctx
,
38 struct messaging_context
*msg_ctx
);
40 static void fssd_reopen_logs(void)
42 char *lfile
= lp_logfile(NULL
);
45 if (lfile
== NULL
|| lfile
[0] == '\0') {
46 rc
= asprintf(&lfile
, "%s/log.%s", get_dyn_LOGFILEBASE(), DAEMON_NAME
);
48 lp_set_logfile(lfile
);
52 if (strstr(lfile
, DAEMON_NAME
) == NULL
) {
53 rc
= asprintf(&lfile
, "%s.%s", lp_logfile(NULL
), DAEMON_NAME
);
55 lp_set_logfile(lfile
);
64 static void fssd_smb_conf_updated(struct messaging_context
*msg
,
67 struct server_id server_id
,
70 DEBUG(10, ("Got message saying smb.conf was updated. Reloading.\n"));
71 change_to_root_user();
75 static void fssd_sig_term_handler(struct tevent_context
*ev
,
76 struct tevent_signal
*se
,
82 rpc_FileServerVssAgent_shutdown();
84 exit_server_cleanly("termination signal");
87 static void fssd_setup_sig_term_handler(struct tevent_context
*ev_ctx
)
89 struct tevent_signal
*se
;
91 se
= tevent_add_signal(ev_ctx
,
94 fssd_sig_term_handler
,
97 exit_server("failed to setup SIGTERM handler");
101 static void fssd_sig_hup_handler(struct tevent_context
*ev
,
102 struct tevent_signal
*se
,
108 change_to_root_user();
110 DEBUG(1,("reopening logs after SIGHUP\n"));
114 static void fssd_setup_sig_hup_handler(struct tevent_context
*ev_ctx
,
115 struct messaging_context
*msg_ctx
)
117 struct tevent_signal
*se
;
119 se
= tevent_add_signal(ev_ctx
,
122 fssd_sig_hup_handler
,
125 exit_server("failed to setup SIGHUP handler");
129 static bool fss_shutdown_cb(void *ptr
)
135 static bool fss_init_cb(void *ptr
)
138 struct messaging_context
*msg_ctx
;
140 msg_ctx
= talloc_get_type_abort(ptr
, struct messaging_context
);
141 status
= srv_fssa_start(msg_ctx
);
142 return NT_STATUS_IS_OK(status
);
145 void start_fssd(struct tevent_context
*ev_ctx
,
146 struct messaging_context
*msg_ctx
)
148 struct rpc_srv_callbacks fss_cb
;
154 fss_cb
.init
= fss_init_cb
;
155 fss_cb
.shutdown
= fss_shutdown_cb
;
156 fss_cb
.private_data
= msg_ctx
;
158 DEBUG(1, ("Forking File Server Shadow-copy Daemon\n"));
163 DEBUG(0, ("failed to fork file server shadow-copy daemon [%s], "
164 "aborting ...\n", strerror(errno
)));
174 status
= smbd_reinit_after_fork(msg_ctx
, ev_ctx
, true, NULL
);
175 if (!NT_STATUS_IS_OK(status
)) {
176 DEBUG(0,("reinit_after_fork() failed\n"));
177 smb_panic("reinit_after_fork() failed");
182 fssd_setup_sig_term_handler(ev_ctx
);
183 fssd_setup_sig_hup_handler(ev_ctx
, msg_ctx
);
185 ok
= serverid_register(messaging_server_id(msg_ctx
),
187 FLAG_MSG_PRINT_GENERAL
);
189 DEBUG(0, ("Failed to register serverid in fssd!\n"));
193 messaging_register(msg_ctx
,
195 MSG_SMB_CONF_UPDATED
,
196 fssd_smb_conf_updated
);
198 status
= rpc_FileServerVssAgent_init(&fss_cb
);
199 if (!NT_STATUS_IS_OK(status
)) {
200 DEBUG(0, ("Failed to register fssd rpc interface! (%s)\n",
205 /* case is normalized by smbd on connection */
206 ok
= setup_named_pipe_socket("fssagentrpc", ev_ctx
, msg_ctx
);
208 DEBUG(0, ("Failed to open fssd named pipe!\n"));
212 DEBUG(1, ("File Server Shadow-copy Daemon Started (%d)\n",
216 rc
= tevent_loop_wait(ev_ctx
);
218 /* should not be reached */
219 DEBUG(0,("tevent_loop_wait() exited with %d - %s\n",
220 rc
, (rc
== 0) ? "out of events" : strerror(errno
)));