From: Francis Cianfrocca Date: 2007-05-02T06:21:17+09:00 Subject: Re: ActiveLdap questions ------=_Part_57581_30959997.1178054476499 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 5/1/07, Reid Wightman wrote: > > Hi All - > > I have some silly questions about ActiveLdap. I'm a pretty new Ruby > programmer, so I may be doing foolish things... > > I am trying to connect to and search for records on my ldap server. I > have > installed activeldap using gem. My test ruby program looks like this: > :: > require 'rubygems' > require 'log4r' > require 'active_ldap' > > class Entry < ActiveLdap::Base > ldap_mapping :dn_attribute=>"cn" > end > > ActiveLdap::Base.establish_connection( > :host => "ldap-server.domain", > :port => 389, > :bind_dn => "ou=A,ou=B,ou=c,ou=D,o=E,c=US" > ) > > entry = Entry.find("krwightm") > :: > When I run this, I get: > /var/lib/gems/1.8/gems/ruby-activeldap-0.8.1 > /lib/active_ldap/base.rb:531:in > `find_one': Couldn't find Device with DN=krwightm (cn=krwightm) > (ActiveLdap::EntryNotFound) > > If I perform the same query with the command-line tool ldapsearch: > > ldapsearch -x -LLL -h ldap-server.domain -p 389 -b > "ou=A,ou=B,ou=C,ou=D,o=E,c=US" "(cn=krwightm)" The ldapsearch line is setting both a treebase and a search filter. Neither is present in your ActiveLDAP query. In addition you're passing what you think is a filter string to Entry.find, whereas it's looking for a DN. (Both queries are binding anonymously, which is unusual, but you'd have gotten a different message from ldapsearch if that were a problem.) Look into the Net::LDAP library on Rubyforge, also installable as a gem. It has a reasonably complete rdoc, including some theory of how LDAP queries work. ------=_Part_57581_30959997.1178054476499--