Use generic function for LDAP connection in LDAP server module

This commit is contained in:
Jamie Cameron
2008-12-04 22:34:01 +00:00
parent 49a37fbf32
commit ed2af49587
4 changed files with 18 additions and 24 deletions

View File

@@ -187,10 +187,10 @@ local $uri = &find_svalue("uri", $conf);
local ($ldap, $use_ssl, $err);
local $ssl = &find_svalue("ssl", $conf);
if ($ldap_hosts) {
# Using hosts from module config
# Using hosts from parameter
local @hosts = split(/\s+/, $ldap_hosts);
if ($config{'ldap_tls'} ne '') {
$use_ssl = $config{'ldap_tls'};
if ($ldap_ssl ne '') {
$use_ssl = $ldap_ssl;
}
else {
$use_ssl = $ssl eq 'yes' ? 1 :
@@ -201,7 +201,7 @@ if ($ldap_hosts) {
($use_ssl == 1 ? 636 : 389);
foreach $host (@hosts) {
$ldap = Net::LDAP->new($host, port => $port,
schema => $use_ssl == 2 ? 'ldaps' : 'ldap');
scheme => $use_ssl == 1 ? 'ldaps' : 'ldap');
if (!$ldap) {
$err = &text('ldap_econn',
"<tt>$host</tt>", "<tt>$port</tt>");
@@ -252,7 +252,7 @@ else {
foreach $host (@hosts) {
$ldap = Net::LDAP->new($host, port => $port,
schema => $use_ssl == 1 ? 'ldaps' : 'ldap');
scheme => $use_ssl == 1 ? 'ldaps' : 'ldap');
if (!$ldap) {
$err = &text('ldap_econn',
"<tt>$host</tt>", "<tt>$port</tt>");

View File

@@ -3,7 +3,7 @@ server=LDAP server hostname,3,This system,Remote system
port=LDAP server port,3,Detect automatically
user=Login for LDAP server,3,Detect automatically
pass=Password for LDAP server,3,Detect automatically
ssl=Use TLS encryption with LDAP server?,1,-Detect automatically,1-Yes,0-No
ssl=Use encryption with LDAP server?,1,-Detect automatically,1-Yes,2-Yes TLS,0-No
slapd=Full path to OpenLDAP server program,8
config_file=OpenLDAP server configuration file,8
schema_dir=OpenLDAP schema directory,7

View File

@@ -63,29 +63,23 @@ else {
}
$ssl = $config{'ssl'};
# Try to connect
local @ssls = $ssl eq "" ? ( 1, 0 ) : ( $ssl );
# Call generic LDAP client function to connect
&foreign_require("ldap-client", "ldap-client-lib.pl");
local @ssls = $ssl eq "" ? ( 1, 2, 0 ) : ( $ssl );
local $ldap;
foreach $ssl (@ssls) {
my $sslport = $port ? $port : $ssl ? 636 : 389;
$ldap = Net::LDAP->new($server, port => $sslport,
scheme=>$ssl ? 'ldaps' : 'ldap');
if (!$ldap) {
# Connection failed .. give up completely
return &text('connect_eldap', "<tt>$server</tt>", $sslport);
my $sslport = $port ? $port : $ssl == 1 ? 636 : 389;
$ldap = &ldap_client::generic_ldap_connect($server, $sslport, $ssl,
$user, $pass);
if (!ref($ldap)) {
# Failed .. but try again in other SSL mode
if ($ssl == $ssls[$#ssls]) {
return $ldap;
}
}
}
$ldap || return "This can't happen!";
# Login to server
local $mesg = $pass eq '' ?
$ldap->bind(dn => $user, anonymous => 1) :
$ldap->bind(dn => $user, password => $pass);
if (!$mesg || $mesg->code) {
return &text('connect_elogin', "<tt>$server</tt>", "<tt>$user</tt>",
&ldap_error($mesg));
}
$connect_ldap_db = $ldap;
return $ldap;
}

View File

@@ -1,6 +1,6 @@
desc=LDAP Server
longdesc=Manage the OpenLDAP server and objects in its database
category=servers
category=servers ldap-client
perldepends=Net::LDAP
desc_ca=Servidor LDAP
desc_nl=LDAP Server