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

Last change on this file since 201 was 133, checked in by Paul Smedley, 18 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