Skip to content

Commit beac837

Browse files
author
Tatsuya Sato
committed
Replace Net::LDAP::LdapError with Net::LDAP::Error in net/ldap/connection.rb
1 parent a6d6ec8 commit beac837

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

lib/net/ldap/connection.rb

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ def initialize(server)
1212
begin
1313
@conn = server[:socket] || TCPSocket.new(server[:host], server[:port])
1414
rescue SocketError
15-
raise Net::LDAP::LdapError, "No such address or other socket error."
15+
raise Net::LDAP::Error, "No such address or other socket error."
1616
rescue Errno::ECONNREFUSED
17-
raise Net::LDAP::LdapError, "Server #{server[:host]} refused connection on port #{server[:port]}."
17+
raise Net::LDAP::Error, "Server #{server[:host]} refused connection on port #{server[:port]}."
1818
rescue Errno::EHOSTUNREACH => error
19-
raise Net::LDAP::LdapError, "Host #{server[:host]} was unreachable (#{error.message})"
19+
raise Net::LDAP::Error, "Host #{server[:host]} was unreachable (#{error.message})"
2020
rescue Errno::ETIMEDOUT
21-
raise Net::LDAP::LdapError, "Connection to #{server[:host]} timed out."
21+
raise Net::LDAP::Error, "Connection to #{server[:host]} timed out."
2222
end
2323

2424
if server[:encryption]
@@ -42,7 +42,7 @@ def close
4242
end
4343

4444
def self.wrap_with_ssl(io, tls_options = {})
45-
raise Net::LDAP::LdapError, "OpenSSL is unavailable" unless Net::LDAP::HasOpenSSL
45+
raise Net::LDAP::Error, "OpenSSL is unavailable" unless Net::LDAP::HasOpenSSL
4646

4747
ctx = OpenSSL::SSL::SSLContext.new
4848

@@ -67,7 +67,7 @@ def self.wrap_with_ssl(io, tls_options = {})
6767
# successfully-opened @conn instance variable, which is a TCP connection.
6868
# Depending on the received arguments, we establish SSL, potentially
6969
# replacing the value of @conn accordingly. Don't generate any errors here
70-
# if no encryption is requested. DO raise Net::LDAP::LdapError objects if encryption
70+
# if no encryption is requested. DO raise Net::LDAP::Error objects if encryption
7171
# is requested and we have trouble setting it up. That includes if OpenSSL
7272
# is not set up on the machine. (Question: how does the Ruby OpenSSL
7373
# wrapper react in that case?) DO NOT filter exceptions raised by the
@@ -105,16 +105,16 @@ def setup_encryption(args)
105105
pdu = queued_read(message_id)
106106

107107
if pdu.nil? || pdu.app_tag != Net::LDAP::PDU::ExtendedResponse
108-
raise Net::LDAP::LdapError, "no start_tls result"
108+
raise Net::LDAP::Error, "no start_tls result"
109109
end
110110

111111
if pdu.result_code.zero?
112112
@conn = self.class.wrap_with_ssl(@conn, args[:tls_options])
113113
else
114-
raise Net::LDAP::LdapError, "start_tls failed: #{pdu.result_code}"
114+
raise Net::LDAP::Error, "start_tls failed: #{pdu.result_code}"
115115
end
116116
else
117-
raise Net::LDAP::LdapError, "unsupported encryption method #{args[:method]}"
117+
raise Net::LDAP::Error, "unsupported encryption method #{args[:method]}"
118118
end
119119
end
120120

@@ -225,7 +225,7 @@ def bind(auth)
225225
elsif meth == :gss_spnego
226226
bind_gss_spnego(auth)
227227
else
228-
raise Net::LDAP::LdapError, "Unsupported auth method (#{meth})"
228+
raise Net::LDAP::Error, "Unsupported auth method (#{meth})"
229229
end
230230
end
231231
end
@@ -241,7 +241,7 @@ def bind_simple(auth)
241241
["", ""]
242242
end
243243

244-
raise Net::LDAP::LdapError, "Invalid binding information" unless (user && psw)
244+
raise Net::LDAP::Error, "Invalid binding information" unless (user && psw)
245245

246246
message_id = next_msgid
247247
request = [
@@ -253,7 +253,7 @@ def bind_simple(auth)
253253
pdu = queued_read(message_id)
254254

255255
if !pdu || pdu.app_tag != Net::LDAP::PDU::BindResult
256-
raise Net::LDAP::LdapError, "no bind result"
256+
raise Net::LDAP::Error, "no bind result"
257257
end
258258

259259
pdu
@@ -283,7 +283,7 @@ def bind_simple(auth)
283283
def bind_sasl(auth)
284284
mech, cred, chall = auth[:mechanism], auth[:initial_credential],
285285
auth[:challenge_response]
286-
raise Net::LDAP::LdapError, "Invalid binding information" unless (mech && cred && chall)
286+
raise Net::LDAP::Error, "Invalid binding information" unless (mech && cred && chall)
287287

288288
message_id = next_msgid
289289

@@ -298,16 +298,16 @@ def bind_sasl(auth)
298298
pdu = queued_read(message_id)
299299

300300
if !pdu || pdu.app_tag != Net::LDAP::PDU::BindResult
301-
raise Net::LDAP::LdapError, "no bind result"
301+
raise Net::LDAP::Error, "no bind result"
302302
end
303303

304304
return pdu unless pdu.result_code == Net::LDAP::ResultCodeSaslBindInProgress
305-
raise Net::LDAP::LdapError, "sasl-challenge overflow" if ((n += 1) > MaxSaslChallenges)
305+
raise Net::LDAP::Error, "sasl-challenge overflow" if ((n += 1) > MaxSaslChallenges)
306306

307307
cred = chall.call(pdu.result_server_sasl_creds)
308308
}
309309

310-
raise Net::LDAP::LdapError, "why are we here?"
310+
raise Net::LDAP::Error, "why are we here?"
311311
end
312312
private :bind_sasl
313313

@@ -326,7 +326,7 @@ def bind_gss_spnego(auth)
326326
require 'ntlm'
327327

328328
user, psw = [auth[:username] || auth[:dn], auth[:password]]
329-
raise Net::LDAP::LdapError, "Invalid binding information" unless (user && psw)
329+
raise Net::LDAP::Error, "Invalid binding information" unless (user && psw)
330330

331331
nego = proc { |challenge|
332332
t2_msg = NTLM::Message.parse(challenge)
@@ -412,10 +412,10 @@ def search(args = nil)
412412
sort = args.fetch(:sort_controls, false)
413413

414414
# arg validation
415-
raise Net::LDAP::LdapError, "search base is required" unless base
416-
raise Net::LDAP::LdapError, "invalid search-size" unless size >= 0
417-
raise Net::LDAP::LdapError, "invalid search scope" unless Net::LDAP::SearchScopes.include?(scope)
418-
raise Net::LDAP::LdapError, "invalid alias dereferencing value" unless Net::LDAP::DerefAliasesArray.include?(deref)
415+
raise Net::LDAP::Error, "search base is required" unless base
416+
raise Net::LDAP::Error, "invalid search-size" unless size >= 0
417+
raise Net::LDAP::Error, "invalid search scope" unless Net::LDAP::SearchScopes.include?(scope)
418+
raise Net::LDAP::Error, "invalid alias dereferencing value" unless Net::LDAP::DerefAliasesArray.include?(deref)
419419

420420
# arg transforms
421421
filter = Net::LDAP::Filter.construct(filter) if filter.is_a?(String)
@@ -527,7 +527,7 @@ def search(args = nil)
527527
end
528528
break
529529
else
530-
raise Net::LDAP::LdapError, "invalid response-type in search: #{pdu.app_tag}"
530+
raise Net::LDAP::Error, "invalid response-type in search: #{pdu.app_tag}"
531531
end
532532
end
533533

@@ -624,7 +624,7 @@ def modify(args)
624624
pdu = queued_read(message_id)
625625

626626
if !pdu || pdu.app_tag != Net::LDAP::PDU::ModifyResponse
627-
raise Net::LDAP::LdapError, "response missing or invalid"
627+
raise Net::LDAP::Error, "response missing or invalid"
628628
end
629629

630630
pdu
@@ -638,7 +638,7 @@ def modify(args)
638638
# to the error message and the matched-DN returned by the server.
639639
#++
640640
def add(args)
641-
add_dn = args[:dn] or raise Net::LDAP::LdapError, "Unable to add empty DN"
641+
add_dn = args[:dn] or raise Net::LDAP::Error, "Unable to add empty DN"
642642
add_attrs = []
643643
a = args[:attributes] and a.each { |k, v|
644644
add_attrs << [ k.to_s.to_ber, Array(v).map { |m| m.to_ber}.to_ber_set ].to_ber_sequence
@@ -651,7 +651,7 @@ def add(args)
651651
pdu = queued_read(message_id)
652652

653653
if !pdu || pdu.app_tag != Net::LDAP::PDU::AddResponse
654-
raise Net::LDAP::LdapError, "response missing or invalid"
654+
raise Net::LDAP::Error, "response missing or invalid"
655655
end
656656

657657
pdu
@@ -674,7 +674,7 @@ def rename(args)
674674
pdu = queued_read(message_id)
675675

676676
if !pdu || pdu.app_tag != Net::LDAP::PDU::ModifyRDNResponse
677-
raise Net::LDAP::LdapError.new "response missing or invalid"
677+
raise Net::LDAP::Error.new "response missing or invalid"
678678
end
679679

680680
pdu
@@ -693,7 +693,7 @@ def delete(args)
693693
pdu = queued_read(message_id)
694694

695695
if !pdu || pdu.app_tag != Net::LDAP::PDU::DeleteResponse
696-
raise Net::LDAP::LdapError, "response missing or invalid"
696+
raise Net::LDAP::Error, "response missing or invalid"
697697
end
698698

699699
pdu

0 commit comments

Comments
 (0)