2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Gerald (Jerry) 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/>.
23 #define DBGC_CLASS DBGC_RPC_PARSE
25 /*******************************************************************
26 ********************************************************************/
28 static bool svcctl_io_service_status( const char *desc, SERVICE_STATUS *status, prs_struct *ps, int depth )
31 prs_debug(ps, depth, desc, "svcctl_io_service_status");
34 if(!prs_uint32("type", ps, depth, &status->type))
37 if(!prs_uint32("state", ps, depth, &status->state))
40 if(!prs_uint32("controls_accepted", ps, depth, &status->controls_accepted))
43 if(!prs_werror("win32_exit_code", ps, depth, &status->win32_exit_code))
46 if(!prs_uint32("service_exit_code", ps, depth, &status->service_exit_code))
49 if(!prs_uint32("check_point", ps, depth, &status->check_point))
52 if(!prs_uint32("wait_hint", ps, depth, &status->wait_hint))
58 /*******************************************************************
59 ********************************************************************/
61 static bool svcctl_io_service_config( const char *desc, SERVICE_CONFIG *config, prs_struct *ps, int depth )
64 prs_debug(ps, depth, desc, "svcctl_io_service_config");
67 if(!prs_uint32("service_type", ps, depth, &config->service_type))
69 if(!prs_uint32("start_type", ps, depth, &config->start_type))
71 if(!prs_uint32("error_control", ps, depth, &config->error_control))
74 if (!prs_io_unistr2_p("", ps, depth, &config->executablepath))
76 if (!prs_io_unistr2_p("", ps, depth, &config->loadordergroup))
79 if(!prs_uint32("tag_id", ps, depth, &config->tag_id))
82 if (!prs_io_unistr2_p("", ps, depth, &config->dependencies))
84 if (!prs_io_unistr2_p("", ps, depth, &config->startname))
86 if (!prs_io_unistr2_p("", ps, depth, &config->displayname))
89 if (!prs_io_unistr2("", ps, depth, config->executablepath))
91 if (!prs_io_unistr2("", ps, depth, config->loadordergroup))
93 if (!prs_io_unistr2("", ps, depth, config->dependencies))
95 if (!prs_io_unistr2("", ps, depth, config->startname))
97 if (!prs_io_unistr2("", ps, depth, config->displayname))
103 /*******************************************************************
104 ********************************************************************/
106 bool svcctl_io_enum_services_status( const char *desc, ENUM_SERVICES_STATUS *enum_status, RPC_BUFFER *buffer, int depth )
108 prs_struct *ps=&buffer->prs;
110 prs_debug(ps, depth, desc, "svcctl_io_enum_services_status");
113 if ( !smb_io_relstr("servicename", buffer, depth, &enum_status->servicename) )
115 if ( !smb_io_relstr("displayname", buffer, depth, &enum_status->displayname) )
118 if ( !svcctl_io_service_status("svc_status", &enum_status->status, ps, depth) )
124 /*******************************************************************
125 ********************************************************************/
127 bool svcctl_io_service_status_process( const char *desc, SERVICE_STATUS_PROCESS *status, RPC_BUFFER *buffer, int depth )
129 prs_struct *ps=&buffer->prs;
131 prs_debug(ps, depth, desc, "svcctl_io_service_status_process");
134 if ( !svcctl_io_service_status("status", &status->status, ps, depth) )
139 if(!prs_uint32("process_id", ps, depth, &status->process_id))
141 if(!prs_uint32("service_flags", ps, depth, &status->service_flags))
147 /*******************************************************************
148 ********************************************************************/
150 uint32 svcctl_sizeof_enum_services_status( ENUM_SERVICES_STATUS *status )
154 size += size_of_relative_string( &status->servicename );
155 size += size_of_relative_string( &status->displayname );
156 size += sizeof(SERVICE_STATUS);
161 /********************************************************************
162 ********************************************************************/
164 static uint32 sizeof_unistr2( UNISTR2 *string )
171 size = sizeof(uint32) * 3; /* length fields */
172 size += 2 * string->uni_max_len; /* string data */
173 size += size % 4; /* alignment */
178 /********************************************************************
179 ********************************************************************/
181 uint32 svcctl_sizeof_service_config( SERVICE_CONFIG *config )
185 size = sizeof(uint32) * 4; /* static uint32 fields */
187 /* now add the UNISTR2 + pointer sizes */
189 size += sizeof(uint32) * sizeof_unistr2(config->executablepath);
190 size += sizeof(uint32) * sizeof_unistr2(config->loadordergroup);
191 size += sizeof(uint32) * sizeof_unistr2(config->dependencies);
192 size += sizeof(uint32) * sizeof_unistr2(config->startname);
193 size += sizeof(uint32) * sizeof_unistr2(config->displayname);
198 /*******************************************************************
199 ********************************************************************/
201 bool svcctl_io_q_open_scmanager(const char *desc, SVCCTL_Q_OPEN_SCMANAGER *q_u, prs_struct *ps, int depth)
206 prs_debug(ps, depth, desc, "svcctl_io_q_open_scmanager");
212 if(!prs_pointer("servername", ps, depth, (void*)&q_u->servername, sizeof(UNISTR2), (PRS_POINTER_CAST)prs_io_unistr2))
217 if(!prs_pointer("database", ps, depth, (void*)&q_u->database, sizeof(UNISTR2), (PRS_POINTER_CAST)prs_io_unistr2))
222 if(!prs_uint32("access", ps, depth, &q_u->access))
228 /*******************************************************************
229 ********************************************************************/
231 bool svcctl_io_r_open_scmanager(const char *desc, SVCCTL_R_OPEN_SCMANAGER *r_u, prs_struct *ps, int depth)
236 prs_debug(ps, depth, desc, "svcctl_io_r_open_scmanager");
242 if(!smb_io_pol_hnd("scm_pol", &r_u->handle, ps, depth))
245 if(!prs_werror("status", ps, depth, &r_u->status))
251 /*******************************************************************
252 ********************************************************************/
254 bool svcctl_io_q_get_display_name(const char *desc, SVCCTL_Q_GET_DISPLAY_NAME *q_u, prs_struct *ps, int depth)
259 prs_debug(ps, depth, desc, "svcctl_io_q_get_display_name");
265 if(!smb_io_pol_hnd("scm_pol", &q_u->handle, ps, depth))
268 if(!smb_io_unistr2("servicename", &q_u->servicename, 1, ps, depth))
274 if(!prs_uint32("display_name_len", ps, depth, &q_u->display_name_len))
280 /*******************************************************************
281 ********************************************************************/
283 bool init_svcctl_r_get_display_name( SVCCTL_R_GET_DISPLAY_NAME *r_u, const char *displayname )
285 r_u->display_name_len = strlen(displayname);
286 init_unistr2( &r_u->displayname, displayname, UNI_STR_TERMINATE );
291 /*******************************************************************
292 ********************************************************************/
294 bool svcctl_io_r_get_display_name(const char *desc, SVCCTL_R_GET_DISPLAY_NAME *r_u, prs_struct *ps, int depth)
299 prs_debug(ps, depth, desc, "svcctl_io_r_get_display_name");
306 if(!smb_io_unistr2("displayname", &r_u->displayname, 1, ps, depth))
312 if(!prs_uint32("display_name_len", ps, depth, &r_u->display_name_len))
315 if(!prs_werror("status", ps, depth, &r_u->status))
322 /*******************************************************************
323 ********************************************************************/
325 bool svcctl_io_q_open_service(const char *desc, SVCCTL_Q_OPEN_SERVICE *q_u, prs_struct *ps, int depth)
330 prs_debug(ps, depth, desc, "svcctl_io_q_open_service");
336 if(!smb_io_pol_hnd("scm_pol", &q_u->handle, ps, depth))
339 if(!smb_io_unistr2("servicename", &q_u->servicename, 1, ps, depth))
345 if(!prs_uint32("access", ps, depth, &q_u->access))
351 /*******************************************************************
352 ********************************************************************/
354 bool svcctl_io_r_open_service(const char *desc, SVCCTL_R_OPEN_SERVICE *r_u, prs_struct *ps, int depth)
359 prs_debug(ps, depth, desc, "svcctl_io_r_open_service");
365 if(!smb_io_pol_hnd("service_pol", &r_u->handle, ps, depth))
368 if(!prs_werror("status", ps, depth, &r_u->status))
374 /*******************************************************************
375 ********************************************************************/
377 bool svcctl_io_q_query_status(const char *desc, SVCCTL_Q_QUERY_STATUS *q_u, prs_struct *ps, int depth)
382 prs_debug(ps, depth, desc, "svcctl_io_q_query_status");
388 if(!smb_io_pol_hnd("service_pol", &q_u->handle, ps, depth))
394 /*******************************************************************
395 ********************************************************************/
397 bool svcctl_io_r_query_status(const char *desc, SVCCTL_R_QUERY_STATUS *r_u, prs_struct *ps, int depth)
402 prs_debug(ps, depth, desc, "svcctl_io_r_query_status");
408 if(!svcctl_io_service_status("service_status", &r_u->svc_status, ps, depth))
411 if(!prs_werror("status", ps, depth, &r_u->status))
417 /*******************************************************************
418 ********************************************************************/
420 bool svcctl_io_q_enum_services_status(const char *desc, SVCCTL_Q_ENUM_SERVICES_STATUS *q_u, prs_struct *ps, int depth)
425 prs_debug(ps, depth, desc, "svcctl_io_q_enum_services_status");
431 if(!smb_io_pol_hnd("scm_pol", &q_u->handle, ps, depth))
434 if(!prs_uint32("type", ps, depth, &q_u->type))
436 if(!prs_uint32("state", ps, depth, &q_u->state))
438 if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size))
441 if(!prs_pointer("resume", ps, depth, (void*)&q_u->resume, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
447 /*******************************************************************
448 ********************************************************************/
450 bool svcctl_io_r_enum_services_status(const char *desc, SVCCTL_R_ENUM_SERVICES_STATUS *r_u, prs_struct *ps, int depth)
455 prs_debug(ps, depth, desc, "svcctl_io_r_enum_services_status");
461 if (!prs_rpcbuffer("", ps, depth, &r_u->buffer))
467 if(!prs_uint32("needed", ps, depth, &r_u->needed))
469 if(!prs_uint32("returned", ps, depth, &r_u->returned))
472 if(!prs_pointer("resume", ps, depth, (void*)&r_u->resume, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32))
475 if(!prs_werror("status", ps, depth, &r_u->status))
481 /*******************************************************************
482 ********************************************************************/
484 bool svcctl_io_q_start_service(const char *desc, SVCCTL_Q_START_SERVICE *q_u, prs_struct *ps, int depth)
489 prs_debug(ps, depth, desc, "svcctl_io_q_start_service");
495 if(!smb_io_pol_hnd("service_pol", &q_u->handle, ps, depth))
498 if(!prs_uint32("parmcount", ps, depth, &q_u->parmcount))
501 if ( !prs_pointer("rights", ps, depth, (void*)&q_u->parameters, sizeof(UNISTR4_ARRAY), (PRS_POINTER_CAST)prs_unistr4_array) )
507 /*******************************************************************
508 ********************************************************************/
510 bool svcctl_io_r_start_service(const char *desc, SVCCTL_R_START_SERVICE *r_u, prs_struct *ps, int depth)
515 prs_debug(ps, depth, desc, "svcctl_io_r_start_service");
518 if(!prs_werror("status", ps, depth, &r_u->status))
525 /*******************************************************************
526 ********************************************************************/
528 bool svcctl_io_q_enum_dependent_services(const char *desc, SVCCTL_Q_ENUM_DEPENDENT_SERVICES *q_u, prs_struct *ps, int depth)
533 prs_debug(ps, depth, desc, "svcctl_io_q_enum_dependent_services");
539 if(!smb_io_pol_hnd("service_pol", &q_u->handle, ps, depth))
542 if(!prs_uint32("state", ps, depth, &q_u->state))
544 if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size))
550 /*******************************************************************
551 ********************************************************************/
553 bool svcctl_io_r_enum_dependent_services(const char *desc, SVCCTL_R_ENUM_DEPENDENT_SERVICES *r_u, prs_struct *ps, int depth)
558 prs_debug(ps, depth, desc, "svcctl_io_r_enum_dependent_services");
564 if (!prs_rpcbuffer("", ps, depth, &r_u->buffer))
570 if(!prs_uint32("needed", ps, depth, &r_u->needed))
572 if(!prs_uint32("returned", ps, depth, &r_u->returned))
575 if(!prs_werror("status", ps, depth, &r_u->status))
581 /*******************************************************************
582 ********************************************************************/
584 bool svcctl_io_q_control_service(const char *desc, SVCCTL_Q_CONTROL_SERVICE *q_u, prs_struct *ps, int depth)
589 prs_debug(ps, depth, desc, "svcctl_io_q_control_service");
595 if(!smb_io_pol_hnd("service_pol", &q_u->handle, ps, depth))
598 if(!prs_uint32("control", ps, depth, &q_u->control))
604 /*******************************************************************
605 ********************************************************************/
607 bool svcctl_io_r_control_service(const char *desc, SVCCTL_R_CONTROL_SERVICE *r_u, prs_struct *ps, int depth)
612 prs_debug(ps, depth, desc, "svcctl_io_r_control_service");
618 if(!svcctl_io_service_status("service_status", &r_u->svc_status, ps, depth))
621 if(!prs_werror("status", ps, depth, &r_u->status))
628 /*******************************************************************
629 ********************************************************************/
631 bool svcctl_io_q_query_service_config(const char *desc, SVCCTL_Q_QUERY_SERVICE_CONFIG *q_u, prs_struct *ps, int depth)
636 prs_debug(ps, depth, desc, "svcctl_io_q_query_service_config");
642 if(!smb_io_pol_hnd("service_pol", &q_u->handle, ps, depth))
645 if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size))
651 /*******************************************************************
652 ********************************************************************/
654 bool svcctl_io_r_query_service_config(const char *desc, SVCCTL_R_QUERY_SERVICE_CONFIG *r_u, prs_struct *ps, int depth)
659 prs_debug(ps, depth, desc, "svcctl_io_r_query_service_config");
666 if(!svcctl_io_service_config("config", &r_u->config, ps, depth))
669 if(!prs_uint32("needed", ps, depth, &r_u->needed))
672 if(!prs_werror("status", ps, depth, &r_u->status))
679 /*******************************************************************
680 ********************************************************************/
682 bool svcctl_io_q_query_service_config2(const char *desc, SVCCTL_Q_QUERY_SERVICE_CONFIG2 *q_u, prs_struct *ps, int depth)
687 prs_debug(ps, depth, desc, "svcctl_io_q_query_service_config2");
693 if(!smb_io_pol_hnd("service_pol", &q_u->handle, ps, depth))
696 if(!prs_uint32("level", ps, depth, &q_u->level))
699 if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size))
706 /*******************************************************************
707 ********************************************************************/
709 void init_service_description_buffer(SERVICE_DESCRIPTION *desc, const char *service_desc )
711 desc->unknown = 0x04; /* always 0x0000 0004 (no idea what this is) */
712 init_unistr( &desc->description, service_desc );
715 /*******************************************************************
716 ********************************************************************/
718 bool svcctl_io_service_description( const char *desc, SERVICE_DESCRIPTION *description, RPC_BUFFER *buffer, int depth )
720 prs_struct *ps = &buffer->prs;
722 prs_debug(ps, depth, desc, "svcctl_io_service_description");
725 if ( !prs_uint32("unknown", ps, depth, &description->unknown) )
727 if ( !prs_unistr("description", ps, depth, &description->description) )
733 /*******************************************************************
734 ********************************************************************/
736 uint32 svcctl_sizeof_service_description( SERVICE_DESCRIPTION *desc )
741 /* make sure to include the terminating NULL */
742 return ( sizeof(uint32) + (2*(str_len_uni(&desc->description)+1)) );
745 /*******************************************************************
746 ********************************************************************/
748 static bool svcctl_io_action( const char *desc, SC_ACTION *action, prs_struct *ps, int depth )
751 prs_debug(ps, depth, desc, "svcctl_io_action");
754 if ( !prs_uint32("type", ps, depth, &action->type) )
756 if ( !prs_uint32("delay", ps, depth, &action->delay) )
762 /*******************************************************************
763 ********************************************************************/
765 bool svcctl_io_service_fa( const char *desc, SERVICE_FAILURE_ACTIONS *fa, RPC_BUFFER *buffer, int depth )
767 prs_struct *ps = &buffer->prs;
770 prs_debug(ps, depth, desc, "svcctl_io_service_description");
773 if ( !prs_uint32("reset_period", ps, depth, &fa->reset_period) )
776 if ( !prs_pointer( desc, ps, depth, (void*)&fa->rebootmsg, sizeof(UNISTR2), (PRS_POINTER_CAST)prs_io_unistr2 ) )
778 if ( !prs_pointer( desc, ps, depth, (void*)&fa->command, sizeof(UNISTR2), (PRS_POINTER_CAST)prs_io_unistr2 ) )
781 if ( !prs_uint32("num_actions", ps, depth, &fa->num_actions) )
784 if ( UNMARSHALLING(ps)) {
785 if (fa->num_actions) {
786 if ( !(fa->actions = TALLOC_ARRAY( talloc_tos(), SC_ACTION, fa->num_actions )) ) {
787 DEBUG(0,("svcctl_io_service_fa: talloc() failure!\n"));
795 for ( i=0; i<fa->num_actions; i++ ) {
796 if ( !svcctl_io_action( "actions", &fa->actions[i], ps, depth ) )
803 /*******************************************************************
804 ********************************************************************/
806 uint32 svcctl_sizeof_service_fa( SERVICE_FAILURE_ACTIONS *fa)
813 size = sizeof(uint32) * 2;
814 size += sizeof_unistr2( fa->rebootmsg );
815 size += sizeof_unistr2( fa->command );
816 size += sizeof(SC_ACTION) * fa->num_actions;
821 /*******************************************************************
822 ********************************************************************/
824 bool svcctl_io_r_query_service_config2(const char *desc, SVCCTL_R_QUERY_SERVICE_CONFIG2 *r_u, prs_struct *ps, int depth)
829 prs_debug(ps, depth, desc, "svcctl_io_r_query_service_config2");
832 if ( !prs_align(ps) )
835 if (!prs_rpcbuffer("", ps, depth, &r_u->buffer))
840 if (!prs_uint32("needed", ps, depth, &r_u->needed))
843 if(!prs_werror("status", ps, depth, &r_u->status))
850 /*******************************************************************
851 ********************************************************************/
853 bool svcctl_io_q_query_service_status_ex(const char *desc, SVCCTL_Q_QUERY_SERVICE_STATUSEX *q_u, prs_struct *ps, int depth)
858 prs_debug(ps, depth, desc, "svcctl_io_q_query_service_status_ex");
864 if(!smb_io_pol_hnd("service_pol", &q_u->handle, ps, depth))
867 if(!prs_uint32("level", ps, depth, &q_u->level))
870 if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size))
877 /*******************************************************************
878 ********************************************************************/
880 bool svcctl_io_r_query_service_status_ex(const char *desc, SVCCTL_R_QUERY_SERVICE_STATUSEX *r_u, prs_struct *ps, int depth)
885 prs_debug(ps, depth, desc, "svcctl_io_r_query_service_status_ex");
888 if (!prs_rpcbuffer("", ps, depth, &r_u->buffer))
894 if(!prs_uint32("needed", ps, depth, &r_u->needed))
897 if(!prs_werror("status", ps, depth, &r_u->status))
903 /*******************************************************************
904 ********************************************************************/
906 bool svcctl_io_q_lock_service_db(const char *desc, SVCCTL_Q_LOCK_SERVICE_DB *q_u, prs_struct *ps, int depth)
911 prs_debug(ps, depth, desc, "svcctl_io_q_lock_service_db");
917 if(!smb_io_pol_hnd("scm_handle", &q_u->handle, ps, depth))
924 /*******************************************************************
925 ********************************************************************/
927 bool svcctl_io_r_lock_service_db(const char *desc, SVCCTL_R_LOCK_SERVICE_DB *r_u, prs_struct *ps, int depth)
932 prs_debug(ps, depth, desc, "svcctl_io_r_lock_service_db");
938 if(!smb_io_pol_hnd("lock_handle", &r_u->h_lock, ps, depth))
941 if(!prs_werror("status", ps, depth, &r_u->status))
947 /*******************************************************************
948 ********************************************************************/
950 bool svcctl_io_q_unlock_service_db(const char *desc, SVCCTL_Q_UNLOCK_SERVICE_DB *q_u, prs_struct *ps, int depth)
955 prs_debug(ps, depth, desc, "svcctl_io_q_unlock_service_db");
961 if(!smb_io_pol_hnd("h_lock", &q_u->h_lock, ps, depth))
968 /*******************************************************************
969 ********************************************************************/
971 bool svcctl_io_r_unlock_service_db(const char *desc, SVCCTL_R_UNLOCK_SERVICE_DB *r_u, prs_struct *ps, int depth)
976 prs_debug(ps, depth, desc, "svcctl_io_r_unlock_service_db");
982 if(!prs_werror("status", ps, depth, &r_u->status))
988 /*******************************************************************
989 ********************************************************************/
991 bool svcctl_io_q_query_service_sec(const char *desc, SVCCTL_Q_QUERY_SERVICE_SEC *q_u, prs_struct *ps, int depth)
996 prs_debug(ps, depth, desc, "svcctl_io_q_query_service_sec");
1002 if(!smb_io_pol_hnd("handle", &q_u->handle, ps, depth))
1004 if(!prs_uint32("security_flags", ps, depth, &q_u->security_flags))
1006 if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size))
1013 /*******************************************************************
1014 ********************************************************************/
1016 bool svcctl_io_r_query_service_sec(const char *desc, SVCCTL_R_QUERY_SERVICE_SEC *r_u, prs_struct *ps, int depth)
1021 prs_debug(ps, depth, desc, "svcctl_io_r_query_service_sec");
1027 if (!prs_rpcbuffer("buffer", ps, depth, &r_u->buffer))
1030 if(!prs_uint32("needed", ps, depth, &r_u->needed))
1033 if(!prs_werror("status", ps, depth, &r_u->status))
1039 /*******************************************************************
1040 ********************************************************************/
1042 bool svcctl_io_q_set_service_sec(const char *desc, SVCCTL_Q_SET_SERVICE_SEC *q_u, prs_struct *ps, int depth)
1047 prs_debug(ps, depth, desc, "svcctl_io_q_set_service_sec");
1053 if(!smb_io_pol_hnd("handle", &q_u->handle, ps, depth))
1055 if(!prs_uint32("security_flags", ps, depth, &q_u->security_flags))
1058 if (!prs_rpcbuffer("buffer", ps, depth, &q_u->buffer))
1064 if(!prs_uint32("buffer_size", ps, depth, &q_u->buffer_size))
1071 /*******************************************************************
1072 ********************************************************************/
1074 bool svcctl_io_r_set_service_sec(const char *desc, SVCCTL_R_SET_SERVICE_SEC *r_u, prs_struct *ps, int depth)
1079 prs_debug(ps, depth, desc, "svcctl_io_r_set_service_sec");
1085 if(!prs_werror("status", ps, depth, &r_u->status))