Nicer error message for pwfile owner/permission mismatch

This commit is contained in:
Kovid Goyal 2023-07-12 20:38:55 +05:30
parent ee4a9c6ed8
commit e363303359
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C

View file

@ -105,10 +105,10 @@ def read_data_from_shared_memory(shm_name: str) -> Any:
with SharedMemory(shm_name, readonly=True) as shm:
shm.unlink()
if shm.stats.st_uid != os.geteuid() or shm.stats.st_gid != os.getegid():
raise ValueError('Incorrect owner on pwfile')
raise ValueError(f'Incorrect owner on pwfile: uid={shm.stats.st_uid} gid={shm.stats.st_gid}')
mode = stat.S_IMODE(shm.stats.st_mode)
if mode != stat.S_IREAD | stat.S_IWRITE:
raise ValueError('Incorrect permissions on pwfile')
raise ValueError(f'Incorrect permissions on pwfile: 0o{mode:03o}')
return json.loads(shm.read_data_with_size())