2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
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/>.
22 #include "rpc_client.h"
24 struct svc_state_msg
{
29 static struct svc_state_msg state_msg_table
[] = {
30 { SVCCTL_STOPPED
, "stopped" },
31 { SVCCTL_START_PENDING
, "start pending" },
32 { SVCCTL_STOP_PENDING
, "stop pending" },
33 { SVCCTL_RUNNING
, "running" },
34 { SVCCTL_CONTINUE_PENDING
, "resume pending" },
35 { SVCCTL_PAUSE_PENDING
, "pause pending" },
36 { SVCCTL_PAUSED
, "paused" },
41 /********************************************************************
42 ********************************************************************/
43 const char* svc_status_string( uint32 state
)
48 fstr_sprintf( msg
, "Unknown State [%d]", state
);
50 for ( i
=0; state_msg_table
[i
].message
; i
++ ) {
51 if ( state_msg_table
[i
].flag
== state
) {
52 fstrcpy( msg
, state_msg_table
[i
].message
);
57 return talloc_strdup(talloc_tos(), msg
);
60 /*******************************************************************
61 *******************************************************************/
63 WERROR
rpccli_svcctl_enumerate_services( struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
64 POLICY_HND
*hSCM
, uint32 type
, uint32 state
,
65 uint32
*returned
, ENUM_SERVICES_STATUS
**service_array
)
67 SVCCTL_Q_ENUM_SERVICES_STATUS in
;
68 SVCCTL_R_ENUM_SERVICES_STATUS out
;
69 prs_struct qbuf
, rbuf
;
71 ENUM_SERVICES_STATUS
*services
;
77 /* setup the request */
79 memcpy( &in
.handle
, hSCM
, sizeof(POLICY_HND
) );
85 /* first time is to get the buffer size */
88 CLI_DO_RPC_WERR( cli
, mem_ctx
, PI_SVCCTL
, SVCCTL_ENUM_SERVICES_STATUS_W
,
91 svcctl_io_q_enum_services_status
,
92 svcctl_io_r_enum_services_status
,
93 WERR_GENERAL_FAILURE
);
95 /* second time with correct buffer size...should be ok */
97 if ( W_ERROR_EQUAL( out
.status
, WERR_MORE_DATA
) ) {
98 in
.buffer_size
= out
.needed
;
100 CLI_DO_RPC_WERR( cli
, mem_ctx
, PI_SVCCTL
, SVCCTL_ENUM_SERVICES_STATUS_W
,
103 svcctl_io_q_enum_services_status
,
104 svcctl_io_r_enum_services_status
,
105 WERR_GENERAL_FAILURE
);
108 if ( !W_ERROR_IS_OK(out
.status
) )
111 /* pull out the data */
113 if ( !(services
= TALLOC_ARRAY( mem_ctx
, ENUM_SERVICES_STATUS
, out
.returned
)) )
119 for ( i
=0; i
<out
.returned
; i
++ ) {
120 svcctl_io_enum_services_status( "", &services
[i
], &out
.buffer
, 0 );
123 *service_array
= services
;
124 *returned
= out
.returned
;
129 /*******************************************************************
130 *******************************************************************/
132 WERROR
rpccli_svcctl_query_config(struct rpc_pipe_client
*cli
, TALLOC_CTX
*mem_ctx
,
133 POLICY_HND
*hService
, SERVICE_CONFIG
*config
)
135 SVCCTL_Q_QUERY_SERVICE_CONFIG in
;
136 SVCCTL_R_QUERY_SERVICE_CONFIG out
;
137 prs_struct qbuf
, rbuf
;
142 memcpy( &in
.handle
, hService
, sizeof(POLICY_HND
) );
146 CLI_DO_RPC_WERR( cli
, mem_ctx
, PI_SVCCTL
, SVCCTL_QUERY_SERVICE_CONFIG_W
,
149 svcctl_io_q_query_service_config
,
150 svcctl_io_r_query_service_config
,
151 WERR_GENERAL_FAILURE
);
153 if ( W_ERROR_EQUAL( out
.status
, WERR_INSUFFICIENT_BUFFER
) ) {
154 in
.buffer_size
= out
.needed
;
156 CLI_DO_RPC_WERR( cli
, mem_ctx
, PI_SVCCTL
, SVCCTL_QUERY_SERVICE_CONFIG_W
,
159 svcctl_io_q_query_service_config
,
160 svcctl_io_r_query_service_config
,
161 WERR_GENERAL_FAILURE
);
164 if ( !W_ERROR_IS_OK( out
.status
) )
167 memcpy( config
, &out
.config
, sizeof(SERVICE_CONFIG
) );
169 config
->executablepath
= TALLOC_ZERO_P( mem_ctx
, UNISTR2
);
170 config
->loadordergroup
= TALLOC_ZERO_P( mem_ctx
, UNISTR2
);
171 config
->dependencies
= TALLOC_ZERO_P( mem_ctx
, UNISTR2
);
172 config
->startname
= TALLOC_ZERO_P( mem_ctx
, UNISTR2
);
173 config
->displayname
= TALLOC_ZERO_P( mem_ctx
, UNISTR2
);
175 if ( out
.config
.executablepath
) {
176 config
->executablepath
= TALLOC_ZERO_P( mem_ctx
, UNISTR2
);
177 copy_unistr2( config
->executablepath
, out
.config
.executablepath
);
180 if ( out
.config
.loadordergroup
) {
181 config
->loadordergroup
= TALLOC_ZERO_P( mem_ctx
, UNISTR2
);
182 copy_unistr2( config
->loadordergroup
, out
.config
.loadordergroup
);
185 if ( out
.config
.dependencies
) {
186 config
->dependencies
= TALLOC_ZERO_P( mem_ctx
, UNISTR2
);
187 copy_unistr2( config
->dependencies
, out
.config
.dependencies
);
190 if ( out
.config
.startname
) {
191 config
->startname
= TALLOC_ZERO_P( mem_ctx
, UNISTR2
);
192 copy_unistr2( config
->startname
, out
.config
.startname
);
195 if ( out
.config
.displayname
) {
196 config
->displayname
= TALLOC_ZERO_P( mem_ctx
, UNISTR2
);
197 copy_unistr2( config
->displayname
, out
.config
.displayname
);