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
This commit is contained in:
Paul Rodger 2002-04-04 07:40:13 +00:00
parent 1ed695b748
commit 81c82ddaf5
1 changed files with 16 additions and 0 deletions

View File

@ -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()