ptg10805159
Section 21.5 Source Code 799
The next file is theprint.hheader.
1#ifndef _PRINT_H
2#define _PRINT_H
3/*
4*Print server header file.
5*/
6#include <sys/socket.h>
7#include <arpa/inet.h>
8#include <netdb.h>
9#include <errno.h>
10 #define CONFIG_FILE "/etc/printer.conf"
11 #define SPOOLDIR "/var/spool/printer"
12 #define JOBFILE "jobno"
13 #define DATADIR "data"
14 #define REQDIR "reqs"
15 #if defined(BSD)
16 #define LPNAME "daemon"
17 #elif defined(MACOS)
18 #define LPNAME "_lp"
19 #else
20 #define LPNAME "lp"
21 #endif
[1 – 9] We include all header files that an application might need if it included this
header.This makes it easy for applications to include print.hwithout
having to track down all the header dependencies.
[10 – 14] We define the files and directories for the implementation. The configuration
file containing the host names of the printer spooling daemon and the
network-attached printer is/etc/printer.conf.Copies of the files to be
printed will be stored in the directory/var/spool/printer/data and
control information for each request will be stored in the directory
/var/spool/printer/reqs.The file containing the next job number is
/var/spool/printer/jobno.
The directories must be created by an administrator and be owned by the same
user account under which the printer spooling daemon runs. The daemon
won’t try to create these directories if they don’t exist, because the daemon
would need root privileges to create directories in/var/spool.Wedesign
the daemon to do as little as possible while running as root to minimize the
chance of creating a security hole.
[15 – 21] Next, we define the account name under which the printer spooling daemon
will run. On Linux and Solaris, this name islp.OnMac OS X, the name is
_lp.FreeBSD, however,doesn’t define a separate account for the printer
spooling daemon, so we use the account reserved for system daemons.