From 2d7e83aaeb0bc43702b81d1a63d45c7657be000c Mon Sep 17 00:00:00 2001 From: twouters Date: Tue, 24 Jul 2001 11:56:56 +0000 Subject: check_privs(): new function that drops root privileges (if we have them) and complains if we aren't running as the right user, gets called from main(). Should we check for the availability of os.(g|s)et(u|g)id ? --- bin/mailmanctl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bin/mailmanctl b/bin/mailmanctl index 73312415e..e305e9b6c 100644 --- a/bin/mailmanctl +++ b/bin/mailmanctl @@ -103,6 +103,17 @@ def kill_subrunners(sig): print >> sys.stderr, 'Stale pid file removed.' os.unlink(mm_cfg.PIDFILE) + +def check_privs(): + # Should we check for the availability of these functions ? + 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) + def main(): try: @@ -128,6 +139,7 @@ def main(): if command not in ('start', 'stop', 'restart'): usage(1, _('Bad command: %(command)s')) + check_privs() # Handle the commands if command == 'stop': # Sent the master qrunner process a SIGINT, which is equivalent to -- cgit v1.3.1