summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbwarsaw2001-07-25 04:20:20 +0000
committerbwarsaw2001-07-25 04:20:20 +0000
commit72ba7026fa51ffd6ba678e5fe609ff91fef4955f (patch)
tree8084d4db17d1262064153e0fa2d3b58241fa2fe7
parent2d7e83aaeb0bc43702b81d1a63d45c7657be000c (diff)
downloadmailman-72ba7026fa51ffd6ba678e5fe609ff91fef4955f.tar.gz
mailman-72ba7026fa51ffd6ba678e5fe609ff91fef4955f.tar.zst
mailman-72ba7026fa51ffd6ba678e5fe609ff91fef4955f.zip
check_privs(): Fix the error message to be a single string
(concatenated strings are harder for some languages to translate correctly), and use the usage() method when the check fails. main(): Add -u / --run-as-user to skip the check_privs() test.
-rw-r--r--bin/mailmanctl33
1 files changed, 26 insertions, 7 deletions
diff --git a/bin/mailmanctl b/bin/mailmanctl
index e305e9b6c..edca6e6db 100644
--- a/bin/mailmanctl
+++ b/bin/mailmanctl
@@ -39,6 +39,17 @@ Options:
Don't restart queue runners when they exit because of an error. Use
this only for debugging. Only useful if the `start' command is given.
+ -u/--run-as-user
+ Normally, this script will refuse to run if the user id and group id
+ are not set to the `mailman' user and group (as defined when you
+ configured Mailman). If run as root, this script will change to this
+ user and group before the check is made.
+
+ This can be inconvenient for testing and debugging purposes, so the -u
+ flag means that the step that sets and checks the uid/gid is skipped,
+ and the program is run as the current user and group. This flag is
+ not recommended for normal production environments.
+
-h/--help
Print this message and exit.
@@ -61,6 +72,7 @@ import os
import getopt
import signal
import errno
+import pwd
import paths
from Mailman import mm_cfg
@@ -105,29 +117,35 @@ def kill_subrunners(sig):
def check_privs():
- # Should we check for the availability of these functions ?
+ # If we're running as root (uid == 0), coerce the uid and gid to that
+ # which Mailman was configured for, and refuse to run if we didn't coerce
+ # the uid/gid.
if os.getuid() == 0:
os.setgid(mm_cfg.MAILMAN_GID)
os.setuid(mm_cfg.MAILMAN_UID)
if os.getuid() <> mm_cfg.MAILMAN_UID:
- print >> sys.stderr, _("This program should only be run as root "
- "or as the Mailman user.")
- sys.exit(1)
+ name = pwd.getpwuid(mm_cfg.MAILMAN_UID)[0]
+ usage(1, _(
+ 'Run this program as root or as the %(name)s user, or use -u.'))
+
def main():
try:
- opts, args = getopt.getopt(sys.argv[1:], 'hn',
- ['help', 'no-start'])
+ opts, args = getopt.getopt(sys.argv[1:], 'hnu',
+ ['help', 'no-start', 'run-as-user'])
except getopt.error, msg:
usage(1, msg)
restart = 1
+ checkprivs = 1
for opt, arg in opts:
if opt in ('-h', '--help'):
usage(0)
elif opt in ('-n', '--no-restart'):
restart = 0
+ elif opt in ('-u', '--run-as-user'):
+ checkprivs = 0
if len(args) < 1:
usage(1, _('No command given.'))
@@ -139,7 +157,8 @@ def main():
if command not in ('start', 'stop', 'restart'):
usage(1, _('Bad command: %(command)s'))
- check_privs()
+ if checkprivs:
+ check_privs()
# Handle the commands
if command == 'stop':
# Sent the master qrunner process a SIGINT, which is equivalent to