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 1997 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 /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */
31
32 #include "stdio.h"
33 #include "sys/types.h"
34 #include "stdlib.h"
35 #include <unistd.h>
36
37 #include "lp.h"
38 #include "printers.h"
39
40 unsigned long badprinter = 0;
41
42 static int okinterface ( char * , PRINTER * );
43
44 /**
45 ** okprinter() - SEE IF PRINTER STRUCTURE IS SOUND
46 **/
47
48 int
okprinter(char * name,PRINTER * prbufp,int isput)49 okprinter(char *name, PRINTER *prbufp, int isput)
50 {
51 badprinter = 0;
52
53 /*
54 * A printer can't be remote and have device, interface,
55 * fault recovery, or alerts.
56 */
57 if (
58 prbufp->remote
59 && (
60 prbufp->device
61 || prbufp->interface
62 || (
63 prbufp->fault_alert.shcmd
64 && !STREQU(NAME_NONE, prbufp->fault_alert.shcmd)
65 )
66 #if defined(CAN_DO_MODULES)
67 # if defined(FIXED)
68 /*
69 * This needs some work...getprinter() initializes this to "default"
70 */
71 || (
72 !emptylist(prbufp->modules)
73 && !STREQU(NAME_NONE, prbufp->modules[0])
74 )
75 # endif
76 #endif
77 )
78 )
79 badprinter |= BAD_REMOTE;
80
81 /*
82 * A local printer must have an interface program. This is
83 * for historical purposes (it let's someone know where the
84 * interface program came from) AND is used by "putprinter()"
85 * to copy the interface program. We must be able to read it.
86 */
87 if (!prbufp->remote && isput && !okinterface(name, prbufp))
88 badprinter |= BAD_INTERFACE;
89
90 /*
91 * A local printer must have device or dial info.
92 */
93 if (!prbufp->remote && !prbufp->device && !prbufp->dial_info)
94 badprinter |= BAD_DEVDIAL;
95
96 /*
97 * Fault recovery must be one of three kinds
98 * (or default).
99 */
100 if (
101 prbufp->fault_rec
102 && !STREQU(prbufp->fault_rec, NAME_CONTINUE)
103 && !STREQU(prbufp->fault_rec, NAME_BEGINNING)
104 && !STREQU(prbufp->fault_rec, NAME_WAIT)
105 )
106 badprinter |= BAD_FAULT;
107
108 /*
109 * Alert command can't be reserved word.
110 */
111 if (
112 prbufp->fault_alert.shcmd
113 && (
114 STREQU(prbufp->fault_alert.shcmd, NAME_QUIET)
115 || STREQU(prbufp->fault_alert.shcmd, NAME_LIST)
116 )
117 )
118 badprinter |= BAD_ALERT;
119
120 return ((badprinter & ~ignprinter)? 0 : 1);
121 }
122
123 /**
124 ** okinterface() - CHECK THAT THE INTERFACE PROGRAM IS OKAY
125 **/
126
127 static int
canread(char * path)128 canread(char *path)
129 {
130 return ((access(path, R_OK) < 0) ? 0 : 1);
131 }
132
133 static int
okinterface(char * name,PRINTER * prbufp)134 okinterface(char *name, PRINTER *prbufp)
135 {
136 int ret;
137
138 register char *path;
139
140
141 if (prbufp->interface)
142 ret = canread(prbufp->interface);
143
144 else
145 if (!(path = makepath(Lp_A_Interfaces, name, (char *)0)))
146 ret = 0;
147 else {
148 ret = canread(path);
149 Free (path);
150 }
151
152 return (ret);
153 }
154