xref: /illumos-gate/usr/src/cmd/lp/include/lp.h (revision dd72704bd9e794056c558153663c739e2012d721)
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 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <errno.h>
37 #include <fcntl.h>
38 #include <sys/types.h>
39 #include <sys/stat.h>
40 #include <stdio.h>
41 #include <dirent.h>
42 
43 /*
44  * Types:
45  */
46 
47 typedef struct SCALED {
48 	float	val;	/* value of number, scaled according to "sc" */
49 	char	sc;	/* 'i' inches, 'c' centimeters, ' ' lines/cols */
50 }			SCALED;
51 
52 typedef struct FALERT {
53 	char	*shcmd;	/* shell command used to perform the alert */
54 	int	Q;	/* # requests queued to activate alert */
55 	int	W;	/* alert is sent every "W" minutes */
56 } FALERT;
57 
58 
59 #define	LP_USE_PAPI_ATTR 1	/* use PAPI attributes for printing */
60 				/* TODO: is this best place for this ? */
61 
62 /*
63  * Places:
64  */
65 
66 /*
67  * These functions no longer exist.  The defines take care
68  * of recompiling code that expects these and the null functions
69  * in getpaths.c take care of relinking objects that expect these.
70  */
71 #define	getpaths()
72 #define	getadminpaths(x)
73 
74 #define	LPDIR		"/usr/lib/lp"
75 #define	ETCDIR		"/etc/lp"
76 #define	SPOOLDIR	"/var/spool/lp"
77 #define	LOGDIR		"/var/lp/logs"
78 
79 #define	TERMINFO	"/usr/share/lib/terminfo"
80 
81 #define	LPUSER		"lp"
82 #define	ROOTUSER	"root"
83 
84 #define	BANG_S		"!"
85 #define	BANG_C		'!'
86 
87 #define	LOCAL_LPUSER	BANG_S LPUSER
88 #define	LOCAL_ROOTUSER	BANG_S ROOTUSER
89 #define	ALL_BANG_ALL	NAME_ALL BANG_S NAME_ALL
90 
91 /* #define	ADMINSDIR	"admins"  */
92 /* # define CLASSESDIR	"classes" */
93 /* # define FORMSDIR	"forms" */
94 /* # define INTERFACESDIR	"interfaces" */
95 /* # define PRINTERSDIR	"printers" */
96 /* # define PRINTWHEELSDIR	"pwheels" */
97 /* #define BINDIR		"bin" */
98 /* #define LOGSDIR		"logs" */
99 /* #define MODELSDIR	"model" */
100 /* #define NETWORKDIR	"network" */
101 #define	FIFOSDIR	"fifos"
102 /* # define PRIVFIFODIR	"private" */
103 /* # define PUBFIFODIR	"public" */
104 /* #define REQUESTSDIR	"requests" */
105 /* #define SYSTEMDIR	"system" */
106 /* #define TEMPDIR		"temp" */
107 /* #define TMPDIR		"tmp" */
108 
109 /* #define SCHEDLOCK	"SCHEDLOCK" */
110 /* #define FIFO		"FIFO" */
111 
112 #define	FILTERTABLE	"filter.table"
113 #define	FILTERTABLE_I	"filter.table.i"
114 
115 /* #define DESCRIBEFILE	"describe" */
116 /* #define ALIGNFILE	"align_ptrn" */
117 #define	COMMENTFILE	"comment"
118 #define	ALLOWFILE	"allow"
119 #define	DENYFILE	"deny"
120 #define	ALERTSHFILE	"alert.sh"
121 #define	ALERTVARSFILE	"alert.vars"
122 #define	ALERTPROTOFILE	"alert.proto"
123 #define	CONFIGFILE	"configuration"
124 #define	FACCESSPREFIX	"forms."
125 #define	PACCESSPREFIX	"paper."
126 #define	UACCESSPREFIX	"users."
127 #define	FALLOWFILE	FACCESSPREFIX ALLOWFILE
128 #define	FDENYFILE	FACCESSPREFIX DENYFILE
129 #define	UALLOWFILE	UACCESSPREFIX ALLOWFILE
130 #define	UDENYFILE	UACCESSPREFIX DENYFILE
131 /* #define DEFAULTFILE	"default" */
132 #define	STATUSFILE	"status"
133 /* #define USERSFILE	"users" */
134 /* #define NAMEFILE	"name" */
135 /* #define XFERFILE	"transfer" */
136 /* #define EXECFILE	"execute" */
137 #define	PSTATUSFILE	"pstatus"
138 #define	CSTATUSFILE	"cstatus"
139 /* #define REQLOGFILE	"requests" */
140 
141 #define	STANDARD	"standard"
142 /* #define SLOWFILTER	"slow.filter" */
143 #define	FAULTMESSAGEFILE "faultMessage"
144 #define	FORMMESSAGEFILE "formMessage"
145 
146 #define	LPNET		"/usr/lib/lp/lpNet"
147 
148 #ifdef LP_USE_PAPI_ATTR
149 #define	STANDARD_FOOMATIC	"standard_foomatic"
150 	/*
151 	 * The default model interface script to use if a printer is configured
152 	 * with a PPD (PostScript Printer Definition) file.
153 	 */
154 #define	LP_PAPIATTRNAME "attributes"
155 	/*
156 	 * Job attributes filename extension,
157 	 * eg. /var/spool/lp/temp/123-attributes
158 	 */
159 #endif
160 
161 /*
162  * Names and phrases:
163  */
164 
165 /*
166  * If you change these from macros to defined (char *) strings,
167  * be aware that in several places the lengths of the strings
168  * are computed using "sizeof()", not "strlen()"!
169  */
170 #define	NAME_ALL	"all"
171 #define	NAME_ANY	"any"
172 #define	NAME_NONE	"none"
173 #define	NAME_TERMINFO	"terminfo"
174 #define	NAME_SIMPLE	"simple"
175 #define	NAME_HOLD	"hold"
176 #define	NAME_RESUME	"resume"
177 #define	NAME_IMMEDIATE	"immediate"
178 #define	NAME_CONTINUE	"continue"
179 #define	NAME_BEGINNING	"beginning"
180 #define	NAME_WAIT	"wait"
181 #define	NAME_MAIL	"mail"
182 #define	NAME_WRITE	"write"
183 #define	NAME_QUIET	"quiet"
184 #define	NAME_LIST	"list"
185 #define	NAME_ON		"on"
186 #define	NAME_OFF	"off"
187 #define	NAME_OPTIONAL	"optional"
188 #define	NAME_ALWAYS	"Always"
189 #define	NAME_UNKNOWN	"unknown"
190 #define	NAME_REJECTING	"rejecting"
191 #define	NAME_ACCEPTING	"accepting"
192 #define	NAME_DISABLED	"disabled"
193 #define	NAME_ENABLED	"enabled"
194 #define	NAME_DIRECT	"direct"
195 #define	NAME_PICA	"pica"
196 #define	NAME_ELITE	"elite"
197 #define	NAME_COMPRESSED	"compressed"
198 #define	NAME_ALLOW	"allow"
199 #define	NAME_DENY	"deny"
200 #define	NAME_ONCE	"once"
201 #define	NAME_DEFAULT	"default"
202 #define	NAME_KEEP	"keep"
203 
204 /*
205  * Common messages:
206  */
207 
208 #define	CUZ_NEW_PRINTER		"new printer"
209 #define	CUZ_NEW_DEST		"new destination"
210 #define	CUZ_STOPPED		"stopped with printer fault"
211 #define	CUZ_FAULT		"printer fault"
212 #define	CUZ_LOGIN_PRINTER	"disabled by Spooler: login terminal"
213 #define	CUZ_MOUNTING		"mounting a form"
214 #define	CUZ_NOFORK		"can't fork"
215 #define	CUZ_PRINTING_OK		"ready and printing"
216 
217 #define	TIMEOUT_FAULT \
218 "Timed-out trying to open the printer port.\n"
219 
220 #define	OPEN_FAULT \
221 "Failed to open the printer port.\n"
222 
223 #define	PUSH_FAULT \
224 "Failed to push module(s) onto the printer port stream.\n"
225 
226 /*
227  * When the Spooler detected the hangup, this message is used.
228  */
229 #define	HANGUP_FAULT \
230 "The connection to the printer dropped; perhaps the printer went off-line!\n"
231 
232 /*
233  * When lp.cat detected the hangup, this message is used.
234  */
235 #define	HANGUP_FAULT_LPCAT \
236 "The connection to the printer dropped; perhaps the printer went off-line.\n"
237 
238 #define	INTERRUPT_FAULT	\
239 "Received an interrupt from the printer. The reason is unknown,\n\
240 although a common cause is that the printer's buffer capacity\n\
241 was exceeded. Using XON/XOFF flow control, adding carriage-return\n\
242 delays, or lowering the baud rate may fix the problem.\n\
243 See stty(1) and lpadmin(8) 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(3GEN) */
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_Requests[],
361 		Lp_Secure[],
362 		Lp_Schedlock[],
363 		Lp_Slow_Filter[],
364 		Lp_System[],
365 		Lp_Temp[],
366 		Lp_Tmp[],
367 		Lp_Users[],
368 		Lp_A[],
369 		Lp_A_Classes[],
370 		Lp_A_Forms[],
371 		Lp_A_Interfaces[],
372 		Lp_A_Logs[],
373 		Lp_A_Printers[],
374 		Lp_A_PrintWheels[],
375 		Lp_A_Filters[],
376 		Lp_A_Systems[],
377 		Lp_Default[],
378 		Lp_A_Faults[];
379 
380 /*
381  * File access:
382  */
383 
384 extern int	open_locked(char *, char *, mode_t);
385 extern char	*fdgets(char *, int, int);
386 extern int	fdprintf(int, char *, ...);
387 extern int	fdputs(char *, int);
388 extern int	fdputc(char, int);
389 
390 extern int	is_printer_uri(char *);
391 
392 FILE		*open_lpfile(char *, char *, mode_t);
393 int		close_lpfile(FILE *);
394 int		chown_lppath(char *);
395 int		mkdir_lpdir(char *, int);
396 int		rmfile(char *);
397 int		dumpstring(char *, char *);
398 
399 char		*loadstring(char *);
400 char		*loadline(char *);
401 char		*sop_up_rest(int, char *);
402 
403 /*
404  * List manipulation routines:
405  */
406 
407 #define	emptylist(LP)	(!(LP) || !(LP)[0])
408 
409 int		addlist(char ***, char *);
410 int		addstring(char **, char *);
411 int		appendlist(char ***, char *);
412 int		dellist(char ***, char *);
413 int		joinlist(char ***, char **);
414 int		lenlist(char **);
415 int		printlist(FILE *, char **);
416 int		fdprintlist(int, char **);
417 int		searchlist(char *, char **);
418 int		searchlist_with_terminfo(char *, char **);
419 
420 char		**duplist(char **);
421 char		**getlist(char *, char *, char *);
422 char		**dashos(char *);
423 char		**wherelist(char *, char **);
424 
425 char		*sprintlist(char **);
426 char		*search_cslist(char *, char **);
427 
428 void		freelist(char **);
429 void		printlist_setup(char *, char *, char *, char *);
430 void		printlist_unsetup(void);
431 
432 /*
433  * Scaled decimal number routines:
434  */
435 
436 #define	getsdn(S)	_getsdn(S, (char **)0, 0)
437 #define	getcpi(S)	_getsdn(S, (char **)0, 1)
438 
439 #define	N_COMPRESSED	9999
440 
441 void		printsdn(FILE *, SCALED);
442 void		fdprintsdn(int, SCALED);
443 void		printsdn_setup(char *, char *, char *);
444 void		printsdn_unsetup(void);
445 
446 SCALED		_getsdn(char *, char **, int);
447 
448 /*
449  * File name routines:
450  */
451 
452 char		*makepath(char *, ...);
453 char		*getspooldir(void);
454 char		*getrequestfile(char *);
455 char		*getprinterfile(char *, char *);
456 char		*getsystemfile(char *, char *);
457 char		*getclassfile(char *);
458 char		*getfilterfile(char *);
459 char		*getformfile(char *, char *);
460 
461 /*
462  * Additional string manipulation routines:
463  */
464 
465 int		cs_strcmp(char *, char *);
466 int		cs_strncmp(char *, char *, int);
467 
468 /*
469  * Syntax checking routines:
470  */
471 
472 int		syn_name(char *);
473 int		syn_text(char *);
474 int		syn_comment(char *);
475 int		syn_machine_name(char *);
476 int		syn_option(char *);
477 
478 /*
479  * Alert management routines:
480  */
481 
482 int		putalert(char *, char *, FALERT *);
483 int		delalert(char *, char *);
484 
485 FALERT		*getalert(char *, char *);
486 
487 void		printalert(FILE *, FALERT *, int);
488 
489 /*
490  * Terminfo Database Inquiry Tool
491  */
492 
493 int		tidbit(char *, char *, ...);
494 void		untidbit(char *);
495 
496 /*
497  * Auto-restarting and other system calls:
498  * The two versions are here to reduce the chance of colliding
499  * with similar names in standard libraries (e.g. dial(3C) uses
500  * Read/Write).
501  */
502 
503 #define	Access	_Access
504 #define	Chdir	_Chdir
505 #define	Chmod	_Chmod
506 #define	Chown	_Chown
507 #define	Close	_Close
508 #define	Creat	_Creat
509 #define	Fcntl	_Fcntl
510 #define	Fstat	_Fstat
511 #define	Link	_Link
512 #define	Lstat	_Lstat
513 #define	Mknod	_Mknod
514 #define	Open	_Open
515 #define	Read	_Read
516 #define	Readlink _Readlink
517 #define	Rename	_Rename
518 #define	Stat	_Stat
519 #define	Symlink	_Symlink
520 #define	Unlink	_Unlink
521 #define	Wait	_Wait
522 #define	Write	_Write
523 
524 #define	Malloc(size)		_Malloc(size, __FILE__, __LINE__)
525 #define	Realloc(ptr, size)	_Realloc(ptr, size, __FILE__, __LINE__)
526 #define	Calloc(nelem, elsize)	_Calloc(nelem, elsize, __FILE__, __LINE__)
527 #define	Strdup(s)		_Strdup(s, __FILE__, __LINE__)
528 #define	Free(ptr)		_Free(ptr, __FILE__, __LINE__)
529 
530 int		_Access(char *, int);
531 int		_Chdir(char *);
532 int		_Chmod(char *, int);
533 int		_Chown(char *, int, int);
534 int		_Close(int);
535 int		_Creat(char *, int);
536 int		_Fcntl(int, int, ...);
537 int		_Fstat(int, struct stat *);
538 int		_Link(char *, char *);
539 int		_Lstat(char *, struct stat *);
540 int		_Mknod(char *, int, int);
541 int		_Mkpipe(char *, int, int);
542 int		_Open(char *, int, ... /* mode_t */);
543 int		_Read(int, char *, unsigned int);
544 int		_Readlink(char *, char *, unsigned int);
545 int		_Rename(char *, char *);
546 int		_Symlink(char *, char *);
547 int		_Stat(char *, struct stat *);
548 int		_Unlink(char *);
549 int		_Wait(int *);
550 int		_Write(int, char *, unsigned int);
551 
552 void		*_Malloc(size_t, const char *, int);
553 void		*_Realloc(void *, size_t, const char *, int);
554 void		*_Calloc(size_t, size_t, const char *, int);
555 char		*_Strdup(const char *, const char *, int);
556 void		_Free(void *, const char *, int);
557 
558 /*
559  * Misc. routines:
560  */
561 
562 int		isterminfo(char *);
563 int		isprinter(char *);
564 int		isrequest(char *);
565 int		isnumber(char *);
566 
567 char		*getname(void);
568 char		*makestr(char *, ...);
569 char		*strip(char *);
570 
571 void		sendmail(char *, char *);
572 
573 extern void	(*lp_alloc_fail_handler)(void);
574 
575 /*
576  * Originally part of liblpfs.a and fs.h, now no longer needed
577  * since the code doesn't have to work on pre-SVR4.0.
578  */
579 #define	Opendir		opendir
580 #define	Telldir		telldir
581 #define	Seekdir		seekdir
582 #define	Rewinddir(dirp)	Seekdir(dirp, 0L)
583 #define	Closedir	closedir
584 #define	Readdir		readdir
585 #define	Mkdir		mkdir
586 #define	Rmdir		rmdir
587 
588 #define	next_dir(base, ptr)	next_x(base, ptr, S_IFDIR)
589 #define	next_file(base, ptr)	next_x(base, ptr, S_IFREG)
590 
591 extern int chownmod(char *, uid_t, gid_t, mode_t);
592 
593 
594 char		*next_x(char *, long *, unsigned int);
595 
596 /*
597  * Stuff needed for Trusted Extensions
598  */
599 
600 extern	char	*get_labeled_zonename(char *);
601 extern int	get_peer_label(int, char **);
602 
603 
604 #ifdef __cplusplus
605 }
606 #endif
607 
608 #endif	/* _LP_LP_H */
609