LCOV - code coverage report
Current view: top level - source3/services - svc_rcinit.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 0 41 0.0 %
Date: 2021-09-23 10:06:22 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /*
       2             :  *  Unix SMB/CIFS implementation.
       3             :  *  Service Control API Implementation
       4             :  *  Copyright (C) Gerald Carter                   2005.
       5             :  *
       6             :  *  This program is free software; you can redistribute it and/or modify
       7             :  *  it under the terms of the GNU General Public License as published by
       8             :  *  the Free Software Foundation; either version 3 of the License, or
       9             :  *  (at your option) any later version.
      10             :  *
      11             :  *  This program is distributed in the hope that it will be useful,
      12             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  *  GNU General Public License for more details.
      15             :  *
      16             :  *  You should have received a copy of the GNU General Public License
      17             :  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
      18             :  */
      19             : 
      20             : #include "includes.h"
      21             : #include "services/services.h"
      22             : 
      23             : /*********************************************************************
      24             : *********************************************************************/
      25             : 
      26           0 : static WERROR rcinit_stop( const char *service, struct SERVICE_STATUS *status )
      27             : {
      28           0 :         char *command = NULL;
      29             :         int ret, fd;
      30             : 
      31           0 :         if (asprintf(&command, "%s/%s/%s stop",
      32             :                                 get_dyn_MODULESDIR(), SVCCTL_SCRIPT_DIR, service) < 0) {
      33           0 :                 return WERR_NOT_ENOUGH_MEMORY;
      34             :         }
      35             : 
      36             :         /* we've already performed the access check when the service was opened */
      37             : 
      38           0 :         become_root();
      39           0 :         ret = smbrun(command, &fd, NULL);
      40           0 :         unbecome_root();
      41             : 
      42           0 :         DEBUGADD(5, ("rcinit_start: [%s] returned [%d]\n", command, ret));
      43           0 :         close(fd);
      44             : 
      45           0 :         SAFE_FREE(command);
      46             : 
      47           0 :         ZERO_STRUCTP( status );
      48             : 
      49           0 :         status->type                 = SERVICE_TYPE_WIN32_SHARE_PROCESS;
      50           0 :         status->state                        = (ret == 0 ) ? SVCCTL_STOPPED : SVCCTL_RUNNING;
      51           0 :         status->controls_accepted    = SVCCTL_ACCEPT_STOP |
      52             :                                           SVCCTL_ACCEPT_SHUTDOWN;
      53             : 
      54           0 :         return ( ret == 0 ) ? WERR_OK : WERR_ACCESS_DENIED;
      55             : }
      56             : 
      57             : /*********************************************************************
      58             : *********************************************************************/
      59             : 
      60           0 : static WERROR rcinit_start( const char *service )
      61             : {
      62           0 :         char *command = NULL;
      63             :         int ret, fd;
      64             : 
      65           0 :         if (asprintf(&command, "%s/%s/%s start",
      66             :                                 get_dyn_MODULESDIR(), SVCCTL_SCRIPT_DIR, service) < 0) {
      67           0 :                 return WERR_NOT_ENOUGH_MEMORY;
      68             :         }
      69             : 
      70             :         /* we've already performed the access check when the service was opened */
      71             : 
      72           0 :         become_root();
      73           0 :         ret = smbrun(command, &fd, NULL);
      74           0 :         unbecome_root();
      75             : 
      76           0 :         DEBUGADD(5, ("rcinit_start: [%s] returned [%d]\n", command, ret));
      77           0 :         close(fd);
      78             : 
      79           0 :         SAFE_FREE(command);
      80             : 
      81           0 :         return ( ret == 0 ) ? WERR_OK : WERR_ACCESS_DENIED;
      82             : }
      83             : 
      84             : /*********************************************************************
      85             : *********************************************************************/
      86             : 
      87           0 : static WERROR rcinit_status( const char *service, struct SERVICE_STATUS *status )
      88             : {
      89           0 :         char *command = NULL;
      90             :         int ret, fd;
      91             : 
      92           0 :         if (asprintf(&command, "%s/%s/%s status",
      93             :                                 get_dyn_MODULESDIR(), SVCCTL_SCRIPT_DIR, service) < 0) {
      94           0 :                 return WERR_NOT_ENOUGH_MEMORY;
      95             :         }
      96             : 
      97             :         /* we've already performed the access check when the service was opened */
      98             :         /* assume as return code of 0 means that the service is ok.  Anything else
      99             :            is STOPPED */
     100             : 
     101           0 :         become_root();
     102           0 :         ret = smbrun(command, &fd, NULL);
     103           0 :         unbecome_root();
     104             : 
     105           0 :         DEBUGADD(5, ("rcinit_start: [%s] returned [%d]\n", command, ret));
     106           0 :         close(fd);
     107             : 
     108           0 :         SAFE_FREE(command);
     109             : 
     110           0 :         ZERO_STRUCTP( status );
     111             : 
     112           0 :         status->type                 = SERVICE_TYPE_WIN32_SHARE_PROCESS;
     113           0 :         status->state                        = (ret == 0 ) ? SVCCTL_RUNNING : SVCCTL_STOPPED;
     114           0 :         status->controls_accepted    = SVCCTL_ACCEPT_STOP |
     115             :                                           SVCCTL_ACCEPT_SHUTDOWN;
     116             : 
     117           0 :         return WERR_OK;
     118             : }
     119             : 
     120             : /*********************************************************************
     121             : *********************************************************************/
     122             : 
     123             : /* struct for svcctl control to manipulate rcinit service */
     124             : 
     125             : SERVICE_CONTROL_OPS rcinit_svc_ops = {
     126             :         rcinit_stop,
     127             :         rcinit_start,
     128             :         rcinit_status
     129             : };

Generated by: LCOV version 1.13