From 8e0fe1920eee959ad14225ad2327793371be05d1 Mon Sep 17 00:00:00 2001 From: Anders Björklund Date: Tue, 18 Feb 2020 14:08:35 +0100 Subject: Use hash for ControlPath instead of full variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The generated socket path can be too long, if your FQDN is very long... Typical error message from ssh client: unix_listener: path "/tmp/ssh-fqduawon/master-USER@HOST:PORT.qfCZ51OAZgTzVLbg" too long for Unix domain socket Use a hashed version instead, to keep within the socket file path limit. This requires OpenSSH_6.7p1, or later. Change-Id: Ia4bb9ae8aac6c4ee31d5a458f917f3753f40001b Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/255632 Reviewed-by: Mike Frysinger Reviewed-by: David Pursehouse Tested-by: Anders Björklund --- git_command.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'git_command.py') diff --git a/git_command.py b/git_command.py index a2782151..1cb8f1aa 100644 --- a/git_command.py +++ b/git_command.py @@ -16,6 +16,7 @@ from __future__ import print_function import os +import re import sys import subprocess import tempfile @@ -47,6 +48,35 @@ LAST_CWD = None _ssh_proxy_path = None _ssh_sock_path = None _ssh_clients = [] +_ssh_version = None + + +def _run_ssh_version(): + """run ssh -V to display the version number""" + return subprocess.check_output(['ssh', '-V'], stderr=subprocess.STDOUT).decode() + + +def _parse_ssh_version(ver_str=None): + """parse a ssh version string into a tuple""" + if ver_str is None: + ver_str = _run_ssh_version() + m = re.match(r'^OpenSSH_([0-9.]+)(p[0-9]+)?\s', ver_str) + if m: + return tuple(int(x) for x in m.group(1).split('.')) + else: + return () + + +def ssh_version(): + """return ssh version as a tuple""" + global _ssh_version + if _ssh_version is None: + try: + _ssh_version = _parse_ssh_version() + except subprocess.CalledProcessError: + print('fatal: unable to detect ssh version', file=sys.stderr) + sys.exit(1) + return _ssh_version def ssh_sock(create=True): @@ -57,9 +87,13 @@ def ssh_sock(create=True): tmp_dir = '/tmp' if not os.path.exists(tmp_dir): tmp_dir = tempfile.gettempdir() + if ssh_version() < (6, 7): + tokens = '%r@%h:%p' + else: + tokens = '%C' # hash of %l%h%p%r _ssh_sock_path = os.path.join( tempfile.mkdtemp('', 'ssh-', tmp_dir), - 'master-%r@%h:%p') + 'master-' + tokens) return _ssh_sock_path -- cgit v1.2.3-54-g00ecf