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