Commit Graph

607 Commits

Author SHA1 Message Date
Mike Gabriel 81f87f1d5e Load host entries from the known_hosts file(s) before writing the file from RAM to disk. Avoids loss of host entries in case other SSH clients have written to the known_hosts file(s) meanwhile. 2013-04-27 20:36:45 -07:00
Mike Gabriel 080bece258 Assure that host entries in known_hosts files do not duplicate endlessly if keys from known_hosts are loaded via HostKeys.load() more than once (e.g. for refreshing the list of known hosts during runtime). 2013-04-27 20:36:45 -07:00
Mike Gabriel 4f481a57a2 Store hostname hashes in memory rathen than the non-hashed host entries. Also assures that the host entries in known_hosts get saved in hashed format as it is currently standard in OpenSSH. 2013-04-27 20:36:45 -07:00
Steven Noonan 5c124cb136 un-break Python 2.5 compatibility by using isAlive() instead of is_alive()
Python's documentation has a bug[1], in that it doesn't correctly annotate
is_alive as being a function introduced in Python 2.6.

[1] http://bugs.python.org/issue15126

Signed-off-by: Steven Noonan <snoonan@amazon.com>
2013-04-11 16:27:49 -07:00
Frank Arnold 068bf63cf0 transport: Wait for thread termination before closing the socket
Make sure the Thread.run() method has terminated before closing the
socket. Currently, the socket is closed through Packetizer.close(),
which happens too early. Move the socket.close() into Transport.close()
and after the Thread.join() call.

While at it, modify the stop_thread() method and use it in
Transport.close() to avoid code duplication. Use join() with a timeout
to make it possible to terminate the main thread with KeyboardInterrupt.
Also, remove the now obsolete socket.close() from Transport.atfork().

This fixes a potential infinite loop if paramiko.SSHClient is connected
through a paramiko.Channel instead of a regular socket (tunneling).

Details:

Using a debug patch to dump the current stack of the thread every
couple of seconds while trying to close it, I've seen the following
over and over again:

Thread could not be stopped, still running.
Current traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 524, in __bootstrap
    self.__bootstrap_inner()
  File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
    self.run()
  File ".../paramiko/transport.py", line 1564, in run
    self._channel_handler_table[ptype](chan, m)
  File ".../paramiko/channel.py", line 1102, in _handle_close
    self.transport._send_user_message(m)
  File ".../paramiko/transport.py", line 1418, in _send_user_message
    self._send_message(data)
  File ".../paramiko/transport.py", line 1398, in _send_message
    self.packetizer.send_message(data)
  File ".../paramiko/packet.py", line 319, in send_message
    self.write_all(out)
  File ".../paramiko/packet.py", line 248, in write_all
    n = self.__socket.send(out)
  File ".../paramiko/channel.py", line 732, in send
    self.lock.release()

The thread was running Packetizer.write_all() in an endless loop:

while len(out) > 0:
    ...
    n = Channel.send(out) # n == 0 because channel got closed
    ...
    out = out[n:]         # essentially out = out

Signed-off-by: Frank Arnold <farnold@amazon.com>
2013-04-11 16:14:21 -07:00
Jeff Forcier b329512636 Merge branch '1.10'
Conflicts:
	NEWS
2013-04-05 13:02:11 -07:00
Jeff Forcier 02d071be07 Bump version to 1.10.1 2013-04-05 13:00:19 -07:00
Kevin Tegtmeier 2e2a915807 Fix bug that leaves fds in select after EOF received 2013-04-05 11:54:48 -07:00
Jeff Forcier 73a0d03bdc Merge branch '1.10'
Conflicts:
	NEWS
2013-04-05 11:51:47 -07:00
Ethan Glasser-Camp ebdbfae5b1 Hook up ECDSA to hostkeys
More sophisticated key negotiation is still necessary in the case
where we have an ECDSA key for the server and it offers us both RSA
and ECDSA. In this case, we will pick RSA and fail because we don't
have it. Instead, we should pick ECDSA. Still, this works if you tell
your server to only offer ECDSA keys :)
2013-03-25 12:19:29 -04:00
Ethan Glasser-Camp 632129c427 Introduce ECDSA
This just adds tests; hooking this up with paramiko comes in the next
commit.
2013-03-25 12:19:21 -04:00
Jeff Forcier a7ee2509e4 Merge branch 'master' into 112-int
Conflicts:
	paramiko/win_pageant.py
2013-03-19 13:36:52 -07:00
Jason R. Coombs c305691492 Remove dependency on pywin32. Just use ctypes for simplicity. 2013-03-19 13:24:31 -07:00
Jason R. Coombs 9858ccf207 Remove test for presence of ctypes (assumed present in global imports). 2013-03-19 13:24:31 -07:00
Jason R. Coombs 3cd7f585d0 Remove 'file_size' check from tests. The docstring indicates this parameter is to be passed to the callback, and there's no reason to think this parameter is relevant in affecting whether a useful stat object has been passed (especially when the 'confirm' parameter is explicitly supplied for that decision. This fixes #142. 2013-03-04 08:46:39 -05:00
Olle Lundberg bd1a97a045 Speed up the write operation by bulk calling read.
Bulk check the ACKs from the server every 32MB
(or every write request). This way you gain speed
but also making sure not to get the error too late
in a large transfer.
This works for smaller files too, since there is a
cleanup routine being called when the file has been transfered.
2013-03-01 11:39:13 -08:00
Phillip Heller edc9eaf4f2 Added width_pixel and height_pixel parameters to Channel.get_pty() and
resize_pty(), and Client.invoke_shell().  Perhaps useless, but more RFC
compliant.  Updated methods to include these parameters in server messages.

Adjusted Channel.resize_pty() to neither request nor wait for a response, as
per RFC 4254 6.7 (A response SHOULD NOT be sent to this message.)  This is
necessary as certain hosts have been observed to not acknowledge this type of
channel request (Cisco IOS XR), which causes paramiko to end the session.
2013-03-01 10:33:03 -08:00
Olle Lundberg 1903ee1432 Pep8 fixes 2013-02-28 12:52:01 +01:00
Olle Lundberg 732417bf98 Merge branch 'openssh-compatibility' of github.com:lndbrg/paramiko into openssh-compatibility
Conflicts:
	paramiko/config.py
	tests/test_util.py
2013-02-28 12:51:00 +01:00
Olle Lundberg 06f9704820 Pep8 fixes 2013-02-28 12:45:07 +01:00
Olle Lundberg 93dce43e86 Fix argument passed to LazyFqdn 2013-02-28 12:36:21 +01:00
Olle Lundberg f41fc8fd28 Create a copy of the identityfile list.
The copy is needed else the original
identityfile list is in the internal
config list is updated when we modify
the return dictionary.
2013-02-28 12:31:59 +01:00
Olle Lundberg ea3c3f53b6 DRY up the code for populating the return list 2013-02-28 12:14:59 +01:00
Olle Lundberg c79e6a3f92 Whitespace fixes. 2013-02-28 12:14:59 +01:00
Olle Lundberg 32424ba109 Be more pythonic. 2013-02-28 12:11:41 +01:00
Olle Lundberg ac1310c4a1 Implement support for parsing proxycommand. 2013-02-28 12:11:41 +01:00
Olle Lundberg 42d77483e8 Pep8 fixes 2013-02-28 12:10:55 +01:00
Olle Lundberg 85551dffd6 Spelling 2013-02-28 12:08:59 +01:00
Olle Lundberg 57d776b318 Add host negation support to paramiko config.
This is a rewrite of the SSHConfig class to
conform with the rules specified by the
manpage for ssh_config.
This change also adds support for negation
according to the rules introduced by
OpenSSH 5.9. Reference:
http://www.openssh.com/txt/release-5.9
2013-02-28 12:08:59 +01:00
Jeff Forcier 3563fca994 Refactor duplicative code re #110 2013-02-27 19:54:22 -08:00
John Hensley 9d2fb82284 Document SSHConfig FQDN logic.
Merged with pre-picked changes re #128.

Conflicts:
	paramiko/config.py
2013-02-27 19:48:50 -08:00
Parantapa Bhattacharya 2f1daad1b9 Compute host's FQDN on demand only 2013-02-27 19:03:49 -08:00
Jeff Forcier 7e5911a1ff Give sdctr a default value for backwards+test compat
Re #102
2013-02-27 18:50:37 -08:00
Kent Gibson adad068b13 Don't random pad packets for SDCTR ciphers 2013-02-27 18:47:04 -08:00
Jeff Forcier 8e697988af Changelog + docs re #127 2013-02-27 15:56:09 -08:00
Jeff Forcier a69abd4606 Merge pull request #127 from mwilliamson/sftp-file-context-manager
Turn SFTPFile into a context manager
2013-02-27 15:50:48 -08:00
Jeff Forcier 37d0247301 Merge pull request #116 from mvschaik/patch-1
Limit memory allocation of get_bytes to 1MB
2013-02-27 15:31:20 -08:00
Jeff Forcier 6b5d748358 Merge pull request #115 from mvanderkolff/master
Add get_pty named argument to SSHClient.exec_command()
2013-02-03 12:53:35 -08:00
Jeff Forcier 0c56e2a40b Merge branch '1.9' 2013-02-03 11:52:36 -08:00
Jeff Forcier 6284666cfd Merge branch '1.8' into 1.9 2013-02-03 11:52:30 -08:00
Jeff Forcier bf87cd124d Update explicitly-stated Python version reqs to 2.5+ 2013-02-03 11:52:11 -08:00
Michael Williamson 602250fdf9 Turn SFTPFile into a context manager 2013-01-04 23:43:15 +00:00
Jason R. Coombs 6c4c00a3f3 Merge changes from no_pywin32 2012-12-02 07:12:37 -05:00
Jason R. Coombs 7bde7840dd Merge with master 2012-12-02 06:48:32 -05:00
Jason R. Coombs 9f21d36040 Restore Python 2.5 compatibility w.r.t with statement. 2012-11-30 20:26:21 -05:00
Maarten 3bbcf808d8 Limit memory allocation of get_bytes to 1MB
If get_bytes() can pad unlimited, a RSA pub key could be crafted
that would allocate GB's of nulls, thereby forming a DoS-vector.
2012-11-30 15:14:49 +01:00
Michael van der Kolff cd51bfc031 Add support for get_pty to SSHClient.exec_command() 2012-11-30 22:02:09 +11:00
Jeff Forcier 2cbe383080 Apply put() version of #90 2012-11-29 16:16:35 -08:00
Eric Buehl 9c0d467667 allow uploading of files from an open file object 2012-11-29 16:09:47 -08:00
Jeff Forcier 531606b0d6 Revert "Make send() and recv() fail when channel is closed"
This reverts commit 23f3099b6f.
2012-11-29 15:19:56 -08:00
Jeff Forcier 2223aa10cc Revert "Forgot to import errno"
This reverts commit 668870aa83.
2012-11-29 15:19:50 -08:00
Jeff Forcier 287f9c3423 Revert "Forgot to import errno"
This reverts commit 203c7379ac.
2012-11-29 15:19:15 -08:00
Jeff Forcier bda161330f Revert "Make send() and recv() fail when channel is closed"
This reverts commit 8496eff0b7.
2012-11-29 15:19:07 -08:00
Jeff Forcier 682a3eff84 Revert "Forgot to import errno"
This reverts commit 537f95dbb3.
2012-11-29 15:18:48 -08:00
Jeff Forcier 7a4d3c4e42 Revert "Make send() and recv() fail when channel is closed"
This reverts commit bc3674d0f0.
2012-11-29 15:18:40 -08:00
Tomer Filiba 203c7379ac Forgot to import errno 2012-11-29 14:55:34 -08:00
Tomer Filiba 8496eff0b7 Make send() and recv() fail when channel is closed
``sendall()`` was checking if the channel has been closed,
and failed accordingly, but ``send()`` and ``recv()`` did not.
This meant that ``chan.send("foo")`` when the channel was already
closed, just blocked forever.
2012-11-29 14:55:31 -08:00
Tomer Filiba 537f95dbb3 Forgot to import errno 2012-11-29 14:38:33 -08:00
Tomer Filiba bc3674d0f0 Make send() and recv() fail when channel is closed
``sendall()`` was checking if the channel has been closed,
and failed accordingly, but ``send()`` and ``recv()`` did not.
This meant that ``chan.send("foo")`` when the channel was already
closed, just blocked forever.
2012-11-29 14:38:23 -08:00
Jeff Forcier 962d4a3cec Merge pull request #99 from tomerfiliba/patch-1
Make send() and recv() fail when channel is closed
2012-11-29 14:35:19 -08:00
Jeff Forcier b9c39fc1d2 Merge pull request #95 from Bockit/master
Add a closed property to BufferedFile
2012-11-29 08:53:53 -08:00
Jeff Forcier 2575b3efc4 Fix #94 2012-11-29 08:52:39 -08:00
Jeff Forcier 2403504b44 Fix #113: add timeout passthru to exec_command 2012-11-28 22:22:33 -08:00
Jeff Forcier 10c51e2726 Bump dev version to 1.10 2012-11-28 22:18:44 -08:00
Jason R. Coombs 13892788c3 Copied code from jaraco.windows rather than requiring it as a dependency. 2012-11-23 14:15:33 -05:00
Jason R. Coombs c0ef3fd493 Create the memory map with the security attributes for the current user (rather than the default) to avoid permissions failures when the client and the agent run in different UAC contexts. Fixes #98. 2012-11-23 14:08:16 -05:00
Jason R. Coombs 0698254b18 Use MemoryMap from jaraco.windows in lieu of mmap.mmap. 2012-11-23 14:03:20 -05:00
Jason R. Coombs 64d6734086 Simplify pageant implementation by using an anonymous mmap instead of an explicit file. Requires Python 2.5. 2012-11-23 13:07:28 -05:00
Olle Lundberg a07a339006 Create a copy of the identityfile list.
The copy is needed else the original
identityfile list is in the internal
config list is updated when we modify
the return dictionary.
2012-11-20 12:43:40 +01:00
Olle Lundberg 78654e82ec DRY up the code for populating the return list 2012-11-20 00:45:32 +01:00
Jeff Forcier 7f4c26f860 Cut 1.8.1 2012-11-06 13:08:41 -08:00
Jeff Forcier a3b44c7ed9 Bump to 1.9.0 for release 2012-11-06 13:06:08 -08:00
Jeff Forcier ebd007b217 Python 2.5 compat 2012-11-05 23:10:13 -08:00
Jeff Forcier e7ab3c068f Fix broken import 2012-11-05 23:10:05 -08:00
Jeff Forcier 308c5f57d9 Add ProxyCommand classes to top level API 2012-11-05 23:09:52 -08:00
Jeff Forcier fd392d6b20 One more patch from @clarete's work 2012-11-05 17:47:33 -08:00
Jeff Forcier 191a5fc08c Implement (& test for) ProxyCommand interpolation.
Forgot this earlier.
2012-11-05 17:44:25 -08:00
Jeff Forcier 0981c25cd8 Formatting 2012-11-05 17:35:06 -08:00
Jeff Forcier 0a276ac34b Bubble up ProxyCommandFailure in packetizer 2012-11-05 17:31:17 -08:00
Jeff Forcier 394ab2699e Post-import edits 2012-11-05 17:29:32 -08:00
Jeff Forcier 5d15467ad4 Import BadProxyCommand 2012-11-05 17:29:23 -08:00
Jeff Forcier 27271fa455 Post-import edits 2012-11-05 17:26:47 -08:00
Jeff Forcier 7cd2f2715b Initial port of ProxyCommand class from @clarete 2012-11-05 17:25:03 -08:00
Jeff Forcier 270bb94a46 Fix ProxyCommand equals splitting.
Uses regex approach from @lndbrg
2012-11-05 17:18:48 -08:00
Jeff Forcier f9b7ce902f Tweak docstring re #77 2012-11-05 13:30:56 -08:00
Steven Noonan 31ea4f0734 SSHClient: add 'sock' parameter to connect() for tunneling
Re #77

This parameter, if set, can be used to make Paramiko wrap an existing socket
connected to a remote SSH server. For instance, you could set up another
SSHClient directly connected to a "gateway" host, and then create a direct-tcpip
tunnel to a "target" host directly accessible from the gateway's perspective
(e.g. think of trying to establish an SSH connection to hosts behind a NAT).
The gateway host would then establish a TCP connection to the target host
directly, and a channel is exposed on the client side. This channel could be
wrapped by an SSHClient class using the connect() function, avoiding the need
to establish a new TCP connnection.

This effectively allows you to create tunneled SSH connections.

Based on work by Oskari Saarenmaa <os@ohmu.fi>, in Paramiko pull request #39.

Signed-off-by: Steven Noonan <steven@uplinklabs.net>
2012-11-05 13:30:48 -08:00
Jason R. Coombs 45aa88b530 Remove dependency on pywin32. Just use ctypes for simplicity. 2012-11-01 10:09:41 -04:00
Jason R. Coombs e0d71b5efb Remove test for presence of ctypes (assumed present in global imports). 2012-11-01 10:03:46 -04:00
Tomer Filiba 668870aa83 Forgot to import errno 2012-10-26 15:46:28 +03:00
Tomer Filiba 23f3099b6f Make send() and recv() fail when channel is closed
``sendall()`` was checking if the channel has been closed, 
and failed accordingly, but ``send()`` and ``recv()`` did not.
This meant that ``chan.send("foo")`` when the channel was already
closed, just blocked forever.
2012-10-26 15:44:34 +03:00
James Hiscock c78a5856e8 Update paramiko/file.py
Added a closed property as an alternative accessor to BufferedFile's _closed property.
2012-10-17 14:25:22 +12:00
Olle Lundberg 04cc4d5510 Be more pythonic. 2012-10-16 16:54:44 +02:00
Olle Lundberg 7ce9875ed7 Implement support for parsing proxycommand. 2012-10-16 16:38:38 +02:00
Olle Lundberg b22c11ab1b Pep8 fixes 2012-10-16 15:00:08 +02:00
Olle Lundberg 2dd74f953d Spelling 2012-10-16 14:52:27 +02:00
Olle Lundberg ad587fa0ef Add host negation support to paramiko config.
This is a rewrite of the SSHConfig class to
conform with the rules specified by the
manpage for ssh_config.
This change also adds support for negation
according to the rules introduced by
OpenSSH 5.9. Reference:
http://www.openssh.com/txt/release-5.9
2012-10-16 13:57:05 +02:00
Jeff Forcier 1341e28882 Move SFTPClient.get() termination condition to loop end.
Ensures callback always executes even for zero-len files.

Fixes #90
2012-10-14 21:46:50 -07:00
Jeff Forcier 2e016358ef Whitespace + lang tweak 2012-09-25 18:09:35 -07:00
Jeff Forcier 30a2d14b78 Init header update 2012-09-25 18:05:01 -07:00
Jeff Forcier dd6fb2577d Bump to 0.8.x due to nontrivial changes
(cherry picked from commit d7def60c4784fed39fc8714753304a150da131c7)

Conflicts:
	setup.py
2012-09-24 19:00:19 -07:00