CC-3299: Media monitor changes the owner of watched files?
- media monitor now tries to set the permission to www-data if the file/dir cannot be read by www-data
This commit is contained in:
parent
613006e69c
commit
a79dd4fe04
|
@ -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,19 +69,18 @@ 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]
|
||||
|
||||
os.chown(item, uid, gid)
|
||||
|
||||
if is_dir is True:
|
||||
os.chmod(item, 02777)
|
||||
else:
|
||||
os.chmod(item, 0666)
|
||||
|
||||
if not has_correct_permissions(item, 'www-data', 'www-data'):
|
||||
os.chown(item, uid, gid)
|
||||
|
||||
if is_dir is True:
|
||||
os.chmod(item, 02777)
|
||||
else:
|
||||
os.chmod(item, 0666)
|
||||
|
||||
except Exception, e:
|
||||
self.logger.error("Failed to change file's owner/group/permissions. %s", e)
|
||||
|
|
Loading…
Reference in New Issue