How to put quoted parameters into parameter strings!

John Trostel jtrostel at connex.com
Mon Mar 5 19:57:32 GMT 2001


Maybe this need to be in the FAQs or the manual:

To use spaces in the valid users list, or probably any other list in the
smb.conf files, you need to make sure that the quotes don't get eaten by
load_param.c

To use spaces in user names, I CAN do the following:

valid users = " "one" "two" "name three" "

or 

valid users = one "name two" three

or

valid users = " one two "name three" "

Note the '"' and then the ' ' at the front and the ' ' and then the '"' at the
end.  These are critical.  The two functions involved are 'next_token' and
'trim_string', in lib/util_str.c

The token reading function, next_token, pulls out the names enclosed inside the
quotes quite nicely.  So a list like:

one "name two" three "name four" 

will get correctly parsed into

one
name two
three
name four

The problem came because the load_param function, called to parse the smb.c
onf file, calls 'trim_string', which chops leading and trailing quotes from a
parameter string. (And that needs to stay.) If I tried to write the valid users
list as:

valid users = "one" "name two"

I'd get

one" "name two

as the list sent to next_token.... not what I really wanted.

Using

valid users = ""one" "name two""

doesn't help because trim_string needs something _other_ than a '"' to stop it
at the front and back of the parameter strings.  I'd get the following from
that string.

one" "name two

A quote-space, '" ', at the front and a space-quote, ' "', at the end of the
parameter string do the trick.  They satisfy the quote munching of trim_string
and preserve the internal quoted parameters I really want.

The bottom line is: keep the code the same and delimit with spaces if you want
(or your old conf files have them), but use this method if you want to use
spaces internally.

P.S.  Are there other parameter strings that can use quoted entries with spaces
in them?

-- 
John M. Trostel
Linux OS Engineer
Connex
jtrostel at connex.com




More information about the samba-technical mailing list