history: fix json file permissions upon sudo (#5220) (#5221)

This commit is contained in:
doronz88 2023-10-25 23:26:04 +03:00 committed by GitHub
parent 0fe0a6c03e
commit f308813f15
Failed to generate hash of commit
2 changed files with 27 additions and 0 deletions

View file

@ -0,0 +1,23 @@
**Added:**
* <news item>
**Changed:**
* <news item>
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* history: fix json file permissions upon `sudo` (#5220)
**Security:**
* <news item>

View file

@ -426,6 +426,10 @@ class JsonHistory(History):
xlj.ljdump(meta, f, sort_keys=True)
try:
sudo_uid = os.environ.get("SUDO_UID")
sudo_gid = os.environ.get("SUDO_GID")
if None not in (sudo_uid, sudo_gid):
os.chown(self.filename, int(sudo_uid), int(sudo_gid))
os.chmod(self.filename, 0o600)
except Exception: # pylint: disable=broad-except
pass