From: mar77i Date: Mon, 27 Nov 2023 02:48:52 +0000 (+0100) Subject: remote_run.py: only re.match current Path.name X-Git-Url: https://git.mar77i.info/?a=commitdiff_plain;h=6c49622b2c192d60863da992f551992dbbc2d910;p=admin remote_run.py: only re.match current Path.name --- diff --git a/remote_run.py b/remote_run.py index b253c9a..943b341 100755 --- a/remote_run.py +++ b/remote_run.py @@ -12,10 +12,8 @@ from subprocess import DEVNULL, PIPE, Popen, check_output, run PORT = "7777" REMOTE_HOST = "localhost" REMOTE_PORT = "7777" -AUTH_SOCK_DIR_PATTERN = re.compile(r"/ssh-[^/]+$") -AUTH_SOCK_PATTERN = re.compile( - rf"{AUTH_SOCK_DIR_PATTERN.pattern.rstrip('$')}/agent.[0-9]+$" -) +AUTH_SOCK_DIR_PATTERN = re.compile(r"ssh-") +AUTH_SOCK_PATTERN = re.compile(f"agent.[0-9]+$") class ReusableTCPServer(TCPServer): @@ -42,12 +40,12 @@ def get_ssh_auth_sock(): for q in chain.from_iterable( p.iterdir() for p in Path(os.environ.get("TMPDIR") or "/tmp").iterdir() - if p.is_dir() and AUTH_SOCK_DIR_PATTERN.search(str(p)) + if p.is_dir() and AUTH_SOCK_DIR_PATTERN.match(p.name) ): q_str = str(q) if ( q.is_socket() - and AUTH_SOCK_PATTERN.search(q_str) + and AUTH_SOCK_PATTERN.fullmatch(q.name) and check_ssh_auth_sock(env={**os.environ, "SSH_AUTH_SOCK": q_str}) ): return q_str