@@ -244,6 +244,33 @@ class Net::LDAP
244
244
VERSION = "0.4.0"
245
245
246
246
class LdapError < StandardError ; end
247
+ class AlreadyOpenedError < LdapError ; end
248
+ class SocketError < LdapError ; end
249
+ class ConnectionRefusedError < LdapError ; end
250
+ class NoOpenSSLError < LdapError ; end
251
+ class NoStartTLSResultError < LdapError ; end
252
+ class StartTLSError < LdapError ; end
253
+ class EncryptionUnsupportedError < LdapError ; end
254
+ class EncMethodUnsupportedError < LdapError ; end
255
+ class AuthMethodUnsupportedError < LdapError ; end
256
+ class BindingInformationInvalidError < LdapError ; end
257
+ class NoBindResultError < LdapError ; end
258
+ class SASLChallengeOverflowError < LdapError ; end
259
+ class SearchSizeInvalidError < LdapError ; end
260
+ class SearchScopeInvalidError < LdapError ; end
261
+ class ResponseTypeInvalidError < LdapError ; end
262
+ class ResponseMissingOrInvalidError < LdapError ; end
263
+ class EmptyDNError < LdapError ; end
264
+ class HashTypeUnsupportedError < LdapError ; end
265
+ class OperatorError < LdapError ; end
266
+ class SubstringFilterError < LdapError ; end
267
+ class SearchFilterError < LdapError ; end
268
+ class BERInvalidError < LdapError ; end
269
+ class SearchFilterTypeUnknownError < LdapError ; end
270
+ class BadAttributeError < LdapError ; end
271
+ class FilterTypeUnknownError < LdapError ; end
272
+ class FilterSyntaxInvalidError < LdapError ; end
273
+ class EntryOverflowError < LdapError ; end
247
274
248
275
SearchScope_BaseObject = 0
249
276
SearchScope_SingleLevel = 1
@@ -563,7 +590,7 @@ def open
563
590
# anything with the bind results. We then pass self to the caller's
564
591
# block, where he will execute his LDAP operations. Of course they will
565
592
# all generate auth failures if the bind was unsuccessful.
566
- raise Net ::LDAP ::LdapError , "Open already in progress" if @open_connection
593
+ raise Net ::LDAP ::AlreadyOpenedError , "Open already in progress" if @open_connection
567
594
568
595
begin
569
596
@open_connection = Net ::LDAP ::Connection . new ( :host => @host ,
@@ -1134,9 +1161,9 @@ def initialize(server)
1134
1161
begin
1135
1162
@conn = TCPSocket . new ( server [ :host ] , server [ :port ] )
1136
1163
rescue SocketError
1137
- raise Net ::LDAP ::LdapError , "No such address or other socket error."
1164
+ raise Net ::LDAP ::SocketError , "No such address or other socket error."
1138
1165
rescue Errno ::ECONNREFUSED
1139
- raise Net ::LDAP ::LdapError , "Server #{ server [ :host ] } refused connection on port #{ server [ :port ] } ."
1166
+ raise Net ::LDAP ::ConnectionRefusedError , "Server #{ server [ :host ] } refused connection on port #{ server [ :port ] } ."
1140
1167
end
1141
1168
1142
1169
if server [ :encryption ]
@@ -1153,7 +1180,7 @@ def getbyte
1153
1180
end
1154
1181
1155
1182
def self . wrap_with_ssl ( io )
1156
- raise Net ::LDAP ::LdapError , "OpenSSL is unavailable" unless Net ::LDAP ::HasOpenSSL
1183
+ raise Net ::LDAP ::NoOpenSSLError , "OpenSSL is unavailable" unless Net ::LDAP ::HasOpenSSL
1157
1184
ctx = OpenSSL ::SSL ::SSLContext . new
1158
1185
conn = OpenSSL ::SSL ::SSLSocket . new ( io , ctx )
1159
1186
conn . connect
@@ -1202,16 +1229,16 @@ def setup_encryption(args)
1202
1229
request_pkt = [ msgid , request ] . to_ber_sequence
1203
1230
@conn . write request_pkt
1204
1231
be = @conn . read_ber ( Net ::LDAP ::AsnSyntax )
1205
- raise Net ::LDAP ::LdapError , "no start_tls result" if be . nil?
1232
+ raise Net ::LDAP ::NoStartTLSResultError , "no start_tls result" if be . nil?
1206
1233
pdu = Net ::LDAP ::PDU . new ( be )
1207
- raise Net ::LDAP ::LdapError , "no start_tls result" if pdu . nil?
1234
+ raise Net ::LDAP ::NoStartTLSResultError , "no start_tls result" if pdu . nil?
1208
1235
if pdu . result_code . zero?
1209
1236
@conn = self . class . wrap_with_ssl ( @conn )
1210
1237
else
1211
- raise Net ::LDAP ::LdapError , "start_tls failed: #{ pdu . result_code } "
1238
+ raise Net ::LDAP ::StartTLSError , "start_tls failed: #{ pdu . result_code } "
1212
1239
end
1213
1240
else
1214
- raise Net ::LDAP ::LdapError , "unsupported encryption method #{ args [ :method ] } "
1241
+ raise Net ::LDAP ::EncryptionUnsupportedError , "unsupported encryption method #{ args [ :method ] } "
1215
1242
end
1216
1243
end
1217
1244
@@ -1239,7 +1266,7 @@ def bind(auth)
1239
1266
elsif meth == :gss_spnego
1240
1267
bind_gss_spnego ( auth )
1241
1268
else
1242
- raise Net ::LDAP ::LdapError , "Unsupported auth method (#{ meth } )"
1269
+ raise Net ::LDAP ::AuthMethodUnsupportedError , "Unsupported auth method (#{ meth } )"
1243
1270
end
1244
1271
end
1245
1272
@@ -1254,15 +1281,15 @@ def bind_simple(auth)
1254
1281
[ "" , "" ]
1255
1282
end
1256
1283
1257
- raise Net ::LDAP ::LdapError , "Invalid binding information" unless ( user && psw )
1284
+ raise Net ::LDAP ::BindingInformationInvalidError , "Invalid binding information" unless ( user && psw )
1258
1285
1259
1286
msgid = next_msgid . to_ber
1260
1287
request = [ LdapVersion . to_ber , user . to_ber ,
1261
1288
psw . to_ber_contextspecific ( 0 ) ] . to_ber_appsequence ( 0 )
1262
1289
request_pkt = [ msgid , request ] . to_ber_sequence
1263
1290
@conn . write request_pkt
1264
1291
1265
- ( be = @conn . read_ber ( Net ::LDAP ::AsnSyntax ) and pdu = Net ::LDAP ::PDU . new ( be ) ) or raise Net ::LDAP ::LdapError , "no bind result"
1292
+ ( be = @conn . read_ber ( Net ::LDAP ::AsnSyntax ) and pdu = Net ::LDAP ::PDU . new ( be ) ) or raise Net ::LDAP ::NoBindResultError , "no bind result"
1266
1293
1267
1294
pdu
1268
1295
end
@@ -1291,7 +1318,7 @@ def bind_simple(auth)
1291
1318
def bind_sasl ( auth )
1292
1319
mech , cred , chall = auth [ :mechanism ] , auth [ :initial_credential ] ,
1293
1320
auth [ :challenge_response ]
1294
- raise Net ::LDAP ::LdapError , "Invalid binding information" unless ( mech && cred && chall )
1321
+ raise Net ::LDAP ::BindingInformationInvalidError , "Invalid binding information" unless ( mech && cred && chall )
1295
1322
1296
1323
n = 0
1297
1324
loop {
@@ -1301,9 +1328,9 @@ def bind_sasl(auth)
1301
1328
request_pkt = [ msgid , request ] . to_ber_sequence
1302
1329
@conn . write request_pkt
1303
1330
1304
- ( be = @conn . read_ber ( Net ::LDAP ::AsnSyntax ) and pdu = Net ::LDAP ::PDU . new ( be ) ) or raise Net ::LDAP ::LdapError , "no bind result"
1331
+ ( be = @conn . read_ber ( Net ::LDAP ::AsnSyntax ) and pdu = Net ::LDAP ::PDU . new ( be ) ) or raise Net ::LDAP ::NoBindResultError , "no bind result"
1305
1332
return pdu unless pdu . result_code == 14 # saslBindInProgress
1306
- raise Net ::LDAP ::LdapError , "sasl-challenge overflow" if ( ( n += 1 ) > MaxSaslChallenges )
1333
+ raise Net ::LDAP ::SASLChallengeOverflowError , "sasl-challenge overflow" if ( ( n += 1 ) > MaxSaslChallenges )
1307
1334
1308
1335
cred = chall . call ( pdu . result_server_sasl_creds )
1309
1336
}
@@ -1327,7 +1354,7 @@ def bind_gss_spnego(auth)
1327
1354
require 'ntlm'
1328
1355
1329
1356
user , psw = [ auth [ :username ] || auth [ :dn ] , auth [ :password ] ]
1330
- raise Net ::LDAP ::LdapError , "Invalid binding information" unless ( user && psw )
1357
+ raise Net ::LDAP ::BindingInformationInvalidError , "Invalid binding information" unless ( user && psw )
1331
1358
1332
1359
nego = proc { |challenge |
1333
1360
t2_msg = NTLM ::Message . parse ( challenge )
@@ -1389,12 +1416,12 @@ def search(args = {})
1389
1416
search_attributes = ( ( args && args [ :attributes ] ) || [ ] ) . map { |attr | attr . to_s . to_ber }
1390
1417
return_referrals = args && args [ :return_referrals ] == true
1391
1418
sizelimit = ( args && args [ :size ] . to_i ) || 0
1392
- raise Net ::LDAP ::LdapError , "invalid search-size" unless sizelimit >= 0
1419
+ raise Net ::LDAP ::SearchSizeInvalidError , "invalid search-size" unless sizelimit >= 0
1393
1420
paged_searches_supported = ( args && args [ :paged_searches_supported ] )
1394
1421
1395
1422
attributes_only = ( args and args [ :attributes_only ] == true )
1396
1423
scope = args [ :scope ] || Net ::LDAP ::SearchScope_WholeSubtree
1397
- raise Net ::LDAP ::LdapError , "invalid search scope" unless Net ::LDAP ::SearchScopes . include? ( scope )
1424
+ raise Net ::LDAP ::SearchScopeInvalidError , "invalid search scope" unless Net ::LDAP ::SearchScopes . include? ( scope )
1398
1425
1399
1426
sort_control = encode_sort_controls ( args . fetch ( :sort_controls ) { false } )
1400
1427
# An interesting value for the size limit would be close to A/D's
@@ -1490,7 +1517,7 @@ def search(args = {})
1490
1517
end
1491
1518
break
1492
1519
else
1493
- raise Net ::LDAP ::LdapError , "invalid response-type in search: #{ pdu . app_tag } "
1520
+ raise Net ::LDAP ::ResponseTypeInvalidError , "invalid response-type in search: #{ pdu . app_tag } "
1494
1521
end
1495
1522
end
1496
1523
@@ -1563,7 +1590,7 @@ def modify(args)
1563
1590
pkt = [ next_msgid . to_ber , request ] . to_ber_sequence
1564
1591
@conn . write pkt
1565
1592
1566
- ( 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"
1593
+ ( be = @conn . read_ber ( Net ::LDAP ::AsnSyntax ) ) && ( pdu = Net ::LDAP ::PDU . new ( be ) ) && ( pdu . app_tag == 7 ) or raise Net ::LDAP ::ResponseMissingOrInvalidError , "response missing or invalid"
1567
1594
1568
1595
pdu
1569
1596
end
@@ -1576,7 +1603,7 @@ def modify(args)
1576
1603
# to the error message and the matched-DN returned by the server.
1577
1604
#++
1578
1605
def add ( args )
1579
- add_dn = args [ :dn ] or raise Net ::LDAP ::LdapError , "Unable to add empty DN"
1606
+ add_dn = args [ :dn ] or raise Net ::LDAP ::EmptyDNError , "Unable to add empty DN"
1580
1607
add_attrs = [ ]
1581
1608
a = args [ :attributes ] and a . each { |k , v |
1582
1609
add_attrs << [ k . to_s . to_ber , Array ( v ) . map { |m | m . to_ber } . to_ber_set ] . to_ber_sequence
@@ -1589,7 +1616,7 @@ def add(args)
1589
1616
( be = @conn . read_ber ( Net ::LDAP ::AsnSyntax ) ) &&
1590
1617
( pdu = Net ::LDAP ::PDU . new ( be ) ) &&
1591
1618
( pdu . app_tag == 9 ) or
1592
- raise Net ::LDAP ::LdapError , "response missing or invalid"
1619
+ raise Net ::LDAP ::ResponseMissingOrInvalidError , "response missing or invalid"
1593
1620
1594
1621
pdu
1595
1622
end
@@ -1611,7 +1638,7 @@ def rename(args)
1611
1638
1612
1639
( be = @conn . read_ber ( Net ::LDAP ::AsnSyntax ) ) &&
1613
1640
( pdu = Net ::LDAP ::PDU . new ( be ) ) && ( pdu . app_tag == 13 ) or
1614
- raise Net ::LDAP ::LdapError . new ( "response missing or invalid" )
1641
+ raise Net ::LDAP ::ResponseMissingOrInvalidError . new ( "response missing or invalid" )
1615
1642
1616
1643
pdu
1617
1644
end
@@ -1626,7 +1653,7 @@ def delete(args)
1626
1653
pkt = [ next_msgid . to_ber , request , controls ] . compact . to_ber_sequence
1627
1654
@conn . write pkt
1628
1655
1629
- ( 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"
1656
+ ( be = @conn . read_ber ( Net ::LDAP ::AsnSyntax ) ) && ( pdu = Net ::LDAP ::PDU . new ( be ) ) && ( pdu . app_tag == 11 ) or raise Net ::LDAP ::ResponseMissingOrInvalidError , "response missing or invalid"
1630
1657
1631
1658
pdu
1632
1659
end
0 commit comments