From f4a7ae20534d1ce9f96b3226f9b217459d49ecf6 Mon Sep 17 00:00:00 2001 From: Marco Dickert Date: Mon, 3 Jul 2017 11:30:11 +0200 Subject: [PATCH] finalized ldap support --- ifm.php | 10 +++++++--- src/config.php | 2 +- src/main.php | 8 ++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/ifm.php b/ifm.php index 5abaa6e..023f233 100644 --- a/ifm.php +++ b/ifm.php @@ -53,7 +53,7 @@ class IFMConfig { LDAP auth syntax - const auth_source = 'ldap;:'; + const auth_source = 'ldap;;'; The script will add "uid=," to the rootdn for binding. If your ldap server does not use uid for usernames you can change it in the function checkCredentials. @@ -1855,15 +1855,19 @@ ifm.init(); break; case "ldap": $authenticated = false; - list( $ldap_server, $rootdn ) = explode( ":", $srcopt ); + list( $ldap_server, $rootdn ) = explode( ";", $srcopt ); $u = "uid=" . $user . "," . $rootdn; - $ds = ldap_connect( $ldap_server ) or ( trigger_error( "Could not reach the ldap server.", E_USER_ERROR ); return false; ); + if( ! $ds = ldap_connect( $ldap_server ) ) { + trigger_error( "Could not reach the ldap server.", E_USER_ERROR ); + return false; + } ldap_set_option( $ds, LDAP_OPT_PROTOCOL_VERSION, 3 ); if( $ds ) { $ldbind = @ldap_bind( $ds, $u, $pass ); if( $ldbind ) { $authenticated = true; } else { + trigger_error( ldap_error( $ds ), E_USER_ERROR ); $authenticated = false; } ldap_unbind( $ds ); diff --git a/src/config.php b/src/config.php index 04b9c99..b48fd37 100644 --- a/src/config.php +++ b/src/config.php @@ -53,7 +53,7 @@ class IFMConfig { LDAP auth syntax - const auth_source = 'ldap;:'; + const auth_source = 'ldap;;'; The script will add "uid=," to the rootdn for binding. If your ldap server does not use uid for usernames you can change it in the function checkCredentials. diff --git a/src/main.php b/src/main.php index b62dc27..9118d72 100644 --- a/src/main.php +++ b/src/main.php @@ -633,15 +633,19 @@ class IFM { break; case "ldap": $authenticated = false; - list( $ldap_server, $rootdn ) = explode( ":", $srcopt ); + list( $ldap_server, $rootdn ) = explode( ";", $srcopt ); $u = "uid=" . $user . "," . $rootdn; - $ds = ldap_connect( $ldap_server ) or ( trigger_error( "Could not reach the ldap server.", E_USER_ERROR ); return false; ); + if( ! $ds = ldap_connect( $ldap_server ) ) { + trigger_error( "Could not reach the ldap server.", E_USER_ERROR ); + return false; + } ldap_set_option( $ds, LDAP_OPT_PROTOCOL_VERSION, 3 ); if( $ds ) { $ldbind = @ldap_bind( $ds, $u, $pass ); if( $ldbind ) { $authenticated = true; } else { + trigger_error( ldap_error( $ds ), E_USER_ERROR ); $authenticated = false; } ldap_unbind( $ds );