python 3.x
FreeBSD 11.3-RELEASE-p12 with custom settings mentioned later.
On vanilla configuration of FreeBSD there is no issue.
Installation of FreeBSD in question has mac_bsdextended turned on (https://www.freebsd.org/cgi/man.cgi?query=mac_bsdextended&sektion=4&apropos=0&manpath=FreeBSD+12.1-RELEASE+and+Ports)
Using ugidfw (https://www.freebsd.org/cgi/man.cgi?query=ugidfw&sektion=8&manpath=freebsd-release-ports), the following rule has been set:
---------------------------------------------------------------
0 subject not uid root gid nobody object gid wheel type d mode sx
---------------------------------------------------------------
The following code shows the minimal reproducible example:
---------------------------------------------------------------
from pathlib import Path
BASE_DIR = Path(__file__).resolve(strict=True).parent.parent
print(BASE_DIR)
---------------------------------------------------------------
Running the code directly works:
---------------------------------------------------------------
$ python test.py
/usr/home/example
---------------------------------------------------------------
But importing it as a module does not:
---------------------------------------------------------------
$ python -m test
Traceback (most recent call last):
File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/home/example/django_3136test/test.py", line 2, in <module>
BASE_DIR = Path(__file__).resolve(strict=True).parent.parent
File "/usr/local/lib/python3.6/pathlib.py", line 1141, in resolve
s = self._flavour.resolve(self, strict=strict)
File "/usr/local/lib/python3.6/pathlib.py", line 346, in resolve
return _resolve(base, str(path)) or sep
File "/usr/local/lib/python3.6/pathlib.py", line 330, in _resolve
target = accessor.readlink(newpath)
File "/usr/local/lib/python3.6/pathlib.py", line 440, in readlink
return os.readlink(path)
PermissionError: [Errno 13] Permission denied: '/usr'
---------------------------------------------------------------
The issue seems to be comnected with following piece code
https://github.com/python/cpython/blob/master/Lib/pathlib.py#L342-L346
---------------------------------------------------------------
try:
target = accessor.readlink(newpath)
except OSError as e:
if e.errno != EINVAL and strict:
raise
# Not a symlink, or non-strict mode. We just leave the path
# untouched.
path = newpath
---------------------------------------------------------------
With ugidfw enabled, `os.readlink` raises a `PermissionError`, which is unhandled by pathlib.
|