From 08c278b44a5b6e520b823910ab153ad96ed76c3d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 30 Apr 2009 13:37:19 +0200 Subject: [PATCH] Re-import the v3-3 version of str_list_make(). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 | 66 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index b9ccb83e556..84e8219843f 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -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; } -- 2.11.4.GIT