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