r6041: cleaning up output from 'rpc service list'
[Samba/gbeck.git] / source / utils / net_rpc_service.c
blobd3343e92ad8229fc3eb9c09e3a2878d426af4947
1 /*
2 Samba Unix/Linux SMB client library
3 Distributed SMB/CIFS Server Management Utility
4 Copyright (C) Gerald (Jerry) Carter 2005
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20 #include "includes.h"
21 #include "utils/net.h"
23 /********************************************************************
24 ********************************************************************/
26 static NTSTATUS rpc_service_list_internal( const DOM_SID *domain_sid, const char *domain_name,
27 struct cli_state *cli, TALLOC_CTX *mem_ctx,
28 int argc, const char **argv )
30 POLICY_HND hSCM;
31 ENUM_SERVICES_STATUS *services;
32 WERROR result = WERR_GENERAL_FAILURE;
33 fstring servicename;
34 fstring displayname;
35 uint32 num_services = 0;
36 int i;
38 if (argc != 0 ) {
39 d_printf("Usage: net rpc service list\n");
40 return NT_STATUS_OK;
43 result = cli_svcctl_open_scm( cli, mem_ctx, &hSCM, SC_RIGHT_MGR_ENUMERATE_SERVICE );
44 if ( !W_ERROR_IS_OK(result) ) {
45 d_printf("Failed to open Service Control Manager. [%s]\n", dos_errstr(result));
46 return werror_to_ntstatus(result);
49 result = cli_svcctl_enumerate_services( cli, mem_ctx, &hSCM, SVCCTL_TYPE_WIN32,
50 SVCCTL_STATE_ALL, &num_services, &services );
52 if ( !W_ERROR_IS_OK(result) ) {
53 d_printf("Failed to enumerate services. [%s]\n", dos_errstr(result));
54 goto done;
57 if ( num_services == 0 )
58 d_printf("No services returned\n");
60 for ( i=0; i<num_services; i++ ) {
61 rpcstr_pull( servicename, services[i].servicename.buffer, sizeof(servicename), -1, STR_TERMINATE );
62 rpcstr_pull( displayname, services[i].displayname.buffer, sizeof(displayname), -1, STR_TERMINATE );
64 d_printf("%-20s \"%s\"\n", servicename, displayname);
67 done:
68 close_service_handle( cli, mem_ctx, &hSCM );
70 return werror_to_ntstatus(result);
74 /********************************************************************
75 ********************************************************************/
77 static int rpc_service_list( int argc, const char **argv )
79 return run_rpc_command( NULL, PI_SVCCTL, 0,
80 rpc_service_list_internal, argc, argv );
83 /********************************************************************
84 ********************************************************************/
86 static int rpc_service_start( int argc, const char **argv )
88 d_printf("not implemented\n");
89 return 0;
92 /********************************************************************
93 ********************************************************************/
95 static int rpc_service_stop( int argc, const char **argv )
97 d_printf("not implemented\n");
98 return 0;
101 /********************************************************************
102 ********************************************************************/
104 static int rpc_service_pause( int argc, const char **argv )
106 d_printf("not implemented\n");
107 return 0;
110 /********************************************************************
111 ********************************************************************/
113 static int rpc_service_status( int argc, const char **argv )
115 d_printf("not implemented\n");
116 return 0;
119 /********************************************************************
120 ********************************************************************/
122 static int net_help_service( int argc, const char **argv )
124 d_printf("net rpc service list View configured Win32 services\n");
125 d_printf("net rpc service start <service> Start a service\n");
126 d_printf("net rpc service stop <service> Stop a service\n");
127 d_printf("net rpc service pause <service> Pause a service\n");
128 d_printf("net rpc service status <service> View the current status of a service\n");
130 return -1;
133 /********************************************************************
134 ********************************************************************/
136 int net_rpc_service(int argc, const char **argv)
138 struct functable func[] = {
139 {"list", rpc_service_list},
140 {"start", rpc_service_start},
141 {"stop", rpc_service_stop},
142 {"pause", rpc_service_pause},
143 {"status", rpc_service_status},
144 {NULL, NULL}
147 if ( argc )
148 return net_run_function( argc, argv, func, net_help_service );
150 return net_help_service( argc, argv );