summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/param/loadparm.c104
-rw-r--r--source3/utils/testparm.c41
2 files changed, 141 insertions, 4 deletions
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index 339624a9a8..c0fbb1b77a 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -2520,6 +2520,59 @@ static int map_parameter(const char *pszParmName)
}
/***************************************************************************
+ 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 @@ static void dump_globals(FILE *f)
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 @@ static void dump_a_service(service * pService, FILE * f)
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,6 +3680,49 @@ static void dump_a_service(service * pService, FILE * f)
}
}
+/***************************************************************************
+ 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.
@@ -4059,8 +4155,10 @@ void lp_dump(FILE *f, BOOL show_defaults, int maxtoprint)
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);
+ }
}
/***************************************************************************
diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c
index dfd12c7a58..2b72479ac0 100644
--- a/source3/utils/testparm.c
+++ b/source3/utils/testparm.c
@@ -201,9 +201,12 @@ via the %%o substitution. With encrypted passwords this is not possible.\n", lp_
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 @@ via the %%o substitution. With encrypted passwords this is not possible.\n", lp_
{"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 @@ via the %%o substitution. With encrypted passwords this is not possible.\n", lp_
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 @@ print command parameter is ignored when using CUPS libraries.\n",
}
- 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 @@ print command parameter is ignored when using CUPS libraries.\n",
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());
}