Net LDAP problem (no attrs or get_attributes methods)

So I am having difficulty getting the attributes for an LDAP entry. If
I
check for specific attributes by name that works fine. However when I
try
the following:

ldap.search(:base => base, :filter => address_only_filter,
:return_result =>
false) do |entry|
p entry.dn
p entry.attrs
puts “\n\n”
end

I get the following error:

/Library/Ruby/Gems/1.8/gems/ruby-net-ldap-0.0.4/lib/net/ldap/entry.rb:152:in
‘method_missing’: undefined method ‘attrs’ (NoMethodError)

I get the same NoMethodError when I try get_attributes.

I am getting a Net::LDAP::Entry object back from the search as verified
by
changing the p entry.attrs to p entry.class

Anyone else run across this?


“Hey brother Christian with your high and mighty errand, Your actions
speak
so loud, I can’t hear a word you’re saying.”

-Greg Graffin (Bad Religion)

ldap.search(base, scope, filter, attrs) { |entry|
p entry.dn
p entry.attrs
}

Does the above work for you?

Regards,

  • Mac

Nope, same error. I passed “*” to the attrs argument.

On Wed, Oct 28, 2009 at 2:03 PM, Michael L.
[email protected]wrote:


Posted via http://www.ruby-forum.com/.


“Hey brother Christian with your high and mighty errand, Your actions
speak
so loud, I can’t hear a word you’re saying.”

-Greg Graffin (Bad Religion)

On Thu, Oct 29, 2009 at 12:28 PM, Michael L.
[email protected]wrote:


Posted via http://www.ruby-forum.com/.

The docs say string or array of strings. Tried it with :attributes =>
[]
and I get the same error. I also tried reinstalling the gem but that
didn’t
help.


“Hey brother Christian with your high and mighty errand, Your actions
speak
so loud, I can’t hear a word you’re saying.”

-Greg Graffin (Bad Religion)

The docs say string or array of strings. Tried it with :attributes =>
[]
and I get the same error. I also tried reinstalling the gem but that
didn’t
help.

What gem are you using? ruby-net-ldap? via require ‘net/ldap’?
Might help to post more of your code so I can understand the whole
picture of things…

p entry.attrs is invalid as it isn’t a method per’se… hence the
NoMethodError.
attrs is like you said a string or array of strings.

It should be used via connection.add(“dc=localhost, dc=localdomain”,
entry)

Regards,

  • Mac

Glen H. wrote:

Nope, same error. I passed “*” to the attrs argument.

Well, attrs should be an array I believe, try initializing it as such:
attrs = []
and see what happens.

Regards,

  • Mac

On Thu, Oct 29, 2009 at 1:54 PM, Michael L.
[email protected]wrote:


Posted via http://www.ruby-forum.com/.

Here is the code in its entirety:

require ‘rubygems’
require ‘net/ldap’

ldap = Net::LDAP.new :host => , :port => 389, :auth => { :method =>
:simple,
:username => “”, :password => “” }

address_only_filter = Net::LDAP::Filter.pres(“mailForwardingAddress”) &
~(Net::LDAP::Filter.eq(“mailDeliveryOption”, “forward”))

base = “ou=People,o=cnm.edu,o=cp”

ldap.search(:base => base, :scope =>
Net::LDAP::SearchScope_WholeSubtree,
:filter => address_only_filter, :attributes => “*”) do |entry|
p entry.dn
p entry.attrs
end

I’ve removed the credentials and the host IP intentionally. Calling a
specific attribute on the object works just fine. It just breaks when I
try
to request all of them. I figured it would be the easiest way to ensure
I
only remove the attribute I’m interested in since not all records are
sure
to have the same attributes.


“Hey brother Christian with your high and mighty errand, Your actions
speak
so loud, I can’t hear a word you’re saying.”

-Greg Graffin (Bad Religion)