Parent

Class Index [+]

Quicksearch

Net::SSH::Authentication::Pageant::Socket

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.

Public Class Methods

new() click to toggle source

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 109
109:       def initialize
110:         @win = Win.FindWindow("Pageant", "Pageant")
111: 
112:         if @win == 0
113:           raise Net::SSH::Exception,
114:             "pageant process not running"
115:         end
116: 
117:         @res = nil
118:         @pos = 0
119:       end
open(location=nil) click to toggle source

The factory method for creating a new Socket instance. The location parameter is ignored, and is only needed for compatibility with the general Socket interface.

     # File lib/net/ssh/authentication/pageant.rb, line 103
103:       def self.open(location=nil)
104:         new
105:       end

Public Instance Methods

close() click to toggle source

Conceptually close the socket. This doesn’t really do anthing significant, but merely complies with the Socket interface.

     # File lib/net/ssh/authentication/pageant.rb, line 174
174:       def close
175:         @res = nil
176:         @pos = 0
177:       end
closed?() click to toggle source

Conceptually asks if the socket is closed. As with #, this doesn’t really do anything significant, but merely complies with the Socket interface.

     # File lib/net/ssh/authentication/pageant.rb, line 182
182:       def closed?
183:         @res.nil? && @pos.zero?
184:       end
read(n = nil) click to toggle source

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 188
188:       def read(n = nil)
189:         return nil unless @res
190:         if n.nil?
191:           start, @pos = @pos, @res.size
192:           return @res[start..1]
193:         else
194:           start, @pos = @pos, @pos + n
195:           return @res[start, n]
196:         end
197:       end
send(data, *args) click to toggle source

Forwards the data to #, ignoring any arguments after the first. Returns 0.

     # File lib/net/ssh/authentication/pageant.rb, line 123
123:       def send(data, *args)
124:         @res = send_query(data)
125:         @pos = 0
126:       end
send_query(query) click to toggle source

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 # is called.

     # File lib/net/ssh/authentication/pageant.rb, line 131
131:       def send_query(query)
132:         res = nil
133:         filemap = 0
134:         ptr = nil
135:         id = DL::PtrData.malloc(DL.sizeof("L"))
136: 
137:         mapname = "PageantRequest%08x\0000" % Win.getCurrentThreadId()
138:         filemap = Win.createFileMapping(Win::INVALID_HANDLE_VALUE, 
139:                                         Win::NULL,
140:                                         Win::PAGE_READWRITE, 0, 
141:                                         AGENT_MAX_MSGLEN, mapname)
142:         if filemap == 0
143:           raise Net::SSH::Exception,
144:             "Creation of file mapping failed"
145:         end
146: 
147:         ptr = Win.mapViewOfFile(filemap, Win::FILE_MAP_WRITE, 0, 0, 
148:                                 AGENT_MAX_MSGLEN)
149: 
150:         if ptr.nil? || ptr.null?
151:           raise Net::SSH::Exception, "Mapping of file failed"
152:         end
153: 
154:         ptr[0] = query
155: 
156:         cds = [AGENT_COPYDATA_ID, mapname.size + 1, mapname].
157:           pack("LLp").to_ptr
158:         succ = Win.sendMessageTimeout(@win, Win::WM_COPYDATA, Win::NULL,
159:                                       cds, Win::SMTO_NORMAL, 5000, id)
160: 
161:         if succ > 0
162:           retlen = 4 + ptr.to_s(4).unpack("N")[0]
163:           res = ptr.to_s(retlen)
164:         end        
165: 
166:         return res
167:       ensure
168:         Win.unmapViewOfFile(ptr) unless ptr.nil? || ptr.null?
169:         Win.closeHandle(filemap) if filemap != 0
170:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.