LinuxQuestions.org
Register a domain and help support LQ
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
 
LinkBack Search this Thread
Old 10-27-2008, 11:26 PM   #1
noir911
Member
 
Registered: Apr 2004
Location: Baltimore, MD
Posts: 681

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
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 13,787

Rep: Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359
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
Location: Baltimore, MD
Posts: 681

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
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 13,787

Rep: Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359Reputation: 2359
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
Location: Baltimore, MD
Posts: 681

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are 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


All times are GMT -5. The time now is 08:14 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration