s3-selftest: make sure to test rpc.samr.passwords.validate over ncacn_ip_tcp.
[Samba.git] / source3 / services / svc_rcinit.c
blob199e5f12ce1b87142cb50462972cbf6f8353d017
1 /*
2 * Unix SMB/CIFS implementation.
3 * Service Control API Implementation
4 * Copyright (C) Gerald Carter 2005.
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.
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, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "services/services.h"
23 /*********************************************************************
24 *********************************************************************/
26 static WERROR rcinit_stop( const char *service, struct SERVICE_STATUS *status )
28 char *command = NULL;
29 int ret, fd;
31 if (asprintf(&command, "%s/%s/%s stop",
32 get_dyn_MODULESDIR(), SVCCTL_SCRIPT_DIR, service) < 0) {
33 return WERR_NOMEM;
36 /* we've already performed the access check when the service was opened */
38 become_root();
39 ret = smbrun( command , &fd );
40 unbecome_root();
42 DEBUGADD(5, ("rcinit_start: [%s] returned [%d]\n", command, ret));
43 close(fd);
45 SAFE_FREE(command);
47 ZERO_STRUCTP( status );
49 status->type = SERVICE_TYPE_WIN32_SHARE_PROCESS;
50 status->state = (ret == 0 ) ? SVCCTL_STOPPED : SVCCTL_RUNNING;
51 status->controls_accepted = SVCCTL_ACCEPT_STOP |
52 SVCCTL_ACCEPT_SHUTDOWN;
54 return ( ret == 0 ) ? WERR_OK : WERR_ACCESS_DENIED;
57 /*********************************************************************
58 *********************************************************************/
60 static WERROR rcinit_start( const char *service )
62 char *command = NULL;
63 int ret, fd;
65 if (asprintf(&command, "%s/%s/%s start",
66 get_dyn_MODULESDIR(), SVCCTL_SCRIPT_DIR, service) < 0) {
67 return WERR_NOMEM;
70 /* we've already performed the access check when the service was opened */
72 become_root();
73 ret = smbrun( command , &fd );
74 unbecome_root();
76 DEBUGADD(5, ("rcinit_start: [%s] returned [%d]\n", command, ret));
77 close(fd);
79 SAFE_FREE(command);
81 return ( ret == 0 ) ? WERR_OK : WERR_ACCESS_DENIED;
84 /*********************************************************************
85 *********************************************************************/
87 static WERROR rcinit_status( const char *service, struct SERVICE_STATUS *status )
89 char *command = NULL;
90 int ret, fd;
92 if (asprintf(&command, "%s/%s/%s status",
93 get_dyn_MODULESDIR(), SVCCTL_SCRIPT_DIR, service) < 0) {
94 return WERR_NOMEM;
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 */
101 become_root();
102 ret = smbrun( command , &fd );
103 unbecome_root();
105 DEBUGADD(5, ("rcinit_start: [%s] returned [%d]\n", command, ret));
106 close(fd);
108 SAFE_FREE(command);
110 ZERO_STRUCTP( status );
112 status->type = SERVICE_TYPE_WIN32_SHARE_PROCESS;
113 status->state = (ret == 0 ) ? SVCCTL_RUNNING : SVCCTL_STOPPED;
114 status->controls_accepted = SVCCTL_ACCEPT_STOP |
115 SVCCTL_ACCEPT_SHUTDOWN;
117 return WERR_OK;
120 /*********************************************************************
121 *********************************************************************/
123 /* struct for svcctl control to manipulate rcinit service */
125 SERVICE_CONTROL_OPS rcinit_svc_ops = {
126 rcinit_stop,
127 rcinit_start,
128 rcinit_status