1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
7 <title>User service daemon and client specification - Service-side configuration</title>
15 [<a href="ch-envir.html">back</a>]
16 [<a href="index.html#abstract">Abstract</a>]
17 [<a href="index.html#copyright">Copyright Notice</a>]
18 [<a href="index.html#contents">Contents</a>]
19 [<a href="ch-ipass.html">next</a>]
24 User service daemon and client specification - Chapter 4<br>
25 Service-side configuration
31 Which services may be run by whom and under what conditions is
32 controlled by configuration files.
36 The daemon will read these files in order. Certain directives in the
37 files modify the daemon's execution settings for invoking the service,
38 for example allowing certain file descriptors to be specified by the
39 client or specifying which program to execute to provide the service.
43 The <em>last</em> instance of each such setting will take effect. The
44 directives which specify which program to execute will not stop the
45 configuration file from being read; they will be remembered and will
46 only take effect if they are not overridden by a later directive.
50 The daemon will first read <samp>/etc/userv/system.default</samp>. Then, by
51 default (this behaviour may be modified), it will read a per-user file
52 <samp>~/.userv/rc</samp>, if it exists and the service user's shell is in
53 <samp>/etc/shells</samp>. Finally it will read
54 <samp>/etc/userv/system.override</samp>.
58 When it has read all of these files it will act according to the
59 currently values of of the execution settings.
65 <a name="s4.1">4.1 Configuration file syntax</a>
69 The configuration file is a series of directives, usually one per
70 line. The portion of a line following a hash character <samp>#</samp> is
71 taken as a comment and ignored. Each directive consists of a series
72 of tokens separated by linear whitespace (spaces and tabs); tokens may
73 be words consisting of non-space characters, or, where a string is
74 required, a string in double quotes. Double-quoted strings may
75 contain the following backslash escapes:
78 <dt><samp>\n</samp><dd>newline
80 <dt><samp>\t</samp><dd>tab
82 <dt><samp>\r</samp><dd>carriage return
84 <dt><samp>\<var>OOO</var></samp><dd>character whose octal code is <var>OOO</var>
86 <dt><samp>\x<var>XX</var></samp><dd>character whose hex code is <var>XX</var>
88 <dt><samp>\<var>punctuation</var></samp><dd>literal punctuation character (eg <samp>\\</samp>, <samp>\"</samp>)
90 <dt><samp>\<var>newline</var></samp> (ie, backslash at end of line)<dd>string continues on next line
96 Relative pathnames in directives are relative to the service program's
97 current directory (usually the service user's home directory).
98 Pathnames starting with the two characters <samp>~/</samp> are taken to be
99 relative to the service user's home directory.
105 <a name="s-directives">4.2 Configuration file directives</a>
111 <a name="s-dirs-immediate">4.2.1 Immediate directives</a>
115 The following directives take effect immediately:
118 <p><dt><samp>cd <var>pathname</var></samp><dd>Change directory in the service program. <code>cd</code> is cumulative. It
119 is an error if the directory cannot be changed to.
121 <code>cd</code> should not be used between <code>execute-from-directory</code> and
122 the invocation of the service program, as the test for the
123 availability of the service program would be done with the old current
124 directory and the actual execution with the new (probably causing an
127 <p><dt><samp>eof</samp><dd>Stop reading the configuration file in question, as if end of file had
128 been reached. Any control constructs (<code>if</code>, <code>catch-quit</code> or
129 <code>errors-push</code>) which were started in that file will be considered
130 finished. Parsing will continue in the file which caused the file
131 containing the <code>eof</code> to be read.
133 <p><dt><samp>quit</samp><dd>Stop reading configuration files and act immediately on the current
134 settings. The behaviour of <code>quit</code> is subject to the
135 <code>catch-quit</code> control construct.
137 <p><dt><samp>include <var>filename</var></samp><p><dt><samp>include-ifexist <var>filename</var></samp><dd>Read the configuration file <var>filename</var>, and then return to this
138 file and continue parsing it with the next directive. It is an error
139 if the file cannot be opened and read, unless <code>include-ifexist</code>
140 is used and the file does not exist, in which case the directive is
143 <p><dt><samp>include-lookup <var>parameter</var> <var>directory</var></samp><p><dt><samp>include-lookup-all <var>parameter</var> <var>directory</var></samp><dd>Read the configuration file in <var>directory</var> whose name is the value
144 of <var>parameter</var> (see the description of <code>if</code>, <a href="#s-dirs-control">Control structure directives, subsection 4.2.3</a>). If <var>parameter</var> has several values they will
145 be tried in order; with <code>include-lookup</code> this search will stop
146 when one is found, but with <code>include-lookup-all</code> the search will
147 continue and any files appropriate to other values will be read too.
149 If none of the parameter's values had a corresponding file then the
150 file <samp>:default</samp> will be read, if it exists. If <var>parameter</var>'s
151 list of values was empty then the file <samp>:none</samp> will be tried first
152 and read if it exists, otherwise <samp>:default</samp> will be tried.
154 It is not an error for any of the files (including <samp>:default</samp>) not
155 to exist, but it is an error if a file exists and cannot be read or if
156 the directory cannot be accessed.
158 A translation will be applied to values before they are used to
159 construct a filename, so that the lookup cannot access dotfiles or
160 files in other directories: values starting with full stops will have
161 a colon prepended (making <samp>:.</samp>), colons will be doubled, and each
162 slash will be replaced with a colon followed by a hyphen <samp>:-</samp>. A
163 parameter value which is the empty string will be replaced with
164 <samp>:empty</samp> (note that this is different from a parameter not having
167 <p><dt><samp>include-directory <var>directory</var></samp><dd>Read configuration from all files in directory <var>directory</var> which
168 are plain files whose names consist only of alphanumerics and hyphens
169 and start with an alphanumeric. They will be read in lexical order.
170 It is an error for the directory not to exist or for it or any of the
171 files found not to be read successfully, or for anything with an
172 appropriate name not to be a plain file or a symbolic link to a plain
175 <p><dt><samp>error <var>text ...</var></samp><dd>Causes an error whose message includes the descriptive string
176 <var>text</var>. <var>text</var> may consist of several tokens with intervening
177 whitespace. The whitespace will be included in the message as found
178 in the configuration file: all the characters until the end of the
179 line will be included verbatim, unless they are part of a
180 double-quoted string, in which case the usual meaning of the string
181 (i.e., after backslash escape processing) will be used. Comments and
182 linear whitespace at the end of the line (or just before the comment)
183 will still be ignored.
185 <p><dt><samp>message <var>text ...</var></samp><dd>Causes a message including the descriptive string <var>text</var> to be
186 delivered as if it were an error message, but does not actually cause
195 <a name="s-dirs-delayed">4.2.2 Directives with delayed effect</a>
199 The following directives have no immediate effect, but are remembered
200 and have an effect on later processing of the configuration files.
203 <p><dt><samp>user-rcfile <var>filename</var></samp><dd>Specifies that the file <var>filename</var> should be read instead of the
204 user's <samp>~/.userv/rc</samp>. This does <em>not</em> happen immediately;
205 instead, the setting is remembered and used after the
206 <code>system.default</code> configuration file has been read. This
207 directive has no effect in a user's configuration file or in the
208 <code>system.override</code> file, as the user's configuration file has
209 already been found and read by then and will not be re-read.
211 <p><dt><samp>errors-to-stderr</samp><dd>Causes error messages to be delivered to the client's stderr.
213 <p><dt><samp>errors-to-file</samp> <var>filename</var><dd>Error messages will be written to <var>filename</var>, which will be opened
214 in the context of and with the privileges of the service user.
216 <p><dt><samp>errors-to-syslog</samp> [<var>facility</var> [<var>level</var>]]<dd>Error messages will be delivered using <code>syslog</code>. The default
217 <var>facility</var> is <samp>user</samp>; the default <var>level</var> is <samp>error</samp>.
225 <a name="s-dirs-control">4.2.3 Control structure directives</a>
229 The following directives are used to create control structures. If
230 the end of the file is encountered before the end of any control
231 structure which was started inside it then that control structure is
232 considered finished. This is not an error.
235 <p><dt><samp>if <var>condition</var></samp><p><dt><samp>elif <var>condition</var></samp><p><dt><samp>else</samp><p><dt><samp>fi</samp><dd>Lines following <code>if</code> are interpreted only if the condition is
236 true. Many conditions are properties of parameter values. Most
237 parameters have a single string as a value; however, some may yield
238 zero or several strings, in which case the condition is true if it is
239 true of any of the strings individually. Parameters are described
246 <dt><samp>glob <var>parameter</var> <var>glob-pattern</var> ...</samp><dd>The value of the parameter whose name is given matches one of the glob
247 patterns (anchored at both ends; backslashes can be used to escape
250 <dt><samp>range <var>parameter</var> <var>min</var> <var>max</var></samp><dd>The value of the parameter is a nonnegative integer and lies within
251 the range specified. <var>min</var> or <var>max</var> may be <samp>$</samp> to indicate
252 no lower or upper limit, respectively.
254 <dt><samp>grep <var>parameter</var> <var>filename</var></samp><dd>The <var>filename</var> refers to a file one of whose lines is the value of
255 the parameter (leading or trailing whitespace on each line and empty
256 lines in the file are ignored). It is an error for the file not to be
259 <dt><samp>! <var>condition</var></samp><dd>The <var>condition</var> is <em>not</em> true.
261 <dt>Conjunctions: <samp>&</samp> and <samp>|</samp><dd><pre>
262 ( <var>condition</var>
263 & <var>condition</var>
264 & <var>condition</var>
269 is true if all the listed conditions are true; where <samp>|</samp> is used it
270 is true if any of them is true. Newlines must be used to separate one
271 condition from the next, as shown, and the parentheses are mandatory.
272 These conjunctions do not do lazy evaluation.
281 <dt><samp>service</samp><dd>The service name specified when the client was called.
283 <dt><samp>calling-user</samp><dd>Two strings: the login name of the calling user (determined as for
284 <code>USERV_USER</code>, above) and the calling uid (represented in
287 <dt><samp>calling-group</samp><dd>Several strings: the primary and supplementary group names and gids
288 (in decimal) of the calling process. All the group names come first,
289 and then the gids. If the first supplementary group is the same as
290 the primary group then it is elided.
292 <dt><samp>calling-user-shell</samp><dd>The calling user's shell, as listed in the password entry for the
293 calling login name (as determined for <code>USERV_USER</code>, above).
295 <dt><samp>service-user</samp><dd>Two strings: the name of the service user (as specified to the client)
296 and their uid (represented in decimal).
298 <dt><samp>service-group</samp><dd>Several strings: the primary and supplementary group names and gids
299 (in decimal) of the service user.
301 <dt><samp>service-user-shell</samp><dd>The service user's shell, as listed in their password entry.
303 <dt><samp>u-<var>name</var></samp><dd>The value of the user-defined variable <var>name</var> passed by the caller
304 using the <code>--defvar</code> command-line option to the client. If the
305 variable was not defined then this parameter is an empty list of
306 strings; in this case any condition which tests it will be false, and
307 <samp>include-lookup</samp> on it will read the <samp>:none</samp> file, or
308 <samp>:default</samp> if <samp>:none</samp> is not found.
313 <dt><samp>errors-push</samp> <var>filename</var><dt><samp>srorre</samp><dd>Stacks the error handling behaviour currently in effect. Any changes
314 to error handling will take effect only between <code>errors-push</code> and
317 <dt><samp>catch-quit</samp><dt><samp>hctac</samp><dd>Any use of <code>quit</code> inside <code>catch-quit</code> will merely cause the
318 parsing to continue at <code>hctac</code> instead. Any control constructs
319 started since the <code>catch-quit</code> will be considered finished if a
320 <code>quit</code> is found.
322 If an error occurs inside <code>catch-quit</code> the execution settings
323 will be reset (as if by the <code>reset</code> directive) and parsing will
324 likewise continue at <code>hctac</code>.
326 If a lexical or syntax error is detected in the same configuration
327 file as the <code>catch-quit</code>, while looking for the <code>hctac</code>
328 after an error or <code>quit</code>, that new error will not be caught.
336 <a name="s-dirs-execution">4.2.4 Directives for changing execution settings</a>
340 The following directives modify the execution settings; the server
341 will remember the fact that the directive was encountered and act on
342 it only after all the configuration has been parsed. The <em>last</em>
343 directive which modifies any particuar setting will take effect.
346 <p><dt><samp>reject</samp><dd>Reject the request. <code>execute</code>, <code>execute-from-directory</code> and
347 <code>execute-from-path</code> will change this setting.
349 <p><dt><samp>execute <var>program</var> [<var>argument</var> ...]</samp><dd>Execute the program <var>program</var>, with the arguments as specified,
350 followed by any arguments given to the client if
351 <code>no-suppress-args</code> is in effect. It is an error for the
352 execution to fail when it is attempted (after all the configuration
353 has been parsed). If <var>program</var> does not contain a slash it will
354 be searched for on the service user's path.
356 <p><dt><samp>execute-from-directory <var>pathname</var> [<var>argument</var> ...]</samp><dd>Take all the characters after the last slash of the service name
357 specified when the client was called, and execute that program in the
358 directory named by <var>pathname</var> as if it had been specified for
359 <var>execute</var>. The part of the service name used may contain only
360 alphanumerics and hyphens and must start with an alphanumeric (and it
361 must be non-empty), otherwise it is an error.
363 This directive is ignored if the relevant program does not exist in
364 the directory specified; in this case the program to execute is left
365 at its previous setting (or unset, if it was not set before).
367 It is an error for the test for the existence of the program to fail
368 other than with a `no such file or directory' indication. It is also
369 an error for the execution to fail if and when it is attempted (after
370 all the configuration has been parsed).
372 <p><dt><samp>execute-from-path</samp><dd><var>service</var> is interpreted as a program on the default <code>PATH</code>
373 (or as a pathname of an executable, if it contains a <samp>/</samp>). This
374 directive is <em>very dangerous</em>, and is only provided to make the
375 <code>--override</code> options effective. It should not normally be used.
376 It is an error for the execution to fail when it is attempted (after
377 all the configuration has been parsed).
379 <p><dt><samp>execute-builtin <var>service-name</var> <var>service-arguments</var></samp><dd><p>
380 Executes the builtin service <var>service-name</var>. These builtin
381 services display information about the server and/or the request, and
382 ignore any arguments passed from the service side except possibly to
383 print them as part of their output. They write their results to their
384 standard output (i.e., wherever file descriptor 1 is directed). The
385 builtin services are:
388 <dt><samp>execute</samp><dd>Displays the execution settings, defined variables,
389 arguments, etc. with which the builtin service was invoked.
391 <dt><samp>environment</samp><dd>Displays the environment variable settings with which the builtin
394 <dt><samp>parameter <var>parameter</var></samp><dd>Displays the values of the service configuration language parameter
397 <dt><samp>version</samp><dd>Displays the version string and compilation details of the uservd
400 <dt><samp>reset</samp><dd>Displays the default reset configuration (evaluated when <code>reset</code>
401 is found in a configuration file, or when an error is caught by
402 <code>catch-quit</code>).
404 <dt><samp>toplevel</samp><dd>Displays the top-level default configuration (the configuration data,
405 evaluated by the server, which calls all the other configuration
408 <dt><samp>override</samp><dd>Displays the top-level override configuration (the configuration data,
409 evaluated by the server, which causes all the other configuration data
412 <dt><samp>help</samp><dd>Displays a list of the understood builtin service names and arguments.
417 In the future other builtin services may be defined which do more than
418 just print information.
421 <dt><samp>set-environment</samp><dt><samp>no-set-environment</samp><dd>Runs <samp>/etc/environment</samp> to set the service user's environment.
422 This adds the overhead of invoking a shell, but doesn't cause any
423 shell (de)mangling of the service's arguments. This is achieved by
426 .../program arg arg arg ...
431 /bin/sh -c '. /etc/environment; exec "$@"' - .../program arg arg arg ...
434 <code>no-set-environment</code> cancels the effect of
435 <code>set-environment</code>.
437 <dt><samp>no-suppress-args</samp><dt><samp>suppress-args</samp><dd>Include any arguments given to the client as arguments to the program
438 invoked as a result of an <code>execute</code>,
439 <code>execute-from-directory</code> or <code>execute-from-path</code> directive.
440 <code>suppress-args</code> undoes the effect of <code>no-suppress-args</code>.
442 <dt><samp>require-fd <var>fd-range</var> read|write</samp><dd>Insist that the filedescriptor(s) be opened for reading resp. writing.
443 It is an error if any descriptor marked as required when the service
444 is about to be invoked (after the configuration has been parsed) was
445 not specified when the client was invoked. Each file descriptor has a
446 separate setting, and the last one of <code>require-fd</code>,
447 <code>allow-fd</code>, <code>ignore-fd</code>, <code>null-fd</code> or <code>reject-fd</code>
448 which affected a particular file descriptor will take effect.
450 <var>fd-range</var> may be a single number, two numbers separated by a
451 hyphen, or one number followed by a hyphen (indicating all descriptors
452 from that number onwards). It may also be one of the words
453 <samp>stdin</samp>, <samp>stdout</samp> or <samp>stderr</samp>. Open-ended file descriptor
454 rangers are allowed only with <code>reject-fd</code> and <code>ignore-fd</code>,
455 as otherwise the service program would find itself with a very large
456 number of file descriptors open.
458 When the configuration has been parsed, and before the service is
459 about to be executed, stderr (fd 2) must be required or allowed
460 (<code>require-fd</code> or <code>allow-fd</code>) for writing; this is so that
461 the error message printed by the server's child process if it cannot
462 <code>exec</code> the service program is not lost.
464 <dt><samp>allow-fd <var>fd-range</var> [read|write]</samp><dd>Allow the descriptor(s) to be opened for reading resp. writing, or
465 either if neither <samp>read</samp> nor <samp>write</samp> is specified. If a
466 particular descriptor not specified by the client then it will be open
467 onto <samp>/dev/null</samp> (for reading, writing, or both, depending on
468 whether <samp>read</samp>, <samp>write</samp> or neither was specified).
470 <dt><samp>null-fd <var>fd-range</var> [read|write]</samp><dd>Specify that the descriptor(s) be opened onto <code>/dev/null</code> for
471 reading resp. writing, or both if neither <samp>read</samp> nor <samp>write</samp>
472 is specified. Any specification of these file descriptors by the
473 client will be silently ignored; the client will see its ends of the
474 descriptors being closed immediately.
476 <dt><samp>reject-fd <var>fd-range</var></samp><dd>Do not allow the descriptor(s) to be specified by the client. It is
477 an error if any descriptor(s) marked for rejection are specified when
478 the service is about to be invoked (after the configuration has been
481 <dt><samp>ignore-fd <var>fd-range</var></samp><dd>Silently ignore any specification by the client of those
482 descriptor(s). The pipes corresponding to these descriptors will be
483 closed just before the service is invoked.
485 <dt><samp>disconnect-hup</samp><dt><samp>no-disconnect-hup</samp><dd>Causes the service's process group to get a <code>SIGHUP</code> if the
486 client disconnects before the main service process terminates.
487 <code>no-disconnect-hup</code> cancels <code>disconnect-hup</code>.
489 If one of the reading descriptors specified when the client is called
490 gets a read error, or if the service is disconnected for some other
491 reason, then the <code>SIGHUP</code> will be delivered <em>before</em> the
492 writing end(s) of the service's reading pipe(s) are closed, so that
493 the client can distinguish disconnection from reading EOF on a pipe.
495 <dt><samp>reset</samp><dd>Resets the execution settings to the default. This is equivalent to:
510 If no <code>execute</code>, <code>execute-from-path</code>,
511 <code>execute-from-directory</code> or <code>builtin</code> is interpreted before
512 all the files are read then the request is rejected.
518 <a name="s-configerrors">4.3 Errors in the configuration file</a>
522 If a syntax error or other problem occurs when processing a
523 configuration file then a diagnostic will be issued, to wherever the
524 error messages are currently being sent (see the <code>errors-</code> family
525 of directives, above).
529 The error will cause processing of the configuration files to cease at
530 that point, unless the error was inside a <code>catch-quit</code> construct.
531 In this case the settings controlling the program's execution will be
532 reset to the defaults as if a <code>reset</code> directive had been issued,
533 and parsing continues after <code>hctac</code>.
539 <a name="s-defaults">4.4 Defaults</a>
543 The default configuration processing is as if the daemon were parsing
544 an overall configuration file whose contents were as follows:
548 user-rcfile ~/.userv/rc
550 include /etc/userv/system.default
551 if grep service-user-shell /etc/shells
554 include-ifexist <var>file specified by most recent user-rcfile directive</var>
558 include /etc/userv/system.override
564 If one of the <code>--override</code> options to the client is used then it
565 will instead be as if the daemon were parsing an overall configuration
571 include <var>file containing configuration data sent by client</var>
578 [<a href="ch-envir.html">back</a>]
579 [<a href="index.html#abstract">Abstract</a>]
580 [<a href="index.html#copyright">Copyright Notice</a>]
581 [<a href="index.html#contents">Contents</a>]
582 [<a href="ch-ipass.html">next</a>]
586 User service daemon and client specification<br>
590 Ian Jackson <a href="mailto:ian@davenant.greenend.org.uk">ian@davenant.greenend.org.uk</a>