drs-getncchanges: do not set the highestUsn to 0
[Samba/gbeck.git] / file_server / file_server.c
blob0777de576594b112c7eef3ed248022f390dfbeba
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"
33 generate a smbd config file for the file server
35 static const char *generate_smb_conf(struct task_server *task)
37 int fd;
38 struct loadparm_context *lp_ctx = task->lp_ctx;
39 const char *path = smbd_tmp_path(task, lp_ctx, "fileserver.conf");
41 if (path == NULL) {
42 return NULL;
45 fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0644);
46 if (fd == -1) {
47 DEBUG(0,("Failed to create %s", path));
48 return NULL;
51 fdprintf(fd, "[globals]\n");
52 fdprintf(fd, "# auto-generated config for fileserver\n");
53 fdprintf(fd, "server role check:inhibit=yes\n");
54 fdprintf(fd, "rpc_server:default = external\n");
55 fdprintf(fd, "rpc_server:svcctl = embedded\n");
56 fdprintf(fd, "rpc_server:srvsvc = embedded\n");
57 fdprintf(fd, "rpc_server:eventlog = embedded\n");
58 fdprintf(fd, "rpc_server:ntsvcs = embedded\n");
59 fdprintf(fd, "rpc_server:winreg = embedded\n");
60 fdprintf(fd, "rpc_server:spoolss = embedded\n");
61 fdprintf(fd, "rpc_daemon:spoolssd = embedded\n");
62 fdprintf(fd, "rpc_server:tcpip = no\n");
64 fdprintf(fd, "map hidden = no\n");
65 fdprintf(fd, "map system = no\n");
66 fdprintf(fd, "map readonly = no\n");
67 fdprintf(fd, "store dos attributes = yes\n");
69 fdprintf(fd, "include = %s\n", lpcfg_configfile(lp_ctx));
71 close(fd);
72 return path;
76 called if smbd exits
78 static void file_server_smbd_done(struct tevent_req *subreq)
80 struct task_server *task =
81 tevent_req_callback_data(subreq,
82 struct task_server);
83 int sys_errno;
84 int ret;
86 ret = samba_runcmd_recv(subreq, &sys_errno);
87 if (ret != 0) {
88 DEBUG(0,("file_server smbd daemon died with exit status %d\n", sys_errno));
89 } else {
90 DEBUG(0,("file_server smbd daemon exited normally\n"));
92 task_server_terminate(task, "smbd child process exited", true);
97 startup a copy of smbd as a child daemon
99 static void s3fs_task_init(struct task_server *task)
101 const char *fileserver_conf;
102 struct tevent_req *subreq;
103 const char *smbd_path;
104 const char *smbd_cmd[2] = { NULL, NULL };
106 task_server_set_title(task, "task[s3fs_parent]");
108 /* create a smb.conf for smbd to use */
109 fileserver_conf = generate_smb_conf(task);
111 smbd_path = talloc_asprintf(task, "%s/smbd", dyn_SBINDIR);
112 smbd_cmd[0] = smbd_path;
114 /* start it as a child process */
115 subreq = samba_runcmd_send(task, task->event_ctx, timeval_zero(), 1, 0,
116 smbd_cmd,
117 "--configfile", fileserver_conf,
118 "--foreground",
119 debug_get_output_is_stdout()?"--log-stdout":NULL,
120 NULL);
121 if (subreq == NULL) {
122 DEBUG(0, ("Failed to start smbd as child daemon\n"));
123 task_server_terminate(task, "Failed to startup s3fs smb task", true);
124 return;
127 tevent_req_set_callback(subreq, file_server_smbd_done, task);
129 DEBUG(1,("Started file server smbd with config %s\n", fileserver_conf));
132 /* called at smbd startup - register ourselves as a server service */
133 NTSTATUS server_service_s3fs_init(void);
135 NTSTATUS server_service_s3fs_init(void)
137 return register_server_service("s3fs", s3fs_task_init);