aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolaus Schulz <microschulz@web.de>2008-08-04 14:12:34 +0200
committerNikolaus Schulz <microschulz@web.de>2009-11-06 21:09:39 +0100
commitaee4df2fcf03f53e33b83c7923e086ed5d659d31 (patch)
tree53bc052739443cc7d59fb8b5f5d474164d14d448
parent2e0f3cd3aaf1ca600a2576ceae575c28bf3c7cbe (diff)
downloadarchivemail-aee4df2fcf03f53e33b83c7923e086ed5d659d31.tar.gz
archivemail-aee4df2fcf03f53e33b83c7923e086ed5d659d31.tar.bz2
archivemail-aee4df2fcf03f53e33b83c7923e086ed5d659d31.zip
Refuse to process mailboxes owned by someone else
This should also protect people relying on the old setuid feature. If the mailbox is local, by checking the ownership we necessarily check for existance.
-rwxr-xr-xarchivemail.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/archivemail.py b/archivemail.py
index af1bb48..47d1888 100755
--- a/archivemail.py
+++ b/archivemail.py
@@ -1100,6 +1100,17 @@ def archive(mailbox_name):
if not dest_dir:
dest_dir = os.getcwd()
check_sane_destdir(dest_dir)
+ is_imap = urlparse.urlparse(mailbox_name)[0] in ('imap', 'imaps')
+ if not is_imap:
+ # Check if the mailbox exists, and refuse to mess with other people's
+ # stuff
+ try:
+ fuid = os.stat(mailbox_name).st_uid
+ except OSError, e:
+ user_error(str(e))
+ else:
+ if fuid != os.getuid():
+ user_error("'%s' is owned by someone else!" % mailbox_name)
vprint("archiving '%s' to '%s' ..." % (mailbox_name, final_archive_name))
old_temp_dir = tempfile.tempdir
@@ -1112,7 +1123,6 @@ def archive(mailbox_name):
tempfile.tempdir = new_temp_dir
vprint("set tempfile directory to '%s'" % new_temp_dir)
- is_imap = urlparse.urlparse(mailbox_name)[0] in ('imap', 'imaps')
if is_imap:
vprint("guessing mailbox is of type: imap(s)")
_archive_imap(mailbox_name, final_archive_name)
@@ -1129,7 +1139,7 @@ def archive(mailbox_name):
vprint("guessing mailbox is of type: MH")
_archive_dir(mailbox_name, final_archive_name, "mh")
else:
- user_error("'%s': no such file or directory" % mailbox_name)
+ user_error("'%s' is not a normal file or directory" % mailbox_name)
# remove our special temp directory - hopefully empty
os.rmdir(new_temp_dir)