aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Rodger <paul@paulrodger.com>2002-04-04 07:40:13 +0000
committerPaul Rodger <paul@paulrodger.com>2002-04-04 07:40:13 +0000
commit81c82ddaf5391e318a1bade96f20e24b9725da8b (patch)
tree881b67f7bf132815fe93c8d1cba8ec98c4ceac90
parent1ed695b748f0c53dea845231e3fd03ec1186ee3f (diff)
downloadarchivemail-81c82ddaf5391e318a1bade96f20e24b9725da8b.tar.gz
archivemail-81c82ddaf5391e318a1bade96f20e24b9725da8b.tar.bz2
archivemail-81c82ddaf5391e318a1bade96f20e24b9725da8b.zip
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
-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()