Remove convert_string_talloc_descriptor, add iconv_talloc().
[abartlet/samba.git/.git] / source3 / rpc_parse / parse_svcctl.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  RPC Pipe client / server routines
4  *  Copyright (C) Gerald (Jerry) 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 #include "includes.h"
21
22 #undef DBGC_CLASS
23 #define DBGC_CLASS DBGC_RPC_PARSE
24
25 /*******************************************************************
26 ********************************************************************/
27
28 static bool svcctl_io_service_status( const char *desc, SERVICE_STATUS *status, prs_struct *ps, int depth )
29 {
30
31         prs_debug(ps, depth, desc, "svcctl_io_service_status");
32         depth++;
33
34         if(!prs_uint32("type", ps, depth, &status->type))
35                 return False;
36
37         if(!prs_uint32("state", ps, depth, &status->state))
38                 return False;
39
40         if(!prs_uint32("controls_accepted", ps, depth, &status->controls_accepted))
41                 return False;
42
43         if(!prs_werror("win32_exit_code", ps, depth, &status->win32_exit_code))
44                 return False;
45
46         if(!prs_uint32("service_exit_code", ps, depth, &status->service_exit_code))
47                 return False;
48
49         if(!prs_uint32("check_point", ps, depth, &status->check_point))
50                 return False;
51
52         if(!prs_uint32("wait_hint", ps, depth, &status->wait_hint))
53                 return False;
54
55         return True;
56 }
57
58 /*******************************************************************
59 ********************************************************************/
60
61 bool svcctl_io_enum_services_status( const char *desc, ENUM_SERVICES_STATUS *enum_status, RPC_BUFFER *buffer, int depth )
62 {
63         prs_struct *ps=&buffer->prs;
64         
65         prs_debug(ps, depth, desc, "svcctl_io_enum_services_status");
66         depth++;
67         
68         if ( !smb_io_relstr("servicename", buffer, depth, &enum_status->servicename) )
69                 return False;
70         if ( !smb_io_relstr("displayname", buffer, depth, &enum_status->displayname) )
71                 return False;
72
73         if ( !svcctl_io_service_status("svc_status", &enum_status->status, ps, depth) )
74                 return False;
75         
76         return True;
77 }
78
79 /*******************************************************************
80 ********************************************************************/
81
82 bool svcctl_io_service_status_process( const char *desc, SERVICE_STATUS_PROCESS *status, RPC_BUFFER *buffer, int depth )
83 {
84         prs_struct *ps=&buffer->prs;
85
86         prs_debug(ps, depth, desc, "svcctl_io_service_status_process");
87         depth++;
88
89         if ( !svcctl_io_service_status("status", &status->status, ps, depth) )
90                 return False;
91         if(!prs_align(ps))
92                 return False;
93
94         if(!prs_uint32("process_id", ps, depth, &status->process_id))
95                 return False;
96         if(!prs_uint32("service_flags", ps, depth, &status->service_flags))
97                 return False;
98
99         return True;
100 }
101
102 /*******************************************************************
103 ********************************************************************/
104
105 uint32 svcctl_sizeof_enum_services_status( ENUM_SERVICES_STATUS *status )
106 {
107         uint32 size = 0;
108         
109         size += size_of_relative_string( &status->servicename );
110         size += size_of_relative_string( &status->displayname );
111         size += sizeof(SERVICE_STATUS);
112
113         return size;
114 }
115
116 /********************************************************************
117 ********************************************************************/
118
119 static uint32 sizeof_unistr2( UNISTR2 *string )
120 {
121         uint32 size = 0;
122
123         if ( !string ) 
124                 return 0;       
125
126         size  = sizeof(uint32) * 3;             /* length fields */
127         size += 2 * string->uni_max_len;        /* string data */
128         size += size % 4;                       /* alignment */
129
130         return size;
131 }
132
133 /*******************************************************************
134 ********************************************************************/
135
136 bool svcctl_io_q_enum_services_status(const char *desc, SVCCTL_Q_ENUM_SERVICES_STATUS *q_u, prs_struct *ps, int depth)
137 {
138         if (q_u == NULL)
139                 return False;
140
141         prs_debug(ps, depth, desc, "svcctl_io_q_enum_services_status");
142         depth++;
143
144         if(!prs_align(ps))
145                 return False;
146
147         if(!smb_io_pol_hnd("scm_pol", &q_u->handle, ps, depth))
148                 return False;
149
150         if(!prs_uint32("type", ps, depth, &q_u->type))
151                 return False;
152         if(!prs_uint32("state", ps, depth, &q_u->state))
153                 return False;
154         if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size))
155                 return False;
156
157         if(!prs_pointer("resume", ps, depth, (void*)&q_u->resume, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
158                 return False;
159         
160         return True;
161 }
162
163 /*******************************************************************
164 ********************************************************************/
165
166 bool svcctl_io_r_enum_services_status(const char *desc, SVCCTL_R_ENUM_SERVICES_STATUS *r_u, prs_struct *ps, int depth)
167 {
168         if (r_u == NULL)
169                 return False;
170
171         prs_debug(ps, depth, desc, "svcctl_io_r_enum_services_status");
172         depth++;
173
174         if(!prs_align(ps))
175                 return False;
176
177         if (!prs_rpcbuffer("", ps, depth, &r_u->buffer))
178                 return False;
179
180         if(!prs_align(ps))
181                 return False;
182
183         if(!prs_uint32("needed", ps, depth, &r_u->needed))
184                 return False;
185         if(!prs_uint32("returned", ps, depth, &r_u->returned))
186                 return False;
187
188         if(!prs_pointer("resume", ps, depth, (void*)&r_u->resume, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
189                 return False;
190
191         if(!prs_werror("status", ps, depth, &r_u->status))
192                 return False;
193
194         return True;
195 }
196
197 /*******************************************************************
198 ********************************************************************/
199
200 bool svcctl_io_q_query_service_config2(const char *desc, SVCCTL_Q_QUERY_SERVICE_CONFIG2 *q_u, prs_struct *ps, int depth)
201 {
202         if (q_u == NULL)
203                 return False;
204
205         prs_debug(ps, depth, desc, "svcctl_io_q_query_service_config2");
206         depth++;
207
208         if(!prs_align(ps))
209                 return False;
210
211         if(!smb_io_pol_hnd("service_pol", &q_u->handle, ps, depth))
212                 return False;
213
214         if(!prs_uint32("level", ps, depth, &q_u->level))
215                 return False;
216
217         if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size))
218                 return False;
219
220         return True;
221 }
222
223
224 /*******************************************************************
225 ********************************************************************/
226
227 void init_service_description_buffer(SERVICE_DESCRIPTION *desc, const char *service_desc )
228 {
229         desc->unknown = 0x04;   /* always 0x0000 0004 (no idea what this is) */
230         init_unistr( &desc->description, service_desc );
231 }
232
233 /*******************************************************************
234 ********************************************************************/
235
236 bool svcctl_io_service_description( const char *desc, SERVICE_DESCRIPTION *description, RPC_BUFFER *buffer, int depth )
237 {
238         prs_struct *ps = &buffer->prs;
239
240         prs_debug(ps, depth, desc, "svcctl_io_service_description");
241         depth++;
242
243         if ( !prs_uint32("unknown", ps, depth, &description->unknown) )
244                 return False;
245         if ( !prs_unistr("description", ps, depth, &description->description) )
246                 return False;
247
248         return True;
249
250
251 /*******************************************************************
252 ********************************************************************/
253
254 uint32 svcctl_sizeof_service_description( SERVICE_DESCRIPTION *desc )
255 {
256         if ( !desc )
257                 return 0;
258
259         /* make sure to include the terminating NULL */
260         return ( sizeof(uint32) + (2*(str_len_uni(&desc->description)+1)) );
261 }
262
263 /*******************************************************************
264 ********************************************************************/
265
266 static bool svcctl_io_action( const char *desc, SC_ACTION *action, prs_struct *ps, int depth )
267 {
268
269         prs_debug(ps, depth, desc, "svcctl_io_action");
270         depth++;
271
272         if ( !prs_uint32("type", ps, depth, &action->type) )
273                 return False;
274         if ( !prs_uint32("delay", ps, depth, &action->delay) )
275                 return False;
276
277         return True;
278 }
279
280 /*******************************************************************
281 ********************************************************************/
282
283 bool svcctl_io_service_fa( const char *desc, SERVICE_FAILURE_ACTIONS *fa, RPC_BUFFER *buffer, int depth )
284 {
285         prs_struct *ps = &buffer->prs;
286         int i;
287
288         prs_debug(ps, depth, desc, "svcctl_io_service_description");
289         depth++;
290
291         if ( !prs_uint32("reset_period", ps, depth, &fa->reset_period) )
292                 return False;
293
294         if ( !prs_pointer( desc, ps, depth, (void*)&fa->rebootmsg, sizeof(UNISTR2), (PRS_POINTER_CAST)prs_io_unistr2 ) )
295                 return False;
296         if ( !prs_pointer( desc, ps, depth, (void*)&fa->command, sizeof(UNISTR2), (PRS_POINTER_CAST)prs_io_unistr2 ) )
297                 return False;
298
299         if ( !prs_uint32("num_actions", ps, depth, &fa->num_actions) )
300                 return False;
301
302         if ( UNMARSHALLING(ps)) {
303                 if (fa->num_actions) {
304                         if ( !(fa->actions = TALLOC_ARRAY( talloc_tos(), SC_ACTION, fa->num_actions )) ) {
305                                 DEBUG(0,("svcctl_io_service_fa: talloc() failure!\n"));
306                                 return False;
307                         }
308                 } else {
309                         fa->actions = NULL;
310                 }
311         }
312
313         for ( i=0; i<fa->num_actions; i++ ) {
314                 if ( !svcctl_io_action( "actions", &fa->actions[i], ps, depth ) )
315                         return False;
316         }
317
318         return True;
319
320
321 /*******************************************************************
322 ********************************************************************/
323
324 uint32 svcctl_sizeof_service_fa( SERVICE_FAILURE_ACTIONS *fa)
325 {
326         uint32 size = 0;
327
328         if ( !fa )
329                 return 0;
330
331         size  = sizeof(uint32) * 2;
332         size += sizeof_unistr2( fa->rebootmsg );
333         size += sizeof_unistr2( fa->command );
334         size += sizeof(SC_ACTION) * fa->num_actions;
335
336         return size;
337 }
338
339 /*******************************************************************
340 ********************************************************************/
341
342 bool svcctl_io_r_query_service_config2(const char *desc, SVCCTL_R_QUERY_SERVICE_CONFIG2 *r_u, prs_struct *ps, int depth)
343 {
344         if ( !r_u )
345                 return False;
346
347         prs_debug(ps, depth, desc, "svcctl_io_r_query_service_config2");
348         depth++;
349
350         if ( !prs_align(ps) )
351                 return False;
352
353         if (!prs_rpcbuffer("", ps, depth, &r_u->buffer))
354                 return False;
355         if(!prs_align(ps))
356                 return False;
357
358         if (!prs_uint32("needed", ps, depth, &r_u->needed))
359                 return False;
360
361         if(!prs_werror("status", ps, depth, &r_u->status))
362                 return False;
363
364         return True;
365 }
366
367
368 /*******************************************************************
369 ********************************************************************/
370
371 bool svcctl_io_q_query_service_status_ex(const char *desc, SVCCTL_Q_QUERY_SERVICE_STATUSEX *q_u, prs_struct *ps, int depth)
372 {
373         if (q_u == NULL)
374                 return False;
375
376         prs_debug(ps, depth, desc, "svcctl_io_q_query_service_status_ex");
377         depth++;
378
379         if(!prs_align(ps))
380                 return False;
381
382         if(!smb_io_pol_hnd("service_pol", &q_u->handle, ps, depth))
383                 return False;
384
385         if(!prs_uint32("level", ps, depth, &q_u->level))
386                 return False;
387
388         if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size))
389                 return False;
390
391         return True;
392
393 }
394
395 /*******************************************************************
396 ********************************************************************/
397
398 bool svcctl_io_r_query_service_status_ex(const char *desc, SVCCTL_R_QUERY_SERVICE_STATUSEX *r_u, prs_struct *ps, int depth)
399 {
400         if ( !r_u )
401                 return False;
402
403         prs_debug(ps, depth, desc, "svcctl_io_r_query_service_status_ex");
404         depth++;
405
406         if (!prs_rpcbuffer("", ps, depth, &r_u->buffer))
407                 return False;
408
409         if(!prs_align(ps))
410                 return False;
411
412         if(!prs_uint32("needed", ps, depth, &r_u->needed))
413                 return False;
414
415         if(!prs_werror("status", ps, depth, &r_u->status))
416                 return False;
417
418         return True;
419 }