|
20 | 20 |
|
21 | 21 | Based on CGIHTTPServer in the Python library. |
22 | 22 |
|
23 | | -$Id: roundup-server,v 1.15 2001-10-12 02:23:26 richard Exp $ |
| 23 | +$Id: roundup-server,v 1.16 2001-10-27 00:12:21 richard Exp $ |
24 | 24 |
|
25 | 25 | """ |
26 | 26 | import sys |
@@ -216,23 +216,24 @@ def main(): |
216 | 216 | elif opt == '-u': user = arg |
217 | 217 | elif opt == '-h': usage() |
218 | 218 |
|
219 | | - # if root, setuid to the running user |
220 | | - if not os.getuid() and user is not None: |
221 | | - try: |
222 | | - import pwd |
223 | | - except ImportError: |
224 | | - raise ValueError, "Can't change users - no pwd module" |
225 | | - try: |
226 | | - uid = pwd.getpwnam(user)[2] |
227 | | - except KeyError: |
228 | | - raise ValueError, "User %s doesn't exist"%user |
229 | | - os.setuid(uid) |
230 | | - elif os.getuid() and user is not None: |
231 | | - print 'WARNING: ignoring "-u" argument, not root' |
232 | | - |
233 | | - # People can remove this check if they're really determined |
234 | | - if not os.getuid() and user is None: |
235 | | - raise ValueError, "Can't run as root!" |
| 219 | + if hasattr(os, 'getuid'): |
| 220 | + # if root, setuid to the running user |
| 221 | + if not os.getuid() and user is not None: |
| 222 | + try: |
| 223 | + import pwd |
| 224 | + except ImportError: |
| 225 | + raise ValueError, "Can't change users - no pwd module" |
| 226 | + try: |
| 227 | + uid = pwd.getpwnam(user)[2] |
| 228 | + except KeyError: |
| 229 | + raise ValueError, "User %s doesn't exist"%user |
| 230 | + os.setuid(uid) |
| 231 | + elif os.getuid() and user is not None: |
| 232 | + print 'WARNING: ignoring "-u" argument, not root' |
| 233 | + |
| 234 | + # People can remove this check if they're really determined |
| 235 | + if not os.getuid() and user is None: |
| 236 | + raise ValueError, "Can't run as root!" |
236 | 237 |
|
237 | 238 | # handle instance specs |
238 | 239 | if args: |
@@ -260,6 +261,9 @@ if __name__ == '__main__': |
260 | 261 |
|
261 | 262 | # |
262 | 263 | # $Log: not supported by cvs2svn $ |
| 264 | +# Revision 1.15 2001/10/12 02:23:26 richard |
| 265 | +# Didn't clean up after myself :) |
| 266 | +# |
263 | 267 | # Revision 1.14 2001/10/12 02:20:32 richard |
264 | 268 | # server now handles setuid'ing much better |
265 | 269 | # |
|
0 commit comments