| Class | Net::SSH::Authentication::Pageant::Socket |
| In: |
lib/net/ssh/authentication/pageant.rb
lib/net/ssh/authentication/pageant.rb |
| Parent: | Object |
This is the pseudo-socket implementation that mimics the interface of a socket, translating each request into a Windows messaging call to the pageant daemon. This allows pageant support to be implemented simply by replacing the socket factory used by the Agent class.
Create a new instance that communicates with the running pageant instance. If no such instance is running, this will cause an error.
# File lib/net/ssh/authentication/pageant.rb, line 89
89: def initialize
90: @win = Win.findWindow("Pageant", "Pageant")
91:
92: if @win == 0
93: raise Net::SSH::Exception,
94: "pageant process not running"
95: end
96:
97: @res = nil
98: @pos = 0
99: end
Reads n bytes from the cached result of the last query. If n is nil, returns all remaining data from the last query.
# File lib/net/ssh/authentication/pageant.rb, line 168
168: def read(n = nil)
169: return nil unless @res
170: if n.nil?
171: start, @pos = @pos, @res.size
172: return @res[start..-1]
173: else
174: start, @pos = @pos, @pos + n
175: return @res[start, n]
176: end
177: end
Reads n bytes from the cached result of the last query. If n is nil, returns all remaining data from the last query.
# File lib/net/ssh/authentication/pageant.rb, line 168
168: def read(n = nil)
169: return nil unless @res
170: if n.nil?
171: start, @pos = @pos, @res.size
172: return @res[start..-1]
173: else
174: start, @pos = @pos, @pos + n
175: return @res[start, n]
176: end
177: end
Forwards the data to send_query, ignoring any arguments after the first. Returns 0.
# File lib/net/ssh/authentication/pageant.rb, line 103
103: def send(data, *args)
104: @res = send_query(data)
105: @pos = 0
106: end
Forwards the data to send_query, ignoring any arguments after the first. Returns 0.
# File lib/net/ssh/authentication/pageant.rb, line 103
103: def send(data, *args)
104: @res = send_query(data)
105: @pos = 0
106: end
Packages the given query string and sends it to the pageant process via the Windows messaging subsystem. The result is cached, to be returned piece-wise when read is called.
# File lib/net/ssh/authentication/pageant.rb, line 111
111: def send_query(query)
112: res = nil
113: filemap = 0
114: ptr = nil
115: id = DL::PtrData.malloc(DL.sizeof("L"))
116:
117: mapname = "PageantRequest%08x\000" % Win.getCurrentThreadId()
118: filemap = Win.createFileMapping(Win::INVALID_HANDLE_VALUE,
119: Win::NULL,
120: Win::PAGE_READWRITE, 0,
121: AGENT_MAX_MSGLEN, mapname)
122: if filemap == 0
123: raise Net::SSH::Exception,
124: "Creation of file mapping failed"
125: end
126:
127: ptr = Win.mapViewOfFile(filemap, Win::FILE_MAP_WRITE, 0, 0,
128: AGENT_MAX_MSGLEN)
129:
130: if ptr.nil? || ptr.null?
131: raise Net::SSH::Exception, "Mapping of file failed"
132: end
133:
134: ptr[0] = query
135:
136: cds = [AGENT_COPYDATA_ID, mapname.size + 1, mapname].
137: pack("LLp").to_ptr
138: succ = Win.sendMessageTimeout(@win, Win::WM_COPYDATA, Win::NULL,
139: cds, Win::SMTO_NORMAL, 5000, id)
140:
141: if succ > 0
142: retlen = 4 + ptr.to_s(4).unpack("N")[0]
143: res = ptr.to_s(retlen)
144: end
145:
146: return res
147: ensure
148: Win.unmapViewOfFile(ptr) unless ptr.nil? || ptr.null?
149: Win.closeHandle(filemap) if filemap != 0
150: end
Packages the given query string and sends it to the pageant process via the Windows messaging subsystem. The result is cached, to be returned piece-wise when read is called.
# File lib/net/ssh/authentication/pageant.rb, line 111
111: def send_query(query)
112: res = nil
113: filemap = 0
114: ptr = nil
115: id = DL::PtrData.malloc(DL.sizeof("L"))
116:
117: mapname = "PageantRequest%08x\000" % Win.getCurrentThreadId()
118: filemap = Win.createFileMapping(Win::INVALID_HANDLE_VALUE,
119: Win::NULL,
120: Win::PAGE_READWRITE, 0,
121: AGENT_MAX_MSGLEN, mapname)
122: if filemap == 0
123: raise Net::SSH::Exception,
124: "Creation of file mapping failed"
125: end
126:
127: ptr = Win.mapViewOfFile(filemap, Win::FILE_MAP_WRITE, 0, 0,
128: AGENT_MAX_MSGLEN)
129:
130: if ptr.nil? || ptr.null?
131: raise Net::SSH::Exception, "Mapping of file failed"
132: end
133:
134: ptr[0] = query
135:
136: cds = [AGENT_COPYDATA_ID, mapname.size + 1, mapname].
137: pack("LLp").to_ptr
138: succ = Win.sendMessageTimeout(@win, Win::WM_COPYDATA, Win::NULL,
139: cds, Win::SMTO_NORMAL, 5000, id)
140:
141: if succ > 0
142: retlen = 4 + ptr.to_s(4).unpack("N")[0]
143: res = ptr.to_s(retlen)
144: end
145:
146: return res
147: ensure
148: Win.unmapViewOfFile(ptr) unless ptr.nil? || ptr.null?
149: Win.closeHandle(filemap) if filemap != 0
150: end