# Simple LDAP query

**URL:** <https://www.ruby-forum.com/t/simple-ldap-query/152023>\
**Category:** Ruby\
**Created:** [October 29, 2008, 7:00am UTC](https://www.ruby-forum.com/t/simple-ldap-query/152023 "2008-10-29T07:00:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [October 29, 2008, 7:00am UTC](https://www.ruby-forum.com/t/simple-ldap-query/152023/1 "2008-10-29T07:00:51Z")

</div>

I’m using ruby-1.8.6 and trying to query my Windows Active Directory  
LDAP server. But I’m getting connection failed. I can ping the AD  
server, I can resolve the host name or the IP address and I know the  
LDAP authentication is working. But I’m still getting error message  
when I query it via the following script. The error message I get is  
“fail!”

Could anyone please tell me what I’m doing wrong? Do I need to define  
the base DN?

#!/usr/bin/ruby  
require ‘rubygems’  
require ‘net/ldap’

ldap = Net::LDAP.new  
ldap.host = “[ldap.domain.com](http://ldap.domain.com)”  
ldap.port = 389  
ldap.auth “user\_ID”, “password”  
if ldap.bind  
print “success!\n”

# authentication succeeded

else  
print “fail!\n”

# authentication failed

end

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [October 29, 2008, 2:10pm UTC](https://www.ruby-forum.com/t/simple-ldap-query/152023/2 "2008-10-29T14:10:33Z")

</div>

What is the value of user\_ID?

it needs to be removed\_email\_address@domain.invalid

On Tue, Oct 28, 2008 at 11:59 PM, Chris H.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> #!/usr/bin/ruby  
> else  
> print “fail!\n”
> 
> # authentication failed
> 
> end

–  
“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)

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [October 29, 2008, 2:11pm UTC](https://www.ruby-forum.com/t/simple-ldap-query/152023/3 "2008-10-29T14:11:09Z")

</div>

On Wed, Oct 29, 2008 at 7:09 AM, Glen H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > LDAP authentication is working. But I’m still getting error message  
> > ldap = Net::LDAP.new
> 
> –  
> “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)

It probably wouldn’t hurt to supply the base either.

–  
“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)

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [October 30, 2008, 5:37am UTC](https://www.ruby-forum.com/t/simple-ldap-query/152023/4 "2008-10-30T05:37:04Z")

</div>

On Thu, Oct 30, 2008 at 12:09 AM, Glen H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> What is the value of user\_ID?  
> it needs to be removed\_email\_address@domain.invalid

Thanks. This works.

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [October 30, 2008, 2:15pm UTC](https://www.ruby-forum.com/t/simple-ldap-query/152023/5 "2008-10-30T14:15:16Z")

</div>

On Wed, Oct 29, 2008 at 10:35 PM, Chris H.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> On Thu, Oct 30, 2008 at 12:09 AM, Glen H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > What is the value of user\_ID?  
> > it needs to be removed\_email\_address@domain.invalid
> 
> Thanks. This works.

Cool

–  
“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)
