svn commit: samba r6040 - in branches/SAMBA_3_0/source: include nsswitch rpc_client utils

jerry at samba.org jerry at samba.org
Thu Mar 24 18:05:31 GMT 2005


Author: jerry
Date: 2005-03-24 18:05:31 +0000 (Thu, 24 Mar 2005)
New Revision: 6040

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=6040

Log:
finish out 'net rpc service list'
Modified:
   branches/SAMBA_3_0/source/include/rpc_client.h
   branches/SAMBA_3_0/source/include/rpc_svcctl.h
   branches/SAMBA_3_0/source/nsswitch/winbindd.h
   branches/SAMBA_3_0/source/rpc_client/cli_svcctl.c
   branches/SAMBA_3_0/source/utils/net_rpc_service.c


Changeset:
Modified: branches/SAMBA_3_0/source/include/rpc_client.h
===================================================================
--- branches/SAMBA_3_0/source/include/rpc_client.h	2005-03-24 17:11:51 UTC (rev 6039)
+++ branches/SAMBA_3_0/source/include/rpc_client.h	2005-03-24 18:05:31 UTC (rev 6040)
@@ -1,7 +1,7 @@
 /* 
    Unix SMB/CIFS implementation.
    SMB parameters and setup
-   Copyright (C) Elrond                            2000
+   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
@@ -21,8 +21,21 @@
 #ifndef _RPC_CLIENT_H
 #define _RPC_CLIENT_H
 
-#if 0	/* JERRY */
-#include "rpc_client_proto.h"
-#endif 
+/* macro to expand cookie-cutter code in cli_xxx() */
+		   
+#define CLI_DO_RPC( pcli, ctx, pipe_num, opnum, q_in, r_out, q_ps, r_ps, q_io_fn, r_io_fn, default_error) \
+{	r_out.status = default_error;\
+	prs_init( &q_ps, MAX_PDU_FRAG_LEN, ctx, MARSHALL ); \
+	prs_init( &r_ps, 0, ctx, UNMARSHALL );\
+	if ( q_io_fn("", &q_in, &q_ps, 0) ) {\
+		if ( rpc_api_pipe_req(pcli, pipe_num, opnum, &q_ps, &r_ps) ) {\
+			if (!r_io_fn("", &r_out, &r_ps, 0)) {\
+				r_out.status = default_error;\
+			}\
+		}\
+	}\
+	prs_mem_free( &q_ps );\
+	prs_mem_free( &r_ps );\
+}
 
 #endif /* _RPC_CLIENT_H */

Modified: branches/SAMBA_3_0/source/include/rpc_svcctl.h
===================================================================
--- branches/SAMBA_3_0/source/include/rpc_svcctl.h	2005-03-24 17:11:51 UTC (rev 6039)
+++ branches/SAMBA_3_0/source/include/rpc_svcctl.h	2005-03-24 18:05:31 UTC (rev 6040)
@@ -50,7 +50,7 @@
 /* SERVER_STATUS - state */
 #define SVCCTL_STATE_ACTIVE		0x00000001
 #define SVCCTL_STATE_INACTIVE		0x00000002
-#define SVCCTL_STATE_ALL		( SVC_STATE_ACTIVE | SVC_STATE_INACTIVE )
+#define SVCCTL_STATE_ALL		( SVCCTL_STATE_ACTIVE | SVCCTL_STATE_INACTIVE )
 
 /* SERVER_STATUS - CurrentState */
 

Modified: branches/SAMBA_3_0/source/nsswitch/winbindd.h
===================================================================
--- branches/SAMBA_3_0/source/nsswitch/winbindd.h	2005-03-24 17:11:51 UTC (rev 6039)
+++ branches/SAMBA_3_0/source/nsswitch/winbindd.h	2005-03-24 18:05:31 UTC (rev 6040)
@@ -245,7 +245,6 @@
 #include "nsswitch/winbindd_proto.h"
 
 #include "rpc_parse.h"
-#include "rpc_client.h"
 
 #define WINBINDD_ESTABLISH_LOOP 30
 #define WINBINDD_RESCAN_FREQ 300

Modified: branches/SAMBA_3_0/source/rpc_client/cli_svcctl.c
===================================================================
--- branches/SAMBA_3_0/source/rpc_client/cli_svcctl.c	2005-03-24 17:11:51 UTC (rev 6039)
+++ branches/SAMBA_3_0/source/rpc_client/cli_svcctl.c	2005-03-24 18:05:31 UTC (rev 6040)
@@ -20,25 +20,8 @@
 
 
 #include "includes.h"
-	
-/* macro to expand cookie-cutter code */
-		   
-#define CLI_DO_RPC( cli, mem_ctx, pipe_num, opnum, in, out, qbuf, rbuf, q_io_fn, r_io_fn, default_error) \
-{	out.status = default_error;\
-	prs_init( &qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL ); \
-	prs_init( &rbuf, 0, mem_ctx, UNMARSHALL );\
-	if ( q_io_fn("", &in, &qbuf, 0) ) {\
-		if ( rpc_api_pipe_req(cli, pipe_num, opnum, &qbuf, &rbuf) ) {\
-			if (!r_io_fn("", &out, &rbuf, 0)) {\
-				out.status = default_error;\
-			}\
-		}\
-	}\
-	prs_mem_free( &qbuf );\
-	prs_mem_free( &rbuf );\
-}
+#include "rpc_client.h"
 
-
 /********************************************************************
 ********************************************************************/
 
@@ -110,14 +93,28 @@
 
 WERROR cli_svcctl_enumerate_services( struct cli_state *cli, TALLOC_CTX *mem_ctx,
                                       POLICY_HND *hSCM, uint32 type, uint32 state, 
-				      uint32 *resume, uint32 returned  )
+				      uint32 *returned, ENUM_SERVICES_STATUS **service_array  )
 {
 	SVCCTL_Q_ENUM_SERVICES_STATUS in;
 	SVCCTL_R_ENUM_SERVICES_STATUS out;
 	prs_struct qbuf, rbuf;
+	uint32 resume = 0;
+	ENUM_SERVICES_STATUS *services;
+	int i;
 
 	ZERO_STRUCT(in);
 	ZERO_STRUCT(out);
+	
+	/* setup the request */
+	
+	memcpy( &in.handle, hSCM, sizeof(POLICY_HND) );
+	
+	in.type        = type;
+	in.state       = state;
+	in.resume      = &resume;
+	
+	/* first time is to get the buffer size */
+	in.buffer_size = 0;
 
 	CLI_DO_RPC( cli, mem_ctx, PI_SVCCTL, SVCCTL_ENUM_SERVICES_STATUS_W, 
 	            in, out, 
@@ -126,8 +123,34 @@
 	            svcctl_io_r_enum_services_status, 
 	            WERR_GENERAL_FAILURE );
 
+	/* second time with correct buffer size...should be ok */
+	
+	if ( !W_ERROR_EQUAL( out.status, WERR_INSUFFICIENT_BUFFER ) ) {
+		in.buffer_size = out.needed;
+
+		CLI_DO_RPC( cli, mem_ctx, PI_SVCCTL, SVCCTL_ENUM_SERVICES_STATUS_W, 
+		            in, out, 
+		            qbuf, rbuf,
+		            svcctl_io_q_enum_services_status,
+		            svcctl_io_r_enum_services_status, 
+		            WERR_GENERAL_FAILURE );
+	}
+	
 	if ( !W_ERROR_IS_OK(out.status) ) 
 		return out.status;
+		
+	/* pull out the data */
+	if ( !(services = TALLOC_ARRAY( mem_ctx, ENUM_SERVICES_STATUS, out.returned )) ) 
+		return WERR_NOMEM;
+		
+	for ( i=0; i<out.returned; i++ ) {
+		svcctl_io_enum_services_status( "", &services[i], &out.buffer, 0 );
+	}
+	
+	*service_array = services;
+	*returned      = out.returned;
+	
+	
 
 	return out.status;
 }

Modified: branches/SAMBA_3_0/source/utils/net_rpc_service.c
===================================================================
--- branches/SAMBA_3_0/source/utils/net_rpc_service.c	2005-03-24 17:11:51 UTC (rev 6039)
+++ branches/SAMBA_3_0/source/utils/net_rpc_service.c	2005-03-24 18:05:31 UTC (rev 6040)
@@ -28,25 +28,46 @@
                                            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<num_services; i++ ) {
+		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);
+	}
+
+done:	
 	close_service_handle( cli, mem_ctx, &hSCM  );
 		
-	return NT_STATUS_OK;
+	return werror_to_ntstatus(result);
 }	
 
 



More information about the samba-cvs mailing list