Re-import the v3-3 version of str_list_make().
authorVolker Lendecke <vl@samba.org>
Thu, 30 Apr 2009 11:37:19 +0000 (13:37 +0200)
committerKarolin Seeger <kseeger@samba.org>
Tue, 26 May 2009 07:38:38 +0000 (09:38 +0200)
The merged version behaves differently: "Domain Users" is parsed into two
values, as it does not look at quotes. Samba3 users depend on the ability do
say for example

valid users = "domain users"

which would not work anymore with the merged version.

Thanks to Björn Jacke for testing this!

Volker
(cherry picked from commit 5b9477f9930d0c6511c70409561c04c5729bcc05)

source3/lib/util_str.c

index b9ccb83e556134a2a54a717b7f3811d943c7870d..84e8219843f55d6c3a8a58a8f80a5e5a01e8ee62 100644 (file)
@@ -2422,17 +2422,69 @@ char *escape_shell_string(const char *src)
 }
 
 /***************************************************
- Wrapper for str_list_make() to restore the s3 behavior.
- In samba 3.2 passing NULL or an empty string returned NULL.
-
- In master, it now returns a list of length 1 with the first string set
- to NULL (an empty list)
+ str_list_make, v3 version. The v4 version does not
+ look at quoted strings with embedded blanks, so
+ do NOT merge this function please!
 ***************************************************/
 
+#define S_LIST_ABS 16 /* List Allocation Block Size */
+
 char **str_list_make_v3(TALLOC_CTX *mem_ctx, const char *string, const char *sep)
 {
-       if (!string || !*string) {
+       char **list;
+       const char *str;
+       char *s;
+       int num, lsize;
+       char *tok;
+
+       if (!string || !*string)
+               return NULL;
+
+       list = TALLOC_ARRAY(mem_ctx, char *, S_LIST_ABS+1);
+       if (list == NULL) {
+               return NULL;
+       }
+       lsize = S_LIST_ABS;
+
+       s = talloc_strdup(list, string);
+       if (s == NULL) {
+               DEBUG(0,("str_list_make: Unable to allocate memory"));
+               TALLOC_FREE(list);
                return NULL;
        }
-       return str_list_make(mem_ctx, string, sep);
+       if (!sep) sep = LIST_SEP;
+
+       num = 0;
+       str = s;
+
+       while (next_token_talloc(list, &str, &tok, sep)) {
+
+               if (num == lsize) {
+                       char **tmp;
+
+                       lsize += S_LIST_ABS;
+
+                       tmp = TALLOC_REALLOC_ARRAY(mem_ctx, list, char *,
+                                                  lsize + 1);
+                       if (tmp == NULL) {
+                               DEBUG(0,("str_list_make: "
+                                       "Unable to allocate memory"));
+                               TALLOC_FREE(list);
+                               return NULL;
+                       }
+
+                       list = tmp;
+
+                       memset (&list[num], 0,
+                               ((sizeof(char**)) * (S_LIST_ABS +1)));
+               }
+
+               list[num] = tok;
+               num += 1;
+       }
+
+       list[num] = NULL;
+
+       TALLOC_FREE(s);
+       return list;
 }