17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 237c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* 277c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 287c478bd9Sstevel@tonic-gate * Use is subject to license terms. 297c478bd9Sstevel@tonic-gate */ 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */ 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #include "sys/types.h" 367c478bd9Sstevel@tonic-gate #include "sys/stat.h" 377c478bd9Sstevel@tonic-gate #include "stdio.h" 387c478bd9Sstevel@tonic-gate #include "string.h" 397c478bd9Sstevel@tonic-gate #include "errno.h" 407c478bd9Sstevel@tonic-gate #include "stdlib.h" 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate #include "lp.h" 437c478bd9Sstevel@tonic-gate #include "printers.h" 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate #include <unistd.h> 467c478bd9Sstevel@tonic-gate #include <sys/wait.h> 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate #define SHELL "/bin/sh" 497c478bd9Sstevel@tonic-gate #define PPDZIP ".gz" 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate extern struct { 527c478bd9Sstevel@tonic-gate char *v; 537c478bd9Sstevel@tonic-gate short len, 547c478bd9Sstevel@tonic-gate okremote; 557c478bd9Sstevel@tonic-gate } prtrheadings[]; 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate #if defined(__STDC__) 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate static void print_sdn (int, char *, SCALED); 607c478bd9Sstevel@tonic-gate static void print_l (int, char *, char **); 617c478bd9Sstevel@tonic-gate static void print_str (int, char *, char *); 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate #ifdef LP_USE_PAPI_ATTR 647c478bd9Sstevel@tonic-gate static int addPrintersPPD(char *name, PRINTER *prbufp); 657c478bd9Sstevel@tonic-gate static int copyPPDFile(char *ppd, char *printersPPD); 667c478bd9Sstevel@tonic-gate static int unzipPPDFile(char *ppd, char *printersPPD); 677c478bd9Sstevel@tonic-gate #endif 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate #else 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate static void print_sdn(), 727c478bd9Sstevel@tonic-gate print_l(), 737c478bd9Sstevel@tonic-gate print_str(); 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate #ifdef LP_USE_PAPI_ATTR 767c478bd9Sstevel@tonic-gate static int addPrintersPPD(); 777c478bd9Sstevel@tonic-gate static int copyPPDFile(); 787c478bd9Sstevel@tonic-gate static int unzipPPDFile(); 797c478bd9Sstevel@tonic-gate #endif 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate #endif 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate unsigned long ignprinter = 0; 847c478bd9Sstevel@tonic-gate int ppdopt = 0; 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate /** 877c478bd9Sstevel@tonic-gate ** putprinter() - WRITE PRINTER STRUCTURE TO DISK FILES 887c478bd9Sstevel@tonic-gate **/ 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate int 917c478bd9Sstevel@tonic-gate putprinter(char *name, PRINTER *prbufp) 927c478bd9Sstevel@tonic-gate { 937c478bd9Sstevel@tonic-gate register char * path; 947c478bd9Sstevel@tonic-gate register char * stty; 957c478bd9Sstevel@tonic-gate register char * speed; 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate int fdin, fdout; 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate int fld; 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate char buf[BUFSIZ]; 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate struct stat statbuf1, 1047c478bd9Sstevel@tonic-gate statbuf2; 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate badprinter = 0; 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate if (!name || !*name) { 1107c478bd9Sstevel@tonic-gate errno = EINVAL; 1117c478bd9Sstevel@tonic-gate return (-1); 1127c478bd9Sstevel@tonic-gate } 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate if (STREQU(NAME_ALL, name)) { 1157c478bd9Sstevel@tonic-gate errno = EINVAL; 1167c478bd9Sstevel@tonic-gate return (-1); 1177c478bd9Sstevel@tonic-gate } 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate /* 1207c478bd9Sstevel@tonic-gate * First go through the structure and see if we have 1217c478bd9Sstevel@tonic-gate * anything strange. 1227c478bd9Sstevel@tonic-gate */ 1237c478bd9Sstevel@tonic-gate if (!okprinter(name, prbufp, 1)) { 1247c478bd9Sstevel@tonic-gate errno = EINVAL; 1257c478bd9Sstevel@tonic-gate return (-1); 1267c478bd9Sstevel@tonic-gate } 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate if (!Lp_A_Printers || !Lp_A_Interfaces) { 1297c478bd9Sstevel@tonic-gate getadminpaths (LPUSER); 1307c478bd9Sstevel@tonic-gate if (!Lp_A_Printers || !Lp_A_Interfaces) 1317c478bd9Sstevel@tonic-gate return (0); 1327c478bd9Sstevel@tonic-gate } 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate /* 1357c478bd9Sstevel@tonic-gate * Create the parent directory for this printer 1367c478bd9Sstevel@tonic-gate * if it doesn't yet exist. 1377c478bd9Sstevel@tonic-gate */ 1387c478bd9Sstevel@tonic-gate if (!(path = getprinterfile(name, (char *)0))) 1397c478bd9Sstevel@tonic-gate return (-1); 1407c478bd9Sstevel@tonic-gate if (Stat(path, &statbuf1) == 0) { 141*4bc0a2efScasper if (!S_ISDIR(statbuf1.st_mode)) { 1427c478bd9Sstevel@tonic-gate Free (path); 1437c478bd9Sstevel@tonic-gate errno = ENOTDIR; 1447c478bd9Sstevel@tonic-gate return (-1); 1457c478bd9Sstevel@tonic-gate } 1467c478bd9Sstevel@tonic-gate } else if (errno != ENOENT || mkdir_lpdir(path, MODE_DIR) == -1) { 1477c478bd9Sstevel@tonic-gate Free (path); 1487c478bd9Sstevel@tonic-gate return (-1); 1497c478bd9Sstevel@tonic-gate } 1507c478bd9Sstevel@tonic-gate Free (path); 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate /* 1537c478bd9Sstevel@tonic-gate * Create the copy of the interface program, unless 1547c478bd9Sstevel@tonic-gate * that would be silly or not desired. 1557c478bd9Sstevel@tonic-gate * Conversely, make sure the interface program doesn't 1567c478bd9Sstevel@tonic-gate * exist for a remote printer. 1577c478bd9Sstevel@tonic-gate */ 1587c478bd9Sstevel@tonic-gate if (prbufp->remote) { 1597c478bd9Sstevel@tonic-gate if (!(path = makepath(Lp_A_Interfaces, name, (char *)0))) 1607c478bd9Sstevel@tonic-gate return (-1); 1617c478bd9Sstevel@tonic-gate (void)rmfile (path); 1627c478bd9Sstevel@tonic-gate Free (path); 1637c478bd9Sstevel@tonic-gate } 1647c478bd9Sstevel@tonic-gate if (prbufp->interface && (ignprinter & BAD_INTERFACE) == 0) { 1657c478bd9Sstevel@tonic-gate if (Stat(prbufp->interface, &statbuf1) == -1) 1667c478bd9Sstevel@tonic-gate return (-1); 1677c478bd9Sstevel@tonic-gate if (!(path = makepath(Lp_A_Interfaces, name, (char *)0))) 1687c478bd9Sstevel@tonic-gate return (-1); 1697c478bd9Sstevel@tonic-gate if ( 1707c478bd9Sstevel@tonic-gate Stat(path, &statbuf2) == -1 1717c478bd9Sstevel@tonic-gate || statbuf1.st_dev != statbuf2.st_dev 1727c478bd9Sstevel@tonic-gate || statbuf1.st_ino != statbuf2.st_ino 1737c478bd9Sstevel@tonic-gate ) { 1747c478bd9Sstevel@tonic-gate register int n; 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate if ((fdin = open_locked(prbufp->interface, "r", 0)) < 0) { 1777c478bd9Sstevel@tonic-gate Free (path); 1787c478bd9Sstevel@tonic-gate return (-1); 1797c478bd9Sstevel@tonic-gate } 1807c478bd9Sstevel@tonic-gate if ((fdout = open_locked(path, "w", MODE_EXEC)) < 0) { 1817c478bd9Sstevel@tonic-gate Free (path); 1827c478bd9Sstevel@tonic-gate close(fdin); 1837c478bd9Sstevel@tonic-gate return (-1); 1847c478bd9Sstevel@tonic-gate } 1857c478bd9Sstevel@tonic-gate while ((n = read(fdin, buf, BUFSIZ)) > 0) 1867c478bd9Sstevel@tonic-gate write (fdout, buf, n); 1877c478bd9Sstevel@tonic-gate close(fdout); 1887c478bd9Sstevel@tonic-gate close(fdin); 1897c478bd9Sstevel@tonic-gate } 1907c478bd9Sstevel@tonic-gate Free (path); 1917c478bd9Sstevel@tonic-gate } 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate #ifdef LP_USE_PAPI_ATTR 1947c478bd9Sstevel@tonic-gate /* 1957c478bd9Sstevel@tonic-gate * Handle PPD (Postscript Printer Definition) file for printer 1967c478bd9Sstevel@tonic-gate * if this printer has been configured with one 1977c478bd9Sstevel@tonic-gate */ 1987c478bd9Sstevel@tonic-gate if ((prbufp->ppd != NULL) && (ppdopt)) 1997c478bd9Sstevel@tonic-gate { 2007c478bd9Sstevel@tonic-gate if (addPrintersPPD(name, prbufp) != 0) 2017c478bd9Sstevel@tonic-gate { 2027c478bd9Sstevel@tonic-gate /* failed to added the printers PPD file */ 2037c478bd9Sstevel@tonic-gate return (-1); 2047c478bd9Sstevel@tonic-gate } 2057c478bd9Sstevel@tonic-gate } 2067c478bd9Sstevel@tonic-gate #endif 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate /* 2097c478bd9Sstevel@tonic-gate * If this printer is dialed up, remove any baud rates 2107c478bd9Sstevel@tonic-gate * from the stty option list and move the last one to 2117c478bd9Sstevel@tonic-gate * the ".speed" member if the ".speed" member isn't already 2127c478bd9Sstevel@tonic-gate * set. Conversely, if this printer is directly connected, 2137c478bd9Sstevel@tonic-gate * move any value from the ".speed" member to the stty list. 2147c478bd9Sstevel@tonic-gate */ 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate stty = (prbufp->stty? Strdup(prbufp->stty) : 0); 2177c478bd9Sstevel@tonic-gate if (prbufp->speed) 2187c478bd9Sstevel@tonic-gate speed = Strdup(prbufp->speed); 2197c478bd9Sstevel@tonic-gate else 2207c478bd9Sstevel@tonic-gate speed = 0; 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate if (prbufp->dial_info && stty) { 2237c478bd9Sstevel@tonic-gate register char *newstty, 2247c478bd9Sstevel@tonic-gate *p, 2257c478bd9Sstevel@tonic-gate *q; 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate register int len; 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate if (!(q = newstty = Malloc(strlen(stty) + 1))) { 2307c478bd9Sstevel@tonic-gate Free (stty); 2317c478bd9Sstevel@tonic-gate errno = ENOMEM; 2327c478bd9Sstevel@tonic-gate return (-1); 2337c478bd9Sstevel@tonic-gate } 2347c478bd9Sstevel@tonic-gate newstty[0] = 0; /* start with empty copy */ 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate for ( 2377c478bd9Sstevel@tonic-gate p = strtok(stty, " "); 2387c478bd9Sstevel@tonic-gate p; 2397c478bd9Sstevel@tonic-gate p = strtok((char *)0, " ") 2407c478bd9Sstevel@tonic-gate ) { 2417c478bd9Sstevel@tonic-gate len = strlen(p); 2427c478bd9Sstevel@tonic-gate if (strspn(p, "0123456789") == len) { 2437c478bd9Sstevel@tonic-gate /* 2447c478bd9Sstevel@tonic-gate * If "prbufp->speed" isn't set, then 2457c478bd9Sstevel@tonic-gate * use the speed we just found. Don't 2467c478bd9Sstevel@tonic-gate * check "speed", because if more than 2477c478bd9Sstevel@tonic-gate * one speed was given in the list, we 2487c478bd9Sstevel@tonic-gate * want the last one. 2497c478bd9Sstevel@tonic-gate */ 2507c478bd9Sstevel@tonic-gate if (!prbufp->speed) { 2517c478bd9Sstevel@tonic-gate if (speed) 2527c478bd9Sstevel@tonic-gate Free (speed); 2537c478bd9Sstevel@tonic-gate speed = Strdup(p); 2547c478bd9Sstevel@tonic-gate } 2557c478bd9Sstevel@tonic-gate 2567c478bd9Sstevel@tonic-gate } else { 2577c478bd9Sstevel@tonic-gate /* 2587c478bd9Sstevel@tonic-gate * Not a speed, so copy it to the 2597c478bd9Sstevel@tonic-gate * new stty string. 2607c478bd9Sstevel@tonic-gate */ 2617c478bd9Sstevel@tonic-gate if (q != newstty) 2627c478bd9Sstevel@tonic-gate *q++ = ' '; 2637c478bd9Sstevel@tonic-gate strcpy (q, p); 2647c478bd9Sstevel@tonic-gate q += len; 2657c478bd9Sstevel@tonic-gate } 2667c478bd9Sstevel@tonic-gate } 2677c478bd9Sstevel@tonic-gate 2687c478bd9Sstevel@tonic-gate Free (stty); 2697c478bd9Sstevel@tonic-gate stty = newstty; 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate } else if (!prbufp->dial_info && speed) { 2727c478bd9Sstevel@tonic-gate register char *newstty; 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate newstty = Malloc(strlen(stty) + 1 + strlen(speed) + 1); 2757c478bd9Sstevel@tonic-gate if (!newstty) { 2767c478bd9Sstevel@tonic-gate if (stty) 2777c478bd9Sstevel@tonic-gate Free (stty); 2787c478bd9Sstevel@tonic-gate errno = ENOMEM; 2797c478bd9Sstevel@tonic-gate return (-1); 2807c478bd9Sstevel@tonic-gate } 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate if (stty) { 2837c478bd9Sstevel@tonic-gate strcpy (newstty, stty); 2847c478bd9Sstevel@tonic-gate strcat (newstty, " "); 2857c478bd9Sstevel@tonic-gate strcat (newstty, speed); 2867c478bd9Sstevel@tonic-gate Free (stty); 2877c478bd9Sstevel@tonic-gate } else 2887c478bd9Sstevel@tonic-gate strcpy (newstty, speed); 2897c478bd9Sstevel@tonic-gate Free (speed); 2907c478bd9Sstevel@tonic-gate speed = 0; 2917c478bd9Sstevel@tonic-gate 2927c478bd9Sstevel@tonic-gate stty = newstty; 2937c478bd9Sstevel@tonic-gate 2947c478bd9Sstevel@tonic-gate } 2957c478bd9Sstevel@tonic-gate 2967c478bd9Sstevel@tonic-gate /* 2977c478bd9Sstevel@tonic-gate * Open the configuration file and write out the printer 2987c478bd9Sstevel@tonic-gate * configuration. 2997c478bd9Sstevel@tonic-gate */ 3007c478bd9Sstevel@tonic-gate 3017c478bd9Sstevel@tonic-gate if (!(path = getprinterfile(name, CONFIGFILE))) { 3027c478bd9Sstevel@tonic-gate if (stty) 3037c478bd9Sstevel@tonic-gate Free (stty); 3047c478bd9Sstevel@tonic-gate if (speed) 3057c478bd9Sstevel@tonic-gate Free (speed); 3067c478bd9Sstevel@tonic-gate return (-1); 3077c478bd9Sstevel@tonic-gate } 3087c478bd9Sstevel@tonic-gate if ((fdout = open_locked(path, "w", MODE_READ)) < 0) { 3097c478bd9Sstevel@tonic-gate Free (path); 3107c478bd9Sstevel@tonic-gate if (stty) 3117c478bd9Sstevel@tonic-gate Free (stty); 3127c478bd9Sstevel@tonic-gate if (speed) 3137c478bd9Sstevel@tonic-gate Free (speed); 3147c478bd9Sstevel@tonic-gate return (-1); 3157c478bd9Sstevel@tonic-gate } 3167c478bd9Sstevel@tonic-gate Free (path); 3177c478bd9Sstevel@tonic-gate 3187c478bd9Sstevel@tonic-gate errno = 0; 3197c478bd9Sstevel@tonic-gate for (fld = 0; fld < PR_MAX; fld++) { 3207c478bd9Sstevel@tonic-gate if (prbufp->remote && !prtrheadings[fld].okremote) 3217c478bd9Sstevel@tonic-gate continue; 3227c478bd9Sstevel@tonic-gate 3237c478bd9Sstevel@tonic-gate switch (fld) { 3247c478bd9Sstevel@tonic-gate 3257c478bd9Sstevel@tonic-gate #define HEAD prtrheadings[fld].v 3267c478bd9Sstevel@tonic-gate 3277c478bd9Sstevel@tonic-gate case PR_BAN: 3287c478bd9Sstevel@tonic-gate { 3297c478bd9Sstevel@tonic-gate char *ptr = NAME_ON; 3307c478bd9Sstevel@tonic-gate 3317c478bd9Sstevel@tonic-gate switch (prbufp->banner) { 3327c478bd9Sstevel@tonic-gate case BAN_ALWAYS: 3337c478bd9Sstevel@tonic-gate ptr = NAME_ON; 3347c478bd9Sstevel@tonic-gate break; 3357c478bd9Sstevel@tonic-gate case BAN_NEVER: 3367c478bd9Sstevel@tonic-gate ptr = NAME_OFF; 3377c478bd9Sstevel@tonic-gate break; 3387c478bd9Sstevel@tonic-gate case BAN_OPTIONAL: 3397c478bd9Sstevel@tonic-gate ptr = NAME_OPTIONAL; 3407c478bd9Sstevel@tonic-gate break; 3417c478bd9Sstevel@tonic-gate } 3427c478bd9Sstevel@tonic-gate (void)fdprintf(fdout, "%s %s\n", HEAD, ptr); 3437c478bd9Sstevel@tonic-gate } 3447c478bd9Sstevel@tonic-gate break; 3457c478bd9Sstevel@tonic-gate 3467c478bd9Sstevel@tonic-gate case PR_CPI: 3477c478bd9Sstevel@tonic-gate print_sdn(fdout, HEAD, prbufp->cpi); 3487c478bd9Sstevel@tonic-gate break; 3497c478bd9Sstevel@tonic-gate 3507c478bd9Sstevel@tonic-gate case PR_CS: 3517c478bd9Sstevel@tonic-gate if (!emptylist(prbufp->char_sets)) 3527c478bd9Sstevel@tonic-gate print_l(fdout, HEAD, prbufp->char_sets); 3537c478bd9Sstevel@tonic-gate break; 3547c478bd9Sstevel@tonic-gate 3557c478bd9Sstevel@tonic-gate case PR_ITYPES: 3567c478bd9Sstevel@tonic-gate /* 3577c478bd9Sstevel@tonic-gate * Put out the header even if the list is empty, 3587c478bd9Sstevel@tonic-gate * to distinguish no input types from the default. 3597c478bd9Sstevel@tonic-gate */ 3607c478bd9Sstevel@tonic-gate print_l(fdout, HEAD, prbufp->input_types); 3617c478bd9Sstevel@tonic-gate break; 3627c478bd9Sstevel@tonic-gate 3637c478bd9Sstevel@tonic-gate case PR_DEV: 3647c478bd9Sstevel@tonic-gate print_str(fdout, HEAD, prbufp->device); 3657c478bd9Sstevel@tonic-gate break; 3667c478bd9Sstevel@tonic-gate 3677c478bd9Sstevel@tonic-gate case PR_DIAL: 3687c478bd9Sstevel@tonic-gate print_str(fdout, HEAD, prbufp->dial_info); 3697c478bd9Sstevel@tonic-gate break; 3707c478bd9Sstevel@tonic-gate 3717c478bd9Sstevel@tonic-gate case PR_RECOV: 3727c478bd9Sstevel@tonic-gate print_str(fdout, HEAD, prbufp->fault_rec); 3737c478bd9Sstevel@tonic-gate break; 3747c478bd9Sstevel@tonic-gate 3757c478bd9Sstevel@tonic-gate case PR_INTFC: 3767c478bd9Sstevel@tonic-gate print_str(fdout, HEAD, prbufp->interface); 3777c478bd9Sstevel@tonic-gate break; 3787c478bd9Sstevel@tonic-gate 3797c478bd9Sstevel@tonic-gate case PR_LPI: 3807c478bd9Sstevel@tonic-gate print_sdn(fdout, HEAD, prbufp->lpi); 3817c478bd9Sstevel@tonic-gate break; 3827c478bd9Sstevel@tonic-gate 3837c478bd9Sstevel@tonic-gate case PR_LEN: 3847c478bd9Sstevel@tonic-gate print_sdn(fdout, HEAD, prbufp->plen); 3857c478bd9Sstevel@tonic-gate break; 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate case PR_LOGIN: 3887c478bd9Sstevel@tonic-gate if (prbufp->login & LOG_IN) 3897c478bd9Sstevel@tonic-gate (void)fdprintf(fdout, "%s\n", HEAD); 3907c478bd9Sstevel@tonic-gate break; 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate case PR_PTYPE: 3937c478bd9Sstevel@tonic-gate { 3947c478bd9Sstevel@tonic-gate char **printer_types; 3957c478bd9Sstevel@tonic-gate 3967c478bd9Sstevel@tonic-gate /* 3977c478bd9Sstevel@tonic-gate * For backward compatibility for those who 3987c478bd9Sstevel@tonic-gate * use only "->printer_type", we have to play 3997c478bd9Sstevel@tonic-gate * some games here. 4007c478bd9Sstevel@tonic-gate */ 4017c478bd9Sstevel@tonic-gate if (prbufp->printer_type && !prbufp->printer_types) 4027c478bd9Sstevel@tonic-gate printer_types = getlist( 4037c478bd9Sstevel@tonic-gate prbufp->printer_type, 4047c478bd9Sstevel@tonic-gate LP_WS, 4057c478bd9Sstevel@tonic-gate LP_SEP 4067c478bd9Sstevel@tonic-gate ); 4077c478bd9Sstevel@tonic-gate else 4087c478bd9Sstevel@tonic-gate printer_types = prbufp->printer_types; 4097c478bd9Sstevel@tonic-gate 4107c478bd9Sstevel@tonic-gate if (!printer_types || !*printer_types) 4117c478bd9Sstevel@tonic-gate print_str(fdout, HEAD, NAME_UNKNOWN); 4127c478bd9Sstevel@tonic-gate else 4137c478bd9Sstevel@tonic-gate print_l(fdout, HEAD, printer_types); 4147c478bd9Sstevel@tonic-gate 4157c478bd9Sstevel@tonic-gate if (printer_types != prbufp->printer_types) 4167c478bd9Sstevel@tonic-gate freelist (printer_types); 4177c478bd9Sstevel@tonic-gate break; 4187c478bd9Sstevel@tonic-gate } 4197c478bd9Sstevel@tonic-gate 4207c478bd9Sstevel@tonic-gate case PR_REMOTE: 4217c478bd9Sstevel@tonic-gate print_str(fdout, HEAD, prbufp->remote); 4227c478bd9Sstevel@tonic-gate break; 4237c478bd9Sstevel@tonic-gate 4247c478bd9Sstevel@tonic-gate case PR_SPEED: 4257c478bd9Sstevel@tonic-gate print_str(fdout, HEAD, speed); 4267c478bd9Sstevel@tonic-gate break; 4277c478bd9Sstevel@tonic-gate 4287c478bd9Sstevel@tonic-gate case PR_STTY: 4297c478bd9Sstevel@tonic-gate print_str(fdout, HEAD, stty); 4307c478bd9Sstevel@tonic-gate break; 4317c478bd9Sstevel@tonic-gate 4327c478bd9Sstevel@tonic-gate case PR_WIDTH: 4337c478bd9Sstevel@tonic-gate print_sdn(fdout, HEAD, prbufp->pwid); 4347c478bd9Sstevel@tonic-gate break; 4357c478bd9Sstevel@tonic-gate 4367c478bd9Sstevel@tonic-gate #if defined(CAN_DO_MODULES) 4377c478bd9Sstevel@tonic-gate case PR_MODULES: 4387c478bd9Sstevel@tonic-gate /* 4397c478bd9Sstevel@tonic-gate * Put out the header even if the list is empty, 4407c478bd9Sstevel@tonic-gate * to distinguish no modules from the default. 4417c478bd9Sstevel@tonic-gate */ 4427c478bd9Sstevel@tonic-gate print_l(fdout, HEAD, prbufp->modules); 4437c478bd9Sstevel@tonic-gate break; 4447c478bd9Sstevel@tonic-gate #endif 4457c478bd9Sstevel@tonic-gate 4467c478bd9Sstevel@tonic-gate case PR_OPTIONS: 4477c478bd9Sstevel@tonic-gate print_l(fdout, HEAD, prbufp->options); 4487c478bd9Sstevel@tonic-gate break; 4497c478bd9Sstevel@tonic-gate 4507c478bd9Sstevel@tonic-gate case PR_PPD: 4517c478bd9Sstevel@tonic-gate { 4527c478bd9Sstevel@tonic-gate print_str(fdout, HEAD, prbufp->ppd); 4537c478bd9Sstevel@tonic-gate break; 4547c478bd9Sstevel@tonic-gate } 4557c478bd9Sstevel@tonic-gate } 4567c478bd9Sstevel@tonic-gate 4577c478bd9Sstevel@tonic-gate } 4587c478bd9Sstevel@tonic-gate if (stty) 4597c478bd9Sstevel@tonic-gate Free (stty); 4607c478bd9Sstevel@tonic-gate if (speed) 4617c478bd9Sstevel@tonic-gate Free (speed); 4627c478bd9Sstevel@tonic-gate if (errno != 0) { 4637c478bd9Sstevel@tonic-gate close(fdout); 4647c478bd9Sstevel@tonic-gate return (-1); 4657c478bd9Sstevel@tonic-gate } 4667c478bd9Sstevel@tonic-gate close(fdout); 4677c478bd9Sstevel@tonic-gate 4687c478bd9Sstevel@tonic-gate /* 4697c478bd9Sstevel@tonic-gate * If we have a description of the printer, 4707c478bd9Sstevel@tonic-gate * write it out to a separate file. 4717c478bd9Sstevel@tonic-gate */ 4727c478bd9Sstevel@tonic-gate if (prbufp->description) { 4737c478bd9Sstevel@tonic-gate 4747c478bd9Sstevel@tonic-gate if (!(path = getprinterfile(name, COMMENTFILE))) 4757c478bd9Sstevel@tonic-gate return (-1); 4767c478bd9Sstevel@tonic-gate 4777c478bd9Sstevel@tonic-gate if (dumpstring(path, prbufp->description) == -1) { 4787c478bd9Sstevel@tonic-gate Free (path); 4797c478bd9Sstevel@tonic-gate return (-1); 4807c478bd9Sstevel@tonic-gate } 4817c478bd9Sstevel@tonic-gate Free (path); 4827c478bd9Sstevel@tonic-gate 4837c478bd9Sstevel@tonic-gate } 4847c478bd9Sstevel@tonic-gate 4857c478bd9Sstevel@tonic-gate /* 4867c478bd9Sstevel@tonic-gate * Now write out the alert condition. 4877c478bd9Sstevel@tonic-gate */ 4887c478bd9Sstevel@tonic-gate if ( 4897c478bd9Sstevel@tonic-gate prbufp->fault_alert.shcmd 4907c478bd9Sstevel@tonic-gate && putalert(Lp_A_Printers, name, &(prbufp->fault_alert)) == -1 4917c478bd9Sstevel@tonic-gate ) 4927c478bd9Sstevel@tonic-gate return (-1); 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate return (0); 4957c478bd9Sstevel@tonic-gate } 4967c478bd9Sstevel@tonic-gate 4977c478bd9Sstevel@tonic-gate /** 4987c478bd9Sstevel@tonic-gate ** print_sdn() - PRINT SCALED DECIMAL NUMBER WITH HEADER 4997c478bd9Sstevel@tonic-gate ** print_l() - PRINT (char **) LIST WITH HEADER 5007c478bd9Sstevel@tonic-gate ** print_str() - PRINT STRING WITH HEADER 5017c478bd9Sstevel@tonic-gate **/ 5027c478bd9Sstevel@tonic-gate 5037c478bd9Sstevel@tonic-gate static void 5047c478bd9Sstevel@tonic-gate print_sdn(int fd, char *head, SCALED sdn) 5057c478bd9Sstevel@tonic-gate { 5067c478bd9Sstevel@tonic-gate if (sdn.val <= 0) 5077c478bd9Sstevel@tonic-gate return; 5087c478bd9Sstevel@tonic-gate 5097c478bd9Sstevel@tonic-gate (void)fdprintf (fd, "%s ", head); 5107c478bd9Sstevel@tonic-gate fdprintsdn (fd, sdn); 5117c478bd9Sstevel@tonic-gate 5127c478bd9Sstevel@tonic-gate return; 5137c478bd9Sstevel@tonic-gate } 5147c478bd9Sstevel@tonic-gate 5157c478bd9Sstevel@tonic-gate static void 5167c478bd9Sstevel@tonic-gate print_l(int fd, char *head, char **list) 5177c478bd9Sstevel@tonic-gate { 5187c478bd9Sstevel@tonic-gate (void)fdprintf (fd, "%s ", head); 5197c478bd9Sstevel@tonic-gate printlist_setup (0, 0, LP_SEP, 0); 5207c478bd9Sstevel@tonic-gate fdprintlist (fd, list); 5217c478bd9Sstevel@tonic-gate printlist_unsetup (); 5227c478bd9Sstevel@tonic-gate 5237c478bd9Sstevel@tonic-gate return; 5247c478bd9Sstevel@tonic-gate } 5257c478bd9Sstevel@tonic-gate 5267c478bd9Sstevel@tonic-gate static void 5277c478bd9Sstevel@tonic-gate print_str(int fd, char *head, char *str) 5287c478bd9Sstevel@tonic-gate { 5297c478bd9Sstevel@tonic-gate if (!str || !*str) 5307c478bd9Sstevel@tonic-gate return; 5317c478bd9Sstevel@tonic-gate 5327c478bd9Sstevel@tonic-gate (void)fdprintf (fd, "%s %s\n", head, str); 5337c478bd9Sstevel@tonic-gate 5347c478bd9Sstevel@tonic-gate return; 5357c478bd9Sstevel@tonic-gate } 5367c478bd9Sstevel@tonic-gate 5377c478bd9Sstevel@tonic-gate 5387c478bd9Sstevel@tonic-gate #ifdef LP_USE_PAPI_ATTR 5397c478bd9Sstevel@tonic-gate /* 5407c478bd9Sstevel@tonic-gate * Function: addPrintersPPD() 5417c478bd9Sstevel@tonic-gate * 5427c478bd9Sstevel@tonic-gate * Description: Handle PPD (Postscript Printer Definition) file for this 5437c478bd9Sstevel@tonic-gate * printer if it has been configured with one 5447c478bd9Sstevel@tonic-gate * 5457c478bd9Sstevel@tonic-gate */ 5467c478bd9Sstevel@tonic-gate 5477c478bd9Sstevel@tonic-gate static int 5487c478bd9Sstevel@tonic-gate addPrintersPPD(char *name, PRINTER *prbufp) 5497c478bd9Sstevel@tonic-gate 5507c478bd9Sstevel@tonic-gate { 5517c478bd9Sstevel@tonic-gate int result = 0; 5527c478bd9Sstevel@tonic-gate char *path = NULL; 5537c478bd9Sstevel@tonic-gate char *ppd = NULL; 5547c478bd9Sstevel@tonic-gate char buf[BUFSIZ]; 5557c478bd9Sstevel@tonic-gate struct stat statbuf; 5567c478bd9Sstevel@tonic-gate 5577c478bd9Sstevel@tonic-gate (void) snprintf(buf, sizeof (buf), "%s.ppd", name); 5587c478bd9Sstevel@tonic-gate if (prbufp->remote) 5597c478bd9Sstevel@tonic-gate { 5607c478bd9Sstevel@tonic-gate /* make sure the PPD file doesn't exist for a remote printer */ 5617c478bd9Sstevel@tonic-gate if (!(path = makepath(ETCDIR, "ppd", buf, (char *)0))) 5627c478bd9Sstevel@tonic-gate { 5637c478bd9Sstevel@tonic-gate result = -1; 5647c478bd9Sstevel@tonic-gate } 5657c478bd9Sstevel@tonic-gate else 5667c478bd9Sstevel@tonic-gate { 5677c478bd9Sstevel@tonic-gate (void) rmfile(path); 5687c478bd9Sstevel@tonic-gate } 5697c478bd9Sstevel@tonic-gate } 5707c478bd9Sstevel@tonic-gate 5717c478bd9Sstevel@tonic-gate if ((result == 0) && (prbufp->ppd != NULL)) 5727c478bd9Sstevel@tonic-gate { 5737c478bd9Sstevel@tonic-gate ppd = strdup(prbufp->ppd); 5747c478bd9Sstevel@tonic-gate 5757c478bd9Sstevel@tonic-gate if (ppd == NULL) 5767c478bd9Sstevel@tonic-gate { 5777c478bd9Sstevel@tonic-gate result = -1; 5787c478bd9Sstevel@tonic-gate } 5797c478bd9Sstevel@tonic-gate else 5807c478bd9Sstevel@tonic-gate { 5817c478bd9Sstevel@tonic-gate /* Check the PPD file given exists */ 5827c478bd9Sstevel@tonic-gate 5837c478bd9Sstevel@tonic-gate if (Stat(ppd, &statbuf) == -1) 5847c478bd9Sstevel@tonic-gate { 5857c478bd9Sstevel@tonic-gate /* 5867c478bd9Sstevel@tonic-gate * The given ppd files does not exist, but 5877c478bd9Sstevel@tonic-gate * check if there is a zipped version of the 5887c478bd9Sstevel@tonic-gate * file that we can use instead 5897c478bd9Sstevel@tonic-gate */ 5907c478bd9Sstevel@tonic-gate if (strstr(ppd, PPDZIP) != NULL) 5917c478bd9Sstevel@tonic-gate { 5927c478bd9Sstevel@tonic-gate /* this is a zipped file so exit */ 5937c478bd9Sstevel@tonic-gate result = -1; 5947c478bd9Sstevel@tonic-gate } 5957c478bd9Sstevel@tonic-gate else 5967c478bd9Sstevel@tonic-gate { 5977c478bd9Sstevel@tonic-gate ppd = Realloc(ppd, 5987c478bd9Sstevel@tonic-gate strlen(ppd)+strlen(PPDZIP)+2); 5997c478bd9Sstevel@tonic-gate if (ppd != NULL) 6007c478bd9Sstevel@tonic-gate { 6017c478bd9Sstevel@tonic-gate ppd = strcat(ppd, PPDZIP); 6027c478bd9Sstevel@tonic-gate if (Stat(ppd, &statbuf) == -1) 6037c478bd9Sstevel@tonic-gate { 6047c478bd9Sstevel@tonic-gate /* 6057c478bd9Sstevel@tonic-gate * this zipped version 6067c478bd9Sstevel@tonic-gate * of the file does not 6077c478bd9Sstevel@tonic-gate * exist either 6087c478bd9Sstevel@tonic-gate */ 6097c478bd9Sstevel@tonic-gate result = -1; 6107c478bd9Sstevel@tonic-gate } 6117c478bd9Sstevel@tonic-gate } 6127c478bd9Sstevel@tonic-gate else 6137c478bd9Sstevel@tonic-gate { 6147c478bd9Sstevel@tonic-gate result = -1; 6157c478bd9Sstevel@tonic-gate } 6167c478bd9Sstevel@tonic-gate } 6177c478bd9Sstevel@tonic-gate } 6187c478bd9Sstevel@tonic-gate } 6197c478bd9Sstevel@tonic-gate 6207c478bd9Sstevel@tonic-gate /* 6217c478bd9Sstevel@tonic-gate * Create the copy of the PPD file for this printer 6227c478bd9Sstevel@tonic-gate * unless that would be silly or not desired 6237c478bd9Sstevel@tonic-gate */ 6247c478bd9Sstevel@tonic-gate 6257c478bd9Sstevel@tonic-gate if (result == 0) 6267c478bd9Sstevel@tonic-gate { 6277c478bd9Sstevel@tonic-gate if (!(path = makepath(ETCDIR, "ppd", buf, (char *)0))) 6287c478bd9Sstevel@tonic-gate { 6297c478bd9Sstevel@tonic-gate result = -1; 6307c478bd9Sstevel@tonic-gate } 6317c478bd9Sstevel@tonic-gate } 6327c478bd9Sstevel@tonic-gate 6337c478bd9Sstevel@tonic-gate /* 6347c478bd9Sstevel@tonic-gate * At this point we may have a zipped or unzipped ppd file, if 6357c478bd9Sstevel@tonic-gate * it's unzipped just copy it otherwise unzip it to the 6367c478bd9Sstevel@tonic-gate * printer's ppd file (/etc/lp/ppd/<printer>.ppd) 6377c478bd9Sstevel@tonic-gate */ 6387c478bd9Sstevel@tonic-gate 6397c478bd9Sstevel@tonic-gate if (result == 0) 6407c478bd9Sstevel@tonic-gate { 6417c478bd9Sstevel@tonic-gate if (strstr(ppd, PPDZIP) == NULL) 6427c478bd9Sstevel@tonic-gate { 6437c478bd9Sstevel@tonic-gate result = copyPPDFile(ppd, path); 6447c478bd9Sstevel@tonic-gate } 6457c478bd9Sstevel@tonic-gate else 6467c478bd9Sstevel@tonic-gate { 6477c478bd9Sstevel@tonic-gate result = unzipPPDFile(ppd, path); 6487c478bd9Sstevel@tonic-gate } 6497c478bd9Sstevel@tonic-gate 6507c478bd9Sstevel@tonic-gate (void) chown_lppath(path); 6517c478bd9Sstevel@tonic-gate (void) chmod(path, 0644); 6527c478bd9Sstevel@tonic-gate } 6537c478bd9Sstevel@tonic-gate 6547c478bd9Sstevel@tonic-gate if (ppd != NULL) 6557c478bd9Sstevel@tonic-gate { 6567c478bd9Sstevel@tonic-gate Free(ppd); 6577c478bd9Sstevel@tonic-gate } 6587c478bd9Sstevel@tonic-gate if (path != NULL) 6597c478bd9Sstevel@tonic-gate { 6607c478bd9Sstevel@tonic-gate Free(path); 6617c478bd9Sstevel@tonic-gate } 6627c478bd9Sstevel@tonic-gate } 6637c478bd9Sstevel@tonic-gate 6647c478bd9Sstevel@tonic-gate return (result); 6657c478bd9Sstevel@tonic-gate } /* addPrintersPPD() */ 6667c478bd9Sstevel@tonic-gate 6677c478bd9Sstevel@tonic-gate 6687c478bd9Sstevel@tonic-gate /* 6697c478bd9Sstevel@tonic-gate * Function: copyPPDFile() 6707c478bd9Sstevel@tonic-gate * 6717c478bd9Sstevel@tonic-gate * Description: Copy the given ppd file to the printer's file in /etc/lp/ppd 6727c478bd9Sstevel@tonic-gate * 6737c478bd9Sstevel@tonic-gate */ 6747c478bd9Sstevel@tonic-gate 6757c478bd9Sstevel@tonic-gate static int 6767c478bd9Sstevel@tonic-gate copyPPDFile(char *ppd, char *printersPPD) 6777c478bd9Sstevel@tonic-gate 6787c478bd9Sstevel@tonic-gate { 6797c478bd9Sstevel@tonic-gate int result = 0; 6807c478bd9Sstevel@tonic-gate register int n = 0; 6817c478bd9Sstevel@tonic-gate int fdin = 0; 6827c478bd9Sstevel@tonic-gate int fdout = 0; 6837c478bd9Sstevel@tonic-gate char buf[BUFSIZ]; 6847c478bd9Sstevel@tonic-gate 6857c478bd9Sstevel@tonic-gate if ((ppd != NULL) && (printersPPD != NULL)) 6867c478bd9Sstevel@tonic-gate { 6877c478bd9Sstevel@tonic-gate if ((fdin = open_locked(ppd, "r", 0)) < 0) 6887c478bd9Sstevel@tonic-gate { 6897c478bd9Sstevel@tonic-gate result = -1; 6907c478bd9Sstevel@tonic-gate } 6917c478bd9Sstevel@tonic-gate else 6927c478bd9Sstevel@tonic-gate { 6937c478bd9Sstevel@tonic-gate fdout = open_locked(printersPPD, "w", MODE_EXEC); 6947c478bd9Sstevel@tonic-gate if (fdout < 0) 6957c478bd9Sstevel@tonic-gate { 6967c478bd9Sstevel@tonic-gate close(fdin); 6977c478bd9Sstevel@tonic-gate result = -1; 6987c478bd9Sstevel@tonic-gate } 6997c478bd9Sstevel@tonic-gate } 7007c478bd9Sstevel@tonic-gate 7017c478bd9Sstevel@tonic-gate if (result == 0) 7027c478bd9Sstevel@tonic-gate { 7037c478bd9Sstevel@tonic-gate while ((n = read(fdin, buf, BUFSIZ)) > 0) 7047c478bd9Sstevel@tonic-gate { 7057c478bd9Sstevel@tonic-gate write(fdout, buf, n); 7067c478bd9Sstevel@tonic-gate } 7077c478bd9Sstevel@tonic-gate close(fdout); 7087c478bd9Sstevel@tonic-gate close(fdin); 7097c478bd9Sstevel@tonic-gate } 7107c478bd9Sstevel@tonic-gate } 7117c478bd9Sstevel@tonic-gate else 7127c478bd9Sstevel@tonic-gate { 7137c478bd9Sstevel@tonic-gate result = -1; 7147c478bd9Sstevel@tonic-gate } 7157c478bd9Sstevel@tonic-gate 7167c478bd9Sstevel@tonic-gate return (result); 7177c478bd9Sstevel@tonic-gate } /* copyPPDFile() */ 7187c478bd9Sstevel@tonic-gate 7197c478bd9Sstevel@tonic-gate 7207c478bd9Sstevel@tonic-gate 7217c478bd9Sstevel@tonic-gate /* 7227c478bd9Sstevel@tonic-gate * Function: unzipPPDFile() 7237c478bd9Sstevel@tonic-gate * 7247c478bd9Sstevel@tonic-gate * Description: Unzip the given ppd file to the printer's file in /etc/lp/ppd. 7257c478bd9Sstevel@tonic-gate * This is done by forking and running the unzip utility on the 7267c478bd9Sstevel@tonic-gate * zipped ppd file. 7277c478bd9Sstevel@tonic-gate * 7287c478bd9Sstevel@tonic-gate */ 7297c478bd9Sstevel@tonic-gate 7307c478bd9Sstevel@tonic-gate static int 7317c478bd9Sstevel@tonic-gate unzipPPDFile(char *ppd, char *printersPPD) 7327c478bd9Sstevel@tonic-gate 7337c478bd9Sstevel@tonic-gate { 7347c478bd9Sstevel@tonic-gate int result = -1; 7357c478bd9Sstevel@tonic-gate char *cmdLine = NULL; 7367c478bd9Sstevel@tonic-gate pid_t childPID = 0; 7377c478bd9Sstevel@tonic-gate int stat = 0; 7387c478bd9Sstevel@tonic-gate int clSize = 0; 7397c478bd9Sstevel@tonic-gate 7407c478bd9Sstevel@tonic-gate 7417c478bd9Sstevel@tonic-gate if ((ppd != NULL) && (printersPPD != NULL)) 7427c478bd9Sstevel@tonic-gate { 7437c478bd9Sstevel@tonic-gate childPID = fork(); 7447c478bd9Sstevel@tonic-gate 7457c478bd9Sstevel@tonic-gate switch (childPID) 7467c478bd9Sstevel@tonic-gate { 7477c478bd9Sstevel@tonic-gate case -1: 7487c478bd9Sstevel@tonic-gate { 7497c478bd9Sstevel@tonic-gate /* return error */ 7507c478bd9Sstevel@tonic-gate break; 7517c478bd9Sstevel@tonic-gate } 7527c478bd9Sstevel@tonic-gate 7537c478bd9Sstevel@tonic-gate case 0: 7547c478bd9Sstevel@tonic-gate { 7557c478bd9Sstevel@tonic-gate /* child process - so execute something */ 7567c478bd9Sstevel@tonic-gate 7577c478bd9Sstevel@tonic-gate clSize = strlen("/usr/bin/rm -f ") + 7587c478bd9Sstevel@tonic-gate strlen(printersPPD) + 7597c478bd9Sstevel@tonic-gate strlen("/usr/bin/gzip -dc ") + 7607c478bd9Sstevel@tonic-gate strlen(ppd) + 7617c478bd9Sstevel@tonic-gate strlen(printersPPD) + 20; 7627c478bd9Sstevel@tonic-gate cmdLine = malloc(clSize); 7637c478bd9Sstevel@tonic-gate if (cmdLine != NULL) 7647c478bd9Sstevel@tonic-gate { 7657c478bd9Sstevel@tonic-gate 7667c478bd9Sstevel@tonic-gate (void) snprintf(cmdLine, clSize, 7677c478bd9Sstevel@tonic-gate "/usr/bin/rm -f %s; /usr/bin/gzip -dc %s > %s", 7687c478bd9Sstevel@tonic-gate printersPPD, ppd, 7697c478bd9Sstevel@tonic-gate printersPPD); 7707c478bd9Sstevel@tonic-gate result = execl(SHELL, SHELL, "-c", 7717c478bd9Sstevel@tonic-gate cmdLine, NULL); 7727c478bd9Sstevel@tonic-gate exit(result); 7737c478bd9Sstevel@tonic-gate } 7747c478bd9Sstevel@tonic-gate break; 7757c478bd9Sstevel@tonic-gate } 7767c478bd9Sstevel@tonic-gate 7777c478bd9Sstevel@tonic-gate default: 7787c478bd9Sstevel@tonic-gate { 7797c478bd9Sstevel@tonic-gate /* parent process, child pid is in childPID */ 7807c478bd9Sstevel@tonic-gate 7817c478bd9Sstevel@tonic-gate while (wait(&stat) != childPID); 7827c478bd9Sstevel@tonic-gate 7837c478bd9Sstevel@tonic-gate if ((stat & 0xff00) == 0) 7847c478bd9Sstevel@tonic-gate { 7857c478bd9Sstevel@tonic-gate result = 0; 7867c478bd9Sstevel@tonic-gate } 7877c478bd9Sstevel@tonic-gate break; 7887c478bd9Sstevel@tonic-gate } 7897c478bd9Sstevel@tonic-gate } 7907c478bd9Sstevel@tonic-gate } 7917c478bd9Sstevel@tonic-gate 7927c478bd9Sstevel@tonic-gate return (result); 7937c478bd9Sstevel@tonic-gate } /* unzipPPDFile() */ 7947c478bd9Sstevel@tonic-gate #endif 795