Permalink
Browse files

extended our support for error messages returned from servers.

  • Loading branch information...
blackhedd
blackhedd committed Mar 20, 2007
1 parent 17dcc52 commit 789b36c9d75c9ca552da8d1b3bd78f519cdaaa7f
Showing with 27 additions and 2 deletions.
  1. +2 −0 ChangeLog
  2. +17 −2 lib/net/ldap.rb
  3. +8 −0 lib/net/ldap/pdu.rb
View
@@ -26,6 +26,8 @@
* Added missing synactic support for Filter ANDs, NOTs and a few other
things.
* Added some support for SNMP data-handling.
+* Extended support for server-reported error messages. This was provisionally
+ added to Net::LDAP#add, and eventually will be added to other methods.
== Net::LDAP 0.0.4: August 15, 2006
View
@@ -510,9 +510,17 @@ def LDAP::open args
# puts "Message: #{ldap.get_operation_result.message}"
# end
#
+ #--
+ # Modified the implementation, 20Mar07. We might get a hash of LDAP response codes
+ # instead of a simple numeric code.
+ #
def get_operation_result
os = OpenStruct.new
- if @result
+ if @result.is_a?(Hash)
+ os.code = (@result[:resultCode] || "").to_i
+ os.error_message = @result[:errorMessage]
+ os.matched_dn = @result[:matchedDN]
+ elsif @result
os.code = @result
else
os.code = 0
@@ -802,6 +810,9 @@ def bind_as args={}
# Net::LDAP.open (:host => host) do |ldap|
# ldap.add( :dn => dn, :attributes => attr )
# end
+ #--
+ # Provisional modification: Connection#add returns a full hash with LDAP status values,
+ # instead of the simple result number we're used to getting.
#
def add args
if @open_connection
@@ -1421,6 +1432,10 @@ def modify args
#--
# add
# TODO, need to support a time limit, in case the server fails to respond.
+ # Unlike other operation-methods in this class, we return a result hash rather
+ # than a simple result number. This is experimental, and eventually we'll want
+ # to do this with all the others. The point is to have access to the error message
+ # and the matched-DN returned by the server.
#
def add args
add_dn = args[:dn] or raise LdapError.new("Unable to add empty DN")
@@ -1434,7 +1449,7 @@ def add args
@conn.write pkt
(be = @conn.read_ber(AsnSyntax)) && (pdu = LdapPdu.new( be )) && (pdu.app_tag == 9) or raise LdapError.new( "response missing or invalid" )
- pdu.result_code
+ pdu.result
end
View
@@ -119,6 +119,14 @@ def initialize ber_object
end
end
+ # Returns a hash which (usually) defines the members :resultCode, :errorMessage, and :matchedDN.
+ # These values come directly from an LDAP response packet returned by the remote peer.
+ # See #result_code for a sugaring.
+ #
+ def result
+ @ldap_result || {}
+ end
+
#
# result_code
# This returns an LDAP result code taken from the PDU,

0 comments on commit 789b36c

Please sign in to comment.