tags:

views:

347

answers:

2

How can I authenticate a user with LDAP using CGI/TCL stack?

Please provide a sample code-snippet if possible.


I am using an Apache Web Server on RHEL 5.0; AD exists on a remote Win2003 server.

+1  A: 

Here's the ldap package. You first bind using some "bind user" who can see everyone. You then search for the user based on some attribute like e-mail address or sAMAccountName. If the user exists, bind again using the given password and the full path of the user.

eed3si9n
Thanks.. i used this package and it was of great help.
Mohit Nanda
+1  A: 

Here is an example that will connect to an ldap server and retrieve all of the info ldap has about an email address:

package require ldap
set sEmailAddress "[email protected]"

set handle [::ldap::connect example.com 3268]
ldap::bind $handle

set result [::ldap::search $handle "dc=example,dc=com" "(mail=$sEmailAddress)" {sAMAccountName}]

foreach {object attributes} $result {
  foreach {name val} $attributes {
    puts "$name\t$val"
  }
}
ramanman
Thanks!This code requires the package mentioned by the other answer (by eed3si9n).
Mohit Nanda