s3fs: added file_server directory
authorAndrew Tridgell <tridge@samba.org>
Mon, 2 May 2011 23:35:07 +0000 (09:35 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 28 Feb 2012 11:01:08 +0000 (12:01 +0100)
this contains a file server backend that forks and starts smbd

Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>

file_server/file_server.c [new file with mode: 0644]
file_server/file_server.h [new file with mode: 0644]
file_server/wscript_build [new file with mode: 0644]
source4/smb_server/service_smb.c
wscript_build

diff --git a/file_server/file_server.c b/file_server/file_server.c
new file mode 100644 (file)
index 0000000..2c5ec43
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+   Unix SMB/CIFS implementation.
+
+   run s3 file server within Samba4
+
+   Copyright (C) Andrew Tridgell       2011
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "talloc.h"
+#include "tevent.h"
+#include "system/filesys.h"
+#include "lib/param/param.h"
+#include "source4/smbd/service.h"
+#include "source4/smbd/process_model.h"
+#include "file_server/file_server.h"
+#include "dynconfig.h"
+
+/*
+  generate a smbd config file for the file server
+ */
+static const char *generate_smb_conf(struct task_server *task)
+{
+       int fd;
+       struct loadparm_context *lp_ctx = task->lp_ctx;
+       const char *path = smbd_tmp_path(task, lp_ctx, "fileserver.conf");
+
+       if (path == NULL) {
+               return NULL;
+       }
+
+       fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0644);
+       if (fd == -1) {
+               DEBUG(0,("Failed to create %s", path));
+               return NULL;
+       }
+
+       fdprintf(fd, "# auto-generated config for fileserver\n");
+       fdprintf(fd, "auth methods = guest samba4\n");
+       fdprintf(fd, "passdb backend = samba4\n");
+        fdprintf(fd, "rpc_server:default = external\n");
+        fdprintf(fd, "rpc_server:dssetup = disabled\n");
+       fdprintf(fd, "rpc_server:spoolss = embedded\n");
+       fdprintf(fd, "rpc_daemon:spoolssd = disabled\n");
+       fdprintf(fd, "rpc_server:tcpip = no\n");
+
+       fdprintf(fd, "include = %s\n", lpcfg_configfile(lp_ctx));
+       close(fd);
+       return path;
+}
+
+/*
+  called if smbd exits
+ */
+static void file_server_smbd_done(struct tevent_req *subreq)
+{
+       int sys_errno;
+       int ret;
+
+       ret = samba_runcmd_recv(subreq, &sys_errno);
+       if (ret != 0) {
+               DEBUG(0,("file_server smbd daemon died with exit status %d\n", sys_errno));
+       } else {
+               DEBUG(0,("file_server smbd daemon exited normally\n"));
+       }
+}
+
+
+/*
+  startup a copy of smbd as a child daemon
+*/
+static void s3fs_task_init(struct task_server *task)
+{
+       const char *fileserver_conf;
+       struct tevent_req *req;
+       const char *smbd_path;
+       const char *smbd_cmd[2] = { NULL, NULL };
+
+       task_server_set_title(task, "task[s3fs_parent]");
+
+       /* create a smb.conf for smbd to use */
+       fileserver_conf = generate_smb_conf(task);
+
+       smbd_path = talloc_asprintf(task, "%s/smbd", dyn_SBINDIR);
+       smbd_cmd[0] = smbd_path;
+
+       /* start it as a child process */
+       req = samba_runcmd_send(task, task->event_ctx, timeval_zero(), 1, 0,
+                               smbd_cmd,
+                               "--configfile", fileserver_conf,
+                               "--foreground", NULL);
+       if (req == NULL) {
+               DEBUG(0, ("Failed to start smbd as child daemon\n"));
+               goto failed;
+       }
+
+       tevent_req_set_callback(req, file_server_smbd_done, task);
+
+       DEBUG(1,("Started file server smbd with config %s\n", fileserver_conf));
+       return;
+failed:
+       task_server_terminate(task, "Failed to startup s3fs smb task", true);
+}
+
+/* called at smbd startup - register ourselves as a server service */
+NTSTATUS server_service_s3fs_init(void);
+
+NTSTATUS server_service_s3fs_init(void)
+{
+       return register_server_service("s3fs", s3fs_task_init);
+}
diff --git a/file_server/file_server.h b/file_server/file_server.h
new file mode 100644 (file)
index 0000000..7da9437
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+   Unix SMB/CIFS implementation.
+
+   run s3 file server within Samba4
+
+   Copyright (C) Andrew Tridgell       2011
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/*
+  open the s3 smb server sockets
+*/
+void s3_smbd_task_init(struct task_server *task);
diff --git a/file_server/wscript_build b/file_server/wscript_build
new file mode 100644 (file)
index 0000000..f76c847
--- /dev/null
@@ -0,0 +1,10 @@
+#!/usr/bin/env python
+
+bld.SAMBA_MODULE('service_s3fs',
+                 source='file_server.c',
+                 autoproto='file_server_proto.h',
+                 subsystem='service',
+                 init_function='server_service_s3fs_init',
+                 deps='samba-hostconfig service talloc UTIL_RUNCMD',
+                 internal_module=False
+                 )
index cbbd2cd..c910b0f 100644 (file)
@@ -33,6 +33,7 @@
 #include "param/share.h"
 #include "dsdb/samdb/samdb.h"
 #include "param/param.h"
+#include "file_server/file_server.h"
 
 /*
   open the smb server sockets
index 5e0c05c..ab6f9be 100644 (file)
@@ -119,6 +119,7 @@ bld.RECURSE('lib')
 bld.RECURSE('libds/common')
 bld.RECURSE('source3')
 bld.RECURSE('dfs_server')
+bld.RECURSE('file_server')
 
 bld.RECURSE('testsuite/headers')
 bld.RECURSE('testsuite/libsmbclient/src')