home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3522 < prev    next >
Encoding:
Internet Message Format  |  1991-06-23  |  5.2 KB

  1. From: darcy@druid.uucp (D'Arcy J.M. Cain)
  2. Newsgroups: alt.sources
  3. Subject: rprint - print on remote systems via UUCP
  4. Message-ID: <1991Jun21.174518.6621@druid.uucp>
  5. Date: 21 Jun 91 17:45:18 GMT
  6. >from: darcy@druid.uucp (D'Arcy J.M. Cain)
  7.  
  8. As promised here is the remote printer that Greg Woods and I have put
  9. together.  This is basically a System V utility as it is in the form
  10. of a model file that is installed by lpadmin(1M).
  11.  
  12. ------------------------- start  of rprint.sh -----------------------------
  13. #!/bin/sh
  14. #
  15. #    rprint.sh - transparent lp interface for a remote printer with compress
  16. #
  17. # Author: Greg A. Woods <woods@eci386>, <woods@robohack>
  18. # Mods:   D'Arcy J.M. Cain <darcy@druid.UUCP>
  19.  
  20. # This is a printer "model" file.  Copy it into /usr/spool/lp/model and
  21. # use lpadmin to install it.  Use /dev/null as the device.  You will
  22. # have to install this once for every remote printer you want.
  23.  
  24. PATH=/bin:/usr/bin:/usr/lbin:/usr/local/bin ; export PATH
  25.  
  26. PRINTER=`basename $0`
  27. ID=$1
  28. USER=$2
  29. TITLE=$3
  30. COPIES=$4
  31. OPTIONS=$5
  32. #
  33. # NOTE, some lp's (notably the one on 3B1's) have 6 options
  34. #
  35. shift; shift; shift; shift; shift
  36. files="$@"
  37.  
  38. # remote_mach contains a list of printers (as per the lp configuration)
  39. # with the remote machine and the printer name on the remote machine.
  40. # If the last entry is missing then the default printer on the remote
  41. # system is used instead.
  42. #
  43. # Sample remote_mach file:
  44. # |   |-----------------------------------------------------------|   |
  45. # | o | # List of remote printers                                 | o |
  46. # |   |                                                           |   |
  47. # | o | # printer bill is on system saint at Bill Jones' desk     | o |
  48. # |   | bill saint lpr5                                           |   |
  49. # | o |                                                           | o |
  50. # |   | # we also want to print on saint's default printer        |   |
  51. # | o | saint saint                                               | o |
  52. # |   |                                                           |   |
  53. # | o | # the next one is for the laser on system foo             | o |
  54. # |   | foo-l foo laser                                           |   |
  55. # | o |-----------------------------------------------------------| o |
  56. #
  57. # mktable is in /usr/lbin on most SysV's, and strips comments and blank
  58. # lines while concatenating it's input.
  59. #
  60. MACHINE=`mktable /usr/spool/lp/remote_mach | awk '$1~/^'$PRINTER'$/ {
  61.     if (NF == 1) { print "ERROR" }
  62.     else { print $2 }
  63. }'`
  64.  
  65. if [ -z "$MACHINE" ]
  66. then
  67.     MACHINE=NOTFOUND
  68. fi
  69.  
  70. RPRINTER=`mktable /usr/spool/lp/remote_mach | awk '$1~/^'$PRINTER'$/ {
  71.     if (NF > 2) { printf "-d%s", $3 }}'`
  72.  
  73. # Logging - don't bother recording remote printer name
  74. #
  75. # echo "`date +%D-%T`:$PRINTER:$MACHINE:$RAW:-t$TITLE:-o$OPTIONS:-n$COPIES:$files" >> /usr/spool/lp/remlog
  76.  
  77. # NOTE: uux "sees" single quotes.  You must not put them anywhere where
  78. # white space is not allowed (i.e. -t'$TITLE'), as uux will introduce
  79. # a space before the first single quote, and after the ending single
  80. # quote, if there is not already whitespace in these places.
  81. #
  82. # Note also the use of '-C' and '-c' to ensure the data makes the hop!
  83. #
  84. # This version requires "COMMANDS=[...:]lp:uncompress" in the remote
  85. # Permissions file.
  86. #                    *** NOTE SECURITY ISSUE *** 
  87. # One security issue of note is that if you give remote 'lp' execute
  88. # permission, or worse yet remote 'uncompress' or 'zcat' execute
  89. # permission, you can't very easily prevent the remote user from
  90. # exploiting *any* of your printers, except through obscurity (i.e.
  91. # don't let the remote user login and run lpstat or look in
  92. # /usr/spool/lp!).  You may be able to hack this to fix this.  In
  93. # the environment I was using it this wasn't a problem.  I preferred
  94. # this method since it didn't require any special programs on the
  95. # remote site.
  96.  
  97. for F in $files ; do
  98.     FZ=/tmp/`basename $F`.Z
  99.  
  100. # D'Arcy J.M. Cain <darcy@druid.UUCP> added the following code to check
  101. # for compressed files and compress them if they weren't already so.  The
  102. # file is always compressed before sending.
  103.  
  104. # The following test requires that file(1) recognize a compressed file.
  105. # I had to add a line to /etc/magic to allow it to do this.  The -i
  106. # option to grep is to allow some flexibility if you already have a
  107. # line in /etc/magic and it uses different case.  I assume that it will
  108. # have the word compress somewhere in the line at least.
  109.  
  110. # BTW: the first 2 bytes in a compressed file are 0x1f and 0x9d.  How
  111. # you read this depends on the endianness of your processor but the
  112. # following lines works on my 386 with Esix.
  113. #    "0   short   0x9d1f     Compressed file"
  114.     if [ -z "`file $F | grep -i compress`" ]
  115.     then
  116.         compress < $F > $FZ
  117.     else
  118.         cp $F $FZ
  119.     fi
  120.  
  121.     uux -C "$MACHINE!uncompress < !$FZ | lp -c $RPRINTER '-t$TITLE' '-o$OPTIONS' -n$COPIES"
  122.     rm -f $FZ
  123. done
  124.  
  125. ret=$?
  126. if [ "$ret" -ne 0 ]
  127.     then disable -r "uux -n -C \"$MACHINE!lp [...] \" failed." $PRINTER
  128. fi
  129.  
  130. # I'm not sure if lp will see this, but we've already disabled the printer
  131. #
  132. exit $ret
  133. ----------------------------------------------------------------------------
  134.  
  135. -- 
  136. D'Arcy J.M. Cain (darcy@druid)     |
  137. D'Arcy Cain Consulting             |   There's no government
  138. Toronto, Ontario, Canada           |   like no government!
  139. +1 416 424 2871                    |
  140.