source: branches/samba-3.2.x/source/rpc_client/cli_svcctl.c

Last change on this file was 133, checked in by Paul Smedley, 17 years ago

Update trunk to 3.2.0pre3

File size: 6.0 KB
Line 
1/*
2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
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
21#include "includes.h"
22#include "rpc_client.h"
23
24struct svc_state_msg {
25 uint32 flag;
26 const char *message;
27};
28
29static 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" },
37 { 0, NULL }
38};
39
40
41/********************************************************************
42********************************************************************/
43const char* svc_status_string( uint32 state )
44{
45 fstring msg;
46 int i;
47
48 fstr_sprintf( msg, "Unknown State [%d]", state );
49
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 );
53 break;
54 }
55 }
56
57 return talloc_strdup(talloc_tos(), msg);
58}
59
60/*******************************************************************
61*******************************************************************/
62
63WERROR 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 )
66{
67 SVCCTL_Q_ENUM_SERVICES_STATUS in;
68 SVCCTL_R_ENUM_SERVICES_STATUS out;
69 prs_struct qbuf, rbuf;
70 uint32 resume = 0;
71 ENUM_SERVICES_STATUS *services;
72 int i;
73
74 ZERO_STRUCT(in);
75 ZERO_STRUCT(out);
76
77 /* setup the request */
78
79 memcpy( &in.handle, hSCM, sizeof(POLICY_HND) );
80
81 in.type = type;
82 in.state = state;
83 in.resume = &resume;
84
85 /* first time is to get the buffer size */
86 in.buffer_size = 0;
87
88 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SVCCTL, SVCCTL_ENUM_SERVICES_STATUS_W,
89 in, out,
90 qbuf, rbuf,
91 svcctl_io_q_enum_services_status,
92 svcctl_io_r_enum_services_status,
93 WERR_GENERAL_FAILURE );
94
95 /* second time with correct buffer size...should be ok */
96
97 if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) {
98 in.buffer_size = out.needed;
99
100 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SVCCTL, SVCCTL_ENUM_SERVICES_STATUS_W,
101 in, out,
102 qbuf, rbuf,
103 svcctl_io_q_enum_services_status,
104 svcctl_io_r_enum_services_status,
105 WERR_GENERAL_FAILURE );
106 }
107
108 if ( !W_ERROR_IS_OK(out.status) )
109 return out.status;
110
111 /* pull out the data */
112 if (out.returned) {
113 if ( !(services = TALLOC_ARRAY( mem_ctx, ENUM_SERVICES_STATUS, out.returned )) )
114 return WERR_NOMEM;
115 } else {
116 services = NULL;
117 }
118
119 for ( i=0; i<out.returned; i++ ) {
120 svcctl_io_enum_services_status( "", &services[i], &out.buffer, 0 );
121 }
122
123 *service_array = services;
124 *returned = out.returned;
125
126 return out.status;
127}
128
129/*******************************************************************
130*******************************************************************/
131
132WERROR rpccli_svcctl_query_config(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
133 POLICY_HND *hService, SERVICE_CONFIG *config )
134{
135 SVCCTL_Q_QUERY_SERVICE_CONFIG in;
136 SVCCTL_R_QUERY_SERVICE_CONFIG out;
137 prs_struct qbuf, rbuf;
138
139 ZERO_STRUCT(in);
140 ZERO_STRUCT(out);
141
142 memcpy( &in.handle, hService, sizeof(POLICY_HND) );
143 in.buffer_size = 0;
144
145
146 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SVCCTL, SVCCTL_QUERY_SERVICE_CONFIG_W,
147 in, out,
148 qbuf, rbuf,
149 svcctl_io_q_query_service_config,
150 svcctl_io_r_query_service_config,
151 WERR_GENERAL_FAILURE );
152
153 if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
154 in.buffer_size = out.needed;
155
156 CLI_DO_RPC_WERR( cli, mem_ctx, PI_SVCCTL, SVCCTL_QUERY_SERVICE_CONFIG_W,
157 in, out,
158 qbuf, rbuf,
159 svcctl_io_q_query_service_config,
160 svcctl_io_r_query_service_config,
161 WERR_GENERAL_FAILURE );
162 }
163
164 if ( !W_ERROR_IS_OK( out.status ) )
165 return out.status;
166
167 memcpy( config, &out.config, sizeof(SERVICE_CONFIG) );
168
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 );
174
175 if ( out.config.executablepath ) {
176 config->executablepath = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
177 copy_unistr2( config->executablepath, out.config.executablepath );
178 }
179
180 if ( out.config.loadordergroup ) {
181 config->loadordergroup = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
182 copy_unistr2( config->loadordergroup, out.config.loadordergroup );
183 }
184
185 if ( out.config.dependencies ) {
186 config->dependencies = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
187 copy_unistr2( config->dependencies, out.config.dependencies );
188 }
189
190 if ( out.config.startname ) {
191 config->startname = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
192 copy_unistr2( config->startname, out.config.startname );
193 }
194
195 if ( out.config.displayname ) {
196 config->displayname = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
197 copy_unistr2( config->displayname, out.config.displayname );
198 }
199
200 return out.status;
201}
Note: See TracBrowser for help on using the repository browser.