aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xarchivemail.py16
1 files changed, 16 insertions, 0 deletions
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()