INNER CODE UNIT · Python
file_target
kejilion/sh · site_access_cli.py:40
def file_target(rootfd, nginx_path):
if not isinstance(nginx_path, str) or any(c in nginx_path for c in ('\0', '$', '\\')):
raise ConfigError('invalid password file path')
if not nginx_path.startswith('/'):
if not nginx_path or any(part in ('', '.', '..') for part in nginx_path.split('/')):
raise ConfigError('invalid password file path')
nginx_path = '/etc/nginx/' + nginx_path
for prefix, mount in MOUNTS.items():
if nginx_path.startswith(prefix):
parts = nginx_path[len(prefix):].split('/')
if not parts[-1] or parts[-1] in ('.', '..'):
raise ConfigError('invalid password file path')
return directory_beneath(rootfd, [mount] + parts[:-1]), parts[-1]
raise ConfigError('password file mount unavailable')
def read_checked(dirfd, name, expected, limit):
fd, _, data = _read(dirfd, name, limit)