LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-27-2008, 11:26 PM   #1
noir911
Member
 
Registered: Apr 2004
Posts: 682

Rep: Reputation: Disabled
[Ruby] simple LDAP query


I'm using ruby-1.8.6 and trying to query my Windows Active Directory LDAP server. But I'm getting connection failed. Could anyone please tell me what I'm doing wrong? Thanks.

Here's the code

Code:
#!/usr/bin/ruby
require 'rubygems'
require 'net/ldap'

ldap = Net::LDAP.new
ldap.host = "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
 
Old 10-28-2008, 09:16 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,635

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by noir911 View Post
I'm using ruby-1.8.6 and trying to query my Windows Active Directory LDAP server. But I'm getting connection failed. Could anyone please tell me what I'm doing wrong? Thanks.

Here's the code

Code:
#!/usr/bin/ruby
require 'rubygems'
require 'net/ldap'

ldap = Net::LDAP.new
ldap.host = "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
Maybe if you included the error message we could.

First thing I'd check is the user ID and password, along with the ldap host name. I'd also make sure you could resolve the name via a ping, or maybe try to put the IP address in, instead of the host name.
 
Old 10-28-2008, 03:28 PM   #3
noir911
Member
 
Registered: Apr 2004
Posts: 682

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
Maybe if you included the error message we could.

First thing I'd check is the user ID and password, along with the ldap host name. I'd also make sure you could resolve the name via a ping, or maybe try to put the IP address in, instead of the host name.
When I run the script it says "Fail!" and this is the only error message I get.

I tried putting the IP address with no luck. And, yes, I can ping the host both via IP and host name. The user name and password is also correct.

How can I get verbose debug output to see exactly which line in the script is failing?
 
Old 10-28-2008, 03:54 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,635

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by noir911 View Post
When I run the script it says "Fail!" and this is the only error message I get.

I tried putting the IP address with no luck. And, yes, I can ping the host both via IP and host name. The user name and password is also correct.

How can I get verbose debug output to see exactly which line in the script is failing?
Well, its your program...how would you enable debugging on it? Check out ruby-debug (http://bashdb.sourceforge.net/ruby-debug.html), and see if it can help you.

You can verify that things are working by firing up an email client (like Thunderbird), which supports LDAP. Enter the criteria in it, and see if you can pull up the address book. If you can get coherent LDAP data using something that you know works (command-line query, Thunderbird, etc.), it's probably something like your syntax, or how you're passing things.
 
Old 10-29-2008, 11:38 PM   #5
noir911
Member
 
Registered: Apr 2004
Posts: 682

Original Poster
Rep: Reputation: Disabled
Solved. The user ID must be user_name@full.base.of.domain. Thanks to the ruby-talk mailing list for pointing this out to me.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LDAP Query cjagdish69 Linux - Server 0 11-18-2006 01:16 AM
Simple query sachinh Linux - Hardware 2 12-28-2004 11:42 PM
a simple query sachinh Linux - Security 1 11-29-2004 06:13 AM
How can I manually query a ldap server from terminal? randomx Linux - General 2 10-07-2003 01:04 PM
maybe NOT so simple an output query dougp Linux - General 1 09-05-2002 08:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration