r10656: BIG merge from trunk. Features not copied over
[vlendec/samba-autobuild/.git] / source3 / rpc_client / cli_svcctl.c
index f85e37dcb5c5d3a89a1df0bb3320f48a686200b7..2df27c2da5b51d2e822ea8739b8fd5e91c2b96e6 100644 (file)
-
-/* 
- *  Unix SMB/Netbios implementation.
- *  Version 1.9.
+/*
+ *  Unix SMB/CIFS implementation.
  *  RPC Pipe client / server routines
- *  Copyright (C) Andrew Tridgell              1992-1998,
- *  Copyright (C) Luke Kenneth Casson Leighton 1996-1998,
- *  Copyright (C) Paul Ashton                  1997-1998.
- *  
+ *  Copyright (C) Gerald Carter                   2005.
+ *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2 of the License, or
  *  (at your option) any later version.
- *  
+ *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
- *  
+ *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 
-#ifdef SYSLOG
-#undef SYSLOG
-#endif
-
 #include "includes.h"
-
-extern int DEBUGLEVEL;
-
-/****************************************************************************
-do a SVC Open Policy
-****************************************************************************/
-BOOL svc_open_sc_man(struct cli_state *cli, uint16 fnum, 
-                               char *srv_name, char *db_name,
-                               uint32 des_access,
-                               POLICY_HND *hnd)
+#include "rpc_client.h"
+
+struct svc_state_msg {
+       uint32 flag;
+       const char *message;
+};
+
+static struct svc_state_msg state_msg_table[] = {
+       { SVCCTL_STOPPED,            "stopped" },
+       { SVCCTL_START_PENDING,      "start pending" },
+       { SVCCTL_STOP_PENDING,       "stop pending" },
+       { SVCCTL_RUNNING,            "running" },
+       { SVCCTL_CONTINUE_PENDING,   "resume pending" },
+       { SVCCTL_PAUSE_PENDING,      "pause pending" },
+       { SVCCTL_PAUSED,             "paused" },
+       { 0,                          NULL }
+};
+       
+
+/********************************************************************
+********************************************************************/
+const char* svc_status_string( uint32 state )
 {
-       prs_struct rbuf;
-       prs_struct buf; 
-       SVC_Q_OPEN_SC_MAN q_o;
-       BOOL valid_pol = False;
-
-       if (hnd == NULL) return False;
-
-       prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
-       prs_init(&rbuf, 0   , 4, SAFETY_MARGIN, True );
-
-       /* create and send a MSRPC command with api SVC_OPEN_SC_MAN */
-
-       DEBUG(4,("SVC Open SC_MAN\n"));
-
-       make_svc_q_open_sc_man(&q_o, srv_name, db_name, des_access);
-
-       /* turn parameters into data stream */
-       svc_io_q_open_sc_man("", &q_o, &buf, 0);
-
-       /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SVC_OPEN_SC_MAN, &buf, &rbuf))
-       {
-               SVC_R_OPEN_SC_MAN r_o;
-               BOOL p;
-
-               ZERO_STRUCT(r_o);
-
-               svc_io_r_open_sc_man("", &r_o, &rbuf, 0);
-               p = rbuf.offset != 0;
-
-               if (p && r_o.status != 0)
-               {
-                       /* report error code */
-                       DEBUG(1,("SVC_OPEN_SC_MAN: %s\n", get_nt_error_msg(r_o.status)));
-                       p = False;
-               }
-
-               if (p)
-               {
-                       /* ok, at last: we're happy. return the policy handle */
-                       memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
-                       valid_pol = True;
+       static fstring msg;
+       int i;
+       
+       fstr_sprintf( msg, "Unknown State [%d]", state );
+       
+       for ( i=0; state_msg_table[i].message; i++ ) {
+               if ( state_msg_table[i].flag == state ) {
+                       fstrcpy( msg, state_msg_table[i].message );
+                       break;  
                }
        }
-
-       prs_mem_free(&rbuf);
-       prs_mem_free(&buf );
-
-       return valid_pol;
+       
+       return msg;
 }
 
+/********************************************************************
+********************************************************************/
 
-/****************************************************************************
-do a SVC Open Service
-****************************************************************************/
-BOOL svc_open_service(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *scm_hnd,
-                               const char *srv_name,
-                               uint32 des_access,
-                               POLICY_HND *hnd)
+WERROR rpccli_svcctl_open_scm(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, 
+                              POLICY_HND *hSCM, uint32 access_desired )
 {
-       prs_struct rbuf;
-       prs_struct buf; 
-       SVC_Q_OPEN_SERVICE q_o;
-       BOOL valid_pol = False;
-
-       if (hnd == NULL || scm_hnd == NULL) return False;
-
-       prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
-       prs_init(&rbuf, 0   , 4, SAFETY_MARGIN, True );
-
-       /* create and send a MSRPC command with api SVC_OPEN_SERVICE */
-
-       DEBUG(4,("SVC Open Service\n"));
-
-       make_svc_q_open_service(&q_o, scm_hnd, srv_name, des_access);
-
-       /* turn parameters into data stream */
-       svc_io_q_open_service("", &q_o, &buf, 0);
-
-       /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SVC_OPEN_SERVICE, &buf, &rbuf))
-       {
-               SVC_R_OPEN_SERVICE r_o;
-               BOOL p;
-
-               ZERO_STRUCT(r_o);
-
-               svc_io_r_open_service("", &r_o, &rbuf, 0);
-               p = rbuf.offset != 0;
+       SVCCTL_Q_OPEN_SCMANAGER in;
+       SVCCTL_R_OPEN_SCMANAGER out;
+       prs_struct qbuf, rbuf;
+       fstring server;
+       
+       ZERO_STRUCT(in);
+       ZERO_STRUCT(out);
+       
+       /* leave the database name NULL to get the default service db */
+
+       in.database = NULL;
+
+       /* set the server name */
+
+       if ( !(in.servername = TALLOC_P( mem_ctx, UNISTR2 )) )
+               return WERR_NOMEM;
+       fstr_sprintf( server, "\\\\%s", cli->cli->desthost );
+       init_unistr2( in.servername, server, UNI_STR_TERMINATE );
+
+       in.access = access_desired;
+       
+       CLI_DO_RPC_WERR( cli, mem_ctx, PI_SVCCTL, SVCCTL_OPEN_SCMANAGER_W, 
+                   in, out, 
+                   qbuf, rbuf,
+                   svcctl_io_q_open_scmanager,
+                   svcctl_io_r_open_scmanager, 
+                   WERR_GENERAL_FAILURE );
+       
+       if ( !W_ERROR_IS_OK( out.status ) )
+               return out.status;
+
+       memcpy( hSCM, &out.handle, sizeof(POLICY_HND) );
+       
+       return out.status;
+}
 
-               if (p && r_o.status != 0)
-               {
-                       /* report error code */
-                       DEBUG(1,("SVC_OPEN_SC_MAN: %s\n", get_nt_error_msg(r_o.status)));
-                       p = False;
-               }
+/********************************************************************
+********************************************************************/
 
-               if (p)
-               {
-                       /* ok, at last: we're happy. return the policy handle */
-                       memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
-                       valid_pol = True;
-               }
-       }
+WERROR rpccli_svcctl_open_service( struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, 
+                                POLICY_HND *hSCM, POLICY_HND *hService, 
+                               const char *servicename, uint32 access_desired )
+{
+       SVCCTL_Q_OPEN_SERVICE in;
+       SVCCTL_R_OPEN_SERVICE out;
+       prs_struct qbuf, rbuf;
+       
+       ZERO_STRUCT(in);
+       ZERO_STRUCT(out);
+       
+       memcpy( &in.handle, hSCM, sizeof(POLICY_HND) );
+       init_unistr2( &in.servicename, servicename, UNI_STR_TERMINATE );
+       in.access = access_desired;
+       
+       CLI_DO_RPC_WERR( cli, mem_ctx, PI_SVCCTL, SVCCTL_OPEN_SERVICE_W, 
+                   in, out, 
+                   qbuf, rbuf,
+                   svcctl_io_q_open_service,
+                   svcctl_io_r_open_service, 
+                   WERR_GENERAL_FAILURE );
+       
+       if ( !W_ERROR_IS_OK( out.status ) )
+               return out.status;
+
+       memcpy( hService, &out.handle, sizeof(POLICY_HND) );
+       
+       return out.status;
+}
 
-       prs_mem_free(&rbuf);
-       prs_mem_free(&buf );
+/********************************************************************
+********************************************************************/
 
-       return valid_pol;
+WERROR rpccli_svcctl_close_service(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *hService )
+{
+       SVCCTL_Q_CLOSE_SERVICE in;
+       SVCCTL_R_CLOSE_SERVICE out;
+       prs_struct qbuf, rbuf;
+       
+       ZERO_STRUCT(in);
+       ZERO_STRUCT(out);
+       
+       memcpy( &in.handle, hService, sizeof(POLICY_HND) );
+       
+       CLI_DO_RPC_WERR( cli, mem_ctx, PI_SVCCTL, SVCCTL_CLOSE_SERVICE, 
+                   in, out, 
+                   qbuf, rbuf,
+                   svcctl_io_q_close_service,
+                   svcctl_io_r_close_service, 
+                   WERR_GENERAL_FAILURE );
+
+       return out.status;
 }
 
+/*******************************************************************
+*******************************************************************/
 
-/****************************************************************************
-do a SVC Enumerate Services
-****************************************************************************/
-BOOL svc_enum_svcs(struct cli_state *cli, uint16 fnum, 
-                               POLICY_HND *hnd,
-                               uint32 services_type, uint32 services_state,
-                               uint32 *buf_size, uint32 *resume_hnd,
-                               uint32 *dos_error,
-                               ENUM_SRVC_STATUS **svcs, uint32 *num_svcs)
+WERROR rpccli_svcctl_enumerate_services( struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
+                                      POLICY_HND *hSCM, uint32 type, uint32 state, 
+                                     uint32 *returned, ENUM_SERVICES_STATUS **service_array  )
 {
-       prs_struct rbuf;
-       prs_struct buf; 
-       SVC_Q_ENUM_SVCS_STATUS q_o;
-       BOOL valid_pol = False;
-
-       if (hnd == NULL || buf_size == NULL || dos_error == NULL || num_svcs == NULL)
-       {
-               return False;
+       SVCCTL_Q_ENUM_SERVICES_STATUS in;
+       SVCCTL_R_ENUM_SERVICES_STATUS out;
+       prs_struct qbuf, rbuf;
+       uint32 resume = 0;
+       ENUM_SERVICES_STATUS *services;
+       int i;
+
+       ZERO_STRUCT(in);
+       ZERO_STRUCT(out);
+       
+       /* setup the request */
+       
+       memcpy( &in.handle, hSCM, sizeof(POLICY_HND) );
+       
+       in.type        = type;
+       in.state       = state;
+       in.resume      = &resume;
+       
+       /* first time is to get the buffer size */
+       in.buffer_size = 0;
+
+       CLI_DO_RPC_WERR( cli, mem_ctx, PI_SVCCTL, SVCCTL_ENUM_SERVICES_STATUS_W, 
+                   in, out, 
+                   qbuf, rbuf,
+                   svcctl_io_q_enum_services_status,
+                   svcctl_io_r_enum_services_status, 
+                   WERR_GENERAL_FAILURE );
+
+       /* second time with correct buffer size...should be ok */
+       
+       if ( W_ERROR_EQUAL( out.status, WERR_MORE_DATA ) ) {
+               in.buffer_size = out.needed;
+
+               CLI_DO_RPC_WERR( cli, mem_ctx, PI_SVCCTL, SVCCTL_ENUM_SERVICES_STATUS_W, 
+                           in, out, 
+                           qbuf, rbuf,
+                           svcctl_io_q_enum_services_status,
+                           svcctl_io_r_enum_services_status, 
+                           WERR_GENERAL_FAILURE );
        }
-
-       prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
-       prs_init(&rbuf, 0   , 4, SAFETY_MARGIN, True );
-
-       /* create and send a MSRPC command with api SVC_ENUM_SVCS_STATUS */
-
-       DEBUG(4,("SVC Enum Services Status\n"));
-
-       make_svc_q_enum_svcs_status(&q_o, hnd,
-                                   services_type, services_state,
-                                   *buf_size, *resume_hnd);
-
-       /* turn parameters into data stream */
-       svc_io_q_enum_svcs_status("", &q_o, &buf, 0);
-
-       /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SVC_ENUM_SVCS_STATUS, &buf, &rbuf))
-       {
-               SVC_R_ENUM_SVCS_STATUS r_o;
-               BOOL p;
-
-               ZERO_STRUCT(r_o);
-
-               svc_io_r_enum_svcs_status("", &r_o, &rbuf, 0);
-               p = rbuf.offset != 0;
-
-               if (p && r_o.dos_status != 0)
-               {
-                       fstring errmsg;
-
-                       if (r_o.dos_status != ERRmoredata)
-                       {
-                               smb_safe_err_msg(ERRDOS, r_o.dos_status,
-                                                errmsg, sizeof(errmsg));
-                               /* report error code */
-                               DEBUG(1,("SVC_ENUM_SVCS_STATUS: %s\n", errmsg));
-                       }
-                       p = r_o.dos_status == ERRmoredata;
-               }
-
-               if (p)
-               {
-                       (*svcs) = r_o.svcs;
-                       (*num_svcs) = r_o.num_svcs;
-                       (*resume_hnd) = get_enum_hnd(&r_o.resume_hnd);
-                       (*buf_size) = r_o.more_buf_size;
-                       (*dos_error) = r_o.dos_status;
-                       valid_pol = True;
-               }
+       
+       if ( !W_ERROR_IS_OK(out.status) ) 
+               return out.status;
+               
+       /* pull out the data */
+       if ( !(services = TALLOC_ARRAY( mem_ctx, ENUM_SERVICES_STATUS, out.returned )) ) 
+               return WERR_NOMEM;
+               
+       for ( i=0; i<out.returned; i++ ) {
+               svcctl_io_enum_services_status( "", &services[i], &out.buffer, 0 );
        }
-
-       prs_mem_free(&rbuf);
-       prs_mem_free(&buf );
-
-       return valid_pol;
+       
+       *service_array = services;
+       *returned      = out.returned;
+       
+       return out.status;
 }
 
+/*******************************************************************
+*******************************************************************/
 
-/****************************************************************************
-do a SVC Stop Service 
-****************************************************************************/
-BOOL svc_stop_service(struct cli_state *cli, uint16 fnum,
-                               POLICY_HND *hnd,
-                               uint32 unknown)
+WERROR rpccli_svcctl_query_status( struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
+                                POLICY_HND *hService, SERVICE_STATUS *status )
 {
-       prs_struct rbuf;
-       prs_struct buf; 
-       SVC_Q_STOP_SERVICE q_c;
-       BOOL valid_cfg = False;
-
-       if (hnd == NULL) return False;
-
-       /* create and send a MSRPC command with api SVC_STOP_SERVICE */
-
-       prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
-       prs_init(&rbuf, 0   , 4, SAFETY_MARGIN, True );
-
-       DEBUG(4,("SVC Stop Service\n"));
-
-       /* store the parameters */
-       make_svc_q_stop_service(&q_c, hnd, unknown);
-
-       /* turn parameters into data stream */
-       svc_io_q_stop_service("", &q_c, &buf, 0);
-
-       /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SVC_STOP_SERVICE, &buf, &rbuf))
-       {
-               SVC_R_STOP_SERVICE r_c;
-               BOOL p;
-
-               ZERO_STRUCT (r_c);
-
-               svc_io_r_stop_service("", &r_c, &rbuf, 0);
-               p = rbuf.offset != 0;
-
-               if (p && r_c.status != 0)
-               {
-                       /* report error code */
-                       DEBUG(1,("SVC_START_SERVICE: %s\n", get_nt_error_msg(r_c.status)));
-                       p = False;
-               }
-
-               if (p)
-               {
-                       valid_cfg = True;
-               }
-       }
-
-       prs_mem_free(&rbuf);
-       prs_mem_free(&buf );
-
-       return valid_cfg;
+       SVCCTL_Q_QUERY_STATUS in;
+       SVCCTL_R_QUERY_STATUS out;
+       prs_struct qbuf, rbuf;
+       
+       ZERO_STRUCT(in);
+       ZERO_STRUCT(out);
+       
+       memcpy( &in.handle, hService, sizeof(POLICY_HND) );
+       
+       CLI_DO_RPC_WERR( cli, mem_ctx, PI_SVCCTL, SVCCTL_QUERY_STATUS, 
+                   in, out, 
+                   qbuf, rbuf,
+                   svcctl_io_q_query_status,
+                   svcctl_io_r_query_status, 
+                   WERR_GENERAL_FAILURE );
+       
+       if ( !W_ERROR_IS_OK( out.status ) )
+               return out.status;
+
+       memcpy( status, &out.svc_status, sizeof(SERVICE_STATUS) );
+       
+       return out.status;
 }
 
+/*******************************************************************
+*******************************************************************/
 
-/****************************************************************************
-do a SVC Start Service 
-****************************************************************************/
-BOOL svc_start_service(struct cli_state *cli, uint16 fnum,
-                               POLICY_HND *hnd,
-                               uint32 argc,
-                               char **argv)
+WERROR rpccli_svcctl_query_config(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
+                                POLICY_HND *hService, SERVICE_CONFIG *config )
 {
-       prs_struct rbuf;
-       prs_struct buf; 
-       SVC_Q_START_SERVICE q_c;
-       BOOL valid_cfg = False;
-
-       if (hnd == NULL) return False;
-
-       /* create and send a MSRPC command with api SVC_START_SERVICE */
-
-       prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
-       prs_init(&rbuf, 0   , 4, SAFETY_MARGIN, True );
-
-       DEBUG(4,("SVC Start Service\n"));
-
-       /* store the parameters */
-       make_svc_q_start_service(&q_c, hnd, argc, argv);
-
-       /* turn parameters into data stream */
-       svc_io_q_start_service("", &q_c, &buf, 0);
-
-       /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SVC_START_SERVICE, &buf, &rbuf))
-       {
-               SVC_R_START_SERVICE r_c;
-               BOOL p;
-
-               ZERO_STRUCT (r_c);
-
-               svc_io_r_start_service("", &r_c, &rbuf, 0);
-               p = rbuf.offset != 0;
+       SVCCTL_Q_QUERY_SERVICE_CONFIG in;
+       SVCCTL_R_QUERY_SERVICE_CONFIG out;
+       prs_struct qbuf, rbuf;
+       
+       ZERO_STRUCT(in);
+       ZERO_STRUCT(out);
+       
+       memcpy( &in.handle, hService, sizeof(POLICY_HND) );
+       in.buffer_size = 0;
+       
+       
+       CLI_DO_RPC_WERR( cli, mem_ctx, PI_SVCCTL, SVCCTL_QUERY_SERVICE_CONFIG_W, 
+                   in, out, 
+                   qbuf, rbuf,
+                   svcctl_io_q_query_service_config,
+                   svcctl_io_r_query_service_config, 
+                   WERR_GENERAL_FAILURE );
+       
+       if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
+               in.buffer_size = out.needed;
+
+               CLI_DO_RPC_WERR( cli, mem_ctx, PI_SVCCTL, SVCCTL_QUERY_SERVICE_CONFIG_W,
+                           in, out, 
+                           qbuf, rbuf,
+                           svcctl_io_q_query_service_config,
+                           svcctl_io_r_query_service_config, 
+                           WERR_GENERAL_FAILURE );
+       }
+       
+       if ( !W_ERROR_IS_OK( out.status ) )
+               return out.status;
+
+       memcpy( config, &out.config, sizeof(SERVICE_CONFIG) );
+       
+       config->executablepath = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
+       config->loadordergroup = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
+       config->dependencies   = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
+       config->startname      = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
+       config->displayname    = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
+       
+       if ( out.config.executablepath ) {
+               config->executablepath = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
+               copy_unistr2( config->executablepath, out.config.executablepath );
+       }
 
-               if (p && r_c.status != 0)
-               {
-                       /* report error code */
-                       DEBUG(1,("SVC_START_SERVICE: %s\n", get_nt_error_msg(r_c.status)));
-                       p = False;
-               }
+       if ( out.config.loadordergroup ) {
+               config->loadordergroup = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
+               copy_unistr2( config->loadordergroup, out.config.loadordergroup );
+       }
 
-               if (p)
-               {
-                       valid_cfg = True;
-               }
+       if ( out.config.dependencies ) {
+               config->dependencies = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
+               copy_unistr2( config->dependencies, out.config.dependencies );
        }
 
-       prs_mem_free(&rbuf);
-       prs_mem_free(&buf );
+       if ( out.config.startname ) {
+               config->startname = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
+               copy_unistr2( config->startname, out.config.startname );
+       }
 
-       return valid_cfg;
+       if ( out.config.displayname ) {
+               config->displayname = TALLOC_ZERO_P( mem_ctx, UNISTR2 );
+               copy_unistr2( config->displayname, out.config.displayname );
+       }
+       
+       return out.status;
 }
 
+/*******************************************************************
+*******************************************************************/
 
-/****************************************************************************
-do a SVC Query Service Config
-****************************************************************************/
-BOOL svc_query_svc_cfg(struct cli_state *cli, uint16 fnum,
-                               POLICY_HND *hnd,
-                               QUERY_SERVICE_CONFIG *cfg,
-                               uint32 *buf_size)
+WERROR rpccli_svcctl_start_service( struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
+                                 POLICY_HND *hService,
+                                 const char **parm_array, uint32 parmcount )
 {
-       prs_struct rbuf;
-       prs_struct buf; 
-       SVC_Q_QUERY_SVC_CONFIG q_c;
-       BOOL valid_cfg = False;
-
-       if (hnd == NULL || buf_size == NULL) return False;
-
-       /* create and send a MSRPC command with api SVC_QUERY_SVC_CONFIG */
-
-       prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
-       prs_init(&rbuf, 0   , 4, SAFETY_MARGIN, True );
-
-       DEBUG(4,("SVC Query Service Config\n"));
-
-       /* store the parameters */
-       make_svc_q_query_svc_config(&q_c, hnd, *buf_size);
-
-       /* turn parameters into data stream */
-       svc_io_q_query_svc_config("", &q_c, &buf, 0);
-
-       /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SVC_QUERY_SVC_CONFIG, &buf, &rbuf))
-       {
-               SVC_R_QUERY_SVC_CONFIG r_c;
-               BOOL p;
-
-               ZERO_STRUCT (r_c);
-               ZERO_STRUCTP(cfg);
-
-               r_c.cfg = cfg;
-
-               svc_io_r_query_svc_config("", &r_c, &rbuf, 0);
-               p = rbuf.offset != 0;
-
-               if (p && r_c.status != 0)
-               {
-                       /* report error code */
-                       DEBUG(1,("SVC_QUERY_SVC_CONFIG: %s\n", get_nt_error_msg(r_c.status)));
-                       p = False;
-               }
-
-               if (p)
-               {
-                       valid_cfg = r_c.buf_size != 0;
-               }
-       }
-
-       prs_mem_free(&rbuf);
-       prs_mem_free(&buf );
-
-       return valid_cfg;
+       SVCCTL_Q_START_SERVICE in;
+       SVCCTL_R_START_SERVICE out;
+       prs_struct qbuf, rbuf;
+       
+       ZERO_STRUCT(in);
+       ZERO_STRUCT(out);
+       
+       memcpy( &in.handle, hService, sizeof(POLICY_HND) );
+       
+       in.parmcount  = 0;
+       in.parameters = NULL;
+       
+       CLI_DO_RPC_WERR( cli, mem_ctx, PI_SVCCTL, SVCCTL_START_SERVICE_W,
+                   in, out, 
+                   qbuf, rbuf,
+                   svcctl_io_q_start_service,
+                   svcctl_io_r_start_service,
+                   WERR_GENERAL_FAILURE );
+       
+       return out.status;
 }
 
+/*******************************************************************
+*******************************************************************/
 
-/****************************************************************************
-do a SVC Close
-****************************************************************************/
-BOOL svc_close(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd)
+WERROR rpccli_svcctl_control_service( struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
+                                   POLICY_HND *hService, uint32 control,
+                                  SERVICE_STATUS *status )
 {
-       prs_struct rbuf;
-       prs_struct buf; 
-       SVC_Q_CLOSE q_c;
-       BOOL valid_close = False;
-
-       if (hnd == NULL) return False;
-
-       /* create and send a MSRPC command with api SVC_CLOSE */
-
-       prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
-       prs_init(&rbuf, 0   , 4, SAFETY_MARGIN, True );
-
-       DEBUG(4,("SVC Close\n"));
-
-       /* store the parameters */
-       make_svc_q_close(&q_c, hnd);
-
-       /* turn parameters into data stream */
-       svc_io_q_close("", &q_c, &buf, 0);
-
-       /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SVC_CLOSE, &buf, &rbuf))
-       {
-               SVC_R_CLOSE r_c;
-               BOOL p;
-
-               ZERO_STRUCT(r_c);
-
-               svc_io_r_close("", &r_c, &rbuf, 0);
-               p = rbuf.offset != 0;
-
-               if (p && r_c.status != 0)
-               {
-                       /* report error code */
-                       DEBUG(1,("SVC_CLOSE: %s\n", get_nt_error_msg(r_c.status)));
-                       p = False;
-               }
-
-               if (p)
-               {
-                       /* check that the returned policy handle is all zeros */
-                       uint32 i;
-                       valid_close = True;
-
-                       for (i = 0; i < sizeof(r_c.pol.data); i++)
-                       {
-                               if (r_c.pol.data[i] != 0)
-                               {
-                                       valid_close = False;
-                                       break;
-                               }
-                       }       
-                       if (!valid_close)
-                       {
-                               DEBUG(1,("SVC_CLOSE: non-zero handle returned\n"));
-                       }
-               }
-       }
-
-       prs_mem_free(&rbuf);
-       prs_mem_free(&buf );
-
-       return valid_close;
+       SVCCTL_Q_CONTROL_SERVICE in;
+       SVCCTL_R_CONTROL_SERVICE out;
+       prs_struct qbuf, rbuf;
+       
+       ZERO_STRUCT(in);
+       ZERO_STRUCT(out);
+       
+       memcpy( &in.handle, hService, sizeof(POLICY_HND) );
+       in.control = control;
+       
+       CLI_DO_RPC_WERR( cli, mem_ctx, PI_SVCCTL, SVCCTL_CONTROL_SERVICE, 
+                   in, out, 
+                   qbuf, rbuf,
+                   svcctl_io_q_control_service,
+                   svcctl_io_r_control_service,
+                   WERR_GENERAL_FAILURE );
+       
+       if ( !W_ERROR_IS_OK( out.status ) )
+               return out.status;
+
+       memcpy( status, &out.svc_status, sizeof(SERVICE_STATUS) );
+       
+       return out.status;
 }
 
-/****************************************************************************
-do a SVC Change Service Config
-****************************************************************************/
-BOOL svc_change_svc_cfg(struct cli_state *cli, uint16 fnum,
-                               POLICY_HND *hnd,
-                               uint32 service_type, uint32 start_type,
-                               uint32 unknown_0,
-                               uint32 error_control,
-                               char* bin_path_name, char* load_order_grp, 
-                               uint32 tag_id,
-                               char* dependencies, char* service_start_name,
-                               char* password,
-                               char* disp_name)
-{
-       prs_struct rbuf;
-       prs_struct buf; 
-       SVC_Q_CHANGE_SVC_CONFIG q_c;
-       BOOL valid_cfg = False;
-
-       if (hnd == NULL) return False;
-
-       /* create and send a MSRPC command with api SVC_CHANGE_SVC_CONFIG */
-
-       prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
-       prs_init(&rbuf, 0   , 4, SAFETY_MARGIN, True );
-
-       DEBUG(4,("SVC Change Service Config\n"));
-
-       /* store the parameters */
-       make_svc_q_change_svc_config(&q_c, hnd, 
-                               service_type, start_type,
-                               unknown_0, error_control,
-                               bin_path_name, load_order_grp, 
-                               tag_id,
-                               dependencies, service_start_name,
-                               password, disp_name);
-
-       /* turn parameters into data stream */
-       svc_io_q_change_svc_config("", &q_c, &buf, 0);
 
-       /* send the data on \PIPE\ */
-       if (rpc_api_pipe_req(cli, fnum, SVC_CHANGE_SVC_CONFIG, &buf, &rbuf))
-       {
-               SVC_R_CHANGE_SVC_CONFIG r_c;
-               BOOL p;
+/*******************************************************************
+*******************************************************************/
 
-               ZERO_STRUCT (r_c);
-
-               svc_io_r_change_svc_config("", &r_c, &rbuf, 0);
-               p = rbuf.offset != 0;
-
-               if (p && r_c.status != 0)
-               {
-                       /* report error code */
-                       DEBUG(1,("SVC_CHANGE_SVC_CONFIG: %s\n", get_nt_error_msg(r_c.status)));
-                       p = False;
-               }
-
-               if (p)
-               {
-                       valid_cfg = True;
-               }
+WERROR rpccli_svcctl_get_dispname( struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, 
+                                POLICY_HND *hService, fstring displayname )
+{
+       SVCCTL_Q_GET_DISPLAY_NAME in;
+       SVCCTL_R_GET_DISPLAY_NAME out;
+       prs_struct qbuf, rbuf;
+       
+       ZERO_STRUCT(in);
+       ZERO_STRUCT(out);
+       
+       memcpy( &in.handle, hService, sizeof(POLICY_HND) );
+       in.display_name_len = 0;
+       
+       CLI_DO_RPC_WERR( cli, mem_ctx, PI_SVCCTL, SVCCTL_GET_DISPLAY_NAME, 
+                   in, out, 
+                   qbuf, rbuf,
+                   svcctl_io_q_get_display_name,
+                   svcctl_io_r_get_display_name, 
+                   WERR_GENERAL_FAILURE );
+       
+       /* second time with correct buffer size...should be ok */
+       
+       if ( W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
+               in.display_name_len = out.display_name_len;
+
+               CLI_DO_RPC_WERR( cli, mem_ctx, PI_SVCCTL, SVCCTL_GET_DISPLAY_NAME, 
+                           in, out, 
+                           qbuf, rbuf,
+                           svcctl_io_q_get_display_name,
+                           svcctl_io_r_get_display_name, 
+                           WERR_GENERAL_FAILURE );
        }
 
-       prs_mem_free(&rbuf);
-       prs_mem_free(&buf );
+       if ( !W_ERROR_IS_OK( out.status ) )
+               return out.status;
 
-       return valid_cfg;
+       rpcstr_pull( displayname, out.displayname.buffer, sizeof(displayname), -1, STR_TERMINATE );
+       
+       return out.status;
 }
-
-