aboutsummaryrefslogtreecommitdiffstats
path: root/archivemail.py
diff options
context:
space:
mode:
authorNikolaus Schulz <microschulz@web.de>2007-11-09 17:04:52 +0000
committerNikolaus Schulz <microschulz@web.de>2007-11-09 17:04:52 +0000
commitead112daba62c9c1dadd73ee4097962e9b414043 (patch)
treed2a4f9137bae7d76b818d60463461eb72e5bf9b9 /archivemail.py
parent0ae7edab8653677ca86ffabf72c37c625d9eb580 (diff)
downloadarchivemail-ead112daba62c9c1dadd73ee4097962e9b414043.tar.gz
archivemail-ead112daba62c9c1dadd73ee4097962e9b414043.tar.bz2
archivemail-ead112daba62c9c1dadd73ee4097962e9b414043.zip
If running as root, only call seteuid/setegid if the if the owner of the mailbox
is not root.
Diffstat (limited to 'archivemail.py')
-rwxr-xr-xarchivemail.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/archivemail.py b/archivemail.py
index 0980c6c..252a2aa 100755
--- a/archivemail.py
+++ b/archivemail.py
@@ -1115,17 +1115,19 @@ def archive(mailbox_name):
# check to see if we are running as root -- if so, change our effective
# userid and groupid to that of the original mailbox
- former_gid = None # groupid doesn't have to be '0' for root on solaris 8?
+ running_setuid = False
if (os.getuid() == 0) and os.path.exists(mailbox_name):
- former_gid = os.getgid(); # remember this so we can change back
+ former_gid = os.getgid() # groupid doesn't have to be '0' for root on solaris 8?
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)
- user_warning("changing effective user id: this automatic feature "
- "is deprecated and will be removed from later versions.")
+ if (mailbox_user, mailbox_group) != (0, former_gid):
+ running_setuid = True
+ 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)
+ user_warning("changing effective user id: this automatic feature "
+ "is deprecated and will be removed from later versions.")
old_temp_dir = tempfile.tempdir
try:
@@ -1167,7 +1169,7 @@ def archive(mailbox_name):
clean_up()
# if we are running as root, revert the seteuid()/setegid() above
- if former_gid != None:
+ if running_setuid:
vprint("changing effective groupid and userid back to root")
os.setegid(former_gid)
os.seteuid(0)