LCOV - code coverage report
Current view: top level - source4/winbind - winbindd.c (source / functions) Hit Total Coverage
Test: coverage report for master 98b443d9 Lines: 23 40 57.5 %
Date: 2024-05-31 13:13:24 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    run s3 winbindd server within Samba4
       5             : 
       6             :    Copyright (C) Andrew Tridgell        2011
       7             :    Copyright (C) Andrew Bartlett        2014
       8             : 
       9             :    This program is free software; you can redistribute it and/or modify
      10             :    it under the terms of the GNU General Public License as published by
      11             :    the Free Software Foundation; either version 3 of the License, or
      12             :    (at your option) any later version.
      13             : 
      14             :    This program is distributed in the hope that it will be useful,
      15             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17             :    GNU General Public License for more details.
      18             : 
      19             :    You should have received a copy of the GNU General Public License
      20             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      21             : */
      22             : 
      23             : #include "includes.h"
      24             : #include "talloc.h"
      25             : #include "tevent.h"
      26             : #include "system/filesys.h"
      27             : #include "lib/param/param.h"
      28             : #include "source4/samba/service.h"
      29             : #include "source4/samba/process_model.h"
      30             : #include "dynconfig.h"
      31             : #include "nsswitch/winbind_client.h"
      32             : 
      33             : /*
      34             :   called if winbindd exits
      35             :  */
      36           0 : static void winbindd_done(struct tevent_req *subreq)
      37             : {
      38           0 :         struct task_server *task =
      39           0 :                 tevent_req_callback_data(subreq,
      40             :                 struct task_server);
      41           0 :         int sys_errno;
      42           0 :         int ret;
      43             : 
      44           0 :         ret = samba_runcmd_recv(subreq, &sys_errno);
      45           0 :         if (ret != 0) {
      46           0 :                 DEBUG(0,("winbindd daemon died with exit status %d\n", sys_errno));
      47             :         } else {
      48           0 :                 DEBUG(0,("winbindd daemon exited normally\n"));
      49             :         }
      50           0 :         task_server_terminate(task, "winbindd child process exited", true);
      51           0 : }
      52             : 
      53             : 
      54             : /*
      55             :   startup a copy of winbindd as a child daemon
      56             : */
      57          65 : static NTSTATUS winbindd_task_init(struct task_server *task)
      58             : {
      59           2 :         struct tevent_req *subreq;
      60           2 :         const char *winbindd_path;
      61          65 :         const char *winbindd_cmd[2] = { NULL, NULL };
      62          65 :         const char *config_file = "";
      63             : 
      64          65 :         task_server_set_title(task, "task[winbindd_parent]");
      65             : 
      66          65 :         winbindd_path = talloc_asprintf(task, "%s/winbindd", dyn_SBINDIR);
      67          65 :         if (winbindd_path == NULL) {
      68           0 :                 return NT_STATUS_NO_MEMORY;
      69             :         }
      70          65 :         winbindd_cmd[0] = winbindd_path;
      71             : 
      72          65 :         if (!is_default_dyn_CONFIGFILE()) {
      73          65 :                 config_file = talloc_asprintf(task,
      74             :                                               "--configfile=%s",
      75             :                                               get_dyn_CONFIGFILE());
      76          65 :                 if (config_file == NULL) {
      77           0 :                         return NT_STATUS_NO_MEMORY;
      78             :                 }
      79             :         }
      80             : 
      81             :         /* start it as a child process */
      82          67 :         subreq = samba_runcmd_send(task, task->event_ctx, timeval_zero(), 1, 0,
      83             :                                 winbindd_cmd,
      84             :                                 "-D",
      85             :                                 "--option=server role check:inhibit=yes",
      86             :                                 "--foreground",
      87             :                                 config_file,
      88          65 :                                 debug_get_output_is_stdout()?"--debug-stdout":NULL,
      89             :                                 NULL);
      90          65 :         if (subreq == NULL) {
      91           0 :                 DEBUG(0, ("Failed to start winbindd as child daemon\n"));
      92           0 :                 task_server_terminate(task, "Failed to startup winbindd task", true);
      93           0 :                 return NT_STATUS_UNSUCCESSFUL;
      94             :         }
      95             : 
      96          65 :         tevent_req_set_callback(subreq, winbindd_done, task);
      97             : 
      98          65 :         DEBUG(5,("Started winbindd as a child daemon\n"));
      99          65 :         return NT_STATUS_OK;
     100             : }
     101             : 
     102             : /* called at winbindd startup - register ourselves as a server service */
     103             : NTSTATUS server_service_winbindd_init(TALLOC_CTX *);
     104             : 
     105          66 : NTSTATUS server_service_winbindd_init(TALLOC_CTX *ctx)
     106             : {
     107           3 :         static const struct service_details details = {
     108             :                 .inhibit_fork_on_accept = true,
     109             :                 .inhibit_pre_fork = true,
     110             :                 .task_init = winbindd_task_init,
     111             :                 .post_fork = NULL
     112             :         };
     113             : 
     114          66 :         NTSTATUS status = register_server_service(ctx, "winbindd", &details);
     115          66 :         if (!NT_STATUS_IS_OK(status)) {
     116           0 :                 return status;
     117             :         }
     118          66 :         return register_server_service(ctx, "winbind", &details);
     119             : }

Generated by: LCOV version 1.14