/usr/lib/printfilters/master-filter is in printfilters-ppd 2.13-11.1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | #!/bin/bash
#
#
# New smart print filter
#
#
# determines input file magic
#
# looks in the default filter plugin (FPI) directory
# finds all *.fpi files, then finds a combination that will
# yield the desired file type, or will indicate this is
# impossible.
#
if [ -f .debug ]; then
set -x
set -v
exec 2>log.filter
thetempfile=''
else
#added by A Mennucc: get errors
# and avoid using /tmp/evillog , which has /tmp security problem
# other scripts use 'mktemp', so I use it
thetempfile=`mktemp /tmp/master-filter.XXXXXX`
exec 2>$thetempfile
fi
function onexit () {
#added by A Mennucc1: more nicely treat unprintable files or any other error
if [ x"$thetempfile" != x -a -s "$thetempfile" ] ; then
#we are called by lpd? This is not a very robust way of detecting
# but overall this script works
JOBNAME=""
[ "$4" = "-n" -a "$6" = "-h" -a "$8" = -j ] && { USER="$5" ; JOBNAME="$9" ;}
[ "$USER" = "" ] && USER=`id -nu`
[ "$USER" ] && mail -s "error while running $0 to print $JOBNAME" "$USER" < $thetempfile
fi
[ x"$thetempfile" != x -a -r "$thetempfile" ] && rm "$thetempfile"
}
trap onexit 0
function filtfrom {
echo -ne ${1%-to-*}
}
function filtto {
echo -ne ${1#*-to-}
}
#
# given filters as input vars, find next level available given the
# first arg is the starting point
#
function nextlvl {
local try
local start
local all
local depth
#
#
# $1 is starting point, find something that will work
#
start="$1"
shift
depth="$1"
shift
all="$@"
#
# get out of here if too deep!
#
if [ $depth -ge $MAX_DEPTH ]; then
return 1
fi
if [ $DEBUG_TREE ]; then
echo "Starting point = $start" >> /tmp/filter.debug
fi
if [ $(filtto $start) = "$DESIRED_TO" ]; then
echo " DONE"
return 0
fi
while [ $1 ]; do
try=$1
shift
if [ $DEBUG_TREE ]; then
echo "for $start trying $try" >> /tmp/filter.debug
fi
if [ $(filtfrom $try) = $(filtto $start) ]; then
echo -n "$start.fpi:$depth:CONT "
#A Mennucc: quotes!
if [ $(filtto $try) = "$DESIRED_TO" ]; then
echo -n "$try.fpi:$((depth+1)):DONE "
return 0
else
# echo -n $try
nextlvl $try $((depth+1)) $all
# echo "|G is $G| "
if [ $DEBUG_TREE ]; then
echo "|rt is $?|" >> /tmp/filter.debug
fi
if [ "$?" = "0" ]
then
if [ $DEBUG_TREE ]; then
echo "for $start we are done" >> /tmp/filter.debug
fi
# return 0
else
if [ $DEBUG_TREE ]; then
echo "for $start we have failed" >> /tmp/filter.debug
fi
return 1
fi
fi
fi
# echo ""
done
}
#
# MAIN
#
#
#
#
# setup some global variables used by this script
#
#
#
# FPIDIR points to where print filter plug-ins are stored
# Normally these will be installed with a package via RPM
#
prefix=/usr
exec_prefix=${prefix}
datadir=${prefix}/share
pkgdatadir=${datadir}/printfilters
# A Mennucc : no this way is wrong, and doesnt work in Debian
# libexecdir=${exec_prefix}/libexec
libexecdir=${prefix}/lib/printfilters
FPIDIR=${prefix}/lib/printfilters
PATH=${FPIDIR}:${PATH}
export PATH
#
# MAX_DEPTH determines how long a string of filters will be
# tried as a possible printing solution. How many input
# formats will take 6 filters to output Postscript!
# Unlikely this will need to be changed.
#
MAX_DEPTH=6
#
# define these to gets lots of feedback
# output is appended on /tmp/filter.debug
#
DEBUG_TREE=""
DEBUG_FILTER=""
#
# Setup variables available to all filter plug-ins
#
#
#
# SPOOLDIR is directory which lpd is spooling from
#
export SPOOLDIR=$(pwd)
#
# Get queue specific information (which was written by printtool)
#
# find the name of the queue from the spool dir
eval `pcap -S $SPOOLDIR`
#
# Load general config options
#
if [ -f "${SPOOLDIR}/general.cfg" ];then
source ${SPOOLDIR}/general.cfg
else
eval `pcap -P$queue:DESIRED_TO` >> /dev/null
eval `pcap -P$queue:PAPERSIZE` >> /dev/null
eval `pcap -P$queue:PRINTER_TYPE` >> /dev/null
eval `pcap -P$queue:ASCII_TO_PS` >> /dev/null
fi
if [ "$DEBUG_FILTER" != "" ]; then
echo "Desired print format is $DESIRED_TO" >> /tmp/filter.debug
echo "Paper size is $PAPERSIZE" >> /tmp/filter.debug
echo -n "A form feed will " >> /tmp/filter.debug
if [ "$SEND_EOF" = "" ]; then
echo "not be sent." >> /tmp/filter.debug
else
echo "be sent." >> /tmp/filter.debug
fi
fi
cd $FPIDIR
fpis=$(ls *.fpi 2> /dev/null | tr '\n' ' ' | sed 's/\.fpi//g')
# RH 7.0 rhs-printfilter 1.81 Has this fragment of code. However,
# this will only work with LPRng not LPR and so we are commenting
# it out here. The point of the change seems to be to remove the
# need for rewindstdin. I don't know if this was due to some bug
# that they discovered or if it is just because the notion of
# using something like rewindstdin is really bizarre. Other effects of this change are marked with the comment RH70.
# -ben Dec 19 2000
#
# let's get the name of the data file, which we can examine
#
# export SPOOLFILE=$(printenv CONTROL | grep -E '(^c|^f|^g|^l|^n|^o|^p|^r|^t|^v|^d)' | sed 's/.//' | head -n 1 -)
# if [ -z "$SPOOLFILE" ] ; then
# printf "No spool file found.\014"
# exit 0
# else
# SPOOLFILE=${SPOOLDIR}/${SPOOLFILE}
# fi
#
# let's see if its a compressed file first
#
#
# Figure out the magic of the input file
#
magic=$(file -)
# RH70
# magic=$(file ${SPOOLFILE})
magic=${magic#*: }
case `echo $magic | tr 'A-Z' 'a-z'` in
# Not sure why RH removed *compress* here
*packed*|*gzip* )
${prefix}/lib/printfilters/rewindstdin # RH70 removed
DECOMPRESS="gzip -dc"
magic=$($DECOMPRESS - | file -)
magic=${magic#*: }
;;
*bzip2* )
DECOMPRESS="bzip2 -dc"
magic=$($DECOMPRESS ${SPOOLFILE} | file -)
magic=${magic#*: }
;;
* )
DECOMPRESS="";;
esac
${prefix}/lib/printfilters/rewindstdin # RH70 removed
magic=${magic#*: }
if [ "$DEBUG_FILTER" != "" ]; then
echo "Magic is |$magic|" >> /tmp/filter.debug
fi
case `echo $magic | tr 'A-Z' 'a-z'` in
*empty* )
exit;;
"pc bitmap data"* )
startpnt="INPUT-to-bmp";;
"gif image data"* )
startpnt="INPUT-to-gif";;
"jpeg image data"* )
startpnt="INPUT-to-jpeg";;
"tiff image data"* )
startpnt="INPUT-to-tiff";;
"sun raster image data"* )
startpnt="INPUT-to-rast";;
"pgm"*|"pbm"*|"ppm"* )
startpnt="INPUT-to-pnm";;
"png"* )
startpnt="INPUT-to-png";;
postscript* )
startpnt="INPUT-to-ps";;
"pdf"* )
startpnt="INPUT-to-pdf";;
"tex dvi file"* )
startpnt="INPUT-to-dvi";;
"fig image text"* )
startpnt="INPUT-to-fig";;
# troff is safe again with groff-1.11a or later we hope
"troff or preprocessor"* )
startpnt="INPUT-to-troff";;
"rpm"* )
startpnt="INPUT-to-rpm";;
*ascii*|*text*|*english*|*script* )
startpnt="INPUT-to-asc";;
*data*|*escape* )
startpnt="INPUT-to-prdata";;
*pcl* )
startpnt="INPUT-to-prdata";;
* )
startpnt="INPUT-to-unknown";;
esac
#
# here is where we could put in hook to call user routine(s) to
# handle extra magics they've defined filters for
#
# call_user_magic_hook()
#
if [ "$DEBUG_FILTER" != "" ]; then
echo "Type of file is $startpnt" >> /tmp/filter.debug
fi
if [ "$startpnt" = "Dont know" ]; then
echo "Error - input file type is unknown - cannot print" 1>&2
exit 1
fi
#
# catch some easy cases without having to figure out best path the hard way
#
bestpath=""
foundbest="NO"
if [ $(filtto $startpnt) = "asc" ]; then
if [ "$ASCII_TO_PS" = "NO" ]; then
bestpath="$startpnt | asc-to-printer.fpi"
foundbest="YES"
fi
elif [ $(filtto $startpnt) = "prdata" ]; then
bestpath="$startpnt | cat -"
foundbest="YES"
#A Mennucc: quotes by Andreas Mohr <a.mohr@mailto.de>
elif [ $(filtto $startpnt) = "$DESIRED_TO" ]; then
bestpath="$startpnt | $DESIRED_TO-to-printer.fpi"
foundbest="YES"
#A Mennucc: shortcut for pdf on non-PostScript printers, which use gs anyway
# elif [ $(filtto $startpnt) = "pdf" ]; then
# if [ -f "${SPOOLDIR}/postscript.cfg" ]; then
# source ${SPOOLDIR}/postscript.cfg
# else
# eval `pcap -P$queue:GSDEVICE` >> /dev/null
# fi
# #gs needs a file to treat pdf
# t=`mktemp /tmp/master-filter-pdf.XXXXXX`
# if [ "$GSDEVICE" != "POSTSCRIPT" ]; then
# bestpath="$startpnt | { cat > $t ; ps-to-printer.fpi --inputfile $t ; rm $t ; }"
# foundbest="YES"
# fi
fi
if [ "$foundbest" != "YES" ]; then
#
# we go through and find best path
#
G=`nextlvl "$startpnt" "0" $fpis`
if [ "$DEBUG_FILTER" != "" ]; then
echo "$G" >> /tmp/filter.debug
fi
#
# now sort out the best path of all available
#
#
# if no processing required, depth will equal 'DONE'
#
if [ "${G# *}" != "DONE" ]; then
root=""
bestdepth=$((MAX_DEPTH*2))
bestpath=""
curdepth="0"
depth="0"
foundbest="NO"
for i in $G; do
entry=${i%%:*}
depth=${i#*:}
depth=${depth%:*}
if [ $depth -le $curdepth ]; then
while [ $(($depth <= $curdepth && $curdepth >= 0)) -eq 1 ]; do
root=${root%* | *}
curdepth=$(($curdepth - 1))
done
fi
if [ $(($curdepth < 0)) -eq 1 ]; then
root=""
fi
curdepth=$depth
if [ "$root" = "" ]; then
root="$entry"
else
root="$root | $entry"
fi
if [ ${i##*:} = "DONE" ]; then
if [ "$DEBUG_FILTER" != "" ]; then
echo "$root -> depth = $depth" >> /tmp/filter.debug
fi
if [ $depth -lt $bestdepth ]; then
foundbest="YES"
bestdepth=$depth
bestpath=$root
fi
fi
done
fi
if [ "$foundbest" = "YES" ]; then
bestpath="$bestpath | $DESIRED_TO-to-printer.fpi"
fi
#
# end of doing it the hard way
#
fi
#
# we have to add filter to convert desired format to something the
# printer can handle. May be as simple as 'cat'
#
#
# ok we got here, and if input data magic is 'data' we'll let it
# through, hoping it really will work on the printer!
# Note we still reject lots of magics, like ELF, by doing this
# which is what we want
#
#
# getting bad, but trapping all "special" cases here
#
#
if [ "$foundbest" = "NO" ]; then
#A.Mennucc: I would not rely on 'printf' to be always available
echo "No way to print this type of input file: $magic" 1>&2
exit 0
else
#
# fix up the best path so we can run it
#
if [ "$DECOMPRESS" = "" ]; then
bestpath="cat - ${bestpath#* }"
else
bestpath="$DECOMPRESS ${bestpath#* }"
fi
fi
#
# any post-filter to run (like smbclient?)
#
if [ "$PRINTER_TYPE" = "SMB" ]; then
bestpath="$bestpath | ${FPIDIR}/smbprint ${SPOOLDIR}/acct"
elif [ "$PRINTER_TYPE" = "NCP" ]; then
bestpath="$bestpath | ${FPIDIR}/ncpprint ${SPOOLDIR}/acct"
elif [ "$PRINTER_TYPE" = "DIRECT" ]; then
bestpath="$bestpath | ${FPIDIR}/directprint ${SPOOLDIR}/acct"
elif [ "$PRINTER_TYPE" = "ATALK" ]; then
PNAME="`cat ${SPOOLDIR}/.paprc`"
bestpath="$bestpath | /usr/bin/pap -p $PNAME"
fi
if [ "$DEBUG_FILTER" != "" ]; then
echo "Best path of depth $bestdepth is $bestpath" >> /tmp/filter.debug
fi
#
# run the command!
#
# A Mennucc: THIS IS VERY BAD FOR SECURITY!!!!!!
# eval $bestpath 2> /tmp/evillog
# instead stderr have already been redirected to $thetempfile
eval $bestpath
#
#
#
# see if we need to send a form feed to eject the page from printer
#
# if [ "$SEND_EOF" != "" ]; then
# printf "\014"
# fi
exit 0
|