r12730: Reimplement --parameter-name, and bring in common samba options.
authorAndrew Bartlett <abartlet@samba.org>
Fri, 6 Jan 2006 02:28:36 +0000 (02:28 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:49:46 +0000 (13:49 -0500)
This changes -s from meaning 'suppress prompt' to 'services file'.

Andrew Bartlett
(This used to be commit 0f78bd743b8bc415e47006a683c53bfdff1bc1e1)

source4/param/loadparm.c
source4/utils/testparm.c

index 6e7716b1f283e7b0e65f351f46268e5c2c69c552..3d079f3e3ed6d77a3f944f74f63e92b75a02ea8c 100644 (file)
@@ -2228,6 +2228,44 @@ static void dump_a_service(service * pService, FILE * f)
         }
 }
 
+BOOL lp_dump_a_parameter(int snum, char *parm_name, FILE * f, BOOL isGlobal)
+{
+       service * pService = ServicePtrs[snum];
+       int i, result = False;
+       parm_class p_class;
+       unsigned flag = 0;
+
+       if (isGlobal) {
+               p_class = P_GLOBAL;
+               flag = FLAG_GLOBAL;
+       } else
+               p_class = P_LOCAL;
+       
+       for (i = 0; parm_table[i].label; i++) {
+               if (strwicmp(parm_table[i].label, parm_name) == 0 &&
+                   (parm_table[i].class == p_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==-1 gives the globals.
index c4b7dd38d877b54cebeec6ef5ad34d6c714b6eb3..fd990221ed54c7464019ff75b3f2d287a434c9cb 100644 (file)
@@ -81,17 +81,17 @@ static int do_global_checks(void)
        static const char *term_code = "";
 /*
        static BOOL show_all_parameters = False;
-       static char *parameter_name = NULL;
        static char *new_local_machine = NULL;
 */
        static const char *section_name = NULL;
+       static char *parameter_name = NULL;
        static const char *cname;
        static const char *caddr;
        static int show_defaults;
 
        struct poptOption long_options[] = {
                POPT_AUTOHELP
-               {"suppress-prompt", 's', POPT_ARG_VAL, &silent_mode, 1, "Suppress prompt for enter"},
+               {"suppress-prompt", '\0', POPT_ARG_VAL, &silent_mode, 1, "Suppress prompt for enter"},
                {"verbose", 'v', POPT_ARG_NONE, &show_defaults, 1, "Show default options too"},
 /*
   We need support for smb.conf macros before this will work again 
@@ -100,11 +100,12 @@ static int do_global_checks(void)
 /*
   These are harder to do with the new code structure
                {"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" },
+               {"parameter-name", '\0', POPT_ARG_STRING, &parameter_name, 0, "Limit testparm to a named parameter" },
                {"client-name", '\0', POPT_ARG_STRING, &cname, 0, "Client DNS name for 'hosts allow' checking (should match reverse lookup)"},
                {"client-ip", '\0', POPT_ARG_STRING, &caddr, 0, "Client IP address for 'hosts allow' checking"},
+               POPT_COMMON_SAMBA
                POPT_COMMON_VERSION
                POPT_TABLEEND
        };
@@ -196,7 +197,7 @@ static int do_global_checks(void)
                        fflush(stdout);
                        getc(stdin);
                }
-               if (section_name) {
+               if (section_name || parameter_name) {
                        BOOL isGlobal = False;
                        if (!section_name) {
                                section_name = GLOBAL_NAME;
@@ -207,10 +208,14 @@ static int do_global_checks(void)
                                                section_name);
                                        return(1);
                        }
-                       if (isGlobal == True) {
-                               lp_dump(stdout, show_defaults, 0);
+                       if (!parameter_name) {
+                               if (isGlobal == True) {
+                                       lp_dump(stdout, show_defaults, 0);
+                               } else {
+                                       lp_dump_one(stdout, show_defaults, s);
+                               }
                        } else {
-                               lp_dump_one(stdout, show_defaults, s);
+                               ret = lp_dump_a_parameter(s, parameter_name, stdout, isGlobal);
                        }
                } else {
                        lp_dump(stdout, show_defaults, lp_numservices());