lib/texpect: prefer bsd/libutil.h if available
[obnox/samba/samba-obnox.git] / file_server / file_server.c
index 46969f3920ce3c3a761884289ba0efd2d15039ad..aab5f39ac76cf2a5c2919f671e6c1ecfb83df200 100644 (file)
 #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, "passdb backend = samba4\n");
-        fdprintf(fd, "rpc_server:default = external\n");
-       fdprintf(fd, "rpc_server:svcctl = embedded\n");
-       fdprintf(fd, "rpc_server:srvsvc = embedded\n");
-       fdprintf(fd, "rpc_server:eventlog = embedded\n");
-       fdprintf(fd, "rpc_server:ntsvcs = embedded\n");
-       fdprintf(fd, "rpc_server:winreg = embedded\n");
-       fdprintf(fd, "rpc_server:spoolss = embedded\n");
-       fdprintf(fd, "rpc_daemon:spoolssd = disabled\n");
-       fdprintf(fd, "rpc_server:tcpip = no\n");
-
-       /* If we are using xattr_tdb:file or posix:eadb then we need to load another VFS object */
-       if (lpcfg_parm_string(lp_ctx, NULL, "xattr_tdb", "file")) {
-               fdprintf(fd, "vfs objects = acl_xattr xattr_tdb\n");
-       } else if (lpcfg_parm_string(lp_ctx, NULL, "posix", "eadb")) {
-               fdprintf(fd, "vfs objects = acl_xattr posix_eadb\n");
-       } else {
-               fdprintf(fd, "vfs objects = acl_xattr\n");
-       }
-
-       fdprintf(fd, "map hidden = no\n");
-       fdprintf(fd, "map system = no\n");
-       fdprintf(fd, "map readonly = no\n");
-       fdprintf(fd, "store dos attributes = yes\n");
-
-       fdprintf(fd, "include = %s\n", lpcfg_configfile(lp_ctx));
-
-       fdprintf(fd, "[IPC$]\n");
-       fdprintf(fd, " vfs objects = dfs_samba4\n");
-
-       close(fd);
-       return path;
-}
+#include "nsswitch/winbind_client.h"
 
 /*
   called if smbd exits
  */
 static void file_server_smbd_done(struct tevent_req *subreq)
 {
+       struct task_server *task =
+               tevent_req_callback_data(subreq,
+               struct task_server);
        int sys_errno;
        int ret;
 
@@ -97,6 +47,7 @@ static void file_server_smbd_done(struct tevent_req *subreq)
        } else {
                DEBUG(0,("file_server smbd daemon exited normally\n"));
        }
+       task_server_terminate(task, "smbd child process exited", true);
 }
 
 
@@ -105,37 +56,40 @@ static void file_server_smbd_done(struct tevent_req *subreq)
 */
 static void s3fs_task_init(struct task_server *task)
 {
-       const char *fileserver_conf;
-       struct tevent_req *req;
+       struct tevent_req *subreq;
        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;
 
+       /* the child should be able to call through nss_winbind */
+       (void)winbind_on();
        /* start it as a child process */
-       req = samba_runcmd_send(task, task->event_ctx, timeval_zero(), 1, 0,
+       subreq = samba_runcmd_send(task, task->event_ctx, timeval_zero(), 1, 0,
                                smbd_cmd,
-                               "--configfile", fileserver_conf,
+                               "-D",
+                               "--option=server role check:inhibit=yes",
                                "--foreground",
                                debug_get_output_is_stdout()?"--log-stdout":NULL,
                                NULL);
-       if (req == NULL) {
+       /* the parent should not be able to call through nss_winbind */
+       if (!winbind_off()) {
+               DEBUG(0,("Failed to re-disable recursive winbindd calls after forking smbd\n"));
+               task_server_terminate(task, "Failed to re-disable recursive winbindd calls", true);
+               return;
+       }
+       if (subreq == NULL) {
                DEBUG(0, ("Failed to start smbd as child daemon\n"));
-               goto failed;
+               task_server_terminate(task, "Failed to startup s3fs smb task", true);
+               return;
        }
 
-       tevent_req_set_callback(req, file_server_smbd_done, task);
+       tevent_req_set_callback(subreq, 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);
+       DEBUG(5,("Started file server child smbd\n"));
 }
 
 /* called at smbd startup - register ourselves as a server service */