aboutsummaryrefslogtreecommitdiff
path: root/printutils/lpd.c
diff options
context:
space:
mode:
Diffstat (limited to 'printutils/lpd.c')
-rw-r--r--printutils/lpd.c45
1 files changed, 26 insertions, 19 deletions
diff --git a/printutils/lpd.c b/printutils/lpd.c
index cac881383..bc0348eba 100644
--- a/printutils/lpd.c
+++ b/printutils/lpd.c
@@ -10,37 +10,40 @@
10/* 10/*
11 * A typical usage of BB lpd looks as follows: 11 * A typical usage of BB lpd looks as follows:
12 * # tcpsvd -E 0 515 lpd SPOOLDIR [HELPER-PROG [ARGS...]] 12 * # tcpsvd -E 0 515 lpd SPOOLDIR [HELPER-PROG [ARGS...]]
13 * 13 *
14 * This means a network listener is started on port 515 (default for LP protocol). 14 * This means a network listener is started on port 515 (default for LP protocol).
15 * When a client connection is made (via lpr) lpd first change its working directory to SPOOLDIR. 15 * When a client connection is made (via lpr) lpd first change its working directory to SPOOLDIR.
16 * 16 *
17 * SPOOLDIR is the spool directory which contains printing queues 17 * SPOOLDIR is the spool directory which contains printing queues
18 * and should have the following structure: 18 * and should have the following structure:
19 * 19 *
20 * SPOOLDIR/ 20 * SPOOLDIR/
21 * <queue1> 21 * <queue1>
22 * ... 22 * ...
23 * <queueN> 23 * <queueN>
24 * 24 *
25 * <queueX> can be of two types: 25 * <queueX> can be of two types:
26 * A. a printer character device or an ordinary file a link to such; 26 * A. a printer character device or an ordinary file a link to such;
27 * B. a directory. 27 * B. a directory.
28 * 28 *
29 * In case A lpd just dumps the data it receives from client (lpr) to the 29 * In case A lpd just dumps the data it receives from client (lpr) to the
30 * end of queue file/device. This is non-spooling mode. 30 * end of queue file/device. This is non-spooling mode.
31 * 31 *
32 * In case B lpd enters spooling mode. It reliably saves client data along with control info 32 * In case B lpd enters spooling mode. It reliably saves client data along with control info
33 * in two unique files under the queue directory. These files are named dfAXXXHHHH and cfAXXXHHHH, 33 * in two unique files under the queue directory. These files are named dfAXXXHHHH and cfAXXXHHHH,
34 * where XXX is the job number and HHHH is the client hostname. Unless a printing helper application 34 * where XXX is the job number and HHHH is the client hostname. Unless a printing helper application
35 * is specified lpd is done at this point. 35 * is specified lpd is done at this point.
36 * 36 *
37 * NB: file names are produced by peer! They actually may be anything at all!
38 * lpd only sanitizes them (by removing most non-alphanumerics).
39 *
37 * If HELPER-PROG (with optional arguments) is specified then lpd continues to process client data: 40 * If HELPER-PROG (with optional arguments) is specified then lpd continues to process client data:
38 * 1. it reads and parses control file (cfA...). The parse process results in setting environment 41 * 1. it reads and parses control file (cfA...). The parse process results in setting environment
39 * variables whose values were passed in control file; when parsing is complete, lpd deletes 42 * variables whose values were passed in control file; when parsing is complete, lpd deletes
40 * control file. 43 * control file.
41 * 2. it spawns specified helper application. It is then the helper application who is responsible 44 * 2. it spawns specified helper application. It is then the helper application who is responsible
42 * for both actual printing and deleting processed data file. 45 * for both actual printing and deleting processed data file.
43 * 46 *
44 * A good lpr passes control files which when parsed provide the following variables: 47 * A good lpr passes control files which when parsed provide the following variables:
45 * $H = host which issues the job 48 * $H = host which issues the job
46 * $P = user who prints 49 * $P = user who prints
@@ -49,13 +52,17 @@
49 * $L = print banner page 52 * $L = print banner page
50 * $M = the user to whom a mail should be sent if a problem occurs 53 * $M = the user to whom a mail should be sent if a problem occurs
51 * $l = name of datafile ("dfAxxx") - file whose content are to be printed 54 * $l = name of datafile ("dfAxxx") - file whose content are to be printed
52 * 55 *
56 * lpd also provides $DATAFILE environment variable - the ACTUAL name
57 * of the datafile under which it was saved.
58 * $l is not reliable (you are at mercy of remote peer), DON'T USE IT.
59 *
53 * Thus, a typical helper can be something like this: 60 * Thus, a typical helper can be something like this:
54 * #!/bin/sh 61 * #!/bin/sh
55 * cat "$l" >/dev/lp0 62 * cat "$l" >/dev/lp0
56 * mv -f "$l" save/ 63 * mv -f "$l" save/
57 *
58 */ 64 */
65
59#include "libbb.h" 66#include "libbb.h"
60 67
61// strip argument of bad chars 68// strip argument of bad chars