4

folks! I get the following error message and I have no idea what to do. Is this a already known net-ldap bug? I tried to update my gems and I already looked for further informations in the internet. The first part is ok, I get ally my data from my ldap database but this error occurs in the end.

/usr/local/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net/ber/core_ext/string.rb:23:in encode': "\x8E" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError) from /usr/local/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net/ber/core_ext/string.rb:23:in raw_utf8_encoded' from /usr/local/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net/ber/core_ext/string.rb:15:in to_ber' from /usr/local/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net/ldap.rb:1396:in block in search' from /usr/local/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net/ldap.rb:1367:in loop' from /usr/local/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net/ldap.rb:1367:in search' from /usr/local/lib/ruby/gems/1.9.1/gems/net-ldap-0.3.1/lib/net/ldap.rb:637:in `search'

and here my code:

require 'rubygems'
require 'net/ldap'

ldap = Net::LDAP.new
ldap.host = 'xxxxxx'
ldap.authenticate "cn=admin, dc=xxxx, dc=xxxxx, dc=de", "xxxxx!"
#puts ldap.bind
if ldap.bind
  # authentication succeeded
else
  # authentication failed
 # p ldap.get_operation_result
end


filter = Net::LDAP::Filter.eq("uid", "*")
treebase = "xxxxx, dc=xxxxxx, dc=de"

ldap.search(:base => treebase, :filter => filter) do |entry|
  puts "DN: #{entry.dn}"
  entry.each do |attribute, values|
    puts "   #{attribute}:"
    values.each do |value|
      puts "      --->#{value}"
    end
  end
end
gadreel
  • 207
  • 1
  • 2
  • 13

1 Answers1

3

There are many encoding issues in v0.3.1 of net-ldap [1],[2],[3],[4]. Several patches are already merged, but sadly, this great project seems semi-abandoned and the changes aren't pushed out to rubygems. Using it directly from github has been working well for me, and if you're using bundler, it is as easy sticking something like this in your Gemfile:

gem "net-ldap", :git => "git://github.com/ruby-ldap/ruby-net-ldap.git", :ref => '8a182675f4'

1 - https://github.com/ruby-ldap/ruby-net-ldap/pull/41
2 - https://github.com/ruby-ldap/ruby-net-ldap/pull/44
3 - https://github.com/ruby-ldap/ruby-net-ldap/pull/64
4 - https://github.com/ruby-ldap/ruby-net-ldap/pull/55

Ryan Horrisberger
  • 955
  • 11
  • 16