Handle new LDAP config config file path seen on Ubuntu 8.04.
---- Changes since 1.440 ----
Changed the LDAP client connection code to handle both pure-SSL and TLS modes, thanks to a patch from Paul R. Ganci.
+---- Changes since 1.450 ----
+Improved support for older versions of Net::LDAP without the hosts() function.
local $port = $ldap_port ||
&find_svalue("port", $conf) ||
($use_ssl == 1 ? 636 : 389);
- foreach $host (@hosts) {
+ foreach my $host (@hosts) {
$ldap = Net::LDAP->new($host, port => $port,
scheme => $use_ssl == 1 ? 'ldaps' : 'ldap');
if (!$ldap) {
}
elsif ($uri) {
# Using uri directive
- foreach $u (split(/\s+/, $uri)) {
+ foreach my $u (split(/\s+/, $uri)) {
if ($u =~ /^(ldap|ldaps|ldapi):\/\/([a-z0-9\_\-\.]+)(:(\d+))?/) {
($proto, $host, $port) = ($1, $2, $4);
if (!$port && $proto eq "ldap") {
return "<input type=button onClick='ifield = document.forms[$form].$field; chooser = window.open(\"popup_browser.cgi?node=$node&base=\"+escape(ifield.value), \"chooser\", \"toolbar=no,menubar=no,scrollbars=yes,width=$w,height=$h\"); chooser.ifield = ifield; window.ifield = ifield' value=\"...\">\n";
}
+# get_ldap_host()
+# Returns the hostname probably used for connecting
+sub get_ldap_host
+{
+local @hosts;
+if ($config{'ldap_hosts'}) {
+ @hosts = split(/\s+/, $config{'ldap_hosts'});
+ }
+elsif (!-r $config{'auth_ldap'}) {
+ @hosts = ( );
+ }
+else {
+ local $conf = &get_config();
+ local $uri = &find_svalue("uri", $conf);
+ if ($uri) {
+ foreach my $u (split(/\s+/, $uri)) {
+ if ($u =~ /^(ldap|ldaps|ldapi):\/\/([a-z0-9\_\-\.]+)(:(\d+))?/) {
+ push(@hosts, $2);
+ }
+ }
+ }
+ else {
+ @hosts = split(/[ ,]+/, &find_svalue("host", $conf));
+ }
+ if (!@hosts) {
+ @hosts = ( "localhost" );
+ }
+ }
+return wantarray ? @hosts : $hosts[0];
+}
+
1;