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