chiark / gitweb /
@@ -1,9 +1,11 @@
[userv.git] / spec.html / ch-config.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2
3 <html>
4
5 <head>
6
7 <title>User service daemon and client specification - Service-side configuration</title>
8
9 </head>
10
11 <body>
12
13 <hr>
14
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>]
20
21 <hr>
22
23 <h1>
24 User service daemon and client specification - Chapter 4<br>
25 Service-side configuration
26 </h1>
27
28 <hr>
29
30 <p>
31 Which services may be run by whom and under what conditions is
32 controlled by configuration files.
33 </p>
34
35 <p>
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.
40 </p>
41
42 <p>
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.
47 </p>
48
49 <p>
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>.
55 </p>
56
57 <p>
58 When it has read all of these files it will act according to the
59 currently values of of the execution settings.
60 </p>
61
62 <hr>
63
64 <h2>
65 <a name="s4.1">4.1 Configuration file syntax</a>
66 </h2>
67
68 <p>
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 (except backslash), or,
74 where a string is required, a string in double quotes.  Double-quoted
75 strings may contain the following backslash escapes:
76
77 <dl compact>
78 <dt><samp>\n</samp><dd>newline
79
80 <dt><samp>\t</samp><dd>tab
81
82 <dt><samp>\r</samp><dd>carriage return
83
84 <dt><samp>\<var>OOO</var></samp><dd>character whose octal code is <var>OOO</var>
85
86 <dt><samp>\x<var>XX</var></samp><dd>character whose hex code is <var>XX</var>
87
88 <dt><samp>\<var>punctuation</var></samp><dd>literal punctuation character (eg <samp>\\</samp>, <samp>\&quot;</samp>)
89
90 <dt><samp>\<var>newline</var></samp> (ie, backslash at end of line)<dd>string continues on next line
91
92 </dl>
93 </p>
94
95 <p>
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.
100 </p>
101
102 <p>
103 Logical lines may be continued by putting a backslash <samp>\</samp> at the
104 end of a line; this counts as part of linear whitespace.
105 </p>
106
107 <hr>
108
109 <h2>
110 <a name="s-directives">4.2 Configuration file directives</a>
111 </h2>
112
113 <hr>
114
115 <h3>
116 <a name="s-dirs-immediate">4.2.1 Immediate directives</a>
117 </h3>
118
119 <p>
120 The following directives take effect immediately:
121
122 <dl>
123 <p><dt><samp>cd <var>pathname</var></samp><dd>Change directory in the service program.  <code>cd</code> is cumulative.  It
124 is an error if the directory cannot be changed to.
125
126 <code>cd</code> should not be used between <code>execute-from-directory</code> and
127 the invocation of the service program, as the test for the
128 availability of the service program would be done with the old current
129 directory and the actual execution with the new (probably causing an
130 error).
131
132 <p><dt><samp>eof</samp><dd>Stop reading the configuration file in question, as if end of file had
133 been reached.  Any control constructs (<code>if</code>, <code>catch-quit</code> or
134 <code>errors-push</code>) which were started in that file will be considered
135 finished.  Parsing will continue in the file which caused the file
136 containing the <code>eof</code> to be read.
137
138 <p><dt><samp>quit</samp><dd>Stop reading configuration files and act immediately on the current
139 settings.  The behaviour of <code>quit</code> is subject to the
140 <code>catch-quit</code> control construct.
141
142 <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
143 file and continue parsing it with the next directive.  It is an error
144 if the file cannot be opened and read, unless <code>include-ifexist</code>
145 is used and the file does not exist, in which case the directive is
146 silently ignored.
147
148 <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
149 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
150 be tried in order; with <code>include-lookup</code> this search will stop
151 when one is found, but with <code>include-lookup-all</code> the search will
152 continue and any files appropriate to other values will be read too.
153
154 If none of the parameter's values had a corresponding file then the
155 file <samp>:default</samp> will be read, if it exists.  If <var>parameter</var>'s
156 list of values was empty then the file <samp>:none</samp> will be tried first
157 and read if it exists, otherwise <samp>:default</samp> will be tried.
158
159 It is not an error for any of the files (including <samp>:default</samp>) not
160 to exist, but it is an error if a file exists and cannot be read or if
161 the directory cannot be accessed.
162
163 A translation will be applied to values before they are used to
164 construct a filename, so that the lookup cannot access dotfiles,
165 backup files, files in other directories and the like: each slash will
166 be replaced with a colon followed by a hyphen <samp>:-</samp>, and all
167 characters which are not lowercase alphanumerics, hyphens or
168 underscores will have a colon prepended (so that colons are doubled).
169 A parameter value which is the empty string will be replaced with
170 <samp>:empty</samp> (note that this is different from a parameter not having
171 any values).
172
173 <p><dt><samp>include-directory <var>directory</var></samp><dd>Read configuration from all files in directory <var>directory</var> which
174 are plain files whose names consist only of alphanumerics and hyphens
175 and start with an alphanumeric.  They will be read in lexical order.
176 It is an error for the directory not to exist or for it or any of the
177 files found not to be read successfully, or for anything with an
178 appropriate name not to be a plain file or a symbolic link to a plain
179 file.
180
181 <p><dt><samp>error <var>text ...</var></samp><dd>Causes an error whose message includes the descriptive string
182 <var>text</var>.  <var>text</var> may consist of several tokens with intervening
183 linear whitespace.  Each set of linear whitespace will appear in the
184 message as a single space.  The usual meaning of double-quoted strings
185 (i.e., after backslash escape processing) will be used.  Comments and
186 linear whitespace at the end of the line (or just before the comment)
187 will still be ignored.  Apart from those cases, each token's text will
188 be included verbatim.
189
190 <p><dt><samp>message <var>text ...</var></samp><dd>Causes a message including the descriptive string <var>text</var> to be
191 delivered as if it were an error message, but does not actually cause
192 an error.
193
194 </dl>
195 </p>
196
197 <hr>
198
199 <h3>
200 <a name="s-dirs-delayed">4.2.2 Directives with delayed effect</a>
201 </h3>
202
203 <p>
204 The following directives have no immediate effect, but are remembered
205 and have an effect on later processing of the configuration files.
206
207 <dl>
208 <p><dt><samp>user-rcfile <var>filename</var></samp><dd>Specifies that the file <var>filename</var> should be read instead of the
209 user's <samp>~/.userv/rc</samp>.  This does <em>not</em> happen immediately;
210 instead, the setting is remembered and used after the
211 <code>system.default</code> configuration file has been read.  This
212 directive has no effect in a user's configuration file or in the
213 <code>system.override</code> file, as the user's configuration file has
214 already been found and read by then and will not be re-read.
215
216 <p><dt><samp>errors-to-stderr</samp><dd>Causes error messages to be delivered to the client's stderr.
217
218 <p><dt><samp>errors-to-file</samp> <var>filename</var><dd>Error messages will be written to <var>filename</var>, which will be opened
219 in the context of and with the privileges of the service user.
220
221 <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
222 <var>facility</var> is <samp>user</samp>; the default <var>level</var> is <samp>error</samp>.
223
224 </dl>
225 </p>
226
227 <hr>
228
229 <h3>
230 <a name="s-dirs-control">4.2.3 Control structure directives</a>
231 </h3>
232
233 <p>
234 The following directives are used to create control structures.  If
235 the end of the file is encountered before the end of any control
236 structure which was started inside it then that control structure is
237 considered finished.  This is not an error.
238
239 <dl>
240 <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
241 true.  Many conditions are properties of parameter values.  Most
242 parameters have a single string as a value; however, some may yield
243 zero or several strings, in which case the condition is true if it is
244 true of any of the strings individually.  Parameters are described
245 below.
246
247 <p>
248 The conditions are:
249
250 <dl compact>
251 <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
252 patterns (anchored at both ends; backslashes can be used to escape
253 metacharacters).
254
255 <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
256 the range specified.  <var>min</var> or <var>max</var> may be <samp>$</samp> to indicate
257 no lower or upper limit, respectively.
258
259 <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
260 the parameter (leading or trailing whitespace on each line and empty
261 lines in the file are ignored).  It is an error for the file not to be
262 opened and read.
263
264 <dt><samp>! <var>condition</var></samp><dd>The <var>condition</var> is <em>not</em> true.
265
266 <dt>Conjunctions: <samp>&amp;</samp> and <samp>|</samp><dd><pre>
267 ( <var>condition</var>
268 &amp; <var>condition</var>
269 &amp; <var>condition</var>
270 ...
271 )
272 </pre>
273
274 is true if all the listed conditions are true; where <samp>|</samp> is used it
275 is true if any of them is true.  Newlines must be used to separate one
276 condition from the next, as shown, and the parentheses are mandatory.
277 These conjunctions do not do lazy evaluation.
278
279 </dl>
280 </p>
281
282 <p>
283 The parameters are:
284
285 <dl compact>
286 <dt><samp>service</samp><dd>The service name specified when the client was called.
287
288 <dt><samp>calling-user</samp><dd>Two strings: the login name of the calling user (determined as for
289 <code>USERV_USER</code>, above) and the calling uid (represented in
290 decimal).
291
292 <dt><samp>calling-group</samp><dd>Several strings: the primary and supplementary group names and gids
293 (in decimal) of the calling process.  All the group names come first,
294 and then the gids.  If the first supplementary group is the same as
295 the primary group then it is elided.
296
297 <dt><samp>calling-user-shell</samp><dd>The calling user's shell, as listed in the password entry for the
298 calling login name (as determined for <code>USERV_USER</code>, above).
299
300 <dt><samp>service-user</samp><dd>Two strings: the name of the service user (as specified to the client)
301 and their uid (represented in decimal).
302
303 <dt><samp>service-group</samp><dd>Several strings: the primary and supplementary group names and gids
304 (in decimal) of the service user.
305
306 <dt><samp>service-user-shell</samp><dd>The service user's shell, as listed in their password entry.
307
308 <dt><samp>u-<var>name</var></samp><dd>The value of the user-defined variable <var>name</var> passed by the caller
309 using the <code>--defvar</code> command-line option to the client.  If the
310 variable was not defined then this parameter is an empty list of
311 strings; in this case any condition which tests it will be false, and
312 <samp>include-lookup</samp> on it will read the <samp>:none</samp> file, or
313 <samp>:default</samp> if <samp>:none</samp> is not found.
314
315 </dl>
316 </p>
317
318 <dt><samp>errors-push</samp> <var>filename</var><dt><samp>srorre</samp><dd>Stacks the error handling behaviour currently in effect.  Any changes
319 to error handling will take effect only between <code>errors-push</code> and
320 <code>srorre</code>.
321
322 <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
323 parsing to continue at <code>hctac</code> instead.  Any control constructs
324 started since the <code>catch-quit</code> will be considered finished if a
325 <code>quit</code> is found.
326
327 If an error occurs inside <code>catch-quit</code> the execution settings
328 will be reset (as if by the <code>reset</code> directive) and parsing will
329 likewise continue at <code>hctac</code>.
330
331 If a lexical or syntax error is detected in the same configuration
332 file as the <code>catch-quit</code>, while looking for the <code>hctac</code>
333 after an error or <code>quit</code>, that new error will not be caught.
334
335 </dl>
336 </p>
337
338 <hr>
339
340 <h3>
341 <a name="s-dirs-execution">4.2.4 Directives for changing execution settings</a>
342 </h3>
343
344 <p>
345 The following directives modify the execution settings; the server
346 will remember the fact that the directive was encountered and act on
347 it only after all the configuration has been parsed.  The <em>last</em>
348 directive which modifies any particuar setting will take effect.
349
350 <dl>
351 <p><dt><samp>reject</samp><dd>Reject the request.  <code>execute</code>, <code>execute-from-directory</code> and
352 <code>execute-from-path</code> will change this setting.
353
354 <p><dt><samp>execute <var>program</var> [<var>argument</var> ...]</samp><dd>Execute the program <var>program</var>, with the arguments as specified,
355 followed by any arguments given to the client if
356 <code>no-suppress-args</code> is in effect.  It is an error for the
357 execution to fail when it is attempted (after all the configuration
358 has been parsed).  If <var>program</var> does not contain a slash it will
359 be searched for on the service user's path.
360
361 <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
362 specified when the client was called, and execute that program in the
363 directory named by <var>pathname</var> as if it had been specified for
364 <var>execute</var>.  The part of the service name used may contain only
365 alphanumerics and hyphens and must start with an alphanumeric (and it
366 must be non-empty), otherwise it is an error.
367
368 This directive is ignored if the relevant program does not exist in
369 the directory specified; in this case the program to execute is left
370 at its previous setting (or unset, if it was not set before).
371
372 It is an error for the test for the existence of the program to fail
373 other than with a `no such file or directory' indication.  It is also
374 an error for the execution to fail if and when it is attempted (after
375 all the configuration has been parsed).
376
377 <p><dt><samp>execute-from-path</samp><dd><var>service</var> is interpreted as a program on the default <code>PATH</code>
378 (or as a pathname of an executable, if it contains a <samp>/</samp>).  This
379 directive is <em>very dangerous</em>, and is only provided to make the
380 <code>--override</code> options effective.  It should not normally be used.
381 It is an error for the execution to fail when it is attempted (after
382 all the configuration has been parsed).
383
384 <p><dt><samp>execute-builtin <var>service-name</var> <var>service-arguments</var></samp><dd><p>
385 Executes the builtin service <var>service-name</var>.  These builtin
386 services display information about the server and/or the request, and
387 ignore any arguments passed from the service side except possibly to
388 print them as part of their output.  They write their results to their
389 standard output (i.e., wherever file descriptor 1 is directed).  The
390 builtin services are:
391
392 <dl compact>
393 <dt><samp>execute</samp><dd>Displays the execution settings, defined variables,
394 arguments, etc. with which the builtin service was invoked.
395
396 <dt><samp>environment</samp><dd>Displays the environment variable settings with which the builtin
397 service was invoked.
398
399 <dt><samp>parameter <var>parameter</var></samp><dd>Displays the values of the service configuration language parameter
400 specified.
401
402 <dt><samp>version</samp><dd>Displays the version string and compilation details of the uservd
403 server program.
404
405 <dt><samp>reset</samp><dd>Displays the default reset configuration (evaluated when <code>reset</code>
406 is found in a configuration file, or when an error is caught by
407 <code>catch-quit</code>).
408
409 <dt><samp>toplevel</samp><dd>Displays the top-level default configuration (the configuration data,
410 evaluated by the server, which calls all the other configuration
411 files).
412
413 <dt><samp>override</samp><dd>Displays the top-level override configuration (the configuration data,
414 evaluated by the server, which causes all the other configuration data
415 to be parsed).
416
417 <dt><samp>help</samp><dd>Displays a list of the understood builtin service names and arguments.
418
419 </dl>
420
421
422 In the future other builtin services may be defined which do more than
423 just print information.
424 </p>
425
426 <dt><samp>set-environment</samp><dt><samp>no-set-environment</samp><dd>Runs <samp>/etc/environment</samp> to set the service user's environment.
427 This adds the overhead of invoking a shell, but doesn't cause any
428 shell (de)mangling of the service's arguments.  This is achieved by
429 invoking
430 <pre>
431 .../program arg arg arg ...
432 </pre>
433
434 as
435 <pre>
436 /bin/sh -c '. /etc/environment; exec &quot;$@&quot;' - .../program arg arg arg ...
437 </pre>
438
439 <code>no-set-environment</code> cancels the effect of
440 <code>set-environment</code>.
441
442 <dt><samp>no-suppress-args</samp><dt><samp>suppress-args</samp><dd>Include any arguments given to the client as arguments to the program
443 invoked as a result of an <code>execute</code>,
444 <code>execute-from-directory</code> or <code>execute-from-path</code> directive.
445 <code>suppress-args</code> undoes the effect of <code>no-suppress-args</code>.
446
447 <dt><samp>require-fd <var>fd-range</var> read|write</samp><dd>Insist that the filedescriptor(s) be opened for reading resp. writing.
448 It is an error if any descriptor marked as required when the service
449 is about to be invoked (after the configuration has been parsed) was
450 not specified when the client was invoked.  Each file descriptor has a
451 separate setting, and the last one of <code>require-fd</code>,
452 <code>allow-fd</code>, <code>ignore-fd</code>, <code>null-fd</code> or <code>reject-fd</code>
453 which affected a particular file descriptor will take effect.
454
455 <var>fd-range</var> may be a single number, two numbers separated by a
456 hyphen, or one number followed by a hyphen (indicating all descriptors
457 from that number onwards).  It may also be one of the words
458 <samp>stdin</samp>, <samp>stdout</samp> or <samp>stderr</samp>.  Open-ended file descriptor
459 rangers are allowed only with <code>reject-fd</code> and <code>ignore-fd</code>,
460 as otherwise the service program would find itself with a very large
461 number of file descriptors open.
462
463 When the configuration has been parsed, and before the service is
464 about to be executed, stderr (fd 2) must be required or allowed
465 (<code>require-fd</code> or <code>allow-fd</code>) for writing; this is so that
466 the error message printed by the server's child process if it cannot
467 <code>exec</code> the service program is not lost.
468
469 <dt><samp>allow-fd <var>fd-range</var> [read|write]</samp><dd>Allow the descriptor(s) to be opened for reading resp. writing, or
470 either if neither <samp>read</samp> nor <samp>write</samp> is specified.  If a
471 particular descriptor not specified by the client then it will be open
472 onto <samp>/dev/null</samp> (for reading, writing, or both, depending on
473 whether <samp>read</samp>, <samp>write</samp> or neither was specified).
474
475 <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
476 reading resp. writing, or both if neither <samp>read</samp> nor <samp>write</samp>
477 is specified.  Any specification of these file descriptors by the
478 client will be silently ignored; the client will see its ends of the
479 descriptors being closed immediately.
480
481 <dt><samp>reject-fd <var>fd-range</var></samp><dd>Do not allow the descriptor(s) to be specified by the client.  It is
482 an error if any descriptor(s) marked for rejection are specified when
483 the service is about to be invoked (after the configuration has been
484 parsed).
485
486 <dt><samp>ignore-fd <var>fd-range</var></samp><dd>Silently ignore any specification by the client of those
487 descriptor(s).  The pipes corresponding to these descriptors will be
488 closed just before the service is invoked.
489
490 <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
491 client disconnects before the main service process terminates.
492 <code>no-disconnect-hup</code> cancels <code>disconnect-hup</code>.
493
494 If one of the reading descriptors specified when the client is called
495 gets a read error, or if the service is disconnected for some other
496 reason, then the <code>SIGHUP</code> will be delivered <em>before</em> the
497 writing end(s) of the service's reading pipe(s) are closed, so that
498 the client can distinguish disconnection from reading EOF on a pipe.
499
500 <dt><samp>reset</samp><dd>Resets the execution settings to the default.  This is equivalent to:
501 <pre>
502 cd ~/
503 reject
504 no-set-environment
505 suppress-args
506 allow-fd 0 read
507 allow-fd 1-2 write
508 reject-fd 3-
509 disconnect-hup
510 </pre>
511
512 </dl>
513
514
515 If no <code>execute</code>, <code>execute-from-path</code>,
516 <code>execute-from-directory</code> or <code>builtin</code> is interpreted before
517 all the files are read then the request is rejected.
518 </p>
519
520 <hr>
521
522 <h2>
523 <a name="s-configerrors">4.3 Errors in the configuration file</a>
524 </h2>
525
526 <p>
527 If a syntax error or other problem occurs when processing a
528 configuration file then a diagnostic will be issued, to wherever the
529 error messages are currently being sent (see the <code>errors-</code> family
530 of directives, above).
531 </p>
532
533 <p>
534 The error will cause processing of the configuration files to cease at
535 that point, unless the error was inside a <code>catch-quit</code> construct.
536 In this case the settings controlling the program's execution will be
537 reset to the defaults as if a <code>reset</code> directive had been issued,
538 and parsing continues after <code>hctac</code>.
539 </p>
540
541 <hr>
542
543 <h2>
544 <a name="s-defaults">4.4 Defaults</a>
545 </h2>
546
547 <p>
548 The default configuration processing is as if the daemon were parsing
549 an overall configuration file whose contents were as follows:
550
551 <pre>
552 reset
553 user-rcfile ~/.userv/rc
554 errors-to-stderr
555 include /etc/userv/system.default
556 if grep service-user-shell /etc/shells
557    errors-push
558      catch-quit
559        include-ifexist <var>file specified by most recent user-rcfile directive</var>
560      hctac
561    srorre
562 fi
563 include /etc/userv/system.override
564 quit
565 </pre>
566 </p>
567
568 <p>
569 If one of the <code>--override</code> options to the client is used then it
570 will instead be as if the daemon were parsing an overall configuration
571 as follows:
572
573 <pre>
574 reset
575 errors-to-stderr
576 include <var>file containing configuration data sent by client</var>
577 quit
578 </pre>
579 </p>
580
581 <hr>
582
583 [<a href="ch-envir.html">back</a>]
584  [<a href="index.html#abstract">Abstract</a>]
585  [<a href="index.html#copyright">Copyright Notice</a>]
586  [<a href="index.html#contents">Contents</a>]
587  [<a href="ch-ipass.html">next</a>]
588
589 <hr>
590
591 User service daemon and client specification<br>
592
593 <address>
594 0.64.1<br>
595 Ian Jackson <a href="mailto:ian@davenant.greenend.org.uk">ian@davenant.greenend.org.uk</a>
596 </address>
597
598 </body>
599
600 </html>
601