Merge branch '2.0.x' of dev.sourcefabric.org:airtime into 2.0.x

This commit is contained in:
Martin Konecny 2012-02-06 12:28:49 -05:00
commit 62d1d56fd2
1 changed files with 15 additions and 12 deletions

View File

@ -46,9 +46,13 @@ class MediaMonitorCommon:
return False
#check if file is readable by "nobody"
def has_correct_permissions(self, filepath):
def has_correct_permissions(self, filepath, euid='nobody', egid='nogroup'):
uid = pwd.getpwnam(euid)[2]
gid = grp.getgrnam(egid)[2]
#drop root permissions and become "nobody"
os.seteuid(65534)
os.seteuid(uid)
os.setegid(gid)
try:
open(filepath)
@ -65,13 +69,12 @@ class MediaMonitorCommon:
return readable
# the function only changes the permission if its not readable by www-data
def set_needed_file_permissions(self, item, is_dir):
try:
omask = os.umask(0)
uid = pwd.getpwnam('www-data')[2]
gid = grp.getgrnam('www-data')[2]
if not has_correct_permissions(item, 'www-data', 'www-data'):
os.chown(item, uid, gid)
if is_dir is True: