summaryrefslogtreecommitdiffhomepage
path: root/paramiko/agent.py
diff options
context:
space:
mode:
authorJeff Forcier <jeff@bitprophet.org>2016-11-30 20:02:20 -0800
committerJeff Forcier <jeff@bitprophet.org>2016-11-30 20:02:20 -0800
commit9aec0c6300686e571fab5405c52876e6399f92e9 (patch)
tree8521aae70c6ebe889b92cbb9db69fd632f0fed08 /paramiko/agent.py
parent2a568863bb462fbae50fdd4795bf4d3e05e101bb (diff)
parent7366f965546c015c3f9e9dd1ccb8f0b7b8758dae (diff)
Merge branch 'master' into 398-int
Diffstat (limited to 'paramiko/agent.py')
-rw-r--r--paramiko/agent.py30
1 files changed, 27 insertions, 3 deletions
diff --git a/paramiko/agent.py b/paramiko/agent.py
index 4f463449..6a8e7fb4 100644
--- a/paramiko/agent.py
+++ b/paramiko/agent.py
@@ -32,7 +32,7 @@ from select import select
from paramiko.common import asbytes, io_sleep
from paramiko.py3compat import byte_chr
-from paramiko.ssh_exception import SSHException
+from paramiko.ssh_exception import SSHException, AuthenticationException
from paramiko.message import Message
from paramiko.pkey import PKey
from paramiko.util import retry_on_signal
@@ -73,7 +73,8 @@ class AgentSSH(object):
self._keys = tuple(keys)
def _close(self):
- #self._conn.close()
+ if self._conn is not None:
+ self._conn.close()
self._conn = None
self._keys = ()
@@ -108,9 +109,12 @@ class AgentProxyThread(threading.Thread):
def run(self):
try:
(r, addr) = self.get_connection()
+ # Found that r should be either a socket from the socket library or None
self.__inr = r
- self.__addr = addr
+ self.__addr = addr # This should be an IP address as a string? or None
self._agent.connect()
+ if not isinstance(self._agent, int) and (self._agent._conn is None or not hasattr(self._agent._conn, 'fileno')):
+ raise AuthenticationException("Unable to connect to SSH agent")
self._communicate()
except:
#XXX Not sure what to do here ... raise or pass ?
@@ -286,6 +290,26 @@ class AgentServerProxy(AgentSSH):
class AgentRequestHandler(object):
+ """
+ Primary/default implementation of SSH agent forwarding functionality.
+
+ Simply instantiate this class, handing it a live command-executing session
+ object, and it will handle forwarding any local SSH agent processes it
+ finds.
+
+ For example::
+
+ # Connect
+ client = SSHClient()
+ client.connect(host, port, username)
+ # Obtain session
+ session = client.get_transport().open_session()
+ # Forward local agent
+ AgentRequestHandler(session)
+ # Commands executed after this point will see the forwarded agent on
+ # the remote end.
+ session.exec_command("git clone https://my.git.repository/")
+ """
def __init__(self, chanClient):
self._conn = None
self.__chanC = chanClient