use of trim_string() in param/loadparms.c:lp_string() ?

Steve Langasek vorlon at
Wed Aug 22 00:00:31 GMT 2001

Hi all,

In pondering the bug report of a Debian user who finds that

  lpq command = lpq -P"%p"

doesn't work for printer names with whitespace because the trailing
double-quote is being stripped, I hoped I would be able to track it down to a
simple bug.  Instead, I found that the code is deliberately stripping leading
and trailing double-quotes on string parameters in the lp_string() function.

The cvs log for param/loadparms.c turned up this entry:

revision 1.57
date: 1997/10/16 03:53:07;  author: tridge;  state: Exp;  lines: +2 -0
fixed the problem that browsing breaks if you put quote marks around
the server string option.

I fixed it by adding: trim_string(ret, "\"", "\"") to lp_string()
which means that it removes leading and trailing quotes from _all_
strings in smb.conf. I think this is what we want as I can't actually
think of any case where quoted strings are needed.

I suspect that this fix will actually fix browsing at quite a few
sites. It's not uncommon to see people putting "" marks around the
workgroup name or other essential strings.

The real reason it was causing browsing to fail is that the browse.dat
file uses " to delimit fields, which means that it wasn't being parsed
correctly. It would be nice to use a proper database format in
browse.dat sometime. In fact, we really need a generic database type
subsystem in Samba to replace the mish-mash we currrently use
(browse.dat, wins.dat, smbpasswd etc)


So, four years later, I definitely have a case where quoted strings are
needed. :)  We also have a generic database subsystem now, although nmbd still
uses browse.dat and wins.dat instead of tdb.

A workaround here might be to use a simple heuristic -- use trim_string(),
then check if the resulting string still contains any double-quotes; if it
does, restore the original string.

Other solutions might be to support optional shell escaping for strings being
substituted, or to switch to using tdb for browse.dat and remove the
trim_string() entirely.  The bug submitter offered the workaround of

  lpq command =  lpq -P"%p" --

which I don't find particularly appealing; certainly not as a default, which
means Samba's default lpq command can't be fixed to support printer names with
spaces in them.

Does anyone have any comments on this before I start writing code to implement
solution #1?

Steve Langasek
postmodern programmer

More information about the samba-technical mailing list