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
5*0a44ef6dSjacobs * Common Development and Distribution License (the "License").
6*0a44ef6dSjacobs * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
21*0a44ef6dSjacobs
224bc0a2efScasper /*
23*0a44ef6dSjacobs * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
244bc0a2efScasper * Use is subject to license terms.
254bc0a2efScasper */
26*0a44ef6dSjacobs
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate
314bc0a2efScasper #pragma ident "%Z%%M% %I% %E% SMI"
327c478bd9Sstevel@tonic-gate /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gate #include "string.h"
357c478bd9Sstevel@tonic-gate #include "errno.h"
367c478bd9Sstevel@tonic-gate #include "sys/types.h"
377c478bd9Sstevel@tonic-gate #include "stdlib.h"
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate #include "lp.h"
407c478bd9Sstevel@tonic-gate #include "printers.h"
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate /**
437c478bd9Sstevel@tonic-gate ** getpwheel() - GET PRINT WHEEL INFO FROM DISK
447c478bd9Sstevel@tonic-gate **/
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate PWHEEL *
477c478bd9Sstevel@tonic-gate #if defined(__STDC__)
getpwheel(char * name)487c478bd9Sstevel@tonic-gate getpwheel (
497c478bd9Sstevel@tonic-gate char * name
507c478bd9Sstevel@tonic-gate )
517c478bd9Sstevel@tonic-gate #else
527c478bd9Sstevel@tonic-gate getpwheel (name)
537c478bd9Sstevel@tonic-gate char *name;
547c478bd9Sstevel@tonic-gate #endif
557c478bd9Sstevel@tonic-gate {
567c478bd9Sstevel@tonic-gate static long lastdir = -1;
577c478bd9Sstevel@tonic-gate
58*0a44ef6dSjacobs PWHEEL *pwp;
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate register FALERT *pa;
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate
637c478bd9Sstevel@tonic-gate if (!name || !*name) {
647c478bd9Sstevel@tonic-gate errno = EINVAL;
657c478bd9Sstevel@tonic-gate return (0);
667c478bd9Sstevel@tonic-gate }
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate * Getting ``all''? If so, jump into the directory
707c478bd9Sstevel@tonic-gate * wherever we left off.
717c478bd9Sstevel@tonic-gate */
727c478bd9Sstevel@tonic-gate if (STREQU(NAME_ALL, name)) {
737c478bd9Sstevel@tonic-gate if (!(name = next_dir(Lp_A_PrintWheels, &lastdir)))
747c478bd9Sstevel@tonic-gate return (0);
757c478bd9Sstevel@tonic-gate } else
767c478bd9Sstevel@tonic-gate lastdir = -1;
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate /*
797c478bd9Sstevel@tonic-gate * Get the information for the alert.
807c478bd9Sstevel@tonic-gate */
817c478bd9Sstevel@tonic-gate if (!(pa = getalert(Lp_A_PrintWheels, name))) {
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate /*
847c478bd9Sstevel@tonic-gate * Unless the world has turned weird, we shouldn't
857c478bd9Sstevel@tonic-gate * get ENOTDIR if we're doing the ``all'' case--because
867c478bd9Sstevel@tonic-gate * getting here in the all case meant the printwheel
877c478bd9Sstevel@tonic-gate * directory exists, but ENOTDIR means it doesn't!
887c478bd9Sstevel@tonic-gate */
897c478bd9Sstevel@tonic-gate if (errno == ENOTDIR)
907c478bd9Sstevel@tonic-gate errno = ENOENT; /* printwheel doesn't exist */
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate return (0);
937c478bd9Sstevel@tonic-gate }
947c478bd9Sstevel@tonic-gate
95*0a44ef6dSjacobs pwp = calloc(1, sizeof (*pwp));
96*0a44ef6dSjacobs pwp->alert = *pa;
97*0a44ef6dSjacobs pwp->name = Strdup(name);
987c478bd9Sstevel@tonic-gate
99*0a44ef6dSjacobs return (pwp);
1007c478bd9Sstevel@tonic-gate }
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate /**
1037c478bd9Sstevel@tonic-gate ** putpwheel() - PUT PRINT WHEEL INFO TO DISK
1047c478bd9Sstevel@tonic-gate **/
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate int
1077c478bd9Sstevel@tonic-gate #if defined(__STDC__)
putpwheel(char * name,PWHEEL * pwheelp)1087c478bd9Sstevel@tonic-gate putpwheel (
1097c478bd9Sstevel@tonic-gate char * name,
1107c478bd9Sstevel@tonic-gate PWHEEL * pwheelp
1117c478bd9Sstevel@tonic-gate )
1127c478bd9Sstevel@tonic-gate #else
1137c478bd9Sstevel@tonic-gate putpwheel (name, pwheelp)
1147c478bd9Sstevel@tonic-gate char *name;
1157c478bd9Sstevel@tonic-gate PWHEEL *pwheelp;
1167c478bd9Sstevel@tonic-gate #endif
1177c478bd9Sstevel@tonic-gate {
1187c478bd9Sstevel@tonic-gate register char *path;
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate struct stat statbuf;
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate if (!name || !*name) {
1247c478bd9Sstevel@tonic-gate errno = EINVAL;
1257c478bd9Sstevel@tonic-gate return (-1);
1267c478bd9Sstevel@tonic-gate }
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate if (STREQU(name, NAME_ALL)) {
1297c478bd9Sstevel@tonic-gate errno = ENOENT;
1307c478bd9Sstevel@tonic-gate return (-1);
1317c478bd9Sstevel@tonic-gate }
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate /*
1347c478bd9Sstevel@tonic-gate * Create the parent directory for this printer
1357c478bd9Sstevel@tonic-gate * if it doesn't yet exist.
1367c478bd9Sstevel@tonic-gate */
1377c478bd9Sstevel@tonic-gate if (!(path = makepath(Lp_A_PrintWheels, name, (char *)0)))
1387c478bd9Sstevel@tonic-gate return (-1);
1397c478bd9Sstevel@tonic-gate if (Stat(path, &statbuf) == 0) {
1404bc0a2efScasper if (!S_ISDIR(statbuf.st_mode)) {
1417c478bd9Sstevel@tonic-gate Free (path);
1427c478bd9Sstevel@tonic-gate errno = ENOTDIR;
1437c478bd9Sstevel@tonic-gate return (-1);
1447c478bd9Sstevel@tonic-gate }
1457c478bd9Sstevel@tonic-gate } else if (errno != ENOENT || mkdir_lpdir(path, MODE_DIR) == -1) {
1467c478bd9Sstevel@tonic-gate Free (path);
1477c478bd9Sstevel@tonic-gate return (-1);
1487c478bd9Sstevel@tonic-gate }
1497c478bd9Sstevel@tonic-gate Free (path);
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate /*
1527c478bd9Sstevel@tonic-gate * Now write out the alert condition.
1537c478bd9Sstevel@tonic-gate */
1547c478bd9Sstevel@tonic-gate if (putalert(Lp_A_PrintWheels, name, &(pwheelp->alert)) == -1)
1557c478bd9Sstevel@tonic-gate return (-1);
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate return (0);
1587c478bd9Sstevel@tonic-gate }
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate /**
1617c478bd9Sstevel@tonic-gate ** delpwheel() - DELETE PRINT WHEEL INFO FROM DISK
1627c478bd9Sstevel@tonic-gate **/
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate #if defined(__STDC__)
1657c478bd9Sstevel@tonic-gate static int _delpwheel ( char * );
1667c478bd9Sstevel@tonic-gate #else
1677c478bd9Sstevel@tonic-gate static int _delpwheel();
1687c478bd9Sstevel@tonic-gate #endif
1697c478bd9Sstevel@tonic-gate
1707c478bd9Sstevel@tonic-gate int
1717c478bd9Sstevel@tonic-gate #if defined(__STDC__)
delpwheel(char * name)1727c478bd9Sstevel@tonic-gate delpwheel (
1737c478bd9Sstevel@tonic-gate char * name
1747c478bd9Sstevel@tonic-gate )
1757c478bd9Sstevel@tonic-gate #else
1767c478bd9Sstevel@tonic-gate delpwheel (name)
1777c478bd9Sstevel@tonic-gate char *name;
1787c478bd9Sstevel@tonic-gate #endif
1797c478bd9Sstevel@tonic-gate {
1807c478bd9Sstevel@tonic-gate long lastdir;
1817c478bd9Sstevel@tonic-gate
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate if (!name || !*name) {
1847c478bd9Sstevel@tonic-gate errno = EINVAL;
1857c478bd9Sstevel@tonic-gate return (-1);
1867c478bd9Sstevel@tonic-gate }
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate if (STREQU(NAME_ALL, name)) {
1897c478bd9Sstevel@tonic-gate lastdir = -1;
1907c478bd9Sstevel@tonic-gate while ((name = next_dir(Lp_A_PrintWheels, &lastdir)))
1917c478bd9Sstevel@tonic-gate if (_delpwheel(name) == -1)
1927c478bd9Sstevel@tonic-gate return (-1);
1937c478bd9Sstevel@tonic-gate return (0);
1947c478bd9Sstevel@tonic-gate } else
1957c478bd9Sstevel@tonic-gate return (_delpwheel(name));
1967c478bd9Sstevel@tonic-gate }
1977c478bd9Sstevel@tonic-gate
1987c478bd9Sstevel@tonic-gate /**
1997c478bd9Sstevel@tonic-gate ** _delpwheel()
2007c478bd9Sstevel@tonic-gate **/
2017c478bd9Sstevel@tonic-gate
2027c478bd9Sstevel@tonic-gate static int
2037c478bd9Sstevel@tonic-gate #if defined(__STDC__)
_delpwheel(char * name)2047c478bd9Sstevel@tonic-gate _delpwheel (
2057c478bd9Sstevel@tonic-gate char * name
2067c478bd9Sstevel@tonic-gate )
2077c478bd9Sstevel@tonic-gate #else
2087c478bd9Sstevel@tonic-gate _delpwheel (name)
2097c478bd9Sstevel@tonic-gate char *name;
2107c478bd9Sstevel@tonic-gate #endif
2117c478bd9Sstevel@tonic-gate {
2127c478bd9Sstevel@tonic-gate register char *path;
2137c478bd9Sstevel@tonic-gate
2147c478bd9Sstevel@tonic-gate if (delalert(Lp_A_PrintWheels, name) == -1)
2157c478bd9Sstevel@tonic-gate return (-1);
2167c478bd9Sstevel@tonic-gate if (!(path = makepath(Lp_A_PrintWheels, name, (char *)0)))
2177c478bd9Sstevel@tonic-gate return (-1);
2187c478bd9Sstevel@tonic-gate if (Rmdir(path)) {
2197c478bd9Sstevel@tonic-gate Free (path);
2207c478bd9Sstevel@tonic-gate return (-1);
2217c478bd9Sstevel@tonic-gate }
2227c478bd9Sstevel@tonic-gate Free (path);
2237c478bd9Sstevel@tonic-gate return (0);
2247c478bd9Sstevel@tonic-gate }
2257c478bd9Sstevel@tonic-gate
2267c478bd9Sstevel@tonic-gate /**
2277c478bd9Sstevel@tonic-gate ** freepwheel() - FREE MEMORY ALLOCATED FOR PRINT WHEEL STRUCTURE
2287c478bd9Sstevel@tonic-gate **/
2297c478bd9Sstevel@tonic-gate
2307c478bd9Sstevel@tonic-gate void
2317c478bd9Sstevel@tonic-gate #if defined(__STDC__)
freepwheel(PWHEEL * ppw)2327c478bd9Sstevel@tonic-gate freepwheel (
2337c478bd9Sstevel@tonic-gate PWHEEL * ppw
2347c478bd9Sstevel@tonic-gate )
2357c478bd9Sstevel@tonic-gate #else
2367c478bd9Sstevel@tonic-gate freepwheel (ppw)
2377c478bd9Sstevel@tonic-gate PWHEEL *ppw;
2387c478bd9Sstevel@tonic-gate #endif
2397c478bd9Sstevel@tonic-gate {
2407c478bd9Sstevel@tonic-gate if (!ppw)
2417c478bd9Sstevel@tonic-gate return;
2427c478bd9Sstevel@tonic-gate if (ppw->name)
2437c478bd9Sstevel@tonic-gate Free (ppw->name);
2447c478bd9Sstevel@tonic-gate if (ppw->alert.shcmd)
2457c478bd9Sstevel@tonic-gate Free (ppw->alert.shcmd);
246*0a44ef6dSjacobs Free (ppw);
247*0a44ef6dSjacobs
2487c478bd9Sstevel@tonic-gate return;
2497c478bd9Sstevel@tonic-gate }
250