Return PDU instead of result code
This commit is contained in:
parent
63db8c836a
commit
2763040162
4 changed files with 74 additions and 30 deletions
|
@ -629,11 +629,10 @@ class Net::LDAP
|
|||
yield entry if block_given?
|
||||
}
|
||||
else
|
||||
@result = 0
|
||||
begin
|
||||
conn = Net::LDAP::Connection.new(:host => @host, :port => @port,
|
||||
:encryption => @encryption)
|
||||
if (@result = conn.bind(args[:auth] || @auth)) == 0
|
||||
if (@result = conn.bind(args[:auth] || @auth)).result_code == 0
|
||||
@result = conn.search(args) { |entry|
|
||||
result_set << entry if result_set
|
||||
yield entry if block_given?
|
||||
|
@ -645,9 +644,9 @@ class Net::LDAP
|
|||
end
|
||||
|
||||
if return_result_set
|
||||
@result == 0 ? result_set : nil
|
||||
(!@result.nil? && @result.result_code == 0) ? result_set : nil
|
||||
else
|
||||
@result == 0
|
||||
@result
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -721,7 +720,7 @@ class Net::LDAP
|
|||
end
|
||||
end
|
||||
|
||||
@result == 0
|
||||
@result
|
||||
end
|
||||
|
||||
# #bind_as is for testing authentication credentials.
|
||||
|
@ -816,14 +815,14 @@ class Net::LDAP
|
|||
begin
|
||||
conn = Connection.new(:host => @host, :port => @port,
|
||||
:encryption => @encryption)
|
||||
if (@result = conn.bind(args[:auth] || @auth)) == 0
|
||||
if (@result = conn.bind(args[:auth] || @auth)).result_code == 0
|
||||
@result = conn.add(args)
|
||||
end
|
||||
ensure
|
||||
conn.close if conn
|
||||
end
|
||||
end
|
||||
@result == 0
|
||||
@result
|
||||
end
|
||||
|
||||
# Modifies the attribute values of a particular entry on the LDAP
|
||||
|
@ -914,14 +913,15 @@ class Net::LDAP
|
|||
begin
|
||||
conn = Connection.new(:host => @host, :port => @port,
|
||||
:encryption => @encryption)
|
||||
if (@result = conn.bind(args[:auth] || @auth)) == 0
|
||||
if (@result = conn.bind(args[:auth] || @auth)).result_code == 0
|
||||
@result = conn.modify(args)
|
||||
end
|
||||
ensure
|
||||
conn.close if conn
|
||||
end
|
||||
end
|
||||
@result == 0
|
||||
|
||||
@result
|
||||
end
|
||||
|
||||
# Add a value to an attribute. Takes the full DN of the entry to modify,
|
||||
|
@ -985,14 +985,14 @@ class Net::LDAP
|
|||
begin
|
||||
conn = Connection.new(:host => @host, :port => @port,
|
||||
:encryption => @encryption)
|
||||
if (@result = conn.bind(args[:auth] || @auth)) == 0
|
||||
if (@result = conn.bind(args[:auth] || @auth)).result_code == 0
|
||||
@result = conn.rename(args)
|
||||
end
|
||||
ensure
|
||||
conn.close if conn
|
||||
end
|
||||
end
|
||||
@result == 0
|
||||
@result
|
||||
end
|
||||
alias_method :modify_rdn, :rename
|
||||
|
||||
|
@ -1013,14 +1013,14 @@ class Net::LDAP
|
|||
begin
|
||||
conn = Connection.new(:host => @host, :port => @port,
|
||||
:encryption => @encryption)
|
||||
if (@result = conn.bind(args[:auth] || @auth)) == 0
|
||||
if (@result = conn.bind(args[:auth] || @auth)).result_code == 0
|
||||
@result = conn.delete(args)
|
||||
end
|
||||
ensure
|
||||
conn.close
|
||||
end
|
||||
end
|
||||
@result == 0
|
||||
@result
|
||||
end
|
||||
|
||||
# Delete an entry from the LDAP directory along with all subordinate entries.
|
||||
|
@ -1250,7 +1250,7 @@ class Net::LDAP::Connection #:nodoc:
|
|||
|
||||
(be = @conn.read_ber(Net::LDAP::AsnSyntax) and pdu = Net::LDAP::PDU.new(be)) or raise Net::LDAP::LdapError, "no bind result"
|
||||
|
||||
pdu.result_code
|
||||
pdu
|
||||
end
|
||||
|
||||
#--
|
||||
|
@ -1288,7 +1288,7 @@ class Net::LDAP::Connection #:nodoc:
|
|||
@conn.write request_pkt
|
||||
|
||||
(be = @conn.read_ber(Net::LDAP::AsnSyntax) and pdu = Net::LDAP::PDU.new(be)) or raise Net::LDAP::LdapError, "no bind result"
|
||||
return pdu.result_code unless pdu.result_code == 14 # saslBindInProgress
|
||||
return pdu unless pdu.result_code == 14 # saslBindInProgress
|
||||
raise Net::LDAP::LdapError, "sasl-challenge overflow" if ((n += 1) > MaxSaslChallenges)
|
||||
|
||||
cred = chall.call(pdu.result_server_sasl_creds)
|
||||
|
@ -1374,7 +1374,7 @@ class Net::LDAP::Connection #:nodoc:
|
|||
# to do a root-DSE record search and not do a paged search if the LDAP
|
||||
# doesn't support it. Yuck.
|
||||
rfc2696_cookie = [126, ""]
|
||||
result_code = 0
|
||||
result_pdu = nil
|
||||
n_results = 0
|
||||
|
||||
loop {
|
||||
|
@ -1413,7 +1413,7 @@ class Net::LDAP::Connection #:nodoc:
|
|||
pkt = [next_msgid.to_ber, request, controls].to_ber_sequence
|
||||
@conn.write pkt
|
||||
|
||||
result_code = 0
|
||||
result_pdu = nil
|
||||
controls = []
|
||||
|
||||
while (be = @conn.read_ber(Net::LDAP::AsnSyntax)) && (pdu = Net::LDAP::PDU.new(be))
|
||||
|
@ -1430,7 +1430,7 @@ class Net::LDAP::Connection #:nodoc:
|
|||
end
|
||||
end
|
||||
when 5 # search-result
|
||||
result_code = pdu.result_code
|
||||
result_pdu = pdu
|
||||
controls = pdu.result_controls
|
||||
break
|
||||
else
|
||||
|
@ -1449,7 +1449,7 @@ class Net::LDAP::Connection #:nodoc:
|
|||
# of type OCTET STRING, covered in the default syntax supported by
|
||||
# read_ber, so I guess we're ok.
|
||||
more_pages = false
|
||||
if result_code == 0 and controls
|
||||
if result_pdu.result_code == 0 and controls
|
||||
controls.each do |c|
|
||||
if c.oid == Net::LDAP::LDAPControls::PAGED_RESULTS
|
||||
# just in case some bogus server sends us more than 1 of these.
|
||||
|
@ -1468,7 +1468,7 @@ class Net::LDAP::Connection #:nodoc:
|
|||
break unless more_pages
|
||||
} # loop
|
||||
|
||||
result_code
|
||||
result_pdu || OpenStruct.new(:status => :failure, :result_code => 1, :message => "Invalid search")
|
||||
end
|
||||
|
||||
MODIFY_OPERATIONS = { #:nodoc:
|
||||
|
@ -1508,7 +1508,8 @@ class Net::LDAP::Connection #:nodoc:
|
|||
@conn.write pkt
|
||||
|
||||
(be = @conn.read_ber(Net::LDAP::AsnSyntax)) && (pdu = Net::LDAP::PDU.new(be)) && (pdu.app_tag == 7) or raise Net::LDAP::LdapError, "response missing or invalid"
|
||||
pdu.result_code
|
||||
|
||||
pdu
|
||||
end
|
||||
|
||||
#--
|
||||
|
@ -1529,8 +1530,12 @@ class Net::LDAP::Connection #:nodoc:
|
|||
pkt = [next_msgid.to_ber, request].to_ber_sequence
|
||||
@conn.write pkt
|
||||
|
||||
(be = @conn.read_ber(Net::LDAP::AsnSyntax)) && (pdu = Net::LDAP::PDU.new(be)) && (pdu.app_tag == 9) or raise Net::LDAP::LdapError, "response missing or invalid"
|
||||
pdu.result_code
|
||||
(be = @conn.read_ber(Net::LDAP::AsnSyntax)) &&
|
||||
(pdu = Net::LDAP::PDU.new(be)) &&
|
||||
(pdu.app_tag == 9) or
|
||||
raise Net::LDAP::LdapError, "response missing or invalid"
|
||||
|
||||
pdu
|
||||
end
|
||||
|
||||
#--
|
||||
|
@ -1551,7 +1556,8 @@ class Net::LDAP::Connection #:nodoc:
|
|||
(be = @conn.read_ber(Net::LDAP::AsnSyntax)) &&
|
||||
(pdu = Net::LDAP::PDU.new( be )) && (pdu.app_tag == 13) or
|
||||
raise Net::LDAP::LdapError.new( "response missing or invalid" )
|
||||
pdu.result_code
|
||||
|
||||
pdu
|
||||
end
|
||||
|
||||
#--
|
||||
|
@ -1565,6 +1571,7 @@ class Net::LDAP::Connection #:nodoc:
|
|||
@conn.write pkt
|
||||
|
||||
(be = @conn.read_ber(Net::LDAP::AsnSyntax)) && (pdu = Net::LDAP::PDU.new(be)) && (pdu.app_tag == 11) or raise Net::LDAP::LdapError, "response missing or invalid"
|
||||
pdu.result_code
|
||||
|
||||
pdu
|
||||
end
|
||||
end # class Connection
|
||||
|
|
|
@ -112,6 +112,10 @@ class Net::LDAP::PDU
|
|||
@ldap_result || {}
|
||||
end
|
||||
|
||||
def error_message
|
||||
result[:errorMessage] || ""
|
||||
end
|
||||
|
||||
##
|
||||
# This returns an LDAP result code taken from the PDU, but it will be nil
|
||||
# if there wasn't a result code. That can easily happen depending on the
|
||||
|
@ -120,6 +124,10 @@ class Net::LDAP::PDU
|
|||
@ldap_result and @ldap_result[code]
|
||||
end
|
||||
|
||||
def status
|
||||
result_code == 0 ? :success : :failure
|
||||
end
|
||||
|
||||
##
|
||||
# Return serverSaslCreds, which are only present in BindResponse packets.
|
||||
#--
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue