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

LEOCADIE Grégory gleocadie at idealx.com
Tue May 17 13:58:34 GMT 2005


hi,
I implemented list share, add share, del share functionnalities for the 
net command.(all *_share.[ch] files )

I had options (*_net.[hc] files ) for net command:
    * -h / --host to set the destination
    * -c / --comment to add descriptive comment (add function only)
    * -L / --long to display full informations about shares(exports)

And the last file (net.patch) is a patch of different files that I 
altered to be able to implement the above functionnalities.

Best regards,

Grégory LEOCADIE
IDEALX
-------------- next part --------------
A non-text attachment was scrubbed...
Name: net_share.c
Type: text/x-csrc
Size: 5144 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20050517/17d6c2ec/net_share.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: popt_net.c
Type: text/x-csrc
Size: 1121 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20050517/17d6c2ec/popt_net.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: popt_net.h
Type: text/x-chdr
Size: 976 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20050517/17d6c2ec/popt_net-0001.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libnet_share.c
Type: text/x-csrc
Size: 7539 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20050517/17d6c2ec/libnet_share.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libnet_share.h
Type: text/x-chdr
Size: 2361 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20050517/17d6c2ec/libnet_share-0001.bin
-------------- next part --------------
Index: lib/cmdline/popt_common.h
===================================================================
--- lib/cmdline/popt_common.h	(revision 6857)
+++ lib/cmdline/popt_common.h	(working copy)
@@ -29,6 +29,7 @@
 extern struct poptOption popt_common_connection[];
 extern struct poptOption popt_common_version[];
 extern struct poptOption popt_common_credentials[];
+extern struct poptOption popt_common_net[];
 
 #ifndef POPT_TABLEEND
 #define POPT_TABLEEND { NULL, '\0', 0, 0, 0, NULL, NULL }
@@ -38,7 +39,8 @@
 #define POPT_COMMON_CONNECTION { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_connection, 0, "Connection options:", NULL },
 #define POPT_COMMON_VERSION { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version, 0, "Common samba options:", NULL },
 #define POPT_COMMON_CREDENTIALS { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_credentials, 0, "Authentication options:", NULL },
+#define POPT_COMMON_NET { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_net, 0, "Net command options:", NULL },
 
 extern struct cli_credentials *cmdline_credentials;
-
+extern struct cli_net_options *cmdline_net_options;
 #endif /* _POPT_COMMON_H */
Index: lib/cmdline/config.m4
===================================================================
--- lib/cmdline/config.m4	(revision 6857)
+++ lib/cmdline/config.m4	(working copy)
@@ -69,7 +69,7 @@
 	     [],
 	     [$TERMLIBS])
 
-TMP_LIBCMDLINE_OBJS="lib/cmdline/readline.o lib/cmdline/popt_common.o"
+TMP_LIBCMDLINE_OBJS="lib/cmdline/readline.o lib/cmdline/popt_common.o lib/cmdline/popt_net.o"
 TMP_LIBCMDLINE_LIBS="$TERMLIBS"
 
 SMB_EXT_LIB(READLINE, [${TMP_LIBCMDLINE_LIBS}])
Index: lib/cmdline/popt_common.c
===================================================================
--- lib/cmdline/popt_common.c	(revision 6857)
+++ lib/cmdline/popt_common.c	(working copy)
@@ -26,6 +26,7 @@
 #include "system/filesys.h"
 #include "system/passwd.h"
 #include "lib/cmdline/popt_common.h"
+#include "lib/cmdline/popt_net.h"
 
 /* Handle command line options:
  *		-d,--debuglevel 
@@ -42,6 +43,7 @@
 
 struct cli_credentials *cmdline_credentials = NULL;
 
+
 static void popt_common_callback(poptContext con, 
 			   enum poptCallbackReason reason,
 			   const struct poptOption *opt,
@@ -63,7 +65,6 @@
 		talloc_free(logfile);
 		return;
 	}
-
 	switch(opt->val) {
 	case 'd':
 		lp_set_cmdline("log level", arg);
@@ -114,6 +115,18 @@
 		lp_set_cmdline("name resolve order", arg);
 		break;
 
+	case 'h':
+		cmdline_net_options->dest_adr = talloc_asprintf(NULL, "%s", arg);
+		break;
+
+	case 'L':
+		cmdline_net_options->full_info = True;
+		break;
+
+	case 'c':
+		cmdline_net_options->share_comment = talloc_asprintf(NULL, "%s", arg);
+		break;
+
 	case OPT_OPTION:
 		if (!lp_set_option(arg)) {
 			fprintf(stderr, "Error setting option '%s'\n", arg);
@@ -159,6 +172,14 @@
 	POPT_TABLEEND
 };
 
+struct poptOption popt_common_net[] = {
+	{ NULL, 0, POPT_ARG_CALLBACK, popt_common_callback },
+	{ "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_TABLEEND
+};
+
 /* Handle command line options:
  *		-U,--user
  *		-A,--authentication-file
Index: libnet/libnet.h
===================================================================
--- libnet/libnet.h	(revision 6857)
+++ libnet/libnet.h	(working copy)
@@ -34,3 +34,4 @@
 #include "libnet/libnet_join.h"
 #include "libnet/libnet_vampire.h"
 #include "libnet/libnet_user.h"
+#include "libnet/libnet_share.h"
Index: libnet/config.mk
===================================================================
--- libnet/config.mk	(revision 6857)
+++ libnet/config.mk	(working copy)
@@ -10,6 +10,7 @@
 		libnet/libnet_join.o \
 		libnet/libnet_vampire.o \
 		libnet/libnet_user.o \
+		libnet/libnet_share.o \
 		libnet/userinfo.o \
 		libnet/userman.o
 REQUIRED_SUBSYSTEMS = RPC_NDR_SAMR RPC_NDR_SRVSVC LIBCLI_COMPOSITE LIBSAMBA3
Index: include/structs.h
===================================================================
--- include/structs.h	(revision 6857)
+++ include/structs.h	(working copy)
@@ -127,6 +127,9 @@
 union libnet_RemoteTOD;
 union libnet_JoinDomain;
 union libnet_CreateUser;
+union libnet_ListShares;
+union libnet_AddShare;
+union libnet_DelShare;
 struct net_functable;
 struct net_context;
 
Index: utils/net/net.c
===================================================================
--- utils/net/net.c	(revision 6857)
+++ utils/net/net.c	(working copy)
@@ -50,6 +50,8 @@
   run a function from a function table. If not found then
   call the specified usage function 
 */
+struct cli_net_options *cmdline_net_options = NULL;
+
 int net_run_function(struct net_context *ctx,
 			int argc, const char **argv,
 			const struct net_functable *functable, 
@@ -107,6 +109,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}
 };
 
@@ -151,6 +154,7 @@
 		POPT_COMMON_CONNECTION
 		POPT_COMMON_CREDENTIALS
 		POPT_COMMON_VERSION
+		POPT_COMMON_NET
 		POPT_TABLEEND
 	};
 
@@ -159,6 +163,7 @@
 #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);
@@ -177,7 +182,6 @@
 	load_interfaces();
 
 	argv_new = (const char **)poptGetArgs(pc);
-
 	argc_new = argc;
 	for (i=0; i<argc; i++) {
 		if (argv_new[i] == NULL) {
@@ -202,6 +206,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/config.mk
===================================================================
--- utils/net/config.mk	(revision 6857)
+++ utils/net/config.mk	(working copy)
@@ -9,6 +9,7 @@
 		utils/net/net_time.o \
 		utils/net/net_join.o \
 		utils/net/net_vampire.o \
+		utils/net/net_share.o \
 		utils/net/net_user.o
 REQUIRED_SUBSYSTEMS = \
 		CONFIG \
Index: utils/net/net.h
===================================================================
--- utils/net/net.h	(revision 6857)
+++ utils/net/net.h	(working copy)
@@ -22,9 +22,12 @@
 #ifndef _UTIL_NET_H
 #define _UTIL_NET_H
 
+#include "lib/cmdline/popt_net.h"
+
 struct net_context {
 	TALLOC_CTX *mem_ctx;
 	struct cli_credentials *credentials;
+	struct cli_net_options *net_options;
 };
 
 struct net_functable {


More information about the samba-technical mailing list