@@ -629,11 +629,10 @@ def search(args = {})
629629 yield entry if block_given?
630630 }
631631 else
632- @result = 0
633632 begin
634633 conn = Net ::LDAP ::Connection . new ( :host => @host , :port => @port ,
635634 :encryption => @encryption )
636- if ( @result = conn . bind ( args [ :auth ] || @auth ) ) == 0
635+ if ( @result = conn . bind ( args [ :auth ] || @auth ) ) . result_code == 0
637636 @result = conn . search ( args ) { |entry |
638637 result_set << entry if result_set
639638 yield entry if block_given?
@@ -645,9 +644,9 @@ def search(args = {})
645644 end
646645
647646 if return_result_set
648- @result == 0 ? result_set : nil
647+ ( ! @result . nil? && @result . result_code == 0 ) ? result_set : nil
649648 else
650- @result == 0
649+ @result
651650 end
652651 end
653652
@@ -721,7 +720,7 @@ def bind(auth = @auth)
721720 end
722721 end
723722
724- @result == 0
723+ @result
725724 end
726725
727726 # #bind_as is for testing authentication credentials.
@@ -816,14 +815,14 @@ def add(args)
816815 begin
817816 conn = Connection . new ( :host => @host , :port => @port ,
818817 :encryption => @encryption )
819- if ( @result = conn . bind ( args [ :auth ] || @auth ) ) == 0
818+ if ( @result = conn . bind ( args [ :auth ] || @auth ) ) . result_code == 0
820819 @result = conn . add ( args )
821820 end
822821 ensure
823822 conn . close if conn
824823 end
825824 end
826- @result == 0
825+ @result
827826 end
828827
829828 # Modifies the attribute values of a particular entry on the LDAP
@@ -914,14 +913,15 @@ def modify(args)
914913 begin
915914 conn = Connection . new ( :host => @host , :port => @port ,
916915 :encryption => @encryption )
917- if ( @result = conn . bind ( args [ :auth ] || @auth ) ) == 0
916+ if ( @result = conn . bind ( args [ :auth ] || @auth ) ) . result_code == 0
918917 @result = conn . modify ( args )
919918 end
920919 ensure
921920 conn . close if conn
922921 end
923922 end
924- @result == 0
923+
924+ @result
925925 end
926926
927927 # Add a value to an attribute. Takes the full DN of the entry to modify,
@@ -985,14 +985,14 @@ def rename(args)
985985 begin
986986 conn = Connection . new ( :host => @host , :port => @port ,
987987 :encryption => @encryption )
988- if ( @result = conn . bind ( args [ :auth ] || @auth ) ) == 0
988+ if ( @result = conn . bind ( args [ :auth ] || @auth ) ) . result_code == 0
989989 @result = conn . rename ( args )
990990 end
991991 ensure
992992 conn . close if conn
993993 end
994994 end
995- @result == 0
995+ @result
996996 end
997997 alias_method :modify_rdn , :rename
998998
@@ -1013,14 +1013,14 @@ def delete(args)
10131013 begin
10141014 conn = Connection . new ( :host => @host , :port => @port ,
10151015 :encryption => @encryption )
1016- if ( @result = conn . bind ( args [ :auth ] || @auth ) ) == 0
1016+ if ( @result = conn . bind ( args [ :auth ] || @auth ) ) . result_code == 0
10171017 @result = conn . delete ( args )
10181018 end
10191019 ensure
10201020 conn . close
10211021 end
10221022 end
1023- @result == 0
1023+ @result
10241024 end
10251025
10261026 # Delete an entry from the LDAP directory along with all subordinate entries.
@@ -1250,7 +1250,7 @@ def bind_simple(auth)
12501250
12511251 ( be = @conn . read_ber ( Net ::LDAP ::AsnSyntax ) and pdu = Net ::LDAP ::PDU . new ( be ) ) or raise Net ::LDAP ::LdapError , "no bind result"
12521252
1253- pdu . result_code
1253+ pdu
12541254 end
12551255
12561256 #--
@@ -1288,7 +1288,7 @@ def bind_sasl(auth)
12881288 @conn . write request_pkt
12891289
12901290 ( 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
12921292 raise Net ::LDAP ::LdapError , "sasl-challenge overflow" if ( ( n += 1 ) > MaxSaslChallenges )
12931293
12941294 cred = chall . call ( pdu . result_server_sasl_creds )
@@ -1374,7 +1374,7 @@ def search(args = {})
13741374 # to do a root-DSE record search and not do a paged search if the LDAP
13751375 # doesn't support it. Yuck.
13761376 rfc2696_cookie = [ 126 , "" ]
1377- result_code = 0
1377+ result_pdu = nil
13781378 n_results = 0
13791379
13801380 loop {
@@ -1413,7 +1413,7 @@ def search(args = {})
14131413 pkt = [ next_msgid . to_ber , request , controls ] . to_ber_sequence
14141414 @conn . write pkt
14151415
1416- result_code = 0
1416+ result_pdu = nil
14171417 controls = [ ]
14181418
14191419 while ( be = @conn . read_ber ( Net ::LDAP ::AsnSyntax ) ) && ( pdu = Net ::LDAP ::PDU . new ( be ) )
@@ -1430,7 +1430,7 @@ def search(args = {})
14301430 end
14311431 end
14321432 when 5 # search-result
1433- result_code = pdu . result_code
1433+ result_pdu = pdu
14341434 controls = pdu . result_controls
14351435 break
14361436 else
@@ -1449,7 +1449,7 @@ def search(args = {})
14491449 # of type OCTET STRING, covered in the default syntax supported by
14501450 # read_ber, so I guess we're ok.
14511451 more_pages = false
1452- if result_code == 0 and controls
1452+ if result_pdu . result_code == 0 and controls
14531453 controls . each do |c |
14541454 if c . oid == Net ::LDAP ::LDAPControls ::PAGED_RESULTS
14551455 # just in case some bogus server sends us more than 1 of these.
@@ -1468,7 +1468,7 @@ def search(args = {})
14681468 break unless more_pages
14691469 } # loop
14701470
1471- result_code
1471+ result_pdu || OpenStruct . new ( :status => :failure , : result_code => 1 , :message => "Invalid search" )
14721472 end
14731473
14741474 MODIFY_OPERATIONS = { #:nodoc:
@@ -1508,7 +1508,8 @@ def modify(args)
15081508 @conn . write pkt
15091509
15101510 ( 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
15121513 end
15131514
15141515 #--
@@ -1529,8 +1530,12 @@ def add(args)
15291530 pkt = [ next_msgid . to_ber , request ] . to_ber_sequence
15301531 @conn . write pkt
15311532
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
15341539 end
15351540
15361541 #--
@@ -1551,7 +1556,8 @@ def rename args
15511556 ( be = @conn . read_ber ( Net ::LDAP ::AsnSyntax ) ) &&
15521557 ( pdu = Net ::LDAP ::PDU . new ( be ) ) && ( pdu . app_tag == 13 ) or
15531558 raise Net ::LDAP ::LdapError . new ( "response missing or invalid" )
1554- pdu . result_code
1559+
1560+ pdu
15551561 end
15561562
15571563 #--
@@ -1565,6 +1571,7 @@ def delete(args)
15651571 @conn . write pkt
15661572
15671573 ( 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
15691576 end
15701577end # class Connection
0 commit comments