diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2013-09-13 19:01:40 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@owncloud.com> | 2013-10-04 11:47:40 +0200 |
commit | 0c837cefb68102dc7548d62fb78ab36ef8be9a29 (patch) | |
tree | cbff15c4de71ae114647f672ada2d35897d89d71 /apps/user_ldap/appinfo/update.php | |
parent | c38638fdf4ccaa04dc33b2975b5e4832ef04b703 (diff) | |
download | nextcloud-server-0c837cefb68102dc7548d62fb78ab36ef8be9a29.tar.gz nextcloud-server-0c837cefb68102dc7548d62fb78ab36ef8be9a29.zip |
LDAP: allow different UUID attributes for groups and users
Diffstat (limited to 'apps/user_ldap/appinfo/update.php')
-rw-r--r-- | apps/user_ldap/appinfo/update.php | 103 |
1 files changed, 17 insertions, 86 deletions
diff --git a/apps/user_ldap/appinfo/update.php b/apps/user_ldap/appinfo/update.php index 179451dad69..41770cf97b1 100644 --- a/apps/user_ldap/appinfo/update.php +++ b/apps/user_ldap/appinfo/update.php @@ -1,20 +1,5 @@ <?php -//from version 0.1 to 0.2 - -//ATTENTION -//Upgrade from ownCloud 3 (LDAP backend 0.1) to ownCloud 4.5 (LDAP backend 0.3) is not supported!! -//You must do upgrade to ownCloud 4.0 first! -//The upgrade stuff in the section from 0.1 to 0.2 is just to minimize the bad effects. - -//settings -$pw = OCP\Config::getAppValue('user_ldap', 'ldap_password'); -if(!is_null($pw)) { - $pwEnc = base64_encode($pw); - OCP\Config::setAppValue('user_ldap', 'ldap_agent_password', $pwEnc); - OC_Appconfig::deleteKey('user_ldap', 'ldap_password'); -} - //detect if we can switch on naming guidelines. We won't do it on conflicts. //it's a bit spaghetti, but hey. $state = OCP\Config::getSystemValue('ldapIgnoreNamingRules', 'unset'); @@ -22,75 +7,21 @@ if($state === 'unset') { OCP\Config::setSystemValue('ldapIgnoreNamingRules', false); } -//from version 0.2 to 0.3 (0.2.0.x dev version) -$objects = array('user', 'group'); - -$connector = new \OCA\user_ldap\lib\Connection(); -$userBE = new \OCA\user_ldap\USER_LDAP(); -$userBE->setConnector($connector); -$groupBE = new \OCA\user_ldap\GROUP_LDAP(); -$groupBE->setConnector($connector); - -foreach($objects as $object) { - $fetchDNSql = ' - SELECT `ldap_dn`, `owncloud_name`, `directory_uuid` - FROM `*PREFIX*ldap_'.$object.'_mapping`'; - $updateSql = ' - UPDATE `*PREFIX*ldap_'.$object.'_mapping` - SET `ldap_DN` = ?, `directory_uuid` = ? - WHERE `ldap_dn` = ?'; - - $query = OCP\DB::prepare($fetchDNSql); - $res = $query->execute(); - $DNs = $res->fetchAll(); - $updateQuery = OCP\DB::prepare($updateSql); - foreach($DNs as $dn) { - $newDN = escapeDN(mb_strtolower($dn['ldap_dn'], 'UTF-8')); - if(!empty($dn['directory_uuid'])) { - $uuid = $dn['directory_uuid']; - } elseif($object === 'user') { - $uuid = $userBE->getUUID($newDN); - //fix home folder to avoid new ones depending on the configuration - $userBE->getHome($dn['owncloud_name']); - } else { - $uuid = $groupBE->getUUID($newDN); - } - try { - $updateQuery->execute(array($newDN, $uuid, $dn['ldap_dn'])); - } catch(Exception $e) { - \OCP\Util::writeLog('user_ldap', - 'Could not update '.$object.' '.$dn['ldap_dn'].' in the mappings table. ', - \OCP\Util::WARN); - } - - } -} - -function escapeDN($dn) { - $aDN = ldap_explode_dn($dn, false); - unset($aDN['count']); - foreach($aDN as $key => $part) { - $value = substr($part, strpos($part, '=')+1); - $escapedValue = strtr($value, Array(','=>'\2c', '='=>'\3d', '+'=>'\2b', - '<'=>'\3c', '>'=>'\3e', ';'=>'\3b', '\\'=>'\5c', - '"'=>'\22', '#'=>'\23')); - $part = str_replace($part, $value, $escapedValue); - } - $dn = implode(',', $aDN); - - return $dn; -} - - -// SUPPORTED UPGRADE FROM Version 0.3 (ownCloud 4.5) to 0.4 (ownCloud 5) - -if(!isset($connector)) { - $connector = new \OCA\user_ldap\lib\Connection(); +$configPrefixes = OCA\user_ldap\lib\Helper::getServerConfigurationPrefixes(true); +$ldap = new OCA\user_ldap\lib\LDAP(); +foreach($configPrefixes as $config) { + $connection = new OCA\user_ldap\lib\Connection($ldap, $config); + $value = \OCP\Config::getAppValue('user_ldap', + $config.'ldap_uuid_attribute', 'auto'); + \OCP\Config::setAppValue('user_ldap', + $config.'ldap_uuid_user_attribute', $value); + \OCP\Config::setAppValue('user_ldap', + $config.'ldap_uuid_group_attribute', $value); + + $value = \OCP\Config::getAppValue('user_ldap', + $config.'ldap_expert_uuid_attr', 'auto'); + \OCP\Config::setAppValue('user_ldap', + $config.'ldap_expert_uuid_user_attr', $value); + \OCP\Config::setAppValue('user_ldap', + $config.'ldap_expert_uuid_group_attr', $value); } -//it is required, that connections do have ldap_configuration_active setting stored in the database -$connector->getConfiguration(); -$connector->saveConfiguration(); - -// we don't save it anymore, was a well-meant bad idea. Clean up database. -$query = OC_DB::prepare('DELETE FROM `*PREFIX*preferences` WHERE `appid` = ? AND `configkey` = ?'); -$query->execute(array('user_ldap' , 'homedir')); |