Bug 1221 - machines missing in network neighborhood (Bad tokenization in next_token())
machines missing in network neighborhood (Bad tokenization in next_token())
Product: Samba 3.0
Classification: Unclassified
Component: Domain Control
All All
: P3 normal
: none
Assigned To: Jeremy Allison
Samba QA Contact
: 989 1004 1420 (view as bug list)
Depends on:
  Show dependency treegraph
Reported: 2004-03-28 12:47 UTC by Peter Backes
Modified: 2010-04-26 03:30 UTC (History)
3 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Peter Backes 2004-03-28 12:47:18 UTC
I noticed machines with a description that contains one apostrophe (') were
neither displayed in the Windows network neighbourhood nor smbclient -L //PDC
listed them anymore since I updated to samba 3.  

I analyzed the problem.

It traced down to the following change from samba 2.2.x to 3.0 in

-               if (*s == '\"') {
+               if (*s == '\"' || *s == '\'') {
                        quoted = !quoted;
                } else {
                        *pbuf++ = *s;

This function is used in lanman.c:get_server_info(), to
tokenize lines from browse.dat.  My browse.dat contained:

"KANGAROO"                40011003 "Peter's Workstation"         "MAIN"

This caused the line to be tokenized incorrectly into <KANGAROO> <40011003> 
<Peters> <Workstation         MAIN> instead of <KANGAROO> <40011003> <Peter's
Workstation> <MAIN>.  This caused !strequal(domain, s->domain) (ie
!strequal("MAIN", "Workstation         MAIN")) in lanman.c:get_server_info() to
be true, so it set ok = False, which finally caused the entry to be omitted from
the server list.

This bug might cause other severe problems in code that uses next_token().


a) investigate if ' is really required as a quote char.
b) if yes, make sure ' is only balanced by another ', not ", and " only
by ", not ', for example (code has not been tested):

-       BOOL quoted;	
+       int qchar = 0;


-               if (*s == '\"' || *s == '\'') {
-                       quoted = !quoted;
+               if ((*s == '\"' || *s == '\'') && (!qchar || qchar == *s)) {
+                       qchar = !qchar ? *s : 0;
                } else {
                        *pbuf++ = *s;

c) if no, revert back to 2.2 code:

-               if (*s == '\"' || *s == '\'') {
+               if (*s == '\"') {
                        quoted = !quoted;
                } else {
                        *pbuf++ = *s;

The workaround is, of course, to remove ' characters from machine descriptions.
Comment 1 Gerald (Jerry) Carter 2004-03-31 07:22:06 UTC
*** Bug 1004 has been marked as a duplicate of this bug. ***
Comment 2 Gerald (Jerry) Carter 2004-04-22 20:14:34 UTC
*** Bug 989 has been marked as a duplicate of this bug. ***
Comment 3 Gerald (Jerry) Carter 2004-06-04 09:40:48 UTC
*** Bug 1420 has been marked as a duplicate of this bug. ***
Comment 4 Gerald (Jerry) Carter 2004-06-08 12:51:38 UTC
I'm reverting the original change to next_token()
and changing print_parameter() to surround values in 
a list with " "s rather than ' 's.  I think this is the
easiest solution.
Comment 5 Peter Backes 2004-06-08 15:38:02 UTC
Only fixes the single quote instance of the bug.  If I change the name of my
computer to Peter"s Workstation (with double instead of single quoted) the
problem reappears.  A possible solution is to escape the quotes ala Peter\"s
workstation before writing wins.dat and then unescaping in
Comment 6 Adam Lebsack 2004-08-20 08:38:37 UTC
I've been having a single quote problem with smbclient 3.0.2a, similar to this.
 If I try to do any operations (ls, get, cd, etc) on a file whose name contains
a single quote in the interactive smbclient, the interpreter discards my single
quote.  I can't seem to make any way of escaping it work. I've tried the
backslash, enclosing it in double quotes, everything I can think of. The patch
listed here seems to fix the problem, but I'm not sure what else it might break.
Comment 7 Gerald (Jerry) Carter 2004-08-25 07:51:27 UTC
jeremy, still want to fix this?  Thanks.
Comment 8 Adam Lebsack 2005-01-31 09:59:28 UTC
Can we get this bug fix into the next release?  I have software that uses
smbclient and depends on this fix, so it's kind of a pain when I have to patch
smbclient on every host I install my software on.
Comment 9 Stefan Metzmacher 2010-04-26 03:30:58 UTC
If it's still broken in 3.5, please reopen.
3.0 isn't supported anymore.