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 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.
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");
35 if(!prs_uint32("type", ps
, depth
, &status
->type
))
38 if(!prs_uint32("state", ps
, depth
, &status
->state
))
41 if(!prs_uint32("controls_accepted", ps
, depth
, &status
->controls_accepted
))
44 if(!prs_uint32("win32_exit_code", ps
, depth
, &status
->win32_exit_code
))
47 if(!prs_uint32("service_exit_code", ps
, depth
, &status
->service_exit_code
))
50 if(!prs_uint32("check_point", ps
, depth
, &status
->check_point
))
53 if(!prs_uint32("wait_hint", ps
, depth
, &status
->wait_hint
))
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");
68 if(!prs_uint32("service_type", ps
, depth
, &config
->service_type
))
70 if(!prs_uint32("start_type", ps
, depth
, &config
->start_type
))
72 if(!prs_uint32("error_control", ps
, depth
, &config
->error_control
))
75 if (!prs_io_unistr2_p("", ps
, depth
, &config
->executablepath
))
77 if (!prs_io_unistr2_p("", ps
, depth
, &config
->loadordergroup
))
80 if(!prs_uint32("tag_id", ps
, depth
, &config
->tag_id
))
83 if (!prs_io_unistr2_p("", ps
, depth
, &config
->dependencies
))
85 if (!prs_io_unistr2_p("", ps
, depth
, &config
->startname
))
87 if (!prs_io_unistr2_p("", ps
, depth
, &config
->displayname
))
90 if (!prs_io_unistr2("", ps
, depth
, config
->executablepath
))
92 if (!prs_io_unistr2("", ps
, depth
, config
->loadordergroup
))
94 if (!prs_io_unistr2("", ps
, depth
, config
->dependencies
))
96 if (!prs_io_unistr2("", ps
, depth
, config
->startname
))
98 if (!prs_io_unistr2("", ps
, depth
, config
->displayname
))
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");
112 if (!prs_io_unistr2("", ps
, depth
, svcdesc
))
119 /*******************************************************************
120 ********************************************************************/
122 BOOL
svcctl_io_enum_services_status( const char *desc
, ENUM_SERVICES_STATUS
*enum_status
, RPC_BUFFER
*buffer
, int depth
)
124 prs_struct
*ps
=&buffer
->prs
;
126 prs_debug(ps
, depth
, desc
, "svcctl_io_enum_services_status");
129 if ( !smb_io_relstr("servicename", buffer
, depth
, &enum_status
->servicename
) )
131 if ( !smb_io_relstr("displayname", buffer
, depth
, &enum_status
->displayname
) )
134 if ( !svcctl_io_service_status("svc_status", &enum_status
->status
, ps
, depth
) )
140 /*******************************************************************
141 ********************************************************************/
143 uint32
svcctl_sizeof_enum_services_status( ENUM_SERVICES_STATUS
*status
)
147 size
+= size_of_relative_string( &status
->servicename
);
148 size
+= size_of_relative_string( &status
->displayname
);
149 size
+= sizeof(SERVICE_STATUS
);
154 /*******************************************************************
155 ********************************************************************/
157 BOOL
svcctl_io_q_close_service(const char *desc
, SVCCTL_Q_CLOSE_SERVICE
*q_u
, prs_struct
*ps
, int depth
)
163 prs_debug(ps
, depth
, desc
, "svcctl_io_q_close_service");
169 if(!smb_io_pol_hnd("scm_pol", &q_u
->handle
, ps
, depth
))
176 /*******************************************************************
177 ********************************************************************/
179 BOOL
svcctl_io_r_close_service(const char *desc
, SVCCTL_R_CLOSE_SERVICE
*r_u
, prs_struct
*ps
, int depth
)
184 prs_debug(ps
, depth
, desc
, "svcctl_io_r_close_service");
190 if(!smb_io_pol_hnd("pol_handle", &r_u
->handle
, ps
, depth
))
193 if(!prs_werror("status", ps
, depth
, &r_u
->status
))
199 /*******************************************************************
200 ********************************************************************/
202 BOOL
svcctl_io_q_open_scmanager(const char *desc
, SVCCTL_Q_OPEN_SCMANAGER
*q_u
, prs_struct
*ps
, int depth
)
207 prs_debug(ps
, depth
, desc
, "svcctl_io_q_open_scmanager");
213 if(!prs_pointer("servername", ps
, depth
, (void**)&q_u
->servername
, sizeof(UNISTR2
), (PRS_POINTER_CAST
)prs_io_unistr2
))
218 if(!prs_pointer("database", ps
, depth
, (void**)&q_u
->database
, sizeof(UNISTR2
), (PRS_POINTER_CAST
)prs_io_unistr2
))
223 if(!prs_uint32("access", ps
, depth
, &q_u
->access
))
229 /*******************************************************************
230 ********************************************************************/
232 BOOL
svcctl_io_r_open_scmanager(const char *desc
, SVCCTL_R_OPEN_SCMANAGER
*r_u
, prs_struct
*ps
, int depth
)
237 prs_debug(ps
, depth
, desc
, "svcctl_io_r_open_scmanager");
243 if(!smb_io_pol_hnd("scm_pol", &r_u
->handle
, ps
, depth
))
246 if(!prs_werror("status", ps
, depth
, &r_u
->status
))
252 /*******************************************************************
253 ********************************************************************/
255 BOOL
svcctl_io_q_get_display_name(const char *desc
, SVCCTL_Q_GET_DISPLAY_NAME
*q_u
, prs_struct
*ps
, int depth
)
260 prs_debug(ps
, depth
, desc
, "svcctl_io_q_get_display_name");
266 if(!smb_io_pol_hnd("scm_pol", &q_u
->handle
, ps
, depth
))
269 if(!smb_io_unistr2("servicename", &q_u
->servicename
, 1, ps
, depth
))
275 if(!prs_uint32("display_name_len", ps
, depth
, &q_u
->display_name_len
))
281 /*******************************************************************
282 ********************************************************************/
284 BOOL
init_svcctl_r_get_display_name( SVCCTL_R_GET_DISPLAY_NAME
*r_u
, const char *displayname
)
286 r_u
->display_name_len
= strlen(displayname
);
287 init_unistr2( &r_u
->displayname
, displayname
, UNI_STR_TERMINATE
);
292 /*******************************************************************
293 ********************************************************************/
295 BOOL
svcctl_io_r_get_display_name(const char *desc
, SVCCTL_R_GET_DISPLAY_NAME
*r_u
, prs_struct
*ps
, int depth
)
300 prs_debug(ps
, depth
, desc
, "svcctl_io_r_get_display_name");
307 if(!smb_io_unistr2("displayname", &r_u
->displayname
, 1, ps
, depth
))
313 if(!prs_uint32("display_name_len", ps
, depth
, &r_u
->display_name_len
))
316 if(!prs_werror("status", ps
, depth
, &r_u
->status
))
323 /*******************************************************************
324 ********************************************************************/
326 BOOL
svcctl_io_q_open_service(const char *desc
, SVCCTL_Q_OPEN_SERVICE
*q_u
, prs_struct
*ps
, int depth
)
331 prs_debug(ps
, depth
, desc
, "svcctl_io_q_open_service");
337 if(!smb_io_pol_hnd("scm_pol", &q_u
->handle
, ps
, depth
))
340 if(!smb_io_unistr2("servicename", &q_u
->servicename
, 1, ps
, depth
))
346 if(!prs_uint32("access", ps
, depth
, &q_u
->access
))
352 /*******************************************************************
353 ********************************************************************/
355 BOOL
svcctl_io_r_open_service(const char *desc
, SVCCTL_R_OPEN_SERVICE
*r_u
, prs_struct
*ps
, int depth
)
360 prs_debug(ps
, depth
, desc
, "svcctl_io_r_open_service");
366 if(!smb_io_pol_hnd("service_pol", &r_u
->handle
, ps
, depth
))
369 if(!prs_werror("status", ps
, depth
, &r_u
->status
))
375 /*******************************************************************
376 ********************************************************************/
378 BOOL
svcctl_io_q_query_status(const char *desc
, SVCCTL_Q_QUERY_STATUS
*q_u
, prs_struct
*ps
, int depth
)
383 prs_debug(ps
, depth
, desc
, "svcctl_io_q_query_status");
389 if(!smb_io_pol_hnd("service_pol", &q_u
->handle
, ps
, depth
))
395 /*******************************************************************
396 ********************************************************************/
398 BOOL
svcctl_io_r_query_status(const char *desc
, SVCCTL_R_QUERY_STATUS
*r_u
, prs_struct
*ps
, int depth
)
403 prs_debug(ps
, depth
, desc
, "svcctl_io_r_query_status");
409 if(!svcctl_io_service_status("service_status", &r_u
->svc_status
, ps
, depth
))
412 if(!prs_werror("status", ps
, depth
, &r_u
->status
))
418 /*******************************************************************
419 ********************************************************************/
421 BOOL
svcctl_io_q_enum_services_status(const char *desc
, SVCCTL_Q_ENUM_SERVICES_STATUS
*q_u
, prs_struct
*ps
, int depth
)
426 prs_debug(ps
, depth
, desc
, "svcctl_io_q_enum_services_status");
432 if(!smb_io_pol_hnd("scm_pol", &q_u
->handle
, ps
, depth
))
435 if(!prs_uint32("type", ps
, depth
, &q_u
->type
))
437 if(!prs_uint32("state", ps
, depth
, &q_u
->state
))
439 if(!prs_uint32("buffer_size", ps
, depth
, &q_u
->buffer_size
))
442 if(!prs_pointer("resume", ps
, depth
, (void**)&q_u
->resume
, sizeof(uint32
), (PRS_POINTER_CAST
)prs_uint32
))
448 /*******************************************************************
449 ********************************************************************/
451 BOOL
svcctl_io_r_enum_services_status(const char *desc
, SVCCTL_R_ENUM_SERVICES_STATUS
*r_u
, prs_struct
*ps
, int depth
)
456 prs_debug(ps
, depth
, desc
, "svcctl_io_r_enum_services_status");
462 if (!prs_rpcbuffer("", ps
, depth
, &r_u
->buffer
))
468 if(!prs_uint32("needed", ps
, depth
, &r_u
->needed
))
470 if(!prs_uint32("returned", ps
, depth
, &r_u
->returned
))
473 if(!prs_pointer("resume", ps
, depth
, (void**)&r_u
->resume
, sizeof(uint32
), (PRS_POINTER_CAST
)prs_uint32
))
476 if(!prs_werror("status", ps
, depth
, &r_u
->status
))
482 /*******************************************************************
483 ********************************************************************/
485 BOOL
svcctl_io_q_start_service(const char *desc
, SVCCTL_Q_START_SERVICE
*q_u
, prs_struct
*ps
, int depth
)
490 prs_debug(ps
, depth
, desc
, "svcctl_io_q_start_service");
496 if(!smb_io_pol_hnd("service_pol", &q_u
->handle
, ps
, depth
))
499 if(!prs_uint32("parmcount", ps
, depth
, &q_u
->parmcount
))
502 if ( !prs_pointer("rights", ps
, depth
, (void**)&q_u
->parameters
, sizeof(UNISTR4_ARRAY
), (PRS_POINTER_CAST
)prs_unistr4_array
) )
508 /*******************************************************************
509 ********************************************************************/
511 BOOL
svcctl_io_r_start_service(const char *desc
, SVCCTL_R_START_SERVICE
*r_u
, prs_struct
*ps
, int depth
)
516 prs_debug(ps
, depth
, desc
, "svcctl_io_r_start_service");
519 if(!prs_werror("status", ps
, depth
, &r_u
->status
))
526 /*******************************************************************
527 ********************************************************************/
529 BOOL
svcctl_io_q_enum_dependent_services(const char *desc
, SVCCTL_Q_ENUM_DEPENDENT_SERVICES
*q_u
, prs_struct
*ps
, int depth
)
534 prs_debug(ps
, depth
, desc
, "svcctl_io_q_enum_dependent_services");
540 if(!smb_io_pol_hnd("service_pol", &q_u
->handle
, ps
, depth
))
543 if(!prs_uint32("state", ps
, depth
, &q_u
->state
))
545 if(!prs_uint32("buffer_size", ps
, depth
, &q_u
->buffer_size
))
551 /*******************************************************************
552 ********************************************************************/
554 BOOL
svcctl_io_r_enum_dependent_services(const char *desc
, SVCCTL_R_ENUM_DEPENDENT_SERVICES
*r_u
, prs_struct
*ps
, int depth
)
559 prs_debug(ps
, depth
, desc
, "svcctl_io_r_enum_dependent_services");
565 if (!prs_rpcbuffer("", ps
, depth
, &r_u
->buffer
))
571 if(!prs_uint32("needed", ps
, depth
, &r_u
->needed
))
573 if(!prs_uint32("returned", ps
, depth
, &r_u
->returned
))
576 if(!prs_werror("status", ps
, depth
, &r_u
->status
))
582 /*******************************************************************
583 ********************************************************************/
585 BOOL
svcctl_io_q_control_service(const char *desc
, SVCCTL_Q_CONTROL_SERVICE
*q_u
, prs_struct
*ps
, int depth
)
590 prs_debug(ps
, depth
, desc
, "svcctl_io_q_control_service");
596 if(!smb_io_pol_hnd("service_pol", &q_u
->handle
, ps
, depth
))
599 if(!prs_uint32("control", ps
, depth
, &q_u
->control
))
605 /*******************************************************************
606 ********************************************************************/
608 BOOL
svcctl_io_r_control_service(const char *desc
, SVCCTL_R_CONTROL_SERVICE
*r_u
, prs_struct
*ps
, int depth
)
613 prs_debug(ps
, depth
, desc
, "svcctl_io_r_control_service");
619 if(!svcctl_io_service_status("service_status", &r_u
->svc_status
, ps
, depth
))
622 if(!prs_werror("status", ps
, depth
, &r_u
->status
))
629 /*******************************************************************
630 ********************************************************************/
632 BOOL
svcctl_io_q_query_service_config(const char *desc
, SVCCTL_Q_QUERY_SERVICE_CONFIG
*q_u
, prs_struct
*ps
, int depth
)
637 prs_debug(ps
, depth
, desc
, "svcctl_io_q_query_service_config");
643 if(!smb_io_pol_hnd("service_pol", &q_u
->handle
, ps
, depth
))
646 if(!prs_uint32("buffer_size", ps
, depth
, &q_u
->buffer_size
))
652 /*******************************************************************
653 ********************************************************************/
655 BOOL
svcctl_io_r_query_service_config(const char *desc
, SVCCTL_R_QUERY_SERVICE_CONFIG
*r_u
, prs_struct
*ps
, int depth
)
660 prs_debug(ps
, depth
, desc
, "svcctl_io_r_query_service_config");
667 if(!svcctl_io_service_config("config", &r_u
->config
, ps
, depth
))
670 if(!prs_uint32("needed", ps
, depth
, &r_u
->needed
))
673 if(!prs_werror("status", ps
, depth
, &r_u
->status
))
680 /*******************************************************************
681 ********************************************************************/
683 BOOL
svcctl_io_q_query_service_config2(const char *desc
, SVCCTL_Q_QUERY_SERVICE_CONFIG2
*q_u
, prs_struct
*ps
, int depth
)
688 prs_debug(ps
, depth
, desc
, "svcctl_io_q_query_service_config2");
694 if(!smb_io_pol_hnd("service_pol", &q_u
->handle
, ps
, depth
))
697 if(!prs_uint32("info_level", ps
, depth
, &q_u
->info_level
))
700 if(!prs_uint32("buffer_size", ps
, depth
, &q_u
->buffer_size
))
707 /*******************************************************************
708 Creates a service description response buffer.
709 The format seems to be DWORD:length of buffer
710 DWORD:offset (fixed as four)
711 UNISTR: unicode description in the rest of the buffer
712 ********************************************************************/
714 void init_service_description_buffer(RPC_DATA_BLOB
*str
, const char *service_desc
, int blob_length
)
723 /* set up string lengths. */
725 str
->buf_len
= create_rpc_blob(str
, blob_length
);
726 DEBUG(10, ("init_service_description buffer: Allocated a blob of [%d] \n",str
->buf_len
));
728 if ( str
&& str
->buffer
&& str
->buf_len
) {
729 memset(str
->buffer
,0,str
->buf_len
);
730 memcpy(str
->buffer
, &offset
, sizeof(uint32
));
731 bp
= &str
->buffer
[4];
733 rpcstr_push(bp
, service_desc
,str
->buf_len
-4,0);
738 /*******************************************************************
739 ********************************************************************/
741 BOOL
svcctl_io_q_query_service_status_ex(const char *desc
, SVCCTL_Q_QUERY_SERVICE_STATUSEX
*q_u
, prs_struct
*ps
, int depth
)
746 prs_debug(ps
, depth
, desc
, "svcctl_io_q_query_service_status_ex");
752 if(!smb_io_pol_hnd("service_pol", &q_u
->handle
, ps
, depth
))
755 if(!prs_uint32("info_level", ps
, depth
, &q_u
->info_level
))
758 if(!prs_uint32("buffer_size", ps
, depth
, &q_u
->buffer_size
))
765 /*******************************************************************
766 ********************************************************************/
768 BOOL
svcctl_io_r_query_service_status_ex(const char *desc
, SVCCTL_R_QUERY_SERVICE_STATUSEX
*r_u
, prs_struct
*ps
, int depth
)
773 prs_debug(ps
, depth
, desc
, "svcctl_io_r_query_service_status_ex");
776 if (!prs_rpcbuffer("", ps
, depth
, &r_u
->buffer
))
782 if(!prs_uint32("needed", ps
, depth
, &r_u
->needed
))
785 if(!prs_werror("status", ps
, depth
, &r_u
->status
))
791 /*******************************************************************
792 ********************************************************************/
794 BOOL
svcctl_io_r_query_service_config2(const char *desc
, SVCCTL_R_QUERY_SERVICE_CONFIG2
*r_u
, prs_struct
*ps
, int depth
)
799 prs_debug(ps
, depth
, desc
, "svcctl_io_r_query_service_config2");
805 if(!prs_uint32("returned", ps
, depth
, &r_u
->returned
))
808 if (r_u
->returned
> 4) {
809 if (!prs_uint32("offset", ps
, depth
, &r_u
->offset
))
812 if ( !prs_pointer( desc
, ps
, depth
, (void**)&r_u
->description
, sizeof(UNISTR2
), (PRS_POINTER_CAST
)prs_io_unistr2
) )
818 /* offset does double duty here */
820 if (!prs_uint32("offset", ps
, depth
, &r_u
->offset
))
824 if (!prs_uint32("needed", ps
, depth
, &r_u
->needed
))
827 if(!prs_werror("status", ps
, depth
, &r_u
->status
))