Ensure that items in a list of strings containing whitespace
authorGerald Carter <jerry@samba.org>
Sat, 22 Nov 2003 04:35:36 +0000 (04:35 +0000)
committerGerald Carter <jerry@samba.org>
Sat, 22 Nov 2003 04:35:36 +0000 (04:35 +0000)
are written out surrounded by single quotes.  This means that
both double and single quotes are now used to surround
strings in smb.conf.  This is a slight change from the previous
behavior but needed or else things like

    printer admin = +ntadmin, 'VALE\Domain, Admin'

get written to smb.conf by SWAT.

source/lib/util_str.c
source/param/loadparm.c
source/web/swat.c

index aa50b07f61ceaf400153aa960f76458f07ccc658..1aa33a1a4be4caad2f67acd65b7cbede360191fc 100644 (file)
@@ -62,7 +62,7 @@ BOOL next_token(const char **ptr,char *buff, const char *sep, size_t bufsize)
        /* copy over the token */
        pbuf = buff;
        for (quoted = False; len < bufsize && *s && (quoted || !strchr_m(sep,*s)); s++) {
-               if (*s == '\"') {
+               if (*s == '\"' || *s == '\'') {
                        quoted = !quoted;
                } else {
                        len++;
index 8e6064ab59f472d99365782a921f4ad1f6a3adf9..b124c6fd3bb8aeb34e74af0ef1b622154ba3d7d3 100644 (file)
@@ -3310,9 +3310,13 @@ static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
                        if ((char ***)ptr && *(char ***)ptr) {
                                char **list = *(char ***)ptr;
                                
-                               for (; *list; list++)
-                                       fprintf(f, "%s%s", *list,
-                                               ((*(list+1))?", ":""));
+                               for (; *list; list++) {
+                                       /* surround strings with whitespace in single quotes */
+                                       if ( strchr_m( *list, ' ' ) )
+                                               fprintf(f, "\'%s\'%s", *list, ((*(list+1))?", ":""));
+                                       else
+                                               fprintf(f, "%s%s", *list, ((*(list+1))?", ":""));
+                               }
                        }
                        break;
 
index f4046b46a2629f0b64b5600bd65e33800f18f807..1faef46e254e91aace92a188be53920c7138e739 100644 (file)
@@ -212,7 +212,11 @@ static void show_parameter(int snum, struct parm_struct *parm)
                if ((char ***)ptr && *(char ***)ptr && **(char ***)ptr) {
                        char **list = *(char ***)ptr;
                        for (;*list;list++) {
-                               d_printf("%s%s", *list, ((*(list+1))?" ":""));
+                               /* enclose in quotes if the string contains a space */
+                               if ( strchr_m(*list, ' ') ) 
+                                       d_printf("\'%s\'%s", *list, ((*(list+1))?", ":""));
+                               else
+                                       d_printf("%s%s", *list, ((*(list+1))?", ":""));
                        }
                }
                d_printf("\">");
@@ -221,7 +225,11 @@ static void show_parameter(int snum, struct parm_struct *parm)
                if (parm->def.lvalue) {
                        char **list = (char **)(parm->def.lvalue);
                        for (; *list; list++) {
-                               d_printf("%s%s", *list, ((*(list+1))?" ":""));
+                               /* enclose in quotes if the string contains a space */
+                               if ( strchr_m(*list, ' ') ) 
+                                       d_printf("\'%s\'%s", *list, ((*(list+1))?", ":""));
+                               else
+                                       d_printf("%s%s", *list, ((*(list+1))?", ":""));
                        }
                }
                d_printf("\'\">");