[PATCH 5/5] s4: improve net docs

Matthieu Patou mat at matws.net
Mon Jan 11 10:13:28 MST 2010


---
 source4/utils/net/net.c               |   39 ++++++++++++++++++++++++--------
 source4/utils/net/net.h               |    1 +
 source4/utils/net/net_export_keytab.c |   14 +++++++----
 source4/utils/net/net_join.c          |    8 ++++--
 source4/utils/net/net_machinepw.c     |    6 +++-
 source4/utils/net/net_password.c      |   25 +++++++++++----------
 source4/utils/net/net_time.c          |    2 +
 source4/utils/net/net_user.c          |   25 +++++++++++++++++----
 source4/utils/net/net_vampire.c       |   39 +++++++++++++++++++++++++++------
 9 files changed, 115 insertions(+), 44 deletions(-)

diff --git a/source4/utils/net/net.c b/source4/utils/net/net.c
index 850fc0c..7a7fa36 100644
--- a/source4/utils/net/net.c
+++ b/source4/utils/net/net.c
@@ -173,6 +173,9 @@ int net_run_usage(struct net_context *ctx,
 		if (strcasecmp_m(argv[0], functable[i].name) == 0) {
 			found = true;
 			if (functable[i].usage) {
+				if (argc == 1) {
+					d_printf("Description: %s",functable[i].desc);
+				}
 				return functable[i].usage(ctx, argc-1, argv+1);
 			}
 		}
@@ -194,19 +197,35 @@ int net_run_usage(struct net_context *ctx,
 	return 1;
 }
 
+int net_run_subusage(struct net_context *ctx,
+			int argc, const char **argv,
+			const struct net_functable *functable)
+{
+	int i;
+	if (argc !=0) {
+		return net_run_usage(ctx,argc,argv,functable);
+	}
+	for (i=0; functable[i].name; i++) {
+		if( i == 0) {
+			d_printf("Available command:\n");
+		}
+		d_printf("%s\t%s",functable[i].synopsis,functable[i].desc);
+	}
+	return 0;
+}
 
 /* main function table */
 static const struct net_functable net_functable[] = {
-	{"password", "Change password\n", net_password, net_password_usage},
-	{"time", "Get remote server's time\n", net_time, net_time_usage},
-	{"join", "Join a domain\n", net_join, net_join_usage},
-	{"samdump", "Dump the sam of a domain\n", net_samdump, net_samdump_usage},
-	{"export", "Dump the sam of this domain\n", net_export, net_export_usage},
-	{"vampire", "Join and syncronise an AD domain onto the local server\n", net_vampire, net_vampire_usage},
-	{"samsync", "Synchronise into the local ldb the sam of an NT4 domain\n", net_samsync_ldb, net_samsync_ldb_usage},
-	{"user", "Manage user accounts\n", net_user, net_user_usage},
-	{"machinepw", "Get a machine password out of our SAM\n", net_machinepw, net_machinepw_usage},
-	{NULL, NULL, NULL, NULL}
+	{"password", "Change password\n",NULL, net_password, net_password_usage},
+	{"time", "Get remote server's time\n",NULL, net_time, net_time_usage},
+	{"join", "Join a domain\n",NULL, net_join, net_join_usage},
+	{"samdump", "Dump the sam of a domain\n",NULL, net_samdump, net_samdump_usage},
+	{"export", "Dump the sam of this domain\n",NULL, net_export, net_export_usage},
+	{"vampire", "Join and syncronise an AD domain onto the local server\n",NULL, net_vampire, net_vampire_usage},
+	{"samsync", "Synchronise into the local ldb the sam of an NT4 domain\n",NULL, net_samsync_ldb, net_samsync_ldb_usage},
+	{"user", "Manage user accounts\n",NULL, net_user, net_user_usage},
+	{"machinepw", "Get a machine password out of our SAM\n",NULL, net_machinepw, net_machinepw_usage},
+	{NULL, NULL, NULL, NULL, NULL}
 };
 
 static int net_help_builtin(const struct net_functable *ftable)
diff --git a/source4/utils/net/net.h b/source4/utils/net/net.h
index d1991cb..4650df9 100644
--- a/source4/utils/net/net.h
+++ b/source4/utils/net/net.h
@@ -32,6 +32,7 @@ struct net_context {
 struct net_functable {
 	const char *name;
 	const char *desc;
+	const char *synopsis;
 	int (*fn)(struct net_context *ctx, int argc, const char **argv);
 	int (*usage)(struct net_context *ctx, int argc, const char **argv);
 };
diff --git a/source4/utils/net/net_export_keytab.c b/source4/utils/net/net_export_keytab.c
index 7f13278..4ab3dc0 100644
--- a/source4/utils/net/net_export_keytab.c
+++ b/source4/utils/net/net_export_keytab.c
@@ -26,15 +26,19 @@
 
 static int net_export_keytab_usage(struct net_context *ctx, int argc, const char **argv)
 {
-	d_printf("net export keytab <keytab>\n");
+	d_printf("net export keytab <keytab> [options]\n");
+	d_printf("Valid options:\n");
+	d_printf("\tSee net --help for the list of valid options\n");
 	return 0;	
 }
 
+/* Not used (anymore ?)
 static int net_export_keytab_help(struct net_context *ctx, int argc, const char **argv)
 {
 	d_printf("Dumps kerberos keys of the domain into a keytab.\n");
 	return 0;	
 }
+*/
 
 static int net_export_keytab(struct net_context *ctx, int argc, const char **argv) 
 {
@@ -74,7 +78,7 @@ static int net_export_keytab(struct net_context *ctx, int argc, const char **arg
 
 /* main function table */
 static const struct net_functable net_export_functable[] = {
-	{"keytab", "dump keys into a keytab\n", net_export_keytab, net_export_keytab_usage},
+	{"keytab", "Dump all principals into a keytab\n", "net export keytab <keytab> [options]\n", net_export_keytab, net_export_keytab_usage},
 	{NULL, NULL, NULL, NULL}
 };
 
@@ -98,13 +102,13 @@ int net_export(struct net_context *ctx, int argc, const char **argv)
 
 int net_export_usage(struct net_context *ctx, int argc, const char **argv)
 {
-	d_printf("net export keytab <keytab>\n");
-	return 0;	
+	return net_run_subusage(ctx,argc,argv,net_export_functable);
 }
 
+/* Not used (anymore ?)
 int net_export_help(struct net_context *ctx, int argc, const char **argv)
 {
 	d_printf("Dumps the sam of the domain we are joined to.\n");
 	return 0;	
 }
-
+*/
diff --git a/source4/utils/net/net_join.c b/source4/utils/net/net_join.c
index 316bc12..e4d0950 100644
--- a/source4/utils/net/net_join.c
+++ b/source4/utils/net/net_join.c
@@ -93,12 +93,14 @@ int net_join(struct net_context *ctx, int argc, const char **argv)
 int net_join_usage(struct net_context *ctx, int argc, const char **argv)
 {
 	d_printf("net join <domain> [BDC | MEMBER] [options]\n");
-	return 0;	
+	d_printf("Valid options:\n");
+	d_printf("\tSee net --help for the list of valid options\n");
+	return 0;
 }
-
+/* Not used (anymore ?)
 int net_join_help(struct net_context *ctx, int argc, const char **argv)
 {
 	d_printf("Joins domain as either member or backup domain controller.\n");
 	return 0;	
 }
-
+*/
diff --git a/source4/utils/net/net_machinepw.c b/source4/utils/net/net_machinepw.c
index 390eb8d..53ac56e 100644
--- a/source4/utils/net/net_machinepw.c
+++ b/source4/utils/net/net_machinepw.c
@@ -29,8 +29,10 @@
 
 int net_machinepw_usage(struct net_context *ctx, int argc, const char **argv)
 {
-	d_printf("net machinepw <accountname>\n");
-	return -1;
+	d_printf("net machinepw <accountname> [options]\n");
+	d_printf("Valid options:\n");
+	d_printf("\tSee net --help for the list of valid options\n");
+	return 0;
 }
 
 int net_machinepw(struct net_context *ctx, int argc, const char **argv)
diff --git a/source4/utils/net/net_password.c b/source4/utils/net/net_password.c
index 55f7c3c..29c9de4 100644
--- a/source4/utils/net/net_password.c
+++ b/source4/utils/net/net_password.c
@@ -31,10 +31,19 @@
 
 static int net_password_change_usage(struct net_context *ctx, int argc, const char **argv)
 {
-	d_printf("net_password_change_usage: TODO\n");
+	d_printf("net password change [password] [options]\n");
+	d_printf("Valid options:\n");
+	d_printf("\tSee net --help for the list of valid options\n");
 	return 0;	
 }
 
+static int net_password_set_usage(struct net_context *ctx, int argc, const char **argv)
+{
+	d_printf("net password set <user> [password] [options]\n");
+	d_printf("Valid options:\n");
+	d_printf("\tSee net --help for the list of valid options\n");
+	return 0;
+}
 
 static int net_password_change(struct net_context *ctx, int argc, const char **argv)
 {
@@ -78,14 +87,6 @@ static int net_password_change(struct net_context *ctx, int argc, const char **a
 	return 0;
 }
 
-
-static int net_password_set_usage(struct net_context *ctx, int argc, const char **argv)
-{
-	d_printf("net_password_set_usage: TODO\n");
-	return 0;	
-}
-
-
 static int net_password_set(struct net_context *ctx, int argc, const char **argv)
 {
 	NTSTATUS status;
@@ -154,8 +155,8 @@ static int net_password_set(struct net_context *ctx, int argc, const char **argv
 
 
 static const struct net_functable net_password_functable[] = {
-	{"change", "change password (old password required)\n", net_password_change, net_password_change_usage },
-	{"set", "set password\n", net_password_set, net_password_set_usage },
+	{"change", "change password (old password required)\n","net password change [password] [options]\n", net_password_change, net_password_change_usage },
+	{"set", "set specified user password \n", "net password set <user> [password] [options]\n", net_password_set, net_password_set_usage },
 	{NULL, NULL}
 };
 
@@ -166,6 +167,6 @@ int net_password(struct net_context *ctx, int argc, const char **argv)
 
 int net_password_usage(struct net_context *ctx, int argc, const char **argv)
 {
-	d_printf("net password <command> [options]\n");
+        return net_run_subusage(ctx,argc,argv,net_password_functable);
 	return 0;	
 }
diff --git a/source4/utils/net/net_time.c b/source4/utils/net/net_time.c
index 92e6e77..8a8e1f8 100644
--- a/source4/utils/net/net_time.c
+++ b/source4/utils/net/net_time.c
@@ -74,5 +74,7 @@ int net_time(struct net_context *ctx, int argc, const char **argv)
 int net_time_usage(struct net_context *ctx, int argc, const char **argv)
 {
 	d_printf("net time <server> [options]\n");
+	d_printf("Valid options:\n");
+	d_printf("\tSee net --help for the list of valid options\n");
 	return 0;	
 }
diff --git a/source4/utils/net/net_user.c b/source4/utils/net/net_user.c
index c4b8ecb..783c4ff 100644
--- a/source4/utils/net/net_user.c
+++ b/source4/utils/net/net_user.c
@@ -34,13 +34,13 @@ static int net_user_add(struct net_context *ctx, int argc, const char **argv)
 	/* command line argument preparation */
 	switch (argc) {
 	case 0:
-		return net_user_usage(ctx, argc, argv);
+		return net_user_add_usage(ctx, argc, argv);
 		break;
 	case 1:
 		user_name = talloc_strdup(ctx, argv[0]);
 		break;
 	default:
-		return net_user_usage(ctx, argc, argv);
+		return net_user_add_usage(ctx, argc, argv);
 	}
 
 	/* libnet context init and its params */
@@ -106,8 +106,8 @@ static int net_user_delete(struct net_context *ctx, int argc, const char **argv)
 
 
 static const struct net_functable net_user_functable[] = {
-	{ "add", "create new user account\n", net_user_add, net_user_usage },
-	{ "delete", "delete an existing user account\n", net_user_delete, net_user_usage },
+	{ "add", "Create new user account\n","net user add <user> [options]\n", net_user_add, net_user_add_usage },
+	{ "delete", "Delete an existing user account\n","net user delete <user> [options]\n", net_user_delete, net_user_del_usage },
 	{ NULL, NULL }
 };
 
@@ -120,6 +120,21 @@ int net_user(struct net_context *ctx, int argc, const char **argv)
 
 int net_user_usage(struct net_context *ctx, int argc, const char **argv)
 {
-	d_printf("net user <command> [options]\n");
+	return net_run_subusage(ctx,argc,argv,net_user_functable);
+}
+
+int net_user_add_usage(struct net_context *ctx, int argc, const char **argv)
+{
+	d_printf("net user add <user> [options]\n");
+	d_printf("Valid options:\n");
+	d_printf("\tSee net --help for the list of valid options\n");
+	return 0;
+}
+
+int net_user_del_usage(struct net_context *ctx, int argc, const char **argv)
+{
+	d_printf("net user delete <user> [options]\n");
+	d_printf("Valid options:\n");
+	d_printf("\tSee net --help for the list of valid options\n");
 	return 0;
 }
diff --git a/source4/utils/net/net_vampire.c b/source4/utils/net/net_vampire.c
index 1bcc8db..7c68d77 100644
--- a/source4/utils/net/net_vampire.c
+++ b/source4/utils/net/net_vampire.c
@@ -30,15 +30,27 @@
 
 static int net_samdump_keytab_usage(struct net_context *ctx, int argc, const char **argv)
 {
-	d_printf("net samdump keytab <keytab>\n");
+	d_printf("net samdump keytab <keytab> [options]\n");
+	d_printf("Valid options:\n");
+	d_printf("\tSee net --help for the list of valid options\n");
 	return 0;	
 }
 
+static int net_samdump_print_usage(struct net_context *ctx, int argc, const char **argv)
+{
+	d_printf("net samdump print [options]\n");
+	d_printf("Valid options:\n");
+	d_printf("\tSee net --help for the list of valid options\n");
+	return 0;
+}
+
+/* Not used (anymore?)
 static int net_samdump_keytab_help(struct net_context *ctx, int argc, const char **argv)
 {
 	d_printf("Dumps kerberos keys of a domain into a keytab.\n");
 	return 0;	
 }
+*/
 
 static int net_samdump_keytab(struct net_context *ctx, int argc, const char **argv) 
 {
@@ -80,11 +92,17 @@ static int net_samdump_keytab(struct net_context *ctx, int argc, const char **ar
 
 /* main function table */
 static const struct net_functable net_samdump_functable[] = {
-	{"keytab", "dump keys into a keytab\n", net_samdump_keytab, net_samdump_keytab_usage},
+	{"keytab", "dump keys into a keytab\n","net samdump keytab <keytab> [options]\n", net_samdump_keytab, net_samdump_keytab_usage},
+	{"print", "dump in a human readable format\n","net samdump print [options]\n", net_samdump_print, net_samdump_print_usage},
 	{NULL, NULL, NULL, NULL}
 };
 
-int net_samdump(struct net_context *ctx, int argc, const char **argv) 
+int net_samdump(struct net_context *ctx, int argc, const char **argv)
+{
+        return net_run_function(ctx, argc, argv, net_samdump_functable, net_samdump_usage);
+}
+
+int net_samdump_print(struct net_context *ctx, int argc, const char **argv)
 {
 	NTSTATUS status;
 	struct libnet_context *libnetctx;
@@ -126,16 +144,16 @@ int net_samdump(struct net_context *ctx, int argc, const char **argv)
 
 int net_samdump_usage(struct net_context *ctx, int argc, const char **argv)
 {
-	d_printf("net samdump\n");
-	d_printf("net samdump keytab <keytab>\n");
-	return 0;	
+	return net_run_subusage(ctx,argc,argv,net_samdump_functable);
 }
 
+/* Not used (anymore ?)
 int net_samdump_help(struct net_context *ctx, int argc, const char **argv)
 {
 	d_printf("Dumps the sam of the domain we are joined to.\n");
 	return 0;	
 }
+*/
 
 int net_samsync_ldb(struct net_context *ctx, int argc, const char **argv) 
 {
@@ -238,12 +256,19 @@ int net_vampire(struct net_context *ctx, int argc, const char **argv)
 
 int net_vampire_usage(struct net_context *ctx, int argc, const char **argv)
 {
-	d_printf("net vampire <domain> [options]\n");
+	d_printf("net vampire <domain> [targetdir] [options]\n");
+	d_printf("Parameters:\n");
+	d_printf("\tdomain: domain to be joined AND synchronized\n");
+	d_printf("\ttargetdir: directory where the synchronized provision will be stored\n");
+	d_printf("Valid options:\n");
+	d_printf("\tSee net --help for the list of valid options\n");
 	return 0;	
 }
 
+/* Not used (anymore?)
 int net_vampire_help(struct net_context *ctx, int argc, const char **argv)
 {
 	d_printf("Join and synchronise a remote AD domain to the local server.\n");
 	return 0;	
 }
+*/
-- 
1.6.3.3


--------------050508060406060009090606
Content-Type: text/x-patch;
 name="0004-s4-make-net-help-include-help-for-switches-as-well.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0004-s4-make-net-help-include-help-for-switches-as-well.patc";
 filename*1="h"



More information about the samba-technical mailing list