# Problem connecting with ruby-net-ldap - Net::BER::BerError

**URL:** <https://www.ruby-forum.com/t/problem-connecting-with-ruby-net-ldap-net-bererror/117969>\
**Category:** Ruby\
**Created:** [October 22, 2007, 9:53pm UTC](https://www.ruby-forum.com/t/problem-connecting-with-ruby-net-ldap-net-bererror/117969 "2007-10-22T21:53:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [October 22, 2007, 9:53pm UTC](https://www.ruby-forum.com/t/problem-connecting-with-ruby-net-ldap-net-bererror/117969/1 "2007-10-22T21:53:53Z")

</div>

Hi all,

Ruby 1.8.6  
Windows XP Pro  
ruby-net-ldap 0.0.4

I’m getting a strange error when I try this simple script, where  
LDAP\_SERVER is a 3rd party ldap server:

ldap = Net::LDAP.new(:host =\> LDAP\_SERVER, :port =\> 9999)  
ldap.bind(:dn =\> ‘cn=Admin’, :password =\> ‘xxx’)  
ldap.unbind

/lib/ruby/gems/1.8/gems/ruby-net-ldap-0.0.4/lib/net/ber.rb:117:in  
`read_ber': unsupported object type: class=contextspecific, encoding=primitive, tag=7 (Net::BER::BerError) from C:/ruby/lib/ruby/gems/1.8/gems/ruby-net-ldap-0.0.4/lib/net/ ber.rb:112:in`read\_ber’  
from C:/ruby/lib/ruby/gems/1.8/gems/ruby-net-ldap-0.0.4/lib/net/  
ldap.rb:1104:in `bind' from C:/ruby/lib/ruby/gems/1.8/gems/ruby-net-ldap-0.0.4/lib/net/ ldap.rb:701:in`bind’  
from user.rb:26

Any ideas?

Thanks,

Dan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [October 22, 2007, 10:00pm UTC](https://www.ruby-forum.com/t/problem-connecting-with-ruby-net-ldap-net-bererror/117969/2 "2007-10-22T22:00:55Z")

</div>

On 10/22/07, Daniel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ldap = Net::LDAP.new(:host =\> LDAP\_SERVER, :port =\> 9999)  
> from C:/ruby/lib/ruby/gems/1.8/gems/ruby-net-ldap-0.0.4/lib/net/  
> ldap.rb:701:in `bind’  
> from user.rb:26

Dan, try syncing to the head revision of the library, there are a  
handful of  
changes not in the current release. If that doesn’t solve the problem,  
then  
I’ll look into it more closely for you.

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [October 22, 2007, 10:14pm UTC](https://www.ruby-forum.com/t/problem-connecting-with-ruby-net-ldap-net-bererror/117969/3 "2007-10-22T22:14:58Z")

</div>

On Oct 22, 2:00 pm, “Francis C.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > ldap.rb:1104:in `bind' from C:/ruby/lib/ruby/gems/1.8/gems/ruby-net-ldap-0.0.4/lib/net/ ldap.rb:701:in `bind’  
> > from user.rb:26
> 
> Dan, try syncing to the head revision of the library, there are a handful of  
> changes not in the current release. If that doesn’t solve the problem, then  
> I’ll look into it more closely for you.

Hi Francis,

Hm, something’s wacky with your SCM repository. RF says you’re using  
Subversion. All I see under trunk, however, is a bunch of CVSROOT  
files. What am I supposed to grab? The stuff under the  
experimental\_netldap branch?

Thanks,

Dan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [October 22, 2007, 10:33pm UTC](https://www.ruby-forum.com/t/problem-connecting-with-ruby-net-ldap-net-bererror/117969/4 "2007-10-22T22:33:06Z")

</div>

On 10/22/07, Daniel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hm, something’s wacky with your SCM repository. RF says you’re using  
> Subversion. All I see under trunk, however, is a bunch of CVSROOT  
> files. What am I supposed to grab? The stuff under the  
> experimental\_netldap branch?

Yes, sorry about that, it’s under branches/experimental\_netldap. I came  
into  
that project in midstream and didn’t want to disturb the existing code,  
so I  
added that branch.

I know I supported some more of the BER types when I added SNMP support  
to  
that library a few months back, so I’m hopeful this will solve your  
problem.

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [October 22, 2007, 11:41pm UTC](https://www.ruby-forum.com/t/problem-connecting-with-ruby-net-ldap-net-bererror/117969/5 "2007-10-22T23:41:01Z")

</div>

On Oct 22, 3:25 pm, Daniel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > then  
> > > that project in midstream and didn’t want to disturb the existing code, so I  
> > > 1238:in `bind': unsupported auth method () (Net::LDAP ::LdapError) from C:/ruby/lib/ruby/gems/1.8/gems/ruby-net-ldap-0.1.0/lib/ net/ldap.rb:730:in `bind’  
> > > from user.rb:26
> 
> Any ideas? Did I botch the install somehow?

I think it’s a code problem. I added this line at 1231:

meth ||= :simple

But now I get this error:

user.rb:28: undefined method `unbind’ for #Net::LDAP:0x2760280  
(NoMethodError)

I think there’s something fundamentally broken with ldap.rb now, but I  
couldn’t tell you what it is.

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [October 22, 2007, 11:56pm UTC](https://www.ruby-forum.com/t/problem-connecting-with-ruby-net-ldap-net-bererror/117969/6 "2007-10-22T23:56:15Z")

</div>

On 10/22/07, Daniel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ldap = Net::LDAP.new(:host =\> LDAP\_SERVER, :port =\> 9999)  
> ldap.bind(:dn =\> ‘cn=Admin’, :password =\> ‘xxx’)  
> ldap.unbind

Try this instead:

ldap.bind(:method=\>:simple, :dn =\> ‘cn=Admin’, :password =\> ‘xxx’)

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [October 22, 2007, 11:27pm UTC](https://www.ruby-forum.com/t/problem-connecting-with-ruby-net-ldap-net-bererror/117969/7 "2007-10-22T23:27:35Z")

</div>

On Oct 22, 2:32 pm, “Francis C.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > Hi Francis,  
> > I know I supported some more of the BER types when I added SNMP support to  
> > that library a few months back, so I’m hopeful this will solve your problem.

Ok. Now I’m seeing this (same code as before):

C:\Documents and Settings\djberge\workspace\ruby-cramer\lib  
\cramer\>ruby user.rb  
C:/ruby/lib/ruby/gems/1.8/gems/ruby-net-ldap-0.1.0/lib/net/ldap.rb:  
1238:in `bind': unsupported auth method () (Net::LDAP ::LdapError) from C:/ruby/lib/ruby/gems/1.8/gems/ruby-net-ldap-0.1.0/lib/ net/ldap.rb:730:in `bind’  
from user.rb:26

Any ideas? Did I botch the install somehow?

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [October 23, 2007, 12:09am UTC](https://www.ruby-forum.com/t/problem-connecting-with-ruby-net-ldap-net-bererror/117969/8 "2007-10-23T00:09:07Z")

</div>

On Oct 22, 3:55 pm, “Francis C.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > I’m getting a strange error when I try this simple script, where  
> > LDAP\_SERVER is a 3rd party ldap server:
> 
> > ldap = Net::LDAP.new(:host =\> LDAP\_SERVER, :port =\> 9999)  
> > ldap.bind(:dn =\> ‘cn=Admin’, :password =\> ‘xxx’)  
> > ldap.unbind
> 
> Try this instead:
> 
> ldap.bind(:method=\>:simple, :dn =\> ‘cn=Admin’, :password =\> ‘xxx’)

Ok, so it seems the bind did work. But now I get this:

user.rb:28: undefined method `unbind’ for #Net::LDAP:0x2760258  
(NoMethodError)

Strange. Any ideas?

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [October 23, 2007, 2:33pm UTC](https://www.ruby-forum.com/t/problem-connecting-with-ruby-net-ldap-net-bererror/117969/9 "2007-10-23T14:33:55Z")

</div>

On 10/22/07, Daniel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Ok, so it seems the bind did work. But now I get this:
> 
> user.rb:28: undefined method `unbind’ for #Net::LDAP:0x2760258  
> (NoMethodError)
> 
> Strange. Any ideas?

There is no unbind method. You don’t need it.

I was a little mystified that you were having so much trouble with a  
simple  
operation that is known to work well, so I went back and checked the  
rdoc  
for Net::LDAP#bind. This is a method that is usually called implicitly  
by  
the library, such as when user code requests a search against the LDAP  
directory.

However, there is an example in the documentation of how you can  
successfully use #bind without parameters. I just added an additional  
example to cover the case you used (in which credentials are passed to  
#bind  
as arguments).
