lp.h revision 1676:37f4a3e2bd99
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
27/*	  All Rights Reserved  	*/
28
29#ifndef _LP_LP_H
30#define	_LP_LP_H
31
32#pragma ident	"%Z%%M%	%I%	%E% SMI"
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38#include <errno.h>
39#include <fcntl.h>
40#include <sys/types.h>
41#include <sys/stat.h>
42#include <stdio.h>
43#include <dirent.h>
44
45/**
46 ** Types:
47 **/
48
49typedef struct SCALED {
50	float	val;	/* value of number, scaled according to "sc" */
51	char	sc;	/* 'i' inches, 'c' centimeters, ' ' lines/cols */
52}			SCALED;
53
54typedef struct FALERT {
55	char *	shcmd;	/* shell command used to perform the alert */
56	int	Q;	/* # requests queued to activate alert */
57	int	W;	/* alert is sent every "W" minutes */
58} FALERT;
59
60
61#define	LP_USE_PAPI_ATTR 1	/* use PAPI attributes for printing */
62				/* TODO: is this best place for this ? */
63
64/**
65 ** Places:
66 **/
67
68/*
69 * These functions no longer exist.  The defines take care
70 * of recompiling code that expects these and the null functions
71 * in getpaths.c take care of relinking objects that expect these.
72 */
73#define	getpaths()
74#define	getadminpaths(x)
75
76#define LPDIR		"/usr/lib/lp"
77#define ETCDIR		"/etc/lp"
78#define SPOOLDIR	"/var/spool/lp"
79#define LOGDIR		"/var/lp/logs"
80
81#define	TERMINFO	"/usr/share/lib/terminfo"
82
83#define	LPUSER		"lp"
84#define ROOTUSER	"root"
85
86#define BANG_S		"!"
87#define BANG_C		'!'
88
89#define	LOCAL_LPUSER	BANG_S LPUSER
90#define LOCAL_ROOTUSER	BANG_S ROOTUSER
91#define ALL_BANG_ALL	NAME_ALL BANG_S NAME_ALL
92
93/* #define	ADMINSDIR	"admins"  */
94/* # define CLASSESDIR	"classes" */
95/* # define FORMSDIR	"forms" */
96/* # define INTERFACESDIR	"interfaces" */
97/* # define PRINTERSDIR	"printers" */
98/* # define PRINTWHEELSDIR	"pwheels" */
99/* #define BINDIR		"bin" */
100/* #define LOGSDIR		"logs" */
101/* #define MODELSDIR	"model" */
102/* #define NETWORKDIR	"network" */
103#define FIFOSDIR	"fifos"
104/* # define PRIVFIFODIR	"private" */
105/* # define PUBFIFODIR	"public" */
106/* #define REQUESTSDIR	"requests" */
107/* #define SYSTEMDIR	"system" */
108/* #define TEMPDIR		"temp" */
109/* #define TMPDIR		"tmp" */
110
111/* #define SCHEDLOCK	"SCHEDLOCK" */
112/* #define FIFO		"FIFO" */
113
114#define	FILTERTABLE	"filter.table"
115#define	FILTERTABLE_I	"filter.table.i"
116
117/* #define DESCRIBEFILE	"describe" */
118/* #define ALIGNFILE	"align_ptrn" */
119#define COMMENTFILE	"comment"
120#define ALLOWFILE	"allow"
121#define DENYFILE	"deny"
122#define ALERTSHFILE	"alert.sh"
123#define ALERTVARSFILE	"alert.vars"
124#define ALERTPROTOFILE	"alert.proto"
125#define CONFIGFILE	"configuration"
126#define FACCESSPREFIX	"forms."
127#define PACCESSPREFIX	"paper."
128#define UACCESSPREFIX	"users."
129#define FALLOWFILE	FACCESSPREFIX ALLOWFILE
130#define FDENYFILE	FACCESSPREFIX DENYFILE
131#define UALLOWFILE	UACCESSPREFIX ALLOWFILE
132#define UDENYFILE	UACCESSPREFIX DENYFILE
133/* #define DEFAULTFILE	"default" */
134#define STATUSFILE	"status"
135/* #define USERSFILE	"users" */
136/* #define NAMEFILE	"name" */
137/* #define XFERFILE	"transfer" */
138/* #define EXECFILE	"execute" */
139#define PSTATUSFILE	"pstatus"
140#define CSTATUSFILE	"cstatus"
141/* #define REQLOGFILE	"requests" */
142
143#define STANDARD	"standard"
144/* #define SLOWFILTER	"slow.filter" */
145#define FAULTMESSAGEFILE "faultMessage"
146#define FORMMESSAGEFILE "formMessage"
147
148#define LPNET		"/usr/lib/lp/lpNet"
149
150#ifdef LP_USE_PAPI_ATTR
151#define	STANDARD_FOOMATIC	"standard_foomatic"
152	/*
153	 * The default model interface script to use if a printer is configured
154	 * with a PPD (PostScript Printer Definition) file.
155	 */
156#define	LP_PAPIATTRNAME "attributes"
157	/*
158	 * Job attributes filename extension,
159	 * eg. /var/spool/lp/temp/123-attributes
160	 */
161#endif
162
163/**
164 ** Names and phrases:
165 **/
166
167/*
168 * If you change these from macros to defined (char *) strings,
169 * be aware that in several places the lengths of the strings
170 * are computed using "sizeof()", not "strlen()"!
171 */
172#define	NAME_ALL	"all"
173#define	NAME_ANY	"any"
174#define NAME_NONE	"none"
175#define	NAME_TERMINFO	"terminfo"
176#define	NAME_SIMPLE	"simple"
177#define NAME_HOLD	"hold"
178#define	NAME_RESUME	"resume"
179#define NAME_IMMEDIATE	"immediate"
180#define NAME_CONTINUE	"continue"
181#define NAME_BEGINNING	"beginning"
182#define NAME_WAIT	"wait"
183#define NAME_MAIL	"mail"
184#define	NAME_WRITE	"write"
185#define NAME_QUIET	"quiet"
186#define NAME_LIST	"list"
187#define NAME_ON		"on"
188#define NAME_OFF	"off"
189#define NAME_OPTIONAL	"optional"
190#define NAME_ALWAYS	"Always"
191#define NAME_UNKNOWN	"unknown"
192#define NAME_REJECTING	"rejecting"
193#define NAME_ACCEPTING	"accepting"
194#define NAME_DISABLED	"disabled"
195#define NAME_ENABLED	"enabled"
196#define NAME_DIRECT	"direct"
197#define NAME_PICA	"pica"
198#define NAME_ELITE	"elite"
199#define NAME_COMPRESSED	"compressed"
200#define NAME_ALLOW	"allow"
201#define NAME_DENY	"deny"
202#define NAME_ONCE	"once"
203#define NAME_DEFAULT	"default"
204#define NAME_KEEP	"keep"
205
206/**
207 ** Common messages:
208 **/
209
210#define CUZ_NEW_PRINTER		"new printer"
211#define CUZ_NEW_DEST		"new destination"
212#define CUZ_STOPPED		"stopped with printer fault"
213#define CUZ_FAULT		"printer fault"
214#define CUZ_LOGIN_PRINTER	"disabled by Spooler: login terminal"
215#define CUZ_MOUNTING		"mounting a form"
216#define CUZ_NOFORK		"can't fork"
217#define CUZ_NOREMOTE		"remote system no longer defined"
218#define CUZ_PRINTING_OK		"ready and printing"
219
220#define TIMEOUT_FAULT \
221"Timed-out trying to open the printer port.\n"
222
223#define OPEN_FAULT \
224"Failed to open the printer port.\n"
225
226#define PUSH_FAULT \
227"Failed to push module(s) onto the printer port stream.\n"
228
229/*
230 * When the Spooler detected the hangup, this message is used.
231 */
232#define HANGUP_FAULT \
233"The connection to the printer dropped; perhaps the printer went off-line!\n"
234
235/*
236 * When lp.cat detected the hangup, this message is used.
237 */
238#define HANGUP_FAULT_LPCAT \
239"The connection to the printer dropped; perhaps the printer went off-line.\n"
240
241#define INTERRUPT_FAULT	\
242"Received an interrupt from the printer. The reason is unknown,\nalthough a common cause is that the printer's buffer capacity\nwas exceeded. Using XON/XOFF flow control, adding carriage-return\ndelays, or lowering the baud rate may fix the problem.\nSee stty(1) and lpadmin(1M) man-pages for help in doing this.\n"
243
244#define PIPE_FAULT \
245"The output ``port'', a FIFO, was closed before all output was written.\n"
246
247#define EXIT_FAULT \
248"The interface program returned with a reserved exit code.\n"
249
250/**
251 ** Lp-errno #defines, etc.
252 **/
253
254#define LP_EBADSDN	1
255#define LP_EBADINT	2
256#define LP_EBADNAME	3
257#define LP_EBADARG	4
258#define LP_ETRAILIN	5
259#define LP_ENOCMT	6
260#define LP_EBADCTYPE	7
261#define LP_ENOALP	8
262#define LP_ENULLPTR	9
263#define LP_EBADHDR	10
264#define LP_ETEMPLATE	11
265#define LP_EKEYWORD	12
266#define LP_EPATTERN	13
267#define LP_ERESULT	14
268#define LP_EREGEX	15  /* and see extern int regerrno, regexpr(3G) */
269#define LP_ENOMEM	99
270
271extern int		lp_errno;
272
273/**
274 ** Misc. Macros
275 **/
276
277#define	LP_WS		" "	/* Whitespace (also list separator) */
278#define	LP_SEP		","	/* List separator */
279#define LP_QUOTES	"'\""
280
281#define MAIL		"mail"
282#define WRITE		"write"
283
284#define STATUS_BREAK	"=========="
285
286#define	STREQU(A,B)	( (!(A) || !(B)) ? 0: (strcmp((A), (B)) == 0) )
287#define	STRNEQU(A,B,N)	( (!(A) || !(B)) ? 0: (strncmp((A), (B), (N)) == 0) )
288#define	CS_STREQU(A,B)	(cs_strcmp((A), (B)) == 0)
289#define	CS_STRNEQU(A,B,N) (cs_strncmp((A), (B), (N)) == 0)
290#define STRSIZE(X)	(sizeof(X) - 1)
291
292/*
293 * Almost STREQU but compares null pointers as equal, too.
294 */
295#define	SAME(A,B)	((A) == (B) || (A) && (B) && STREQU((A), (B)))
296
297#define	PRINTF		(void)printf
298#define SPRINTF		(void)sprintf
299#define FPRINTF		(void)fprintf
300
301#define	NB(X)		(X? X : "")
302
303#define PERROR		strerror(errno)
304
305/*
306 * Largest number we'll ever expect to get from doing %ld in printf,
307 * as a string and number. ULONG_MAX from limits.h gives us the number,
308 * but I can't figure out how to get that into a string.
309 */
310#define BIGGEST_NUMBER		ULONG_MAX
311#define BIGGEST_NUMBER_S	"4294967295"
312
313/*
314 * Largest request ID (numerical part), as string and number.
315 * See comment above.
316 */
317#define BIGGEST_REQID		999999
318#define BIGGEST_REQID_S		"999999"
319
320/*
321 * Maximum number of files queued per request, as string and number.
322 * See earlier comment above.
323 */
324#define MOST_FILES	999999
325#define MOST_FILES_S	"999999"
326
327/**
328 ** Alert macros:
329 **/
330
331/*
332 * Type of alert to be S_QUIET'd
333 */
334#define	QA_FORM		1
335#define	QA_PRINTER	2
336#define	QA_PRINTWHEEL	3
337
338/**
339 ** File modes:
340 ** (The "NO" prefix is relative to ``others''.)
341 **/
342
343#define	MODE_READ	(mode_t)0664
344#define MODE_NOREAD	(mode_t)0660
345#define MODE_EXEC	(mode_t)0775
346#define MODE_NOEXEC	(mode_t)0770
347#define MODE_DIR	(mode_t)0775
348#define MODE_NODIR	(mode_t)0770
349
350extern int	printlist_qsep;
351
352extern char	Lp_Spooldir[],
353		Lp_Admins[],
354		Lp_Bin[],
355		Lp_FIFO[],
356		Lp_Logs[],
357		Lp_ReqLog[],
358		Lp_Model[],
359		Lp_Private_FIFOs[],
360		Lp_Public_FIFOs[],
361		Lp_Requests[],
362		Lp_Secure[],
363		Lp_Schedlock[],
364		Lp_Slow_Filter[],
365		Lp_System[],
366		Lp_Temp[],
367		Lp_Tmp[],
368		Lp_NetTmp[],
369		Lp_NetData[],
370		Lp_Users[],
371		Lp_A[],
372		Lp_A_Classes[],
373		Lp_A_Forms[],
374		Lp_A_Interfaces[],
375		Lp_A_Logs[],
376		Lp_A_Printers[],
377		Lp_A_PrintWheels[],
378		Lp_A_Filters[],
379		Lp_A_Systems[],
380		Lp_Default[],
381		Lp_A_Faults[];
382
383extern int	Lp_NTBase;
384
385/*
386 * File access:
387 */
388
389extern int	open_locked(char *, char *, mode_t);
390extern char	*fdgets(char *, int, int);
391extern int	fdprintf(int, char *, ...);
392extern int	fdputs(char *, int);
393extern int	fdputc(char, int);
394
395extern int	is_printer_uri(char *);
396
397FILE		*open_lpfile ( char * , char * , mode_t );
398int		close_lpfile ( FILE * );
399int		chown_lppath ( char * path );
400int		mkdir_lpdir ( char * path , int mode );
401int		rmfile ( char * path );
402int		dumpstring ( char * path , char * str );
403
404char *		loadstring ( char * path );
405char *		loadline ( char * path );
406char *		sop_up_rest (int, char * endsop );
407
408/*
409 * List manipulation routines:
410 */
411
412#define emptylist(LP)	(!(LP) || !(LP)[0])
413
414int		addlist ( char *** , char * );
415int		addstring ( char ** , char * );
416int		appendlist ( char *** , char * );
417int		dellist ( char *** , char * );
418int		joinlist ( char *** , char ** );
419int		lenlist ( char ** );
420int		printlist ( FILE * , char ** );
421int		fdprintlist(int , char ** );
422int		searchlist ( char *, char ** );
423int		searchlist_with_terminfo ( char * , char ** );
424
425char **		duplist ( char ** );
426char **		getlist ( char * , char * , char * );
427char **		dashos ( char * );
428char **		wherelist ( char * , char ** );
429
430char *		sprintlist ( char ** );
431char *		search_cslist ( char * , char ** );
432
433void		freelist ( char ** );
434void		printlist_setup ( char * , char * , char * , char * );
435void		printlist_unsetup ( void );
436
437/*
438 * Scaled decimal number routines:
439 */
440
441#define getsdn(S)	_getsdn(S, (char **)0, 0)
442#define getcpi(S)	_getsdn(S, (char **)0, 1)
443
444#define N_COMPRESSED	9999
445
446void		printsdn ( FILE * , SCALED );
447void		fdprintsdn ( int , SCALED );
448void		printsdn_setup ( char * , char * , char * );
449void		printsdn_unsetup ( void );
450
451SCALED		_getsdn ( char * , char ** , int );
452
453/*
454 * File name routines:
455 */
456
457char *		makepath ( char * , ... );
458char *		getspooldir ( void );
459char *		getrequestfile ( char * );
460char *		getprinterfile ( char * , char * );
461char *		getsystemfile ( char * , char * );
462char *		getclassfile ( char * );
463char *		getfilterfile ( char * );
464char *		getformfile ( char * , char * );
465
466/*
467 * Additional string manipulation routines:
468 */
469
470int		cs_strcmp ( char * , char * );
471int		cs_strncmp ( char * , char * , int );
472
473/*
474 * Syntax checking routines:
475 */
476
477int		syn_name ( char * );
478int		syn_text ( char * );
479int		syn_comment ( char * );
480int		syn_machine_name ( char * );
481int		syn_option ( char * );
482
483/*
484 * Alert management routines:
485 */
486
487int		putalert ( char * , char * , FALERT * );
488int		delalert ( char * , char * );
489
490FALERT *	getalert ( char * , char * );
491
492void		printalert ( FILE * , FALERT * , int );
493
494/*
495 * Terminfo Database Inquiry Tool
496 */
497
498int		tidbit ( char * , char * , ... );
499void		untidbit ( char * );
500
501/*
502 * Auto-restarting and other system calls:
503 * The two versions are here to reduce the chance of colliding
504 * with similar names in standard libraries (e.g. dial(3C) uses
505 * Read/Write).
506 */
507
508#define Access	_Access
509#define Chdir	_Chdir
510#define Chmod	_Chmod
511#define Chown	_Chown
512#define Close	_Close
513#define Creat	_Creat
514#define Fcntl	_Fcntl
515#define Fstat	_Fstat
516#define Link	_Link
517#define Lstat	_Lstat
518#define Mknod	_Mknod
519#define Open	_Open
520#define Read	_Read
521#define Readlink _Readlink
522#define Rename	_Rename
523#define Stat	_Stat
524#define Symlink	_Symlink
525#define Unlink	_Unlink
526#define Wait	_Wait
527#define Write	_Write
528
529#define Malloc(size)		_Malloc(size, __FILE__, __LINE__)
530#define Realloc(ptr,size)	_Realloc(ptr, size, __FILE__, __LINE__)
531#define Calloc(nelem,elsize)	_Calloc(nelem, elsize, __FILE__, __LINE__)
532#define Strdup(s)		_Strdup(s, __FILE__, __LINE__)
533#define Free(ptr)		_Free(ptr, __FILE__, __LINE__)
534
535int		_Access ( char * , int );
536int		_Chdir ( char * );
537int		_Chmod ( char * , int );
538int		_Chown ( char * , int , int );
539int		_Close ( int );
540int		_Creat ( char * , int );
541int		_Fcntl ( int , int , ... );
542int		_Fstat ( int , struct stat * );
543int		_Link ( char * , char * );
544int		_Lstat ( char * , struct stat * );
545int		_Mknod ( char * , int , int );
546int		_Mkpipe ( char * , int , int );
547int		_Open ( char * , int , ... /* mode_t */ );
548int		_Read ( int , char * , unsigned int );
549int		_Readlink ( char * , char * , unsigned int );
550int		_Rename ( char * , char * );
551int		_Symlink ( char * , char * );
552int		_Stat ( char * , struct stat * );
553int		_Unlink ( char * );
554int		_Wait ( int * );
555int		_Write ( int , char * , unsigned int );
556
557void *		_Malloc ( size_t , const char * , int );
558void *		_Realloc ( void * , size_t , const char * , int );
559void *		_Calloc ( size_t , size_t , const char * , int );
560char *		_Strdup ( const char * , const char * , int );
561void		_Free ( void * , const char * , int );
562
563/*
564 * Misc. routines:
565 */
566
567int		isterminfo ( char * );
568int		isprinter ( char * );
569int		isrequest ( char * );
570int		isnumber ( char * );
571
572char *		getname ( void );
573char *		makestr ( char * , ... );
574char *		strip ( char * );
575
576void		sendmail ( char * , char * );
577
578void		(*lp_alloc_fail_handler)( void );
579
580/*
581 * Originally part of liblpfs.a and fs.h, now no longer needed
582 * since the code doesn't have to work on pre-SVR4.0.
583 */
584#define	Opendir		opendir
585#define	Telldir		telldir
586#define	Seekdir		seekdir
587#define	Rewinddir(dirp)	Seekdir(dirp, 0L)
588#define	Closedir	closedir
589#define	Readdir		readdir
590#define	Mkdir		mkdir
591#define	Rmdir		rmdir
592
593#define	next_dir(base, ptr)	next_x(base, ptr, S_IFDIR)
594#define	next_file(base, ptr)	next_x(base, ptr, S_IFREG)
595
596extern int chownmod(char *path, uid_t owner, gid_t group, mode_t mode);
597
598
599char *		next_x  ( char * , long * , unsigned int );
600
601/*
602 * Stuff needed for Trusted Extensions
603 */
604
605extern	char	*get_labeled_zonename(char *);
606extern int	get_peer_label(int fd, char **slabel);
607
608
609#ifdef __cplusplus
610}
611#endif
612
613#endif	/* _LP_LP_H */
614