Home | History | Annotate | Download | only in include
      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
     35 extern "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 
     49 typedef struct SCALED {
     50 	float	val;	/* value of number, scaled according to "sc" */
     51 	char	sc;	/* 'i' inches, 'c' centimeters, ' ' lines/cols */
     52 }			SCALED;
     53 
     54 typedef 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_PRINTING_OK		"ready and printing"
    218 
    219 #define TIMEOUT_FAULT \
    220 "Timed-out trying to open the printer port.\n"
    221 
    222 #define OPEN_FAULT \
    223 "Failed to open the printer port.\n"
    224 
    225 #define PUSH_FAULT \
    226 "Failed to push module(s) onto the printer port stream.\n"
    227 
    228 /*
    229  * When the Spooler detected the hangup, this message is used.
    230  */
    231 #define HANGUP_FAULT \
    232 "The connection to the printer dropped; perhaps the printer went off-line!\n"
    233 
    234 /*
    235  * When lp.cat detected the hangup, this message is used.
    236  */
    237 #define HANGUP_FAULT_LPCAT \
    238 "The connection to the printer dropped; perhaps the printer went off-line.\n"
    239 
    240 #define INTERRUPT_FAULT	\
    241 "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"
    242 
    243 #define PIPE_FAULT \
    244 "The output ``port'', a FIFO, was closed before all output was written.\n"
    245 
    246 #define EXIT_FAULT \
    247 "The interface program returned with a reserved exit code.\n"
    248 
    249 /**
    250  ** Lp-errno #defines, etc.
    251  **/
    252 
    253 #define LP_EBADSDN	1
    254 #define LP_EBADINT	2
    255 #define LP_EBADNAME	3
    256 #define LP_EBADARG	4
    257 #define LP_ETRAILIN	5
    258 #define LP_ENOCMT	6
    259 #define LP_EBADCTYPE	7
    260 #define LP_ENOALP	8
    261 #define LP_ENULLPTR	9
    262 #define LP_EBADHDR	10
    263 #define LP_ETEMPLATE	11
    264 #define LP_EKEYWORD	12
    265 #define LP_EPATTERN	13
    266 #define LP_ERESULT	14
    267 #define LP_EREGEX	15  /* and see extern int regerrno, regexpr(3G) */
    268 #define LP_ENOMEM	99
    269 
    270 extern int		lp_errno;
    271 
    272 /**
    273  ** Misc. Macros
    274  **/
    275 
    276 #define	LP_WS		" "	/* Whitespace (also list separator) */
    277 #define	LP_SEP		","	/* List separator */
    278 #define LP_QUOTES	"'\""
    279 
    280 #define MAIL		"mail"
    281 #define WRITE		"write"
    282 
    283 #define STATUS_BREAK	"=========="
    284 
    285 #define	STREQU(A,B)	( (!(A) || !(B)) ? 0: (strcmp((A), (B)) == 0) )
    286 #define	STRNEQU(A,B,N)	( (!(A) || !(B)) ? 0: (strncmp((A), (B), (N)) == 0) )
    287 #define	CS_STREQU(A,B)	(cs_strcmp((A), (B)) == 0)
    288 #define	CS_STRNEQU(A,B,N) (cs_strncmp((A), (B), (N)) == 0)
    289 #define STRSIZE(X)	(sizeof(X) - 1)
    290 
    291 /*
    292  * Almost STREQU but compares null pointers as equal, too.
    293  */
    294 #define	SAME(A,B)	((A) == (B) || (A) && (B) && STREQU((A), (B)))
    295 
    296 #define	PRINTF		(void)printf
    297 #define SPRINTF		(void)sprintf
    298 #define FPRINTF		(void)fprintf
    299 
    300 #define	NB(X)		(X? X : "")
    301 
    302 #define PERROR		strerror(errno)
    303 
    304 /*
    305  * Largest number we'll ever expect to get from doing %ld in printf,
    306  * as a string and number. ULONG_MAX from limits.h gives us the number,
    307  * but I can't figure out how to get that into a string.
    308  */
    309 #define BIGGEST_NUMBER		ULONG_MAX
    310 #define BIGGEST_NUMBER_S	"4294967295"
    311 
    312 /*
    313  * Largest request ID (numerical part), as string and number.
    314  * See comment above.
    315  */
    316 #define BIGGEST_REQID		999999
    317 #define BIGGEST_REQID_S		"999999"
    318 
    319 /*
    320  * Maximum number of files queued per request, as string and number.
    321  * See earlier comment above.
    322  */
    323 #define MOST_FILES	999999
    324 #define MOST_FILES_S	"999999"
    325 
    326 /**
    327  ** Alert macros:
    328  **/
    329 
    330 /*
    331  * Type of alert to be S_QUIET'd
    332  */
    333 #define	QA_FORM		1
    334 #define	QA_PRINTER	2
    335 #define	QA_PRINTWHEEL	3
    336 
    337 /**
    338  ** File modes:
    339  ** (The "NO" prefix is relative to ``others''.)
    340  **/
    341 
    342 #define	MODE_READ	(mode_t)0664
    343 #define MODE_NOREAD	(mode_t)0660
    344 #define MODE_EXEC	(mode_t)0775
    345 #define MODE_NOEXEC	(mode_t)0770
    346 #define MODE_DIR	(mode_t)0775
    347 #define MODE_NODIR	(mode_t)0770
    348 
    349 extern int	printlist_qsep;
    350 
    351 extern char	Lp_Spooldir[],
    352 		Lp_Admins[],
    353 		Lp_Bin[],
    354 		Lp_FIFO[],
    355 		Lp_Logs[],
    356 		Lp_ReqLog[],
    357 		Lp_Model[],
    358 		Lp_Requests[],
    359 		Lp_Secure[],
    360 		Lp_Schedlock[],
    361 		Lp_Slow_Filter[],
    362 		Lp_System[],
    363 		Lp_Temp[],
    364 		Lp_Tmp[],
    365 		Lp_Users[],
    366 		Lp_A[],
    367 		Lp_A_Classes[],
    368 		Lp_A_Forms[],
    369 		Lp_A_Interfaces[],
    370 		Lp_A_Logs[],
    371 		Lp_A_Printers[],
    372 		Lp_A_PrintWheels[],
    373 		Lp_A_Filters[],
    374 		Lp_A_Systems[],
    375 		Lp_Default[],
    376 		Lp_A_Faults[];
    377 
    378 /*
    379  * File access:
    380  */
    381 
    382 extern int	open_locked(char *, char *, mode_t);
    383 extern char	*fdgets(char *, int, int);
    384 extern int	fdprintf(int, char *, ...);
    385 extern int	fdputs(char *, int);
    386 extern int	fdputc(char, int);
    387 
    388 extern int	is_printer_uri(char *);
    389 
    390 FILE		*open_lpfile ( char * , char * , mode_t );
    391 int		close_lpfile ( FILE * );
    392 int		chown_lppath ( char * path );
    393 int		mkdir_lpdir ( char * path , int mode );
    394 int		rmfile ( char * path );
    395 int		dumpstring ( char * path , char * str );
    396 
    397 char *		loadstring ( char * path );
    398 char *		loadline ( char * path );
    399 char *		sop_up_rest (int, char * endsop );
    400 
    401 /*
    402  * List manipulation routines:
    403  */
    404 
    405 #define emptylist(LP)	(!(LP) || !(LP)[0])
    406 
    407 int		addlist ( char *** , char * );
    408 int		addstring ( char ** , char * );
    409 int		appendlist ( char *** , char * );
    410 int		dellist ( char *** , char * );
    411 int		joinlist ( char *** , char ** );
    412 int		lenlist ( char ** );
    413 int		printlist ( FILE * , char ** );
    414 int		fdprintlist(int , char ** );
    415 int		searchlist ( char *, char ** );
    416 int		searchlist_with_terminfo ( char * , char ** );
    417 
    418 char **		duplist ( char ** );
    419 char **		getlist ( char * , char * , char * );
    420 char **		dashos ( char * );
    421 char **		wherelist ( char * , char ** );
    422 
    423 char *		sprintlist ( char ** );
    424 char *		search_cslist ( char * , char ** );
    425 
    426 void		freelist ( char ** );
    427 void		printlist_setup ( char * , char * , char * , char * );
    428 void		printlist_unsetup ( void );
    429 
    430 /*
    431  * Scaled decimal number routines:
    432  */
    433 
    434 #define getsdn(S)	_getsdn(S, (char **)0, 0)
    435 #define getcpi(S)	_getsdn(S, (char **)0, 1)
    436 
    437 #define N_COMPRESSED	9999
    438 
    439 void		printsdn ( FILE * , SCALED );
    440 void		fdprintsdn ( int , SCALED );
    441 void		printsdn_setup ( char * , char * , char * );
    442 void		printsdn_unsetup ( void );
    443 
    444 SCALED		_getsdn ( char * , char ** , int );
    445 
    446 /*
    447  * File name routines:
    448  */
    449 
    450 char *		makepath ( char * , ... );
    451 char *		getspooldir ( void );
    452 char *		getrequestfile ( char * );
    453 char *		getprinterfile ( char * , char * );
    454 char *		getsystemfile ( char * , char * );
    455 char *		getclassfile ( char * );
    456 char *		getfilterfile ( char * );
    457 char *		getformfile ( char * , char * );
    458 
    459 /*
    460  * Additional string manipulation routines:
    461  */
    462 
    463 int		cs_strcmp ( char * , char * );
    464 int		cs_strncmp ( char * , char * , int );
    465 
    466 /*
    467  * Syntax checking routines:
    468  */
    469 
    470 int		syn_name ( char * );
    471 int		syn_text ( char * );
    472 int		syn_comment ( char * );
    473 int		syn_machine_name ( char * );
    474 int		syn_option ( char * );
    475 
    476 /*
    477  * Alert management routines:
    478  */
    479 
    480 int		putalert ( char * , char * , FALERT * );
    481 int		delalert ( char * , char * );
    482 
    483 FALERT *	getalert ( char * , char * );
    484 
    485 void		printalert ( FILE * , FALERT * , int );
    486 
    487 /*
    488  * Terminfo Database Inquiry Tool
    489  */
    490 
    491 int		tidbit ( char * , char * , ... );
    492 void		untidbit ( char * );
    493 
    494 /*
    495  * Auto-restarting and other system calls:
    496  * The two versions are here to reduce the chance of colliding
    497  * with similar names in standard libraries (e.g. dial(3C) uses
    498  * Read/Write).
    499  */
    500 
    501 #define Access	_Access
    502 #define Chdir	_Chdir
    503 #define Chmod	_Chmod
    504 #define Chown	_Chown
    505 #define Close	_Close
    506 #define Creat	_Creat
    507 #define Fcntl	_Fcntl
    508 #define Fstat	_Fstat
    509 #define Link	_Link
    510 #define Lstat	_Lstat
    511 #define Mknod	_Mknod
    512 #define Open	_Open
    513 #define Read	_Read
    514 #define Readlink _Readlink
    515 #define Rename	_Rename
    516 #define Stat	_Stat
    517 #define Symlink	_Symlink
    518 #define Unlink	_Unlink
    519 #define Wait	_Wait
    520 #define Write	_Write
    521 
    522 #define Malloc(size)		_Malloc(size, __FILE__, __LINE__)
    523 #define Realloc(ptr,size)	_Realloc(ptr, size, __FILE__, __LINE__)
    524 #define Calloc(nelem,elsize)	_Calloc(nelem, elsize, __FILE__, __LINE__)
    525 #define Strdup(s)		_Strdup(s, __FILE__, __LINE__)
    526 #define Free(ptr)		_Free(ptr, __FILE__, __LINE__)
    527 
    528 int		_Access ( char * , int );
    529 int		_Chdir ( char * );
    530 int		_Chmod ( char * , int );
    531 int		_Chown ( char * , int , int );
    532 int		_Close ( int );
    533 int		_Creat ( char * , int );
    534 int		_Fcntl ( int , int , ... );
    535 int		_Fstat ( int , struct stat * );
    536 int		_Link ( char * , char * );
    537 int		_Lstat ( char * , struct stat * );
    538 int		_Mknod ( char * , int , int );
    539 int		_Mkpipe ( char * , int , int );
    540 int		_Open ( char * , int , ... /* mode_t */ );
    541 int		_Read ( int , char * , unsigned int );
    542 int		_Readlink ( char * , char * , unsigned int );
    543 int		_Rename ( char * , char * );
    544 int		_Symlink ( char * , char * );
    545 int		_Stat ( char * , struct stat * );
    546 int		_Unlink ( char * );
    547 int		_Wait ( int * );
    548 int		_Write ( int , char * , unsigned int );
    549 
    550 void *		_Malloc ( size_t , const char * , int );
    551 void *		_Realloc ( void * , size_t , const char * , int );
    552 void *		_Calloc ( size_t , size_t , const char * , int );
    553 char *		_Strdup ( const char * , const char * , int );
    554 void		_Free ( void * , const char * , int );
    555 
    556 /*
    557  * Misc. routines:
    558  */
    559 
    560 int		isterminfo ( char * );
    561 int		isprinter ( char * );
    562 int		isrequest ( char * );
    563 int		isnumber ( char * );
    564 
    565 char *		getname ( void );
    566 char *		makestr ( char * , ... );
    567 char *		strip ( char * );
    568 
    569 void		sendmail ( char * , char * );
    570 
    571 void		(*lp_alloc_fail_handler)( void );
    572 
    573 /*
    574  * Originally part of liblpfs.a and fs.h, now no longer needed
    575  * since the code doesn't have to work on pre-SVR4.0.
    576  */
    577 #define	Opendir		opendir
    578 #define	Telldir		telldir
    579 #define	Seekdir		seekdir
    580 #define	Rewinddir(dirp)	Seekdir(dirp, 0L)
    581 #define	Closedir	closedir
    582 #define	Readdir		readdir
    583 #define	Mkdir		mkdir
    584 #define	Rmdir		rmdir
    585 
    586 #define	next_dir(base, ptr)	next_x(base, ptr, S_IFDIR)
    587 #define	next_file(base, ptr)	next_x(base, ptr, S_IFREG)
    588 
    589 extern int chownmod(char *path, uid_t owner, gid_t group, mode_t mode);
    590 
    591 
    592 char *		next_x  ( char * , long * , unsigned int );
    593 
    594 /*
    595  * Stuff needed for Trusted Extensions
    596  */
    597 
    598 extern	char	*get_labeled_zonename(char *);
    599 extern int	get_peer_label(int fd, char **slabel);
    600 
    601 
    602 #ifdef __cplusplus
    603 }
    604 #endif
    605 
    606 #endif	/* _LP_LP_H */
    607