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