From 253f101b392bdc65c0ca9fb7ab1ddf217300ec4c Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 17 May 2012 19:33:38 +0200 Subject: [PATCH] LDAP: check wether applying naming rule would end up in conflicts on update, if so don't do it --- apps/user_ldap/appinfo/app.php | 6 ---- apps/user_ldap/appinfo/update.php | 24 ++++++++++++++++ apps/user_ldap/lib_ldap.php | 46 +++++++++++++++++++------------ 3 files changed, 53 insertions(+), 23 deletions(-) diff --git a/apps/user_ldap/appinfo/app.php b/apps/user_ldap/appinfo/app.php index 79675f940bc..330574c1d42 100644 --- a/apps/user_ldap/appinfo/app.php +++ b/apps/user_ldap/appinfo/app.php @@ -27,12 +27,6 @@ require_once('apps/user_ldap/group_ldap.php'); OCP\App::registerAdmin('user_ldap','settings'); -// define LDAP_DEFAULT_PORT -define('OC_USER_BACKEND_LDAP_DEFAULT_PORT', 389); - -// define OC_USER_BACKEND_LDAP_DEFAULT_DISPLAY_NAME -define('OC_USER_BACKEND_LDAP_DEFAULT_DISPLAY_NAME', 'uid'); - // register user backend OC_User::useBackend( 'LDAP' ); OC_Group::useBackend( new OC_GROUP_LDAP() ); diff --git a/apps/user_ldap/appinfo/update.php b/apps/user_ldap/appinfo/update.php index 07afeeea8a1..048d804217b 100644 --- a/apps/user_ldap/appinfo/update.php +++ b/apps/user_ldap/appinfo/update.php @@ -1,9 +1,33 @@ getUsers(); +$query = OCP\DB::prepare($sqlCleanMap); +$query->execute(); +OCP\Config::setSystemValue('ldapIgnoreNamingRules', false); +OC_LDAP::init(true); +$users_new = $LDAP_USER->getUsers(); +$query = OCP\DB::prepare($sqlCleanMap); +$query->execute(); +if($users_old !== $users_new) { + //we don't need to check Groups, because they were not supported in 3' + OCP\Config::setSystemValue('ldapIgnoreNamingRules', true); } \ No newline at end of file diff --git a/apps/user_ldap/lib_ldap.php b/apps/user_ldap/lib_ldap.php index 5252f4cce7c..5cd7e0241bf 100644 --- a/apps/user_ldap/lib_ldap.php +++ b/apps/user_ldap/lib_ldap.php @@ -45,14 +45,21 @@ class OC_LDAP { static protected $ldapAgentPassword; static protected $ldapTLS; static protected $ldapNoCase; + static protected $ldapIgnoreNamingRules; // user and group settings, that are needed in both backends static protected $ldapUserDisplayName; static protected $ldapUserFilter; static protected $ldapGroupDisplayName; static protected $ldapLoginFilter; - static public function init() { - self::readConfiguration(); + /** + * @brief initializes the LDAP backend + * @param $force read the config settings no matter what + * + * initializes the LDAP backend + */ + static public function init($force = false) { + self::readConfiguration($force); self::establishConnection(); } @@ -527,6 +534,10 @@ class OC_LDAP { } static private function sanitizeUsername($name) { + if(self::$ldapIgnoreNamingRules) { + return $name; + } + //REPLACEMENTS $name = str_replace(' ', '_', $name); @@ -594,21 +605,22 @@ class OC_LDAP { /** * Caches the general LDAP configuration. */ - static private function readConfiguration() { - if(!self::$configured) { - self::$ldapHost = OCP\Config::getAppValue('user_ldap', 'ldap_host', ''); - self::$ldapPort = OCP\Config::getAppValue('user_ldap', 'ldap_port', OC_USER_BACKEND_LDAP_DEFAULT_PORT); - self::$ldapAgentName = OCP\Config::getAppValue('user_ldap', 'ldap_dn',''); - self::$ldapAgentPassword = base64_decode(OCP\Config::getAppValue('user_ldap', 'ldap_agent_password','')); - self::$ldapBase = OCP\Config::getAppValue('user_ldap', 'ldap_base', ''); - self::$ldapBaseUsers = OCP\Config::getAppValue('user_ldap', 'ldap_base_users',self::$ldapBase); - self::$ldapBaseGroups = OCP\Config::getAppValue('user_ldap', 'ldap_base_groups', self::$ldapBase); - self::$ldapTLS = OCP\Config::getAppValue('user_ldap', 'ldap_tls',0); - self::$ldapNoCase = OCP\Config::getAppValue('user_ldap', 'ldap_nocase', 0); - self::$ldapUserDisplayName = strtolower(OCP\Config::getAppValue('user_ldap', 'ldap_display_name', OC_USER_BACKEND_LDAP_DEFAULT_DISPLAY_NAME)); - self::$ldapUserFilter = OCP\Config::getAppValue('user_ldap', 'ldap_userlist_filter','objectClass=person'); - self::$ldapLoginFilter = OCP\Config::getAppValue('user_ldap', 'ldap_login_filter', '(uid=%uid)'); - self::$ldapGroupDisplayName = strtolower(OCP\Config::getAppValue('user_ldap', 'ldap_group_display_name', LDAP_GROUP_DISPLAY_NAME_ATTR)); + static private function readConfiguration($force = false) { + if(!self::$configured || $force) { + self::$ldapHost = OCP\Config::getAppValue('user_ldap', 'ldap_host', ''); + self::$ldapPort = OCP\Config::getAppValue('user_ldap', 'ldap_port', 389); + self::$ldapAgentName = OCP\Config::getAppValue('user_ldap', 'ldap_dn',''); + self::$ldapAgentPassword = base64_decode(OCP\Config::getAppValue('user_ldap', 'ldap_agent_password','')); + self::$ldapBase = OCP\Config::getAppValue('user_ldap', 'ldap_base', ''); + self::$ldapBaseUsers = OCP\Config::getAppValue('user_ldap', 'ldap_base_users',self::$ldapBase); + self::$ldapBaseGroups = OCP\Config::getAppValue('user_ldap', 'ldap_base_groups', self::$ldapBase); + self::$ldapTLS = OCP\Config::getAppValue('user_ldap', 'ldap_tls',0); + self::$ldapNoCase = OCP\Config::getAppValue('user_ldap', 'ldap_nocase', 0); + self::$ldapUserDisplayName = strtolower(OCP\Config::getAppValue('user_ldap', 'ldap_display_name', 'uid')); + self::$ldapUserFilter = OCP\Config::getAppValue('user_ldap', 'ldap_userlist_filter','objectClass=person'); + self::$ldapLoginFilter = OCP\Config::getAppValue('user_ldap', 'ldap_login_filter', '(uid=%uid)'); + self::$ldapGroupDisplayName = strtolower(OCP\Config::getAppValue('user_ldap', 'ldap_group_display_name', LDAP_GROUP_DISPLAY_NAME_ATTR)); + self::$ldapIgnoreNamingRules = OCP\Config::getSystemValue('ldapIgnoreNamingRules', false); if(empty(self::$ldapBaseUsers)) { OCP\Util::writeLog('ldap', 'Base for Users is empty, using Base DN', OCP\Util::INFO); -- 2.39.5