chiark / gitweb /
Rebuild everything for 0.95.0
[userv.git] / spec.sgml.in
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></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 or
645 files in other directories: values starting with full stops will have
646 a colon prepended (making <tt/:./), colons will be doubled, and each
647 slash will be replaced with a colon followed by a hyphen <tt>:-</>.  A
648 parameter value which is the empty string will be replaced with
649 <tt/:empty/ (note that this is different from a parameter not having
650 any values).
651
652 <tag/<tt/include-directory <var/directory///
653 <item>
654 Read configuration from all files in directory <var/directory/ which
655 are plain files whose names consist only of alphanumerics and hyphens
656 and start with an alphanumeric.  They will be read in lexical order.
657 It is an error for the directory not to exist or for it or any of the
658 files found not to be read successfully, or for anything with an
659 appropriate name not to be a plain file or a symbolic link to a plain
660 file.
661
662 <tag/<tt/error <var/text ...///
663 <item>
664 Causes an error whose message includes the descriptive string
665 <var/text/.  <var/text/ may consist of several tokens with intervening
666 whitespace.  The whitespace will be included in the message as found
667 in the configuration file: all the characters until the end of the
668 line will be included verbatim, unless they are part of a
669 double-quoted string, in which case the usual meaning of the string
670 (i.e., after backslash escape processing) will be used.  Comments and
671 linear whitespace at the end of the line (or just before the comment)
672 will still be ignored.
673
674 <tag/<tt/message <var/text ...///
675 <item>
676 Causes a message including the descriptive string <var/text/ to be
677 delivered as if it were an error message, but does not actually cause
678 an error.
679 </taglist>
680
681 <sect1 id="dirs-delayed">Directives with delayed effect
682 <p>
683
684 The following directives have no immediate effect, but are remembered
685 and have an effect on later processing of the configuration files.
686
687 <taglist>
688 <tag/<tt/user-rcfile <var/filename///
689 <item>
690 Specifies that the file <var/filename/ should be read instead of the
691 user's <tt>~/.userv/rc</>.  This does <em/not/ happen immediately;
692 instead, the setting is remembered and used after the
693 <prgn/system.default/ configuration file has been read.  This
694 directive has no effect in a user's configuration file or in the
695 <prgn/system.override/ file, as the user's configuration file has
696 already been found and read by then and will not be re-read.
697
698 <tag/<tt/errors-to-stderr//
699 <item>
700 Causes error messages to be delivered to the client's stderr.
701
702 <tag/<tt/errors-to-file/ <var/filename//
703 <item>
704 Error messages will be written to <var/filename/, which will be opened
705 in the context of and with the privileges of the service user.
706
707 <tag/<tt/errors-to-syslog/ [<var/facility/ [<var/level/]]/
708 <item>
709 Error messages will be delivered using <prgn/syslog/.  The default
710 <var/facility/ is <tt/user/; the default <var/level/ is <tt/error/.
711 </taglist>
712
713 <sect1 id="dirs-control">Control structure directives
714 <p>
715
716 The following directives are used to create control structures.  If
717 the end of the file is encountered before the end of any control
718 structure which was started inside it then that control structure is
719 considered finished.  This is not an error.
720
721 <taglist>
722 <tag/<tt/if <var/condition///
723 <tag/<tt/elif <var/condition///
724 <tag/<tt/else//
725 <tag/<tt/fi//
726 <item>
727 Lines following <prgn/if/ are interpreted only if the condition is
728 true.  Many conditions are properties of parameter values.  Most
729 parameters have a single string as a value; however, some may yield
730 zero or several strings, in which case the condition is true if it is
731 true of any of the strings individually.  Parameters are described
732 below.
733 <p>
734
735 The conditions are:
736
737 <taglist compact>
738 <tag/<tt/glob <var/parameter/ <var/glob-pattern/ ...//
739 <item>
740 The value of the parameter whose name is given matches one of the glob
741 patterns (anchored at both ends; backslashes can be used to escape
742 metacharacters).
743
744 <tag/<tt/range <var/parameter/ <var/min/ <var/max///
745 <item>
746 The value of the parameter is a nonnegative integer and lies within
747 the range specified.  <var/min/ or <var/max/ may be <tt/$/ to indicate
748 no lower or upper limit, respectively.
749
750 <tag/<tt/grep <var/parameter/ <var/filename///
751 <item>
752 The <var/filename/ refers to a file one of whose lines is the value of
753 the parameter (leading or trailing whitespace on each line and empty
754 lines in the file are ignored).  It is an error for the file not to be
755 opened and read.
756
757 <tag/<tt/! <var/condition///
758 <item>
759 The <var/condition/ is <em/not/ true.
760
761 <tag/Conjunctions: <tt/&amp;/ and <tt/|//
762 <item>
763 <example>
764 ( <var/condition/
765 &amp; <var/condition/
766 &amp; <var/condition/
767 ...
768 )
769 </example>
770 is true if all the listed conditions are true; where <tt/|/ is used it
771 is true if any of them is true.  Newlines must be used to separate one
772 condition from the next, as shown, and the parentheses are mandatory.
773 These conjunctions do not do lazy evaluation.
774 </taglist>
775 <p>
776
777 The parameters are:
778
779 <taglist compact>
780 <tag/<tt/service//
781 <item>
782 The service name specified when the client was called.
783
784 <tag/<tt/calling-user//
785 <item>
786 Two strings: the login name of the calling user (determined as for
787 <prgn/USERV_USER/, above) and the calling uid (represented in
788 decimal).
789
790 <tag/<tt/calling-group//
791 <item>
792 Several strings: the primary and supplementary group names and gids
793 (in decimal) of the calling process.  All the group names come first,
794 and then the gids.  If the first supplementary group is the same as
795 the primary group then it is elided.
796
797 <tag/<tt/calling-user-shell//
798 <item>
799 The calling user's shell, as listed in the password entry for the
800 calling login name (as determined for <prgn/USERV_USER/, above).
801
802 <tag/<tt/service-user//
803 <item>
804 Two strings: the name of the service user (as specified to the client)
805 and their uid (represented in decimal).
806
807 <tag/<tt/service-group//
808 <item>
809 Several strings: the primary and supplementary group names and gids
810 (in decimal) of the service user.
811
812 <tag/<tt/service-user-shell//
813 <item>
814 The service user's shell, as listed in their password entry.
815
816 <tag/<tt/u-<var/name///
817 <item>
818 The value of the user-defined variable <var/name/ passed by the caller
819 using the <prgn/--defvar/ command-line option to the client.  If the
820 variable was not defined then this parameter is an empty list of
821 strings; in this case any condition which tests it will be false, and
822 <tt/include-lookup/ on it will read the <tt/:none/ file, or
823 <tt/:default/ if <tt/:none/ is not found.
824
825 </taglist>
826
827 <tag/<tt/errors-push/ <var/filename//
828 <tag/<tt/srorre//
829 <item>
830 Stacks the error handling behaviour currently in effect.  Any changes
831 to error handling will take effect only between <prgn/errors-push/ and
832 <prgn/srorre/.
833
834 <tag/<tt/catch-quit//
835 <tag/<tt/hctac//
836 <item>
837 Any use of <prgn/quit/ inside <prgn/catch-quit/ will merely cause the
838 parsing to continue at <prgn/hctac/ instead.  Any control constructs
839 started since the <prgn/catch-quit/ will be considered finished if a
840 <prgn/quit/ is found.
841 <p>
842
843 If an error occurs inside <prgn/catch-quit/ the execution settings
844 will be reset (as if by the <prgn/reset/ directive) and parsing will
845 likewise continue at <prgn/hctac/.
846 <p>
847
848 If a lexical or syntax error is detected in the same configuration
849 file as the <prgn/catch-quit/, while looking for the <prgn/hctac/
850 after an error or <prgn/quit/, that new error will not be caught.
851
852 </taglist>
853
854 <sect1 id="dirs-execution">Directives for changing execution settings
855 <p>
856
857 The following directives modify the execution settings; the server
858 will remember the fact that the directive was encountered and act on
859 it only after all the configuration has been parsed.  The <em/last/
860 directive which modifies any particuar setting will take effect.
861
862 <taglist>
863 <tag/<tt/reject//
864 <item>
865 Reject the request.  <prgn/execute/, <prgn/execute-from-directory/ and
866 <prgn/execute-from-path/ will change this setting.
867
868 <tag/<tt/execute <var/program/ [<var/argument/ ...]//
869 <item>
870 Execute the program <var/program/, with the arguments as specified,
871 followed by any arguments given to the client if
872 <prgn/no-suppress-args/ is in effect.  It is an error for the
873 execution to fail when it is attempted (after all the configuration
874 has been parsed).  If <var/program/ does not contain a slash it will
875 be searched for on the service user's path.
876
877 <tag/<tt/execute-from-directory <var/pathname/ [<var/argument/ ...]//
878 <item>
879 Take all the characters after the last slash of the service name
880 specified when the client was called, and execute that program in the
881 directory named by <var/pathname/ as if it had been specified for
882 <var/execute/.  The part of the service name used may contain only
883 alphanumerics and hyphens and must start with an alphanumeric (and it
884 must be non-empty), otherwise it is an error.
885 <p>
886
887 This directive is ignored if the relevant program does not exist in
888 the directory specified; in this case the program to execute is left
889 at its previous setting (or unset, if it was not set before).
890 <p>
891
892 It is an error for the test for the existence of the program to fail
893 other than with a `no such file or directory' indication.  It is also
894 an error for the execution to fail if and when it is attempted (after
895 all the configuration has been parsed).
896
897 <tag/<tt/execute-from-path//
898 <item>
899 <var/service/ is interpreted as a program on the default <prgn/PATH/
900 (or as a pathname of an executable, if it contains a <tt>/</>).  This
901 directive is <em/very dangerous/, and is only provided to make the
902 <prgn/--override/ options effective.  It should not normally be used.
903 It is an error for the execution to fail when it is attempted (after
904 all the configuration has been parsed).
905
906 <tag/<tt/execute-builtin <var/service-name/ <var/service-arguments//
907 <item>
908 Executes the builtin service <var/service-name/.  These builtin
909 services display information about the server and/or the request, and
910 ignore any arguments passed from the service side except possibly to
911 print them as part of their output.  They write their results to their
912 standard output (i.e., wherever file descriptor 1 is directed).  The
913 builtin services are:
914
915 <taglist compact>
916 <tag/<tt/execute//
917 <item>
918 Displays the execution settings, defined variables,
919 arguments, etc. with which the builtin service was invoked.
920
921 <tag/<tt/environment//
922 <item>
923 Displays the environment variable settings with which the builtin
924 service was invoked.
925
926 <tag/<tt/parameter <var/parameter///
927 <item>
928 Displays the values of the service configuration language parameter
929 specified.
930
931 <tag/<tt/version//
932 <item>
933 Displays the version string and compilation details of the uservd
934 server program.
935
936 <tag/<tt/reset//
937 <item>
938 Displays the default reset configuration (evaluated when <prgn/reset/
939 is found in a configuration file, or when an error is caught by
940 <prgn/catch-quit/).
941
942 <tag/<tt/toplevel//
943 <item>
944 Displays the top-level default configuration (the configuration data,
945 evaluated by the server, which calls all the other configuration
946 files).
947
948 <tag/<tt/override//
949 <item>
950 Displays the top-level override configuration (the configuration data,
951 evaluated by the server, which causes all the other configuration data
952 to be parsed).
953
954 <tag/<tt/help//
955 <item>
956 Displays a list of the understood builtin service names and arguments.
957 </taglist>
958
959 In the future other builtin services may be defined which do more than
960 just print information.
961
962 <tag/<tt/set-environment//
963 <tag/<tt/no-set-environment//
964 <item>
965 Runs <tt>/etc/environment</> to set the service user's environment.
966 This adds the overhead of invoking a shell, but doesn't cause any
967 shell (de)mangling of the service's arguments.  This is achieved by
968 invoking
969 <example>
970 .../program arg arg arg ...
971 </example>
972 as
973 <example>
974 /bin/sh -c '. /etc/environment; exec "$@"' - .../program arg arg arg ...
975 </example>
976 <prgn/no-set-environment/ cancels the effect of
977 <prgn/set-environment/.
978
979 <tag/<tt/no-suppress-args//
980 <tag/<tt/suppress-args//
981 <item>
982 Include any arguments given to the client as arguments to the program
983 invoked as a result of an <prgn/execute/,
984 <prgn/execute-from-directory/ or <prgn/execute-from-path/ directive.
985 <prgn/suppress-args/ undoes the effect of <prgn/no-suppress-args/.
986
987 <tag/<tt/require-fd <var/fd-range/ read|write//
988 <item>
989 Insist that the filedescriptor(s) be opened for reading resp. writing.
990 It is an error if any descriptor marked as required when the service
991 is about to be invoked (after the configuration has been parsed) was
992 not specified when the client was invoked.  Each file descriptor has a
993 separate setting, and the last one of <prgn/require-fd/,
994 <prgn/allow-fd/, <prgn/ignore-fd/, <prgn/null-fd/ or <prgn/reject-fd/
995 which affected a particular file descriptor will take effect.
996 <p>
997
998 <var/fd-range/ may be a single number, two numbers separated by a
999 hyphen, or one number followed by a hyphen (indicating all descriptors
1000 from that number onwards).  It may also be one of the words
1001 <tt/stdin/, <tt/stdout/ or <tt/stderr/.  Open-ended file descriptor
1002 rangers are allowed only with <prgn/reject-fd/ and <prgn/ignore-fd/,
1003 as otherwise the service program would find itself with a very large
1004 number of file descriptors open.
1005 <p>
1006
1007 When the configuration has been parsed, and before the service is
1008 about to be executed, stderr (fd 2) must be required or allowed
1009 (<prgn/require-fd/ or <prgn/allow-fd/) for writing; this is so that
1010 the error message printed by the server's child process if it cannot
1011 <prgn/exec/ the service program is not lost.
1012
1013 <tag/<tt/allow-fd <var/fd-range/ [read|write]//
1014 <item>
1015 Allow the descriptor(s) to be opened for reading resp. writing, or
1016 either if neither <tt/read/ nor <tt/write/ is specified.  If a
1017 particular descriptor not specified by the client then it will be open
1018 onto <tt>/dev/null</> (for reading, writing, or both, depending on
1019 whether <tt/read/, <tt/write/ or neither was specified).
1020
1021 <tag/<tt/null-fd <var/fd-range/ [read|write]//
1022 <item>
1023 Specify that the descriptor(s) be opened onto <prgn>/dev/null</> for
1024 reading resp. writing, or both if neither <tt/read/ nor <tt/write/
1025 is specified.  Any specification of these file descriptors by the
1026 client will be silently ignored; the client will see its ends of the
1027 descriptors being closed immediately.
1028
1029 <tag/<tt/reject-fd <var/fd-range///
1030 <item>
1031 Do not allow the descriptor(s) to be specified by the client.  It is
1032 an error if any descriptor(s) marked for rejection are specified when
1033 the service is about to be invoked (after the configuration has been
1034 parsed).
1035
1036 <tag/<tt/ignore-fd <var/fd-range///
1037 <item>
1038 Silently ignore any specification by the client of those
1039 descriptor(s).  The pipes corresponding to these descriptors will be
1040 closed just before the service is invoked.
1041
1042 <tag/<tt/disconnect-hup//
1043 <tag/<tt/no-disconnect-hup//
1044 <item>
1045 Causes the service's process group to get a <prgn/SIGHUP/ if the
1046 client disconnects before the main service process terminates.
1047 <prgn/no-disconnect-hup/ cancels <prgn/disconnect-hup/.
1048 <p>
1049
1050 If one of the reading descriptors specified when the client is called
1051 gets a read error, or if the service is disconnected for some other
1052 reason, then the <prgn/SIGHUP/ will be delivered <em/before/ the
1053 writing end(s) of the service's reading pipe(s) are closed, so that
1054 the client can distinguish disconnection from reading EOF on a pipe.
1055
1056 <tag/<tt/reset//
1057 <item>
1058 Resets the execution settings to the default.  This is equivalent to:
1059 <example>
1060 cd ~/
1061 reject
1062 no-set-environment
1063 suppress-args
1064 allow-fd 0 read
1065 allow-fd 1-2 write
1066 reject-fd 3-
1067 disconnect-hup
1068 </example>
1069
1070 </taglist>
1071
1072 If no <prgn/execute/, <prgn/execute-from-path/,
1073 <prgn/execute-from-directory/ or <prgn/builtin/ is interpreted before
1074 all the files are read then the request is rejected.
1075
1076
1077 <sect id="configerrors">Errors in the configuration file
1078 <p>
1079
1080 If a syntax error or other problem occurs when processing a
1081 configuration file then a diagnostic will be issued, to wherever the
1082 error messages are currently being sent (see the <prgn/errors-/ family
1083 of directives, above).
1084 <p>
1085
1086 The error will cause processing of the configuration files to cease at
1087 that point, unless the error was inside a <prgn/catch-quit/ construct.
1088 In this case the settings controlling the program's execution will be
1089 reset to the defaults as if a <prgn/reset/ directive had been issued,
1090 and parsing continues after <prgn/hctac/.
1091
1092
1093 <sect id="defaults">Defaults
1094 <p>
1095
1096 The default configuration processing is as if the daemon were parsing
1097 an overall configuration file whose contents were as follows:
1098
1099 <example>
1100 reset
1101 user-rcfile ~/.userv/rc
1102 errors-to-stderr
1103 include /etc/userv/system.default
1104 if grep service-user-shell /etc/shells
1105    errors-push
1106      catch-quit
1107        include-ifexist <var/file specified by most recent user-rcfile directive/
1108      hctac
1109    srorre
1110 fi
1111 include /etc/userv/system.override
1112 quit
1113 </example>
1114 <p>
1115
1116 If one of the <prgn/--override/ options to the client is used then it
1117 will instead be as if the daemon were parsing an overall configuration
1118 as follows:
1119
1120 <example>
1121 reset
1122 errors-to-stderr
1123 include <var/file containing configuration data sent by client/
1124 quit
1125 </example>
1126
1127
1128 <chapt id="ipass">Information passed through the client/daemon combination
1129 <p>
1130
1131 The information described below is the only information which passes
1132 between the caller and the service.
1133
1134 <list>
1135 <item>
1136 The service name supplied by the caller is available in the
1137 configuration language for deciding whether and which service program
1138 to invoke, in the <prgn/service/ parameter, and is used by the
1139 <prgn/execute-from-directory/ and <prgn/execute-from-path/
1140 configuration directives.  It is usually used to select which service
1141 program to invoke.  It is also passed to the service program in the
1142 <prgn/USERV_SERVICE/ environment variable.
1143
1144 <item>
1145 File descriptors specified by the client and allowed according to the
1146 configuration language will be connected.  Each file descriptor is
1147 opened for reading or writing.  Communication is via pipes, one end of
1148 each pipe being open on the appropriate file descriptor in the service
1149 program (when it is invoked) and the other end being held by the
1150 client process, which will read and write files it opens on behalf of
1151 its caller or file descriptors it is passed by its caller.
1152 <p>
1153
1154 Data may be passed into the service through reading pipes and out of
1155 it through writing pipes.  These pipes can remain open only until the
1156 service and client have terminated, or can be made to stay open after
1157 the client has terminated and (if the service program forks) the main
1158 service process has exited; the behaviour is controlled by options
1159 passed to the client by its caller.
1160 <p>
1161
1162 The caller can arrange that a writing pipe be connected to a pipe or
1163 similar object and cause attempts to write to that descriptor by the
1164 service to generate a <prgn/SIGPIPE/ (or <prgn/EPIPE/ if
1165 <prgn/SIGPIPE/ is caught or ignored) in the service.
1166 <p>
1167
1168 Likewise, the service can close filedescriptors specified for reading,
1169 which will cause the corresponding filedescriptors passed by the
1170 caller to be closed, so that if these are pipes processes which write
1171 to them will receive <prgn/SIGPIPE/ or <prgn/EPIPE/.
1172
1173 <item>
1174 If <prgn/no-suppress-args/ is set then arguments passed to the client
1175 by its caller will be passed on, verbatim, to the service.
1176
1177 <item>
1178 Fatal signals and system call failures experienced by the client will
1179 result in the disconnection of the service from the client and
1180 possibly some of the communication file descriptors described above;
1181 if <prgn/disconnect-hup/ is set then the service will also be sent a
1182 <prgn/SIGHUP/.
1183
1184 <item>
1185 The value of the <prgn/LOGNAME/ (or <prgn/USER/) environment variable
1186 as passed to the client will be used as the login name of the calling
1187 user if the uid of the calling process matches the uid corresponding
1188 to that login name.  Otherwise the calling uid's password entry will
1189 be used to determine the calling user's login name.
1190 <p>
1191
1192 This login name and the calling uid are available in the configuration
1193 language in the <prgn/calling-user/ parameter and are passed to the
1194 service program in environment variables <prgn/USERV_USER/ and
1195 <prgn/USERV_UID/.
1196 <p>
1197
1198 The shell corresponding to that login name (according to the password
1199 entry) is available as in the configuration language's
1200 <prgn/calling-user-shell/ parameter.
1201 <p>
1202
1203 If no relevant password entry can be found then no service will be
1204 invoked.
1205
1206 <item>
1207 The numeric values and textual names for calling gid and supplementary
1208 group list are available in the configuration language in the
1209 <prgn/calling-group/ parameter and are passed to the service in
1210 environment variables.
1211 <p>
1212
1213 If no name can be found for a numeric group to which the calling
1214 process belongs then no service will be invoked.
1215
1216 <item>
1217 The name of the current working directory in which the client was
1218 invoked is passed, if available and not hidden using <prgn/--hidecwd/,
1219 to the service program in the <prgn/USERV_CWD/ variable.  This grants no
1220 special access to that directory unless it is a subdirectory of a
1221 directory which is executable (searchable) but not readable by the
1222 service user.
1223
1224 <item>
1225 Settings specified by the caller using the <tt/--defvar
1226 <var/name/=<var/value// option to the client are available in the
1227 configuration language as the corresponding <tt/u-<var/name//
1228 parameters and are passed to the service program in environment
1229 variables <tt/USERV_U_<var/name//.
1230
1231 <item>
1232 If the calling user is root or the same as the service user then
1233 options may be given to the client which bypass the usual security
1234 features; in this case other information may pass between the caller
1235 and the service.
1236
1237 </list>
1238
1239 <chapt id="notes">Applications and notes on use
1240 <p>
1241
1242 <sect id="standards">Standard services and directory management
1243 <p>
1244
1245 In later versions of this specification standard service names and
1246 interfaces for common services such as mail delivery and WWW CGI
1247 scripts will be specified.
1248 <p>
1249
1250 <prgn/userv/-using applications and system services which hide
1251 <prgn/userv/ behind wrapper scripts may need to store information in
1252 the user's filespace to preserve the correct placement of the security
1253 perimiters.  Such applications should usually do so in a directory
1254 (created by them) <tt>~/.userv/.servdata/<var/service/</>, where
1255 <var/service/ is the service name or application in question.
1256 <p>
1257
1258 The use of a dot-directory inside <tt>~/.userv</> will hopefully avoid
1259 the user becoming confused by finding parts of a semi-privileged
1260 application's internal state in their filespace, and or discourage
1261 them from fiddling with and thus corrupting it.  (Note that such
1262 applications should of course not rely for their global integrity on
1263 the integrity of the data on the user's side of the security
1264 boundary.)
1265
1266 <sect id="reducepriv">Reducing the number of absolutely privileged subsystems
1267 <p>
1268
1269 Currently most Unix systems have many components which need to run as
1270 root, even though most of their activity does not strictly require
1271 it.  This gives rise to a large and complex body of code which must be
1272 trusted with the security of the system.
1273 <p>
1274
1275 Using <prgn/userv/ many of these subsystems no longer need any unusual
1276 privilege.
1277 <p>
1278
1279 <prgn/cron/ and <prgn/at/, <prgn/lpr/ and the system's mail transfer
1280 agent (<prgn/sendmail/, <prgn/smail/, <prgn/exim/ or the like) all
1281 fall into this category.
1282
1283 <sect id="noexcess">Do not give away excessive privilege to <prgn/userv/-using facilities
1284 <p>
1285
1286 There is a danger that people reimplementing the facilities I mention
1287 above using <prgn/userv/ will discard much of the security benefit by
1288 using a naive implementation technique.  This will become clearer with
1289 an example:
1290 <p>
1291
1292 Consider the <prgn/lpr/ program.  In current systems this needs to
1293 have an absolutely privileged component in order to support delayed
1294 printing without copying: when the user queues a file to be printed
1295 the filename is stored in the print queue, rather than a copy of it,
1296 and the printer daemon accesses the file directly when it is ready to
1297 print the job.  In order that the user can print files which are not
1298 world-readable the daemon is given root privilege so that it can open
1299 the file in the context of the user, rather than its own.
1300 <p>
1301
1302 A simple-minded approach to converting this scheme to use <prgn/userv/
1303 might involve giving the printer daemon (the <prgn/lp/ user) the
1304 ability to read the file by allowing them to run <prgn/cat/ (or a
1305 special-purpose file-reading program) as any user.  The <prgn/lpr/
1306 program would use a <prgn/userv/ service to store the filename in the
1307 printer daemon's queues, and the daemon would read the file later when
1308 it felt like it.
1309 <p>
1310
1311 However, this would allow the printer daemon to read any file on the
1312 system, whether or not someone had asked for it to be printed.  Since
1313 many files will contain passwords and other security-critical
1314 information this is nearly as bad as giving the daemon root access in
1315 the first place.  Any security holes in the print server which allow a
1316 user to execute commands as the <prgn/lp/ user will give the user the
1317 ability to read any file on the system.
1318 <p>
1319
1320 Instead, it is necessary to keep a record of which files the daemon
1321 has been asked to print <em/outside/ the control of the print daemon.
1322 This record could be kept by a new root-privileged component, but this
1323 is not necessary: the record of which files a user has asked to be
1324 printed can be kept under the control of the user in question.  The
1325 submission program <prgn/lpr/ will make a record in an area under the
1326 user's control before communicating with the print server, and the
1327 print server would be given the ability to run a special file-reading
1328 program which would only allow files to be read which were listed in
1329 the user's file of things they'd asked to print.
1330 <p>
1331
1332 Now security holes in most of the printing system do not critically
1333 affect the security of the entire system: they only allow the attacker
1334 to read and interfere with print jobs.  Bugs in the programs run by the
1335 print server to read users' files (and to remove entries from the list
1336 of files when it has done with them) will still be serious, but this
1337 program can be quite simple.
1338 <p>
1339
1340 Similar considerations apply to many <prgn/userv/-based versions of
1341 facilities which currently run as root.
1342 <p>
1343
1344 It is debatable whether the user-controlled state should be kept in
1345 the user's filespace (in dotfiles, say) or kept in a separate area set
1346 aside for the purpose; however, using the user's home directory (and
1347 probably creating a separate subdirectory of it as a dotfile to
1348 contain many subsystems' state) has fewer implications for the rest of
1349 the system and makes it entirely clear where the security boundaries
1350 lie.
1351
1352 <sect id="notreally"><prgn/userv/ is not a replacement for <prgn/really/ and <prgn/sudo/
1353 <p>
1354
1355 <prgn/userv/ is not intended as a general-purpose system
1356 administration tool with which system administrators can execute
1357 privileged programs when they need to.  It is unsuitable for this
1358 purpose precisely because it enforces a strong separation between the
1359 calling and the called program, which is undesirable in this context.
1360 <p>
1361
1362 Its facilities for restricting activities to running certain programs
1363 may at first glance seem to provide similar functionality to
1364 <prgn/sudo/<footnote><prgn/sudo/ is a program which allows users to
1365 execute certain programs as root, according to configuration files
1366 specified by the system administrator.</footnote>.  However, the
1367 separation mentioned above is a problem here too, particular for
1368 interaction - it can be hard for a <prgn/userv/ service program to
1369 interact with its real caller or the user in question.
1370
1371 <sect id="nogeneral">Don't give access to general-purpose utilities
1372 <p>
1373
1374 Do not specify general purpose programs like <prgn/mv/ or <prgn/cat/
1375 in <prgn/execute-/ directives without careful thought about their
1376 arguments, and certainly not if <prgn/no-suppress-args/ is specified.
1377 If you do so it will give the caller much more privilige than you
1378 probably intend.
1379 <p>
1380
1381 It is a shame that I have to say this here, but inexperienced
1382 administrators have made similar mistakes with programs like
1383 <prgn/sudo/.
1384
1385 </book>