@@ -42,7 +42,7 @@ def close
42
42
end
43
43
44
44
def self . wrap_with_ssl ( io , tls_options = { } )
45
- raise Net ::LDAP ::Error , "OpenSSL is unavailable" unless Net ::LDAP ::HasOpenSSL
45
+ raise Net ::LDAP ::NoOpenSSLError , "OpenSSL is unavailable" unless Net ::LDAP ::HasOpenSSL
46
46
47
47
ctx = OpenSSL ::SSL ::SSLContext . new
48
48
@@ -105,16 +105,16 @@ def setup_encryption(args)
105
105
pdu = queued_read ( message_id )
106
106
107
107
if pdu . nil? || pdu . app_tag != Net ::LDAP ::PDU ::ExtendedResponse
108
- raise Net ::LDAP ::Error , "no start_tls result"
108
+ raise Net ::LDAP ::NoStartTLSResultError , "no start_tls result"
109
109
end
110
110
111
111
if pdu . result_code . zero?
112
112
@conn = self . class . wrap_with_ssl ( @conn , args [ :tls_options ] )
113
113
else
114
- raise Net ::LDAP ::Error , "start_tls failed: #{ pdu . result_code } "
114
+ raise Net ::LDAP ::StartTlSError , "start_tls failed: #{ pdu . result_code } "
115
115
end
116
116
else
117
- raise Net ::LDAP ::Error , "unsupported encryption method #{ args [ :method ] } "
117
+ raise Net ::LDAP ::EncMethodUnsupportedError , "unsupported encryption method #{ args [ :method ] } "
118
118
end
119
119
end
120
120
@@ -225,7 +225,7 @@ def bind(auth)
225
225
elsif meth == :gss_spnego
226
226
bind_gss_spnego ( auth )
227
227
else
228
- raise Net ::LDAP ::Error , "Unsupported auth method (#{ meth } )"
228
+ raise Net ::LDAP ::AuthMethodUnsupportedError , "Unsupported auth method (#{ meth } )"
229
229
end
230
230
end
231
231
end
@@ -241,7 +241,7 @@ def bind_simple(auth)
241
241
[ "" , "" ]
242
242
end
243
243
244
- raise Net ::LDAP ::Error , "Invalid binding information" unless ( user && psw )
244
+ raise Net ::LDAP ::BindingInformationInvalidError , "Invalid binding information" unless ( user && psw )
245
245
246
246
message_id = next_msgid
247
247
request = [
@@ -253,7 +253,7 @@ def bind_simple(auth)
253
253
pdu = queued_read ( message_id )
254
254
255
255
if !pdu || pdu . app_tag != Net ::LDAP ::PDU ::BindResult
256
- raise Net ::LDAP ::Error , "no bind result"
256
+ raise Net ::LDAP ::NoBindResultError , "no bind result"
257
257
end
258
258
259
259
pdu
@@ -283,7 +283,7 @@ def bind_simple(auth)
283
283
def bind_sasl ( auth )
284
284
mech , cred , chall = auth [ :mechanism ] , auth [ :initial_credential ] ,
285
285
auth [ :challenge_response ]
286
- raise Net ::LDAP ::Error , "Invalid binding information" unless ( mech && cred && chall )
286
+ raise Net ::LDAP ::BindingInformationInvalidError , "Invalid binding information" unless ( mech && cred && chall )
287
287
288
288
message_id = next_msgid
289
289
@@ -298,16 +298,16 @@ def bind_sasl(auth)
298
298
pdu = queued_read ( message_id )
299
299
300
300
if !pdu || pdu . app_tag != Net ::LDAP ::PDU ::BindResult
301
- raise Net ::LDAP ::Error , "no bind result"
301
+ raise Net ::LDAP ::NoBindResultError , "no bind result"
302
302
end
303
303
304
304
return pdu unless pdu . result_code == Net ::LDAP ::ResultCodeSaslBindInProgress
305
- raise Net ::LDAP ::Error , "sasl-challenge overflow" if ( ( n += 1 ) > MaxSaslChallenges )
305
+ raise Net ::LDAP ::SASLChallengeOverflowError , "sasl-challenge overflow" if ( ( n += 1 ) > MaxSaslChallenges )
306
306
307
307
cred = chall . call ( pdu . result_server_sasl_creds )
308
308
}
309
309
310
- raise Net ::LDAP ::Error , "why are we here?"
310
+ raise Net ::LDAP ::SASLChallengeOverflowError , "why are we here?"
311
311
end
312
312
private :bind_sasl
313
313
@@ -326,7 +326,7 @@ def bind_gss_spnego(auth)
326
326
require 'ntlm'
327
327
328
328
user , psw = [ auth [ :username ] || auth [ :dn ] , auth [ :password ] ]
329
- raise Net ::LDAP ::Error , "Invalid binding information" unless ( user && psw )
329
+ raise Net ::LDAP ::BindingInformationInvalidError , "Invalid binding information" unless ( user && psw )
330
330
331
331
nego = proc { |challenge |
332
332
t2_msg = NTLM ::Message . parse ( challenge )
@@ -412,9 +412,9 @@ def search(args = nil)
412
412
sort = args . fetch ( :sort_controls , false )
413
413
414
414
# arg validation
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 )
415
+ raise Net ::LDAP ::NoSearchBaseError , "search base is required" unless base
416
+ raise Net ::LDAP ::SearchSizeInvalidError , "invalid search-size" unless size >= 0
417
+ raise Net ::LDAP ::SearchScopeInvalidError , "invalid search scope" unless Net ::LDAP ::SearchScopes . include? ( scope )
418
418
raise Net ::LDAP ::Error , "invalid alias dereferencing value" unless Net ::LDAP ::DerefAliasesArray . include? ( deref )
419
419
420
420
# arg transforms
@@ -527,7 +527,7 @@ def search(args = nil)
527
527
end
528
528
break
529
529
else
530
- raise Net ::LDAP ::Error , "invalid response-type in search: #{ pdu . app_tag } "
530
+ raise Net ::LDAP ::ResponseTypeInvalidError , "invalid response-type in search: #{ pdu . app_tag } "
531
531
end
532
532
end
533
533
@@ -624,7 +624,7 @@ def modify(args)
624
624
pdu = queued_read ( message_id )
625
625
626
626
if !pdu || pdu . app_tag != Net ::LDAP ::PDU ::ModifyResponse
627
- raise Net ::LDAP ::Error , "response missing or invalid"
627
+ raise Net ::LDAP ::ResponseMissingOrInvalidError , "response missing or invalid"
628
628
end
629
629
630
630
pdu
@@ -638,7 +638,7 @@ def modify(args)
638
638
# to the error message and the matched-DN returned by the server.
639
639
#++
640
640
def add ( args )
641
- add_dn = args [ :dn ] or raise Net ::LDAP ::Error , "Unable to add empty DN"
641
+ add_dn = args [ :dn ] or raise Net ::LDAP ::EmptyDNError , "Unable to add empty DN"
642
642
add_attrs = [ ]
643
643
a = args [ :attributes ] and a . each { |k , v |
644
644
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)
651
651
pdu = queued_read ( message_id )
652
652
653
653
if !pdu || pdu . app_tag != Net ::LDAP ::PDU ::AddResponse
654
- raise Net ::LDAP ::Error , "response missing or invalid"
654
+ raise Net ::LDAP ::ResponseMissingError , "response missing or invalid"
655
655
end
656
656
657
657
pdu
@@ -674,7 +674,7 @@ def rename(args)
674
674
pdu = queued_read ( message_id )
675
675
676
676
if !pdu || pdu . app_tag != Net ::LDAP ::PDU ::ModifyRDNResponse
677
- raise Net ::LDAP ::Error . new "response missing or invalid"
677
+ raise Net ::LDAP ::ResponseMissingOrInvalidError . new "response missing or invalid"
678
678
end
679
679
680
680
pdu
@@ -693,7 +693,7 @@ def delete(args)
693
693
pdu = queued_read ( message_id )
694
694
695
695
if !pdu || pdu . app_tag != Net ::LDAP ::PDU ::DeleteResponse
696
- raise Net ::LDAP ::Error , "response missing or invalid"
696
+ raise Net ::LDAP ::ResponseMissingOrInvalidError , "response missing or invalid"
697
697
end
698
698
699
699
pdu
0 commit comments