Skip to content

Commit 789b36c

Browse files
author
blackhedd
committed
extended our support for error messages returned from servers.
1 parent 17dcc52 commit 789b36c

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
* Added missing synactic support for Filter ANDs, NOTs and a few other
2727
things.
2828
* Added some support for SNMP data-handling.
29+
* Extended support for server-reported error messages. This was provisionally
30+
added to Net::LDAP#add, and eventually will be added to other methods.
2931

3032

3133
== Net::LDAP 0.0.4: August 15, 2006

lib/net/ldap.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,17 @@ def LDAP::open args
510510
# puts "Message: #{ldap.get_operation_result.message}"
511511
# end
512512
#
513+
#--
514+
# Modified the implementation, 20Mar07. We might get a hash of LDAP response codes
515+
# instead of a simple numeric code.
516+
#
513517
def get_operation_result
514518
os = OpenStruct.new
515-
if @result
519+
if @result.is_a?(Hash)
520+
os.code = (@result[:resultCode] || "").to_i
521+
os.error_message = @result[:errorMessage]
522+
os.matched_dn = @result[:matchedDN]
523+
elsif @result
516524
os.code = @result
517525
else
518526
os.code = 0
@@ -802,6 +810,9 @@ def bind_as args={}
802810
# Net::LDAP.open (:host => host) do |ldap|
803811
# ldap.add( :dn => dn, :attributes => attr )
804812
# end
813+
#--
814+
# Provisional modification: Connection#add returns a full hash with LDAP status values,
815+
# instead of the simple result number we're used to getting.
805816
#
806817
def add args
807818
if @open_connection
@@ -1421,6 +1432,10 @@ def modify args
14211432
#--
14221433
# add
14231434
# TODO, need to support a time limit, in case the server fails to respond.
1435+
# Unlike other operation-methods in this class, we return a result hash rather
1436+
# than a simple result number. This is experimental, and eventually we'll want
1437+
# to do this with all the others. The point is to have access to the error message
1438+
# and the matched-DN returned by the server.
14241439
#
14251440
def add args
14261441
add_dn = args[:dn] or raise LdapError.new("Unable to add empty DN")
@@ -1434,7 +1449,7 @@ def add args
14341449
@conn.write pkt
14351450

14361451
(be = @conn.read_ber(AsnSyntax)) && (pdu = LdapPdu.new( be )) && (pdu.app_tag == 9) or raise LdapError.new( "response missing or invalid" )
1437-
pdu.result_code
1452+
pdu.result
14381453
end
14391454

14401455

lib/net/ldap/pdu.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ def initialize ber_object
119119
end
120120
end
121121

122+
# Returns a hash which (usually) defines the members :resultCode, :errorMessage, and :matchedDN.
123+
# These values come directly from an LDAP response packet returned by the remote peer.
124+
# See #result_code for a sugaring.
125+
#
126+
def result
127+
@ldap_result || {}
128+
end
129+
122130
#
123131
# result_code
124132
# This returns an LDAP result code taken from the PDU,

0 commit comments

Comments
 (0)