svn commit: samba r16552 - in branches/SAMBA_3_0/source: lib libsmb

derrell at samba.org derrell at samba.org
Tue Jun 27 03:07:03 GMT 2006


Author: derrell
Date: 2006-06-27 03:07:02 +0000 (Tue, 27 Jun 2006)
New Revision: 16552

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=16552

Log:
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

Modified:
   branches/SAMBA_3_0/source/lib/util_str.c
   branches/SAMBA_3_0/source/libsmb/libsmbclient.c


Changeset:
Modified: branches/SAMBA_3_0/source/lib/util_str.c
===================================================================
--- branches/SAMBA_3_0/source/lib/util_str.c	2006-06-27 02:32:45 UTC (rev 16551)
+++ branches/SAMBA_3_0/source/lib/util_str.c	2006-06-27 03:07:02 UTC (rev 16552)
@@ -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 at VILLAGE.COM. 
  * Extensively modified by Andrew.Tridgell at 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 @@
 	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 @@
 	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

Modified: branches/SAMBA_3_0/source/libsmb/libsmbclient.c
===================================================================
--- branches/SAMBA_3_0/source/libsmb/libsmbclient.c	2006-06-27 02:32:45 UTC (rev 16551)
+++ branches/SAMBA_3_0/source/libsmb/libsmbclient.c	2006-06-27 03:07:02 UTC (rev 16552)
@@ -359,19 +359,19 @@
 		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);
 



More information about the samba-cvs mailing list