1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <!DOCTYPE chapter PUBLIC "-//Samba-Team//DTD DocBook V4.2-Based Variant V1.0//EN" "http://www.samba.org/samba/DTD/samba-doc">
6 <firstname>Chris</firstname><surname>Hertel</surname>
8 <pubdate>November 1997</pubdate>
11 <title>The smb.conf file</title>
14 <title>Lexical Analysis</title>
17 Basically, the file is processed on a line by line basis. There are
18 four types of lines that are recognized by the lexical analyzer
24 Blank lines - Lines containing only whitespace.
27 Comment lines - Lines beginning with either a semi-colon or a
28 pound sign (';' or '#').
31 Section header lines - Lines beginning with an open square bracket ('[').
34 Parameter lines - Lines beginning with any other character.
35 (The default line type.)
40 The first two are handled exclusively by the lexical analyzer, which
41 ignores them. The latter two line types are scanned for
57 These are the only tokens passed to the parameter loader
58 (loadparm.c). Parameter names and values are divided from one
59 another by an equal sign: '='.
63 <title>Handling of Whitespace</title>
66 Whitespace is defined as all characters recognized by the isspace()
67 function (see ctype(3C)) except for the newline character ('\n')
68 The newline is excluded because it identifies the end of the line.
73 The lexical analyzer scans past white space at the beginning of a line.
77 Section and parameter names may contain internal white space. All
78 whitespace within a name is compressed to a single space character.
82 Internal whitespace within a parameter value is kept verbatim with
83 the exception of carriage return characters ('\r'), all of which
88 Leading and trailing whitespace is removed from names and values.
96 <title>Handling of Line Continuation</title>
99 Long section header and parameter lines may be extended across
100 multiple lines by use of the backslash character ('\\'). Line
101 continuation is ignored for blank and comment lines.
105 If the last (non-whitespace) character within a section header or on
106 a parameter line is a backslash, then the next line will be
107 (logically) concatonated with the current line by the lexical
108 analyzer. For example:
111 <para><programlisting>
112 param name = parameter value string \
113 with line continuation.
114 </programlisting></para>
116 <para>Would be read as</para>
118 <para><programlisting>
119 param name = parameter value string with line continuation.
120 </programlisting></para>
123 Note that there are five spaces following the word 'string',
124 representing the one space between 'string' and '\\' in the top
125 line, plus the four preceeding the word 'with' in the second line.
126 (Yes, I'm counting the indentation.)
130 Line continuation characters are ignored on blank lines and at the end
131 of comments. They are *only* recognized within section and parameter
138 <title>Line Continuation Quirks</title>
140 <para>Note the following example:</para>
142 <para><programlisting>
143 param name = parameter value string \
145 with line continuation.
146 </programlisting></para>
149 The middle line is *not* parsed as a blank line because it is first
150 concatonated with the top line. The result is
153 <para><programlisting>
154 param name = parameter value string with line continuation.
155 </programlisting></para>
157 <para>The same is true for comment lines.</para>
159 <para><programlisting>
160 param name = parameter value string \
163 </programlisting></para>
165 <para>This becomes:</para>
167 <para><programlisting>
168 param name = parameter value string ; comment with a comment.
169 </programlisting></para>
172 On a section header line, the closing bracket (']') is considered a
173 terminating character, and the rest of the line is ignored. The lines
176 <para><programlisting>
177 [ section name ] garbage \
179 </programlisting></para>
181 <para>are read as</para>
183 <para><programlisting>
186 </programlisting></para>
192 <title>Syntax</title>
194 <para>The syntax of the smb.conf file is as follows:</para>
196 <para><programlisting>
197 <file> :== { <section> } EOF
198 <section> :== <section header> { <parameter line> }
199 <section header> :== '[' NAME ']'
200 <parameter line> :== NAME '=' VALUE NL
201 </programlisting></para>
203 <para>Basically, this means that</para>
207 a file is made up of zero or more sections, and is terminated by
208 an EOF (we knew that).
212 A section is made up of a section header followed by zero or more
217 A section header is identified by an opening bracket and
218 terminated by the closing bracket. The enclosed NAME identifies
223 A parameter line is divided into a NAME and a VALUE. The *first*
224 equal sign on the line separates the NAME from the VALUE. The
225 VALUE is terminated by a newline character (NL = '\n').
231 <title>About params.c</title>
234 The parsing of the config file is a bit unusual if you are used to
235 lex, yacc, bison, etc. Both lexical analysis (scanning) and parsing
236 are performed by params.c. Values are loaded via callbacks to