net command: list shares, add share, del share + net options

LEOCADIE Grégory gleocadie at idealx.com
Wed May 18 10:17:27 GMT 2005


Hi,
in this patch, I have implemented net options in utils/net/net.c by 
using samba3 model.
I have created a new structure (cli_net_options with its initialisation 
function : cli_net_options_init) that permit to put net options together 
and to use them with the net context.

cheers,
LEOCADIE Grégory
IDEALX

-------------- next part --------------
Index: utils/net/net.c
===================================================================
--- utils/net/net.c	(revision 6877)
+++ utils/net/net.c	(working copy)
@@ -74,6 +74,22 @@
 }
 
 /*
+ initialize a cli_net_options struct.
+*/
+static struct cli_net_options* cli_net_options_init(TALLOC_CTX *mem_ctx)
+{
+	struct cli_net_options *opt = talloc(mem_ctx, struct cli_net_options);
+
+	if (!opt)
+		return opt;
+	
+	opt->full_info		= False;
+	opt->dest_adr		= "localhost";
+	opt->share_comment	= "";
+
+	return opt;
+}
+/*
   run a usage function from a function table. If not found then fail
 */
 int net_run_usage(struct net_context *ctx,
@@ -107,6 +123,7 @@
 	{"join", "join a domain\n", net_join, net_join_usage},
 	{"samdump", "dump the sam of a domain\n", net_samdump, net_samdump_usage},
 	{"user", "manage user accounts\n", net_user, net_user_usage},
+	{"share", "manage share\n", net_share, net_share_usage},
 	{NULL, NULL, NULL, NULL}
 };
 
@@ -145,7 +162,11 @@
 	TALLOC_CTX *mem_ctx;
 	struct net_context *ctx = NULL;
 	poptContext pc;
+	struct cli_net_options *cmdline_net_options = NULL;
 	struct poptOption long_options[] = {
+		{ "long", 'L', POPT_ARG_NONE, NULL, 'L', "Show Name, Type and Comments of all services", "LONG" },
+		{ "host", 'h', POPT_ARG_STRING, NULL, 'h', "Set the host rpc desctination", "HOST" },
+		{ "comment", 'c', POPT_ARG_STRING, NULL, 'c', "Set descriptive comment(add only)", "COMMENT" },
 		POPT_AUTOHELP
 		POPT_COMMON_SAMBA
 		POPT_COMMON_CONNECTION
@@ -159,12 +180,25 @@
 #ifdef HAVE_SETBUFFER
 	setbuffer(stdout, NULL, 0);
 #endif
+	cmdline_net_options = cli_net_options_init(talloc_autofree_context());
 
 	pc = poptGetContext("net", argc, (const char **) argv, long_options, 
 				POPT_CONTEXT_KEEP_FIRST);
 
 	while((opt = poptGetNextOpt(pc)) != -1) {
 		switch (opt) {
+		case 'L':
+			cmdline_net_options->full_info = True;
+			break;
+
+		case 'h':
+			cmdline_net_options->dest_adr = talloc_asprintf(NULL, "%s", poptGetOptArg(pc));
+			break;
+
+		case 'c':
+			cmdline_net_options->share_comment = talloc_asprintf(NULL, "%s", poptGetOptArg(pc));
+			break;
+
 		default:
 			d_printf("Invalid option %s: %s\n", 
 				 poptBadOption(pc, 0), poptStrerror(opt));
@@ -202,6 +236,7 @@
 	ZERO_STRUCTP(ctx);
 	ctx->mem_ctx = mem_ctx;
 	ctx->credentials = cmdline_credentials;
+	ctx->net_options = cmdline_net_options;
 
 	rc = net_run_function(ctx, argc_new-1, argv_new+1, net_functable, net_usage);
 
Index: utils/net/net.h
===================================================================
--- utils/net/net.h	(revision 6877)
+++ utils/net/net.h	(working copy)
@@ -25,6 +25,7 @@
 struct net_context {
 	TALLOC_CTX *mem_ctx;
 	struct cli_credentials *credentials;
+	struct cli_net_options *net_options;
 };
 
 struct net_functable {
@@ -34,4 +35,9 @@
 	int (*usage)(struct net_context *ctx, int argc, const char **argv);
 };
 
+struct cli_net_options {
+	BOOL full_info;
+	const char* dest_adr;
+	const char* share_comment;
+};
 #endif /* _UTIL_NET_H */


More information about the samba-technical mailing list