LCOV - code coverage report
Current view: top level - file_server - file_server.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 23 42 54.8 %
Date: 2024-02-28 12:06:22 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    run s3 file server within Samba4
       5             : 
       6             :    Copyright (C) Andrew Tridgell        2011
       7             : 
       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.
      12             : 
      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.
      17             : 
      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/>.
      20             : */
      21             : 
      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/samba/service.h"
      28             : #include "source4/samba/process_model.h"
      29             : #include "dynconfig.h"
      30             : #include "nsswitch/winbind_client.h"
      31             : 
      32             : /*
      33             :   called if smbd exits
      34             :  */
      35           0 : static void file_server_smbd_done(struct tevent_req *subreq)
      36             : {
      37           0 :         struct task_server *task =
      38           0 :                 tevent_req_callback_data(subreq,
      39             :                 struct task_server);
      40           0 :         int sys_errno;
      41           0 :         int ret;
      42             : 
      43           0 :         ret = samba_runcmd_recv(subreq, &sys_errno);
      44           0 :         if (ret != 0) {
      45           0 :                 DEBUG(0,("file_server smbd daemon died with exit status %d\n", sys_errno));
      46             :         } else {
      47           0 :                 DEBUG(0,("file_server smbd daemon exited normally\n"));
      48             :         }
      49           0 :         task_server_terminate(task, "smbd child process exited", true);
      50           0 : }
      51             : 
      52             : 
      53             : /*
      54             :   startup a copy of smbd as a child daemon
      55             : */
      56          50 : static NTSTATUS s3fs_task_init(struct task_server *task)
      57             : {
      58           2 :         struct tevent_req *subreq;
      59           2 :         const char *smbd_path;
      60          50 :         const char *smbd_cmd[2] = { NULL, NULL };
      61          50 :         const char *config_file = "";
      62             : 
      63          50 :         task_server_set_title(task, "task[s3fs_parent]");
      64             : 
      65          50 :         smbd_path = talloc_asprintf(task, "%s/smbd", dyn_SBINDIR);
      66          50 :         if (smbd_path == NULL) {
      67           0 :                 return NT_STATUS_NO_MEMORY;
      68             :         }
      69          50 :         smbd_cmd[0] = smbd_path;
      70             : 
      71          50 :         if (!is_default_dyn_CONFIGFILE()) {
      72          50 :                 config_file = talloc_asprintf(task,
      73             :                                               "--configfile=%s",
      74             :                                               get_dyn_CONFIGFILE());
      75          50 :                 if (config_file == NULL) {
      76           0 :                         return NT_STATUS_NO_MEMORY;
      77             :                 }
      78             :         }
      79             : 
      80             :         /* the child should be able to call through nss_winbind */
      81          50 :         (void)winbind_on();
      82             :         /* start it as a child process */
      83          52 :         subreq = samba_runcmd_send(task, task->event_ctx, timeval_zero(), 1, 0,
      84             :                                 smbd_cmd,
      85             :                                 "-D",
      86             :                                 "--option=server role check:inhibit=yes",
      87             :                                 "--foreground",
      88             :                                 config_file,
      89          50 :                                 debug_get_output_is_stdout()?"--debug-stdout":NULL,
      90             :                                 NULL);
      91             :         /* the parent should not be able to call through nss_winbind */
      92          50 :         if (!winbind_off()) {
      93           0 :                 DEBUG(0,("Failed to re-disable recursive winbindd calls after forking smbd\n"));
      94           0 :                 task_server_terminate(task, "Failed to re-disable recursive winbindd calls", true);
      95           0 :                 return NT_STATUS_UNSUCCESSFUL;
      96             :         }
      97          50 :         if (subreq == NULL) {
      98           0 :                 DEBUG(0, ("Failed to start smbd as child daemon\n"));
      99           0 :                 task_server_terminate(task, "Failed to startup s3fs smb task", true);
     100           0 :                 return NT_STATUS_UNSUCCESSFUL;
     101             :         }
     102             : 
     103          50 :         tevent_req_set_callback(subreq, file_server_smbd_done, task);
     104             : 
     105          50 :         DEBUG(5,("Started file server child smbd\n"));
     106             : 
     107          50 :         return NT_STATUS_OK;
     108             : }
     109             : 
     110             : /* called at smbd startup - register ourselves as a server service */
     111             : NTSTATUS server_service_s3fs_init(TALLOC_CTX *);
     112             : 
     113          66 : NTSTATUS server_service_s3fs_init(TALLOC_CTX *ctx)
     114             : {
     115          66 :         struct service_details details = {
     116             :                 .inhibit_fork_on_accept = true,
     117             :                 .inhibit_pre_fork = true,
     118             :                 .task_init = s3fs_task_init,
     119             :                 .post_fork = NULL
     120             :         };
     121          66 :         return register_server_service(ctx, "s3fs", &details);
     122             : }

Generated by: LCOV version 1.14