r7563: svcctl patches from Marcin; have cleaned up formating and am checking the...
[Samba/gbeck.git] / source / rpc_parse / parse_svcctl.c
blob1f21cb2aab9594cc01d7ed9bc9896925fe7be69b
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 2 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, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "includes.h"
23 #undef DBGC_CLASS
24 #define DBGC_CLASS DBGC_RPC_PARSE
26 /*******************************************************************
27 ********************************************************************/
29 static BOOL svcctl_io_service_status( const char *desc, SERVICE_STATUS *status, prs_struct *ps, int depth )
32 prs_debug(ps, depth, desc, "svcctl_io_service_status");
33 depth++;
35 if(!prs_uint32("type", ps, depth, &status->type))
36 return False;
38 if(!prs_uint32("state", ps, depth, &status->state))
39 return False;
41 if(!prs_uint32("controls_accepted", ps, depth, &status->controls_accepted))
42 return False;
44 if(!prs_uint32("win32_exit_code", ps, depth, &status->win32_exit_code))
45 return False;
47 if(!prs_uint32("service_exit_code", ps, depth, &status->service_exit_code))
48 return False;
50 if(!prs_uint32("check_point", ps, depth, &status->check_point))
51 return False;
53 if(!prs_uint32("wait_hint", ps, depth, &status->wait_hint))
54 return False;
56 return True;
59 /*******************************************************************
60 ********************************************************************/
62 static BOOL svcctl_io_service_config( const char *desc, SERVICE_CONFIG *config, prs_struct *ps, int depth )
65 prs_debug(ps, depth, desc, "svcctl_io_service_config");
66 depth++;
68 if(!prs_uint32("service_type", ps, depth, &config->service_type))
69 return False;
70 if(!prs_uint32("start_type", ps, depth, &config->start_type))
71 return False;
72 if(!prs_uint32("error_control", ps, depth, &config->error_control))
73 return False;
75 if (!prs_io_unistr2_p("", ps, depth, &config->executablepath))
76 return False;
77 if (!prs_io_unistr2_p("", ps, depth, &config->loadordergroup))
78 return False;
80 if(!prs_uint32("tag_id", ps, depth, &config->tag_id))
81 return False;
83 if (!prs_io_unistr2_p("", ps, depth, &config->dependencies))
84 return False;
85 if (!prs_io_unistr2_p("", ps, depth, &config->startname))
86 return False;
87 if (!prs_io_unistr2_p("", ps, depth, &config->displayname))
88 return False;
90 if (!prs_io_unistr2("", ps, depth, config->executablepath))
91 return False;
92 if (!prs_io_unistr2("", ps, depth, config->loadordergroup))
93 return False;
94 if (!prs_io_unistr2("", ps, depth, config->dependencies))
95 return False;
96 if (!prs_io_unistr2("", ps, depth, config->startname))
97 return False;
98 if (!prs_io_unistr2("", ps, depth, config->displayname))
99 return False;
101 return True;
103 /*******************************************************************
104 ********************************************************************/
106 BOOL svcctl_io_service_description( const char *desc, UNISTR2 *svcdesc, prs_struct *ps, int depth )
109 prs_debug(ps, depth, desc, "svcctl_io_service_description");
110 depth++;
112 //DEBUG(10, ("_svcctl_io_service_description: descrption is [%s]\n",svcdesc));
113 if (!prs_io_unistr2("", ps, depth, svcdesc))
114 return False;
116 return True;
120 /*******************************************************************
121 ********************************************************************/
123 BOOL svcctl_io_enum_services_status( const char *desc, ENUM_SERVICES_STATUS *enum_status, RPC_BUFFER *buffer, int depth )
125 prs_struct *ps=&buffer->prs;
127 prs_debug(ps, depth, desc, "svcctl_io_enum_services_status");
128 depth++;
130 if ( !smb_io_relstr("servicename", buffer, depth, &enum_status->servicename) )
131 return False;
132 if ( !smb_io_relstr("displayname", buffer, depth, &enum_status->displayname) )
133 return False;
135 if ( !svcctl_io_service_status("svc_status", &enum_status->status, ps, depth) )
136 return False;
138 return True;
141 /*******************************************************************
142 ********************************************************************/
144 uint32 svcctl_sizeof_enum_services_status( ENUM_SERVICES_STATUS *status )
146 uint32 size = 0;
148 size += size_of_relative_string( &status->servicename );
149 size += size_of_relative_string( &status->displayname );
150 size += sizeof(SERVICE_STATUS);
152 return size;
155 /*******************************************************************
156 ********************************************************************/
158 BOOL svcctl_io_q_close_service(const char *desc, SVCCTL_Q_CLOSE_SERVICE *q_u, prs_struct *ps, int depth)
161 if (q_u == NULL)
162 return False;
164 prs_debug(ps, depth, desc, "svcctl_io_q_close_service");
165 depth++;
167 if(!prs_align(ps))
168 return False;
170 if(!smb_io_pol_hnd("scm_pol", &q_u->handle, ps, depth))
171 return False;
173 return True;
177 /*******************************************************************
178 ********************************************************************/
180 BOOL svcctl_io_r_close_service(const char *desc, SVCCTL_R_CLOSE_SERVICE *r_u, prs_struct *ps, int depth)
182 if (r_u == NULL)
183 return False;
185 prs_debug(ps, depth, desc, "svcctl_io_r_close_service");
186 depth++;
188 if(!prs_align(ps))
189 return False;
191 if(!smb_io_pol_hnd("pol_handle", &r_u->handle, ps, depth))
192 return False;
194 if(!prs_werror("status", ps, depth, &r_u->status))
195 return False;
197 return True;
200 /*******************************************************************
201 ********************************************************************/
203 BOOL svcctl_io_q_open_scmanager(const char *desc, SVCCTL_Q_OPEN_SCMANAGER *q_u, prs_struct *ps, int depth)
205 if (q_u == NULL)
206 return False;
208 prs_debug(ps, depth, desc, "svcctl_io_q_open_scmanager");
209 depth++;
211 if(!prs_align(ps))
212 return False;
214 if(!prs_pointer("servername", ps, depth, (void**)&q_u->servername, sizeof(UNISTR2), (PRS_POINTER_CAST)prs_io_unistr2))
215 return False;
216 if(!prs_align(ps))
217 return False;
219 if(!prs_pointer("database", ps, depth, (void**)&q_u->database, sizeof(UNISTR2), (PRS_POINTER_CAST)prs_io_unistr2))
220 return False;
221 if(!prs_align(ps))
222 return False;
224 if(!prs_uint32("access", ps, depth, &q_u->access))
225 return False;
227 return True;
230 /*******************************************************************
231 ********************************************************************/
233 BOOL svcctl_io_r_open_scmanager(const char *desc, SVCCTL_R_OPEN_SCMANAGER *r_u, prs_struct *ps, int depth)
235 if (r_u == NULL)
236 return False;
238 prs_debug(ps, depth, desc, "svcctl_io_r_open_scmanager");
239 depth++;
241 if(!prs_align(ps))
242 return False;
244 if(!smb_io_pol_hnd("scm_pol", &r_u->handle, ps, depth))
245 return False;
247 if(!prs_werror("status", ps, depth, &r_u->status))
248 return False;
250 return True;
253 /*******************************************************************
254 ********************************************************************/
256 BOOL svcctl_io_q_get_display_name(const char *desc, SVCCTL_Q_GET_DISPLAY_NAME *q_u, prs_struct *ps, int depth)
258 if (q_u == NULL)
259 return False;
261 prs_debug(ps, depth, desc, "svcctl_io_q_get_display_name");
262 depth++;
264 if(!prs_align(ps))
265 return False;
267 if(!smb_io_pol_hnd("scm_pol", &q_u->handle, ps, depth))
268 return False;
270 if(!smb_io_unistr2("servicename", &q_u->servicename, 1, ps, depth))
271 return False;
273 if(!prs_align(ps))
274 return False;
276 if(!prs_uint32("display_name_len", ps, depth, &q_u->display_name_len))
277 return False;
279 return True;
282 /*******************************************************************
283 ********************************************************************/
285 BOOL init_svcctl_r_get_display_name( SVCCTL_R_GET_DISPLAY_NAME *r_u, const char *displayname )
287 r_u->display_name_len = strlen(displayname);
288 init_unistr2( &r_u->displayname, displayname, UNI_STR_TERMINATE );
290 return True;
293 /*******************************************************************
294 ********************************************************************/
296 BOOL svcctl_io_r_get_display_name(const char *desc, SVCCTL_R_GET_DISPLAY_NAME *r_u, prs_struct *ps, int depth)
298 if (r_u == NULL)
299 return False;
301 prs_debug(ps, depth, desc, "svcctl_io_r_get_display_name");
302 depth++;
304 if(!prs_align(ps))
305 return False;
308 if(!smb_io_unistr2("displayname", &r_u->displayname, 1, ps, depth))
309 return False;
311 if(!prs_align(ps))
312 return False;
314 if(!prs_uint32("display_name_len", ps, depth, &r_u->display_name_len))
315 return False;
317 if(!prs_werror("status", ps, depth, &r_u->status))
318 return False;
320 return True;
324 /*******************************************************************
325 ********************************************************************/
327 BOOL svcctl_io_q_open_service(const char *desc, SVCCTL_Q_OPEN_SERVICE *q_u, prs_struct *ps, int depth)
329 if (q_u == NULL)
330 return False;
332 prs_debug(ps, depth, desc, "svcctl_io_q_open_service");
333 depth++;
335 if(!prs_align(ps))
336 return False;
338 if(!smb_io_pol_hnd("scm_pol", &q_u->handle, ps, depth))
339 return False;
341 if(!smb_io_unistr2("servicename", &q_u->servicename, 1, ps, depth))
342 return False;
344 if(!prs_align(ps))
345 return False;
347 if(!prs_uint32("access", ps, depth, &q_u->access))
348 return False;
350 return True;
353 /*******************************************************************
354 ********************************************************************/
356 BOOL svcctl_io_r_open_service(const char *desc, SVCCTL_R_OPEN_SERVICE *r_u, prs_struct *ps, int depth)
358 if (r_u == NULL)
359 return False;
361 prs_debug(ps, depth, desc, "svcctl_io_r_open_service");
362 depth++;
364 if(!prs_align(ps))
365 return False;
367 if(!smb_io_pol_hnd("service_pol", &r_u->handle, ps, depth))
368 return False;
370 if(!prs_werror("status", ps, depth, &r_u->status))
371 return False;
373 return True;
376 /*******************************************************************
377 ********************************************************************/
379 BOOL svcctl_io_q_query_status(const char *desc, SVCCTL_Q_QUERY_STATUS *q_u, prs_struct *ps, int depth)
381 if (q_u == NULL)
382 return False;
384 prs_debug(ps, depth, desc, "svcctl_io_q_query_status");
385 depth++;
387 if(!prs_align(ps))
388 return False;
390 if(!smb_io_pol_hnd("service_pol", &q_u->handle, ps, depth))
391 return False;
393 return True;
396 /*******************************************************************
397 ********************************************************************/
399 BOOL svcctl_io_r_query_status(const char *desc, SVCCTL_R_QUERY_STATUS *r_u, prs_struct *ps, int depth)
401 if (r_u == NULL)
402 return False;
404 prs_debug(ps, depth, desc, "svcctl_io_r_query_status");
405 depth++;
407 if(!prs_align(ps))
408 return False;
410 if(!svcctl_io_service_status("service_status", &r_u->svc_status, ps, depth))
411 return False;
413 if(!prs_werror("status", ps, depth, &r_u->status))
414 return False;
416 return True;
419 /*******************************************************************
420 ********************************************************************/
422 BOOL svcctl_io_q_enum_services_status(const char *desc, SVCCTL_Q_ENUM_SERVICES_STATUS *q_u, prs_struct *ps, int depth)
424 if (q_u == NULL)
425 return False;
427 prs_debug(ps, depth, desc, "svcctl_io_q_enum_services_status");
428 depth++;
430 if(!prs_align(ps))
431 return False;
433 if(!smb_io_pol_hnd("scm_pol", &q_u->handle, ps, depth))
434 return False;
436 if(!prs_uint32("type", ps, depth, &q_u->type))
437 return False;
438 if(!prs_uint32("state", ps, depth, &q_u->state))
439 return False;
440 if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size))
441 return False;
443 if(!prs_pointer("resume", ps, depth, (void**)&q_u->resume, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
444 return False;
446 return True;
449 /*******************************************************************
450 ********************************************************************/
452 BOOL svcctl_io_r_enum_services_status(const char *desc, SVCCTL_R_ENUM_SERVICES_STATUS *r_u, prs_struct *ps, int depth)
454 if (r_u == NULL)
455 return False;
457 prs_debug(ps, depth, desc, "svcctl_io_r_enum_services_status");
458 depth++;
460 if(!prs_align(ps))
461 return False;
463 if (!prs_rpcbuffer("", ps, depth, &r_u->buffer))
464 return False;
466 if(!prs_align(ps))
467 return False;
469 if(!prs_uint32("needed", ps, depth, &r_u->needed))
470 return False;
471 if(!prs_uint32("returned", ps, depth, &r_u->returned))
472 return False;
474 if(!prs_pointer("resume", ps, depth, (void**)&r_u->resume, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
475 return False;
477 if(!prs_werror("status", ps, depth, &r_u->status))
478 return False;
480 return True;
483 /*******************************************************************
484 ********************************************************************/
486 BOOL svcctl_io_q_start_service(const char *desc, SVCCTL_Q_START_SERVICE *q_u, prs_struct *ps, int depth)
488 if (q_u == NULL)
489 return False;
491 prs_debug(ps, depth, desc, "svcctl_io_q_start_service");
492 depth++;
494 if(!prs_align(ps))
495 return False;
497 if(!smb_io_pol_hnd("service_pol", &q_u->handle, ps, depth))
498 return False;
500 if(!prs_uint32("parmcount", ps, depth, &q_u->parmcount))
501 return False;
503 if ( !prs_pointer("rights", ps, depth, (void**)&q_u->parameters, sizeof(UNISTR4_ARRAY), (PRS_POINTER_CAST)prs_unistr4_array) )
504 return False;
506 return True;
509 /*******************************************************************
510 ********************************************************************/
512 BOOL svcctl_io_r_start_service(const char *desc, SVCCTL_R_START_SERVICE *r_u, prs_struct *ps, int depth)
514 if (r_u == NULL)
515 return False;
517 prs_debug(ps, depth, desc, "svcctl_io_r_start_service");
518 depth++;
520 if(!prs_werror("status", ps, depth, &r_u->status))
521 return False;
523 return True;
527 /*******************************************************************
528 ********************************************************************/
530 BOOL svcctl_io_q_enum_dependent_services(const char *desc, SVCCTL_Q_ENUM_DEPENDENT_SERVICES *q_u, prs_struct *ps, int depth)
532 if (q_u == NULL)
533 return False;
535 prs_debug(ps, depth, desc, "svcctl_io_q_enum_dependent_services");
536 depth++;
538 if(!prs_align(ps))
539 return False;
541 if(!smb_io_pol_hnd("service_pol", &q_u->handle, ps, depth))
542 return False;
544 if(!prs_uint32("state", ps, depth, &q_u->state))
545 return False;
546 if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size))
547 return False;
549 return True;
552 /*******************************************************************
553 ********************************************************************/
555 BOOL svcctl_io_r_enum_dependent_services(const char *desc, SVCCTL_R_ENUM_DEPENDENT_SERVICES *r_u, prs_struct *ps, int depth)
557 if (r_u == NULL)
558 return False;
560 prs_debug(ps, depth, desc, "svcctl_io_r_enum_dependent_services");
561 depth++;
563 if(!prs_align(ps))
564 return False;
566 if (!prs_rpcbuffer("", ps, depth, &r_u->buffer))
567 return False;
569 if(!prs_align(ps))
570 return False;
572 if(!prs_uint32("needed", ps, depth, &r_u->needed))
573 return False;
574 if(!prs_uint32("returned", ps, depth, &r_u->returned))
575 return False;
577 if(!prs_werror("status", ps, depth, &r_u->status))
578 return False;
580 return True;
583 /*******************************************************************
584 ********************************************************************/
586 BOOL svcctl_io_q_control_service(const char *desc, SVCCTL_Q_CONTROL_SERVICE *q_u, prs_struct *ps, int depth)
588 if (q_u == NULL)
589 return False;
591 prs_debug(ps, depth, desc, "svcctl_io_q_control_service");
592 depth++;
594 if(!prs_align(ps))
595 return False;
597 if(!smb_io_pol_hnd("service_pol", &q_u->handle, ps, depth))
598 return False;
600 if(!prs_uint32("control", ps, depth, &q_u->control))
601 return False;
603 return True;
606 /*******************************************************************
607 ********************************************************************/
609 BOOL svcctl_io_r_control_service(const char *desc, SVCCTL_R_CONTROL_SERVICE *r_u, prs_struct *ps, int depth)
611 if (r_u == NULL)
612 return False;
614 prs_debug(ps, depth, desc, "svcctl_io_r_control_service");
615 depth++;
617 if(!prs_align(ps))
618 return False;
620 if(!svcctl_io_service_status("service_status", &r_u->svc_status, ps, depth))
621 return False;
623 if(!prs_werror("status", ps, depth, &r_u->status))
624 return False;
626 return True;
630 /*******************************************************************
631 ********************************************************************/
633 BOOL svcctl_io_q_query_service_config(const char *desc, SVCCTL_Q_QUERY_SERVICE_CONFIG *q_u, prs_struct *ps, int depth)
635 if (q_u == NULL)
636 return False;
638 prs_debug(ps, depth, desc, "svcctl_io_q_query_service_config");
639 depth++;
641 if(!prs_align(ps))
642 return False;
644 if(!smb_io_pol_hnd("service_pol", &q_u->handle, ps, depth))
645 return False;
647 if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size))
648 return False;
650 return True;
653 /*******************************************************************
654 ********************************************************************/
656 BOOL svcctl_io_r_query_service_config(const char *desc, SVCCTL_R_QUERY_SERVICE_CONFIG *r_u, prs_struct *ps, int depth)
658 if (r_u == NULL)
659 return False;
661 prs_debug(ps, depth, desc, "svcctl_io_r_query_service_config");
662 depth++;
665 if(!prs_align(ps))
666 return False;
668 if(!svcctl_io_service_config("config", &r_u->config, ps, depth))
669 return False;
671 if(!prs_uint32("needed", ps, depth, &r_u->needed))
672 return False;
674 if(!prs_werror("status", ps, depth, &r_u->status))
675 return False;
678 return True;
681 /*******************************************************************
682 ********************************************************************/
684 BOOL svcctl_io_q_query_service_config2(const char *desc, SVCCTL_Q_QUERY_SERVICE_CONFIG2 *q_u, prs_struct *ps, int depth)
686 if (q_u == NULL)
687 return False;
689 prs_debug(ps, depth, desc, "svcctl_io_q_query_service_config2");
690 depth++;
692 if(!prs_align(ps))
693 return False;
695 if(!smb_io_pol_hnd("service_pol", &q_u->handle, ps, depth))
696 return False;
698 if(!prs_uint32("info_level", ps, depth, &q_u->info_level))
699 return False;
701 if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size))
702 return False;
704 return True;
708 /*******************************************************************
709 Creates a service description response buffer.
710 The format seems to be DWORD:length of buffer
711 DWORD:offset (fixed as four)
712 UNISTR: unicode description in the rest of the buffer
713 ********************************************************************/
715 void init_service_description_buffer(RPC_DATA_BLOB *str, const char *service_desc, int blob_length)
717 uint32 offset;
718 char *bp;
720 ZERO_STRUCTP(str);
722 offset = 4;
724 /* set up string lengths. */
726 str->buf_len = create_rpc_blob(str, blob_length);
727 DEBUG(10, ("init_service_description buffer: Allocated a blob of [%d] \n",str->buf_len));
729 if ( str && str->buffer && str->buf_len) {
730 memset(str->buffer,0,str->buf_len);
731 memcpy(str->buffer, &offset, sizeof(uint32));
732 bp = &str->buffer[4];
733 if (service_desc) {
734 rpcstr_push(bp, service_desc,str->buf_len-4,0);
739 /*******************************************************************
740 ********************************************************************/
742 BOOL svcctl_io_q_query_service_status_ex(const char *desc, SVCCTL_Q_QUERY_SERVICE_STATUSEX *q_u, prs_struct *ps, int depth)
744 if (q_u == NULL)
745 return False;
747 prs_debug(ps, depth, desc, "svcctl_io_q_query_service_status_ex");
748 depth++;
750 if(!prs_align(ps))
751 return False;
753 if(!smb_io_pol_hnd("service_pol", &q_u->handle, ps, depth))
754 return False;
756 if(!prs_uint32("info_level", ps, depth, &q_u->info_level))
757 return False;
759 if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size))
760 return False;
762 return True;
766 /*******************************************************************
767 ********************************************************************/
769 BOOL svcctl_io_r_query_service_status_ex(const char *desc, SVCCTL_R_QUERY_SERVICE_STATUSEX *r_u, prs_struct *ps, int depth)
771 if ( !r_u )
772 return False;
774 prs_debug(ps, depth, desc, "svcctl_io_r_query_service_status_ex");
775 depth++;
777 if (!prs_rpcbuffer("", ps, depth, &r_u->buffer))
778 return False;
780 if(!prs_align(ps))
781 return False;
783 if(!prs_uint32("needed", ps, depth, &r_u->needed))
784 return False;
786 if(!prs_werror("status", ps, depth, &r_u->status))
787 return False;
789 return True;
792 /*******************************************************************
793 ********************************************************************/
795 BOOL svcctl_io_r_query_service_config2(const char *desc, SVCCTL_R_QUERY_SERVICE_CONFIG2 *r_u, prs_struct *ps, int depth)
797 if ( !r_u )
798 return False;
800 prs_debug(ps, depth, desc, "svcctl_io_r_query_service_config2");
801 depth++;
803 if(!prs_align(ps))
804 return False;
806 if(!prs_uint32("returned", ps, depth, &r_u->returned))
807 return False;
809 if (r_u->returned > 4) {
810 if (!prs_uint32("offset", ps, depth, &r_u->offset))
811 return False;
812 if(!prs_unistr2(True, "description ", ps, depth, r_u->description))
813 return False;
814 if(!prs_align(ps))
815 return False;
816 } else {
817 /* offset does double duty here */
818 r_u->offset = 0;
819 if (!prs_uint32("offset", ps, depth, &r_u->offset))
820 return False;
823 if (!prs_uint32("needed", ps, depth, &r_u->needed))
824 return False;
826 if(!prs_werror("status", ps, depth, &r_u->status))
827 return False;
829 return True;