svn commit: samba r7511 - in branches/SAMBA_3_0/source: param utils

lmuelle at samba.org lmuelle at samba.org
Sun Jun 12 16:00:31 GMT 2005


Author: lmuelle
Date: 2005-06-12 16:00:29 +0000 (Sun, 12 Jun 2005)
New Revision: 7511

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

Log:
Add three new command line switches to testparm:

--show-all-parameters
        Enumerates all available parameters, grouped in to sections
        [local] and [global] by the class of the parameter.  Each line
        is formated name=type[,enum values],flags
--parameter-name
        Display the setting of the named parameter.  The global section
        is assumed if no other is set with --section-name
--section-name
        Limit the view of testparm to the named section.  Use 'global'
        to only view the settings of the global section.

This fixes bug #2767.

Lars

Modified:
   branches/SAMBA_3_0/source/param/loadparm.c
   branches/SAMBA_3_0/source/utils/testparm.c


Changeset:
Modified: branches/SAMBA_3_0/source/param/loadparm.c
===================================================================
--- branches/SAMBA_3_0/source/param/loadparm.c	2005-06-12 12:24:54 UTC (rev 7510)
+++ branches/SAMBA_3_0/source/param/loadparm.c	2005-06-12 16:00:29 UTC (rev 7511)
@@ -2520,6 +2520,59 @@
 }
 
 /***************************************************************************
+ Show all parameter's name, type, [values,] and flags.
+***************************************************************************/
+
+void show_parameter_list(void)
+{
+	int classIndex, parmIndex, enumIndex, flagIndex;
+	BOOL hadFlag;
+	char *section_names[] = { "local", "global", NULL};
+	char *type[] = { "P_BOOL", "P_BOOLREV", "P_CHAR", "P_INTEGER",
+		"P_OCTAL", "P_LIST", "P_STRING", "P_USTRING", "P_GSTRING",
+		"P_UGSTRING", "P_ENUM", "P_SEP"};
+	unsigned flags[] = { FLAG_BASIC, FLAG_SHARE, FLAG_PRINT, FLAG_GLOBAL,
+		FLAG_WIZARD, FLAG_ADVANCED, FLAG_DEVELOPER, FLAG_DEPRECATED,
+		FLAG_HIDE, FLAG_DOS_STRING};
+	char *flag_names[] = { "FLAG_BASIC", "FLAG_SHARE", "FLAG_PRINT",
+		"FLAG_GLOBAL", "FLAG_WIZARD", "FLAG_ADVANCED", "FLAG_DEVELOPER",
+		"FLAG_DEPRECATED", "FLAG_HIDE", "FLAG_DOS_STRING", NULL};
+
+	for ( classIndex=0; section_names[classIndex]; classIndex++) {
+		printf("[%s]\n", section_names[classIndex]);
+		for (parmIndex = 0; parm_table[parmIndex].label; parmIndex++) {
+			if (parm_table[parmIndex].class == classIndex) {
+				printf("%s=%s", 
+					parm_table[parmIndex].label,
+					type[parm_table[parmIndex].type]);
+				switch (parm_table[parmIndex].type) {
+				case P_ENUM:
+					printf(",");
+					for (enumIndex=0; parm_table[parmIndex].enum_list[enumIndex].name; enumIndex++)
+						printf("%s%s",
+							enumIndex ? "|" : "",
+							parm_table[parmIndex].enum_list[enumIndex].name);
+					break;
+				default:
+					break;
+				}
+				printf(",");
+				hadFlag = False;
+				for ( flagIndex=0; flag_names[flagIndex]; flagIndex++ ) {
+					if (parm_table[parmIndex].flags & flags[flagIndex]) {
+						printf("%s%s",
+							hadFlag ? "|" : "",
+							flag_names[flagIndex]);
+						hadFlag = True;
+					}
+				}
+				printf("\n");
+			}
+		}
+	}
+}
+
+/***************************************************************************
  Set a boolean variable from the text value stored in the passed string.
  Returns True in success, False if the passed string does not correctly 
  represent a boolean.
@@ -3542,7 +3595,7 @@
 	int i;
 	param_opt_struct *data;
 	
-	fprintf(f, "# Global parameters\n[global]\n");
+	fprintf(f, "[global]\n");
 
 	for (i = 0; parm_table[i].label; i++)
 		if (parm_table[i].class == P_GLOBAL &&
@@ -3587,7 +3640,7 @@
 	param_opt_struct *data;
 	
 	if (pService != &sDefault)
-		fprintf(f, "\n[%s]\n", pService->szService);
+		fprintf(f, "[%s]\n", pService->szService);
 
 	for (i = 0; parm_table[i].label; i++) {
 
@@ -3627,7 +3680,50 @@
 	}
 }
 
+/***************************************************************************
+ Display the contents of a parameter of a single services record.
+***************************************************************************/
 
+BOOL dump_a_parameter(int snum, char *parm_name, FILE * f, BOOL isGlobal)
+{
+	service * pService = ServicePtrs[snum];
+	int i, result = False;
+	parm_class class;
+	unsigned flag = 0;
+	void *ptr;
+
+	if (isGlobal) {
+		class = P_GLOBAL;
+		flag = FLAG_GLOBAL;
+	} else
+		class = P_LOCAL;
+	
+	for (i = 0; parm_table[i].label; i++) {
+		if (strwicmp(parm_table[i].label, parm_name) == 0 &&
+		    (parm_table[i].class == class || parm_table[i].flags & flag) &&
+		    parm_table[i].ptr &&
+		    (*parm_table[i].label != '-') &&
+		    (i == 0 || (parm_table[i].ptr != parm_table[i - 1].ptr))) 
+		{
+			void *ptr;
+
+			if (isGlobal)
+				ptr = parm_table[i].ptr;
+			else
+				ptr = ((char *)pService) +
+					PTR_DIFF(parm_table[i].ptr, &sDefault);
+
+			print_parameter(&parm_table[i],
+					ptr, f);
+			fprintf(f, "\n");
+			result = True;
+			break;
+		}
+	}
+
+	return result;
+}
+
 /***************************************************************************
  Return info about the next service  in a service. snum==GLOBAL_SECTION_SNUM gives the globals.
  Return NULL when out of parameters.
@@ -4059,8 +4155,10 @@
 
 	dump_a_service(&sDefault, f);
 
-	for (iService = 0; iService < maxtoprint; iService++)
+	for (iService = 0; iService < maxtoprint; iService++) {
+		fprintf(f,"\n");
 		lp_dump_one(f, show_defaults, iService);
+	}
 }
 
 /***************************************************************************

Modified: branches/SAMBA_3_0/source/utils/testparm.c
===================================================================
--- branches/SAMBA_3_0/source/utils/testparm.c	2005-06-12 12:24:54 UTC (rev 7510)
+++ branches/SAMBA_3_0/source/utils/testparm.c	2005-06-12 16:00:29 UTC (rev 7511)
@@ -201,9 +201,12 @@
 	const char *config_file = dyn_CONFIGFILE;
 	int s;
 	static BOOL silent_mode = False;
+	static BOOL show_all_parameters = False;
 	int ret = 0;
 	poptContext pc;
 	static const char *term_code = "";
+	static char *parameter_name = NULL;
+	static char *section_name = NULL;
 	static char *new_local_machine = NULL;
 	const char *cname;
 	const char *caddr;
@@ -215,6 +218,9 @@
 		{"verbose", 'v', POPT_ARG_NONE, &show_defaults, 1, "Show default options too"},
 		{"server", 'L',POPT_ARG_STRING, &new_local_machine, 0, "Set %%L macro to servername\n"},
 		{"encoding", 't', POPT_ARG_STRING, &term_code, 0, "Print parameters with encoding"},
+		{"show-all-parameters", '\0', POPT_ARG_VAL, &show_all_parameters, True, "Show the parameters, type, possible values" },
+		{"parameter-name", '\0', POPT_ARG_STRING, &parameter_name, 0, "Limit testparm to a named parameter" },
+		{"section-name", '\0', POPT_ARG_STRING, &section_name, 0, "Limit testparm to a named section" },
 		POPT_COMMON_VERSION
 		POPT_TABLEEND
 	};
@@ -225,6 +231,11 @@
 
 	while(poptGetNextOpt(pc) != -1);
 
+	if (show_all_parameters) {
+		show_parameter_list();
+		exit(0);
+	}
+
 	setup_logging(poptGetArg(pc), True);
 
 	if (poptPeekArg(pc)) 
@@ -331,7 +342,7 @@
 	}
 
 
-	if (!silent_mode) {
+	if (!silent_mode && !section_name && !parameter_name) {
 		fprintf(stderr,"Server role: ");
 		switch(lp_server_role()) {
 			case ROLE_STANDALONE:
@@ -358,6 +369,34 @@
 			fflush(stdout);
 			getc(stdin);
 		}
+		if (parameter_name || section_name) {
+			BOOL isGlobal = False;
+			s = GLOBAL_SECTION_SNUM;
+
+			if (!section_name) {
+				section_name = GLOBAL_NAME;
+				isGlobal = True;
+			} else if ((isGlobal=!strwicmp(section_name, GLOBAL_NAME)) == 0 &&
+				 (s=lp_servicenumber(section_name)) == -1) {
+					fprintf(stderr,"Unknown section %s\n",
+						section_name);
+					return(1);
+			}
+			if (parameter_name) {
+				if (!dump_a_parameter( s, parameter_name, stdout, isGlobal)) {
+					fprintf(stderr,"Parameter %s unknown for section %s\n",
+						parameter_name, section_name);
+					return(1);
+				}
+			} else {
+				if (isGlobal == True)
+					lp_dump(stdout, show_defaults, 0);
+				else
+					lp_dump_one(stdout, show_defaults, s);
+			}
+			return(ret);
+		}
+
 		lp_dump(stdout, show_defaults, lp_numservices());
 	}
 



More information about the samba-cvs mailing list