#!/usr/bin/perl
#^^^^^^^^^^^^^^^^^^^^ Update pathname appropriately to where you have Perl installed
# And update the path below of the configuration file as appropriate.
$suid_ph = "/var/www/html/LPRng/admin/cgi-bin/suid.ph";

#-------------- Should be fairly boilerplate from here on out --------------
# lprm_suid - a setUID script to allow httpd to lprm selected jobs
# This script would be setUID root and in a directory readable by httpd ONLY
# and protected via a .htaccess file
# Copyright 1997, 1998, 1999, 2000 by Alek Komarnitsky, alek@komar.org, http://www.komar.org/
# Use and distribution of this software is covered by the GNU GPL license.  
# Please see the LICENSE file and http://www.gnu.org/

# Grab stuff from suid.ph ...
if ( -r "$suid_ph" ) { 
   require "$suid_ph";
} else {
   print "could not open $suid_ph - serious error ... \n";
   exit(2);
}


if ($#ARGV != 4) {
   print ("Usage: lprm_suid adminmode browserhost queuename printserver jobnumber\n");
   exit(1);
}

# LPRng requires setting UID to EUID ...
$< = $>; 

$ARGV[0] =~ /^(\S+)$/;
$_ = $1;              # Not tainted
$adminmode = sanitize($_); 
$adminmode = nobody if ($adminmode eq 0 ) ; 
$ARGV[1] =~ /^(\S+)$/;
$_ = $1;              # Not tainted
$browserhost = sanitize($_); 
$ARGV[2] =~ /^(\S+)$/;
$_ = $1;
$queuename = sanitize($_); 
$ARGV[3] =~ /^(\S+)$/;
$_ = $1;
$printserver = sanitize($_); 
$ARGV[4] =~ /^(\S+)$/;
$_ = $1;
$jobnumber = sanitize($_); 


if ( $printserver =~ /unix/ ) {
   $command = "$lprm -P$queuename $jobnumber";
} else {
   $< = "$lprng_uid";
   if ($jobnumber eq "all") { 
      $command = "rsh $printserver \"$nt_lpc $queuename /PG\"";
   } else {
      $command = "rsh $printserver \"$nt_lpc $queuename /JK$jobnumber\"" ;
   }
}

$_ = `$command`;
print "$_"; 

&openlog("lprm_suid","cons,pid","local2");
&syslog('info',"lprm -P$queuename $jobnumber from browserhost $browserhost by $adminmode");
&closelog();
exit(); 
