Newsgroups: alt.sources Path: utzoo!telly!druid!darcy From: darcy@druid.uucp (D'Arcy J.M. Cain) Subject: rprint - print on remote systems via UUCP Message-ID: <1991Jun21.174518.6621@druid.uucp> >from: darcy@druid.uucp (D'Arcy J.M. Cain) Organization: D'Arcy Cain Consulting, West Hill, Ontario Date: Fri, 21 Jun 91 17:45:18 GMT As promised here is the remote printer that Greg Woods and I have put together. This is basically a System V utility as it is in the form of a model file that is installed by lpadmin(1M). ------------------------- start of rprint.sh ----------------------------- #!/bin/sh # # rprint.sh - transparent lp interface for a remote printer with compress # # Author: Greg A. Woods , # Mods: D'Arcy J.M. Cain # This is a printer "model" file. Copy it into /usr/spool/lp/model and # use lpadmin to install it. Use /dev/null as the device. You will # have to install this once for every remote printer you want. PATH=/bin:/usr/bin:/usr/lbin:/usr/local/bin ; export PATH PRINTER=`basename $0` ID=$1 USER=$2 TITLE=$3 COPIES=$4 OPTIONS=$5 # # NOTE, some lp's (notably the one on 3B1's) have 6 options # shift; shift; shift; shift; shift files="$@" # remote_mach contains a list of printers (as per the lp configuration) # with the remote machine and the printer name on the remote machine. # If the last entry is missing then the default printer on the remote # system is used instead. # # Sample remote_mach file: # | |-----------------------------------------------------------| | # | o | # List of remote printers | o | # | | | | # | o | # printer bill is on system saint at Bill Jones' desk | o | # | | bill saint lpr5 | | # | o | | o | # | | # we also want to print on saint's default printer | | # | o | saint saint | o | # | | | | # | o | # the next one is for the laser on system foo | o | # | | foo-l foo laser | | # | o |-----------------------------------------------------------| o | # # mktable is in /usr/lbin on most SysV's, and strips comments and blank # lines while concatenating it's input. # MACHINE=`mktable /usr/spool/lp/remote_mach | awk '$1~/^'$PRINTER'$/ { if (NF == 1) { print "ERROR" } else { print $2 } }'` if [ -z "$MACHINE" ] then MACHINE=NOTFOUND fi RPRINTER=`mktable /usr/spool/lp/remote_mach | awk '$1~/^'$PRINTER'$/ { if (NF > 2) { printf "-d%s", $3 }}'` # Logging - don't bother recording remote printer name # # echo "`date +%D-%T`:$PRINTER:$MACHINE:$RAW:-t$TITLE:-o$OPTIONS:-n$COPIES:$files" >> /usr/spool/lp/remlog # NOTE: uux "sees" single quotes. You must not put them anywhere where # white space is not allowed (i.e. -t'$TITLE'), as uux will introduce # a space before the first single quote, and after the ending single # quote, if there is not already whitespace in these places. # # Note also the use of '-C' and '-c' to ensure the data makes the hop! # # This version requires "COMMANDS=[...:]lp:uncompress" in the remote # Permissions file. # *** NOTE SECURITY ISSUE *** # One security issue of note is that if you give remote 'lp' execute # permission, or worse yet remote 'uncompress' or 'zcat' execute # permission, you can't very easily prevent the remote user from # exploiting *any* of your printers, except through obscurity (i.e. # don't let the remote user login and run lpstat or look in # /usr/spool/lp!). You may be able to hack this to fix this. In # the environment I was using it this wasn't a problem. I preferred # this method since it didn't require any special programs on the # remote site. for F in $files ; do FZ=/tmp/`basename $F`.Z # D'Arcy J.M. Cain added the following code to check # for compressed files and compress them if they weren't already so. The # file is always compressed before sending. # The following test requires that file(1) recognize a compressed file. # I had to add a line to /etc/magic to allow it to do this. The -i # option to grep is to allow some flexibility if you already have a # line in /etc/magic and it uses different case. I assume that it will # have the word compress somewhere in the line at least. # BTW: the first 2 bytes in a compressed file are 0x1f and 0x9d. How # you read this depends on the endianness of your processor but the # following lines works on my 386 with Esix. # "0 short 0x9d1f Compressed file" if [ -z "`file $F | grep -i compress`" ] then compress < $F > $FZ else cp $F $FZ fi uux -C "$MACHINE!uncompress < !$FZ | lp -c $RPRINTER '-t$TITLE' '-o$OPTIONS' -n$COPIES" rm -f $FZ done ret=$? if [ "$ret" -ne 0 ] then disable -r "uux -n -C \"$MACHINE!lp [...] \" failed." $PRINTER fi # I'm not sure if lp will see this, but we've already disabled the printer # exit $ret ---------------------------------------------------------------------------- -- D'Arcy J.M. Cain (darcy@druid) | D'Arcy Cain Consulting | There's no government Toronto, Ontario, Canada | like no government! +1 416 424 2871 |