diff options
author | Derrell Lipman <derrell@samba.org> | 2006-06-27 03:07:02 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 11:19:00 -0500 |
commit | 9220a7bb7ba0468113deae3c033504ab4ff31eb2 (patch) | |
tree | 029b3732b5832fa662097f5bfb95b92203721d03 | |
parent | 9718506d35ca14c5233b613c647609bf2589f38b (diff) | |
download | samba-9220a7bb7ba0468113deae3c033504ab4ff31eb2.tar.gz samba-9220a7bb7ba0468113deae3c033504ab4ff31eb2.tar.bz2 samba-9220a7bb7ba0468113deae3c033504ab4ff31eb2.zip |
r16552: Fix bug 3849.
Added a next_token_no_ltrim() function which does not strip leading separator
characters. The new function is used only where really necessary, even though
it could reasonably be used in many more places, to avoid superfluous code
changes.
Derrell
(This used to be commit d90061aa933f7d8c81973918657dd72cbc88bab5)
-rw-r--r-- | source3/lib/util_str.c | 42 | ||||
-rw-r--r-- | source3/libsmb/libsmbclient.c | 6 |
2 files changed, 38 insertions, 10 deletions
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 6fe1668e88..0248ad63ad 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -29,13 +29,18 @@ **/ /** - * Get the next token from a string, return False if none found. - * Handles double-quotes. - * + * 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 - **/ -BOOL next_token(const char **ptr,char *buff, const char *sep, size_t bufsize) + */ +static BOOL next_token_internal(const char **ptr, + char *buff, + const char *sep, + size_t bufsize, + int ltrim) { char *s; char *pbuf; @@ -51,8 +56,8 @@ BOOL next_token(const char **ptr,char *buff, const char *sep, size_t bufsize) if (!sep) sep = " \t\n\r"; - /* find the first non sep char */ - while (*s && strchr_m(sep,*s)) + /* find the first non sep char, if left-trimming is requested */ + while (ltrim && *s && strchr_m(sep,*s)) s++; /* nothing left? */ @@ -76,6 +81,29 @@ BOOL next_token(const char **ptr,char *buff, const char *sep, size_t bufsize) return(True); } +/* + * Get the next token from a string, return False if none found. Handles + * double-quotes. This version trims leading separator characters before + * looking for a token. + */ +BOOL next_token(const char **ptr, char *buff, const char *sep, size_t bufsize) +{ + return next_token_internal(ptr, buff, sep, bufsize, True); +} + +/* + * Get the next token from a string, return False if none found. Handles + * 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); +} + /** This is like next_token but is not re-entrant and "remembers" the first parameter so you can pass NULL. This is useful for user interface code diff --git a/source3/libsmb/libsmbclient.c b/source3/libsmb/libsmbclient.c index 7f41103e4f..240be50879 100644 --- a/source3/libsmb/libsmbclient.c +++ b/source3/libsmb/libsmbclient.c @@ -359,19 +359,19 @@ smbc_parse_path(SMBCCTX *context, pstring username, passwd, domain; const char *u = userinfo; - next_token(&p, userinfo, "@", sizeof(fstring)); + next_token_no_ltrim(&p, userinfo, "@", sizeof(fstring)); username[0] = passwd[0] = domain[0] = 0; if (strchr_m(u, ';')) { - next_token(&u, domain, ";", sizeof(fstring)); + next_token_no_ltrim(&u, domain, ";", sizeof(fstring)); } if (strchr_m(u, ':')) { - next_token(&u, username, ":", sizeof(fstring)); + next_token_no_ltrim(&u, username, ":", sizeof(fstring)); pstrcpy(passwd, u); |