1
0
Fork 0
mirror of https://git.code.sf.net/p/archivemail/code synced 2024-12-23 00:06:43 +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,17 +1115,19 @@ def archive(mailbox_name):
# check to see if we are running as root -- if so, change our effective # check to see if we are running as root -- if so, change our effective
# userid and groupid to that of the original mailbox # 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): 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_user = os.stat(mailbox_name)[stat.ST_UID]
mailbox_group = os.stat(mailbox_name)[stat.ST_GID] mailbox_group = os.stat(mailbox_name)[stat.ST_GID]
vprint("changing effective group id to: %d" % mailbox_group) if (mailbox_user, mailbox_group) != (0, former_gid):
os.setegid(mailbox_group) running_setuid = True
vprint("changing effective user id to: %d" % mailbox_user) vprint("changing effective group id to: %d" % mailbox_group)
os.seteuid(mailbox_user) os.setegid(mailbox_group)
user_warning("changing effective user id: this automatic feature " vprint("changing effective user id to: %d" % mailbox_user)
"is deprecated and will be removed from later versions.") 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 old_temp_dir = tempfile.tempdir
try: try:
@ -1167,7 +1169,7 @@ def archive(mailbox_name):
clean_up() clean_up()
# if we are running as root, revert the seteuid()/setegid() above # 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") vprint("changing effective groupid and userid back to root")
os.setegid(former_gid) os.setegid(former_gid)
os.seteuid(0) os.seteuid(0)