From 42cfffae80480eae4381902fff3f7c61f858a933 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 7 Dec 2007 17:32:32 -0800 Subject: Remove next_token - all uses must now be next_token_talloc. No more temptations to use static length strings. Jeremy. (This used to be commit ec003f39369910dee852b7cafb883ddaa321c2de) --- source3/lib/sharesec.c | 4 +- source3/lib/util_sock.c | 6 ++- source3/lib/util_str.c | 110 +++++++----------------------------------------- 3 files changed, 22 insertions(+), 98 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/sharesec.c b/source3/lib/sharesec.c index 4b1ec556c5..b3b000579f 100644 --- a/source3/lib/sharesec.c +++ b/source3/lib/sharesec.c @@ -290,10 +290,10 @@ bool parse_usershare_acl(TALLOC_CTX *ctx, const char *acl_str, SEC_DESC **ppsd) uint32 g_access; uint32 s_access; DOM_SID sid; - fstring sidstr; + char *sidstr; uint8 type = SEC_ACE_TYPE_ACCESS_ALLOWED; - if (!next_token(&pacl, sidstr, ":", sizeof(sidstr))) { + if (!next_token_talloc(ctx, &pacl, &sidstr, ":")) { DEBUG(0,("parse_usershare_acl: malformed usershare acl looking " "for ':' in string '%s'\n", pacl)); return False; diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index e49db340ae..e919cc5a46 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -785,9 +785,10 @@ static void print_socket_options(int s) void set_socket_options(int fd, const char *options) { - fstring tok; + TALLOC_CTX *ctx = talloc_stackframe(); + char *tok; - while (next_token(&options,tok," \t,", sizeof(tok))) { + while (next_token_talloc(ctx, &options, &tok," \t,")) { int ret=0,i; int value = 1; char *p; @@ -836,6 +837,7 @@ void set_socket_options(int fd, const char *options) } } + TALLOC_FREE(ctx); print_socket_options(fd); } diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 2c0d86ec9a..ee76e33de8 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -29,62 +29,6 @@ * @brief String utilities. **/ -/** - * Internal function to get the next token from a string, return false if none - * found. Handles double-quotes. This is the work horse function called by - * next_token() and next_token_no_ltrim(). - * - * Based on a routine by GJC@VILLAGE.COM. - * Extensively modified by Andrew.Tridgell@anu.edu.au - */ -static bool next_token_internal(const char **ptr, - char *buff, - const char *sep, - size_t bufsize, - bool ltrim) -{ - char *s; - char *pbuf; - bool quoted; - size_t len=1; - - if (!ptr) - return(false); - - s = (char *)*ptr; - - /* default to simple separators */ - if (!sep) - sep = " \t\n\r"; - - /* find the first non sep char, if left-trimming is requested */ - if (ltrim) { - while (*s && strchr_m(sep,*s)) - s++; - } - - /* nothing left? */ - if (! *s) - return(false); - - /* copy over the token */ - pbuf = buff; - for (quoted = false; len < bufsize && *s && - (quoted || !strchr_m(sep,*s)); s++) { - if ( *s == '\"' ) { - quoted = !quoted; - } else { - len++; - *pbuf++ = *s; - } - } - - *ptr = (*s) ? s+1 : s; - *pbuf = 0; - - return(true); -} - static bool next_token_internal_talloc(TALLOC_CTX *ctx, const char **ptr, char **pp_buff, @@ -111,8 +55,9 @@ static bool next_token_internal_talloc(TALLOC_CTX *ctx, /* find the first non sep char, if left-trimming is requested */ if (ltrim) { - while (*s && strchr_m(sep,*s)) + while (*s && strchr_m(sep,*s)) { s++; + } } /* nothing left? */ @@ -157,6 +102,7 @@ static bool next_token_internal_talloc(TALLOC_CTX *ctx, return true; } +#if 0 /* * Get the next token from a string, return false if none found. Handles * double-quotes. This version trims leading separator characters before @@ -166,6 +112,7 @@ bool next_token(const char **ptr, char *buff, const char *sep, size_t bufsize) { return next_token_internal(ptr, buff, sep, bufsize, true); } +#endif bool next_token_talloc(TALLOC_CTX *ctx, const char **ptr, @@ -180,13 +127,6 @@ bool next_token_talloc(TALLOC_CTX *ctx, * double-quotes. This version does not trim leading separator characters * before looking for a token. */ -bool next_token_no_ltrim(const char **ptr, - char *buff, - const char *sep, - size_t bufsize) -{ - return next_token_internal(ptr, buff, sep, bufsize, false); -} bool next_token_no_ltrim_talloc(TALLOC_CTX *ctx, const char **ptr, @@ -204,18 +144,6 @@ but beware the fact that it is not re-entrant! static const char *last_ptr=NULL; -bool next_token_nr(const char **ptr,char *buff, const char *sep, size_t bufsize) -{ - bool ret; - if (!ptr) { - ptr = &last_ptr; - } - - ret = next_token(ptr, buff, sep, bufsize); - last_ptr = *ptr; - return ret; -} - bool next_token_nr_talloc(TALLOC_CTX *ctx, const char **ptr, char **pp_buff, @@ -1097,23 +1025,16 @@ char *hex_encode(TALLOC_CTX *mem_ctx, const unsigned char *buff_in, size_t len) bool in_list(const char *s, const char *list, bool casesensitive) { - char *tok; - const char *p=list; - size_t bufsize = strlen(list); + char *tok = NULL; bool ret = false; + TALLOC_CTX *frame; - if (!list) - return(false); - - /* We know a token can't be larger - * than the entire list. */ - - tok = SMB_MALLOC_ARRAY(char, bufsize+1); - if (!tok) { + if (!list) { return false; } - while (next_token(&p,tok,LIST_SEP,bufsize+1)) { + frame = talloc_stackframe(); + while (next_token_talloc(frame, &list, &tok,LIST_SEP)) { if (casesensitive) { if (strcmp(tok,s) == 0) { ret = true; @@ -1126,8 +1047,7 @@ bool in_list(const char *s, const char *list, bool casesensitive) } } } - - SAFE_FREE(tok); + TALLOC_FREE(frame); return ret; } @@ -2409,7 +2329,8 @@ char *ipstr_list_make(char **ipstr_list, int ipstr_list_parse(const char *ipstr_list, struct ip_service **ip_list) { - fstring token_str; + TALLOC_CTX *frame; + char *token_str = NULL; size_t count; int i; @@ -2423,8 +2344,9 @@ int ipstr_list_parse(const char *ipstr_list, struct ip_service **ip_list) return 0; } - for ( i=0; next_token(&ipstr_list, token_str, - IPSTR_LIST_SEP, FSTRING_LEN) && i