| 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 2 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, write to the Free Software
|
|---|
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|---|
| 19 | */
|
|---|
| 20 |
|
|---|
| 21 | #include "includes.h"
|
|---|
| 22 |
|
|---|
| 23 | /*********************************************************************
|
|---|
| 24 | *********************************************************************/
|
|---|
| 25 |
|
|---|
| 26 | static WERROR rcinit_stop( const char *service, SERVICE_STATUS *status )
|
|---|
| 27 | {
|
|---|
| 28 | pstring command;
|
|---|
| 29 | int ret, fd;
|
|---|
| 30 |
|
|---|
| 31 | pstr_sprintf( command, "%s/%s/%s stop", dyn_LIBDIR, SVCCTL_SCRIPT_DIR, service );
|
|---|
| 32 |
|
|---|
| 33 | /* we've already performed the access check when the service was opened */
|
|---|
| 34 |
|
|---|
| 35 | become_root();
|
|---|
| 36 | ret = smbrun( command , &fd );
|
|---|
| 37 | unbecome_root();
|
|---|
| 38 |
|
|---|
| 39 | DEBUGADD(5, ("rcinit_start: [%s] returned [%d]\n", command, ret));
|
|---|
| 40 | close(fd);
|
|---|
| 41 |
|
|---|
| 42 | ZERO_STRUCTP( status );
|
|---|
| 43 | status->type = 0x0020;
|
|---|
| 44 | status->state = (ret == 0 ) ? 0x0001 : 0x0004;
|
|---|
| 45 | status->controls_accepted = 0x0005;
|
|---|
| 46 |
|
|---|
| 47 | return ( ret == 0 ) ? WERR_OK : WERR_ACCESS_DENIED;
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | /*********************************************************************
|
|---|
| 51 | *********************************************************************/
|
|---|
| 52 |
|
|---|
| 53 | static WERROR rcinit_start( const char *service )
|
|---|
| 54 | {
|
|---|
| 55 | pstring command;
|
|---|
| 56 | int ret, fd;
|
|---|
| 57 |
|
|---|
| 58 | pstr_sprintf( command, "%s/%s/%s start", dyn_LIBDIR, SVCCTL_SCRIPT_DIR, service );
|
|---|
| 59 |
|
|---|
| 60 | /* we've already performed the access check when the service was opened */
|
|---|
| 61 |
|
|---|
| 62 | become_root();
|
|---|
| 63 | ret = smbrun( command , &fd );
|
|---|
| 64 | unbecome_root();
|
|---|
| 65 |
|
|---|
| 66 | DEBUGADD(5, ("rcinit_start: [%s] returned [%d]\n", command, ret));
|
|---|
| 67 | close(fd);
|
|---|
| 68 |
|
|---|
| 69 | return ( ret == 0 ) ? WERR_OK : WERR_ACCESS_DENIED;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | /*********************************************************************
|
|---|
| 73 | *********************************************************************/
|
|---|
| 74 |
|
|---|
| 75 | static WERROR rcinit_status( const char *service, SERVICE_STATUS *status )
|
|---|
| 76 | {
|
|---|
| 77 | pstring command;
|
|---|
| 78 | int ret, fd;
|
|---|
| 79 |
|
|---|
| 80 | pstr_sprintf( command, "%s/%s/%s status", dyn_LIBDIR, SVCCTL_SCRIPT_DIR, service );
|
|---|
| 81 |
|
|---|
| 82 | /* we've already performed the access check when the service was opened */
|
|---|
| 83 | /* assume as return code of 0 means that the service is ok. Anything else
|
|---|
| 84 | is STOPPED */
|
|---|
| 85 |
|
|---|
| 86 | become_root();
|
|---|
| 87 | ret = smbrun( command , &fd );
|
|---|
| 88 | unbecome_root();
|
|---|
| 89 |
|
|---|
| 90 | DEBUGADD(5, ("rcinit_start: [%s] returned [%d]\n", command, ret));
|
|---|
| 91 | close(fd);
|
|---|
| 92 |
|
|---|
| 93 | ZERO_STRUCTP( status );
|
|---|
| 94 | status->type = 0x0020;
|
|---|
| 95 | status->state = (ret == 0 ) ? 0x0004 : 0x0001;
|
|---|
| 96 | status->controls_accepted = 0x0005;
|
|---|
| 97 |
|
|---|
| 98 | return WERR_OK;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | /*********************************************************************
|
|---|
| 102 | *********************************************************************/
|
|---|
| 103 |
|
|---|
| 104 | /* struct for svcctl control to manipulate rcinit service */
|
|---|
| 105 |
|
|---|
| 106 | SERVICE_CONTROL_OPS rcinit_svc_ops = {
|
|---|
| 107 | rcinit_stop,
|
|---|
| 108 | rcinit_start,
|
|---|
| 109 | rcinit_status
|
|---|
| 110 | };
|
|---|