Changeset 2006 for pykota/trunk
- Timestamp:
- 01/06/05 23:52:53 (20 years ago)
- Location:
- pykota/trunk
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/cupspykota
r1974 r2006 24 24 # 25 25 # $Log$ 26 # Revision 1.82 2005/01/06 22:52:53 jalet 27 # Implemented the dropping of priviledges. Beware, beware... 28 # 26 29 # Revision 1.81 2004/12/07 16:54:02 jalet 27 30 # Now logs as errors differences between computed and precomputed job's sizes … … 613 616 # Here we absolutely WANT to remove any filename from the command line ! 614 617 arguments = [ "Fake this because we are printing a banner" ] + sys.argv[1:6] 618 619 self.regainPriv() 620 615 621 self.logdebug("Starting real backend %s with args %s" % (realbackend, " ".join(['"%s"' % a for a in ([os.environ["DEVICE_URI"]] + arguments[1:])]))) 616 622 subprocess = PyKotaPopen4([realbackend] + arguments[1:], bufsize=0, arg0=os.environ["DEVICE_URI"]) … … 818 824 else : 819 825 retcode = self.removeJob() 826 827 self.dropPriv() 828 820 829 return retcode 821 830 -
pykota/trunk/NEWS
r2002 r2006 24 24 - 1.21alpha17 : 25 25 26 - Now drops priviledges to user 'pykota' when launched as root 27 (directly or as a CUPS backend), if such an user exists. 28 26 29 - Fixed PCL3/4/5 parser for some drivers' output. 27 30 -
pykota/trunk/pykota/tool.py
r1977 r2006 22 22 # 23 23 # $Log$ 24 # Revision 1.147 2005/01/06 22:52:53 jalet 25 # Implemented the dropping of priviledges. Beware, beware... 26 # 24 27 # Revision 1.146 2004/12/09 23:03:57 jalet 25 28 # Fixed a bug when pkbanner's output was piped into another command (e.g. gs) … … 575 578 def __init__(self, lang="", charset=None, doc="PyKota %s (c) 2003-2004 %s" % (version.__version__, version.__author__)) : 576 579 """Initializes the command line tool.""" 580 # did we drop priviledges ? 581 self.privdropped = 0 582 577 583 # locale stuff 578 584 defaultToCLocale = 0 … … 611 617 # try to find the configuration files in user's 'pykota' home directory. 612 618 try : 613 pykotauser = pwd.getpwnam("pykota")619 self.pykotauser = pwd.getpwnam("pykota") 614 620 except KeyError : 621 self.pykotauser = None 615 622 confdir = "/etc/pykota" 616 623 missingUser = 1 617 624 else : 618 confdir = pykotauser[5]625 confdir = self.pykotauser[5] 619 626 missingUser = 0 620 627 … … 635 642 raise 636 643 644 # now drop priviledge if possible 645 self.dropPriv() 646 637 647 # We NEED this here, even when not in an accounting filter/backend 638 648 self.softwareJobSize = 0 … … 647 657 arguments = " ".join(['"%s"' % arg for arg in sys.argv]) 648 658 self.logdebug("Command line arguments : %s" % arguments) 659 660 def dropPriv(self) : 661 """Drops priviledges.""" 662 uid = os.geteuid() 663 if uid : 664 try : 665 username = pwd.getpwuid(uid)[0] 666 except (KeyError, IndexError), msg : 667 self.printInfo(_("Strange problem with uid(%s) : %s") % (uid, msg), "warn") 668 else : 669 self.logdebug(_("Running as user '%s'.") % username) 670 else : 671 if self.pykotauser is None : 672 self.logdebug(_("No user named 'pykota'. Not dropping priviledges.")) 673 else : 674 try : 675 os.setegid(self.pykotauser[3]) 676 os.seteuid(self.pykotauser[2]) 677 except OSError, msg : 678 self.printInfo(_("Impossible to drop priviledges : %s") % msg, "warn") 679 else : 680 self.logdebug(_("Priviledges dropped. Now running as user 'pykota'.")) 681 self.privdropped = 1 682 683 def regainPriv(self) : 684 """Drops priviledges.""" 685 if self.privdropped : 686 try : 687 os.seteuid(0) 688 os.setegid(0) 689 except OSError, msg : 690 self.printInfo(_("Impossible to regain priviledges : %s") % msg, "warn") 691 else : 692 self.logdebug(_("Regained priviledges.")) 693 self.privdropped = 0 649 694 650 695 def getCharset(self) :