summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/lib/util_str.c42
-rw-r--r--source3/libsmb/libsmbclient.c6
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);