chiark / gitweb /
Avoid accessing backup, auto-save files, etc, with include-lookup.
[userv.git] / spec.sgml
1 <!doctype debiandoc system>
2
3 <book>
4 <title>User service daemon and client specification
5 <author>Ian Jackson <email>ian@davenant.greenend.org.uk
6 <version>0.64.1</version>
7
8 <abstract>
9 This is a specification for a Unix system facility to allow one
10 program to invoke another when only limited trust exists
11 between them.
12
13 <copyright>
14 <prgn/userv/ is Copyright 1996-1999 Ian Jackson.
15 <p>
16
17 <prgn/userv/ is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation; either version 2 of the License, or (at
20 your option) any later version.
21 <p>
22
23 This program is distributed in the hope that it will be useful, but
24 <em/without any warranty/; without even the implied warranty of
25 <em/merchantability/ or <em/fitness for a particular purpose/.  See
26 the GNU General Public License for more details.
27 <p>
28
29 You should have received a copy of the GNU General Public License
30 along with <prgn/userv/; if not, write to the Free Software
31 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32
33 <toc sect>
34
35 <chapt id="intro">Introduction
36 <p>
37 There is a daemon which invokes user service programs (henceforth
38 `services') in response to requests by callers of a companion client
39 program (henceforth the `client') and according to rules set forth in
40 system-wide and user-specific configuration files.  The companion
41 client program is setuid root, and negotiates with the daemon through
42 an <prgn/AF_UNIX/ socket and associated objects in a system-wide
43 private directory set aside for the purpose.  The user who wishes the
44 service to be performed and calls the client is called the `calling
45 user'; the process which calls the client is called the `calling
46 process'.
47
48 <p>
49 The daemon and the client are responsible for ensuring that
50 information is safely carried across the security boundary between the
51 two users, and that the processes on either side cannot interact with
52 each other in any unexpected ways.
53
54 <chapt id="client">Client program usage
55
56 <p>
57 <example>
58 userv <var/options/ [--] <var/service-user/ <var/service-name/ [<var/argument/ ...]
59 userv <var/options/ -B|--builtin [--] <var/builtin-service/ [<var/info-argument/ ...]
60 </example>
61 <p>
62
63 <var/service-user/ specifies which user is to provide the service.
64 The user may be a login name or a numeric uid, or <tt/-/ to indicate
65 that the service user is to be the same as the calling user.
66 <p>
67
68 The service name is interpreted by the userv<footnote><prgn/userv/ is
69 short for `user services', and is pronounced `you-serve'.</footnote>
70 daemon on behalf of the service user.  It will often be the name of a
71 program.
72
73 <sect>Options
74 <p>
75
76 Single-letter options may be combined as is usual with Unix programs,
77 and the value for such an option may appear in the same argument or in
78 the next.
79
80 <taglist>
81 <tag/<tt/-B//
82 <tag/<tt/--builtin//
83 <item>
84 Requests that a builtin service be provided.  This is equivalent to
85 using the <prgn/--override/ option to specify a string consisting of
86 <prgn/execute-builtin/ followed by the <var/builtin-service/
87 requested, and requesting a service user of <tt/-/ (indicating the
88 calling user).
89 <p>
90
91 If the builtin service being requested requires a
92 <var/service-argument/ then this must be supplied to the client in the
93 same argument as the <var/builtin-service/.  See <ref
94 id="dirs-execution"> for details of the builtin services available,
95 and <ref id="optoverride"> for details of the <prgn/--override/
96 options.
97 <p>
98
99 The actual service name passed will be the <var/builtin-service/; note
100 that this actual service name (as opposed to the override data) and
101 the <var/info-argument/s supplied will be ignored by most builtin
102 services; the override mechanism and <prgn/execute-builtin/ will be
103 used to ensure that the right builtin service is called with the right
104 <var/service-argument/s.
105
106 <tag/<tt/-f<var/fd/[<var/modifiers/]=<var/filename///
107 <tag/<tt/--file <var/fd/[<var/modifiers/]=<var/filename///
108 <item>
109 Requests that data be copied in and out of the service using pipes.
110 For each file or descriptor this will be done by creating a pipe, one
111 end of which is passed to the service program and the other end of
112 which is passed to a copy of <prgn/cat/ invoked by the client; the
113 other file descriptor passed to <prgn/cat/ will be one inherited by
114 the client program from the caller or one opened by the client program
115 on behalf of the caller.
116 <p>
117
118 The descriptor in the service program that should be connected must be
119 specified as <var/fd/, either as a decimal number or as one of the
120 strings <tt/stdin/, <tt/stdout/ or <tt/stderr/.  The next argument is
121 a filename which will be opened by the client with the privileges of
122 the calling user.
123
124 <p>
125 <var/modifiers/ is used to specify whether the file or descriptor is
126 to be read from or written to.  It consists of a series of words
127 separated by commas.  A comma may separate the <var/modifiers/ from
128 the <var/fd/ and is required if <var/fd/ is not numeric.
129
130 <p>
131 The modifier words are:
132 <taglist compact>
133 <tag/<tt/read//
134 <item>
135 <tt/O_RDONLY/: Allow reading and not writing.  May not be used with
136 <tt/write/ or things that imply it.
137
138 <tag/<tt/write//
139 <item>
140 <tt/O_WRONLY/: Allow writing and not reading.  <em/Doesn't truncate or
141 create/ without <tt/truncate/ or <tt/create/.  <tt/write/ or things
142 that imply it may not be used with <tt/read/.
143
144 <tag/<tt/overwrite//
145 <item>
146 Equivalent to <tt/write,create,truncate/.
147
148 <tag/<tt/create//
149 <tag/<tt/creat//
150 <item>
151 <tt/O_CREAT/: Creates the file if necessary.  Implies <tt/write/.
152
153 <tag/<tt/exclusive//
154 <tag/<tt/excl//
155 <item>
156 <tt/O_EXCL/: Fails if the file already exists.  Implies <tt/write/ and
157 <tt/create/.  May not be used with <tt/truncate/.
158
159 <tag/<tt/truncate//
160 <tag/<tt/trunc//
161 <item>
162 <tt/O_TRUNC/: Truncate any existing file.  Implies <tt/write/.
163 May not be used with <tt/exclusive/.
164
165 <tag/<tt/append//
166 <item>
167 <tt/O_APPEND/: All writes will append to the file.  Implies <tt/write/
168 (but not <tt/create/).
169
170 <tag/<tt/sync//
171 <item>
172 <tt/O_SYNC/: Do writes synchronously.  Implies <tt/write/.
173
174 <tag/<tt/wait//
175 <tag/<tt/nowait//
176 <tag/<tt/close//
177 <item>
178
179 These modifiers control the behaviour of the client, with respect to
180 the pipes carrying data to and from the service, when the service
181 terminates.  See below.
182
183 <tag/<tt/fd//
184 <item>
185 The <var/filename/ is not a filename but a numeric file descriptor.
186 One or both of <tt/read/ and <tt/write/ must be specified, and no
187 other words are allowed.  The <var/filename/ may also be <tt/stdin/,
188 <tt/stdout/ or <tt/stderr/ for file descriptor 0, 1 or 2 respectively.
189
190 </taglist>
191 <p>
192
193 If no <var/modifiers/ which imply <tt/read/ or <tt/write/ are used it
194 is as if <tt/write/ had been specified, except that if the
195 filedescriptor 0 of the service is being opened (either specified
196 numerically or with <tt/stdin/) it is as if <tt/overwrite/ had been
197 specified (or <tt/write/ if only <tt/fd/ was specified).
198 <p>
199
200 The client will also use <tt/O_NOCTTY/ when opening files specified by
201 the caller, to avoid changing its controlling terminal.
202 <p>
203
204 By default stdin, stdout and stderr of the service will be connected
205 to the corresponding descriptors on the client.  Diagnostics from
206 the client and daemon will also appear on stderr.
207 <p>
208
209 If <tt/wait/ is specified, the client will wait for the pipe to be
210 closed, and only exit after this has happened.  This means that either
211 the receiving end of the pipe connection was closed while data was
212 still available at the sending end, or that the end of file was
213 reached on the reading file descriptor.  Errors encountered reading or
214 writing in the client at this stage will be considered a system error
215 and cause the client to exit with status 255, but will not cause
216 disconnection at the service side since the service has already
217 exited.
218 <p>
219
220 If <tt/close/ is specified the client will immediately close the pipe
221 connection by killing the relevant copy of <prgn/cat/.  If the service
222 uses the descriptor it will get <prgn/SIGPIPE/ (or <prgn/EPIPE/) for a
223 writing descriptor or end of file for a reading one; the descriptor
224 opened by or passed to the client will also be closed.
225 <p>
226
227 If <tt/nowait/ is specified then the client will not wait and the
228 connection will remain open after the client terminates.  Data may
229 continue to be passed between the inheritors of the relevant
230 descriptor on the service side and the corresponding file or
231 descriptor on the client side until either side closes their
232 descriptor.  This should not usually be specified for stderr (or
233 stdout if <tt/--signals stdout/ is used) since diagnostics from
234 the service side may arrive after the client has exited and be
235 confused with expected output.
236 <p>
237
238 The default is <tt/wait/ for writing file descriptors and <tt/close/
239 for reading ones.
240
241 <tag/<tt/-w<var/fd/=<var/action///
242 <tag/<tt/--fdwait<var/fd/=<var/action///
243 <item>
244 Sets the action on termination of the service for the specified file
245 descriptor; <var/action/ must be <tt/wait/, <tt/nowait/ or <tt/close/
246 as described above.  The file descriptor must be specified as open
247 when this option is encountered; this option is overridden by any
248 later <prgn/--file/ or <prgn/--fdwait/ option - even by a
249 <prgn/--file/ which does not specify an action on termination (in this
250 case the default will be used, as described above).
251
252 <tag/<tt/-D<var/name/=<var/value///
253 <tag/<tt/--defvar <var/name/=<var/value///
254 <item>
255 Set a user-defined variable <var/name/ to <var/value/.  These
256 user-defined variables are made available in the configuration
257 language as the parameters <tt/u-<var/name// and are passed to the
258 service in environment variables <tt/USERV_U_<var/name//.  <var/name/
259 may contain only alphanumerics and underscores, and must start with a
260 letter.  If several definitions are given for the same <var/name/ then
261 only the last is effective.
262
263 <tag/<tt/-t <var/seconds///
264 <tag/<tt/--timeout <var/seconds///
265 <item>
266 Time out the service if it takes longer than <var/seconds/ seconds (a
267 positive integer, in decimal).  Timeout will produce a diagnostic on
268 stderr and an exit status of 255.  If <var/seconds/ is zero then no
269 timeout will be implemented (this is the default).
270
271 <tag/<tt/-S/ <var/method//
272 <tag/<tt/--signals/ <var/method//
273 <item>
274 Affects the handling of the exit status when the service terminates
275 due to a signal.  (The client will always finish by calling
276 <prgn/_exit/, so that only numbers from 0 to 255 can be returned and
277 not the full range of numbers and signal indications which can be
278 returned by the <prgn/wait/ family of system calls.)
279 <p>
280
281 The <var/method/ may be one of the following:
282 <taglist compact>
283 <tag/<var/status/
284 <item>
285 The client's exit status will be <var/status/.  This will not be
286 distinguishable from the service really having exited with code
287 <var/status/.  This method is the default, with a <var/status/ of 254.
288
289 <tag/<tt/number//
290 <tag/<tt/number-nocore//
291 <item>
292 The client's exit status will be the number of the signal which caused
293 the termination of the service.  If <tt/number/ is used rather than
294 <tt/number-nocore/ then 128 will be added if the service dumped core.
295 <tt/number/ is very like the exit code mangling done by the Bourne
296 shell.
297
298 <tag/<tt/highbit//
299 <item>The client's exit status will be the number of the signal with
300 128 added.  If the service exits normally with an exit code of greater
301 than 127 then 127 will be returned.
302
303 <tag/<tt/stdout//
304 <item>
305 The service's numeric wait status as two decimal numbers (high byte
306 first) and a textual description of its meaning will be printed to the
307 client's standard output.  It will be preceded by a newline and
308 followed by an extra newline, and the numbers are separated from each
309 other and from the textual description by single spaces.  The exit
310 status of the client will be zero, unless a system error occurs in
311 which case no exit status and description will be printed to stdout,
312 and an error message will be printed to stderr as usual.
313 </taglist>
314
315 <p>
316 Problems such as client usage errors, the service not being found or
317 permission being denied or failure of a system call are system errors.
318 An error message describing the problem will be printed on the
319 client's stderr, and the client's exit status will be 255.  If the
320 client dies due to a signal this should be treated as a serious system
321 error.
322
323 <tag/<tt/-H//
324 <tag/<tt/--hidecwd//
325 <item>
326 Prevents the calling process's current directory name from being
327 passed to the service; the null string will be passed instead.
328
329 <tag/<tt/-P//
330 <tag/<tt/--sigpipe//
331 <item>
332 If the service program is terminated due to a <prgn/SIGPIPE/ the exit
333 status of the client will be zero, even if it would have been
334 something else according to the exit status method specified.  This
335 option has no effect on the code and description printed if the exit
336 status method <tt/stdout/ is in use.
337
338 <tag/<tt/-h//
339 <tag/<tt/--help//
340 <tag/<tt/--copyright//
341 <item>
342 <tt/-h/ or <tt/--help/ prints the client's usage message;
343 <tt/--copyright/ prints the copyright and lack of warranty notice.
344
345 </taglist>
346
347 <sect id="optoverride">Security-overriding options
348 <p>
349
350 There are also some options which are available for debugging and to
351 allow the system administrator to override a user's policy.  These
352 options are available only if the client is called by root or if the
353 calling user is the same as the service user.
354
355 <taglist>
356
357 <tag/<tt/--override <var/configuration-data///
358 <tag/<tt/--override-file <var/filename///
359 <item>
360 Do not read the usual configuration files.  Instead, the client sends
361 <var/configuration-data/ (followed by a newline) or the contents of
362 <var/filename/ (which is opened in the context of the client) to the
363 daemon and the daemon uses that data instead.  The
364 <var/configuration-data/ must all be in one argument.  It will have a
365 single newline appended so that a single directive can easily be
366 given, but if more than one directive is required it will have to
367 contain one or more real newlines.
368
369 <tag/<tt/--spoof-user <var/user///
370 <item>
371 Pretend to the service that it is being called by <var/user/ (which
372 may be a username or a uid).  This will also affect the group and
373 supplementary groups supplied to the service; they will be the
374 standard group and supplementary groups for <var/user/.  The
375 <tt/--spoof-user/ option will <em/not/ affect which user is chosen if
376 the service user is specified as just <tt/-/; in this case the service
377 user will be the real calling user.
378
379 </taglist>
380
381
382 <chapt id="envir">Execution environment of the service program
383 <p>
384
385 The daemon which is handling the service user side of things will read
386 configuration files to decide what to do.  If it decides to allow the
387 service to be provided it will fork a subprocess to execute the
388 service.
389 <p>
390
391 The service will have no controlling terminal, but it will be a
392 process group leader.
393 <p>
394
395 If the client is killed or times out or a file or descriptor being
396 read or written by the client process gets an error then the service
397 will be disconnected from the client.  The client will return an exit
398 status of 255 and some the service's pipes may be closed at the other
399 end.  The service will become a child of <prgn/init/.  The service may
400 well not notice the disconnection, though writing to a pipe after this
401 may produce a <prgn/SIGPIPE/ and the facility exists to have a
402 <prgn/SIGHUP/ sent to the service on disconnection.
403
404 <sect>File descriptors
405 <p>
406
407 The service program's standard filedescriptors, and possibly other
408 file descriptors, will be connected to pipes or to
409 <prgn>/dev/null</>.  The <prgn/userv/ client/daemon pair will arrange
410 that data is copied between the files or file descriptors specified to
411 to the client by the caller and these these pipes.
412 <p>
413
414 Pipes which may be written to will be closed if a write error occurs
415 on the corresponding client-side file or descriptor, which may result
416 in a <prgn/SIGPIPE/ in the service program; pipes open for reading
417 will get <prgn/EOF/ if the client-side file descriptor gets <prgn/EOF/
418 or an error.
419 <p>
420
421 If the service closes one of its reading file descriptors the writing
422 end of the corresponding pipe will generate a <prgn/SIGPIPE/ when
423 attempts are made by the client/daemon pair to write to it.  This will
424 not be considered an error; rather, the relevant pipe will be
425 discarded and the corresponding file or file descriptor held by the
426 client will be closed.
427 <p>
428
429 Likewise, if one of the file descriptors held by the client for
430 writing by the service is a pipe whose other end is closed by the
431 caller then the client/daemon pair will see an error when trying to
432 copy data provided by the service.  This too will not be considered an
433 error; rather, the pipe correspondong to that descriptor will be
434 closed and any further writes will cause the service to get a
435 <prgn/SIGPIPE/.
436 <p>
437
438 Note that not all write errors or broken pipes on file descriptors may
439 be visible to the service, since buffered data may be discarded by the
440 operating system and there will be a finite interval between the error
441 happening and the service being disconnected from the client or the
442 next write causing a <prgn/SIGPIPE/.
443 <p>
444
445 Read errors on file descriptors (and disconnection) will only be
446 visible to the service and distinguishable from normal end of file if
447 <prgn/disconnect-hup/ is in effect.
448 <p>
449
450 Read and write errors (other than broken pipes, as described above)
451 will always be visible to the caller; they are system errors, and will
452 therefore cause the client to print an error message to stderr and
453 return with an exit status of 255.
454 <p>
455
456 If the main service program process exits while it still has running
457 children any file descriptors held by those children can remain open,
458 depending on the use of <tt/wait/, <tt/nowait/ or <tt/close/ for the
459 relevant file descriptor in the client's arguments.  By default
460 writing filedescriptors remain open and the client will wait for them
461 to be closed at the service end, and reading file descriptors are
462 closed immediately.  These leftover child processes will not get a any
463 <prgn/SIGHUP/ even if a read or write error occurs or the client
464 disconnects before then.
465
466 <sect>Environment
467 <p>
468
469 The service will have some information in environment variables:
470 <taglist compact>
471 <tag/<tt/USERV_USER//
472 <item>
473 The login name of the calling user.  If the <prgn/LOGNAME/ variable is
474 set (or, if that is unset, if the <prgn/USER/ variable is set) in the
475 environment passed to the client by the caller then the password entry
476 for that login name will be looked up; if that password entry's uid is
477 the same as that of the calling process then that login name will be
478 used, otherwise (or if neither <prgn/LOGNAME/ nor <prgn/USER/ is set)
479 the calling process's uid will be looked up to determine their login
480 name (and if this lookup fails then the service will not be invoked).
481
482 <tag/<tt/USERV_UID//
483 <item>
484 The uid of the calling process.
485
486 <tag/<tt/USERV_GID//
487 <item>
488 The gid and supplementary group list of the calling process: first the
489 group in gid and then those in the supplementary group list, in
490 decimal, separated by spaces.
491
492 <tag/<tt/USERV_GROUP//
493 <item>
494 The group names of the calling process, listed in the same way as the
495 ids are in <prgn/USERV_GID/.  If no name can be found for any of the
496 calling process's group(s) then the service will not be invoked.
497
498 <tag/<tt/USERV_CWD//
499 <item>
500 The client's current working directory name (this directory may not be
501 accessible to the service).  If it could not be determined or the
502 <prgn/--hidecwd/ flag was used then this variable will be set to an
503 empty string (this is not considered an error).
504
505 <tag/<tt/USERV_SERVICE//
506 <item>
507 The service name requested by the caller.
508
509 <tag/<tt/USERV_U_<var/name///
510 <item>
511 The value supplied to the client by the caller using -D<var/name/.
512
513 </taglist>
514
515 <prgn/HOME/, <prgn/PATH/, <prgn/SHELL/, <prgn/LOGNAME/ and <prgn/USER/
516 will be set appropriately (according to the details of the service
517 user).
518
519
520 <chapt id="config">Service-side configuration
521 <p>
522
523 Which services may be run by whom and under what conditions is
524 controlled by configuration files.
525 <p>
526
527 The daemon will read these files in order.  Certain directives in the
528 files modify the daemon's execution settings for invoking the service,
529 for example allowing certain file descriptors to be specified by the
530 client or specifying which program to execute to provide the service.
531 <p>
532
533 The <em/last/ instance of each such setting will take effect.  The
534 directives which specify which program to execute will not stop the
535 configuration file from being read; they will be remembered and will
536 only take effect if they are not overridden by a later directive.
537 <p>
538
539 The daemon will first read <tt>/etc/userv/system.default</>.  Then, by
540 default (this behaviour may be modified), it will read a per-user file
541 <tt>~/.userv/rc</>, if it exists and the service user's shell is in
542 <tt>/etc/shells</>.  Finally it will read
543 <tt>/etc/userv/system.override</>.
544 <p>
545
546 When it has read all of these files it will act according to the
547 currently values of of the execution settings.
548
549 <sect>Configuration file syntax
550 <p>
551
552 The configuration file is a series of directives, usually one per
553 line.  The portion of a line following a hash character <tt/#/ is
554 taken as a comment and ignored.  Each directive consists of a series
555 of tokens separated by linear whitespace (spaces and tabs); tokens may
556 be words consisting of non-space characters, or, where a string is
557 required, a string in double quotes.  Double-quoted strings may
558 contain the following backslash escapes:
559
560 <taglist compact>
561 <tag/<tt/\n//<item>newline
562 <tag/<tt/\t//<item>tab
563 <tag/<tt/\r//<item>carriage return
564 <tag/<tt/\<var/OOO///<item>character whose octal code is <var/OOO/
565 <tag/<tt/\x<var/XX///<item>character whose hex code is <var/XX/
566 <tag/<tt/\<var/punctuation///<item>literal punctuation character (eg <tt/\\/, <tt/\"/)
567 <tag/<tt/\<var/newline// (ie, backslash at end of line)/
568 <item>string continues on next line
569 </taglist>
570 <p>
571
572 Relative pathnames in directives are relative to the service program's
573 current directory (usually the service user's home directory).
574 Pathnames starting with the two characters <tt>~/</> are taken to be
575 relative to the service user's home directory.
576
577 <sect id="directives">Configuration file directives
578 <p>
579
580 <sect1 id="dirs-immediate">Immediate directives
581 <p>
582
583 The following directives take effect immediately:
584
585 <taglist>
586 <tag/<tt/cd <var/pathname///
587 <item>
588 Change directory in the service program.  <prgn/cd/ is cumulative.  It
589 is an error if the directory cannot be changed to.
590 <p>
591
592 <prgn/cd/ should not be used between <prgn/execute-from-directory/ and
593 the invocation of the service program, as the test for the
594 availability of the service program would be done with the old current
595 directory and the actual execution with the new (probably causing an
596 error).
597
598 <tag/<tt/eof//
599 <item>
600 Stop reading the configuration file in question, as if end of file had
601 been reached.  Any control constructs (<prgn/if/, <prgn/catch-quit/ or
602 <prgn/errors-push/) which were started in that file will be considered
603 finished.  Parsing will continue in the file which caused the file
604 containing the <prgn/eof/ to be read.
605
606 <tag/<tt/quit//
607 <item>
608 Stop reading configuration files and act immediately on the current
609 settings.  The behaviour of <prgn/quit/ is subject to the
610 <prgn/catch-quit/ control construct.
611
612 <tag/<tt/include <var/filename///
613 <tag/<tt/include-ifexist <var/filename///
614 <item>
615 Read the configuration file <var/filename/, and then return to this
616 file and continue parsing it with the next directive.  It is an error
617 if the file cannot be opened and read, unless <prgn/include-ifexist/
618 is used and the file does not exist, in which case the directive is
619 silently ignored.
620
621 <tag/<tt/include-lookup <var/parameter/ <var/directory///
622 <tag/<tt/include-lookup-all <var/parameter/ <var/directory///
623 <item>
624 Read the configuration file in <var/directory/ whose name is the value
625 of <var/parameter/ (see the description of <prgn/if/, <ref
626 id="dirs-control">).  If <var/parameter/ has several values they will
627 be tried in order; with <prgn/include-lookup/ this search will stop
628 when one is found, but with <prgn/include-lookup-all/ the search will
629 continue and any files appropriate to other values will be read too.
630 <p>
631
632 If none of the parameter's values had a corresponding file then the
633 file <tt/:default/ will be read, if it exists.  If <var/parameter/'s
634 list of values was empty then the file <tt/:none/ will be tried first
635 and read if it exists, otherwise <tt/:default/ will be tried.
636 <p>
637
638 It is not an error for any of the files (including <tt/:default/) not
639 to exist, but it is an error if a file exists and cannot be read or if
640 the directory cannot be accessed.
641
642 <p>
643 A translation will be applied to values before they are used to
644 construct a filename, so that the lookup cannot access dotfiles,
645 backup files, files in other directories and the like: each slash will
646 be replaced with a colon followed by a hyphen <tt>:-</>, and all
647 characters which are not lowercase alphanumerics, hyphens or
648 underscores will have a colon prepended (so that colons are doubled).
649 A parameter value which is the empty string will be replaced with
650 <tt/:empty/ (note that this is different from a parameter not having
651 any values).
652
653 <tag/<tt/include-directory <var/directory///
654 <item>
655 Read configuration from all files in directory <var/directory/ which
656 are plain files whose names consist only of alphanumerics and hyphens
657 and start with an alphanumeric.  They will be read in lexical order.
658 It is an error for the directory not to exist or for it or any of the
659 files found not to be read successfully, or for anything with an
660 appropriate name not to be a plain file or a symbolic link to a plain
661 file.
662
663 <tag/<tt/error <var/text ...///
664 <item>
665 Causes an error whose message includes the descriptive string
666 <var/text/.  <var/text/ may consist of several tokens with intervening
667 whitespace.  The whitespace will be included in the message as found
668 in the configuration file: all the characters until the end of the
669 line will be included verbatim, unless they are part of a
670 double-quoted string, in which case the usual meaning of the string
671 (i.e., after backslash escape processing) will be used.  Comments and
672 linear whitespace at the end of the line (or just before the comment)
673 will still be ignored.
674
675 <tag/<tt/message <var/text ...///
676 <item>
677 Causes a message including the descriptive string <var/text/ to be
678 delivered as if it were an error message, but does not actually cause
679 an error.
680 </taglist>
681
682 <sect1 id="dirs-delayed">Directives with delayed effect
683 <p>
684
685 The following directives have no immediate effect, but are remembered
686 and have an effect on later processing of the configuration files.
687
688 <taglist>
689 <tag/<tt/user-rcfile <var/filename///
690 <item>
691 Specifies that the file <var/filename/ should be read instead of the
692 user's <tt>~/.userv/rc</>.  This does <em/not/ happen immediately;
693 instead, the setting is remembered and used after the
694 <prgn/system.default/ configuration file has been read.  This
695 directive has no effect in a user's configuration file or in the
696 <prgn/system.override/ file, as the user's configuration file has
697 already been found and read by then and will not be re-read.
698
699 <tag/<tt/errors-to-stderr//
700 <item>
701 Causes error messages to be delivered to the client's stderr.
702
703 <tag/<tt/errors-to-file/ <var/filename//
704 <item>
705 Error messages will be written to <var/filename/, which will be opened
706 in the context of and with the privileges of the service user.
707
708 <tag/<tt/errors-to-syslog/ [<var/facility/ [<var/level/]]/
709 <item>
710 Error messages will be delivered using <prgn/syslog/.  The default
711 <var/facility/ is <tt/user/; the default <var/level/ is <tt/error/.
712 </taglist>
713
714 <sect1 id="dirs-control">Control structure directives
715 <p>
716
717 The following directives are used to create control structures.  If
718 the end of the file is encountered before the end of any control
719 structure which was started inside it then that control structure is
720 considered finished.  This is not an error.
721
722 <taglist>
723 <tag/<tt/if <var/condition///
724 <tag/<tt/elif <var/condition///
725 <tag/<tt/else//
726 <tag/<tt/fi//
727 <item>
728 Lines following <prgn/if/ are interpreted only if the condition is
729 true.  Many conditions are properties of parameter values.  Most
730 parameters have a single string as a value; however, some may yield
731 zero or several strings, in which case the condition is true if it is
732 true of any of the strings individually.  Parameters are described
733 below.
734 <p>
735
736 The conditions are:
737
738 <taglist compact>
739 <tag/<tt/glob <var/parameter/ <var/glob-pattern/ ...//
740 <item>
741 The value of the parameter whose name is given matches one of the glob
742 patterns (anchored at both ends; backslashes can be used to escape
743 metacharacters).
744
745 <tag/<tt/range <var/parameter/ <var/min/ <var/max///
746 <item>
747 The value of the parameter is a nonnegative integer and lies within
748 the range specified.  <var/min/ or <var/max/ may be <tt/$/ to indicate
749 no lower or upper limit, respectively.
750
751 <tag/<tt/grep <var/parameter/ <var/filename///
752 <item>
753 The <var/filename/ refers to a file one of whose lines is the value of
754 the parameter (leading or trailing whitespace on each line and empty
755 lines in the file are ignored).  It is an error for the file not to be
756 opened and read.
757
758 <tag/<tt/! <var/condition///
759 <item>
760 The <var/condition/ is <em/not/ true.
761
762 <tag/Conjunctions: <tt/&amp;/ and <tt/|//
763 <item>
764 <example>
765 ( <var/condition/
766 &amp; <var/condition/
767 &amp; <var/condition/
768 ...
769 )
770 </example>
771 is true if all the listed conditions are true; where <tt/|/ is used it
772 is true if any of them is true.  Newlines must be used to separate one
773 condition from the next, as shown, and the parentheses are mandatory.
774 These conjunctions do not do lazy evaluation.
775 </taglist>
776 <p>
777
778 The parameters are:
779
780 <taglist compact>
781 <tag/<tt/service//
782 <item>
783 The service name specified when the client was called.
784
785 <tag/<tt/calling-user//
786 <item>
787 Two strings: the login name of the calling user (determined as for
788 <prgn/USERV_USER/, above) and the calling uid (represented in
789 decimal).
790
791 <tag/<tt/calling-group//
792 <item>
793 Several strings: the primary and supplementary group names and gids
794 (in decimal) of the calling process.  All the group names come first,
795 and then the gids.  If the first supplementary group is the same as
796 the primary group then it is elided.
797
798 <tag/<tt/calling-user-shell//
799 <item>
800 The calling user's shell, as listed in the password entry for the
801 calling login name (as determined for <prgn/USERV_USER/, above).
802
803 <tag/<tt/service-user//
804 <item>
805 Two strings: the name of the service user (as specified to the client)
806 and their uid (represented in decimal).
807
808 <tag/<tt/service-group//
809 <item>
810 Several strings: the primary and supplementary group names and gids
811 (in decimal) of the service user.
812
813 <tag/<tt/service-user-shell//
814 <item>
815 The service user's shell, as listed in their password entry.
816
817 <tag/<tt/u-<var/name///
818 <item>
819 The value of the user-defined variable <var/name/ passed by the caller
820 using the <prgn/--defvar/ command-line option to the client.  If the
821 variable was not defined then this parameter is an empty list of
822 strings; in this case any condition which tests it will be false, and
823 <tt/include-lookup/ on it will read the <tt/:none/ file, or
824 <tt/:default/ if <tt/:none/ is not found.
825
826 </taglist>
827
828 <tag/<tt/errors-push/ <var/filename//
829 <tag/<tt/srorre//
830 <item>
831 Stacks the error handling behaviour currently in effect.  Any changes
832 to error handling will take effect only between <prgn/errors-push/ and
833 <prgn/srorre/.
834
835 <tag/<tt/catch-quit//
836 <tag/<tt/hctac//
837 <item>
838 Any use of <prgn/quit/ inside <prgn/catch-quit/ will merely cause the
839 parsing to continue at <prgn/hctac/ instead.  Any control constructs
840 started since the <prgn/catch-quit/ will be considered finished if a
841 <prgn/quit/ is found.
842 <p>
843
844 If an error occurs inside <prgn/catch-quit/ the execution settings
845 will be reset (as if by the <prgn/reset/ directive) and parsing will
846 likewise continue at <prgn/hctac/.
847 <p>
848
849 If a lexical or syntax error is detected in the same configuration
850 file as the <prgn/catch-quit/, while looking for the <prgn/hctac/
851 after an error or <prgn/quit/, that new error will not be caught.
852
853 </taglist>
854
855 <sect1 id="dirs-execution">Directives for changing execution settings
856 <p>
857
858 The following directives modify the execution settings; the server
859 will remember the fact that the directive was encountered and act on
860 it only after all the configuration has been parsed.  The <em/last/
861 directive which modifies any particuar setting will take effect.
862
863 <taglist>
864 <tag/<tt/reject//
865 <item>
866 Reject the request.  <prgn/execute/, <prgn/execute-from-directory/ and
867 <prgn/execute-from-path/ will change this setting.
868
869 <tag/<tt/execute <var/program/ [<var/argument/ ...]//
870 <item>
871 Execute the program <var/program/, with the arguments as specified,
872 followed by any arguments given to the client if
873 <prgn/no-suppress-args/ is in effect.  It is an error for the
874 execution to fail when it is attempted (after all the configuration
875 has been parsed).  If <var/program/ does not contain a slash it will
876 be searched for on the service user's path.
877
878 <tag/<tt/execute-from-directory <var/pathname/ [<var/argument/ ...]//
879 <item>
880 Take all the characters after the last slash of the service name
881 specified when the client was called, and execute that program in the
882 directory named by <var/pathname/ as if it had been specified for
883 <var/execute/.  The part of the service name used may contain only
884 alphanumerics and hyphens and must start with an alphanumeric (and it
885 must be non-empty), otherwise it is an error.
886 <p>
887
888 This directive is ignored if the relevant program does not exist in
889 the directory specified; in this case the program to execute is left
890 at its previous setting (or unset, if it was not set before).
891 <p>
892
893 It is an error for the test for the existence of the program to fail
894 other than with a `no such file or directory' indication.  It is also
895 an error for the execution to fail if and when it is attempted (after
896 all the configuration has been parsed).
897
898 <tag/<tt/execute-from-path//
899 <item>
900 <var/service/ is interpreted as a program on the default <prgn/PATH/
901 (or as a pathname of an executable, if it contains a <tt>/</>).  This
902 directive is <em/very dangerous/, and is only provided to make the
903 <prgn/--override/ options effective.  It should not normally be used.
904 It is an error for the execution to fail when it is attempted (after
905 all the configuration has been parsed).
906
907 <tag/<tt/execute-builtin <var/service-name/ <var/service-arguments//
908 <item>
909 Executes the builtin service <var/service-name/.  These builtin
910 services display information about the server and/or the request, and
911 ignore any arguments passed from the service side except possibly to
912 print them as part of their output.  They write their results to their
913 standard output (i.e., wherever file descriptor 1 is directed).  The
914 builtin services are:
915
916 <taglist compact>
917 <tag/<tt/execute//
918 <item>
919 Displays the execution settings, defined variables,
920 arguments, etc. with which the builtin service was invoked.
921
922 <tag/<tt/environment//
923 <item>
924 Displays the environment variable settings with which the builtin
925 service was invoked.
926
927 <tag/<tt/parameter <var/parameter///
928 <item>
929 Displays the values of the service configuration language parameter
930 specified.
931
932 <tag/<tt/version//
933 <item>
934 Displays the version string and compilation details of the uservd
935 server program.
936
937 <tag/<tt/reset//
938 <item>
939 Displays the default reset configuration (evaluated when <prgn/reset/
940 is found in a configuration file, or when an error is caught by
941 <prgn/catch-quit/).
942
943 <tag/<tt/toplevel//
944 <item>
945 Displays the top-level default configuration (the configuration data,
946 evaluated by the server, which calls all the other configuration
947 files).
948
949 <tag/<tt/override//
950 <item>
951 Displays the top-level override configuration (the configuration data,
952 evaluated by the server, which causes all the other configuration data
953 to be parsed).
954
955 <tag/<tt/help//
956 <item>
957 Displays a list of the understood builtin service names and arguments.
958 </taglist>
959
960 In the future other builtin services may be defined which do more than
961 just print information.
962
963 <tag/<tt/set-environment//
964 <tag/<tt/no-set-environment//
965 <item>
966 Runs <tt>/etc/environment</> to set the service user's environment.
967 This adds the overhead of invoking a shell, but doesn't cause any
968 shell (de)mangling of the service's arguments.  This is achieved by
969 invoking
970 <example>
971 .../program arg arg arg ...
972 </example>
973 as
974 <example>
975 /bin/sh -c '. /etc/environment; exec "$@"' - .../program arg arg arg ...
976 </example>
977 <prgn/no-set-environment/ cancels the effect of
978 <prgn/set-environment/.
979
980 <tag/<tt/no-suppress-args//
981 <tag/<tt/suppress-args//
982 <item>
983 Include any arguments given to the client as arguments to the program
984 invoked as a result of an <prgn/execute/,
985 <prgn/execute-from-directory/ or <prgn/execute-from-path/ directive.
986 <prgn/suppress-args/ undoes the effect of <prgn/no-suppress-args/.
987
988 <tag/<tt/require-fd <var/fd-range/ read|write//
989 <item>
990 Insist that the filedescriptor(s) be opened for reading resp. writing.
991 It is an error if any descriptor marked as required when the service
992 is about to be invoked (after the configuration has been parsed) was
993 not specified when the client was invoked.  Each file descriptor has a
994 separate setting, and the last one of <prgn/require-fd/,
995 <prgn/allow-fd/, <prgn/ignore-fd/, <prgn/null-fd/ or <prgn/reject-fd/
996 which affected a particular file descriptor will take effect.
997 <p>
998
999 <var/fd-range/ may be a single number, two numbers separated by a
1000 hyphen, or one number followed by a hyphen (indicating all descriptors
1001 from that number onwards).  It may also be one of the words
1002 <tt/stdin/, <tt/stdout/ or <tt/stderr/.  Open-ended file descriptor
1003 rangers are allowed only with <prgn/reject-fd/ and <prgn/ignore-fd/,
1004 as otherwise the service program would find itself with a very large
1005 number of file descriptors open.
1006 <p>
1007
1008 When the configuration has been parsed, and before the service is
1009 about to be executed, stderr (fd 2) must be required or allowed
1010 (<prgn/require-fd/ or <prgn/allow-fd/) for writing; this is so that
1011 the error message printed by the server's child process if it cannot
1012 <prgn/exec/ the service program is not lost.
1013
1014 <tag/<tt/allow-fd <var/fd-range/ [read|write]//
1015 <item>
1016 Allow the descriptor(s) to be opened for reading resp. writing, or
1017 either if neither <tt/read/ nor <tt/write/ is specified.  If a
1018 particular descriptor not specified by the client then it will be open
1019 onto <tt>/dev/null</> (for reading, writing, or both, depending on
1020 whether <tt/read/, <tt/write/ or neither was specified).
1021
1022 <tag/<tt/null-fd <var/fd-range/ [read|write]//
1023 <item>
1024 Specify that the descriptor(s) be opened onto <prgn>/dev/null</> for
1025 reading resp. writing, or both if neither <tt/read/ nor <tt/write/
1026 is specified.  Any specification of these file descriptors by the
1027 client will be silently ignored; the client will see its ends of the
1028 descriptors being closed immediately.
1029
1030 <tag/<tt/reject-fd <var/fd-range///
1031 <item>
1032 Do not allow the descriptor(s) to be specified by the client.  It is
1033 an error if any descriptor(s) marked for rejection are specified when
1034 the service is about to be invoked (after the configuration has been
1035 parsed).
1036
1037 <tag/<tt/ignore-fd <var/fd-range///
1038 <item>
1039 Silently ignore any specification by the client of those
1040 descriptor(s).  The pipes corresponding to these descriptors will be
1041 closed just before the service is invoked.
1042
1043 <tag/<tt/disconnect-hup//
1044 <tag/<tt/no-disconnect-hup//
1045 <item>
1046 Causes the service's process group to get a <prgn/SIGHUP/ if the
1047 client disconnects before the main service process terminates.
1048 <prgn/no-disconnect-hup/ cancels <prgn/disconnect-hup/.
1049 <p>
1050
1051 If one of the reading descriptors specified when the client is called
1052 gets a read error, or if the service is disconnected for some other
1053 reason, then the <prgn/SIGHUP/ will be delivered <em/before/ the
1054 writing end(s) of the service's reading pipe(s) are closed, so that
1055 the client can distinguish disconnection from reading EOF on a pipe.
1056
1057 <tag/<tt/reset//
1058 <item>
1059 Resets the execution settings to the default.  This is equivalent to:
1060 <example>
1061 cd ~/
1062 reject
1063 no-set-environment
1064 suppress-args
1065 allow-fd 0 read
1066 allow-fd 1-2 write
1067 reject-fd 3-
1068 disconnect-hup
1069 </example>
1070
1071 </taglist>
1072
1073 If no <prgn/execute/, <prgn/execute-from-path/,
1074 <prgn/execute-from-directory/ or <prgn/builtin/ is interpreted before
1075 all the files are read then the request is rejected.
1076
1077
1078 <sect id="configerrors">Errors in the configuration file
1079 <p>
1080
1081 If a syntax error or other problem occurs when processing a
1082 configuration file then a diagnostic will be issued, to wherever the
1083 error messages are currently being sent (see the <prgn/errors-/ family
1084 of directives, above).
1085 <p>
1086
1087 The error will cause processing of the configuration files to cease at
1088 that point, unless the error was inside a <prgn/catch-quit/ construct.
1089 In this case the settings controlling the program's execution will be
1090 reset to the defaults as if a <prgn/reset/ directive had been issued,
1091 and parsing continues after <prgn/hctac/.
1092
1093
1094 <sect id="defaults">Defaults
1095 <p>
1096
1097 The default configuration processing is as if the daemon were parsing
1098 an overall configuration file whose contents were as follows:
1099
1100 <example>
1101 reset
1102 user-rcfile ~/.userv/rc
1103 errors-to-stderr
1104 include /etc/userv/system.default
1105 if grep service-user-shell /etc/shells
1106    errors-push
1107      catch-quit
1108        include-ifexist <var/file specified by most recent user-rcfile directive/
1109      hctac
1110    srorre
1111 fi
1112 include /etc/userv/system.override
1113 quit
1114 </example>
1115 <p>
1116
1117 If one of the <prgn/--override/ options to the client is used then it
1118 will instead be as if the daemon were parsing an overall configuration
1119 as follows:
1120
1121 <example>
1122 reset
1123 errors-to-stderr
1124 include <var/file containing configuration data sent by client/
1125 quit
1126 </example>
1127
1128
1129 <chapt id="ipass">Information passed through the client/daemon combination
1130 <p>
1131
1132 The information described below is the only information which passes
1133 between the caller and the service.
1134
1135 <list>
1136 <item>
1137 The service name supplied by the caller is available in the
1138 configuration language for deciding whether and which service program
1139 to invoke, in the <prgn/service/ parameter, and is used by the
1140 <prgn/execute-from-directory/ and <prgn/execute-from-path/
1141 configuration directives.  It is usually used to select which service
1142 program to invoke.  It is also passed to the service program in the
1143 <prgn/USERV_SERVICE/ environment variable.
1144
1145 <item>
1146 File descriptors specified by the client and allowed according to the
1147 configuration language will be connected.  Each file descriptor is
1148 opened for reading or writing.  Communication is via pipes, one end of
1149 each pipe being open on the appropriate file descriptor in the service
1150 program (when it is invoked) and the other end being held by the
1151 client process, which will read and write files it opens on behalf of
1152 its caller or file descriptors it is passed by its caller.
1153 <p>
1154
1155 Data may be passed into the service through reading pipes and out of
1156 it through writing pipes.  These pipes can remain open only until the
1157 service and client have terminated, or can be made to stay open after
1158 the client has terminated and (if the service program forks) the main
1159 service process has exited; the behaviour is controlled by options
1160 passed to the client by its caller.
1161 <p>
1162
1163 The caller can arrange that a writing pipe be connected to a pipe or
1164 similar object and cause attempts to write to that descriptor by the
1165 service to generate a <prgn/SIGPIPE/ (or <prgn/EPIPE/ if
1166 <prgn/SIGPIPE/ is caught or ignored) in the service.
1167 <p>
1168
1169 Likewise, the service can close filedescriptors specified for reading,
1170 which will cause the corresponding filedescriptors passed by the
1171 caller to be closed, so that if these are pipes processes which write
1172 to them will receive <prgn/SIGPIPE/ or <prgn/EPIPE/.
1173
1174 <item>
1175 If <prgn/no-suppress-args/ is set then arguments passed to the client
1176 by its caller will be passed on, verbatim, to the service.
1177
1178 <item>
1179 Fatal signals and system call failures experienced by the client will
1180 result in the disconnection of the service from the client and
1181 possibly some of the communication file descriptors described above;
1182 if <prgn/disconnect-hup/ is set then the service will also be sent a
1183 <prgn/SIGHUP/.
1184
1185 <item>
1186 The value of the <prgn/LOGNAME/ (or <prgn/USER/) environment variable
1187 as passed to the client will be used as the login name of the calling
1188 user if the uid of the calling process matches the uid corresponding
1189 to that login name.  Otherwise the calling uid's password entry will
1190 be used to determine the calling user's login name.
1191 <p>
1192
1193 This login name and the calling uid are available in the configuration
1194 language in the <prgn/calling-user/ parameter and are passed to the
1195 service program in environment variables <prgn/USERV_USER/ and
1196 <prgn/USERV_UID/.
1197 <p>
1198
1199 The shell corresponding to that login name (according to the password
1200 entry) is available as in the configuration language's
1201 <prgn/calling-user-shell/ parameter.
1202 <p>
1203
1204 If no relevant password entry can be found then no service will be
1205 invoked.
1206
1207 <item>
1208 The numeric values and textual names for calling gid and supplementary
1209 group list are available in the configuration language in the
1210 <prgn/calling-group/ parameter and are passed to the service in
1211 environment variables.
1212 <p>
1213
1214 If no name can be found for a numeric group to which the calling
1215 process belongs then no service will be invoked.
1216
1217 <item>
1218 The name of the current working directory in which the client was
1219 invoked is passed, if available and not hidden using <prgn/--hidecwd/,
1220 to the service program in the <prgn/USERV_CWD/ variable.  This grants no
1221 special access to that directory unless it is a subdirectory of a
1222 directory which is executable (searchable) but not readable by the
1223 service user.
1224
1225 <item>
1226 Settings specified by the caller using the <tt/--defvar
1227 <var/name/=<var/value// option to the client are available in the
1228 configuration language as the corresponding <tt/u-<var/name//
1229 parameters and are passed to the service program in environment
1230 variables <tt/USERV_U_<var/name//.
1231
1232 <item>
1233 If the calling user is root or the same as the service user then
1234 options may be given to the client which bypass the usual security
1235 features; in this case other information may pass between the caller
1236 and the service.
1237
1238 </list>
1239
1240 <chapt id="notes">Applications and notes on use
1241 <p>
1242
1243 <sect id="standards">Standard services and directory management
1244 <p>
1245
1246 In later versions of this specification standard service names and
1247 interfaces for common services such as mail delivery and WWW CGI
1248 scripts will be specified.
1249 <p>
1250
1251 <prgn/userv/-using applications and system services which hide
1252 <prgn/userv/ behind wrapper scripts may need to store information in
1253 the user's filespace to preserve the correct placement of the security
1254 perimiters.  Such applications should usually do so in a directory
1255 (created by them) <tt>~/.userv/.servdata/<var/service/</>, where
1256 <var/service/ is the service name or application in question.
1257 <p>
1258
1259 The use of a dot-directory inside <tt>~/.userv</> will hopefully avoid
1260 the user becoming confused by finding parts of a semi-privileged
1261 application's internal state in their filespace, and or discourage
1262 them from fiddling with and thus corrupting it.  (Note that such
1263 applications should of course not rely for their global integrity on
1264 the integrity of the data on the user's side of the security
1265 boundary.)
1266
1267 <sect id="reducepriv">Reducing the number of absolutely privileged subsystems
1268 <p>
1269
1270 Currently most Unix systems have many components which need to run as
1271 root, even though most of their activity does not strictly require
1272 it.  This gives rise to a large and complex body of code which must be
1273 trusted with the security of the system.
1274 <p>
1275
1276 Using <prgn/userv/ many of these subsystems no longer need any unusual
1277 privilege.
1278 <p>
1279
1280 <prgn/cron/ and <prgn/at/, <prgn/lpr/ and the system's mail transfer
1281 agent (<prgn/sendmail/, <prgn/smail/, <prgn/exim/ or the like) all
1282 fall into this category.
1283
1284 <sect id="noexcess">Do not give away excessive privilege to <prgn/userv/-using facilities
1285 <p>
1286
1287 There is a danger that people reimplementing the facilities I mention
1288 above using <prgn/userv/ will discard much of the security benefit by
1289 using a naive implementation technique.  This will become clearer with
1290 an example:
1291 <p>
1292
1293 Consider the <prgn/lpr/ program.  In current systems this needs to
1294 have an absolutely privileged component in order to support delayed
1295 printing without copying: when the user queues a file to be printed
1296 the filename is stored in the print queue, rather than a copy of it,
1297 and the printer daemon accesses the file directly when it is ready to
1298 print the job.  In order that the user can print files which are not
1299 world-readable the daemon is given root privilege so that it can open
1300 the file in the context of the user, rather than its own.
1301 <p>
1302
1303 A simple-minded approach to converting this scheme to use <prgn/userv/
1304 might involve giving the printer daemon (the <prgn/lp/ user) the
1305 ability to read the file by allowing them to run <prgn/cat/ (or a
1306 special-purpose file-reading program) as any user.  The <prgn/lpr/
1307 program would use a <prgn/userv/ service to store the filename in the
1308 printer daemon's queues, and the daemon would read the file later when
1309 it felt like it.
1310 <p>
1311
1312 However, this would allow the printer daemon to read any file on the
1313 system, whether or not someone had asked for it to be printed.  Since
1314 many files will contain passwords and other security-critical
1315 information this is nearly as bad as giving the daemon root access in
1316 the first place.  Any security holes in the print server which allow a
1317 user to execute commands as the <prgn/lp/ user will give the user the
1318 ability to read any file on the system.
1319 <p>
1320
1321 Instead, it is necessary to keep a record of which files the daemon
1322 has been asked to print <em/outside/ the control of the print daemon.
1323 This record could be kept by a new root-privileged component, but this
1324 is not necessary: the record of which files a user has asked to be
1325 printed can be kept under the control of the user in question.  The
1326 submission program <prgn/lpr/ will make a record in an area under the
1327 user's control before communicating with the print server, and the
1328 print server would be given the ability to run a special file-reading
1329 program which would only allow files to be read which were listed in
1330 the user's file of things they'd asked to print.
1331 <p>
1332
1333 Now security holes in most of the printing system do not critically
1334 affect the security of the entire system: they only allow the attacker
1335 to read and interfere with print jobs.  Bugs in the programs run by the
1336 print server to read users' files (and to remove entries from the list
1337 of files when it has done with them) will still be serious, but this
1338 program can be quite simple.
1339 <p>
1340
1341 Similar considerations apply to many <prgn/userv/-based versions of
1342 facilities which currently run as root.
1343 <p>
1344
1345 It is debatable whether the user-controlled state should be kept in
1346 the user's filespace (in dotfiles, say) or kept in a separate area set
1347 aside for the purpose; however, using the user's home directory (and
1348 probably creating a separate subdirectory of it as a dotfile to
1349 contain many subsystems' state) has fewer implications for the rest of
1350 the system and makes it entirely clear where the security boundaries
1351 lie.
1352
1353 <sect id="notreally"><prgn/userv/ is not a replacement for <prgn/really/ and <prgn/sudo/
1354 <p>
1355
1356 <prgn/userv/ is not intended as a general-purpose system
1357 administration tool with which system administrators can execute
1358 privileged programs when they need to.  It is unsuitable for this
1359 purpose precisely because it enforces a strong separation between the
1360 calling and the called program, which is undesirable in this context.
1361 <p>
1362
1363 Its facilities for restricting activities to running certain programs
1364 may at first glance seem to provide similar functionality to
1365 <prgn/sudo/<footnote><prgn/sudo/ is a program which allows users to
1366 execute certain programs as root, according to configuration files
1367 specified by the system administrator.</footnote>.  However, the
1368 separation mentioned above is a problem here too, particular for
1369 interaction - it can be hard for a <prgn/userv/ service program to
1370 interact with its real caller or the user in question.
1371
1372 <sect id="nogeneral">Don't give access to general-purpose utilities
1373 <p>
1374
1375 Do not specify general purpose programs like <prgn/mv/ or <prgn/cat/
1376 in <prgn/execute-/ directives without careful thought about their
1377 arguments, and certainly not if <prgn/no-suppress-args/ is specified.
1378 If you do so it will give the caller much more privilige than you
1379 probably intend.
1380 <p>
1381
1382 It is a shame that I have to say this here, but inexperienced
1383 administrators have made similar mistakes with programs like
1384 <prgn/sudo/.
1385
1386 </book>