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