lp.h revision 78300
11590Srgrimes/*
21590Srgrimes * Copyright (c) 1983, 1993
31590Srgrimes *	The Regents of the University of California.  All rights reserved.
41590Srgrimes *
51590Srgrimes * Redistribution and use in source and binary forms, with or without
61590Srgrimes * modification, are permitted provided that the following conditions
71590Srgrimes * are met:
81590Srgrimes * 1. Redistributions of source code must retain the above copyright
91590Srgrimes *    notice, this list of conditions and the following disclaimer.
101590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111590Srgrimes *    notice, this list of conditions and the following disclaimer in the
121590Srgrimes *    documentation and/or other materials provided with the distribution.
131590Srgrimes * 3. All advertising materials mentioning features or use of this software
141590Srgrimes *    must display the following acknowledgement:
151590Srgrimes *	This product includes software developed by the University of
161590Srgrimes *	California, Berkeley and its contributors.
171590Srgrimes * 4. Neither the name of the University nor the names of its contributors
181590Srgrimes *    may be used to endorse or promote products derived from this software
191590Srgrimes *    without specific prior written permission.
201590Srgrimes *
211590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241590Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311590Srgrimes * SUCH DAMAGE.
321590Srgrimes *
331590Srgrimes * 	From: @(#)lp.h	8.2 (Berkeley) 4/28/95
341590Srgrimes * $FreeBSD: head/usr.sbin/lpr/common_source/lp.h 78300 2001-06-15 22:03:07Z gad $
3528564Scharnier */
361590Srgrimes
371590Srgrimes#include <sys/queue.h>
381590Srgrimes#include <time.h>
391590Srgrimes#include <netdb.h>
4096438Smike
411590Srgrimes/*
421590Srgrimes * All this information used to be in global static variables shared
4396438Smike * mysteriously by various parts of the lpr/lpd suite.
4428564Scharnier * This structure attempts to centralize all these declarations in the
451590Srgrimes * hope that they can later be made more dynamic.
4696438Smike */
4796438Smikeenum	lpd_filters { LPF_CIFPLOT, LPF_DVI, LPF_GRAPH, LPF_INPUT,
4896438Smike		      LPF_DITROFF, LPF_OUTPUT, LPF_FORTRAN, LPF_TROFF,
491590Srgrimes		      LPF_RASTER, LPF_COUNT };
501590Srgrimes/* NB: there is a table in common.c giving the mapping from capability names */
511590Srgrimes
521590Srgrimesstruct	printer {
531590Srgrimes	char	*printer;	/* printer name */
541590Srgrimes	int	 remote;	/* true if RM points to a remote host */
551590Srgrimes	int	 rp_matches_local; /* true if rp has same name as us */
5691661Sjmallett	int	 tof;		/* true if we are at top-of-form */
571590Srgrimes	/* ------------------------------------------------------ */
581590Srgrimes	char	*acct_file;	/* AF: accounting file */
5991661Sjmallett	long	 baud_rate;	/* BR: baud rate if lp is a tty */
6091661Sjmallett	char	*filters[LPF_COUNT]; /* CF, DF, GF, IF, NF, OF, RF, TF, VF */
6128564Scharnier	long	 conn_timeout;	/* CT: TCP connection timeout */
62106275Sfanf	long	 daemon_user;	/* DU: daemon user id -- XXX belongs ???? */
63106275Sfanf	char	*form_feed;	/* FF: form feed */
641590Srgrimes	long	 header_last;	/* HL: print header last */
6591661Sjmallett	char	*log_file;	/* LF: log file */
661590Srgrimes	char	*lock_file;	/* LO: lock file */
6728564Scharnier	char	*lp;		/* LP: device name or network address */
681590Srgrimes	long	 max_copies;	/* MC: maximum number of copies allowed */
6928564Scharnier	long	 max_blocks;	/* MX: maximum number of blocks to copy */
701590Srgrimes	long	 price100;	/* PC: price per 100 units of output */
71106280Sfanf	long	 page_length;	/* PL: page length */
72106280Sfanf	long	 page_width;	/* PW: page width */
73106280Sfanf	long	 page_pwidth;	/* PX: page width in pixels */
741590Srgrimes	long	 page_plength;	/* PY: page length in pixels */
75106280Sfanf	char	*restrict_grp;	/* RG: restricted group */
76106280Sfanf	char	*remote_host;	/* RM: remote machine name */
77106280Sfanf	char	*remote_queue;	/* RP: remote printer name */
78106280Sfanf	long	 restricted;	/* RS: restricted to those with local accts */
79106280Sfanf	long	 rw;		/* RW: open LP for reading and writing */
8019078Swosch	long	 short_banner;	/* SB: short banner */
811590Srgrimes	long	 no_copies;	/* SC: suppress multiple copies */
8296386Salfred	char	*spool_dir;	/* SD: spool directory */
831590Srgrimes	long	 no_formfeed;	/* SF: suppress FF on each print job */
8419078Swosch	long	 no_header;	/* SH: suppress header page */
851590Srgrimes	char	*stat_recv;	/* SR: statistics file, receiving jobs */
8689882Smike	char	*stat_send;	/* SS: statistics file, sending jobs */
8719078Swosch	char	*status_file;	/* ST: status file name */
8819078Swosch	char	*trailer;	/* TR: trailer string send when Q empties */
8989882Smike	char	*mode_set;	/* MS: mode set, a la stty */
9089882Smike
9119078Swosch	/* variables used by trstat*() to keep statistics on file transfers */
9219078Swosch#define JOBNUM_SIZE   8
9332780Swosch	char 	 jobnum[JOBNUM_SIZE];
9432780Swosch	long	 jobdfnum;	/* current datafile number within job */
9532780Swosch	struct timespec tr_start, tr_done;
9689882Smike#define TIMESTR_SIZE 40		/* holds result from LPD_TIMESTAMP_PATTERN */
9789882Smike	char	 tr_timestr[TIMESTR_SIZE];
9889882Smike#define DIFFTIME_TS(endTS,startTS) \
9989882Smike		((double)(endTS.tv_sec - startTS.tv_sec) \
10089882Smike		+ (endTS.tv_nsec - startTS.tv_nsec) * 1.0e-9)
10189882Smike};
10289882Smike
10319078Swosch/*
10489882Smike * Lists of user names and job numbers, for the benefit of the structs
10589882Smike * defined below.  We use TAILQs so that requests don't get mysteriously
10619078Swosch * reversed in process.
10719078Swosch */
10832780Swoschstruct	req_user {
10989882Smike	TAILQ_ENTRY(req_user)	ru_link; /* macro glue */
11089882Smike	char	ru_uname[1];	/* name of user */
11132780Swosch};
11232780SwoschTAILQ_HEAD(req_user_head, req_user);
11319078Swosch
11428564Scharnierstruct	req_file {
11519078Swosch	TAILQ_ENTRY(req_file)	rf_link; /* macro glue */
11619078Swosch	char	 rf_type;	/* type (lowercase cf file letter) of file */
11719078Swosch	char	*rf_prettyname;	/* user-visible name of file */
11819078Swosch	char	 rf_fname[1];	/* name of file */
11919078Swosch};
12019078SwoschTAILQ_HEAD(req_file_head, req_file);
1211590Srgrimes
1221590Srgrimesstruct	req_jobid {
123106280Sfanf	TAILQ_ENTRY(req_jobid)	rj_link; /* macro glue */
124106274Sfanf	int	rj_job;		/* job number */
12528564Scharnier};
1261590SrgrimesTAILQ_HEAD(req_jobid_head, req_jobid);
1271590Srgrimes
1281590Srgrimes/*
1291590Srgrimes * Encapsulate all the information relevant to a request in the
130106274Sfanf * lpr/lpd protocol.
1311590Srgrimes */
1321590Srgrimesenum	req_type { REQ_START, REQ_RECVJOB, REQ_LIST, REQ_DELETE };
133106280Sfanf
134106274Sfanfstruct	request {
1351590Srgrimes	enum	 req_type type;	/* what sort of request is this? */
1361590Srgrimes	struct	 printer prtr;	/* which printer is it for? */
1371590Srgrimes	int	 remote;	/* did request arrive over network? */
1381590Srgrimes	char	*logname;	/* login name of requesting user */
1391590Srgrimes	char	*authname;	/* authenticated identity of requesting user */
140106280Sfanf	char	*prettyname;	/* ``pretty'' name of requesting user */
14196438Smike	int	 privileged;	/* was the request from a privileged user? */
1421590Srgrimes	void	*authinfo;	/* authentication information */
143103200Sfanf	int	 authentic;	/* was the request securely authenticated? */
14419078Swosch
145103200Sfanf	/* Information for queries and deletes... */
146103200Sfanf	int	 nusers;	/* length of following list... */
147106280Sfanf	struct	 req_user_head users; /* list of users to query/delete */
148103200Sfanf	int	 njobids;	/* length of following list... */
149103200Sfanf	struct	 req_jobid_head jobids;	/* list of jobids to query/delete */
150103200Sfanf};
151103200Sfanf
152103200Sfanf/*
15319078Swosch * Global definitions for the line printer system.
154103200Sfanf */
155103200Sfanfextern char	line[BUFSIZ];
15619078Swoschextern const char	*progname;	/* program name (lpr, lpq, etc) */
15719078Swosch
158106280Sfanf    /*
159103200Sfanf     * 'local_host' is the name of the machine that lpd (lpr, whatever)
16019078Swosch     * is actually running on.
161106280Sfanf     *
162106280Sfanf     * 'from_host' will point to the 'host' variable when receiving a job
163106280Sfanf     * from a user on the same host, or "somewhere else" when receiving a
164106280Sfanf     * job from a remote host.  If 'from_host != local_host', then 'from_ip'
1651590Srgrimes     * is the character representation of the IP address of from_host (note
166103200Sfanf     * that string could be an IPv6 address).
16792623Sjmallett     *
1681590Srgrimes     * Also note that when 'from_host' is not pointing at 'local_host', the
169103195Sfanf     * string it is pointing at may be as long as NI_MAXHOST (which is very
1701590Srgrimes     * likely to be much longer than MAXHOSTNAMELEN).
171103200Sfanf     */
172106274Sfanfextern char	 local_host[MAXHOSTNAMELEN];
173103200Sfanfextern const char	*from_host;	/* client's machine name */
174103200Sfanfextern const char	*from_ip;	/* client machine's IP address */
175103200Sfanf
176103200Sfanfextern int	requ[];		/* job number of spool entries */
177103200Sfanfextern int	requests;	/* # of spool requests */
178103200Sfanfextern char	*user[];        /* users to process */
179103200Sfanfextern int	users;		/* # of users in user array */
180103200Sfanfextern char	*person;	/* name of person doing lprm */
181103200Sfanfextern u_char	family;		/* address family */
182103200Sfanf
183103200Sfanf/*
184103200Sfanf * Structure used for building a sorted list of control files.
185103200Sfanf */
186103200Sfanfstruct jobqueue {
187103200Sfanf	time_t	job_time;		/* last-mod time of cf-file */
188103200Sfanf	char	job_cfname[MAXNAMLEN+1];	/* control file name */
189103200Sfanf};
190103200Sfanf
191103200Sfanf/* lpr/lpd generates readable timestamps for logfiles, etc.  Have all those
192103200Sfanf * timestamps be in the same format wrt strftime().  This is ISO 8601 format,
193103200Sfanf * with the addition of an easy-readable day-of-the-week field.  Note that
194103200Sfanf * '%T' = '%H:%M:%S', and that '%z' is not available on all platforms.
19519078Swosch */
196106280Sfanf#define LPD_TIMESTAMP_PATTERN    "%Y-%m-%dT%T%z %a"
197106280Sfanf
198106280Sfanf/*
199103200Sfanf * Codes to indicate which statistic records trstat_write should write.
20091661Sjmallett */
201106280Sfanftypedef enum { TR_SENDING, TR_RECVING, TR_PRINTING } tr_sendrecv;
202106280Sfanf
2031590Srgrimes/*
204106280Sfanf * Error codes for our mini printcap library.
205103200Sfanf */
206103200Sfanf#define	PCAPERR_TCLOOP		(-3)
207103200Sfanf#define	PCAPERR_OSERR		(-2)
208103200Sfanf#define	PCAPERR_NOTFOUND	(-1)
209103200Sfanf#define	PCAPERR_SUCCESS		0
210103200Sfanf#define	PCAPERR_TCOPEN		1
211103200Sfanf
212103200Sfanf/*
213103200Sfanf * File modes for the various status files maintained by lpd.
21432780Swosch */
215103200Sfanf#define	LOCK_FILE_MODE	(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)
216106280Sfanf#define	LFM_PRINT_DIS	(S_IXUSR)
217106280Sfanf#define	LFM_QUEUE_DIS	(S_IXGRP)
218106280Sfanf#define	LFM_RESET_QUE	(S_IXOTH)
219106280Sfanf
220106280Sfanf#define	STAT_FILE_MODE	(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)
221106280Sfanf#define	LOG_FILE_MODE	(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)
222106280Sfanf#define	TEMP_FILE_MODE	(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)
223106280Sfanf
224106280Sfanf/*
225106280Sfanf * Command codes used in the protocol.
226106280Sfanf */
227106280Sfanf#define	CMD_CHECK_QUE	'\1'
2281590Srgrimes#define	CMD_TAKE_THIS	'\2'
229111586Sfanf#define	CMD_SHOWQ_SHORT	'\3'
230103200Sfanf#define	CMD_SHOWQ_LONG	'\4'
231103200Sfanf#define	CMD_RMJOB	'\5'
232103200Sfanf
233106280Sfanf#include <sys/cdefs.h>
2341590Srgrimes
235106280Sfanf__BEGIN_DECLS
236106280Sfanfstruct	 dirent;
2371590Srgrimes
238111586Sfanfvoid	 blankfill(int _tocol);
239111586Sfanfchar	*checkremote(struct printer *_pp);
240106275Sfanfint	 chk(char *_file);
241106275Sfanfvoid	 closeallfds(int _start);
242106280Sfanfvoid	 delay(int _millisec);
243106280Sfanfvoid	 displayq(struct printer *_pp, int _format);
244106275Sfanfvoid	 dump(const char *_nfile, const char *_datafile, int _copies);
245106280Sfanfvoid	 fatal(const struct printer *_pp, const char *_msg, ...);
246106275Sfanfint	 firstprinter(struct printer *_pp, int *_error);
247106275Sfanfvoid	 free_printer(struct printer *_pp);
248106275Sfanfvoid	 free_request(struct request *_rp);
249106275Sfanfint	 getline(FILE *_cfp);
250106275Sfanfint	 getport(const struct printer *_pp, const char *_rhost, int _rport);
251106275Sfanfint	 getprintcap(const char *_printer, struct printer *_pp);
252106280Sfanfint	 getq(const struct printer *_pp, struct jobqueue *(*_namelist[]));
253106275Sfanfvoid	 header(void);
254106280Sfanfvoid	 inform(const struct printer *_pp, char *_cf);
255106275Sfanfvoid	 init_printer(struct printer *_pp);
256106275Sfanfvoid	 init_request(struct request *_rp);
257106280Sfanfint	 inlist(char *_uname, char *_cfile);
258106275Sfanfint	 iscf(struct dirent *_d);
259106275Sfanfint	 isowner(char *_owner, char *_file);
260106275Sfanfvoid	 ldump(const char *_nfile, const char *_datafile, int _copies);
261106275Sfanfvoid	 lastprinter(void);
262106275Sfanfint	 lockchk(struct printer *_pp, char *_slockf);
263106275Sfanfchar	*lock_file_name(const struct printer *_pp, char *_buf, size_t _len);
264106275Sfanfvoid	 lpd_gettime(struct timespec *_tsp, char *_strp, int _strsize);
265106280Sfanfint	 nextprinter(struct printer *_pp, int *_error);
266106275Sfanfconst
267106275Sfanfchar	*pcaperr(int _error);
268106275Sfanfvoid	 prank(int _n);
269106280Sfanfvoid	 process(const struct printer *_pp, char *_file);
270106275Sfanfvoid	 rmjob(const char *_printer);
271103200Sfanfvoid	 rmremote(const struct printer *_pp);
272106280Sfanfvoid	 setprintcap(char *_newfile);
273106280Sfanfvoid	 show(const char *_nfile, const char *_datafile, int _copies);
274106280Sfanfint	 startdaemon(const struct printer *_pp);
275103197Sfanfchar	*status_file_name(const struct printer *_pp, char *_buf,
27632780Swosch	    size_t _len);
2771590Srgrimesvoid	 trstat_init(struct printer *_pp, const char *_fname, int _filenum);
2781590Srgrimesvoid	 trstat_write(struct printer *_pp, tr_sendrecv _sendrecv,
279103203Sfanf	    size_t _bytecnt, const char *_userid, const char *_otherhost,
280106280Sfanf	    const char *_orighost);
281106280Sfanfssize_t	 writel(int _strm, ...);
282106280Sfanf__END_DECLS
283106280Sfanf