INNER CODE UNIT · Python
directory_beneath
kejilion/sh · site_access_cli.py:24
def directory_beneath(rootfd, parts):
current = os.dup(rootfd)
try:
for part in parts:
if not part or part in ('.', '..') or '\x00' in part or '/' in part or '\\' in part:
raise ConfigError('invalid path')
following = os.open(part, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW | os.O_CLOEXEC,
dir_fd=current)
os.close(current)
current = following
return current
except BaseException:
os.close(current)
raise
def file_target(rootfd, nginx_path):
if not isinstance(nginx_path, str) or any(c in nginx_path for c in ('\0', '$', '\\')):