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