Samba 3: added Samba 3.0.24 sources
[tomato.git] / release / src / router / samba3 / source / services / svc_rcinit.c
blobf60019601fe60b1eef20902694e55697b199b8dc
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.
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.
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.
21 #include "includes.h"
23 /*********************************************************************
24 *********************************************************************/
26 static WERROR rcinit_stop( const char *service, SERVICE_STATUS *status )
28 pstring command;
29 int ret, fd;
31 pstr_sprintf( command, "%s/%s/%s stop", dyn_LIBDIR, SVCCTL_SCRIPT_DIR, service );
33 /* we've already performed the access check when the service was opened */
35 become_root();
36 ret = smbrun( command , &fd );
37 unbecome_root();
39 DEBUGADD(5, ("rcinit_start: [%s] returned [%d]\n", command, ret));
40 close(fd);
42 ZERO_STRUCTP( status );
43 status->type = 0x0020;
44 status->state = (ret == 0 ) ? 0x0001 : 0x0004;
45 status->controls_accepted = 0x0005;
47 return ( ret == 0 ) ? WERR_OK : WERR_ACCESS_DENIED;
50 /*********************************************************************
51 *********************************************************************/
53 static WERROR rcinit_start( const char *service )
55 pstring command;
56 int ret, fd;
58 pstr_sprintf( command, "%s/%s/%s start", dyn_LIBDIR, SVCCTL_SCRIPT_DIR, service );
60 /* we've already performed the access check when the service was opened */
62 become_root();
63 ret = smbrun( command , &fd );
64 unbecome_root();
66 DEBUGADD(5, ("rcinit_start: [%s] returned [%d]\n", command, ret));
67 close(fd);
69 return ( ret == 0 ) ? WERR_OK : WERR_ACCESS_DENIED;
72 /*********************************************************************
73 *********************************************************************/
75 static WERROR rcinit_status( const char *service, SERVICE_STATUS *status )
77 pstring command;
78 int ret, fd;
80 pstr_sprintf( command, "%s/%s/%s status", dyn_LIBDIR, SVCCTL_SCRIPT_DIR, service );
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 */
86 become_root();
87 ret = smbrun( command , &fd );
88 unbecome_root();
90 DEBUGADD(5, ("rcinit_start: [%s] returned [%d]\n", command, ret));
91 close(fd);
93 ZERO_STRUCTP( status );
94 status->type = 0x0020;
95 status->state = (ret == 0 ) ? 0x0004 : 0x0001;
96 status->controls_accepted = 0x0005;
98 return WERR_OK;
101 /*********************************************************************
102 *********************************************************************/
104 /* struct for svcctl control to manipulate rcinit service */
106 SERVICE_CONTROL_OPS rcinit_svc_ops = {
107 rcinit_stop,
108 rcinit_start,
109 rcinit_status