2020
2121Based on CGIHTTPServer in the Python library.
2222
23- $Id: roundup-server,v 1.13 2001-10-05 02:23:24 richard Exp $
23+ $Id: roundup-server,v 1.14 2001-10-12 02:20:32 richard Exp $
2424
2525"""
2626import sys
@@ -46,6 +46,9 @@ ROUNDUP_INSTANCE_HOMES = {
4646 'bar' : '/tmp/bar' ,
4747}
4848
49+ ROUNDUP_USER = None
50+
51+
4952# Where to log debugging information to. Use an instance of DevNull if you
5053# don't want to log anywhere.
5154# TODO: actually use this stuff
@@ -62,6 +65,7 @@ ROUNDUP_INSTANCE_HOMES = {
6265
6366class RoundupRequestHandler (SimpleHTTPServer .SimpleHTTPRequestHandler ):
6467 ROUNDUP_INSTANCE_HOMES = ROUNDUP_INSTANCE_HOMES
68+ ROUNDUP_USER = ROUNDUP_USER
6569 def send_head (self ):
6670 """Version of send_head that support CGI scripts"""
6771 # TODO: actually do the HEAD ...
@@ -160,12 +164,6 @@ class RoundupRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
160164
161165 decoded_query = query .replace ('+' , ' ' )
162166
163- # if root, setuid to nobody
164- # TODO why isn't this done much earlier? - say, in main()?
165- if not os .getuid ():
166- nobody = nobody_uid ()
167- os .setuid (nobody )
168-
169167 # reload all modules
170168 # TODO check for file timestamp changes and dependencies
171169 #reload(date)
@@ -187,22 +185,13 @@ class RoundupRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
187185
188186 do_POST = run_cgi
189187
190- nobody = None
188+ user = None
191189
192190def nobody_uid ():
193191 """Internal routine to get nobody's uid"""
194- global nobody
195- if nobody :
196- return nobody
197- try :
198- import pwd
199- except ImportError :
200- return - 1
201- try :
202- nobody = pwd .getpwnam ('nobody' )[2 ]
203- except KeyError :
204- nobody = 1 + max (map (lambda x : x [2 ], pwd .getpwall ()))
205- return nobody
192+ global user
193+ if user :
194+ return user
206195
207196def usage (message = '' ):
208197 if message : message = 'Error: %s\n ' % message
@@ -227,17 +216,40 @@ def main():
227216 port = 8080
228217 try :
229218 # handle the command-line args
230- optlist , args = getopt .getopt (sys .argv [1 :], 'n:p:' )
219+ optlist , args = getopt .getopt (sys .argv [1 :], 'n:p:u:' )
220+ user = ROUNDUP_USER
231221 for (opt , arg ) in optlist :
232222 if opt == '-n' : hostname = arg
233223 elif opt == '-p' : port = int (arg )
224+ elif opt == '-u' : user = arg
234225 elif opt == '-h' : usage ()
235226
227+ # if root, setuid to the running user
228+ if not os .getuid () and user is not None :
229+ try :
230+ import pwd
231+ except ImportError :
232+ raise ValueError , "Can't change users - no pwd module"
233+ try :
234+ uid = pwd .getpwnam (user )[2 ]
235+ except KeyError :
236+ raise ValueError , "User %s doesn't exist" % user
237+ os .setuid (uid )
238+ elif os .getuid () and user is not None :
239+ print 'WARNING: ignoring "-u" argument, not root'
240+
241+ # People can remove this check if they're really determined
242+ if not os .getuid () and user is None :
243+ raise ValueError , "Can't run as root!"
244+
236245 # handle instance specs
237246 if args :
238247 d = {}
239248 for arg in args :
240- name , home = string .split (arg , '=' )
249+ try :
250+ name , home = string .split (arg , '=' )
251+ except ValueError :
252+ raise ValueError , "Instances must be name=home"
241253 d [name ] = home
242254 RoundupRequestHandler .ROUNDUP_INSTANCE_HOMES = d
243255 except :
@@ -256,6 +268,26 @@ if __name__ == '__main__':
256268
257269#
258270# $Log: not supported by cvs2svn $
271+ # Revision 1.13 2001/10/05 02:23:24 richard
272+ # . roundup-admin create now prompts for property info if none is supplied
273+ # on the command-line.
274+ # . hyperdb Class getprops() method may now return only the mutable
275+ # properties.
276+ # . Login now uses cookies, which makes it a whole lot more flexible. We can
277+ # now support anonymous user access (read-only, unless there's an
278+ # "anonymous" user, in which case write access is permitted). Login
279+ # handling has been moved into cgi_client.Client.main()
280+ # . The "extended" schema is now the default in roundup init.
281+ # . The schemas have had their page headings modified to cope with the new
282+ # login handling. Existing installations should copy the interfaces.py
283+ # file from the roundup lib directory to their instance home.
284+ # . Incorrectly had a Bizar Software copyright on the cgitb.py module from
285+ # Ping - has been removed.
286+ # . Fixed a whole bunch of places in the CGI interface where we should have
287+ # been returning Not Found instead of throwing an exception.
288+ # . Fixed a deviation from the spec: trying to modify the 'id' property of
289+ # an item now throws an exception.
290+ #
259291# Revision 1.12 2001/09/29 13:27:00 richard
260292# CGI interfaces now spit up a top-level index of all the instances they can
261293# serve.
0 commit comments