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
|
return False
|
||||||
|
|
||||||
#check if file is readable by "nobody"
|
#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"
|
#drop root permissions and become "nobody"
|
||||||
os.seteuid(65534)
|
os.seteuid(uid)
|
||||||
|
os.setegid(gid)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
open(filepath)
|
open(filepath)
|
||||||
|
@ -65,19 +69,18 @@ class MediaMonitorCommon:
|
||||||
|
|
||||||
return readable
|
return readable
|
||||||
|
|
||||||
|
# the function only changes the permission if its not readable by www-data
|
||||||
def set_needed_file_permissions(self, item, is_dir):
|
def set_needed_file_permissions(self, item, is_dir):
|
||||||
try:
|
try:
|
||||||
omask = os.umask(0)
|
omask = os.umask(0)
|
||||||
|
|
||||||
uid = pwd.getpwnam('www-data')[2]
|
if not has_correct_permissions(item, 'www-data', 'www-data'):
|
||||||
gid = grp.getgrnam('www-data')[2]
|
os.chown(item, uid, gid)
|
||||||
|
|
||||||
os.chown(item, uid, gid)
|
if is_dir is True:
|
||||||
|
os.chmod(item, 02777)
|
||||||
if is_dir is True:
|
else:
|
||||||
os.chmod(item, 02777)
|
os.chmod(item, 0666)
|
||||||
else:
|
|
||||||
os.chmod(item, 0666)
|
|
||||||
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.logger.error("Failed to change file's owner/group/permissions. %s", e)
|
self.logger.error("Failed to change file's owner/group/permissions. %s", e)
|
||||||
|
|
Loading…
Reference in New Issue