diff options
author | Christopher Hunt <chrahunt@gmail.com> | 2014-05-11 19:23:29 -0400 |
---|---|---|
committer | Christopher Hunt <chrahunt@gmail.com> | 2014-05-11 19:23:29 -0400 |
commit | 3630ccf34fc32d608e9cce0a488cfdd5884e1b0b (patch) | |
tree | c8fd0f6a4db5ec6c84475fa1e8e6c65bff4fc6a3 | |
parent | 9e8093cf569421d29406bbdc444347e62d3677b7 (diff) | |
download | net-ssh-3630ccf34fc32d608e9cce0a488cfdd5884e1b0b.tar.gz |
Remove unnecessary unicode code, fix length determination and implement KeeAgent support.
-rw-r--r-- | lib/net/ssh/authentication/pageant.rb | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/lib/net/ssh/authentication/pageant.rb b/lib/net/ssh/authentication/pageant.rb index 20d53e7..885054f 100644 --- a/lib/net/ssh/authentication/pageant.rb +++ b/lib/net/ssh/authentication/pageant.rb @@ -70,8 +70,8 @@ module Net; module SSH; module Authentication # args: hFile, (ignored), flProtect, dwMaximumSizeHigh, # dwMaximumSizeLow, lpName - extern 'HANDLE CreateFileMapping(HANDLE, void *, DWORD, DWORD, ' + - 'DWORD, LPCTSTR)' + extern 'HANDLE CreateFileMapping(HANDLE, void *, DWORD, ' + + 'DWORD, DWORD, LPCTSTR)' # args: hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh, # dwfileOffsetLow, dwNumberOfBytesToMap @@ -111,8 +111,6 @@ module Net; module SSH; module Authentication # args: pSecurityDescriptor extern 'BOOL IsValidSecurityDescriptor(LPVOID)' - extern 'BOOL IsWindowUnicode(HWND)' - # Constants needed for security attribute retrieval. # Specifies the access mask corresponding to the desired access # rights. @@ -151,7 +149,6 @@ module Net; module SSH; module Authentication openProcessToken getTokenInformation getLastError - isWindowUnicode getCurrentThreadId createFileMapping mapViewOfFile @@ -188,7 +185,6 @@ module Net; module SSH; module Authentication end end - def self.get_security_attributes_for_user user = get_current_user @@ -287,11 +283,6 @@ module Net; module SSH; module Authentication "pageant process not running" end - res = Win.IsWindowUnicode(@win) - - @unicode = (res != 0) - puts @unicode - @input_buffer = Net::SSH::Buffer.new @output_buffer = Net::SSH::Buffer.new end @@ -334,9 +325,10 @@ module Net; module SSH; module Authentication mapname = "PageantRequest%08x\000" % Win.GetCurrentThreadId() security_attributes = Win.get_ptr Win.get_security_attributes_for_user - filemap = Win.CreateFileMapping(Win::INVALID_HANDLE_VALUE, + + filemap = Win.CreateFileMapping(Win::INVALID_HANDLE_VALUE, security_attributes, - Win::PAGE_READWRITE, 0, + Win::PAGE_READWRITE, 0, AGENT_MAX_MSGLEN, mapname) if filemap == 0 || filemap == Win::INVALID_HANDLE_VALUE @@ -353,7 +345,11 @@ module Net; module SSH; module Authentication Win.set_ptr_data(ptr, query) - cds = Win.get_ptr [AGENT_COPYDATA_ID, mapname.size + 1, + # The second element should be (mapname.size + 1) to mirror the + # implementation in PuTTY/Pageant. Because strlen in C does not + # count null-terminator but String#size in Ruby does, we will + # leave it as-is and call it even. + cds = Win.get_ptr [AGENT_COPYDATA_ID, mapname.size, mapname].pack("LLp") succ = Win.SendMessageTimeout(@win, Win::WM_COPYDATA, Win::NULL, cds, Win::SMTO_NORMAL, 5000, id) |