Skip to content

Commit 0117d38

Browse files
author
blackhedd
committed
Converted LDAP#bind to return T/F and added LDAP::get_operation_result
to retrieve extended error information.
1 parent 4bc667f commit 0117d38

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

lib/net/ldap.rb

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242

4343
require 'socket'
44+
require 'ostruct'
4445
require 'net/ber'
4546
require 'net/ldap/pdu'
4647
require 'net/ldap/filter'
@@ -141,6 +142,27 @@ def LDAP::open args
141142
ldap.open {|ldap1| yield ldap1 }
142143
end
143144

145+
# This method will return a meaningful result any time after
146+
# a protocol operation (bind, search, add, modify, rename, delete)
147+
# has completed.
148+
# It returns an OpenStruct containing an LDAP result code (0 means success),
149+
# and a human-readable string.
150+
# unless ldap.bind
151+
# puts "Result: #{ldap.get_operation_result.code}"
152+
# puts "Message: #{ldap.get_operation_result.message}"
153+
# end
154+
#
155+
def get_operation_result
156+
os = OpenStruct.new
157+
if @result
158+
os.code = @result
159+
else
160+
os.code = 0
161+
end
162+
os.message = LDAP.result2string( os.code )
163+
os
164+
end
165+
144166

145167
# This method opens a network connection to the server and then
146168
# passes self to the caller-supplied block. The connection is
@@ -206,13 +228,14 @@ def search args
206228
#
207229
def bind
208230
if @open_connection
209-
@open_connection.bind @auth
231+
@result = @open_connection.bind @auth
210232
else
211233
conn = Connection.new( :host => @host, :port => @port )
212-
result = conn.bind @auth
234+
@result = conn.bind @auth
213235
conn.close
214-
result
215236
end
237+
238+
@result == 0
216239
end
217240

218241
#

0 commit comments

Comments
 (0)