From 077fdae801da506dda05078d1486bf7f874efd43 Mon Sep 17 00:00:00 2001 From: Jeff Forcier Date: Mon, 7 May 2012 20:09:28 -0700 Subject: [PATCH] Reorganize forwarded agent cxns to avoid errors Fixes [Fabric #562](https://github.com/fabric/fabric/issues/562). (cherry picked from commit 58aa52085bc664fbfce61c5981ba54c1452f7abf) --- CHANGES | 6 ++++++ paramiko/agent.py | 28 +++++++++++++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index be3b2ad..e529a66 100644 --- a/CHANGES +++ b/CHANGES @@ -7,6 +7,12 @@ Temporary, post-Paramiko changelog while we get our sh!t together. * #24: Switch some internal type checking to use `isinstance` to help prevent problems with client libraries using subclasses of builtin types. Thanks to Alex Morega for the patch. +* [Fabric #562](https://github.com/fabric/fabric/issues/562): Agent forwarding + would error out (with `Authentication response too long`) or freeze, when more + than one remote connection to the local agent was active at the same time. + This has been fixed. Thanks to Steven McDonald for assisting in + troubleshooting/patching, and to GitHub user `@lynxis` for providing the + final version of the patch. ## ssh 1.7.13 (2012-02-13) diff --git a/paramiko/agent.py b/paramiko/agent.py index 31dcaf8..7115f17 100644 --- a/paramiko/agent.py +++ b/paramiko/agent.py @@ -186,10 +186,11 @@ class AgentClientProxy(object): the remote fake agent and the local agent -> Communication occurs ... """ - def __init__(self, chanClient): + def __init__(self, chanRemote): self._conn = None - self.__chanC = chanClient - chanClient.request_forward_agent(self._forward_agent_handler) + self.__chanR = chanRemote + self.thread = AgentRemoteProxy(self, chanRemote) + self.thread.start() def __del__(self): self.close() @@ -227,10 +228,6 @@ class AgentClientProxy(object): if self._conn is not None: self._conn.close() - def _forward_agent_handler(self, chanRemote): - self.thread = AgentRemoteProxy(self, chanRemote) - self.thread.start() - class AgentServerProxy(AgentSSH): """ @param t : transport used for the Forward for SSH Agent communication @@ -281,6 +278,23 @@ class AgentServerProxy(AgentSSH): def _get_filename(self): return self._file +class AgentRequestHandler(object): + def __init__(self, chanClient): + self._conn = None + self.__chanC = chanClient + chanClient.request_forward_agent(self._forward_agent_handler) + self.__clientProxys = [] + + def _forward_agent_handler(self, chanRemote): + self.__clientProxys.append(AgentClientProxy(chanRemote)) + + def __del__(self): + self.close() + + def close(self): + for p in self.__clientProxys: + p.close() + class Agent(AgentSSH): """ Client interface for using private keys from an SSH agent running on the