r6039: add CLI_DO_RPC macro for cookie cutter code; no new functionality to 'net...
authorGerald Carter <jerry@samba.org>
Thu, 24 Mar 2005 17:11:51 +0000 (17:11 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 15:56:18 +0000 (10:56 -0500)
(This used to be commit 759affb1e1aa59fcb878b4dee781aa362b3e7e1c)

source3/rpc_client/cli_svcctl.c
source3/utils/net_rpc_service.c

index 7bf7392cd6f80e7841d343d7a6e4fc0e2147d1f4..1702112bba3963ce86dc6f05e9d5174b04e11491 100644 (file)
 
 
 #include "includes.h"
+       
+/* macro to expand cookie-cutter code */
+                  
+#define CLI_DO_RPC( cli, mem_ctx, pipe_num, opnum, in, out, qbuf, rbuf, q_io_fn, r_io_fn, default_error) \
+{      out.status = default_error;\
+       prs_init( &qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL ); \
+       prs_init( &rbuf, 0, mem_ctx, UNMARSHALL );\
+       if ( q_io_fn("", &in, &qbuf, 0) ) {\
+               if ( rpc_api_pipe_req(cli, pipe_num, opnum, &qbuf, &rbuf) ) {\
+                       if (!r_io_fn("", &out, &rbuf, 0)) {\
+                               out.status = default_error;\
+                       }\
+               }\
+       }\
+       prs_mem_free( &qbuf );\
+       prs_mem_free( &rbuf );\
+}
 
-/*******************************************************************
-*******************************************************************/
+
+/********************************************************************
+********************************************************************/
 
 WERROR cli_svcctl_open_scm( struct cli_state *cli, TALLOC_CTX *mem_ctx, 
-                            SVCCTL_Q_OPEN_SCMANAGER *in, SVCCTL_R_OPEN_SCMANAGER *out )
+                              POLICY_HND *hSCM, uint32 access_desired )
 {
+       SVCCTL_Q_OPEN_SCMANAGER in;
+       SVCCTL_R_OPEN_SCMANAGER out;
        prs_struct qbuf, rbuf;
-
-       /* Initialise parse structures */
-
-       prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
-       prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
+       fstring server;
+       
+       ZERO_STRUCT(in);
+       ZERO_STRUCT(out);
        
-       out->status = WERR_GENERAL_FAILURE;
+       /* leave the database name NULL to get the default service db */
 
-       /* Marshall data and send request */
+       in.database = NULL;
 
-       if ( svcctl_io_q_open_scmanager("", in, &qbuf, 0) ) {
-               if ( rpc_api_pipe_req(cli, PI_SVCCTL, SVCCTL_OPEN_SCMANAGER_W, &qbuf, &rbuf) ) {
-                       /* Unmarshall response */
-                       if (!svcctl_io_r_open_scmanager("", out, &rbuf, 0)) {
-                               out->status = WERR_GENERAL_FAILURE;
-                       }               
-               }
-       }
+       /* set the server name */
 
-       prs_mem_free(&qbuf);
-       prs_mem_free(&rbuf);
+       if ( !(in.servername = TALLOC_P( mem_ctx, UNISTR2 )) )
+               return WERR_NOMEM;
+       fstr_sprintf( server, "\\\\%s", cli->desthost );
+       init_unistr2( in.servername, server, UNI_STR_TERMINATE );
 
-       return out->status;
+       in.access = access_desired;
+       
+       CLI_DO_RPC( 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;
 }
 
-/*******************************************************************
-*******************************************************************/
+/********************************************************************
+********************************************************************/
 
-WERROR cli_svcctl_close_service( struct cli_state *cli, TALLOC_CTX *mem_ctx, 
-                            SVCCTL_Q_CLOSE_SERVICE *in, SVCCTL_R_CLOSE_SERVICE *out )
+WERROR close_service_handle( struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *hService )
 {
+       SVCCTL_Q_CLOSE_SERVICE in;
+       SVCCTL_R_CLOSE_SERVICE out;
        prs_struct qbuf, rbuf;
-
-       /* Initialise parse structures */
-
-       prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
-       prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
        
-       out->status = WERR_GENERAL_FAILURE;
-
-       /* Marshall data and send request */
-
-       if ( svcctl_io_q_close_service("", in, &qbuf, 0) ) {
-               if ( rpc_api_pipe_req(cli, PI_SVCCTL, SVCCTL_CLOSE_SERVICE, &qbuf, &rbuf) ) {
-                       /* Unmarshall response */
-                       if (!svcctl_io_r_close_service("", out, &rbuf, 0)) {
-                               out->status = WERR_GENERAL_FAILURE;
-                       }               
-               }
-       }
-
-       prs_mem_free(&qbuf);
-       prs_mem_free(&rbuf);
-
-       return out->status;
+       ZERO_STRUCT(in);
+       ZERO_STRUCT(out);
+       
+       memcpy( &in.handle, hService, sizeof(POLICY_HND) );
+       
+       CLI_DO_RPC( 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;
 }
 
 /*******************************************************************
@@ -90,93 +110,70 @@ WERROR cli_svcctl_close_service( struct cli_state *cli, TALLOC_CTX *mem_ctx,
 
 WERROR cli_svcctl_enumerate_services( struct cli_state *cli, TALLOC_CTX *mem_ctx,
                                       POLICY_HND *hSCM, uint32 type, uint32 state, 
-                                     uint32 *resume, uint32 buffer_size, RPC_BUFFER *buffer,
-                                     uint32 returned )
+                                     uint32 *resume, uint32 returned  )
 {
+       SVCCTL_Q_ENUM_SERVICES_STATUS in;
+       SVCCTL_R_ENUM_SERVICES_STATUS out;
        prs_struct qbuf, rbuf;
-       SVCCTL_Q_ENUM_SERVICES_STATUS q;
-       SVCCTL_R_ENUM_SERVICES_STATUS r;
-       WERROR result = WERR_GENERAL_FAILURE;
-
-       ZERO_STRUCT(q);
-       ZERO_STRUCT(r);
-
-       /* Initialise parse structures */
-
-       prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
-       prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
-
-       /* Initialise input parameters */
-
-
-       /* Marshall data and send request */
-       
-       if (!svcctl_io_q_enum_services_status("", &q, &qbuf, 0) ||
-           !rpc_api_pipe_req(cli, PI_SVCCTL, SVCCTL_ENUM_SERVICES_STATUS_W, &qbuf, &rbuf)) {
-               goto done;
-       }
-
-       /* Unmarshall response */
-
-       if (!svcctl_io_r_enum_services_status("", &r, &rbuf, 0)) {
-               goto done;
-       }
 
-       /* Return output parameters */
+       ZERO_STRUCT(in);
+       ZERO_STRUCT(out);
 
-       if (W_ERROR_IS_OK(result = r.status)) {
-               *buffer = r.buffer;
-       }
+       CLI_DO_RPC( 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 );
 
-done:
-       prs_mem_free(&qbuf);
-       prs_mem_free(&rbuf);
+       if ( !W_ERROR_IS_OK(out.status) ) 
+               return out.status;
 
-       return result;
+       return out.status;
 }
 
 /*******************************************************************
 *******************************************************************/
 
-NTSTATUS cli_svcctl_start_service(struct cli_state *cli, TALLOC_CTX *mem_ctx )
+WERROR cli_svcctl_start_service(struct cli_state *cli, TALLOC_CTX *mem_ctx )
 {
 
-       return NT_STATUS_OK;
+       return WERR_OK;
 }
 
 /*******************************************************************
 *******************************************************************/
 
-NTSTATUS cli_svcctl_control_service(struct cli_state *cli, TALLOC_CTX *mem_ctx )
+WERROR cli_svcctl_control_service(struct cli_state *cli, TALLOC_CTX *mem_ctx )
 {
 
-       return NT_STATUS_OK;
+       return WERR_OK;
 }
 
 /*******************************************************************
 *******************************************************************/
 
-NTSTATUS cli_svcctl_query_status(struct cli_state *cli, TALLOC_CTX *mem_ctx )
+WERROR cli_svcctl_query_status(struct cli_state *cli, TALLOC_CTX *mem_ctx )
 {
 
-       return NT_STATUS_OK;
+       return WERR_OK;
 }
 
 /*******************************************************************
 *******************************************************************/
 
-NTSTATUS cli_svcctl_query_config(struct cli_state *cli, TALLOC_CTX *mem_ctx )
+WERROR cli_svcctl_query_config(struct cli_state *cli, TALLOC_CTX *mem_ctx )
 {
 
-       return NT_STATUS_OK;
+       return WERR_OK;
 }
 
 /*******************************************************************
 *******************************************************************/
 
-NTSTATUS cli_svcctl_get_dispname(struct cli_state *cli, TALLOC_CTX *mem_ctx )
+WERROR cli_svcctl_get_dispname(struct cli_state *cli, TALLOC_CTX *mem_ctx )
 {
 
-       return NT_STATUS_OK;
+       return WERR_OK;
 }
 
index 79e7eaa900a50f01f4f5a49a9ce34e2e23372b03..98711c95b6ba7300785ede13fc2534dac501e376 100644 (file)
 #include "includes.h"
 #include "utils/net.h"
 
-
-/********************************************************************
-********************************************************************/
-
-static WERROR open_scmanager( struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *hSCM )
-{
-       SVCCTL_Q_OPEN_SCMANAGER in;
-       SVCCTL_R_OPEN_SCMANAGER out;
-       WERROR result;
-       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->desthost );
-       init_unistr2( in.servername, server, UNI_STR_TERMINATE );
-
-       in.access = SC_MANAGER_ALL_ACCESS;
-       
-       result = cli_svcctl_open_scm( cli, mem_ctx, &in, &out );
-       
-       if ( !W_ERROR_IS_OK( result ) )
-               return result;
-
-       memcpy( hSCM, &out.handle, sizeof(POLICY_HND) );
-       
-       return WERR_OK;
-}
-
-
-/********************************************************************
-********************************************************************/
-
-static WERROR close_service_handle( struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *hService )
-{
-       SVCCTL_Q_CLOSE_SERVICE in;
-       SVCCTL_R_CLOSE_SERVICE out;
-       WERROR result;
-       
-       ZERO_STRUCT(in);
-       ZERO_STRUCT(out);
-       
-       memcpy( &in.handle, hService, sizeof(POLICY_HND) );
-       
-       result = cli_svcctl_close_service( cli, mem_ctx, &in, &out );
-       
-       if ( !W_ERROR_IS_OK( result ) )
-               return result;
-       
-       return WERR_OK;
-}
-
-
-
 /********************************************************************
 ********************************************************************/
 
@@ -97,13 +35,15 @@ static NTSTATUS rpc_service_list_internal( const DOM_SID *domain_sid, const char
                return NT_STATUS_OK;
        }
 
-       if ( !W_ERROR_IS_OK(result = open_scmanager( cli, mem_ctx, &hSCM )) ) {
+       if ( !W_ERROR_IS_OK(result = cli_svcctl_open_scm( cli, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE  )) ) {
                d_printf("Failed to open Service Control Manager.  [%s]\n", dos_errstr(result));
                return werror_to_ntstatus(result);
        }
        
        d_printf("Successfully opened Service Control Manager.\n");
        
+       
+       
        close_service_handle( cli, mem_ctx, &hSCM  );
                
        return NT_STATUS_OK;