@@ -629,11 +629,10 @@ def search(args = {})
629
629
yield entry if block_given?
630
630
}
631
631
else
632
- @result = 0
633
632
begin
634
633
conn = Net ::LDAP ::Connection . new ( :host => @host , :port => @port ,
635
634
:encryption => @encryption )
636
- if ( @result = conn . bind ( args [ :auth ] || @auth ) ) == 0
635
+ if ( @result = conn . bind ( args [ :auth ] || @auth ) ) . result_code == 0
637
636
@result = conn . search ( args ) { |entry |
638
637
result_set << entry if result_set
639
638
yield entry if block_given?
@@ -645,9 +644,9 @@ def search(args = {})
645
644
end
646
645
647
646
if return_result_set
648
- @result == 0 ? result_set : nil
647
+ ( ! @result . nil? && @result . result_code == 0 ) ? result_set : nil
649
648
else
650
- @result == 0
649
+ @result
651
650
end
652
651
end
653
652
@@ -721,7 +720,7 @@ def bind(auth = @auth)
721
720
end
722
721
end
723
722
724
- @result == 0
723
+ @result
725
724
end
726
725
727
726
# #bind_as is for testing authentication credentials.
@@ -816,14 +815,14 @@ def add(args)
816
815
begin
817
816
conn = Connection . new ( :host => @host , :port => @port ,
818
817
:encryption => @encryption )
819
- if ( @result = conn . bind ( args [ :auth ] || @auth ) ) == 0
818
+ if ( @result = conn . bind ( args [ :auth ] || @auth ) ) . result_code == 0
820
819
@result = conn . add ( args )
821
820
end
822
821
ensure
823
822
conn . close if conn
824
823
end
825
824
end
826
- @result == 0
825
+ @result
827
826
end
828
827
829
828
# Modifies the attribute values of a particular entry on the LDAP
@@ -914,14 +913,15 @@ def modify(args)
914
913
begin
915
914
conn = Connection . new ( :host => @host , :port => @port ,
916
915
:encryption => @encryption )
917
- if ( @result = conn . bind ( args [ :auth ] || @auth ) ) == 0
916
+ if ( @result = conn . bind ( args [ :auth ] || @auth ) ) . result_code == 0
918
917
@result = conn . modify ( args )
919
918
end
920
919
ensure
921
920
conn . close if conn
922
921
end
923
922
end
924
- @result == 0
923
+
924
+ @result
925
925
end
926
926
927
927
# Add a value to an attribute. Takes the full DN of the entry to modify,
@@ -985,14 +985,14 @@ def rename(args)
985
985
begin
986
986
conn = Connection . new ( :host => @host , :port => @port ,
987
987
:encryption => @encryption )
988
- if ( @result = conn . bind ( args [ :auth ] || @auth ) ) == 0
988
+ if ( @result = conn . bind ( args [ :auth ] || @auth ) ) . result_code == 0
989
989
@result = conn . rename ( args )
990
990
end
991
991
ensure
992
992
conn . close if conn
993
993
end
994
994
end
995
- @result == 0
995
+ @result
996
996
end
997
997
alias_method :modify_rdn , :rename
998
998
@@ -1013,14 +1013,14 @@ def delete(args)
1013
1013
begin
1014
1014
conn = Connection . new ( :host => @host , :port => @port ,
1015
1015
:encryption => @encryption )
1016
- if ( @result = conn . bind ( args [ :auth ] || @auth ) ) == 0
1016
+ if ( @result = conn . bind ( args [ :auth ] || @auth ) ) . result_code == 0
1017
1017
@result = conn . delete ( args )
1018
1018
end
1019
1019
ensure
1020
1020
conn . close
1021
1021
end
1022
1022
end
1023
- @result == 0
1023
+ @result
1024
1024
end
1025
1025
1026
1026
# Delete an entry from the LDAP directory along with all subordinate entries.
@@ -1250,7 +1250,7 @@ def bind_simple(auth)
1250
1250
1251
1251
( be = @conn . read_ber ( Net ::LDAP ::AsnSyntax ) and pdu = Net ::LDAP ::PDU . new ( be ) ) or raise Net ::LDAP ::LdapError , "no bind result"
1252
1252
1253
- pdu . result_code
1253
+ pdu
1254
1254
end
1255
1255
1256
1256
#--
@@ -1288,7 +1288,7 @@ def bind_sasl(auth)
1288
1288
@conn . write request_pkt
1289
1289
1290
1290
( be = @conn . read_ber ( Net ::LDAP ::AsnSyntax ) and pdu = Net ::LDAP ::PDU . new ( be ) ) or raise Net ::LDAP ::LdapError , "no bind result"
1291
- return pdu . result_code unless pdu . result_code == 14 # saslBindInProgress
1291
+ return pdu unless pdu . result_code == 14 # saslBindInProgress
1292
1292
raise Net ::LDAP ::LdapError , "sasl-challenge overflow" if ( ( n += 1 ) > MaxSaslChallenges )
1293
1293
1294
1294
cred = chall . call ( pdu . result_server_sasl_creds )
@@ -1374,7 +1374,7 @@ def search(args = {})
1374
1374
# to do a root-DSE record search and not do a paged search if the LDAP
1375
1375
# doesn't support it. Yuck.
1376
1376
rfc2696_cookie = [ 126 , "" ]
1377
- result_code = 0
1377
+ result_pdu = nil
1378
1378
n_results = 0
1379
1379
1380
1380
loop {
@@ -1413,7 +1413,7 @@ def search(args = {})
1413
1413
pkt = [ next_msgid . to_ber , request , controls ] . to_ber_sequence
1414
1414
@conn . write pkt
1415
1415
1416
- result_code = 0
1416
+ result_pdu = nil
1417
1417
controls = [ ]
1418
1418
1419
1419
while ( be = @conn . read_ber ( Net ::LDAP ::AsnSyntax ) ) && ( pdu = Net ::LDAP ::PDU . new ( be ) )
@@ -1430,7 +1430,7 @@ def search(args = {})
1430
1430
end
1431
1431
end
1432
1432
when 5 # search-result
1433
- result_code = pdu . result_code
1433
+ result_pdu = pdu
1434
1434
controls = pdu . result_controls
1435
1435
break
1436
1436
else
@@ -1449,7 +1449,7 @@ def search(args = {})
1449
1449
# of type OCTET STRING, covered in the default syntax supported by
1450
1450
# read_ber, so I guess we're ok.
1451
1451
more_pages = false
1452
- if result_code == 0 and controls
1452
+ if result_pdu . result_code == 0 and controls
1453
1453
controls . each do |c |
1454
1454
if c . oid == Net ::LDAP ::LDAPControls ::PAGED_RESULTS
1455
1455
# just in case some bogus server sends us more than 1 of these.
@@ -1468,7 +1468,7 @@ def search(args = {})
1468
1468
break unless more_pages
1469
1469
} # loop
1470
1470
1471
- result_code
1471
+ result_pdu || OpenStruct . new ( :status => :failure , : result_code => 1 , :message => "Invalid search" )
1472
1472
end
1473
1473
1474
1474
MODIFY_OPERATIONS = { #:nodoc:
@@ -1508,7 +1508,8 @@ def modify(args)
1508
1508
@conn . write pkt
1509
1509
1510
1510
( 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"
1511
- pdu . result_code
1511
+
1512
+ pdu
1512
1513
end
1513
1514
1514
1515
#--
@@ -1529,8 +1530,12 @@ def add(args)
1529
1530
pkt = [ next_msgid . to_ber , request ] . to_ber_sequence
1530
1531
@conn . write pkt
1531
1532
1532
- ( 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"
1533
- pdu . result_code
1533
+ ( be = @conn . read_ber ( Net ::LDAP ::AsnSyntax ) ) &&
1534
+ ( pdu = Net ::LDAP ::PDU . new ( be ) ) &&
1535
+ ( pdu . app_tag == 9 ) or
1536
+ raise Net ::LDAP ::LdapError , "response missing or invalid"
1537
+
1538
+ pdu
1534
1539
end
1535
1540
1536
1541
#--
@@ -1551,7 +1556,8 @@ def rename args
1551
1556
( be = @conn . read_ber ( Net ::LDAP ::AsnSyntax ) ) &&
1552
1557
( pdu = Net ::LDAP ::PDU . new ( be ) ) && ( pdu . app_tag == 13 ) or
1553
1558
raise Net ::LDAP ::LdapError . new ( "response missing or invalid" )
1554
- pdu . result_code
1559
+
1560
+ pdu
1555
1561
end
1556
1562
1557
1563
#--
@@ -1565,6 +1571,7 @@ def delete(args)
1565
1571
@conn . write pkt
1566
1572
1567
1573
( 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"
1568
- pdu . result_code
1574
+
1575
+ pdu
1569
1576
end
1570
1577
end # class Connection
0 commit comments