r16552: Fix bug 3849.
authorDerrell Lipman <derrell@samba.org>
Tue, 27 Jun 2006 03:07:02 +0000 (03:07 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:19:00 +0000 (11:19 -0500)
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)

source3/lib/util_str.c
source3/libsmb/libsmbclient.c

index 6fe1668e880998c596120a9682321f65d676c0d2..0248ad63ad86441175194a815646a56d29767454 100644 (file)
  **/
 
 /**
- * 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
index 7f41103e4f076656eba11183e430125e8e14dfc0..240be5087910d561adb40d2d42250384aeb40da4 100644 (file)
@@ -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);