Argument error on connect: int too long to convert #758

Closed
swohlerLL opened this Issue May 31, 2016 · 10 comments

Projects

None yet

7 participants

@swohlerLL

Attempting to perform a simple connection with IP address on local network, username and password yields the following error:
ArgumentError: argument 2: <class 'OverflowError'>: int too long to convert

I'm running this in the iPython interpreter, on a 64-bit machine with Anaconda as the base python environment:

Python 3.5.1 |Anaconda 2.5.0 (64-bit)| (default, Jan 29 2016, 15:01:46) [MSC v.1900 64 bit (AMD64)]
IPython 4.0.3 -- An enhanced Interactive Python.

The sequence of commands:

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, username=username, password=password)

The full stack trace (some identifying info commented out with ***):

C:\Users\***\Anaconda3\lib\site-packages\paramiko\client.py in connect(self, hostname, port, username, password, pkey, key_filename, timeout, allow_agent, look_for_keys, compress, sock, gss_auth, gss_kex, gss_deleg_creds, gss_host, banner_timeout)
    378             gss_host = hostname
    379         self._auth(username, password, pkey, key_filenames, allow_agent,
--> 380                    look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)
    381
    382     def close(self):

C:\Users\***\Anaconda3\lib\site-packages\paramiko\client.py in _auth(self, username, password, pkey, key_filenames, allow_agent, look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)
    528         if not two_factor and allow_agent:
    529             if self._agent is None:
--> 530                 self._agent = Agent()
    531
    532             for key in self._agent.get_keys():

C:\Users\***\Anaconda3\lib\site-packages\paramiko\agent.py in __init__(self)
    361             # no agent support
    362             return
--> 363         self._connect(conn)
    364
    365     def close(self):

C:\Users\***\Anaconda3\lib\site-packages\paramiko\agent.py in _connect(self, conn)
     64     def _connect(self, conn):
     65         self._conn = conn
---> 66         ptype, result = self._send_message(cSSH2_AGENTC_REQUEST_IDENTITIES)
     67         if ptype != SSH2_AGENT_IDENTITIES_ANSWER:
     68             raise SSHException('could not get keys from ssh-agent')

C:\Users\***\Anaconda3\lib\site-packages\paramiko\agent.py in _send_message(self, msg)
     81     def _send_message(self, msg):
     82         msg = asbytes(msg)
---> 83         self._conn.send(struct.pack('>I', len(msg)) + msg)
     84         l = self._read_all(4)
     85         msg = Message(self._read_all(struct.unpack('>I', l)[0]))

C:\Users\***\Anaconda3\lib\site-packages\paramiko\win_pageant.py in send(self, data)
    121
    122     def send(self, data):
--> 123         self._response = _query_pageant(data)
    124
    125     def recv(self, n):

C:\Users\***\Anaconda3\lib\site-packages\paramiko\win_pageant.py in _query_pageant(msg)
     87
     88     pymap = _winapi.MemoryMap(map_name, _AGENT_MAX_MSGLEN,
---> 89         _winapi.get_security_attributes_for_user(),
     90         )
     91     with pymap:

C:\Users\***\Anaconda3\lib\site-packages\paramiko\_winapi.py in get_security_attributes_for_user(user)
    362         SECURITY_DESCRIPTOR.REVISION)
    363     ctypes.windll.advapi32.SetSecurityDescriptorOwner(ctypes.byref(SD),
--> 364         user.SID, 0)
    365     return SA

ArgumentError: argument 2: <class 'OverflowError'>: int too long to convert
@birm
birm commented Jun 4, 2016 edited

I think that this is related to the confusing int sizes on x86-64 windows and advapi32.dll.

@birm birm added a commit to birm/paramiko that referenced this issue Jun 4, 2016
@birm birm fix common 64 bit issue with user SID
force user SID to be cast as longlong, brought up in #758
ba6ad13
@bitprophet
Member

Most/all of the code in _winapi.py actually comes from @jaraco's Windows module (https://github.com/jaraco/jaraco.windows), so it may be more appropriate to apply the fix there (assuming he agrees it's appropriate) and then we can upgrade our vendored copy.

@brabulla

This issue has resurfaced for me, I cannot open an ssh connection to anywhere with paramiko right now. I'm using an Anaconda 2.4.1 64-bit installation of Python 3.5.1, with paramiko 2.0.1. Tried updating paramiko, but I couldn't find a newer version.

Also, the issue is really strange, because until today, everything worked fine for me. I haven't changed anything, no windows reinstall, no python reinstall, nothing. Could have a silent windows update cause it?

@jaraco jaraco referenced this issue in jaraco/jaraco.windows Jul 21, 2016
Closed

ArgumentError: int too long to convert #7

@jaraco
Contributor
jaraco commented Jul 21, 2016

The issue has been corrected upstream (though it's quite possible there are other, related, failures that the test suite doesn't yet cover. The next step will be to re-vendor these changes into paramiko and test them. Would someone be wiling to do that?

@miso-belica

@jaraco How can I help? What should I do?

@jaraco
Contributor
jaraco commented Jul 21, 2016

Awesome. Thanks for offering to help @miso-belica.

The _winapi.py module in paramiko is just copy-pasta from the jaraco.windows distribution. To update the repo, check out that project and then walk through _winapi.py and everyplace you see

#########################
# jaraco.windows.security

or similar, replace the content with the contents from that module in jaraco.windows. You'll want to disregard imports... and there may be other aspects that you can disregard. It's been a while since I've last done it.

With any luck, when you're done, the diff on the _winapi.py should look very similar to this diff.

@bitprophet bitprophet added this to the 1.16.3 et al milestone Jul 21, 2016
@miso-belica

@jaraco I ended with this diff

diff --git a/paramiko/_winapi.py b/paramiko/_winapi.py
index 77e0129..94bf601 100644
--- a/paramiko/_winapi.py
+++ b/paramiko/_winapi.py
@@ -118,6 +118,18 @@ CreateFileMapping.restype = ctypes.wintypes.HANDLE
 MapViewOfFile = ctypes.windll.kernel32.MapViewOfFile
 MapViewOfFile.restype = ctypes.wintypes.HANDLE

+UnmapViewOfFile = ctypes.windll.kernel32.UnmapViewOfFile
+UnmapViewOfFile.argtypes = ctypes.wintypes.HANDLE,
+
+RtlMoveMemory = ctypes.windll.kernel32.RtlMoveMemory
+RtlMoveMemory.argtypes = (
+    ctypes.c_void_p,
+    ctypes.c_void_p,
+    ctypes.c_size_t,
+)
+
+ctypes.windll.kernel32.LocalFree.argtypes = ctypes.wintypes.HLOCAL,
+
 #####################
 # jaraco.windows.mmap

@@ -307,6 +319,13 @@ class SECURITY_ATTRIBUTES(ctypes.Structure):
         self._descriptor = value
         self.lpSecurityDescriptor = ctypes.addressof(value)

+
+ctypes.windll.advapi32.SetSecurityDescriptorOwner.argtypes = (
+    ctypes.POINTER(SECURITY_DESCRIPTOR),
+    ctypes.c_void_p,
+    ctypes.wintypes.BOOL,
+)
+
 #########################
 # jaraco.windows.security

And works like a charm 🙌 Is it possible to release new version of paramiko with this? This annoys me very long time :( Thanks for all your work.

@jaraco
Contributor
jaraco commented Jul 22, 2016

Looks good to me. I'll apply that and submit a PR. Thanks for testing.

@bk8190
bk8190 commented Jul 25, 2016

That diff also worked for me

@bitprophet
Member

Merged PR, this will be out in next bugfix release (today).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment