mirror of
https://github.com/naruxde/revpipyload.git
synced 2025-11-08 15:13:52 +01:00
Fix problem with extended unix user groups
PLC program got only uid and gid, but not the other group ids of user. Set gid to work directory, too. Set uid and gid to uploaded files.
This commit is contained in:
@@ -6,6 +6,7 @@ __license__ = "GPLv3"
|
||||
import os
|
||||
import shlex
|
||||
import subprocess
|
||||
from pwd import getpwuid
|
||||
from sys import stdout as sysstdout
|
||||
from threading import Event, Thread
|
||||
from time import sleep, asctime
|
||||
@@ -95,6 +96,15 @@ class RevPiPlc(Thread):
|
||||
"set uid {0} and gid {1} for plc program".format(
|
||||
self.uid, self.gid)
|
||||
)
|
||||
|
||||
# Set user last to hold root right to do the group things
|
||||
try:
|
||||
name = getpwuid(self.uid).pw_name
|
||||
os.initgroups(name, self.gid)
|
||||
except Exception:
|
||||
proginit.logger.warning(
|
||||
"could not initialize the group access list with all groups"
|
||||
)
|
||||
os.setgid(self.gid)
|
||||
os.setuid(self.uid)
|
||||
|
||||
|
||||
@@ -343,9 +343,9 @@ class RevPiPyLoad:
|
||||
# Workdirectory owner setzen
|
||||
try:
|
||||
if self.plcworkdir_set_uid:
|
||||
os.chown(self.plcworkdir, self.plcuid, -1)
|
||||
os.chown(self.plcworkdir, self.plcuid, self.plcgid)
|
||||
else:
|
||||
os.chown(self.plcworkdir, 0, -1)
|
||||
os.chown(self.plcworkdir, 0, 0)
|
||||
except Exception:
|
||||
proginit.logger.warning(
|
||||
"could not set user id on working directory"
|
||||
@@ -1207,6 +1207,10 @@ class RevPiPyLoad:
|
||||
try:
|
||||
with open(filename, "wb") as fh:
|
||||
fh.write(gzip.decompress(filedata.data))
|
||||
if self.plcworkdir_set_uid:
|
||||
os.chown(self.plcworkdir, self.plcuid, self.plcgid)
|
||||
else:
|
||||
os.chown(self.plcworkdir, 0, 0)
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user