[Zodb-checkins] CVS: ZODB3/zdaemon - zdoptions.py:1.15 zdrun.py:1.12
Guido van Rossum
guido@python.org
Mon, 27 Jan 2003 10:13:22 -0500
Update of /cvs-repository/ZODB3/zdaemon
In directory cvs.zope.org:/tmp/cvs-serv11119/zdaemon
Modified Files:
zdoptions.py zdrun.py
Log Message:
Move user validity checking from zdrun to zdoptions.
Don't complain if you're already the requested user.
=== ZODB3/zdaemon/zdoptions.py 1.14 => 1.15 ===
--- ZODB3/zdaemon/zdoptions.py:1.14 Fri Jan 24 13:00:51 2003
+++ ZODB3/zdaemon/zdoptions.py Mon Jan 27 10:13:17 2003
@@ -279,6 +279,8 @@
class RunnerOptions(ZDOptions):
+ uid = gid = None
+
def __init__(self):
ZDOptions.__init__(self)
self.add("backofflimit", "runner.backoff_limit",
@@ -294,6 +296,29 @@
self.add("directory", "runner.directory", "z:", "directory=",
ZConfig.datatypes.existing_directory)
self.add("hang_around", "runner.hang_around", default=0)
+
+ def realize(self, *args, **kwds):
+ ZDOptions.realize(self, *args, **kwds)
+
+ # Additional checking of user option; set uid and gid
+ if self.user is not None:
+ import pwd
+ try:
+ uid = int(self.user)
+ except ValueError:
+ try:
+ pwrec = pwd.getpwnam(self.user)
+ except KeyError:
+ self.usage("username %r not found" % self.user)
+ uid = pwrec[2]
+ else:
+ try:
+ pwrec = pwd.getpwuid(uid)
+ except KeyError:
+ self.usage("uid %r not found" % self.user)
+ gid = pwrec[3]
+ self.uid = uid
+ self.gid = gid
# ZConfig datatype
=== ZODB3/zdaemon/zdrun.py 1.11 => 1.12 ===
--- ZODB3/zdaemon/zdrun.py:1.11 Fri Jan 24 08:04:08 2003
+++ ZODB3/zdaemon/zdrun.py Mon Jan 27 10:13:17 2003
@@ -218,29 +218,13 @@
self.run()
def set_uid(self):
- if self.options.user is None:
+ if self.options.uid is None:
return
- if os.name != "posix":
- self.options.usage("-u USER only supported on Unix")
- if os.geteuid() != 0:
- self.options.usage("only root can use -u USER")
- import pwd
- try:
- uid = int(self.options.user)
- except: # int() can raise all sorts of errors
- try:
- pwrec = pwd.getpwnam(self.options.user)
- except KeyError:
- self.options.usage("username %r not found" % self.options.user)
- uid = pwrec[2]
- else:
- try:
- pwrec = pwd.getpwuid(uid)
- except KeyError:
- self.options.usage("uid %r not found" % self.options.user)
- gid = pwrec[3]
- os.setgid(gid)
- os.setuid(uid)
+ uid = os.geteuid()
+ if uid != 0 and uid != self.options.uid:
+ self.options.usage("only root can use -u USER to change users")
+ os.setuid(self.options.uid)
+ os.setgid(self.options.gid)
def run(self):
self.proc = Subprocess(self.options)