From 2e3ce1d534b544b2eedd9183f9f97c17a8e403fc Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 24 Mar 2005 04:25:49 +0000 Subject: r6029: adding files necessary to support 'net rpc service' functions; will fill in tomorrow (This used to be commit 6bbd61cfd1ca2dbe8d96d894f90f263b8f24571f) --- source3/utils/net_rpc_service.c | 154 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 source3/utils/net_rpc_service.c (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c new file mode 100644 index 0000000000..d9791610dd --- /dev/null +++ b/source3/utils/net_rpc_service.c @@ -0,0 +1,154 @@ +/* + Samba Unix/Linux SMB client library + Distributed SMB/CIFS Server Management Utility + Copyright (C) Gerald (Jerry) 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. */ + +#include "includes.h" +#include "utils/net.h" + +/******************************************************************** +********************************************************************/ + +static NTSTATUS rpc_service_list_internal( const DOM_SID *domain_sid, const char *domain_name, + struct cli_state *cli, TALLOC_CTX *mem_ctx, + int argc, const char **argv ) +{ +#if 0 + POLICY_HND dom_pol; + NTSTATUS result = NT_STATUS_UNSUCCESSFUL; + + DOM_SID sid; + + if (argc < 2 ) { + d_printf("Usage: net rpc rights revoke \n"); + return NT_STATUS_OK; + } + + result = name_to_sid(cli, mem_ctx, &sid, argv[0]); + if (!NT_STATUS_IS_OK(result)) + return result; + + result = cli_lsa_open_policy2(cli, mem_ctx, True, + SEC_RIGHTS_MAXIMUM_ALLOWED, + &dom_pol); + + if (!NT_STATUS_IS_OK(result)) + return result; + + result = cli_lsa_remove_account_rights(cli, mem_ctx, &dom_pol, sid, + False, argc-1, argv+1); + + if (!NT_STATUS_IS_OK(result)) + goto done; + + d_printf("Successfully revoked rights.\n"); + +done: + if ( !NT_STATUS_IS_OK(result) ) { + d_printf("Failed to revoke privileges for %s (%s)", + argv[0], nt_errstr(result)); + } + + cli_lsa_close(cli, mem_ctx, &dom_pol); + + return result; +#else + return NT_STATUS_OK; +#endif +} + + +/******************************************************************** +********************************************************************/ + +static int rpc_service_list( int argc, const char **argv ) +{ + return run_rpc_command( NULL, PI_LSARPC, 0, + rpc_service_list_internal, argc, argv ); +} + +/******************************************************************** +********************************************************************/ + +static int rpc_service_start( int argc, const char **argv ) +{ + d_printf("not implemented\n"); + return 0; +} + +/******************************************************************** +********************************************************************/ + +static int rpc_service_stop( int argc, const char **argv ) +{ + d_printf("not implemented\n"); + return 0; +} + +/******************************************************************** +********************************************************************/ + +static int rpc_service_pause( int argc, const char **argv ) +{ + d_printf("not implemented\n"); + return 0; +} + +/******************************************************************** +********************************************************************/ + +static int rpc_service_status( int argc, const char **argv ) +{ + d_printf("not implemented\n"); + return 0; +} + +/******************************************************************** +********************************************************************/ + +static int net_help_service( int argc, const char **argv ) +{ + d_printf("net rpc service list View configured Win32 services\n"); + d_printf("net rpc service start Start a service\n"); + d_printf("net rpc service stop Stop a service\n"); + d_printf("net rpc service pause Pause a service\n"); + d_printf("net rpc service status View the current status of a service\n"); + + return -1; +} + +/******************************************************************** +********************************************************************/ + +int net_rpc_service(int argc, const char **argv) +{ + struct functable func[] = { + {"list", rpc_service_list}, + {"start", rpc_service_start}, + {"stop", rpc_service_stop}, + {"pause", rpc_service_pause}, + {"status", rpc_service_status}, + {NULL, NULL} + }; + + if ( argc ) + return net_run_function( argc, argv, func, net_help_service ); + + return net_help_service( argc, argv ); +} + + -- cgit From 259d44dbb2c2239339f6888fd5da12632abcbb28 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 24 Mar 2005 16:11:23 +0000 Subject: r6038: adding more flesh to 'net rpc service' open and close the service control manager. Also experimenting with ideas for cli_xxx() interface. (This used to be commit 4da89ef17b8c4644b97b923cebfe8e446b508b4d) --- source3/utils/net_rpc_service.c | 106 +++++++++++++++++++++++++++------------- 1 file changed, 72 insertions(+), 34 deletions(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index d9791610dd..79e7eaa900 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -20,55 +20,93 @@ #include "includes.h" #include "utils/net.h" + /******************************************************************** ********************************************************************/ -static NTSTATUS rpc_service_list_internal( const DOM_SID *domain_sid, const char *domain_name, - struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, const char **argv ) +static WERROR open_scmanager( struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *hSCM ) { -#if 0 - POLICY_HND dom_pol; - NTSTATUS result = NT_STATUS_UNSUCCESSFUL; + 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 */ - DOM_SID sid; + in.database = NULL; - if (argc < 2 ) { - d_printf("Usage: net rpc rights revoke \n"); - return NT_STATUS_OK; - } + /* set the server name */ - result = name_to_sid(cli, mem_ctx, &sid, argv[0]); - if (!NT_STATUS_IS_OK(result)) - return result; + 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 ); - result = cli_lsa_open_policy2(cli, mem_ctx, True, - SEC_RIGHTS_MAXIMUM_ALLOWED, - &dom_pol); + in.access = SC_MANAGER_ALL_ACCESS; + + result = cli_svcctl_open_scm( cli, mem_ctx, &in, &out ); + + if ( !W_ERROR_IS_OK( result ) ) + return result; - if (!NT_STATUS_IS_OK(result)) - return result; + memcpy( hSCM, &out.handle, sizeof(POLICY_HND) ); + + return WERR_OK; +} - result = cli_lsa_remove_account_rights(cli, mem_ctx, &dom_pol, sid, - False, argc-1, argv+1); - if (!NT_STATUS_IS_OK(result)) - goto done; +/******************************************************************** +********************************************************************/ - d_printf("Successfully revoked rights.\n"); +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; +} -done: - if ( !NT_STATUS_IS_OK(result) ) { - d_printf("Failed to revoke privileges for %s (%s)", - argv[0], nt_errstr(result)); - } + + +/******************************************************************** +********************************************************************/ + +static NTSTATUS rpc_service_list_internal( const DOM_SID *domain_sid, const char *domain_name, + struct cli_state *cli, TALLOC_CTX *mem_ctx, + int argc, const char **argv ) +{ + POLICY_HND hSCM; + WERROR result = WERR_GENERAL_FAILURE; - cli_lsa_close(cli, mem_ctx, &dom_pol); + if (argc != 0 ) { + d_printf("Usage: net rpc service list\n"); + return NT_STATUS_OK; + } - return result; -#else + if ( !W_ERROR_IS_OK(result = open_scmanager( cli, mem_ctx, &hSCM )) ) { + 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; -#endif } @@ -77,7 +115,7 @@ done: static int rpc_service_list( int argc, const char **argv ) { - return run_rpc_command( NULL, PI_LSARPC, 0, + return run_rpc_command( NULL, PI_SVCCTL, 0, rpc_service_list_internal, argc, argv ); } -- cgit From eb1adc527bb1b01f28fa86e7caa66c85181df764 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 24 Mar 2005 17:11:51 +0000 Subject: r6039: add CLI_DO_RPC macro for cookie cutter code; no new functionality to 'net rpc service' (This used to be commit 759affb1e1aa59fcb878b4dee781aa362b3e7e1c) --- source3/utils/net_rpc_service.c | 66 ++--------------------------------------- 1 file changed, 3 insertions(+), 63 deletions(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index 79e7eaa900..98711c95b6 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -20,68 +20,6 @@ #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; -- cgit From 9d009834a63e45e8a348419d4f5313757cff8c8d Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 24 Mar 2005 18:05:31 +0000 Subject: r6040: finish out 'net rpc service list' (This used to be commit 42588ba50cb1b47a00f3e0bed33ca3431eb8af14) --- source3/utils/net_rpc_service.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index 98711c95b6..3d6bf7617c 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -28,25 +28,46 @@ static NTSTATUS rpc_service_list_internal( const DOM_SID *domain_sid, const char int argc, const char **argv ) { POLICY_HND hSCM; + ENUM_SERVICES_STATUS *services; WERROR result = WERR_GENERAL_FAILURE; + fstring servicename; + fstring displayname; + uint32 num_services = 0; + int i; if (argc != 0 ) { d_printf("Usage: net rpc service list\n"); return NT_STATUS_OK; } - if ( !W_ERROR_IS_OK(result = cli_svcctl_open_scm( cli, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE )) ) { + result = cli_svcctl_open_scm( cli, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); + if ( !W_ERROR_IS_OK(result) ) { 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"); + result = cli_svcctl_enumerate_services( cli, mem_ctx, &hSCM, SVCCTL_TYPE_WIN32, + SVCCTL_STATE_ALL, &num_services, &services ); + if ( !W_ERROR_IS_OK(result) ) { + d_printf("Failed to enumerate services. [%s]\n", dos_errstr(result)); + goto done; + } + if ( num_services == 0 ) + d_printf("No services returned\n"); + for ( i=0; i Date: Thu, 24 Mar 2005 18:13:51 +0000 Subject: r6041: cleaning up output from 'rpc service list' (This used to be commit 7f02ba6646d5c9685250b8ee6e45c9723d748143) --- source3/utils/net_rpc_service.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index 3d6bf7617c..d3343e92ad 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -61,7 +61,7 @@ static NTSTATUS rpc_service_list_internal( const DOM_SID *domain_sid, const char rpcstr_pull( servicename, services[i].servicename.buffer, sizeof(servicename), -1, STR_TERMINATE ); rpcstr_pull( displayname, services[i].displayname.buffer, sizeof(displayname), -1, STR_TERMINATE ); - d_printf("%s (%s)\n", displayname, servicename); + d_printf("%-20s \"%s\"\n", servicename, displayname); } done: -- cgit From dbb5a1fdabf8e66343cd2a4a2dda79cef95e14b1 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 24 Mar 2005 22:32:31 +0000 Subject: r6046: $ net -S block -U % -W VALE rpc service status spooler spooler service is SVCCTL_RUNNING. Configuration details: Service Type = 0x110 Start Type = 0x2 Error Control = 0x1 Tag ID = 0x0 Executable Path = C:\WINNT\system32\spoolsv.exe Load Order Group = SpoolerGroup Dependencies = RPCSS/ Start Name = LocalSystem Display Name = Print Spooler (This used to be commit b921bf568835042a43bb0bcb2abd9d36c9d2e43f) --- source3/utils/net_rpc_service.c | 100 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index d3343e92ad..5e933e76cd 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -70,6 +70,102 @@ done: return werror_to_ntstatus(result); } +/******************************************************************** +********************************************************************/ + +static NTSTATUS rpc_service_status_internal( const DOM_SID *domain_sid, const char *domain_name, + struct cli_state *cli, TALLOC_CTX *mem_ctx, + int argc, const char **argv ) +{ + POLICY_HND hSCM, hService; + WERROR result = WERR_GENERAL_FAILURE; + fstring servicename; + SERVICE_STATUS service_status; + SERVICE_CONFIG config; + fstring ascii_string; + + if (argc != 1 ) { + d_printf("Usage: net rpc service status \n"); + return NT_STATUS_OK; + } + + fstrcpy( servicename, argv[0] ); + + /* Open the Service Control Manager */ + + result = cli_svcctl_open_scm( cli, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); + if ( !W_ERROR_IS_OK(result) ) { + d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); + return werror_to_ntstatus(result); + } + + /* Open the Service */ + + result = cli_svcctl_open_service( cli, mem_ctx, &hSCM, &hService, servicename, + (SC_RIGHT_SVC_QUERY_STATUS|SC_RIGHT_SVC_QUERY_CONFIG) ); + + if ( !W_ERROR_IS_OK(result) ) { + d_printf("Failed to open service. [%s]\n", dos_errstr(result)); + goto done; + } + + /* get the status */ + + result = cli_svcctl_query_status( cli, mem_ctx, &hService, &service_status ); + if ( !W_ERROR_IS_OK(result) ) { + d_printf("Query status request failed. [%s]\n", dos_errstr(result)); + goto done; + } + + d_printf("%s service is %s.\n", servicename, svc_status_string(service_status.state)); + + /* get the config */ + + result = cli_svcctl_query_config( cli, mem_ctx, &hService, &config ); + if ( !W_ERROR_IS_OK(result) ) { + d_printf("Query config request failed. [%s]\n", dos_errstr(result)); + goto done; + } + + /* print out the configuration information for the service */ + + d_printf("Configuration details:\n"); + d_printf("\tService Type = 0x%x\n", config.service_type); + d_printf("\tStart Type = 0x%x\n", config.start_type); + d_printf("\tError Control = 0x%x\n", config.error_control); + d_printf("\tTag ID = 0x%x\n", config.tag_id); + + if ( config.executablepath ) { + rpcstr_pull( ascii_string, config.executablepath->buffer, sizeof(ascii_string), -1, STR_TERMINATE ); + d_printf("\tExecutable Path = %s\n", ascii_string); + } + + if ( config.loadordergroup ) { + rpcstr_pull( ascii_string, config.loadordergroup->buffer, sizeof(ascii_string), -1, STR_TERMINATE ); + d_printf("\tLoad Order Group = %s\n", ascii_string); + } + + if ( config.dependencies ) { + rpcstr_pull( ascii_string, config.dependencies->buffer, sizeof(ascii_string), -1, STR_TERMINATE ); + d_printf("\tDependencies = %s\n", ascii_string); + } + + if ( config.startname ) { + rpcstr_pull( ascii_string, config.startname->buffer, sizeof(ascii_string), -1, STR_TERMINATE ); + d_printf("\tStart Name = %s\n", ascii_string); + } + + if ( config.displayname ) { + rpcstr_pull( ascii_string, config.displayname->buffer, sizeof(ascii_string), -1, STR_TERMINATE ); + d_printf("\tDisplay Name = %s\n", ascii_string); + } + +done: + close_service_handle( cli, mem_ctx, &hService ); + close_service_handle( cli, mem_ctx, &hSCM ); + + return werror_to_ntstatus(result); +} /******************************************************************** ********************************************************************/ @@ -112,8 +208,8 @@ static int rpc_service_pause( int argc, const char **argv ) static int rpc_service_status( int argc, const char **argv ) { - d_printf("not implemented\n"); - return 0; + return run_rpc_command( NULL, PI_SVCCTL, 0, + rpc_service_status_internal, argc, argv ); } /******************************************************************** -- cgit From 66e8ed2632f8efb4e749a79609eb34dc488aacdc Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 25 Mar 2005 00:38:30 +0000 Subject: r6051: finish off net rpc service stop net rpc service start net rpc service pause net rpc service resume (This used to be commit a7fb2c50b07a7d9965675272a71f42beba92acfe) --- source3/utils/net_rpc_service.c | 298 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 289 insertions(+), 9 deletions(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index 5e933e76cd..94644f8dcf 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -20,6 +20,113 @@ #include "includes.h" #include "utils/net.h" + +/******************************************************************** +********************************************************************/ + +static WERROR query_service_state( struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *hSCM, const char *service, uint32 *state ) +{ + POLICY_HND hService; + SERVICE_STATUS service_status; + WERROR result = WERR_GENERAL_FAILURE; + + /* now cycle until the status is actually 'watch_state' */ + + result = cli_svcctl_open_service( cli, mem_ctx, hSCM, &hService, + service, SC_RIGHT_SVC_QUERY_STATUS ); + + if ( !W_ERROR_IS_OK(result) ) { + d_printf("Failed to open service. [%s]\n", dos_errstr(result)); + return result; + } + + result = cli_svcctl_query_status( cli, mem_ctx, &hService, &service_status ); + if ( W_ERROR_IS_OK(result) ) { + *state = service_status.state; + } + + cli_svcctl_close_service( cli, mem_ctx, &hService ); + + return result; +} + +/******************************************************************** +********************************************************************/ + +static WERROR watch_service_state( struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *hSCM, const char *service, + uint32 watch_state, uint32 *final_state ) +{ + uint32 i; + uint32 state = 0; + WERROR result = WERR_GENERAL_FAILURE; + + + i = 0; + while ( (state != watch_state ) && i<30 ) { + /* get the status */ + + result = query_service_state( cli, mem_ctx, hSCM, service, &state ); + if ( !W_ERROR_IS_OK(result) ) { + break; + } + + d_printf("."); + i++; + usleep( 100 ); + } + d_printf("\n"); + + *final_state = state; + + return result; +} + +/******************************************************************** +********************************************************************/ + +static WERROR control_service( struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *hSCM, const char *service, + uint32 control, uint32 watch_state ) +{ + POLICY_HND hService; + WERROR result = WERR_GENERAL_FAILURE; + SERVICE_STATUS service_status; + uint32 state = 0; + + /* Open the Service */ + + result = cli_svcctl_open_service( cli, mem_ctx, hSCM, &hService, + service, (SC_RIGHT_SVC_STOP|SC_RIGHT_SVC_PAUSE_CONTINUE) ); + + if ( !W_ERROR_IS_OK(result) ) { + d_printf("Failed to open service. [%s]\n", dos_errstr(result)); + goto done; + } + + /* get the status */ + + result = cli_svcctl_control_service( cli, mem_ctx, &hService, + control, &service_status ); + + if ( !W_ERROR_IS_OK(result) ) { + d_printf("Control service request failed. [%s]\n", dos_errstr(result)); + goto done; + } + + /* loop -- checking the state until we are where we want to be */ + + result = watch_service_state( cli, mem_ctx, hSCM, service, watch_state, &state ); + + d_printf("%s service is %s.\n", service, svc_status_string(state)); + +done: + cli_svcctl_close_service( cli, mem_ctx, &hService ); + + return result; +} + /******************************************************************** ********************************************************************/ @@ -65,7 +172,7 @@ static NTSTATUS rpc_service_list_internal( const DOM_SID *domain_sid, const char } done: - close_service_handle( cli, mem_ctx, &hSCM ); + cli_svcctl_close_service( cli, mem_ctx, &hSCM ); return werror_to_ntstatus(result); } @@ -161,8 +268,77 @@ static NTSTATUS rpc_service_status_internal( const DOM_SID *domain_sid, const ch } done: - close_service_handle( cli, mem_ctx, &hService ); - close_service_handle( cli, mem_ctx, &hSCM ); + cli_svcctl_close_service( cli, mem_ctx, &hService ); + cli_svcctl_close_service( cli, mem_ctx, &hSCM ); + + return werror_to_ntstatus(result); +} + + +/******************************************************************** +********************************************************************/ + +static NTSTATUS rpc_service_stop_internal( const DOM_SID *domain_sid, const char *domain_name, + struct cli_state *cli, TALLOC_CTX *mem_ctx, + int argc, const char **argv ) +{ + POLICY_HND hSCM; + WERROR result = WERR_GENERAL_FAILURE; + fstring servicename; + + if (argc != 1 ) { + d_printf("Usage: net rpc service status \n"); + return NT_STATUS_OK; + } + + fstrcpy( servicename, argv[0] ); + + /* Open the Service Control Manager */ + + result = cli_svcctl_open_scm( cli, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); + if ( !W_ERROR_IS_OK(result) ) { + d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); + return werror_to_ntstatus(result); + } + + result = control_service( cli, mem_ctx, &hSCM, servicename, + SVCCTL_CONTROL_STOP, SVCCTL_STOPPED ); + + cli_svcctl_close_service( cli, mem_ctx, &hSCM ); + + return werror_to_ntstatus(result); +} + +/******************************************************************** +********************************************************************/ + +static NTSTATUS rpc_service_pause_internal( const DOM_SID *domain_sid, const char *domain_name, + struct cli_state *cli, TALLOC_CTX *mem_ctx, + int argc, const char **argv ) +{ + POLICY_HND hSCM; + WERROR result = WERR_GENERAL_FAILURE; + fstring servicename; + + if (argc != 1 ) { + d_printf("Usage: net rpc service status \n"); + return NT_STATUS_OK; + } + + fstrcpy( servicename, argv[0] ); + + /* Open the Service Control Manager */ + + result = cli_svcctl_open_scm( cli, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); + if ( !W_ERROR_IS_OK(result) ) { + d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); + return werror_to_ntstatus(result); + } + + result = control_service( cli, mem_ctx, &hSCM, servicename, + SVCCTL_CONTROL_PAUSE, SVCCTL_PAUSED ); + + cli_svcctl_close_service( cli, mem_ctx, &hSCM ); return werror_to_ntstatus(result); } @@ -170,6 +346,99 @@ done: /******************************************************************** ********************************************************************/ +static NTSTATUS rpc_service_resume_internal( const DOM_SID *domain_sid, const char *domain_name, + struct cli_state *cli, TALLOC_CTX *mem_ctx, + int argc, const char **argv ) +{ + POLICY_HND hSCM; + WERROR result = WERR_GENERAL_FAILURE; + fstring servicename; + + if (argc != 1 ) { + d_printf("Usage: net rpc service status \n"); + return NT_STATUS_OK; + } + + fstrcpy( servicename, argv[0] ); + + /* Open the Service Control Manager */ + + result = cli_svcctl_open_scm( cli, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); + if ( !W_ERROR_IS_OK(result) ) { + d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); + return werror_to_ntstatus(result); + } + + result = control_service( cli, mem_ctx, &hSCM, servicename, + SVCCTL_CONTROL_CONTINUE, SVCCTL_RUNNING ); + + cli_svcctl_close_service( cli, mem_ctx, &hSCM ); + + return werror_to_ntstatus(result); +} + +/******************************************************************** +********************************************************************/ + +static NTSTATUS rpc_service_start_internal( const DOM_SID *domain_sid, const char *domain_name, + struct cli_state *cli, TALLOC_CTX *mem_ctx, + int argc, const char **argv ) +{ + POLICY_HND hSCM, hService; + WERROR result = WERR_GENERAL_FAILURE; + fstring servicename; + uint32 state = 0; + + if (argc != 1 ) { + d_printf("Usage: net rpc service status \n"); + return NT_STATUS_OK; + } + + fstrcpy( servicename, argv[0] ); + + /* Open the Service Control Manager */ + + result = cli_svcctl_open_scm( cli, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); + if ( !W_ERROR_IS_OK(result) ) { + d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); + return werror_to_ntstatus(result); + } + + /* Open the Service */ + + result = cli_svcctl_open_service( cli, mem_ctx, &hSCM, &hService, + servicename, SC_RIGHT_SVC_START ); + + if ( !W_ERROR_IS_OK(result) ) { + d_printf("Failed to open service. [%s]\n", dos_errstr(result)); + goto done; + } + + /* get the status */ + + result = cli_svcctl_start_service( cli, mem_ctx, &hService, NULL, 0 ); + if ( !W_ERROR_IS_OK(result) ) { + d_printf("Query status request failed. [%s]\n", dos_errstr(result)); + goto done; + } + + result = watch_service_state( cli, mem_ctx, &hSCM, servicename, SVCCTL_RUNNING, &state ); + + if ( W_ERROR_IS_OK(result) && (state == SVCCTL_RUNNING) ) + d_printf("Successfully started service: %s\n", servicename ); + else + d_printf("Failed to start service: %s [%s]\n", servicename, dos_errstr(result) ); + +done: + cli_svcctl_close_service( cli, mem_ctx, &hService ); + cli_svcctl_close_service( cli, mem_ctx, &hSCM ); + + return werror_to_ntstatus(result); +} + +/******************************************************************** +********************************************************************/ + static int rpc_service_list( int argc, const char **argv ) { return run_rpc_command( NULL, PI_SVCCTL, 0, @@ -181,8 +450,8 @@ static int rpc_service_list( int argc, const char **argv ) static int rpc_service_start( int argc, const char **argv ) { - d_printf("not implemented\n"); - return 0; + return run_rpc_command( NULL, PI_SVCCTL, 0, + rpc_service_start_internal, argc, argv ); } /******************************************************************** @@ -190,8 +459,17 @@ static int rpc_service_start( int argc, const char **argv ) static int rpc_service_stop( int argc, const char **argv ) { - d_printf("not implemented\n"); - return 0; + return run_rpc_command( NULL, PI_SVCCTL, 0, + rpc_service_stop_internal, argc, argv ); +} + +/******************************************************************** +********************************************************************/ + +static int rpc_service_resume( int argc, const char **argv ) +{ + return run_rpc_command( NULL, PI_SVCCTL, 0, + rpc_service_resume_internal, argc, argv ); } /******************************************************************** @@ -199,8 +477,8 @@ static int rpc_service_stop( int argc, const char **argv ) static int rpc_service_pause( int argc, const char **argv ) { - d_printf("not implemented\n"); - return 0; + return run_rpc_command( NULL, PI_SVCCTL, 0, + rpc_service_pause_internal, argc, argv ); } /******************************************************************** @@ -221,6 +499,7 @@ static int net_help_service( int argc, const char **argv ) d_printf("net rpc service start Start a service\n"); d_printf("net rpc service stop Stop a service\n"); d_printf("net rpc service pause Pause a service\n"); + d_printf("net rpc service resume Resume a paused a service\n"); d_printf("net rpc service status View the current status of a service\n"); return -1; @@ -236,6 +515,7 @@ int net_rpc_service(int argc, const char **argv) {"start", rpc_service_start}, {"stop", rpc_service_stop}, {"pause", rpc_service_pause}, + {"resume", rpc_service_resume}, {"status", rpc_service_status}, {NULL, NULL} }; -- cgit From 063078d92763e25935c704f24e1719e309249961 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 30 Aug 2005 11:31:49 +0000 Subject: r9787: BUG 2998: patch from Humberto Diogenes to include 'net rpc service' help in net rpc usage output (This used to be commit ace8556b6525959114bea47d3be3b1b40756b058) --- source3/utils/net_rpc_service.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index 94644f8dcf..8f93ab3d06 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -499,7 +499,7 @@ static int net_help_service( int argc, const char **argv ) d_printf("net rpc service start Start a service\n"); d_printf("net rpc service stop Stop a service\n"); d_printf("net rpc service pause Pause a service\n"); - d_printf("net rpc service resume Resume a paused a service\n"); + d_printf("net rpc service resume Resume a paused service\n"); d_printf("net rpc service status View the current status of a service\n"); return -1; -- cgit From 54abd2aa66069e6baf7769c496f46d9dba18db39 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 30 Sep 2005 17:13:37 +0000 Subject: r10656: BIG merge from trunk. Features not copied over * \PIPE\unixinfo * winbindd's {group,alias}membership new functions * winbindd's lookupsids() functionality * swat (trunk changes to be reverted as per discussion with Deryck) (This used to be commit 939c3cb5d78e3a2236209b296aa8aba8bdce32d3) --- source3/utils/net_rpc_service.c | 156 ++++++++++++++++++++++++---------------- 1 file changed, 93 insertions(+), 63 deletions(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index 8f93ab3d06..3cc4790884 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -24,8 +24,11 @@ /******************************************************************** ********************************************************************/ -static WERROR query_service_state( struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *hSCM, const char *service, uint32 *state ) +static WERROR query_service_state(struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + POLICY_HND *hSCM, + const char *service, + uint32 *state ) { POLICY_HND hService; SERVICE_STATUS service_status; @@ -33,7 +36,7 @@ static WERROR query_service_state( struct cli_state *cli, TALLOC_CTX *mem_ctx, /* now cycle until the status is actually 'watch_state' */ - result = cli_svcctl_open_service( cli, mem_ctx, hSCM, &hService, + result = rpccli_svcctl_open_service(pipe_hnd, mem_ctx, hSCM, &hService, service, SC_RIGHT_SVC_QUERY_STATUS ); if ( !W_ERROR_IS_OK(result) ) { @@ -41,12 +44,12 @@ static WERROR query_service_state( struct cli_state *cli, TALLOC_CTX *mem_ctx, return result; } - result = cli_svcctl_query_status( cli, mem_ctx, &hService, &service_status ); + result = rpccli_svcctl_query_status(pipe_hnd, mem_ctx, &hService, &service_status ); if ( W_ERROR_IS_OK(result) ) { *state = service_status.state; } - cli_svcctl_close_service( cli, mem_ctx, &hService ); + rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hService ); return result; } @@ -54,9 +57,12 @@ static WERROR query_service_state( struct cli_state *cli, TALLOC_CTX *mem_ctx, /******************************************************************** ********************************************************************/ -static WERROR watch_service_state( struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *hSCM, const char *service, - uint32 watch_state, uint32 *final_state ) +static WERROR watch_service_state(struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + POLICY_HND *hSCM, + const char *service, + uint32 watch_state, + uint32 *final_state ) { uint32 i; uint32 state = 0; @@ -67,7 +73,7 @@ static WERROR watch_service_state( struct cli_state *cli, TALLOC_CTX *mem_ctx, while ( (state != watch_state ) && i<30 ) { /* get the status */ - result = query_service_state( cli, mem_ctx, hSCM, service, &state ); + result = query_service_state(pipe_hnd, mem_ctx, hSCM, service, &state ); if ( !W_ERROR_IS_OK(result) ) { break; } @@ -86,9 +92,12 @@ static WERROR watch_service_state( struct cli_state *cli, TALLOC_CTX *mem_ctx, /******************************************************************** ********************************************************************/ -static WERROR control_service( struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *hSCM, const char *service, - uint32 control, uint32 watch_state ) +static WERROR control_service(struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + POLICY_HND *hSCM, + const char *service, + uint32 control, + uint32 watch_state ) { POLICY_HND hService; WERROR result = WERR_GENERAL_FAILURE; @@ -97,7 +106,7 @@ static WERROR control_service( struct cli_state *cli, TALLOC_CTX *mem_ctx, /* Open the Service */ - result = cli_svcctl_open_service( cli, mem_ctx, hSCM, &hService, + result = rpccli_svcctl_open_service(pipe_hnd, mem_ctx, hSCM, &hService, service, (SC_RIGHT_SVC_STOP|SC_RIGHT_SVC_PAUSE_CONTINUE) ); if ( !W_ERROR_IS_OK(result) ) { @@ -107,7 +116,7 @@ static WERROR control_service( struct cli_state *cli, TALLOC_CTX *mem_ctx, /* get the status */ - result = cli_svcctl_control_service( cli, mem_ctx, &hService, + result = rpccli_svcctl_control_service(pipe_hnd, mem_ctx, &hService, control, &service_status ); if ( !W_ERROR_IS_OK(result) ) { @@ -117,12 +126,12 @@ static WERROR control_service( struct cli_state *cli, TALLOC_CTX *mem_ctx, /* loop -- checking the state until we are where we want to be */ - result = watch_service_state( cli, mem_ctx, hSCM, service, watch_state, &state ); + result = watch_service_state(pipe_hnd, mem_ctx, hSCM, service, watch_state, &state ); d_printf("%s service is %s.\n", service, svc_status_string(state)); done: - cli_svcctl_close_service( cli, mem_ctx, &hService ); + rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hService ); return result; } @@ -130,9 +139,13 @@ done: /******************************************************************** ********************************************************************/ -static NTSTATUS rpc_service_list_internal( const DOM_SID *domain_sid, const char *domain_name, - struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, const char **argv ) +static NTSTATUS rpc_service_list_internal(const DOM_SID *domain_sid, + const char *domain_name, + struct cli_state *cli, + struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + int argc, + const char **argv ) { POLICY_HND hSCM; ENUM_SERVICES_STATUS *services; @@ -147,13 +160,13 @@ static NTSTATUS rpc_service_list_internal( const DOM_SID *domain_sid, const char return NT_STATUS_OK; } - result = cli_svcctl_open_scm( cli, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); + result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); if ( !W_ERROR_IS_OK(result) ) { d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } - result = cli_svcctl_enumerate_services( cli, mem_ctx, &hSCM, SVCCTL_TYPE_WIN32, + result = rpccli_svcctl_enumerate_services(pipe_hnd, mem_ctx, &hSCM, SVCCTL_TYPE_WIN32, SVCCTL_STATE_ALL, &num_services, &services ); if ( !W_ERROR_IS_OK(result) ) { @@ -172,7 +185,7 @@ static NTSTATUS rpc_service_list_internal( const DOM_SID *domain_sid, const char } done: - cli_svcctl_close_service( cli, mem_ctx, &hSCM ); + rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hSCM ); return werror_to_ntstatus(result); } @@ -180,9 +193,13 @@ done: /******************************************************************** ********************************************************************/ -static NTSTATUS rpc_service_status_internal( const DOM_SID *domain_sid, const char *domain_name, - struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, const char **argv ) +static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, + const char *domain_name, + struct cli_state *cli, + struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + int argc, + const char **argv ) { POLICY_HND hSCM, hService; WERROR result = WERR_GENERAL_FAILURE; @@ -200,7 +217,7 @@ static NTSTATUS rpc_service_status_internal( const DOM_SID *domain_sid, const ch /* Open the Service Control Manager */ - result = cli_svcctl_open_scm( cli, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); + result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); if ( !W_ERROR_IS_OK(result) ) { d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); @@ -208,7 +225,7 @@ static NTSTATUS rpc_service_status_internal( const DOM_SID *domain_sid, const ch /* Open the Service */ - result = cli_svcctl_open_service( cli, mem_ctx, &hSCM, &hService, servicename, + result = rpccli_svcctl_open_service(pipe_hnd, mem_ctx, &hSCM, &hService, servicename, (SC_RIGHT_SVC_QUERY_STATUS|SC_RIGHT_SVC_QUERY_CONFIG) ); if ( !W_ERROR_IS_OK(result) ) { @@ -218,7 +235,7 @@ static NTSTATUS rpc_service_status_internal( const DOM_SID *domain_sid, const ch /* get the status */ - result = cli_svcctl_query_status( cli, mem_ctx, &hService, &service_status ); + result = rpccli_svcctl_query_status(pipe_hnd, mem_ctx, &hService, &service_status ); if ( !W_ERROR_IS_OK(result) ) { d_printf("Query status request failed. [%s]\n", dos_errstr(result)); goto done; @@ -228,7 +245,7 @@ static NTSTATUS rpc_service_status_internal( const DOM_SID *domain_sid, const ch /* get the config */ - result = cli_svcctl_query_config( cli, mem_ctx, &hService, &config ); + result = rpccli_svcctl_query_config(pipe_hnd, mem_ctx, &hService, &config ); if ( !W_ERROR_IS_OK(result) ) { d_printf("Query config request failed. [%s]\n", dos_errstr(result)); goto done; @@ -268,19 +285,22 @@ static NTSTATUS rpc_service_status_internal( const DOM_SID *domain_sid, const ch } done: - cli_svcctl_close_service( cli, mem_ctx, &hService ); - cli_svcctl_close_service( cli, mem_ctx, &hSCM ); - + rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hService ); + rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hSCM ); + return werror_to_ntstatus(result); } - /******************************************************************** ********************************************************************/ -static NTSTATUS rpc_service_stop_internal( const DOM_SID *domain_sid, const char *domain_name, - struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, const char **argv ) +static NTSTATUS rpc_service_stop_internal(const DOM_SID *domain_sid, + const char *domain_name, + struct cli_state *cli, + struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + int argc, + const char **argv ) { POLICY_HND hSCM; WERROR result = WERR_GENERAL_FAILURE; @@ -295,16 +315,16 @@ static NTSTATUS rpc_service_stop_internal( const DOM_SID *domain_sid, const char /* Open the Service Control Manager */ - result = cli_svcctl_open_scm( cli, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); + result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); if ( !W_ERROR_IS_OK(result) ) { d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } - result = control_service( cli, mem_ctx, &hSCM, servicename, + result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename, SVCCTL_CONTROL_STOP, SVCCTL_STOPPED ); - cli_svcctl_close_service( cli, mem_ctx, &hSCM ); + rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hSCM ); return werror_to_ntstatus(result); } @@ -312,9 +332,13 @@ static NTSTATUS rpc_service_stop_internal( const DOM_SID *domain_sid, const char /******************************************************************** ********************************************************************/ -static NTSTATUS rpc_service_pause_internal( const DOM_SID *domain_sid, const char *domain_name, - struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, const char **argv ) +static NTSTATUS rpc_service_pause_internal(const DOM_SID *domain_sid, + const char *domain_name, + struct cli_state *cli, + struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + int argc, + const char **argv ) { POLICY_HND hSCM; WERROR result = WERR_GENERAL_FAILURE; @@ -329,16 +353,16 @@ static NTSTATUS rpc_service_pause_internal( const DOM_SID *domain_sid, const cha /* Open the Service Control Manager */ - result = cli_svcctl_open_scm( cli, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); + result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); if ( !W_ERROR_IS_OK(result) ) { d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } - result = control_service( cli, mem_ctx, &hSCM, servicename, + result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename, SVCCTL_CONTROL_PAUSE, SVCCTL_PAUSED ); - cli_svcctl_close_service( cli, mem_ctx, &hSCM ); + rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hSCM ); return werror_to_ntstatus(result); } @@ -346,9 +370,13 @@ static NTSTATUS rpc_service_pause_internal( const DOM_SID *domain_sid, const cha /******************************************************************** ********************************************************************/ -static NTSTATUS rpc_service_resume_internal( const DOM_SID *domain_sid, const char *domain_name, - struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, const char **argv ) +static NTSTATUS rpc_service_resume_internal(const DOM_SID *domain_sid, + const char *domain_name, + struct cli_state *cli, + struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + int argc, + const char **argv ) { POLICY_HND hSCM; WERROR result = WERR_GENERAL_FAILURE; @@ -363,16 +391,16 @@ static NTSTATUS rpc_service_resume_internal( const DOM_SID *domain_sid, const ch /* Open the Service Control Manager */ - result = cli_svcctl_open_scm( cli, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); + result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); if ( !W_ERROR_IS_OK(result) ) { d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } - result = control_service( cli, mem_ctx, &hSCM, servicename, + result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename, SVCCTL_CONTROL_CONTINUE, SVCCTL_RUNNING ); - cli_svcctl_close_service( cli, mem_ctx, &hSCM ); + rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hSCM ); return werror_to_ntstatus(result); } @@ -380,9 +408,13 @@ static NTSTATUS rpc_service_resume_internal( const DOM_SID *domain_sid, const ch /******************************************************************** ********************************************************************/ -static NTSTATUS rpc_service_start_internal( const DOM_SID *domain_sid, const char *domain_name, - struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, const char **argv ) +static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, + const char *domain_name, + struct cli_state *cli, + struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + int argc, + const char **argv ) { POLICY_HND hSCM, hService; WERROR result = WERR_GENERAL_FAILURE; @@ -398,7 +430,7 @@ static NTSTATUS rpc_service_start_internal( const DOM_SID *domain_sid, const cha /* Open the Service Control Manager */ - result = cli_svcctl_open_scm( cli, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); + result = rpccli_svcctl_open_scm( pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); if ( !W_ERROR_IS_OK(result) ) { d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); @@ -406,7 +438,7 @@ static NTSTATUS rpc_service_start_internal( const DOM_SID *domain_sid, const cha /* Open the Service */ - result = cli_svcctl_open_service( cli, mem_ctx, &hSCM, &hService, + result = rpccli_svcctl_open_service(pipe_hnd, mem_ctx, &hSCM, &hService, servicename, SC_RIGHT_SVC_START ); if ( !W_ERROR_IS_OK(result) ) { @@ -416,13 +448,13 @@ static NTSTATUS rpc_service_start_internal( const DOM_SID *domain_sid, const cha /* get the status */ - result = cli_svcctl_start_service( cli, mem_ctx, &hService, NULL, 0 ); + result = rpccli_svcctl_start_service(pipe_hnd, mem_ctx, &hService, NULL, 0 ); if ( !W_ERROR_IS_OK(result) ) { d_printf("Query status request failed. [%s]\n", dos_errstr(result)); goto done; } - result = watch_service_state( cli, mem_ctx, &hSCM, servicename, SVCCTL_RUNNING, &state ); + result = watch_service_state(pipe_hnd, mem_ctx, &hSCM, servicename, SVCCTL_RUNNING, &state ); if ( W_ERROR_IS_OK(result) && (state == SVCCTL_RUNNING) ) d_printf("Successfully started service: %s\n", servicename ); @@ -430,9 +462,9 @@ static NTSTATUS rpc_service_start_internal( const DOM_SID *domain_sid, const cha d_printf("Failed to start service: %s [%s]\n", servicename, dos_errstr(result) ); done: - cli_svcctl_close_service( cli, mem_ctx, &hService ); - cli_svcctl_close_service( cli, mem_ctx, &hSCM ); - + rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hService ); + rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hSCM ); + return werror_to_ntstatus(result); } @@ -525,5 +557,3 @@ int net_rpc_service(int argc, const char **argv) return net_help_service( argc, argv ); } - - -- cgit From a48955306705ac7f045e3726d7097900550bebe3 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sun, 11 Dec 2005 04:21:34 +0000 Subject: r12173: doing some service control work * Add a few new error codes for disabled services * dump some more details about service status in 'net rpc service' * disable the WINS and NetLogon services if not configured in smb.conf Still trying to figure out how to disable the start button on the NetLogon and WINS services. (This used to be commit c0f54eeebc84ec9fab63c5b105511762bcc136be) --- source3/utils/net_rpc_service.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index 3cc4790884..ed7d1dfab1 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -254,6 +254,7 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, /* print out the configuration information for the service */ d_printf("Configuration details:\n"); + d_printf("\tControls Accepted = 0x%x\n", service_status.controls_accepted); d_printf("\tService Type = 0x%x\n", config.service_type); d_printf("\tStart Type = 0x%x\n", config.start_type); d_printf("\tError Control = 0x%x\n", config.error_control); -- cgit From c42be9fd38556a1cc2e16c8d763a592beb863806 Mon Sep 17 00:00:00 2001 From: Lars Müller Date: Tue, 17 Jan 2006 21:22:00 +0000 Subject: r12986: Use d_fprintf(stderr, ...) for any error message in net. All 'usage' messages are still printed to stdout. Fix some compiler warnings for system() calls where we didn't used the return code. Add appropriate error messages and return with the error code we got from system() or NT_STATUS_UNSUCCESSFUL. (This used to be commit f650e3bdafc4c6bcd7eb4bcf8b6b885b979919eb) --- source3/utils/net_rpc_service.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index ed7d1dfab1..27127a1c3f 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -40,7 +40,7 @@ static WERROR query_service_state(struct rpc_pipe_client *pipe_hnd, service, SC_RIGHT_SVC_QUERY_STATUS ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Failed to open service. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Failed to open service. [%s]\n", dos_errstr(result)); return result; } @@ -110,7 +110,7 @@ static WERROR control_service(struct rpc_pipe_client *pipe_hnd, service, (SC_RIGHT_SVC_STOP|SC_RIGHT_SVC_PAUSE_CONTINUE) ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Failed to open service. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Failed to open service. [%s]\n", dos_errstr(result)); goto done; } @@ -120,7 +120,7 @@ static WERROR control_service(struct rpc_pipe_client *pipe_hnd, control, &service_status ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Control service request failed. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Control service request failed. [%s]\n", dos_errstr(result)); goto done; } @@ -162,7 +162,7 @@ static NTSTATUS rpc_service_list_internal(const DOM_SID *domain_sid, result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } @@ -170,7 +170,7 @@ static NTSTATUS rpc_service_list_internal(const DOM_SID *domain_sid, SVCCTL_STATE_ALL, &num_services, &services ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Failed to enumerate services. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Failed to enumerate services. [%s]\n", dos_errstr(result)); goto done; } @@ -219,7 +219,7 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } @@ -229,7 +229,7 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, (SC_RIGHT_SVC_QUERY_STATUS|SC_RIGHT_SVC_QUERY_CONFIG) ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Failed to open service. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Failed to open service. [%s]\n", dos_errstr(result)); goto done; } @@ -237,7 +237,7 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, result = rpccli_svcctl_query_status(pipe_hnd, mem_ctx, &hService, &service_status ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Query status request failed. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Query status request failed. [%s]\n", dos_errstr(result)); goto done; } @@ -247,7 +247,7 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, result = rpccli_svcctl_query_config(pipe_hnd, mem_ctx, &hService, &config ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Query config request failed. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Query config request failed. [%s]\n", dos_errstr(result)); goto done; } @@ -318,7 +318,7 @@ static NTSTATUS rpc_service_stop_internal(const DOM_SID *domain_sid, result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } @@ -356,7 +356,7 @@ static NTSTATUS rpc_service_pause_internal(const DOM_SID *domain_sid, result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } @@ -394,7 +394,7 @@ static NTSTATUS rpc_service_resume_internal(const DOM_SID *domain_sid, result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } @@ -433,7 +433,7 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, result = rpccli_svcctl_open_scm( pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } @@ -443,7 +443,7 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, servicename, SC_RIGHT_SVC_START ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Failed to open service. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Failed to open service. [%s]\n", dos_errstr(result)); goto done; } @@ -451,7 +451,7 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, result = rpccli_svcctl_start_service(pipe_hnd, mem_ctx, &hService, NULL, 0 ); if ( !W_ERROR_IS_OK(result) ) { - d_printf("Query status request failed. [%s]\n", dos_errstr(result)); + d_fprintf(stderr, "Query status request failed. [%s]\n", dos_errstr(result)); goto done; } @@ -460,7 +460,7 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, if ( W_ERROR_IS_OK(result) && (state == SVCCTL_RUNNING) ) d_printf("Successfully started service: %s\n", servicename ); else - d_printf("Failed to start service: %s [%s]\n", servicename, dos_errstr(result) ); + d_fprintf(stderr, "Failed to start service: %s [%s]\n", servicename, dos_errstr(result) ); done: rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hService ); -- cgit From 1888bb4fd98138b2ac2ba01b9e2eae1736c76a33 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 27 Sep 2006 11:37:02 +0000 Subject: r18949: use sys_usleep() metze (This used to be commit f9944941415b88559b67f6c7e780e364d5030240) --- source3/utils/net_rpc_service.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index 27127a1c3f..58a5b27f40 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -80,7 +80,7 @@ static WERROR watch_service_state(struct rpc_pipe_client *pipe_hnd, d_printf("."); i++; - usleep( 100 ); + sys_usleep( 100 ); } d_printf("\n"); -- cgit From d99f4f004ca46e4c0f2e60a231a14708a128f0f2 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 31 May 2007 17:24:30 +0000 Subject: r23271: merge service control pidl change for CloseServiceHandle() from SAMBA_3_0_26 (This used to be commit 0b1bc3521fac52f3164b6cc9e053abc3ceabf5e7) --- source3/utils/net_rpc_service.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index 58a5b27f40..c0b1fe3515 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -49,7 +49,7 @@ static WERROR query_service_state(struct rpc_pipe_client *pipe_hnd, *state = service_status.state; } - rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hService ); + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService); return result; } @@ -131,7 +131,7 @@ static WERROR control_service(struct rpc_pipe_client *pipe_hnd, d_printf("%s service is %s.\n", service, svc_status_string(state)); done: - rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hService ); + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService); return result; } @@ -185,7 +185,7 @@ static NTSTATUS rpc_service_list_internal(const DOM_SID *domain_sid, } done: - rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hSCM ); + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM); return werror_to_ntstatus(result); } @@ -286,8 +286,8 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, } done: - rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hService ); - rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hSCM ); + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService); + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM); return werror_to_ntstatus(result); } @@ -325,7 +325,7 @@ static NTSTATUS rpc_service_stop_internal(const DOM_SID *domain_sid, result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename, SVCCTL_CONTROL_STOP, SVCCTL_STOPPED ); - rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hSCM ); + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM); return werror_to_ntstatus(result); } @@ -363,7 +363,7 @@ static NTSTATUS rpc_service_pause_internal(const DOM_SID *domain_sid, result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename, SVCCTL_CONTROL_PAUSE, SVCCTL_PAUSED ); - rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hSCM ); + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM); return werror_to_ntstatus(result); } @@ -401,7 +401,7 @@ static NTSTATUS rpc_service_resume_internal(const DOM_SID *domain_sid, result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename, SVCCTL_CONTROL_CONTINUE, SVCCTL_RUNNING ); - rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hSCM ); + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM); return werror_to_ntstatus(result); } @@ -463,8 +463,8 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, d_fprintf(stderr, "Failed to start service: %s [%s]\n", servicename, dos_errstr(result) ); done: - rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hService ); - rpccli_svcctl_close_service(pipe_hnd, mem_ctx, &hSCM ); + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService); + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM); return werror_to_ntstatus(result); } -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/utils/net_rpc_service.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index c0b1fe3515..69ff55f162 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -5,7 +5,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/utils/net_rpc_service.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index 69ff55f162..0938cec74d 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -14,8 +14,7 @@ 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. */ + along with this program. If not, see . */ #include "includes.h" #include "utils/net.h" -- cgit From 9ab00383487d1c6906b7cbe097de6cc58165471f Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 3 Dec 2007 18:25:13 +0100 Subject: Fix svcctl callers. Guenther (This used to be commit 91bf2ac1af66acd8bcc831e758b3765fc94b2485) --- source3/utils/net_rpc_service.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index 0938cec74d..a70ecf3c72 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -48,7 +48,7 @@ static WERROR query_service_state(struct rpc_pipe_client *pipe_hnd, *state = service_status.state; } - rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService); + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService, NULL); return result; } @@ -130,7 +130,7 @@ static WERROR control_service(struct rpc_pipe_client *pipe_hnd, d_printf("%s service is %s.\n", service, svc_status_string(state)); done: - rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService); + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService, NULL); return result; } @@ -184,7 +184,7 @@ static NTSTATUS rpc_service_list_internal(const DOM_SID *domain_sid, } done: - rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM); + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL); return werror_to_ntstatus(result); } @@ -285,8 +285,8 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, } done: - rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService); - rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM); + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService, NULL); + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL); return werror_to_ntstatus(result); } @@ -324,7 +324,7 @@ static NTSTATUS rpc_service_stop_internal(const DOM_SID *domain_sid, result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename, SVCCTL_CONTROL_STOP, SVCCTL_STOPPED ); - rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM); + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL); return werror_to_ntstatus(result); } @@ -362,7 +362,7 @@ static NTSTATUS rpc_service_pause_internal(const DOM_SID *domain_sid, result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename, SVCCTL_CONTROL_PAUSE, SVCCTL_PAUSED ); - rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM); + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL); return werror_to_ntstatus(result); } @@ -400,7 +400,7 @@ static NTSTATUS rpc_service_resume_internal(const DOM_SID *domain_sid, result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename, SVCCTL_CONTROL_CONTINUE, SVCCTL_RUNNING ); - rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM); + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL); return werror_to_ntstatus(result); } @@ -462,8 +462,8 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, d_fprintf(stderr, "Failed to start service: %s [%s]\n", servicename, dos_errstr(result) ); done: - rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService); - rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM); + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService, NULL); + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL); return werror_to_ntstatus(result); } -- cgit From 50e31b9346a1d191a959e493a1e4f0f6fdc582b8 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 18 Feb 2008 11:48:51 +0100 Subject: Remove whitespace, no code changes. Guenther (This used to be commit d752d52f1a4b75d7d4934da66566bc62e14caf27) --- source3/utils/net_rpc_service.c | 208 ++++++++++++++++++++-------------------- 1 file changed, 104 insertions(+), 104 deletions(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index a70ecf3c72..5ad907e8a6 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -1,21 +1,21 @@ -/* - Samba Unix/Linux SMB client library - Distributed SMB/CIFS Server Management Utility +/* + Samba Unix/Linux SMB client library + Distributed SMB/CIFS Server Management Utility Copyright (C) Gerald (Jerry) 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 3 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, see . */ - + #include "includes.h" #include "utils/net.h" @@ -24,7 +24,7 @@ ********************************************************************/ static WERROR query_service_state(struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, POLICY_HND *hSCM, const char *service, uint32 *state ) @@ -32,10 +32,10 @@ static WERROR query_service_state(struct rpc_pipe_client *pipe_hnd, POLICY_HND hService; SERVICE_STATUS service_status; WERROR result = WERR_GENERAL_FAILURE; - + /* now cycle until the status is actually 'watch_state' */ - - result = rpccli_svcctl_open_service(pipe_hnd, mem_ctx, hSCM, &hService, + + result = rpccli_svcctl_open_service(pipe_hnd, mem_ctx, hSCM, &hService, service, SC_RIGHT_SVC_QUERY_STATUS ); if ( !W_ERROR_IS_OK(result) ) { @@ -47,9 +47,9 @@ static WERROR query_service_state(struct rpc_pipe_client *pipe_hnd, if ( W_ERROR_IS_OK(result) ) { *state = service_status.state; } - + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService, NULL); - + return result; } @@ -57,17 +57,17 @@ static WERROR query_service_state(struct rpc_pipe_client *pipe_hnd, ********************************************************************/ static WERROR watch_service_state(struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, POLICY_HND *hSCM, - const char *service, + const char *service, uint32 watch_state, uint32 *final_state ) { uint32 i; uint32 state = 0; WERROR result = WERR_GENERAL_FAILURE; - - + + i = 0; while ( (state != watch_state ) && i<30 ) { /* get the status */ @@ -76,15 +76,15 @@ static WERROR watch_service_state(struct rpc_pipe_client *pipe_hnd, if ( !W_ERROR_IS_OK(result) ) { break; } - + d_printf("."); i++; sys_usleep( 100 ); } d_printf("\n"); - + *final_state = state; - + return result; } @@ -92,9 +92,9 @@ static WERROR watch_service_state(struct rpc_pipe_client *pipe_hnd, ********************************************************************/ static WERROR control_service(struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, POLICY_HND *hSCM, - const char *service, + const char *service, uint32 control, uint32 watch_state ) { @@ -102,47 +102,47 @@ static WERROR control_service(struct rpc_pipe_client *pipe_hnd, WERROR result = WERR_GENERAL_FAILURE; SERVICE_STATUS service_status; uint32 state = 0; - + /* Open the Service */ - - result = rpccli_svcctl_open_service(pipe_hnd, mem_ctx, hSCM, &hService, + + result = rpccli_svcctl_open_service(pipe_hnd, mem_ctx, hSCM, &hService, service, (SC_RIGHT_SVC_STOP|SC_RIGHT_SVC_PAUSE_CONTINUE) ); if ( !W_ERROR_IS_OK(result) ) { d_fprintf(stderr, "Failed to open service. [%s]\n", dos_errstr(result)); goto done; } - + /* get the status */ - result = rpccli_svcctl_control_service(pipe_hnd, mem_ctx, &hService, + result = rpccli_svcctl_control_service(pipe_hnd, mem_ctx, &hService, control, &service_status ); - + if ( !W_ERROR_IS_OK(result) ) { d_fprintf(stderr, "Control service request failed. [%s]\n", dos_errstr(result)); goto done; } - + /* loop -- checking the state until we are where we want to be */ - + result = watch_service_state(pipe_hnd, mem_ctx, hSCM, service, watch_state, &state ); - + d_printf("%s service is %s.\n", service, svc_status_string(state)); -done: +done: rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService, NULL); - + return result; -} +} /******************************************************************** ********************************************************************/ static NTSTATUS rpc_service_list_internal(const DOM_SID *domain_sid, - const char *domain_name, + const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, int argc, const char **argv ) { @@ -153,7 +153,7 @@ static NTSTATUS rpc_service_list_internal(const DOM_SID *domain_sid, fstring displayname; uint32 num_services = 0; int i; - + if (argc != 0 ) { d_printf("Usage: net rpc service list\n"); return NT_STATUS_OK; @@ -164,39 +164,39 @@ static NTSTATUS rpc_service_list_internal(const DOM_SID *domain_sid, d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } - + result = rpccli_svcctl_enumerate_services(pipe_hnd, mem_ctx, &hSCM, SVCCTL_TYPE_WIN32, SVCCTL_STATE_ALL, &num_services, &services ); - + if ( !W_ERROR_IS_OK(result) ) { d_fprintf(stderr, "Failed to enumerate services. [%s]\n", dos_errstr(result)); goto done; } - + if ( num_services == 0 ) d_printf("No services returned\n"); - + for ( i=0; i\n"); return NT_STATUS_OK; @@ -215,23 +215,23 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, fstrcpy( servicename, argv[0] ); /* Open the Service Control Manager */ - + result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); if ( !W_ERROR_IS_OK(result) ) { d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } - + /* Open the Service */ - - result = rpccli_svcctl_open_service(pipe_hnd, mem_ctx, &hSCM, &hService, servicename, + + result = rpccli_svcctl_open_service(pipe_hnd, mem_ctx, &hSCM, &hService, servicename, (SC_RIGHT_SVC_QUERY_STATUS|SC_RIGHT_SVC_QUERY_CONFIG) ); if ( !W_ERROR_IS_OK(result) ) { d_fprintf(stderr, "Failed to open service. [%s]\n", dos_errstr(result)); goto done; } - + /* get the status */ result = rpccli_svcctl_query_status(pipe_hnd, mem_ctx, &hService, &service_status ); @@ -239,7 +239,7 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, d_fprintf(stderr, "Query status request failed. [%s]\n", dos_errstr(result)); goto done; } - + d_printf("%s service is %s.\n", servicename, svc_status_string(service_status.state)); /* get the config */ @@ -284,28 +284,28 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, d_printf("\tDisplay Name = %s\n", ascii_string); } -done: +done: rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService, NULL); rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL); return werror_to_ntstatus(result); -} +} /******************************************************************** ********************************************************************/ static NTSTATUS rpc_service_stop_internal(const DOM_SID *domain_sid, - const char *domain_name, + const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, int argc, const char **argv ) { POLICY_HND hSCM; WERROR result = WERR_GENERAL_FAILURE; fstring servicename; - + if (argc != 1 ) { d_printf("Usage: net rpc service status \n"); return NT_STATUS_OK; @@ -314,36 +314,36 @@ static NTSTATUS rpc_service_stop_internal(const DOM_SID *domain_sid, fstrcpy( servicename, argv[0] ); /* Open the Service Control Manager */ - + result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); if ( !W_ERROR_IS_OK(result) ) { d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } - - result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename, + + result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename, SVCCTL_CONTROL_STOP, SVCCTL_STOPPED ); - + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL); - + return werror_to_ntstatus(result); -} +} /******************************************************************** ********************************************************************/ static NTSTATUS rpc_service_pause_internal(const DOM_SID *domain_sid, - const char *domain_name, + const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, int argc, const char **argv ) { POLICY_HND hSCM; WERROR result = WERR_GENERAL_FAILURE; fstring servicename; - + if (argc != 1 ) { d_printf("Usage: net rpc service status \n"); return NT_STATUS_OK; @@ -352,36 +352,36 @@ static NTSTATUS rpc_service_pause_internal(const DOM_SID *domain_sid, fstrcpy( servicename, argv[0] ); /* Open the Service Control Manager */ - + result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); if ( !W_ERROR_IS_OK(result) ) { d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } - - result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename, + + result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename, SVCCTL_CONTROL_PAUSE, SVCCTL_PAUSED ); - + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL); - + return werror_to_ntstatus(result); -} +} /******************************************************************** ********************************************************************/ static NTSTATUS rpc_service_resume_internal(const DOM_SID *domain_sid, - const char *domain_name, + const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, int argc, const char **argv ) { POLICY_HND hSCM; WERROR result = WERR_GENERAL_FAILURE; fstring servicename; - + if (argc != 1 ) { d_printf("Usage: net rpc service status \n"); return NT_STATUS_OK; @@ -390,29 +390,29 @@ static NTSTATUS rpc_service_resume_internal(const DOM_SID *domain_sid, fstrcpy( servicename, argv[0] ); /* Open the Service Control Manager */ - + result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); if ( !W_ERROR_IS_OK(result) ) { d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } - - result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename, + + result = control_service(pipe_hnd, mem_ctx, &hSCM, servicename, SVCCTL_CONTROL_CONTINUE, SVCCTL_RUNNING ); - + rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL); - + return werror_to_ntstatus(result); -} +} /******************************************************************** ********************************************************************/ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, - const char *domain_name, + const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, int argc, const char **argv ) { @@ -420,7 +420,7 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, WERROR result = WERR_GENERAL_FAILURE; fstring servicename; uint32 state = 0; - + if (argc != 1 ) { d_printf("Usage: net rpc service status \n"); return NT_STATUS_OK; @@ -429,23 +429,23 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, fstrcpy( servicename, argv[0] ); /* Open the Service Control Manager */ - + result = rpccli_svcctl_open_scm( pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); if ( !W_ERROR_IS_OK(result) ) { d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } - + /* Open the Service */ - - result = rpccli_svcctl_open_service(pipe_hnd, mem_ctx, &hSCM, &hService, + + result = rpccli_svcctl_open_service(pipe_hnd, mem_ctx, &hSCM, &hService, servicename, SC_RIGHT_SVC_START ); if ( !W_ERROR_IS_OK(result) ) { d_fprintf(stderr, "Failed to open service. [%s]\n", dos_errstr(result)); goto done; } - + /* get the status */ result = rpccli_svcctl_start_service(pipe_hnd, mem_ctx, &hService, NULL, 0 ); @@ -453,15 +453,15 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, d_fprintf(stderr, "Query status request failed. [%s]\n", dos_errstr(result)); goto done; } - + result = watch_service_state(pipe_hnd, mem_ctx, &hSCM, servicename, SVCCTL_RUNNING, &state ); - + if ( W_ERROR_IS_OK(result) && (state == SVCCTL_RUNNING) ) d_printf("Successfully started service: %s\n", servicename ); else d_fprintf(stderr, "Failed to start service: %s [%s]\n", servicename, dos_errstr(result) ); - -done: + +done: rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService, NULL); rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hSCM, NULL); @@ -473,7 +473,7 @@ done: static int rpc_service_list( int argc, const char **argv ) { - return run_rpc_command( NULL, PI_SVCCTL, 0, + return run_rpc_command( NULL, PI_SVCCTL, 0, rpc_service_list_internal, argc, argv ); } @@ -482,7 +482,7 @@ static int rpc_service_list( int argc, const char **argv ) static int rpc_service_start( int argc, const char **argv ) { - return run_rpc_command( NULL, PI_SVCCTL, 0, + return run_rpc_command( NULL, PI_SVCCTL, 0, rpc_service_start_internal, argc, argv ); } @@ -491,7 +491,7 @@ static int rpc_service_start( int argc, const char **argv ) static int rpc_service_stop( int argc, const char **argv ) { - return run_rpc_command( NULL, PI_SVCCTL, 0, + return run_rpc_command( NULL, PI_SVCCTL, 0, rpc_service_stop_internal, argc, argv ); } @@ -500,7 +500,7 @@ static int rpc_service_stop( int argc, const char **argv ) static int rpc_service_resume( int argc, const char **argv ) { - return run_rpc_command( NULL, PI_SVCCTL, 0, + return run_rpc_command( NULL, PI_SVCCTL, 0, rpc_service_resume_internal, argc, argv ); } @@ -509,7 +509,7 @@ static int rpc_service_resume( int argc, const char **argv ) static int rpc_service_pause( int argc, const char **argv ) { - return run_rpc_command( NULL, PI_SVCCTL, 0, + return run_rpc_command( NULL, PI_SVCCTL, 0, rpc_service_pause_internal, argc, argv ); } @@ -518,7 +518,7 @@ static int rpc_service_pause( int argc, const char **argv ) static int rpc_service_status( int argc, const char **argv ) { - return run_rpc_command( NULL, PI_SVCCTL, 0, + return run_rpc_command( NULL, PI_SVCCTL, 0, rpc_service_status_internal, argc, argv ); } @@ -533,14 +533,14 @@ static int net_help_service( int argc, const char **argv ) d_printf("net rpc service pause Pause a service\n"); d_printf("net rpc service resume Resume a paused service\n"); d_printf("net rpc service status View the current status of a service\n"); - + return -1; } /******************************************************************** ********************************************************************/ -int net_rpc_service(int argc, const char **argv) +int net_rpc_service(int argc, const char **argv) { struct functable func[] = { {"list", rpc_service_list}, @@ -551,9 +551,9 @@ int net_rpc_service(int argc, const char **argv) {"status", rpc_service_status}, {NULL, NULL} }; - + if ( argc ) return net_run_function( argc, argv, func, net_help_service ); - + return net_help_service( argc, argv ); } -- cgit From 0ca295bb32d69711eb799d8f8323aa17e5928a10 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 18 Feb 2008 12:10:54 +0100 Subject: Use rpccli_svcctl_OpenSCManagerW() in net. Guenther (This used to be commit 275ce92e277c0d30cfa098e62674111c994aeb4c) --- source3/utils/net_rpc_service.c | 92 +++++++++++++++++++++++++++++++++-------- 1 file changed, 75 insertions(+), 17 deletions(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index 5ad907e8a6..789afe234f 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -20,6 +20,9 @@ #include "utils/net.h" +#define CLI_SERVER_NAME_SLASH(_ctx, _p, _cli) \ + _p = talloc_asprintf(_ctx, "\\\\%s", _cli->cli->desthost); + /******************************************************************** ********************************************************************/ @@ -149,9 +152,11 @@ static NTSTATUS rpc_service_list_internal(const DOM_SID *domain_sid, POLICY_HND hSCM; ENUM_SERVICES_STATUS *services; WERROR result = WERR_GENERAL_FAILURE; + NTSTATUS status; fstring servicename; fstring displayname; uint32 num_services = 0; + const char *server_name; int i; if (argc != 0 ) { @@ -159,8 +164,16 @@ static NTSTATUS rpc_service_list_internal(const DOM_SID *domain_sid, return NT_STATUS_OK; } - result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); - if ( !W_ERROR_IS_OK(result) ) { + CLI_SERVER_NAME_SLASH(mem_ctx, server_name, pipe_hnd); + NT_STATUS_HAVE_NO_MEMORY(server_name); + + status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx, + server_name, + NULL, + SC_RIGHT_MGR_ENUMERATE_SERVICE, + &hSCM, + &result); + if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) { d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } @@ -202,10 +215,12 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, { POLICY_HND hSCM, hService; WERROR result = WERR_GENERAL_FAILURE; + NTSTATUS status; fstring servicename; SERVICE_STATUS service_status; SERVICE_CONFIG config; fstring ascii_string; + const char *server_name; if (argc != 1 ) { d_printf("Usage: net rpc service status \n"); @@ -215,9 +230,16 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, fstrcpy( servicename, argv[0] ); /* Open the Service Control Manager */ - - result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); - if ( !W_ERROR_IS_OK(result) ) { + CLI_SERVER_NAME_SLASH(mem_ctx, server_name, pipe_hnd); + NT_STATUS_HAVE_NO_MEMORY(server_name); + + status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx, + server_name, + NULL, + SC_RIGHT_MGR_ENUMERATE_SERVICE, + &hSCM, + &result); + if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) { d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } @@ -304,7 +326,9 @@ static NTSTATUS rpc_service_stop_internal(const DOM_SID *domain_sid, { POLICY_HND hSCM; WERROR result = WERR_GENERAL_FAILURE; + NTSTATUS status; fstring servicename; + const char *server_name; if (argc != 1 ) { d_printf("Usage: net rpc service status \n"); @@ -314,9 +338,16 @@ static NTSTATUS rpc_service_stop_internal(const DOM_SID *domain_sid, fstrcpy( servicename, argv[0] ); /* Open the Service Control Manager */ - - result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); - if ( !W_ERROR_IS_OK(result) ) { + CLI_SERVER_NAME_SLASH(mem_ctx, server_name, pipe_hnd); + NT_STATUS_HAVE_NO_MEMORY(server_name); + + status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx, + server_name, + NULL, + SC_RIGHT_MGR_ENUMERATE_SERVICE, + &hSCM, + &result); + if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) { d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } @@ -342,7 +373,9 @@ static NTSTATUS rpc_service_pause_internal(const DOM_SID *domain_sid, { POLICY_HND hSCM; WERROR result = WERR_GENERAL_FAILURE; + NTSTATUS status; fstring servicename; + const char *server_name; if (argc != 1 ) { d_printf("Usage: net rpc service status \n"); @@ -352,9 +385,16 @@ static NTSTATUS rpc_service_pause_internal(const DOM_SID *domain_sid, fstrcpy( servicename, argv[0] ); /* Open the Service Control Manager */ - - result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); - if ( !W_ERROR_IS_OK(result) ) { + CLI_SERVER_NAME_SLASH(mem_ctx, server_name, pipe_hnd); + NT_STATUS_HAVE_NO_MEMORY(server_name); + + status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx, + server_name, + NULL, + SC_RIGHT_MGR_ENUMERATE_SERVICE, + &hSCM, + &result); + if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) { d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } @@ -380,7 +420,9 @@ static NTSTATUS rpc_service_resume_internal(const DOM_SID *domain_sid, { POLICY_HND hSCM; WERROR result = WERR_GENERAL_FAILURE; + NTSTATUS status; fstring servicename; + const char *server_name; if (argc != 1 ) { d_printf("Usage: net rpc service status \n"); @@ -390,9 +432,16 @@ static NTSTATUS rpc_service_resume_internal(const DOM_SID *domain_sid, fstrcpy( servicename, argv[0] ); /* Open the Service Control Manager */ - - result = rpccli_svcctl_open_scm(pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); - if ( !W_ERROR_IS_OK(result) ) { + CLI_SERVER_NAME_SLASH(mem_ctx, server_name, pipe_hnd); + NT_STATUS_HAVE_NO_MEMORY(server_name); + + status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx, + server_name, + NULL, + SC_RIGHT_MGR_ENUMERATE_SERVICE, + &hSCM, + &result); + if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) { d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } @@ -418,8 +467,10 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, { POLICY_HND hSCM, hService; WERROR result = WERR_GENERAL_FAILURE; + NTSTATUS status; fstring servicename; uint32 state = 0; + const char *server_name; if (argc != 1 ) { d_printf("Usage: net rpc service status \n"); @@ -429,9 +480,16 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, fstrcpy( servicename, argv[0] ); /* Open the Service Control Manager */ - - result = rpccli_svcctl_open_scm( pipe_hnd, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE ); - if ( !W_ERROR_IS_OK(result) ) { + CLI_SERVER_NAME_SLASH(mem_ctx, server_name, pipe_hnd); + NT_STATUS_HAVE_NO_MEMORY(server_name); + + status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx, + server_name, + NULL, + SC_RIGHT_MGR_ENUMERATE_SERVICE, + &hSCM, + &result); + if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result)) { d_fprintf(stderr, "Failed to open Service Control Manager. [%s]\n", dos_errstr(result)); return werror_to_ntstatus(result); } -- cgit From f40f80008d9a20d54c3a43b001929c3963c82d0a Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 18 Feb 2008 12:45:13 +0100 Subject: Use rpccli_svcctl_OpenServiceW() in net. Guenther (This used to be commit 1537a2ff36841fea7bd5d49283667dd02bae84b8) --- source3/utils/net_rpc_service.c | 57 ++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 23 deletions(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index 789afe234f..74848b23a4 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -35,13 +35,17 @@ static WERROR query_service_state(struct rpc_pipe_client *pipe_hnd, POLICY_HND hService; SERVICE_STATUS service_status; WERROR result = WERR_GENERAL_FAILURE; + NTSTATUS status; /* now cycle until the status is actually 'watch_state' */ - result = rpccli_svcctl_open_service(pipe_hnd, mem_ctx, hSCM, &hService, - service, SC_RIGHT_SVC_QUERY_STATUS ); - - if ( !W_ERROR_IS_OK(result) ) { + status = rpccli_svcctl_OpenServiceW(pipe_hnd, mem_ctx, + hSCM, + service, + SC_RIGHT_SVC_QUERY_STATUS, + &hService, + &result); + if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) { d_fprintf(stderr, "Failed to open service. [%s]\n", dos_errstr(result)); return result; } @@ -103,15 +107,20 @@ static WERROR control_service(struct rpc_pipe_client *pipe_hnd, { POLICY_HND hService; WERROR result = WERR_GENERAL_FAILURE; + NTSTATUS status; SERVICE_STATUS service_status; uint32 state = 0; /* Open the Service */ - result = rpccli_svcctl_open_service(pipe_hnd, mem_ctx, hSCM, &hService, - service, (SC_RIGHT_SVC_STOP|SC_RIGHT_SVC_PAUSE_CONTINUE) ); + status = rpccli_svcctl_OpenServiceW(pipe_hnd, mem_ctx, + hSCM, + service, + (SC_RIGHT_SVC_STOP|SC_RIGHT_SVC_PAUSE_CONTINUE), + &hService, + &result); - if ( !W_ERROR_IS_OK(result) ) { + if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) { d_fprintf(stderr, "Failed to open service. [%s]\n", dos_errstr(result)); goto done; } @@ -216,7 +225,6 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, POLICY_HND hSCM, hService; WERROR result = WERR_GENERAL_FAILURE; NTSTATUS status; - fstring servicename; SERVICE_STATUS service_status; SERVICE_CONFIG config; fstring ascii_string; @@ -227,8 +235,6 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, return NT_STATUS_OK; } - fstrcpy( servicename, argv[0] ); - /* Open the Service Control Manager */ CLI_SERVER_NAME_SLASH(mem_ctx, server_name, pipe_hnd); NT_STATUS_HAVE_NO_MEMORY(server_name); @@ -246,10 +252,14 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, /* Open the Service */ - result = rpccli_svcctl_open_service(pipe_hnd, mem_ctx, &hSCM, &hService, servicename, - (SC_RIGHT_SVC_QUERY_STATUS|SC_RIGHT_SVC_QUERY_CONFIG) ); + status = rpccli_svcctl_OpenServiceW(pipe_hnd, mem_ctx, + &hSCM, + argv[0], + (SC_RIGHT_SVC_QUERY_STATUS|SC_RIGHT_SVC_QUERY_CONFIG), + &hService, + &result); - if ( !W_ERROR_IS_OK(result) ) { + if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) { d_fprintf(stderr, "Failed to open service. [%s]\n", dos_errstr(result)); goto done; } @@ -262,7 +272,7 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, goto done; } - d_printf("%s service is %s.\n", servicename, svc_status_string(service_status.state)); + d_printf("%s service is %s.\n", argv[0], svc_status_string(service_status.state)); /* get the config */ @@ -468,7 +478,6 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, POLICY_HND hSCM, hService; WERROR result = WERR_GENERAL_FAILURE; NTSTATUS status; - fstring servicename; uint32 state = 0; const char *server_name; @@ -477,8 +486,6 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, return NT_STATUS_OK; } - fstrcpy( servicename, argv[0] ); - /* Open the Service Control Manager */ CLI_SERVER_NAME_SLASH(mem_ctx, server_name, pipe_hnd); NT_STATUS_HAVE_NO_MEMORY(server_name); @@ -496,10 +503,14 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, /* Open the Service */ - result = rpccli_svcctl_open_service(pipe_hnd, mem_ctx, &hSCM, &hService, - servicename, SC_RIGHT_SVC_START ); + status = rpccli_svcctl_OpenServiceW(pipe_hnd, mem_ctx, + &hSCM, + argv[0], + SC_RIGHT_SVC_START, + &hService, + &result); - if ( !W_ERROR_IS_OK(result) ) { + if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) { d_fprintf(stderr, "Failed to open service. [%s]\n", dos_errstr(result)); goto done; } @@ -512,12 +523,12 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, goto done; } - result = watch_service_state(pipe_hnd, mem_ctx, &hSCM, servicename, SVCCTL_RUNNING, &state ); + result = watch_service_state(pipe_hnd, mem_ctx, &hSCM, argv[0], SVCCTL_RUNNING, &state ); if ( W_ERROR_IS_OK(result) && (state == SVCCTL_RUNNING) ) - d_printf("Successfully started service: %s\n", servicename ); + d_printf("Successfully started service: %s\n", argv[0] ); else - d_fprintf(stderr, "Failed to start service: %s [%s]\n", servicename, dos_errstr(result) ); + d_fprintf(stderr, "Failed to start service: %s [%s]\n", argv[0], dos_errstr(result) ); done: rpccli_svcctl_CloseServiceHandle(pipe_hnd, mem_ctx, &hService, NULL); -- cgit From cea7718db8defbf418f06b78a20ff57750b5346f Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 19 Feb 2008 02:29:16 +0100 Subject: Use rpccli_svcctl_StartServiceW() in net. Guenther (This used to be commit 5ca4358c1a2c13b316df7cc07d8ca5b820c79988) --- source3/utils/net_rpc_service.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index 74848b23a4..77e2ee4ac3 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -517,8 +517,13 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, /* get the status */ - result = rpccli_svcctl_start_service(pipe_hnd, mem_ctx, &hService, NULL, 0 ); - if ( !W_ERROR_IS_OK(result) ) { + status = rpccli_svcctl_StartServiceW(pipe_hnd, mem_ctx, + &hService, + 0, + NULL, + &result); + + if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) { d_fprintf(stderr, "Query status request failed. [%s]\n", dos_errstr(result)); goto done; } -- cgit From 87bccd70caa6521fbbf6aa603ffff3ce30d8133d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 19 Feb 2008 02:37:12 +0100 Subject: Use rpccli_svcctl_ControlService() in net. Guenther (This used to be commit 49375f0b4d5ead7d26659cfc94997bd3e18c48a9) --- source3/utils/net_rpc_service.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index 77e2ee4ac3..3c22bfe381 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -127,10 +127,13 @@ static WERROR control_service(struct rpc_pipe_client *pipe_hnd, /* get the status */ - result = rpccli_svcctl_control_service(pipe_hnd, mem_ctx, &hService, - control, &service_status ); + status = rpccli_svcctl_ControlService(pipe_hnd, mem_ctx, + &hService, + control, + &service_status, + &result); - if ( !W_ERROR_IS_OK(result) ) { + if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) { d_fprintf(stderr, "Control service request failed. [%s]\n", dos_errstr(result)); goto done; } -- cgit From 3c3944ee3850398a8d1349143aef53cdee44cdf4 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 19 Feb 2008 02:43:04 +0100 Subject: Use rpccli_svcctl_QueryServiceStatus() in net. Guenther (This used to be commit 1cc0e9b7e5b8685dc4aff8e379837dd32e386f9f) --- source3/utils/net_rpc_service.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index 3c22bfe381..242d653017 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -50,8 +50,12 @@ static WERROR query_service_state(struct rpc_pipe_client *pipe_hnd, return result; } - result = rpccli_svcctl_query_status(pipe_hnd, mem_ctx, &hService, &service_status ); - if ( W_ERROR_IS_OK(result) ) { + status = rpccli_svcctl_QueryServiceStatus(pipe_hnd, mem_ctx, + &hService, + &service_status, + &result); + + if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) { *state = service_status.state; } @@ -269,8 +273,12 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, /* get the status */ - result = rpccli_svcctl_query_status(pipe_hnd, mem_ctx, &hService, &service_status ); - if ( !W_ERROR_IS_OK(result) ) { + status = rpccli_svcctl_QueryServiceStatus(pipe_hnd, mem_ctx, + &hService, + &service_status, + &result); + + if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(result) ) { d_fprintf(stderr, "Query status request failed. [%s]\n", dos_errstr(result)); goto done; } -- cgit From 2ee645121295cc416cc190c0d14a1e739ad6fb6d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 20 Mar 2008 01:24:55 +0100 Subject: No need to compose CLI_SERVER_NAME_SLASH in "net rpc service" anymore. Guenther (This used to be commit b5291d477381521cd4b71674616f8c9899007002) --- source3/utils/net_rpc_service.c | 40 ++++++---------------------------------- 1 file changed, 6 insertions(+), 34 deletions(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index 242d653017..c4cc19eaa1 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -19,10 +19,6 @@ #include "includes.h" #include "utils/net.h" - -#define CLI_SERVER_NAME_SLASH(_ctx, _p, _cli) \ - _p = talloc_asprintf(_ctx, "\\\\%s", _cli->cli->desthost); - /******************************************************************** ********************************************************************/ @@ -172,7 +168,6 @@ static NTSTATUS rpc_service_list_internal(const DOM_SID *domain_sid, fstring servicename; fstring displayname; uint32 num_services = 0; - const char *server_name; int i; if (argc != 0 ) { @@ -180,11 +175,8 @@ static NTSTATUS rpc_service_list_internal(const DOM_SID *domain_sid, return NT_STATUS_OK; } - CLI_SERVER_NAME_SLASH(mem_ctx, server_name, pipe_hnd); - NT_STATUS_HAVE_NO_MEMORY(server_name); - status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx, - server_name, + pipe_hnd->cli->srv_name_slash, NULL, SC_RIGHT_MGR_ENUMERATE_SERVICE, &hSCM, @@ -235,7 +227,6 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, SERVICE_STATUS service_status; SERVICE_CONFIG config; fstring ascii_string; - const char *server_name; if (argc != 1 ) { d_printf("Usage: net rpc service status \n"); @@ -243,11 +234,8 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, } /* Open the Service Control Manager */ - CLI_SERVER_NAME_SLASH(mem_ctx, server_name, pipe_hnd); - NT_STATUS_HAVE_NO_MEMORY(server_name); - status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx, - server_name, + pipe_hnd->cli->srv_name_slash, NULL, SC_RIGHT_MGR_ENUMERATE_SERVICE, &hSCM, @@ -349,7 +337,6 @@ static NTSTATUS rpc_service_stop_internal(const DOM_SID *domain_sid, WERROR result = WERR_GENERAL_FAILURE; NTSTATUS status; fstring servicename; - const char *server_name; if (argc != 1 ) { d_printf("Usage: net rpc service status \n"); @@ -359,11 +346,8 @@ static NTSTATUS rpc_service_stop_internal(const DOM_SID *domain_sid, fstrcpy( servicename, argv[0] ); /* Open the Service Control Manager */ - CLI_SERVER_NAME_SLASH(mem_ctx, server_name, pipe_hnd); - NT_STATUS_HAVE_NO_MEMORY(server_name); - status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx, - server_name, + pipe_hnd->cli->srv_name_slash, NULL, SC_RIGHT_MGR_ENUMERATE_SERVICE, &hSCM, @@ -396,7 +380,6 @@ static NTSTATUS rpc_service_pause_internal(const DOM_SID *domain_sid, WERROR result = WERR_GENERAL_FAILURE; NTSTATUS status; fstring servicename; - const char *server_name; if (argc != 1 ) { d_printf("Usage: net rpc service status \n"); @@ -406,11 +389,8 @@ static NTSTATUS rpc_service_pause_internal(const DOM_SID *domain_sid, fstrcpy( servicename, argv[0] ); /* Open the Service Control Manager */ - CLI_SERVER_NAME_SLASH(mem_ctx, server_name, pipe_hnd); - NT_STATUS_HAVE_NO_MEMORY(server_name); - status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx, - server_name, + pipe_hnd->cli->srv_name_slash, NULL, SC_RIGHT_MGR_ENUMERATE_SERVICE, &hSCM, @@ -443,7 +423,6 @@ static NTSTATUS rpc_service_resume_internal(const DOM_SID *domain_sid, WERROR result = WERR_GENERAL_FAILURE; NTSTATUS status; fstring servicename; - const char *server_name; if (argc != 1 ) { d_printf("Usage: net rpc service status \n"); @@ -453,11 +432,8 @@ static NTSTATUS rpc_service_resume_internal(const DOM_SID *domain_sid, fstrcpy( servicename, argv[0] ); /* Open the Service Control Manager */ - CLI_SERVER_NAME_SLASH(mem_ctx, server_name, pipe_hnd); - NT_STATUS_HAVE_NO_MEMORY(server_name); - status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx, - server_name, + pipe_hnd->cli->srv_name_slash, NULL, SC_RIGHT_MGR_ENUMERATE_SERVICE, &hSCM, @@ -490,7 +466,6 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, WERROR result = WERR_GENERAL_FAILURE; NTSTATUS status; uint32 state = 0; - const char *server_name; if (argc != 1 ) { d_printf("Usage: net rpc service status \n"); @@ -498,11 +473,8 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, } /* Open the Service Control Manager */ - CLI_SERVER_NAME_SLASH(mem_ctx, server_name, pipe_hnd); - NT_STATUS_HAVE_NO_MEMORY(server_name); - status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx, - server_name, + pipe_hnd->cli->srv_name_slash, NULL, SC_RIGHT_MGR_ENUMERATE_SERVICE, &hSCM, -- cgit From d8acf199876867189f212837059d1d6ac401c6b5 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 20 Mar 2008 01:26:37 +0100 Subject: Move svc_status_string() out of rpc_client/cli_svcctl.c Guenther (This used to be commit 2860ae2eb2cb99b4febb352f516b3fa9fbd2abbb) --- source3/utils/net_rpc_service.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index c4cc19eaa1..1b12bd3114 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -19,6 +19,43 @@ #include "includes.h" #include "utils/net.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 ) +{ + 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; + } + } + + return talloc_strdup(talloc_tos(), msg); +} + /******************************************************************** ********************************************************************/ -- cgit From 9048cafbeaf82d1916de6538024fd660612dd25f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 19 Apr 2008 23:03:16 +0200 Subject: Move srv_name_slash from cli_state to rpc_pipe_client (This used to be commit a9061e52e1ff8e31aa480f4a30cda64c9d93214e) --- source3/utils/net_rpc_service.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index 1b12bd3114..b886283adc 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -213,7 +213,7 @@ static NTSTATUS rpc_service_list_internal(const DOM_SID *domain_sid, } status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx, - pipe_hnd->cli->srv_name_slash, + pipe_hnd->srv_name_slash, NULL, SC_RIGHT_MGR_ENUMERATE_SERVICE, &hSCM, @@ -272,7 +272,7 @@ static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, /* Open the Service Control Manager */ status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx, - pipe_hnd->cli->srv_name_slash, + pipe_hnd->srv_name_slash, NULL, SC_RIGHT_MGR_ENUMERATE_SERVICE, &hSCM, @@ -384,7 +384,7 @@ static NTSTATUS rpc_service_stop_internal(const DOM_SID *domain_sid, /* Open the Service Control Manager */ status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx, - pipe_hnd->cli->srv_name_slash, + pipe_hnd->srv_name_slash, NULL, SC_RIGHT_MGR_ENUMERATE_SERVICE, &hSCM, @@ -427,7 +427,7 @@ static NTSTATUS rpc_service_pause_internal(const DOM_SID *domain_sid, /* Open the Service Control Manager */ status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx, - pipe_hnd->cli->srv_name_slash, + pipe_hnd->srv_name_slash, NULL, SC_RIGHT_MGR_ENUMERATE_SERVICE, &hSCM, @@ -470,7 +470,7 @@ static NTSTATUS rpc_service_resume_internal(const DOM_SID *domain_sid, /* Open the Service Control Manager */ status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx, - pipe_hnd->cli->srv_name_slash, + pipe_hnd->srv_name_slash, NULL, SC_RIGHT_MGR_ENUMERATE_SERVICE, &hSCM, @@ -511,7 +511,7 @@ static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, /* Open the Service Control Manager */ status = rpccli_svcctl_OpenSCManagerW(pipe_hnd, mem_ctx, - pipe_hnd->cli->srv_name_slash, + pipe_hnd->srv_name_slash, NULL, SC_RIGHT_MGR_ENUMERATE_SERVICE, &hSCM, -- cgit From f5769109447d8da0f09b102d444a816ad97a00dc Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Fri, 9 May 2008 23:22:12 +0200 Subject: net: Remove globals (This used to be commit 1e9319cf88b65a2a8d4f5099a1fe5297e405ed2e) --- source3/utils/net_rpc_service.c | 50 +++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 22 deletions(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index b886283adc..05279aea1a 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -190,7 +190,8 @@ done: /******************************************************************** ********************************************************************/ -static NTSTATUS rpc_service_list_internal(const DOM_SID *domain_sid, +static NTSTATUS rpc_service_list_internal(struct net_context *c, + const DOM_SID *domain_sid, const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, @@ -250,7 +251,8 @@ done: /******************************************************************** ********************************************************************/ -static NTSTATUS rpc_service_status_internal(const DOM_SID *domain_sid, +static NTSTATUS rpc_service_status_internal(struct net_context *c, + const DOM_SID *domain_sid, const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, @@ -362,7 +364,8 @@ done: /******************************************************************** ********************************************************************/ -static NTSTATUS rpc_service_stop_internal(const DOM_SID *domain_sid, +static NTSTATUS rpc_service_stop_internal(struct net_context *c, + const DOM_SID *domain_sid, const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, @@ -405,7 +408,8 @@ static NTSTATUS rpc_service_stop_internal(const DOM_SID *domain_sid, /******************************************************************** ********************************************************************/ -static NTSTATUS rpc_service_pause_internal(const DOM_SID *domain_sid, +static NTSTATUS rpc_service_pause_internal(struct net_context *c, + const DOM_SID *domain_sid, const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, @@ -448,7 +452,8 @@ static NTSTATUS rpc_service_pause_internal(const DOM_SID *domain_sid, /******************************************************************** ********************************************************************/ -static NTSTATUS rpc_service_resume_internal(const DOM_SID *domain_sid, +static NTSTATUS rpc_service_resume_internal(struct net_context *c, + const DOM_SID *domain_sid, const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, @@ -491,7 +496,8 @@ static NTSTATUS rpc_service_resume_internal(const DOM_SID *domain_sid, /******************************************************************** ********************************************************************/ -static NTSTATUS rpc_service_start_internal(const DOM_SID *domain_sid, +static NTSTATUS rpc_service_start_internal(struct net_context *c, + const DOM_SID *domain_sid, const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, @@ -565,61 +571,61 @@ done: /******************************************************************** ********************************************************************/ -static int rpc_service_list( int argc, const char **argv ) +static int rpc_service_list(struct net_context *c, int argc, const char **argv ) { - return run_rpc_command( NULL, PI_SVCCTL, 0, + return run_rpc_command(c, NULL, PI_SVCCTL, 0, rpc_service_list_internal, argc, argv ); } /******************************************************************** ********************************************************************/ -static int rpc_service_start( int argc, const char **argv ) +static int rpc_service_start(struct net_context *c, int argc, const char **argv ) { - return run_rpc_command( NULL, PI_SVCCTL, 0, + return run_rpc_command(c, NULL, PI_SVCCTL, 0, rpc_service_start_internal, argc, argv ); } /******************************************************************** ********************************************************************/ -static int rpc_service_stop( int argc, const char **argv ) +static int rpc_service_stop(struct net_context *c, int argc, const char **argv ) { - return run_rpc_command( NULL, PI_SVCCTL, 0, + return run_rpc_command(c, NULL, PI_SVCCTL, 0, rpc_service_stop_internal, argc, argv ); } /******************************************************************** ********************************************************************/ -static int rpc_service_resume( int argc, const char **argv ) +static int rpc_service_resume(struct net_context *c, int argc, const char **argv ) { - return run_rpc_command( NULL, PI_SVCCTL, 0, + return run_rpc_command(c, NULL, PI_SVCCTL, 0, rpc_service_resume_internal, argc, argv ); } /******************************************************************** ********************************************************************/ -static int rpc_service_pause( int argc, const char **argv ) +static int rpc_service_pause(struct net_context *c, int argc, const char **argv ) { - return run_rpc_command( NULL, PI_SVCCTL, 0, + return run_rpc_command(c, NULL, PI_SVCCTL, 0, rpc_service_pause_internal, argc, argv ); } /******************************************************************** ********************************************************************/ -static int rpc_service_status( int argc, const char **argv ) +static int rpc_service_status(struct net_context *c, int argc, const char **argv ) { - return run_rpc_command( NULL, PI_SVCCTL, 0, + return run_rpc_command(c, NULL, PI_SVCCTL, 0, rpc_service_status_internal, argc, argv ); } /******************************************************************** ********************************************************************/ -static int net_help_service( int argc, const char **argv ) +static int net_help_service(struct net_context *c, int argc, const char **argv ) { d_printf("net rpc service list View configured Win32 services\n"); d_printf("net rpc service start Start a service\n"); @@ -634,7 +640,7 @@ static int net_help_service( int argc, const char **argv ) /******************************************************************** ********************************************************************/ -int net_rpc_service(int argc, const char **argv) +int net_rpc_service(struct net_context *c, int argc, const char **argv) { struct functable func[] = { {"list", rpc_service_list}, @@ -647,7 +653,7 @@ int net_rpc_service(int argc, const char **argv) }; if ( argc ) - return net_run_function( argc, argv, func, net_help_service ); + return net_run_function(c, argc, argv, func, net_help_service ); - return net_help_service( argc, argv ); + return net_help_service(c, argc, argv ); } -- cgit From e0f2f8d57ee8628ca438176444291649852ab85d Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Wed, 21 May 2008 10:37:10 +0200 Subject: net: Make "net rpc service" use functable3 (This used to be commit aa06cd5cb2c72cc6c883bbfafe43546accce00a1) --- source3/utils/net_rpc_service.c | 120 +++++++++++++++++++++++++++++++--------- 1 file changed, 93 insertions(+), 27 deletions(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index 05279aea1a..8a725598c0 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -573,6 +573,13 @@ done: static int rpc_service_list(struct net_context *c, int argc, const char **argv ) { + if (c->display_usage) { + d_printf("Usage:\n" + "net rpc service list\n" + " View configured Win32 services\n"); + return 0; + } + return run_rpc_command(c, NULL, PI_SVCCTL, 0, rpc_service_list_internal, argc, argv ); } @@ -582,6 +589,13 @@ static int rpc_service_list(struct net_context *c, int argc, const char **argv ) static int rpc_service_start(struct net_context *c, int argc, const char **argv ) { + if (c->display_usage) { + d_printf("Usage:\n" + "net rpc service start \n" + " Start a Win32 service\n"); + return 0; + } + return run_rpc_command(c, NULL, PI_SVCCTL, 0, rpc_service_start_internal, argc, argv ); } @@ -591,6 +605,13 @@ static int rpc_service_start(struct net_context *c, int argc, const char **argv static int rpc_service_stop(struct net_context *c, int argc, const char **argv ) { + if (c->display_usage) { + d_printf("Usage:\n" + "net rpc service stop \n" + " Stop a Win32 service\n"); + return 0; + } + return run_rpc_command(c, NULL, PI_SVCCTL, 0, rpc_service_stop_internal, argc, argv ); } @@ -600,6 +621,13 @@ static int rpc_service_stop(struct net_context *c, int argc, const char **argv ) static int rpc_service_resume(struct net_context *c, int argc, const char **argv ) { + if (c->display_usage) { + d_printf("Usage:\n" + "net rpc service resume \n" + " Resume a Win32 service\n"); + return 0; + } + return run_rpc_command(c, NULL, PI_SVCCTL, 0, rpc_service_resume_internal, argc, argv ); } @@ -609,6 +637,13 @@ static int rpc_service_resume(struct net_context *c, int argc, const char **argv static int rpc_service_pause(struct net_context *c, int argc, const char **argv ) { + if (c->display_usage) { + d_printf("Usage:\n" + "net rpc service pause \n" + " Pause a Win32 service\n"); + return 0; + } + return run_rpc_command(c, NULL, PI_SVCCTL, 0, rpc_service_pause_internal, argc, argv ); } @@ -618,6 +653,13 @@ static int rpc_service_pause(struct net_context *c, int argc, const char **argv static int rpc_service_status(struct net_context *c, int argc, const char **argv ) { + if (c->display_usage) { + d_printf("Usage:\n" + "net rpc service status \n" + " Show the current status of a service\n"); + return 0; + } + return run_rpc_command(c, NULL, PI_SVCCTL, 0, rpc_service_status_internal, argc, argv ); } @@ -625,35 +667,59 @@ static int rpc_service_status(struct net_context *c, int argc, const char **argv /******************************************************************** ********************************************************************/ -static int net_help_service(struct net_context *c, int argc, const char **argv ) -{ - d_printf("net rpc service list View configured Win32 services\n"); - d_printf("net rpc service start Start a service\n"); - d_printf("net rpc service stop Stop a service\n"); - d_printf("net rpc service pause Pause a service\n"); - d_printf("net rpc service resume Resume a paused service\n"); - d_printf("net rpc service status View the current status of a service\n"); - - return -1; -} - -/******************************************************************** -********************************************************************/ - int net_rpc_service(struct net_context *c, int argc, const char **argv) { - struct functable func[] = { - {"list", rpc_service_list}, - {"start", rpc_service_start}, - {"stop", rpc_service_stop}, - {"pause", rpc_service_pause}, - {"resume", rpc_service_resume}, - {"status", rpc_service_status}, - {NULL, NULL} + struct functable3 func[] = { + { + "list", + rpc_service_list, + NET_TRANSPORT_RPC, + "View configured Win32 services", + "net rpc service list\n" + " View configured Win32 services" + }, + { + "start", + rpc_service_start, + NET_TRANSPORT_RPC, + "Start a service", + "net rpc service start\n" + " Start a service" + }, + { + "stop", + rpc_service_stop, + NET_TRANSPORT_RPC, + "Stop a service", + "net rpc service stop\n" + " Stop a service" + }, + { + "pause", + rpc_service_pause, + NET_TRANSPORT_RPC, + "Pause a service", + "net rpc service pause\n" + " Pause a service" + }, + { + "resume", + rpc_service_resume, + NET_TRANSPORT_RPC, + "Resume a paused service", + "net rpc service resume\n" + " Resume a service" + }, + { + "status", + rpc_service_status, + NET_TRANSPORT_RPC, + "View current status of a service", + "net rpc service status\n" + " View current status of a service" + }, + {NULL, NULL, 0, NULL, NULL} }; - if ( argc ) - return net_run_function(c, argc, argv, func, net_help_service ); - - return net_help_service(c, argc, argv ); + return net_run_function3(c, argc, argv, "net rpc service",func); } -- cgit From 255bdb26025a5025bc60637dd924f6ec71c49ee5 Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Sat, 7 Jun 2008 02:25:08 +0200 Subject: net: Rename functable3 to functable, get rid of old functables (This used to be commit bb7c5fc4ec77db4073d3beccf12af12910b6bd07) --- source3/utils/net_rpc_service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index 8a725598c0..5842c800c3 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -669,7 +669,7 @@ static int rpc_service_status(struct net_context *c, int argc, const char **argv int net_rpc_service(struct net_context *c, int argc, const char **argv) { - struct functable3 func[] = { + struct functable func[] = { { "list", rpc_service_list, @@ -721,5 +721,5 @@ int net_rpc_service(struct net_context *c, int argc, const char **argv) {NULL, NULL, 0, NULL, NULL} }; - return net_run_function3(c, argc, argv, "net rpc service",func); + return net_run_function(c, argc, argv, "net rpc service",func); } -- cgit From f23567fcb9d626c29603430a9cedd899e56ded32 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 20 Jul 2008 18:36:31 +0200 Subject: Refactoring: run_rpc_command uses ndr_syntax_id instead of pipe_idx (This used to be commit 850166ec0d17eb85a0c921dc3b966fac0677af4a) --- source3/utils/net_rpc_service.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/utils/net_rpc_service.c') diff --git a/source3/utils/net_rpc_service.c b/source3/utils/net_rpc_service.c index 5842c800c3..d1349a903d 100644 --- a/source3/utils/net_rpc_service.c +++ b/source3/utils/net_rpc_service.c @@ -580,7 +580,7 @@ static int rpc_service_list(struct net_context *c, int argc, const char **argv ) return 0; } - return run_rpc_command(c, NULL, PI_SVCCTL, 0, + return run_rpc_command(c, NULL, &ndr_table_svcctl.syntax_id, 0, rpc_service_list_internal, argc, argv ); } @@ -596,7 +596,7 @@ static int rpc_service_start(struct net_context *c, int argc, const char **argv return 0; } - return run_rpc_command(c, NULL, PI_SVCCTL, 0, + return run_rpc_command(c, NULL, &ndr_table_svcctl.syntax_id, 0, rpc_service_start_internal, argc, argv ); } @@ -612,7 +612,7 @@ static int rpc_service_stop(struct net_context *c, int argc, const char **argv ) return 0; } - return run_rpc_command(c, NULL, PI_SVCCTL, 0, + return run_rpc_command(c, NULL, &ndr_table_svcctl.syntax_id, 0, rpc_service_stop_internal, argc, argv ); } @@ -628,7 +628,7 @@ static int rpc_service_resume(struct net_context *c, int argc, const char **argv return 0; } - return run_rpc_command(c, NULL, PI_SVCCTL, 0, + return run_rpc_command(c, NULL, &ndr_table_svcctl.syntax_id, 0, rpc_service_resume_internal, argc, argv ); } @@ -644,7 +644,7 @@ static int rpc_service_pause(struct net_context *c, int argc, const char **argv return 0; } - return run_rpc_command(c, NULL, PI_SVCCTL, 0, + return run_rpc_command(c, NULL, &ndr_table_svcctl.syntax_id, 0, rpc_service_pause_internal, argc, argv ); } @@ -660,7 +660,7 @@ static int rpc_service_status(struct net_context *c, int argc, const char **argv return 0; } - return run_rpc_command(c, NULL, PI_SVCCTL, 0, + return run_rpc_command(c, NULL, &ndr_table_svcctl.syntax_id, 0, rpc_service_status_internal, argc, argv ); } -- cgit