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