[Zope-dev] ZopeHTTPServer patch for userid
Christopher Petrilli
petrilli@amber.org
Wed, 24 Mar 1999 16:41:30 -0500
--Qxx1br4bt0+wmkIi
Content-Type: text/plain; charset=us-ascii
Gang,
I was bored, annoyed with this silly being forced to run something as
nobody (since I'm using ZopeHTTPServer), and since it's a trivial fix,
attached is a patch that behaves the same by default, but adds a command
line option to ZopeHTTPServer which lets you specify the userid tor un
as (obviously you must be able to change your userid)... it's still
defaults to nobody.
The option is.... </drumroll> -u ;-)
You can also find the patch verbatim on the web:
http://www.amber.org/petrilli/Technical/Python/Zope/ZopeHTTPServer.py.patch
Have fun... bitch at me ;-)
CHris
--
| Christopher Petrilli ``Television is bubble-gum for
| petrilli@amber.org the mind.''-Frank Lloyd Wright
--Qxx1br4bt0+wmkIi
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="ZopeHTTPServer.py.patch"
*** ZopeHTTPServer.py.~1~ Mon Feb 22 17:10:49 1999
--- ZopeHTTPServer.py Wed Mar 24 16:34:58 1999
***************
*** 399,413 ****
pass
! def try_to_become_nobody():
! # from CGIHTTPServer
try: import pwd
except: return
try:
! nobody = pwd.getpwnam('nobody')[2]
except pwd.error:
! nobody = 1 + max(map(lambda x: x[2], pwd.getpwall()))
! try: os.setuid(nobody)
except os.error: pass
def set_published_module(file,klass,env=None):
--- 399,413 ----
pass
! def try_to_become_somebody(uid='nobody'):
! # from CGIHTTPServer, modified to be more abstract
try: import pwd
except: return
try:
! whoami = pwd.getpwnam(uid)[2]
except pwd.error:
! whoami = 1 + max(map(lambda x: x[2], pwd.getpwall()))
! try: os.setuid(whoami)
except os.error: pass
def set_published_module(file,klass,env=None):
***************
*** 432,438 ****
__import__(name) # to catch problem modules right away
print "Publishing module %s" % name
! def start(module_file, host='', port=8080, threading=None,env=None):
set_published_module(module_file,BoboRequestHandler,env)
server_address = (host, port)
if threading:
--- 432,438 ----
__import__(name) # to catch problem modules right away
print "Publishing module %s" % name
! def start(module_file, host='', port=8080, threading=None,env=None,uid="nobody"):
set_published_module(module_file,BoboRequestHandler,env)
server_address = (host, port)
if threading:
***************
*** 448,454 ****
httpd = NonThreadingHTTPServer(server_address,
BoboRequestHandler)
print "Serving HTTP on port", port, "..."
! try_to_become_nobody()
try:
httpd.serve_forever()
except:
--- 448,454 ----
httpd = NonThreadingHTTPServer(server_address,
BoboRequestHandler)
print "Serving HTTP on port", port, "..."
! try_to_become_somebody(uid)
try:
httpd.serve_forever()
except:
***************
*** 463,469 ****
def main(args=None):
args=args or sys.argv[1:]
import getopt
! optlist, args=getopt.getopt(args,"tp:h:P:s:")
if len(args) < 1: die()
env={}
--- 463,469 ----
def main(args=None):
args=args or sys.argv[1:]
import getopt
! optlist, args=getopt.getopt(args,"tp:h:P:s:u:")
if len(args) < 1: die()
env={}
***************
*** 482,487 ****
--- 482,488 ----
port=9673
threading=None
host=''
+ uid='nobody'
for k,v in optlist:
if k=="-p":
port=string.atoi(v)
***************
*** 495,500 ****
while v[:1]=='/': v=v[1:]
while v[-1:]=='/': v=v[:-1]
BoboRequestHandler.script="/%s/" % v
! start(module_file,host,port,threading,env)
if __name__=="__main__": main()
--- 496,503 ----
while v[:1]=='/': v=v[1:]
while v[-1:]=='/': v=v[:-1]
BoboRequestHandler.script="/%s/" % v
! elif k=='-u':
! uid=v
! start(module_file,host,port,threading,env,uid)
if __name__=="__main__": main()
--Qxx1br4bt0+wmkIi--