ctdb-packaging: Remove mkversion.sh script
[Samba.git] / file_server / file_server.c
blob83641f819f618d5345ec7916194dc18792b82bde
1 /*
2 Unix SMB/CIFS implementation.
4 run s3 file server within Samba4
6 Copyright (C) Andrew Tridgell 2011
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/>.
22 #include "includes.h"
23 #include "talloc.h"
24 #include "tevent.h"
25 #include "system/filesys.h"
26 #include "lib/param/param.h"
27 #include "source4/smbd/service.h"
28 #include "source4/smbd/process_model.h"
29 #include "file_server/file_server.h"
30 #include "dynconfig.h"
31 #include "nsswitch/winbind_client.h"
34 called if smbd exits
36 static void file_server_smbd_done(struct tevent_req *subreq)
38 struct task_server *task =
39 tevent_req_callback_data(subreq,
40 struct task_server);
41 int sys_errno;
42 int ret;
44 ret = samba_runcmd_recv(subreq, &sys_errno);
45 if (ret != 0) {
46 DEBUG(0,("file_server smbd daemon died with exit status %d\n", sys_errno));
47 } else {
48 DEBUG(0,("file_server smbd daemon exited normally\n"));
50 task_server_terminate(task, "smbd child process exited", true);
55 startup a copy of smbd as a child daemon
57 static void s3fs_task_init(struct task_server *task)
59 struct tevent_req *subreq;
60 const char *smbd_path;
61 const char *smbd_cmd[2] = { NULL, NULL };
63 task_server_set_title(task, "task[s3fs_parent]");
65 smbd_path = talloc_asprintf(task, "%s/smbd", dyn_SBINDIR);
66 smbd_cmd[0] = smbd_path;
68 /* the child should be able to call through nss_winbind */
69 (void)winbind_on();
70 /* start it as a child process */
71 subreq = samba_runcmd_send(task, task->event_ctx, timeval_zero(), 1, 0,
72 smbd_cmd,
73 "-D",
74 "--option=server role check:inhibit=yes",
75 "--foreground",
76 debug_get_output_is_stdout()?"--log-stdout":NULL,
77 NULL);
78 /* the parent should not be able to call through nss_winbind */
79 if (!winbind_off()) {
80 DEBUG(0,("Failed to re-disable recursive winbindd calls after forking smbd\n"));
81 task_server_terminate(task, "Failed to re-disable recursive winbindd calls", true);
82 return;
84 if (subreq == NULL) {
85 DEBUG(0, ("Failed to start smbd as child daemon\n"));
86 task_server_terminate(task, "Failed to startup s3fs smb task", true);
87 return;
90 tevent_req_set_callback(subreq, file_server_smbd_done, task);
92 DEBUG(5,("Started file server child smbd\n"));
95 /* called at smbd startup - register ourselves as a server service */
96 NTSTATUS server_service_s3fs_init(TALLOC_CTX *);
98 NTSTATUS server_service_s3fs_init(TALLOC_CTX *ctx)
100 return register_server_service(ctx, "s3fs", s3fs_task_init);