1
0
Fork 0
mirror of https://git.code.sf.net/p/archivemail/code synced 2024-12-22 07:42:55 +00:00

If running as root, only call seteuid/setegid if the if the owner of the mailbox

is not root.
This commit is contained in:
Nikolaus Schulz 2007-11-09 17:04:52 +00:00
parent 0ae7edab86
commit ead112daba

View file

@ -1115,11 +1115,13 @@ 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]
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)
@ -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)