class ROM::LDAP::Client
Uses socket to read and write using BER encoding.
@api private
@api private
@api private
Attributes
socket[R]
Public Instance Methods
alive?()
click to toggle source
@return [Boolean]
# File lib/rom/ldap/client.rb, line 77 def alive? return false if closed? if IO.select([socket], nil, nil, 0) begin !socket.eof? rescue StandardError false end else true end rescue IOError false end
close()
click to toggle source
@return [NilClass]
# File lib/rom/ldap/client.rb, line 68 def close return if socket.nil? socket.close @socket = nil end
closed?()
click to toggle source
@return [Boolean]
# File lib/rom/ldap/client.rb, line 62 def closed? socket.nil? || (socket.is_a?(::Socket) && socket.closed?) end
open() { |socket| ... }
click to toggle source
Create connection (encrypted) and authenticate.
@yield [Socket]
@raise [BindError, SecureBindError]
# File lib/rom/ldap/client.rb, line 44 def open unless alive? @socket = Socket.new(**options).call # tls if ssl start_tls sasl_bind # (mechanism:, credentials:, challenge:) end bind(**auth) unless auth.nil? # simple auth end yield(@socket) end
Private Instance Methods
from_queue(message_id)
click to toggle source
@return [PDU]
@api private
# File lib/rom/ldap/client.rb, line 135 def from_queue(message_id) if (pdu = queue[message_id].shift) return pdu end while (pdu = read) return pdu if pdu.message_id.eql?(message_id) queue[pdu.message_id].push(pdu) next end pdu end
next_msgid()
click to toggle source
Increment the message counter.
@return [Integer]
@api private
# File lib/rom/ldap/client.rb, line 155 def next_msgid @msgid ||= 0 @msgid += 1 end
pdu_lookup(symbol)
click to toggle source
@see BER
@param symbol [Symbol]
@return [Integer]
# File lib/rom/ldap/client.rb, line 100 def pdu_lookup(symbol) ::BER.fetch(:response, symbol) end
read()
click to toggle source
Read from socket and wrap in PDU
class.
@return [PDU, NilClass]
# File lib/rom/ldap/client.rb, line 107 def read open do |socket| return unless (ber_object = socket.read_ber) PDU.new(*ber_object) end rescue Errno::ECONNRESET close retry end
submit(type, request, controls = nil)
click to toggle source
Persist changes to the server and return response object. Enable stdout debugging with DEBUG=y.
@return [PDU]
@raise [ResponseError]
@api private
# File lib/rom/ldap/client.rb, line 168 def submit(type, request, controls = nil) message_id = next_msgid write(request, message_id, controls) pdu = from_queue(message_id) if pdu&.app_tag == pdu_lookup(type) puts pdu.advice if ENV['DEBUG'] && pdu.advice && !pdu.advice.empty? pdu else raise(ResponseError, "Invalid #{type}") end end
write(request, message_id, controls = nil)
click to toggle source
Write to socket.
@api private
# File lib/rom/ldap/client.rb, line 121 def write(request, message_id, controls = nil) open do |socket| packet = [message_id.to_ber, request, controls].compact.to_ber_sequence socket.write(packet) socket.flush end rescue Errno::EPIPE, IOError close retry end