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_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 271 extern 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 350 extern int printlist_qsep; 351 352 extern 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_Users[], 369 Lp_A[], 370 Lp_A_Classes[], 371 Lp_A_Forms[], 372 Lp_A_Interfaces[], 373 Lp_A_Logs[], 374 Lp_A_Printers[], 375 Lp_A_PrintWheels[], 376 Lp_A_Filters[], 377 Lp_A_Systems[], 378 Lp_Default[], 379 Lp_A_Faults[]; 380 381 /* 382 * File access: 383 */ 384 385 extern int open_locked(char *, char *, mode_t); 386 extern char *fdgets(char *, int, int); 387 extern int fdprintf(int, char *, ...); 388 extern int fdputs(char *, int); 389 extern int fdputc(char, int); 390 391 extern int is_printer_uri(char *); 392 393 FILE *open_lpfile ( char * , char * , mode_t ); 394 int close_lpfile ( FILE * ); 395 int chown_lppath ( char * path ); 396 int mkdir_lpdir ( char * path , int mode ); 397 int rmfile ( char * path ); 398 int dumpstring ( char * path , char * str ); 399 400 char * loadstring ( char * path ); 401 char * loadline ( char * path ); 402 char * sop_up_rest (int, char * endsop ); 403 404 /* 405 * List manipulation routines: 406 */ 407 408 #define emptylist(LP) (!(LP) || !(LP)[0]) 409 410 int addlist ( char *** , char * ); 411 int addstring ( char ** , char * ); 412 int appendlist ( char *** , char * ); 413 int dellist ( char *** , char * ); 414 int joinlist ( char *** , char ** ); 415 int lenlist ( char ** ); 416 int printlist ( FILE * , char ** ); 417 int fdprintlist(int , char ** ); 418 int searchlist ( char *, char ** ); 419 int searchlist_with_terminfo ( char * , char ** ); 420 421 char ** duplist ( char ** ); 422 char ** getlist ( char * , char * , char * ); 423 char ** dashos ( char * ); 424 char ** wherelist ( char * , char ** ); 425 426 char * sprintlist ( char ** ); 427 char * search_cslist ( char * , char ** ); 428 429 void freelist ( char ** ); 430 void printlist_setup ( char * , char * , char * , char * ); 431 void printlist_unsetup ( void ); 432 433 /* 434 * Scaled decimal number routines: 435 */ 436 437 #define getsdn(S) _getsdn(S, (char **)0, 0) 438 #define getcpi(S) _getsdn(S, (char **)0, 1) 439 440 #define N_COMPRESSED 9999 441 442 void printsdn ( FILE * , SCALED ); 443 void fdprintsdn ( int , SCALED ); 444 void printsdn_setup ( char * , char * , char * ); 445 void printsdn_unsetup ( void ); 446 447 SCALED _getsdn ( char * , char ** , int ); 448 449 /* 450 * File name routines: 451 */ 452 453 char * makepath ( char * , ... ); 454 char * getspooldir ( void ); 455 char * getrequestfile ( char * ); 456 char * getprinterfile ( char * , char * ); 457 char * getsystemfile ( char * , char * ); 458 char * getclassfile ( char * ); 459 char * getfilterfile ( char * ); 460 char * getformfile ( char * , char * ); 461 462 /* 463 * Additional string manipulation routines: 464 */ 465 466 int cs_strcmp ( char * , char * ); 467 int cs_strncmp ( char * , char * , int ); 468 469 /* 470 * Syntax checking routines: 471 */ 472 473 int syn_name ( char * ); 474 int syn_text ( char * ); 475 int syn_comment ( char * ); 476 int syn_machine_name ( char * ); 477 int syn_option ( char * ); 478 479 /* 480 * Alert management routines: 481 */ 482 483 int putalert ( char * , char * , FALERT * ); 484 int delalert ( char * , char * ); 485 486 FALERT * getalert ( char * , char * ); 487 488 void printalert ( FILE * , FALERT * , int ); 489 490 /* 491 * Terminfo Database Inquiry Tool 492 */ 493 494 int tidbit ( char * , char * , ... ); 495 void untidbit ( char * ); 496 497 /* 498 * Auto-restarting and other system calls: 499 * The two versions are here to reduce the chance of colliding 500 * with similar names in standard libraries (e.g. dial(3C) uses 501 * Read/Write). 502 */ 503 504 #define Access _Access 505 #define Chdir _Chdir 506 #define Chmod _Chmod 507 #define Chown _Chown 508 #define Close _Close 509 #define Creat _Creat 510 #define Fcntl _Fcntl 511 #define Fstat _Fstat 512 #define Link _Link 513 #define Lstat _Lstat 514 #define Mknod _Mknod 515 #define Open _Open 516 #define Read _Read 517 #define Readlink _Readlink 518 #define Rename _Rename 519 #define Stat _Stat 520 #define Symlink _Symlink 521 #define Unlink _Unlink 522 #define Wait _Wait 523 #define Write _Write 524 525 #define Malloc(size) _Malloc(size, __FILE__, __LINE__) 526 #define Realloc(ptr,size) _Realloc(ptr, size, __FILE__, __LINE__) 527 #define Calloc(nelem,elsize) _Calloc(nelem, elsize, __FILE__, __LINE__) 528 #define Strdup(s) _Strdup(s, __FILE__, __LINE__) 529 #define Free(ptr) _Free(ptr, __FILE__, __LINE__) 530 531 int _Access ( char * , int ); 532 int _Chdir ( char * ); 533 int _Chmod ( char * , int ); 534 int _Chown ( char * , int , int ); 535 int _Close ( int ); 536 int _Creat ( char * , int ); 537 int _Fcntl ( int , int , ... ); 538 int _Fstat ( int , struct stat * ); 539 int _Link ( char * , char * ); 540 int _Lstat ( char * , struct stat * ); 541 int _Mknod ( char * , int , int ); 542 int _Mkpipe ( char * , int , int ); 543 int _Open ( char * , int , ... /* mode_t */ ); 544 int _Read ( int , char * , unsigned int ); 545 int _Readlink ( char * , char * , unsigned int ); 546 int _Rename ( char * , char * ); 547 int _Symlink ( char * , char * ); 548 int _Stat ( char * , struct stat * ); 549 int _Unlink ( char * ); 550 int _Wait ( int * ); 551 int _Write ( int , char * , unsigned int ); 552 553 void * _Malloc ( size_t , const char * , int ); 554 void * _Realloc ( void * , size_t , const char * , int ); 555 void * _Calloc ( size_t , size_t , const char * , int ); 556 char * _Strdup ( const char * , const char * , int ); 557 void _Free ( void * , const char * , int ); 558 559 /* 560 * Misc. routines: 561 */ 562 563 int isterminfo ( char * ); 564 int isprinter ( char * ); 565 int isrequest ( char * ); 566 int isnumber ( char * ); 567 568 char * getname ( void ); 569 char * makestr ( char * , ... ); 570 char * strip ( char * ); 571 572 void sendmail ( char * , char * ); 573 574 void (*lp_alloc_fail_handler)( void ); 575 576 /* 577 * Originally part of liblpfs.a and fs.h, now no longer needed 578 * since the code doesn't have to work on pre-SVR4.0. 579 */ 580 #define Opendir opendir 581 #define Telldir telldir 582 #define Seekdir seekdir 583 #define Rewinddir(dirp) Seekdir(dirp, 0L) 584 #define Closedir closedir 585 #define Readdir readdir 586 #define Mkdir mkdir 587 #define Rmdir rmdir 588 589 #define next_dir(base, ptr) next_x(base, ptr, S_IFDIR) 590 #define next_file(base, ptr) next_x(base, ptr, S_IFREG) 591 592 extern int chownmod(char *path, uid_t owner, gid_t group, mode_t mode); 593 594 595 char * next_x ( char * , long * , unsigned int ); 596 597 /* 598 * Stuff needed for Trusted Extensions 599 */ 600 601 extern char *get_labeled_zonename(char *); 602 extern int get_peer_label(int fd, char **slabel); 603 604 605 #ifdef __cplusplus 606 } 607 #endif 608 609 #endif /* _LP_LP_H */ 610