Index: pykota/trunk/bin/pkinvoice
===================================================================
--- pykota/trunk/bin/pkinvoice (revision 3275)
+++ pykota/trunk/bin/pkinvoice (revision 3276)
@@ -198,5 +198,5 @@
                                         pageCompression=1)
         
-        c.setAuthor(self.originalUserName)
+        c.setAuthor(self.effectiveUserName)
         c.setTitle("PyKota invoices")
         c.setSubject("Invoices generated with PyKota")
Index: pykota/trunk/bin/pkprinters
===================================================================
--- pykota/trunk/bin/pkprinters (revision 3275)
+++ pykota/trunk/bin/pkprinters (revision 3276)
@@ -171,8 +171,6 @@
         if uri and (not self.isPrinterCaptured(deviceuri=uri)) :
              newuri = "cupspykota://%s" % uri
-             self.regainPriv() # to avoid having to enter password.
              os.system('lpadmin -p "%s" -v "%s"' % (printer.Name, newuri))
              self.logdebug("Printer %s rerouted to %s" % (printer.Name, newuri))
-             self.dropPriv()
              
     def deroutePrinterFromPyKota(self, printer) :    
@@ -183,8 +181,6 @@
              if newuri.startswith("//") :
                  newuri = newuri[2:]
-             self.regainPriv() # to avoid having to enter password.
              os.system('lpadmin -p "%s" -v "%s"' % (printer.Name, newuri))
              self.logdebug("Printer %s rerouted to %s" % (printer.Name, newuri))
-             self.dropPriv()    
                                      
     def main(self, names, options) :
Index: pykota/trunk/bin/cupspykota
===================================================================
--- pykota/trunk/bin/cupspykota (revision 3275)
+++ pykota/trunk/bin/cupspykota (revision 3276)
@@ -72,4 +72,5 @@
         signal.signal(signal.SIGTERM, signal.SIG_IGN)
         signal.signal(signal.SIGPIPE, signal.SIG_IGN)
+        self.oldSigIntHandler = signal.signal(signal.SIGINT, signal.SIG_IGN)
         self.MyName = "PyKota"
         self.myname = "cupspykota"
@@ -84,39 +85,10 @@
         if not self.config.isAdmin :
             from pykota import config
-            username = self.originalUserName
+            username = self.effectiveUserName
             raise config.PyKotaConfigError, _("User %(username)s is not allowed to read ~pykota/pykotadmin.conf, you must check the permissions.") % locals()
-        self.gotSigTerm = 0
-        self.disableSigInt()
-        self.installSigTermHandler()
-        
-    def sigtermHandler(self, signum, frame) :
-        """Sets an attribute whenever SIGTERM is received."""
-        self.gotSigTerm = 1
-        self.printInfo(_("SIGTERM received, job %s cancelled.") % self.Ticket.JobId)
-        os.environ["PYKOTASTATUS"] = "CANCELLED"
-        
-    def deinstallSigTermHandler(self) :           
-        """Deinstalls the SIGTERM handler."""
-        self.logdebug("Deinstalling SIGTERM handler...")
-        signal.signal(signal.SIGTERM, signal.SIG_IGN)
-        self.logdebug("SIGTERM handler deinstalled.")
-        
-    def installSigTermHandler(self) :           
-        """Installs the SIGTERM handler."""
-        self.logdebug("Installing SIGTERM handler...")
-        signal.signal(signal.SIGTERM, self.sigtermHandler)
-        self.logdebug("SIGTERM handler installed.")
-        
-    def disableSigInt(self) :    
-        """Disables the SIGINT signal (which raises KeyboardInterrupt)."""
-        self.logdebug("Disabling SIGINT...")
-        self.oldSigIntHandler = signal.signal(signal.SIGINT, signal.SIG_IGN)
-        self.logdebug("SIGINT disabled.")
         
     def enableSigInt(self) :    
         """Enables the SIGINT signal (which raises KeyboardInterrupt)."""
-        self.logdebug("Enabling SIGINT...")
         signal.signal(signal.SIGINT, self.oldSigIntHandler)
-        self.logdebug("SIGINT enabled.")
         
     def waitForLock(self) :    
@@ -153,8 +125,9 @@
            Executes each existing backend in turn in device enumeration mode.
            Returns the list of available backends.
+           
+           Unfortunately this method can't output any debug information
+           to stdout or stderr, else CUPS considers that the device is
+           not available.
         """
-        # Unfortunately this method can't output any debug information
-        # to stdout or stderr, else CUPS considers that the device is
-        # not available.
         available = []
         (directory, myname) = os.path.split(sys.argv[0])
@@ -226,4 +199,19 @@
         return available
                         
+    def checkCUPSVersion(self) :                    
+        """Checks if CUPS is not v1.3.4 or higher."""
+        fullversion = os.environ.get("SOFTWARE", "")
+        if fullversion.startswith("CUPS/") :
+            vnum = fullversion.split("/")[1]
+            try :
+               (major, minor, release) = [int(p) for p in vnum.split(".")]
+            except ValueError :   
+                pass
+            else :    
+                return (major > 1) \
+                        or ((major == 1) and (minor > 3)) \
+                        or ((major == 1) and (minor == 3) and (release >= 4))
+        return False
+        
     def initBackendParameters(self) :    
         """Initializes the backend's attributes."""
@@ -233,4 +221,7 @@
         # the environment before launching the real backend 
         self.logdebug("Initializing backend...")
+        
+        if not self.checkCUPSVersion() :
+            self.printInfo("BEWARE : CUPS is too old. You must use CUPS v1.3.4 or higher.", "error")
         
         self.PrinterName = os.environ.get("PRINTER", "")
@@ -410,5 +401,4 @@
             self.logdebug("Launching subprocess [%s] to overwrite the job ticket." \
                                      % jobticketcommand)
-            self.regainPriv()                         
             inputfile = os.popen(jobticketcommand, "r")
             try :
@@ -433,5 +423,4 @@
                 self.logdebug("IOError while reading subprocess' output : %s" % msg)
             inputfile.close()    
-            self.dropPriv()
             
             # now overwrite the job's ticket if new data was supplied
@@ -458,5 +447,4 @@
         outfile = open(self.DataFile, "wb")    
         if self.Ticket.FileName is not None :
-            self.regainPriv()
             infile = open(self.Ticket.FileName, "rb")
             self.logdebug("Reading input datas from %s" % self.Ticket.FileName)
@@ -481,5 +469,4 @@
         if mustclose :    
             infile.close()
-            self.dropPriv()
             
         outfile.close()
@@ -494,6 +481,4 @@
         """Cleans up the place."""
         self.logdebug("Cleaning up...")
-        self.regainPriv()
-        self.deinstallSigTermHandler()
         if (self.DataFile is not None) and os.path.exists(self.DataFile) :
             try :
@@ -933,7 +918,5 @@
             if mailto == "EXTERNAL" :
                 # TODO : clean this again
-                self.regainPriv()
                 self.externalMailTo(arguments, self.Action, self.User, self.Printer, self.Reason)
-                self.dropPriv()
             else :    
                 # TODO : clean this again
@@ -1114,15 +1097,12 @@
         else :
             self.printInfo(_("Job accounting begins."))
-            self.deinstallSigTermHandler()
             self.accounter.beginJob(self.Printer)
-            self.installSigTermHandler()
         
         # handle starting banner pages with accounting
         if (self.Action != "CANCEL") and accountbanner in ["STARTING", "BOTH"] :
-            if not self.gotSigTerm :
-                self.handleBanner("starting", 1)
-        
-        # pass the job's data to the real backend    
-        if (not self.gotSigTerm) and (self.Action in ["ALLOW", "WARN"]) :
+            self.handleBanner("starting", 1)
+        
+        # pass the job's data to the real backend if needed   
+        if self.Action in ("ALLOW", "WARN") :
             retcode = self.printJobDatas()
         else :        
@@ -1134,6 +1114,5 @@
         # handle ending banner pages with accounting
         if (self.Action != "CANCEL") and accountbanner in ["ENDING", "BOTH"] :
-            if not self.gotSigTerm :
-                self.handleBanner("ending", 1)
+            self.handleBanner("ending", 1)
         
         # stops accounting
@@ -1143,7 +1122,5 @@
             self.printInfo(_("Job cancelled, no accounting has been done."))
         else :
-            self.deinstallSigTermHandler()
             self.accounter.endJob(self.Printer)
-            self.installSigTermHandler()
             self.printInfo(_("Job accounting ends."))
         
@@ -1284,5 +1261,4 @@
         
         self.logdebug("Starting original backend %s with args %s" % (originalbackend, " ".join(['"%s"' % a for a in arguments])))
-        self.regainPriv()    
         pid = os.fork()
         self.logdebug("Forked !")
@@ -1298,8 +1274,7 @@
             self.logdebug("We shouldn't be there !!!")    
             os._exit(-1)
-        self.dropPriv()    
         
         self.logdebug("Waiting for original backend to exit...")    
-        killed = 0
+        killed = False
         status = -1
         while status == -1 :
@@ -1307,7 +1282,6 @@
                 status = os.waitpid(pid, 0)[1]
             except OSError, (err, msg) :
-                if (err == 4) and self.gotSigTerm :
-                    os.kill(pid, signal.SIGTERM)
-                    killed = 1
+                if err == 4 :
+                    killed = True
                     
         if os.WIFEXITED(status) :
@@ -1325,5 +1299,5 @@
             self.Reason = "CUPS backend %s died abnormally." % originalbackend
             self.printInfo(self.Reason, "error")
-            return -1
+            return 1
         else :
             self.Reason = "CUPS backend %s was killed." % originalbackend
Index: pykota/trunk/bin/pknotify
===================================================================
--- pykota/trunk/bin/pknotify (revision 3275)
+++ pykota/trunk/bin/pknotify (revision 3276)
@@ -180,5 +180,4 @@
             retcode = False
             self.password = password
-            self.regainPriv()
             auth = PAM.pam()
             auth.start("passwd")
@@ -195,5 +194,4 @@
                 self.logdebug(_("Password correct for user %s") % username)
                 retcode = True
-            self.dropPriv()    
             return retcode
             
Index: pykota/trunk/bin/pkrefund
===================================================================
--- pykota/trunk/bin/pkrefund (revision 3275)
+++ pykota/trunk/bin/pkrefund (revision 3276)
@@ -209,5 +209,5 @@
                                         pageCompression=1)
         
-        c.setAuthor(self.originalUserName)
+        c.setAuthor(self.effectiveUserName)
         c.setTitle("PyKota print job refunding receipts")
         c.setSubject("Print job refunding receipts generated with PyKota")
