From 81c82ddaf5391e318a1bade96f20e24b9725da8b Mon Sep 17 00:00:00 2001 From: Paul Rodger Date: Thu, 4 Apr 2002 07:40:13 +0000 Subject: check to see if we are running as root -- if so, change our effective userid and groupid to that of the owner of the original mailbox --- archivemail.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/archivemail.py b/archivemail.py index b06bed3..ee9fa7e 100755 --- a/archivemail.py +++ b/archivemail.py @@ -678,6 +678,16 @@ def archive(mailbox_name): os.path.basename(final_archive_name)) vprint("archiving '%s' to '%s' ..." % (mailbox_name, final_archive_name)) + # check to see if we are running as root -- if so, change our effective + # userid and groupid to that of the original mailbox + if (os.getuid() == 0) and os.path.exists(mailbox_name): + mailbox_user = os.stat(mailbox_name)[stat.ST_UID] + mailbox_group = os.stat(mailbox_name)[stat.ST_GID] + vprint("changing effective group id to: %d" % mailbox_group) + os.setegid(mailbox_group) + vprint("changing effective user id to: %d" % mailbox_user) + os.seteuid(mailbox_user) + if os.path.islink(mailbox_name): unexpected_error("'%s' is a symbolic link -- I feel nervous!" % mailbox_name) @@ -696,6 +706,12 @@ def archive(mailbox_name): else: user_error("'%s': no such file or directory" % mailbox_name) + # if we are running as root, revert the seteuid()/setegid() above + if (os.getuid() == 0): + vprint("changing effective groupid and userid back to root") + os.setegid(0) + os.seteuid(0) + def _archive_mbox(mailbox_name, final_archive_name): """Archive a 'mbox' style mailbox - used by archive_mailbox() -- cgit v1.2.3