xref: /titanic_51/usr/src/cmd/lp/model/netstandard (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate#
2*7c478bd9Sstevel@tonic-gate# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3*7c478bd9Sstevel@tonic-gate# Use is subject to license terms.
4*7c478bd9Sstevel@tonic-gate#
5*7c478bd9Sstevel@tonic-gate# CDDL HEADER START
6*7c478bd9Sstevel@tonic-gate#
7*7c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
8*7c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
9*7c478bd9Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
10*7c478bd9Sstevel@tonic-gate# with the License.
11*7c478bd9Sstevel@tonic-gate#
12*7c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
13*7c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
14*7c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
15*7c478bd9Sstevel@tonic-gate# and limitations under the License.
16*7c478bd9Sstevel@tonic-gate#
17*7c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
18*7c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
19*7c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
20*7c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
21*7c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
22*7c478bd9Sstevel@tonic-gate#
23*7c478bd9Sstevel@tonic-gate# CDDL HEADER END
24*7c478bd9Sstevel@tonic-gate#
25*7c478bd9Sstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
26*7c478bd9Sstevel@tonic-gate###########
27*7c478bd9Sstevel@tonic-gate##
28*7c478bd9Sstevel@tonic-gate## Network Standard printer interface program.
29*7c478bd9Sstevel@tonic-gate##
30*7c478bd9Sstevel@tonic-gate###########
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gate#####
33*7c478bd9Sstevel@tonic-gate# We can't do much except exit if spooler/scheduler
34*7c478bd9Sstevel@tonic-gate# cancels us.
35*7c478bd9Sstevel@tonic-gate#####
36*7c478bd9Sstevel@tonic-gatetrap 'eval exit_clean 15' 15
37*7c478bd9Sstevel@tonic-gate
38*7c478bd9Sstevel@tonic-gate####
39*7c478bd9Sstevel@tonic-gate#
40*7c478bd9Sstevel@tonic-gate# Send standard error messages to /dev/null rather than to
41*7c478bd9Sstevel@tonic-gate# the spooler. Avoids "Terminated" messages that shell puts out
42*7c478bd9Sstevel@tonic-gate# when gets SIGTERM. Save standard error so it can be used
43*7c478bd9Sstevel@tonic-gate# when we need it
44*7c478bd9Sstevel@tonic-gate####
45*7c478bd9Sstevel@tonic-gateexec 5>&2 2>/dev/null 3>&1
46*7c478bd9Sstevel@tonic-gate
47*7c478bd9Sstevel@tonic-gate####
48*7c478bd9Sstevel@tonic-gate# set some global variables
49*7c478bd9Sstevel@tonic-gate####
50*7c478bd9Sstevel@tonic-gate
51*7c478bd9Sstevel@tonic-gate: ${LPTMPDIR:=/tmp}
52*7c478bd9Sstevel@tonic-gate: ${SPOOLDIR:=/usr/spool/lp}
53*7c478bd9Sstevel@tonic-gate: ${LOCALPATH:=${SPOOLDIR}/bin}
54*7c478bd9Sstevel@tonic-gatePATH="/bin:/usr/bin:${LOCALPATH}"
55*7c478bd9Sstevel@tonic-gateexit_code=0
56*7c478bd9Sstevel@tonic-gate
57*7c478bd9Sstevel@tonic-gate
58*7c478bd9Sstevel@tonic-gate# ${LPTELL} is the name of a program that will send its
59*7c478bd9Sstevel@tonic-gate# standard input to the Spooler. It is used to forward
60*7c478bd9Sstevel@tonic-gate# the description of a printer fault to the Spooler,
61*7c478bd9Sstevel@tonic-gate# which uses it in an alert to the administrator.
62*7c478bd9Sstevel@tonic-gate#####
63*7c478bd9Sstevel@tonic-gateif [ ! -x "${LPTELL:=${LOCALPATH}/lp.tell}" ]
64*7c478bd9Sstevel@tonic-gatethen
65*7c478bd9Sstevel@tonic-gate        fake_lptell () {
66*7c478bd9Sstevel@tonic-gate                header="no"
67*7c478bd9Sstevel@tonic-gate                while read line
68*7c478bd9Sstevel@tonic-gate                do
69*7c478bd9Sstevel@tonic-gate                        if [ "no" = "${header}" ]
70*7c478bd9Sstevel@tonic-gate                        then
71*7c478bd9Sstevel@tonic-gate                                errmsg ERROR ${E_IP_UNKNOWN} \
72*7c478bd9Sstevel@tonic-gate                "unknown printer/interface failure" \
73*7c478bd9Sstevel@tonic-gate                "consult your system administrator;
74*7c478bd9Sstevel@tonic-gate                reasons for failure (if any) follow:"
75*7c478bd9Sstevel@tonic-gate                                header=yes
76*7c478bd9Sstevel@tonic-gate                        fi
77*7c478bd9Sstevel@tonic-gate                        echo "${line}" >&2
78*7c478bd9Sstevel@tonic-gate                done
79*7c478bd9Sstevel@tonic-gate                return 1
80*7c478bd9Sstevel@tonic-gate        }
81*7c478bd9Sstevel@tonic-gate        LPTELL=fake_lptell
82*7c478bd9Sstevel@tonic-gatefi
83*7c478bd9Sstevel@tonic-gate
84*7c478bd9Sstevel@tonic-gate#####
85*7c478bd9Sstevel@tonic-gate# Error message formatter:
86*7c478bd9Sstevel@tonic-gate#
87*7c478bd9Sstevel@tonic-gate# Invoke as
88*7c478bd9Sstevel@tonic-gate#
89*7c478bd9Sstevel@tonic-gate#       errmsg severity message-number problem help
90*7c478bd9Sstevel@tonic-gate#
91*7c478bd9Sstevel@tonic-gate# where severity is "ERROR" or "WARNING", message-number is
92*7c478bd9Sstevel@tonic-gate# a unique identifier, problem is a short description of the
93*7c478bd9Sstevel@tonic-gate# problem, and help is a short suggestion for fixing the problem.
94*7c478bd9Sstevel@tonic-gate#####
95*7c478bd9Sstevel@tonic-gate
96*7c478bd9Sstevel@tonic-gateLP_ERR_LABEL="UX:lp"
97*7c478bd9Sstevel@tonic-gateE_IP_ARGS=1
98*7c478bd9Sstevel@tonic-gateE_IP_OPTS=2
99*7c478bd9Sstevel@tonic-gate#E_IP_FILTER=3
100*7c478bd9Sstevel@tonic-gateE_IP_UNKNOWN=5
101*7c478bd9Sstevel@tonic-gateE_IP_BADFILE=6
102*7c478bd9Sstevel@tonic-gateE_IP_ERRORS=12 	# (in slow.filter)
103*7c478bd9Sstevel@tonic-gate
104*7c478bd9Sstevel@tonic-gateerrmsg () {
105*7c478bd9Sstevel@tonic-gate
106*7c478bd9Sstevel@tonic-gate        case $1 in
107*7c478bd9Sstevel@tonic-gate        ERROR )
108*7c478bd9Sstevel@tonic-gate                sev="  ERROR";
109*7c478bd9Sstevel@tonic-gate                ;;
110*7c478bd9Sstevel@tonic-gate        WARNING )
111*7c478bd9Sstevel@tonic-gate                sev="WARNING";
112*7c478bd9Sstevel@tonic-gate                ;;
113*7c478bd9Sstevel@tonic-gate        esac
114*7c478bd9Sstevel@tonic-gate
115*7c478bd9Sstevel@tonic-gate        echo "${LP_ERR_LABEL}:$2 ${sev}: $3
116*7c478bd9Sstevel@tonic-gate        TO FIX: $4" >&5
117*7c478bd9Sstevel@tonic-gate}
118*7c478bd9Sstevel@tonic-gate
119*7c478bd9Sstevel@tonic-gate###########
120*7c478bd9Sstevel@tonic-gate##
121*7c478bd9Sstevel@tonic-gate## Check arguments
122*7c478bd9Sstevel@tonic-gate###########
123*7c478bd9Sstevel@tonic-gate
124*7c478bd9Sstevel@tonic-gateparse () {
125*7c478bd9Sstevel@tonic-gate        echo "`expr \"$1\" : \"^[^=]*=\(.*\)\"`"
126*7c478bd9Sstevel@tonic-gate}
127*7c478bd9Sstevel@tonic-gate
128*7c478bd9Sstevel@tonic-gate#####
129*7c478bd9Sstevel@tonic-gate##
130*7c478bd9Sstevel@tonic-gate## Error Cleanup and Exit
131*7c478bd9Sstevel@tonic-gate##
132*7c478bd9Sstevel@tonic-gate#####
133*7c478bd9Sstevel@tonic-gate
134*7c478bd9Sstevel@tonic-gateexit_clean()
135*7c478bd9Sstevel@tonic-gate{
136*7c478bd9Sstevel@tonic-gate
137*7c478bd9Sstevel@tonic-gate	if [ -f "${LPTMPDIR}/pr_eexit_code.$$" ]
138*7c478bd9Sstevel@tonic-gate	then
139*7c478bd9Sstevel@tonic-gate		/bin/rm ${LPTMPDIR}/pr_eexit_code.$$
140*7c478bd9Sstevel@tonic-gate	fi
141*7c478bd9Sstevel@tonic-gate
142*7c478bd9Sstevel@tonic-gate	if [ -f "${LPTMPDIR}/small_banner.$$" ]
143*7c478bd9Sstevel@tonic-gate	then
144*7c478bd9Sstevel@tonic-gate		/bin/rm ${LPTMPDIR}/small_banner.$$
145*7c478bd9Sstevel@tonic-gate	fi
146*7c478bd9Sstevel@tonic-gate
147*7c478bd9Sstevel@tonic-gate	if [ -f "${tmpfile}" ]
148*7c478bd9Sstevel@tonic-gate	then
149*7c478bd9Sstevel@tonic-gate		/bin/rm "${tmpfile}"
150*7c478bd9Sstevel@tonic-gate	fi
151*7c478bd9Sstevel@tonic-gate
152*7c478bd9Sstevel@tonic-gate	exit $1
153*7c478bd9Sstevel@tonic-gate}
154*7c478bd9Sstevel@tonic-gate
155*7c478bd9Sstevel@tonic-gate#####
156*7c478bd9Sstevel@tonic-gate#
157*7c478bd9Sstevel@tonic-gate# This program is invoked as
158*7c478bd9Sstevel@tonic-gate#
159*7c478bd9Sstevel@tonic-gate# ${SPOOLDIR}/.../printer request-id user title copies options files...
160*7c478bd9Sstevel@tonic-gate#
161*7c478bd9Sstevel@tonic-gate# The first three arguments are simply reprinted on the banner page,
162*7c478bd9Sstevel@tonic-gate# the fourth (copies) is used to control the number of copies to print,
163*7c478bd9Sstevel@tonic-gate# the fifth (options) is a blank separated list (in a single argument)
164*7c478bd9Sstevel@tonic-gate# of user or Spooler supplied options (without the -o prefix),
165*7c478bd9Sstevel@tonic-gate# and the last arguments are the files to print.
166*7c478bd9Sstevel@tonic-gate#####
167*7c478bd9Sstevel@tonic-gate
168*7c478bd9Sstevel@tonic-gateif [ $# -lt 5 ]
169*7c478bd9Sstevel@tonic-gatethen
170*7c478bd9Sstevel@tonic-gate
171*7c478bd9Sstevel@tonic-gate        errmsg ERROR ${E_IP_ARGS} \
172*7c478bd9Sstevel@tonic-gate                "wrong number of arguments to interface program" \
173*7c478bd9Sstevel@tonic-gate                "consult your system administrator"
174*7c478bd9Sstevel@tonic-gate        exit 1
175*7c478bd9Sstevel@tonic-gatefi
176*7c478bd9Sstevel@tonic-gate
177*7c478bd9Sstevel@tonic-gateprinter=`basename $0`
178*7c478bd9Sstevel@tonic-gaterequest_id=$1
179*7c478bd9Sstevel@tonic-gateuser_name=$2
180*7c478bd9Sstevel@tonic-gatetitle=$3
181*7c478bd9Sstevel@tonic-gatecopies=$4
182*7c478bd9Sstevel@tonic-gateoption_list=$5
183*7c478bd9Sstevel@tonic-gate
184*7c478bd9Sstevel@tonic-gateshift 5
185*7c478bd9Sstevel@tonic-gatefiles="$*"
186*7c478bd9Sstevel@tonic-gate
187*7c478bd9Sstevel@tonic-gate
188*7c478bd9Sstevel@tonic-gate#
189*7c478bd9Sstevel@tonic-gate# debug sent to file if defined in /etc/syslog.conf
190*7c478bd9Sstevel@tonic-gate# syslog.conf entry:
191*7c478bd9Sstevel@tonic-gate#	lpr.debug	/path/filename
192*7c478bd9Sstevel@tonic-gate#
193*7c478bd9Sstevel@tonic-gatelogger -p lpr.debug -t "netstandard: ${request_id}" " "
194*7c478bd9Sstevel@tonic-gatelogger -p lpr.debug -t "netstandard: ${request_id}" "INPUT"
195*7c478bd9Sstevel@tonic-gatelogger -p lpr.debug -t "netstandard: ${request_id}" "    printer : ${printer}"
196*7c478bd9Sstevel@tonic-gatelogger -p lpr.debug -t "netstandard: ${request_id}" "    request_id : ${request_id}"
197*7c478bd9Sstevel@tonic-gatelogger -p lpr.debug -t "netstandard: ${request_id}" "    user_name : ${user_name}"
198*7c478bd9Sstevel@tonic-gatelogger -p lpr.debug -t "netstandard: ${request_id}" "    title : ${title}"
199*7c478bd9Sstevel@tonic-gatelogger -p lpr.debug -t "netstandard: ${request_id}" "    copies : ${copies}"
200*7c478bd9Sstevel@tonic-gatelogger -p lpr.debug -t "netstandard: ${request_id}" "    option_list : ${option_list}"
201*7c478bd9Sstevel@tonic-gatelogger -p lpr.debug -t "netstandard: ${request_id}" "    files : ${files}"
202*7c478bd9Sstevel@tonic-gatelogger -p lpr.debug -t "netstandard: ${request_id}" "	 spooler_key ${SPOOLER_KEY}"
203*7c478bd9Sstevel@tonic-gate
204*7c478bd9Sstevel@tonic-gate####
205*7c478bd9Sstevel@tonic-gate# default: do print a banner
206*7c478bd9Sstevel@tonic-gate####
207*7c478bd9Sstevel@tonic-gatenobanner=no
208*7c478bd9Sstevel@tonic-gatenofilebreak="no"
209*7c478bd9Sstevel@tonic-gateinlist=
210*7c478bd9Sstevel@tonic-gatedata_file_flag=
211*7c478bd9Sstevel@tonic-gate
212*7c478bd9Sstevel@tonic-gatefor i in ${option_list}
213*7c478bd9Sstevel@tonic-gatedo
214*7c478bd9Sstevel@tonic-gate        case "${inlist}${i}" in
215*7c478bd9Sstevel@tonic-gate
216*7c478bd9Sstevel@tonic-gate        nobanner )
217*7c478bd9Sstevel@tonic-gate                nobanner="yes"
218*7c478bd9Sstevel@tonic-gate                ;;
219*7c478bd9Sstevel@tonic-gate
220*7c478bd9Sstevel@tonic-gate        nofilebreak )
221*7c478bd9Sstevel@tonic-gate                nofilebreak="yes"
222*7c478bd9Sstevel@tonic-gate                ;;
223*7c478bd9Sstevel@tonic-gate
224*7c478bd9Sstevel@tonic-gate        #####
225*7c478bd9Sstevel@tonic-gate        #
226*7c478bd9Sstevel@tonic-gate        # If you want to add simple options (e.g. -o simple)
227*7c478bd9Sstevel@tonic-gate        # identify them here.
228*7c478bd9Sstevel@tonic-gate        #####
229*7c478bd9Sstevel@tonic-gate#       simple )
230*7c478bd9Sstevel@tonic-gate#               simple="yes"
231*7c478bd9Sstevel@tonic-gate# 		;;
232*7c478bd9Sstevel@tonic-gate
233*7c478bd9Sstevel@tonic-gate        cpi=pica )
234*7c478bd9Sstevel@tonic-gate                cpi=10
235*7c478bd9Sstevel@tonic-gate                ;;
236*7c478bd9Sstevel@tonic-gate        cpi=elite )
237*7c478bd9Sstevel@tonic-gate                cpi=12
238*7c478bd9Sstevel@tonic-gate                ;;
239*7c478bd9Sstevel@tonic-gate        cpi=* )
240*7c478bd9Sstevel@tonic-gate                cpi=`parse ${i}`
241*7c478bd9Sstevel@tonic-gate                ;;
242*7c478bd9Sstevel@tonic-gate
243*7c478bd9Sstevel@tonic-gate        lpi=* )
244*7c478bd9Sstevel@tonic-gate                lpi=`parse ${i}`
245*7c478bd9Sstevel@tonic-gate                ;;
246*7c478bd9Sstevel@tonic-gate
247*7c478bd9Sstevel@tonic-gate        length=* )
248*7c478bd9Sstevel@tonic-gate                length=`parse ${i}`
249*7c478bd9Sstevel@tonic-gate                ;;
250*7c478bd9Sstevel@tonic-gate
251*7c478bd9Sstevel@tonic-gate        width=* )
252*7c478bd9Sstevel@tonic-gate                width=`parse ${i}`
253*7c478bd9Sstevel@tonic-gate                ;;
254*7c478bd9Sstevel@tonic-gate        dest=* )
255*7c478bd9Sstevel@tonic-gate                dest="-d `parse ${i}`"
256*7c478bd9Sstevel@tonic-gate                ;;
257*7c478bd9Sstevel@tonic-gate
258*7c478bd9Sstevel@tonic-gate        protocol=* )
259*7c478bd9Sstevel@tonic-gate                protocol="-P `parse ${i}`"
260*7c478bd9Sstevel@tonic-gate                ;;
261*7c478bd9Sstevel@tonic-gate        bsdctrl=* )
262*7c478bd9Sstevel@tonic-gate		controlfile="-c `parse ${i}`"
263*7c478bd9Sstevel@tonic-gate                ;;
264*7c478bd9Sstevel@tonic-gate        timeout=* )
265*7c478bd9Sstevel@tonic-gate                timeout="-t `parse ${i}`"
266*7c478bd9Sstevel@tonic-gate                ;;
267*7c478bd9Sstevel@tonic-gate
268*7c478bd9Sstevel@tonic-gate        data-file-type=* )
269*7c478bd9Sstevel@tonic-gate                data_file_flag="-f `parse ${i}`"
270*7c478bd9Sstevel@tonic-gate                ;;
271*7c478bd9Sstevel@tonic-gate
272*7c478bd9Sstevel@tonic-gate        #####
273*7c478bd9Sstevel@tonic-gate        #
274*7c478bd9Sstevel@tonic-gate        # If you want to add simple-value options (e.g. -o value=a)
275*7c478bd9Sstevel@tonic-gate        # identify them here.
276*7c478bd9Sstevel@tonic-gate        #####
277*7c478bd9Sstevel@tonic-gate#       value=* )
278*7c478bd9Sstevel@tonic-gate#		value=`parse ${i}`
279*7c478bd9Sstevel@tonic-gate#		;;
280*7c478bd9Sstevel@tonic-gate
281*7c478bd9Sstevel@tonic-gate        #####
282*7c478bd9Sstevel@tonic-gate        #
283*7c478bd9Sstevel@tonic-gate        # If you want to add options that,
284*7c478bd9Sstevel@tonic-gate        # take a list (e.g. -o lopt='a b c'), identif
285*7c478bd9Sstevel@tonic-gate        # them here and below (look for LOPT).
286*7c478bd9Sstevel@tonic-gate        #####
287*7c478bd9Sstevel@tonic-gate
288*7c478bd9Sstevel@tonic-gate#	flist=* | lpd=* | options=* )
289*7c478bd9Sstevel@tonic-gate        flist=* | lpd=* )
290*7c478bd9Sstevel@tonic-gate#LOPT   stty=* | flist=* | lpd=* | lopt=* )
291*7c478bd9Sstevel@tonic-gate
292*7c478bd9Sstevel@tonic-gate                inlist=`expr "${inlist}${i}" : "^\([^=]*=\)"`
293*7c478bd9Sstevel@tonic-gate                case "${i}" in
294*7c478bd9Sstevel@tonic-gate                ${inlist}\'*\' )
295*7c478bd9Sstevel@tonic-gate                        item=`expr "${i}" : "^[^=]*='*\(.*\)'\$"`
296*7c478bd9Sstevel@tonic-gate                        ;;
297*7c478bd9Sstevel@tonic-gate                ${inlist}\' )
298*7c478bd9Sstevel@tonic-gate                        continue
299*7c478bd9Sstevel@tonic-gate                        ;;
300*7c478bd9Sstevel@tonic-gate                ${inlist}\'* )
301*7c478bd9Sstevel@tonic-gate                        item=`expr "${i}" : "^[^=]*='*\(.*\)\$"`
302*7c478bd9Sstevel@tonic-gate                        ;;
303*7c478bd9Sstevel@tonic-gate                ${inlist}* )
304*7c478bd9Sstevel@tonic-gate                        item=`expr "${i}" : "^[^=]*=\(.*\)\$"`
305*7c478bd9Sstevel@tonic-gate                        ;;
306*7c478bd9Sstevel@tonic-gate                *\' )
307*7c478bd9Sstevel@tonic-gate                        item=`expr "${i}" : "^\(.*\)'\$"`
308*7c478bd9Sstevel@tonic-gate                        ;;
309*7c478bd9Sstevel@tonic-gate                * )
310*7c478bd9Sstevel@tonic-gate                        item="${i}"
311*7c478bd9Sstevel@tonic-gate                        ;;
312*7c478bd9Sstevel@tonic-gate                esac
313*7c478bd9Sstevel@tonic-gate
314*7c478bd9Sstevel@tonic-gate                #####
315*7c478bd9Sstevel@tonic-gate                #
316*7c478bd9Sstevel@tonic-gate                # We don't dare use "eval" because a clever user could
317*7c478bd9Sstevel@tonic-gate                # put something in an option value that we'd end up
318*7c478bd9Sstevel@tonic-gate                # exec'ing.
319*7c478bd9Sstevel@tonic-gate                #####
320*7c478bd9Sstevel@tonic-gate                case "${inlist}" in
321*7c478bd9Sstevel@tonic-gate                flist= )
322*7c478bd9Sstevel@tonic-gate                        flist="${flist} ${item}"
323*7c478bd9Sstevel@tonic-gate                        ;;
324*7c478bd9Sstevel@tonic-gate                lpd= )
325*7c478bd9Sstevel@tonic-gate                        lpd="${lpd} ${item}"
326*7c478bd9Sstevel@tonic-gate                        ;;
327*7c478bd9Sstevel@tonic-gate#LOPT		lopt= )
328*7c478bd9Sstevel@tonic-gate#LOPT                   lopt="${lopt} ${item}"
329*7c478bd9Sstevel@tonic-gate#LOPT			;;
330*7c478bd9Sstevel@tonic-gate#		options= )
331*7c478bd9Sstevel@tonic-gate#			options="${options} ${item}"
332*7c478bd9Sstevel@tonic-gate#			;;
333*7c478bd9Sstevel@tonic-gate                esac
334*7c478bd9Sstevel@tonic-gate
335*7c478bd9Sstevel@tonic-gate                case "${i}" in
336*7c478bd9Sstevel@tonic-gate                ${inlist}\'*\' )
337*7c478bd9Sstevel@tonic-gate                        inlist=
338*7c478bd9Sstevel@tonic-gate                        ;;
339*7c478bd9Sstevel@tonic-gate                ${inlist}\'* )
340*7c478bd9Sstevel@tonic-gate                        ;;
341*7c478bd9Sstevel@tonic-gate                *\' | ${inlist}* )
342*7c478bd9Sstevel@tonic-gate                        inlist=
343*7c478bd9Sstevel@tonic-gate                        ;;
344*7c478bd9Sstevel@tonic-gate                esac
345*7c478bd9Sstevel@tonic-gate                ;;
346*7c478bd9Sstevel@tonic-gate
347*7c478bd9Sstevel@tonic-gate        * )
348*7c478bd9Sstevel@tonic-gate                errmsg WARNING ${E_IP_OPTS} \
349*7c478bd9Sstevel@tonic-gate                        "unrecognized \"-o ${i}\" option" \
350*7c478bd9Sstevel@tonic-gate                        "check the option, resubmit if necessary
351*7c478bd9Sstevel@tonic-gate                printing continues"
352*7c478bd9Sstevel@tonic-gate                ;;
353*7c478bd9Sstevel@tonic-gate        esac
354*7c478bd9Sstevel@tonic-gatedone
355*7c478bd9Sstevel@tonic-gate
356*7c478bd9Sstevel@tonic-gatelogger -p lpr.debug -t "netstandard: ${request_id}"  "term : ${TERM}"
357*7c478bd9Sstevel@tonic-gate
358*7c478bd9Sstevel@tonic-gateif [ -z "${FILTER}" ]
359*7c478bd9Sstevel@tonic-gatethen
360*7c478bd9Sstevel@tonic-gate        #####
361*7c478bd9Sstevel@tonic-gate        #
362*7c478bd9Sstevel@tonic-gate        # If no filter is being used, we use netpr to push the
363*7c478bd9Sstevel@tonic-gate	# file to the printer.
364*7c478bd9Sstevel@tonic-gate        # (QUOTES ARE IMPORTANT!)
365*7c478bd9Sstevel@tonic-gate        #####
366*7c478bd9Sstevel@tonic-gate
367*7c478bd9Sstevel@tonic-gate        case "$TERM" in
368*7c478bd9Sstevel@tonic-gate                PS )
369*7c478bd9Sstevel@tonic-gate                        # make the "postscript" printers use netpr
370*7c478bd9Sstevel@tonic-gate                        FILTER=
371*7c478bd9Sstevel@tonic-gate                ;;
372*7c478bd9Sstevel@tonic-gate                PSR )
373*7c478bd9Sstevel@tonic-gate                        # make the "reverse postscript" printers reverse the
374*7c478bd9Sstevel@tonic-gate                        # output and the use postio to talk to the printer
375*7c478bd9Sstevel@tonic-gate                        #FILTER="/usr/lib/lp/postscript/postreverse "
376*7c478bd9Sstevel@tonic-gate                        #FILTER=
377*7c478bd9Sstevel@tonic-gate                        FILTER="/usr/lib/lp/postscript/postreverse "
378*7c478bd9Sstevel@tonic-gate                ;;
379*7c478bd9Sstevel@tonic-gate                * )
380*7c478bd9Sstevel@tonic-gate                        # We don't know the type, so just assume that the
381*7c478bd9Sstevel@tonic-gate                        # input and output are the same. Use netpr.
382*7c478bd9Sstevel@tonic-gate                        #FILTER=/bin/cat
383*7c478bd9Sstevel@tonic-gate			FILTER=
384*7c478bd9Sstevel@tonic-gate                ;;
385*7c478bd9Sstevel@tonic-gate        esac
386*7c478bd9Sstevel@tonic-gatefi
387*7c478bd9Sstevel@tonic-gate
388*7c478bd9Sstevel@tonic-gate####
389*7c478bd9Sstevel@tonic-gate# sets default value for ordering of data and control files with
390*7c478bd9Sstevel@tonic-gate# bsd protocol. Default: data files first. Administrator
391*7c478bd9Sstevel@tonic-gate# may set to control file first with lpadmin -o bsdctrl=first
392*7c478bd9Sstevel@tonic-gate####
393*7c478bd9Sstevel@tonic-gate
394*7c478bd9Sstevel@tonic-gatebanner_flag=""
395*7c478bd9Sstevel@tonic-gatecase "${nobanner}" in
396*7c478bd9Sstevel@tonic-gate	yes )
397*7c478bd9Sstevel@tonic-gate		banner_flag="-b"
398*7c478bd9Sstevel@tonic-gate	;;
399*7c478bd9Sstevel@tonic-gateesac
400*7c478bd9Sstevel@tonic-gate
401*7c478bd9Sstevel@tonic-gateNETPR="/usr/lib/lp/bin/netpr ${banner_flag} ${data_file_flag} \
402*7c478bd9Sstevel@tonic-gate	-I ${request_id} -U ${user_name} \
403*7c478bd9Sstevel@tonic-gate	-p ${printer} ${dest} -T \"${title}\"  \
404*7c478bd9Sstevel@tonic-gate	${timeout}  ${protocol} ${controlfile} "
405*7c478bd9Sstevel@tonic-gateLPTELL_OPTS="-l"	# netpr sends LaserWriter style messages back
406*7c478bd9Sstevel@tonic-gate
407*7c478bd9Sstevel@tonic-gatelogger -p lpr.debug -t "netstandard: ${request_id}" "NETPR= ${NETPR}"
408*7c478bd9Sstevel@tonic-gatelogger -p lpr.debug -t "netstandard: ${request_id}" "filter : ${FILTER}"
409*7c478bd9Sstevel@tonic-gate
410*7c478bd9Sstevel@tonic-gatenode=`uname -n`
411*7c478bd9Sstevel@tonic-gatepid=$$
412*7c478bd9Sstevel@tonic-gatetmpfile=${LPTMPDIR}/${node}.${pid}
413*7c478bd9Sstevel@tonic-gate
414*7c478bd9Sstevel@tonic-gatelogger -p lpr.debug -t "netstandard: ${request_id}" "tmpfile : ${tmpfile}"
415*7c478bd9Sstevel@tonic-gate
416*7c478bd9Sstevel@tonic-gate#####
417*7c478bd9Sstevel@tonic-gate#
418*7c478bd9Sstevel@tonic-gate# Set up filter for banner page
419*7c478bd9Sstevel@tonic-gate#
420*7c478bd9Sstevel@tonic-gate#####
421*7c478bd9Sstevel@tonic-gatebanner_filter=
422*7c478bd9Sstevel@tonic-gatecase "${TERM}" in
423*7c478bd9Sstevel@tonic-gatePS | PSR )
424*7c478bd9Sstevel@tonic-gate	banner_filter=" | /usr/lib/lp/postscript/postprint "
425*7c478bd9Sstevel@tonic-gate	LPTELL_OPTS="-l"
426*7c478bd9Sstevel@tonic-gate	;;
427*7c478bd9Sstevel@tonic-gateesac
428*7c478bd9Sstevel@tonic-gate
429*7c478bd9Sstevel@tonic-gate#####
430*7c478bd9Sstevel@tonic-gate#
431*7c478bd9Sstevel@tonic-gate# Build temporary file that is the banner page
432*7c478bd9Sstevel@tonic-gate#
433*7c478bd9Sstevel@tonic-gate#####
434*7c478bd9Sstevel@tonic-gatePAD="#####${NL}"
435*7c478bd9Sstevel@tonic-gateCR="\r"
436*7c478bd9Sstevel@tonic-gateNL="${CR}\n"
437*7c478bd9Sstevel@tonic-gateFF=
438*7c478bd9Sstevel@tonic-gate
439*7c478bd9Sstevel@tonic-gatesmall_banner() {
440*7c478bd9Sstevel@tonic-gate        echo "${CR}\c"
441*7c478bd9Sstevel@tonic-gate        echo "${PAD}\c"
442*7c478bd9Sstevel@tonic-gate        echo "#####  User: ${user_name}${NL}\c"
443*7c478bd9Sstevel@tonic-gate        if [ -n "${title}" ]
444*7c478bd9Sstevel@tonic-gate        then
445*7c478bd9Sstevel@tonic-gate                echo "##### Title: ${title}${NL}\c"
446*7c478bd9Sstevel@tonic-gate        fi
447*7c478bd9Sstevel@tonic-gate        echo "#####  Date: `LANG=C date '+%a %H:%M %h %d, %Y'`${NL}\c"
448*7c478bd9Sstevel@tonic-gate        echo "#####   Job: ${request_id}${NL}\c"
449*7c478bd9Sstevel@tonic-gate        echo "${PAD}\c"
450*7c478bd9Sstevel@tonic-gate        if [ -n "${FF}" ]
451*7c478bd9Sstevel@tonic-gate        then
452*7c478bd9Sstevel@tonic-gate                echo "${CR}${FF}\c"
453*7c478bd9Sstevel@tonic-gate        fi
454*7c478bd9Sstevel@tonic-gate}
455*7c478bd9Sstevel@tonic-gate
456*7c478bd9Sstevel@tonic-gate#####
457*7c478bd9Sstevel@tonic-gate#
458*7c478bd9Sstevel@tonic-gate# Doing small banner as we don't know what printer is out there
459*7c478bd9Sstevel@tonic-gate#
460*7c478bd9Sstevel@tonic-gate#####
461*7c478bd9Sstevel@tonic-gatebanner=small_banner
462*7c478bd9Sstevel@tonic-gate
463*7c478bd9Sstevel@tonic-gateif [ "no" = "${nobanner}" ]
464*7c478bd9Sstevel@tonic-gatethen
465*7c478bd9Sstevel@tonic-gate	eval "${banner} ${banner_filter}" 2>&1 1>${LPTMPDIR}/small_banner.$$
466*7c478bd9Sstevel@tonic-gatefi
467*7c478bd9Sstevel@tonic-gate
468*7c478bd9Sstevel@tonic-gate#####
469*7c478bd9Sstevel@tonic-gate#
470*7c478bd9Sstevel@tonic-gate# Print banner page before job unless PSR
471*7c478bd9Sstevel@tonic-gate#
472*7c478bd9Sstevel@tonic-gate#####
473*7c478bd9Sstevel@tonic-gate
474*7c478bd9Sstevel@tonic-gate
475*7c478bd9Sstevel@tonic-gateif [ "no" = "${nobanner}" -a "${TERM}" != "PSR" ]
476*7c478bd9Sstevel@tonic-gatethen
477*7c478bd9Sstevel@tonic-gate	(
478*7c478bd9Sstevel@tonic-gate		eval ${NETPR} ${LPTMPDIR}/small_banner.$$ 2>&1
479*7c478bd9Sstevel@tonic-gate		echo $? > ${LPTMPDIR}/pr_eexit_code.$$
480*7c478bd9Sstevel@tonic-gate	) | ${LPTELL} ${LPTELL_OPTS} ${printer}
481*7c478bd9Sstevel@tonic-gate
482*7c478bd9Sstevel@tonic-gate	exit_code=`cat ${LPTMPDIR}/pr_eexit_code.$$`
483*7c478bd9Sstevel@tonic-gate	logger -p lpr.debug -t "netstandard: ${request_id}"	\
484*7c478bd9Sstevel@tonic-gate		"banner page exit code : ${exit_code}"
485*7c478bd9Sstevel@tonic-gate
486*7c478bd9Sstevel@tonic-gatefi
487*7c478bd9Sstevel@tonic-gate
488*7c478bd9Sstevel@tonic-gatei=1
489*7c478bd9Sstevel@tonic-gatewhile [ $i -le $copies ]
490*7c478bd9Sstevel@tonic-gatedo
491*7c478bd9Sstevel@tonic-gate        for file in ${files}
492*7c478bd9Sstevel@tonic-gate        do
493*7c478bd9Sstevel@tonic-gate                if [ -r "${file}" ]
494*7c478bd9Sstevel@tonic-gate                then
495*7c478bd9Sstevel@tonic-gate
496*7c478bd9Sstevel@tonic-gate			if [ ! -z "${FILTER}" ]
497*7c478bd9Sstevel@tonic-gate			then
498*7c478bd9Sstevel@tonic-gate 				(
499*7c478bd9Sstevel@tonic-gate					#####
500*7c478bd9Sstevel@tonic-gate					# There is a filter, use it
501*7c478bd9Sstevel@tonic-gate					#
502*7c478bd9Sstevel@tonic-gate					# Put 0<${file} before the "eval" to keep
503*7c478bd9Sstevel@tonic-gate					# clever users from giving a file name that
504*7c478bd9Sstevel@tonic-gate					# evaluates as something to execute.
505*7c478bd9Sstevel@tonic-gate					# Redirect stderr to stdout so LPTELL will
506*7c478bd9Sstevel@tonic-gate					# get error messages from pipe.
507*7c478bd9Sstevel@tonic-gate					#####
508*7c478bd9Sstevel@tonic-gate
509*7c478bd9Sstevel@tonic-gate					0<${file} eval ${FILTER} 2>&1 1>${tmpfile}
510*7c478bd9Sstevel@tonic-gate					echo $? > ${LPTMPDIR}/pr_eexit_code.$$
511*7c478bd9Sstevel@tonic-gate				) | ${LPTELL} ${LPTELL_OPTS} ${printer}
512*7c478bd9Sstevel@tonic-gate
513*7c478bd9Sstevel@tonic-gate				exit_code=`cat ${LPTMPDIR}/pr_eexit_code.$$`
514*7c478bd9Sstevel@tonic-gate				logger -p lpr.debug -t "netstandard: ${request_id}" \
515*7c478bd9Sstevel@tonic-gate					"filter exit_code : ${exit_code}"
516*7c478bd9Sstevel@tonic-gate
517*7c478bd9Sstevel@tonic-gate 			 	if [ -n "${exit_code}" ]
518*7c478bd9Sstevel@tonic-gate 				then
519*7c478bd9Sstevel@tonic-gate					if [ "${exit_code}" -eq 0 ]
520*7c478bd9Sstevel@tonic-gate					then
521*7c478bd9Sstevel@tonic-gate						printfile=${tmpfile}
522*7c478bd9Sstevel@tonic-gate					else
523*7c478bd9Sstevel@tonic-gate						####
524*7c478bd9Sstevel@tonic-gate						# The filter did not succeed, so don't try to print
525*7c478bd9Sstevel@tonic-gate						####
526*7c478bd9Sstevel@tonic-gate							printfile=
527*7c478bd9Sstevel@tonic-gate					fi
528*7c478bd9Sstevel@tonic-gate				fi
529*7c478bd9Sstevel@tonic-gate
530*7c478bd9Sstevel@tonic-gate			else
531*7c478bd9Sstevel@tonic-gate				printfile=${file}
532*7c478bd9Sstevel@tonic-gate			fi
533*7c478bd9Sstevel@tonic-gate
534*7c478bd9Sstevel@tonic-gate			logger -p lpr.debug -t "netstandard: ${request_id}" \
535*7c478bd9Sstevel@tonic-gate				"printfile : ${printfile}"
536*7c478bd9Sstevel@tonic-gate
537*7c478bd9Sstevel@tonic-gate			#####
538*7c478bd9Sstevel@tonic-gate			# Print the file
539*7c478bd9Sstevel@tonic-gate			#####
540*7c478bd9Sstevel@tonic-gate
541*7c478bd9Sstevel@tonic-gate			if [ -r "${printfile}" ]
542*7c478bd9Sstevel@tonic-gate			then
543*7c478bd9Sstevel@tonic-gate				(
544*7c478bd9Sstevel@tonic-gate					eval ${NETPR} ${printfile} 2>&1
545*7c478bd9Sstevel@tonic-gate					echo $? > ${LPTMPDIR}/pr_eexit_code.$$
546*7c478bd9Sstevel@tonic-gate				) | ${LPTELL} ${LPTELL_OPTS} ${printer}
547*7c478bd9Sstevel@tonic-gate
548*7c478bd9Sstevel@tonic-gate				exit_code=`cat ${LPTMPDIR}/pr_eexit_code.$$`
549*7c478bd9Sstevel@tonic-gate				logger -p lpr.debug -t "netstandard: ${request_id}" \
550*7c478bd9Sstevel@tonic-gate					"netpr exit_code : ${exit_code}"
551*7c478bd9Sstevel@tonic-gate
552*7c478bd9Sstevel@tonic-gate				if [ -f "${tmpfile}" ]
553*7c478bd9Sstevel@tonic-gate				then
554*7c478bd9Sstevel@tonic-gate					/bin/rm "${tmpfile}"
555*7c478bd9Sstevel@tonic-gate				fi
556*7c478bd9Sstevel@tonic-gate
557*7c478bd9Sstevel@tonic-gate				if [ -n "${exit_code}" ]
558*7c478bd9Sstevel@tonic-gate				then
559*7c478bd9Sstevel@tonic-gate					if [ "${exit_code}" -eq 0 ]
560*7c478bd9Sstevel@tonic-gate					then
561*7c478bd9Sstevel@tonic-gate						printone=yes
562*7c478bd9Sstevel@tonic-gate					else
563*7c478bd9Sstevel@tonic-gate						if [ "${exit_code}" -lt 128 ]
564*7c478bd9Sstevel@tonic-gate						then
565*7c478bd9Sstevel@tonic-gate							noprint=yes
566*7c478bd9Sstevel@tonic-gate						else
567*7c478bd9Sstevel@tonic-gate							retry=yes
568*7c478bd9Sstevel@tonic-gate						fi
569*7c478bd9Sstevel@tonic-gate					fi
570*7c478bd9Sstevel@tonic-gate				fi
571*7c478bd9Sstevel@tonic-gate
572*7c478bd9Sstevel@tonic-gate
573*7c478bd9Sstevel@tonic-gate			else
574*7c478bd9Sstevel@tonic-gate
575*7c478bd9Sstevel@tonic-gate				errmsg WARNING ${E_IP_BADFILE} \
576*7c478bd9Sstevel@tonic-gate				"cannot read temporary file \"${printfile}\""\
577*7c478bd9Sstevel@tonic-gate					"see if file still exists,
578*7c478bd9Sstevel@tonic-gate			or consult your system administrator;
579*7c478bd9Sstevel@tonic-gate			printing continues"
580*7c478bd9Sstevel@tonic-gate
581*7c478bd9Sstevel@tonic-gate			fi
582*7c478bd9Sstevel@tonic-gate		else
583*7c478bd9Sstevel@tonic-gate
584*7c478bd9Sstevel@tonic-gate                        #####
585*7c478bd9Sstevel@tonic-gate                        #
586*7c478bd9Sstevel@tonic-gate                        # Don't complain about not being able to read
587*7c478bd9Sstevel@tonic-gate                        # a file on second and subsequent copies, unless
588*7c478bd9Sstevel@tonic-gate                        # we've not complained yet. This removes repeated
589*7c478bd9Sstevel@tonic-gate                        # messages about the same file yet reduces the
590*7c478bd9Sstevel@tonic-gate                        # chance that the user can remove a file and not
591*7c478bd9Sstevel@tonic-gate                        # know that we had trouble finding it.
592*7c478bd9Sstevel@tonic-gate                        #####
593*7c478bd9Sstevel@tonic-gate
594*7c478bd9Sstevel@tonic-gate                        if [ "${i}" -le 1 -o -z "${badfileyet}" ]
595*7c478bd9Sstevel@tonic-gate                        then
596*7c478bd9Sstevel@tonic-gate                                errmsg WARNING ${E_IP_BADFILE} \
597*7c478bd9Sstevel@tonic-gate                                        "cannot read file \"${file}\"" \
598*7c478bd9Sstevel@tonic-gate                                        "see if the file still exists and is readable,
599*7c478bd9Sstevel@tonic-gate                or consult your system administrator;
600*7c478bd9Sstevel@tonic-gate                printing continues"
601*7c478bd9Sstevel@tonic-gate                                badfileyet=yes
602*7c478bd9Sstevel@tonic-gate                        fi
603*7c478bd9Sstevel@tonic-gate
604*7c478bd9Sstevel@tonic-gate		fi
605*7c478bd9Sstevel@tonic-gate
606*7c478bd9Sstevel@tonic-gate# for file in ${files}
607*7c478bd9Sstevel@tonic-gate	done
608*7c478bd9Sstevel@tonic-gate	i=`expr $i + 1`
609*7c478bd9Sstevel@tonic-gatedone
610*7c478bd9Sstevel@tonic-gate
611*7c478bd9Sstevel@tonic-gate#####
612*7c478bd9Sstevel@tonic-gate#
613*7c478bd9Sstevel@tonic-gate# If printing in reverse order, print the banner page now
614*7c478bd9Sstevel@tonic-gate#
615*7c478bd9Sstevel@tonic-gate#####
616*7c478bd9Sstevel@tonic-gate
617*7c478bd9Sstevel@tonic-gateif [ "no" = "${nobanner}" -a "${TERM}" = "PSR" ]
618*7c478bd9Sstevel@tonic-gatethen
619*7c478bd9Sstevel@tonic-gate(
620*7c478bd9Sstevel@tonic-gate	eval ${NETPR} ${LPTMPDIR}/small_banner.$$ 2>&1
621*7c478bd9Sstevel@tonic-gate	echo $? > ${LPTMPDIR}/pr_eexit_code.$$
622*7c478bd9Sstevel@tonic-gate) | ${LPTELL} ${LPTELL_OPTS} ${printer}
623*7c478bd9Sstevel@tonic-gatefi
624*7c478bd9Sstevel@tonic-gate
625*7c478bd9Sstevel@tonic-gateexit_code=`cat ${LPTMPDIR}/pr_eexit_code.$$`
626*7c478bd9Sstevel@tonic-gatelogger -p lpr.debug -t "netstandard: ${request_id}"     \
627*7c478bd9Sstevel@tonic-gate                "banner page exit code : ${exit_code}"
628*7c478bd9Sstevel@tonic-gate
629*7c478bd9Sstevel@tonic-gateif [ -n "${printone}" -a -z "${retry}" -a -z "${noprint}" ]
630*7c478bd9Sstevel@tonic-gatethen
631*7c478bd9Sstevel@tonic-gate       	exit_code=`expr 0`
632*7c478bd9Sstevel@tonic-gateelse
633*7c478bd9Sstevel@tonic-gate        if [ -n "${retry}" -a -z "${printone}" -a -z "${noprint}" ]
634*7c478bd9Sstevel@tonic-gate        then
635*7c478bd9Sstevel@tonic-gate                exit_code=`expr 129`
636*7c478bd9Sstevel@tonic-gate        else
637*7c478bd9Sstevel@tonic-gate		exit_code=`expr 1`
638*7c478bd9Sstevel@tonic-gate	fi
639*7c478bd9Sstevel@tonic-gatefi
640*7c478bd9Sstevel@tonic-gate
641*7c478bd9Sstevel@tonic-gatelogger -p lpr.debug -t "netstandard: ${request_id}" \
642*7c478bd9Sstevel@tonic-gate	"FINAL exit_code : ${exit_code}"
643*7c478bd9Sstevel@tonic-gate
644*7c478bd9Sstevel@tonic-gateexit_clean ${exit_code}
645