Use MemoryMap from jaraco.windows in lieu of mmap.mmap.
This commit is contained in:
parent
64d6734086
commit
0698254b18
|
@ -23,11 +23,12 @@ Functions for communicating with Pageant, the basic windows ssh agent program.
|
||||||
|
|
||||||
import struct
|
import struct
|
||||||
import threading
|
import threading
|
||||||
import mmap
|
|
||||||
import array
|
import array
|
||||||
import platform
|
import platform
|
||||||
import ctypes.wintypes
|
import ctypes.wintypes
|
||||||
|
|
||||||
|
import jaraco.windows.mmap as mmap
|
||||||
|
|
||||||
_AGENT_COPYDATA_ID = 0x804e50ba
|
_AGENT_COPYDATA_ID = 0x804e50ba
|
||||||
_AGENT_MAX_MSGLEN = 8192
|
_AGENT_MAX_MSGLEN = 8192
|
||||||
# Note: The WM_COPYDATA value is pulled from win32con, as a workaround
|
# Note: The WM_COPYDATA value is pulled from win32con, as a workaround
|
||||||
|
@ -61,19 +62,21 @@ class COPYDATASTRUCT(ctypes.Structure):
|
||||||
]
|
]
|
||||||
|
|
||||||
def _query_pageant(msg):
|
def _query_pageant(msg):
|
||||||
|
"""
|
||||||
|
Communication with the Pageant process is done through a shared
|
||||||
|
memory-mapped file.
|
||||||
|
"""
|
||||||
hwnd = _get_pageant_window_object()
|
hwnd = _get_pageant_window_object()
|
||||||
if not hwnd:
|
if not hwnd:
|
||||||
# Raise a failure to connect exception, pageant isn't running anymore!
|
# Raise a failure to connect exception, pageant isn't running anymore!
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
# create a name for the mmap
|
||||||
map_name = 'PageantRequest%08x' % threading.current_thread().ident
|
map_name = 'PageantRequest%08x' % threading.current_thread().ident
|
||||||
|
|
||||||
# Create the shared memory from which Pageant will read the request
|
pymap = mmap.MemoryMap(map_name, _AGENT_MAX_MSGLEN)
|
||||||
pymap = mmap.mmap(-1, _AGENT_MAX_MSGLEN, tagname=map_name,
|
with pymap:
|
||||||
access=mmap.ACCESS_WRITE)
|
|
||||||
try:
|
|
||||||
pymap.write(msg)
|
pymap.write(msg)
|
||||||
|
|
||||||
# Create an array buffer containing the mapped filename
|
# Create an array buffer containing the mapped filename
|
||||||
char_buffer = array.array("c", map_name + '\0')
|
char_buffer = array.array("c", map_name + '\0')
|
||||||
char_buffer_address, char_buffer_size = char_buffer.buffer_info()
|
char_buffer_address, char_buffer_size = char_buffer.buffer_info()
|
||||||
|
@ -90,9 +93,6 @@ def _query_pageant(msg):
|
||||||
retlen = struct.unpack('>I', datalen)[0]
|
retlen = struct.unpack('>I', datalen)[0]
|
||||||
return datalen + pymap.read(retlen)
|
return datalen + pymap.read(retlen)
|
||||||
return None
|
return None
|
||||||
finally:
|
|
||||||
pymap.close()
|
|
||||||
|
|
||||||
|
|
||||||
class PageantConnection (object):
|
class PageantConnection (object):
|
||||||
"""
|
"""
|
||||||
|
|
5
setup.py
5
setup.py
|
@ -40,7 +40,10 @@ import sys
|
||||||
try:
|
try:
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
kw = {
|
kw = {
|
||||||
'install_requires': 'pycrypto >= 2.1, != 2.4',
|
'install_requires': [
|
||||||
|
'pycrypto >= 2.1, != 2.4',
|
||||||
|
'jaraco.windows >= 2.10, <3.0dev',
|
||||||
|
],
|
||||||
}
|
}
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
|
|
Loading…
Reference in New Issue