patch to use net options

LEOCADIE Grégory gleocadie at idealx.com
Mon May 23 08:57:10 GMT 2005


Sorry, it was utils/net/net.c
here is the patch.

> Hi,
> in this patch, I made changes to be able to treat options in subcommands.
> Options that are treated as bad options are stocked in a var and then 
> added to
> the main char** to be passed to subcommands.
> what do you think about that patch?
>
> gleocadie
> IDEALX

-------------- next part --------------
Index: utils/net/net.c
===================================================================
--- utils/net/net.c	(revision 6919)
+++ utils/net/net.c	(working copy)
@@ -44,7 +44,6 @@
 #include "includes.h"
 #include "dynconfig.h"
 #include "utils/net/net.h"
-#include "lib/cmdline/popt_common.h"
 
 /*
   run a function from a function table. If not found then
@@ -107,6 +106,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 shares(exports)\n", net_share, net_share_usage},
 	{NULL, NULL, NULL, NULL}
 };
 
@@ -138,13 +138,15 @@
 ****************************************************************************/
 static int binary_net(int argc, const char **argv)
 {
-	int opt,i;
+	int opt,i,j,k;
 	int rc;
 	int argc_new;
 	const char **argv_new;
 	TALLOC_CTX *mem_ctx;
 	struct net_context *ctx = NULL;
 	poptContext pc;
+	char** tmp_argv = (char**)malloc(sizeof(char*)*argc);
+	int tmp_argc = 0;
 	struct poptOption long_options[] = {
 		POPT_AUTOHELP
 		POPT_COMMON_SAMBA
@@ -166,10 +168,7 @@
 	while((opt = poptGetNextOpt(pc)) != -1) {
 		switch (opt) {
 		default:
-			d_printf("Invalid option %s: %s\n", 
-				 poptBadOption(pc, 0), poptStrerror(opt));
-			net_usage(ctx, argc, argv);
-			exit(1);
+			tmp_argv[tmp_argc++] = talloc_asprintf(NULL,"%s",poptBadOption(pc, 0));
 		}
 	}
 
@@ -186,6 +185,30 @@
 		}
 	}
 
+	//add to argv_new options and args that were treated as bad options
+	for (i=0; i<argc_new; i++) {
+		if (strcmp(argv_new[i], argv[i]) != 0) {
+			break;
+		}
+	}
+
+ 	k = 0;
+	j = 0;
+	while (j<tmp_argc) {
+		if (strcmp(tmp_argv[j],argv[k])==0) {
+			argv_new[i] = tmp_argv[j];
+			i++;
+			if ((argv[k+1] != NULL) && argv[k+1][0] != '-') {
+				argv_new[i] = argv[k+1];
+				i++;
+			}
+			j++;
+			k = 0;	
+		}
+		k++;
+	}
+	argc_new = i;
+
 	if (argc_new < 2) {
 		return net_usage(ctx, argc, argv);
 	}


More information about the samba-technical mailing list