Mercurial > moin > 1.9
annotate MoinMoin/server/__init__.py @ 3102:a78bf6977df8
removed 'logging initialized' message because it filled the logs for CGI (ported from 1.6)
author | Thomas Waldmann <tw AT waldmann-edv DOT de> |
---|---|
date | Sat, 23 Feb 2008 16:14:04 +0100 |
parents | cfdb0ffc2910 |
children | 80e1a910a2f1 |
rev | line source |
---|---|
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
1 # -*- coding: iso-8859-1 -*- |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
2 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
3 MoinMoin server package |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
4 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
5 Supply common server utilities. |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
6 |
1918
bb2e053067fb
fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1585
diff
changeset
|
7 @copyright: 2004 Nir Soffer |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
8 @license: GNU GPL, see COPYING for details. |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
9 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
10 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
11 import os |
1585
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
12 import logging |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
13 |
1582
f37b49b6313d
url_prefix_static: move default to MoinMoin.config, use matching defaults for Twisted/standalone
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
988
diff
changeset
|
14 from MoinMoin import config |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
15 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
16 def switchUID(uid, gid): |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
17 """ Switch identity to safe user and group |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
18 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
19 Does not support Windows, because the necessary calls are not available. |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
20 TODO: can we use win32api calls to achieve the same effect on Windows? |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
21 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
22 Raise RuntimeError if can't switch or trying to switch to root. |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
23 """ |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
24 if uid == 0 or gid == 0: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
25 # We will not run as root. If you like to run a web |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
26 # server as root, then hack this code. |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
27 raise RuntimeError('will not run as root!') |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
28 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
29 try: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
30 os.setgid(gid) |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
31 os.setuid(uid) |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
32 except (OSError, AttributeError): |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
33 # Either we can't switch, or we are on windows, which does not have |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
34 # those calls. |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
35 raise RuntimeError("can't change uid/gid to %s/%s" % |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
36 (uid, gid)) |
1585
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
37 logging.info("Running as uid/gid %d/%d" % (uid, gid)) |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
38 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
39 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
40 class Config: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
41 """ Base class for server configuration |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
42 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
43 When you create a server, you should run it with a Config |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
44 instance. Sub class to define the default values. |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
45 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
46 This class does all error checking needed for config values, and will |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
47 raise a RuntimeError on any fatal error. |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
48 """ |
1582
f37b49b6313d
url_prefix_static: move default to MoinMoin.config, use matching defaults for Twisted/standalone
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
988
diff
changeset
|
49 # some defaults that should be common for all servers: |
f37b49b6313d
url_prefix_static: move default to MoinMoin.config, use matching defaults for Twisted/standalone
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
988
diff
changeset
|
50 url_prefix_static = config.url_prefix_static |
1584
1a1d6e0fe14f
make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1582
diff
changeset
|
51 docs = None # document root (if supported) |
1a1d6e0fe14f
make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1582
diff
changeset
|
52 user = None # user we shall use for running (if supported) |
1a1d6e0fe14f
make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1582
diff
changeset
|
53 group = None # group ... |
1a1d6e0fe14f
make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1582
diff
changeset
|
54 port = None # tcp port number (if supported) |
988
65dc979761f0
whitespace only and style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
0
diff
changeset
|
55 |
1585
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
56 # log levels for different log handlers |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
57 # None means "don't use this handler", otherwise specify the minimum loglevel, e.g. logging.DEBUG |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
58 # TODO: change later to an appropriate level, for now, we want everything |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
59 loglevel_file = logging.DEBUG # None |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
60 loglevel_stderr = logging.DEBUG # None |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
61 logPath = None |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
62 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
63 def __init__(self): |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
64 """ Validate and post process configuration values |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
65 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
66 Will raise RuntimeError for any wrong config value. |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
67 """ |
1585
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
68 # First, initialize the logging |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
69 logger = logging.getLogger('') # root logger |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
70 logger.setLevel(logging.NOTSET) # otherwise it has WARNING by default! |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
71 |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
72 if self.loglevel_file is not None and self.logPath is not None: |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
73 # define a Handler which writes to a log file |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
74 logfile = logging.FileHandler(self.logPath, 'at') # XXX we can't say ", 0" for sync here :( |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
75 logfile.setLevel(self.loglevel_file) |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
76 # set a format which is better for logfile use |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
77 formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
78 # tell the handler to use this format |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
79 logfile.setFormatter(formatter) |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
80 # add the handler to the root logger |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
81 logger.addHandler(logfile) |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
82 |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
83 if self.loglevel_stderr is not None: |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
84 # define a Handler which writes INFO to sys.stderr |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
85 logstderr = logging.StreamHandler() |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
86 logstderr.setLevel(self.loglevel_stderr) |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
87 # set a format which is simpler for console use |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
88 formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(message)s', '%H%M%S') |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
89 # tell the handler to use this format |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
90 logstderr.setFormatter(formatter) |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
91 # add the handler to the root logger |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
92 logger.addHandler(logstderr) |
a843bc5793fb
introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1584
diff
changeset
|
93 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
94 # Check that docs path is accessible |
1584
1a1d6e0fe14f
make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1582
diff
changeset
|
95 if self.docs: |
1a1d6e0fe14f
make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1582
diff
changeset
|
96 self.docs = os.path.normpath(os.path.abspath(self.docs)) |
1a1d6e0fe14f
make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1582
diff
changeset
|
97 if not os.access(self.docs, os.F_OK | os.R_OK | os.X_OK): |
1a1d6e0fe14f
make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1582
diff
changeset
|
98 raise RuntimeError("Can't access docs directory '%s'. Check docs " |
1a1d6e0fe14f
make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1582
diff
changeset
|
99 "setting and permissions." % self.docs) |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
100 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
101 # Don't check uid and gid on windows, those calls are not available. |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
102 if os.name == 'nt': |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
103 self.uid = self.gid = 0 |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
104 return |
988
65dc979761f0
whitespace only and style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
0
diff
changeset
|
105 |
1584
1a1d6e0fe14f
make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1582
diff
changeset
|
106 self.uid = os.getuid() |
1a1d6e0fe14f
make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1582
diff
changeset
|
107 self.gid = os.getgid() |
1a1d6e0fe14f
make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1582
diff
changeset
|
108 |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
109 # If serving privileged port, we must run as root to bind the port. |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
110 # we will give up root privileges later |
1584
1a1d6e0fe14f
make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1582
diff
changeset
|
111 if self.port and self.port < 1024 and self.uid != 0: |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
112 raise RuntimeError('Must run as root to serve port number under 1024. ' |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
113 'Run as root or change port setting.') |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
114 |
1584
1a1d6e0fe14f
make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1582
diff
changeset
|
115 if self.user and self.group and self.uid == 0: |
1a1d6e0fe14f
make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1582
diff
changeset
|
116 # If we run as root to serve privileged port, we change user and group |
1a1d6e0fe14f
make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1582
diff
changeset
|
117 # to a safe setting. Get the uid and gid now, switch later. |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
118 import pwd, grp |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
119 try: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
120 self.uid = pwd.getpwnam(self.user)[2] |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
121 except KeyError: |
1584
1a1d6e0fe14f
make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1582
diff
changeset
|
122 raise RuntimeError("Unknown user: '%s', check user setting" % self.user) |
0
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
123 try: |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
124 self.gid = grp.getgrnam(self.group)[2] |
77665d8e2254
tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff
changeset
|
125 except KeyError: |
1584
1a1d6e0fe14f
make moin.cgi work similar to the standalone/Twisted start scripts
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
1582
diff
changeset
|
126 raise RuntimeError("Unknown group: '%s', check group setting" % self.group) |
988
65dc979761f0
whitespace only and style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
0
diff
changeset
|
127 |