diff options
author | Bart Visscher <bartv@thisnet.nl> | 2013-02-14 22:16:48 +0100 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2013-02-14 22:16:48 +0100 |
commit | 1ef2ecd6e84321056f654e8634d8df5adbfb18d0 (patch) | |
tree | 489ee011a6c53e78e80fd2225ef1fcee7530d7e9 /apps/user_ldap/lib | |
parent | bfe6334cd9d50ce99f0a6fd02c1aa0dc43b2b7e9 (diff) | |
download | nextcloud-server-1ef2ecd6e84321056f654e8634d8df5adbfb18d0.tar.gz nextcloud-server-1ef2ecd6e84321056f654e8634d8df5adbfb18d0.zip |
Style cleanup user_ldap
Diffstat (limited to 'apps/user_ldap/lib')
-rw-r--r-- | apps/user_ldap/lib/access.php | 62 | ||||
-rw-r--r-- | apps/user_ldap/lib/connection.php | 88 | ||||
-rw-r--r-- | apps/user_ldap/lib/jobs.php | 34 |
3 files changed, 140 insertions, 44 deletions
diff --git a/apps/user_ldap/lib/access.php b/apps/user_ldap/lib/access.php index 4aa8ae8e8a4..32910b6e252 100644 --- a/apps/user_ldap/lib/access.php +++ b/apps/user_ldap/lib/access.php @@ -48,7 +48,9 @@ abstract class Access { */ public function readAttribute($dn, $attr, $filter = 'objectClass=*') { if(!$this->checkConnection()) { - \OCP\Util::writeLog('user_ldap', 'No LDAP Connector assigned, access impossible for readAttribute.', \OCP\Util::WARN); + \OCP\Util::writeLog('user_ldap', + 'No LDAP Connector assigned, access impossible for readAttribute.', + \OCP\Util::WARN); return false; } $cr = $this->connection->getConnectionResource(); @@ -123,7 +125,8 @@ abstract class Access { return $result; } - //OID sometimes gives back DNs with whitespace after the comma a la "uid=foo, cn=bar, dn=..." We need to tackle this! + //OID sometimes gives back DNs with whitespace after the comma + // a la "uid=foo, cn=bar, dn=..." We need to tackle this! $dn = preg_replace('/([^\\\]),(\s+)/u', '\1,', $dn); //make comparisons and everything work @@ -218,7 +221,8 @@ abstract class Access { * @param $ldapname optional, the display name of the object * @returns string with with the name to use in ownCloud, false on DN outside of search DN * - * returns the internal ownCloud name for the given LDAP DN of the group, false on DN outside of search DN or failure + * returns the internal ownCloud name for the given LDAP DN of the + * group, false on DN outside of search DN or failure */ public function dn2groupname($dn, $ldapname = null) { //To avoid bypassing the base DN settings under certain circumstances @@ -646,7 +650,9 @@ abstract class Access { $sr = ldap_search($linkResources, $base, $filter, $attr); $error = ldap_errno($link_resource); if(!is_array($sr) || $error > 0) { - \OCP\Util::writeLog('user_ldap', 'Error when searching: '.ldap_error($link_resource).' code '.ldap_errno($link_resource), \OCP\Util::ERROR); + \OCP\Util::writeLog('user_ldap', + 'Error when searching: '.ldap_error($link_resource).' code '.ldap_errno($link_resource), + \OCP\Util::ERROR); \OCP\Util::writeLog('user_ldap', 'Attempt for Paging? '.print_r($pagedSearchOK, true), \OCP\Util::ERROR); return array(); } @@ -668,7 +674,9 @@ abstract class Access { if($skipHandling) { return; } - //if count is bigger, then the server does not support paged search. Instead, he did a normal search. We set a flag here, so the callee knows how to deal with it. + // if count is bigger, then the server does not support + // paged search. Instead, he did a normal search. We set a + // flag here, so the callee knows how to deal with it. if($findings['count'] <= $limit) { $this->pagedSearchedSuccessful = true; } @@ -702,7 +710,9 @@ abstract class Access { $key = mb_strtolower($key, 'UTF-8'); if(isset($item[$key])) { if($key != 'dn') { - $selection[$i][$key] = $this->resemblesDN($key) ? $this->sanitizeDN($item[$key][0]) : $item[$key][0]; + $selection[$i][$key] = $this->resemblesDN($key) ? + $this->sanitizeDN($item[$key][0]) + : $item[$key][0]; } else { $selection[$i][$key] = $this->sanitizeDN($item[$key]); } @@ -806,7 +816,9 @@ abstract class Access { * @return string the final filter part to use in LDAP searches */ public function getFilterPartForUserSearch($search) { - return $this->getFilterPartForSearch($search, $this->connection->ldapAttributesForUserSearch, $this->connection->ldapUserDisplayName); + return $this->getFilterPartForSearch($search, + $this->connection->ldapAttributesForUserSearch, + $this->connection->ldapUserDisplayName); } /** @@ -815,7 +827,9 @@ abstract class Access { * @return string the final filter part to use in LDAP searches */ public function getFilterPartForGroupSearch($search) { - return $this->getFilterPartForSearch($search, $this->connection->ldapAttributesForGroupSearch, $this->connection->ldapGroupDisplayName); + return $this->getFilterPartForSearch($search, + $this->connection->ldapAttributesForGroupSearch, + $this->connection->ldapGroupDisplayName); } /** @@ -874,13 +888,15 @@ abstract class Access { foreach($testAttributes as $attribute) { \OCP\Util::writeLog('user_ldap', 'Testing '.$attribute.' as UUID attr', \OCP\Util::DEBUG); - $value = $this->readAttribute($dn, $attribute); - if(is_array($value) && isset($value[0]) && !empty($value[0])) { + $value = $this->readAttribute($dn, $attribute); + if(is_array($value) && isset($value[0]) && !empty($value[0])) { \OCP\Util::writeLog('user_ldap', 'Setting '.$attribute.' as UUID attr', \OCP\Util::DEBUG); $this->connection->ldapUuidAttribute = $attribute; return true; - } - \OCP\Util::writeLog('user_ldap', 'The looked for uuid attr is not '.$attribute.', result was '.print_r($value, true), \OCP\Util::DEBUG); + } + \OCP\Util::writeLog('user_ldap', + 'The looked for uuid attr is not '.$attribute.', result was '.print_r($value, true), + \OCP\Util::DEBUG); } return false; @@ -888,7 +904,9 @@ abstract class Access { public function getUUID($dn) { if($this->detectUuidAttribute($dn)) { - \OCP\Util::writeLog('user_ldap', 'UUID Checking \ UUID for '.$dn.' using '. $this->connection->ldapUuidAttribute, \OCP\Util::DEBUG); + \OCP\Util::writeLog('user_ldap', + 'UUID Checking \ UUID for '.$dn.' using '. $this->connection->ldapUuidAttribute, + \OCP\Util::DEBUG); $uuid = $this->readAttribute($dn, $this->connection->ldapUuidAttribute); if(!is_array($uuid) && $this->connection->ldapOverrideUuidAttribute) { $this->detectUuidAttribute($dn, true); @@ -1027,13 +1045,20 @@ abstract class Access { $pagedSearchOK = false; if($this->connection->hasPagedResultSupport && !is_null($limit)) { $offset = intval($offset); //can be null - \OCP\Util::writeLog('user_ldap', 'initializing paged search for Filter'.$filter.' base '.print_r($bases, true).' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset, \OCP\Util::INFO); + \OCP\Util::writeLog('user_ldap', + 'initializing paged search for Filter'.$filter.' base '.print_r($bases, true) + .' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset, + \OCP\Util::INFO); //get the cookie from the search for the previous search, required by LDAP foreach($bases as $base) { $cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset); if(empty($cookie) && ($offset > 0)) { - //no cookie known, although the offset is not 0. Maybe cache run out. We need to start all over *sigh* (btw, Dear Reader, did you need LDAP paged searching was designed by MSFT?) + // no cookie known, although the offset + // is not 0. Maybe cache run out. We need + // to start all over *sigh* (btw, Dear + // Reader, did you need LDAP paged + // searching was designed by MSFT?) $reOffset = ($offset - $limit) < 0 ? 0 : $offset - $limit; //a bit recursive, $offset of 0 is the exit \OCP\Util::writeLog('user_ldap', 'Looking for cookie L/O '.$limit.'/'.$reOffset, \OCP\Util::INFO); @@ -1049,13 +1074,16 @@ abstract class Access { if($offset > 0) { \OCP\Util::writeLog('user_ldap', 'Cookie '.$cookie, \OCP\Util::INFO); } - $pagedSearchOK = ldap_control_paged_result($this->connection->getConnectionResource(), $limit, false, $cookie); + $pagedSearchOK = ldap_control_paged_result($this->connection->getConnectionResource(), + $limit, false, $cookie); if(!$pagedSearchOK) { return false; } \OCP\Util::writeLog('user_ldap', 'Ready for a paged search', \OCP\Util::INFO); } else { - \OCP\Util::writeLog('user_ldap', 'No paged search for us, Cpt., Limit '.$limit.' Offset '.$offset, \OCP\Util::INFO); + \OCP\Util::writeLog('user_ldap', + 'No paged search for us, Cpt., Limit '.$limit.' Offset '.$offset, + \OCP\Util::INFO); } } diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php index 933f2f42074..63cd5e78da5 100644 --- a/apps/user_ldap/lib/connection.php +++ b/apps/user_ldap/lib/connection.php @@ -76,7 +76,8 @@ class Connection { $this->configPrefix = $configPrefix; $this->configID = $configID; $this->cache = \OC_Cache::getGlobalCache(); - $this->config['hasPagedResultSupport'] = (function_exists('ldap_control_paged_result') && function_exists('ldap_control_paged_result_response')); + $this->config['hasPagedResultSupport'] = (function_exists('ldap_control_paged_result') + && function_exists('ldap_control_paged_result_response')); } public function __destruct() { @@ -235,7 +236,7 @@ class Connection { $this->config['turnOffCertCheck'] = $this->$v('ldap_turn_off_cert_check'); $this->config['ldapUserDisplayName'] - = mb_strtolower($this->$v('ldap_display_name'),'UTF-8'); + = mb_strtolower($this->$v('ldap_display_name'), 'UTF-8'); $this->config['ldapUserFilter'] = $this->$v('ldap_userlist_filter'); $this->config['ldapGroupFilter'] = $this->$v('ldap_group_filter'); @@ -274,9 +275,36 @@ class Connection { * @return returns an array that maps internal variable names to database fields */ private function getConfigTranslationArray() { - static $array = array('ldap_host'=>'ldapHost', 'ldap_port'=>'ldapPort', 'ldap_backup_host'=>'ldapBackupHost', 'ldap_backup_port'=>'ldapBackupPort', 'ldap_override_main_server' => 'ldapOverrideMainServer', 'ldap_dn'=>'ldapAgentName', 'ldap_agent_password'=>'ldapAgentPassword', 'ldap_base'=>'ldapBase', 'ldap_base_users'=>'ldapBaseUsers', 'ldap_base_groups'=>'ldapBaseGroups', 'ldap_userlist_filter'=>'ldapUserFilter', 'ldap_login_filter'=>'ldapLoginFilter', 'ldap_group_filter'=>'ldapGroupFilter', 'ldap_display_name'=>'ldapUserDisplayName', 'ldap_group_display_name'=>'ldapGroupDisplayName', - - 'ldap_tls'=>'ldapTLS', 'ldap_nocase'=>'ldapNoCase', 'ldap_quota_def'=>'ldapQuotaDefault', 'ldap_quota_attr'=>'ldapQuotaAttribute', 'ldap_email_attr'=>'ldapEmailAttribute', 'ldap_group_member_assoc_attribute'=>'ldapGroupMemberAssocAttr', 'ldap_cache_ttl'=>'ldapCacheTTL', 'home_folder_naming_rule' => 'homeFolderNamingRule', 'ldap_turn_off_cert_check' => 'turnOffCertCheck', 'ldap_configuration_active' => 'ldapConfigurationActive', 'ldap_attributes_for_user_search' => 'ldapAttributesForUserSearch', 'ldap_attributes_for_group_search' => 'ldapAttributesForGroupSearch'); + static $array = array( + 'ldap_host'=>'ldapHost', + 'ldap_port'=>'ldapPort', + 'ldap_backup_host'=>'ldapBackupHost', + 'ldap_backup_port'=>'ldapBackupPort', + 'ldap_override_main_server' => 'ldapOverrideMainServer', + 'ldap_dn'=>'ldapAgentName', + 'ldap_agent_password'=>'ldapAgentPassword', + 'ldap_base'=>'ldapBase', + 'ldap_base_users'=>'ldapBaseUsers', + 'ldap_base_groups'=>'ldapBaseGroups', + 'ldap_userlist_filter'=>'ldapUserFilter', + 'ldap_login_filter'=>'ldapLoginFilter', + 'ldap_group_filter'=>'ldapGroupFilter', + 'ldap_display_name'=>'ldapUserDisplayName', + 'ldap_group_display_name'=>'ldapGroupDisplayName', + + 'ldap_tls'=>'ldapTLS', + 'ldap_nocase'=>'ldapNoCase', + 'ldap_quota_def'=>'ldapQuotaDefault', + 'ldap_quota_attr'=>'ldapQuotaAttribute', + 'ldap_email_attr'=>'ldapEmailAttribute', + 'ldap_group_member_assoc_attribute'=>'ldapGroupMemberAssocAttr', + 'ldap_cache_ttl'=>'ldapCacheTTL', + 'home_folder_naming_rule' => 'homeFolderNamingRule', + 'ldap_turn_off_cert_check' => 'turnOffCertCheck', + 'ldap_configuration_active' => 'ldapConfigurationActive', + 'ldap_attributes_for_user_search' => 'ldapAttributesForUserSearch', + 'ldap_attributes_for_group_search' => 'ldapAttributesForGroupSearch' + ); return $array; } @@ -387,7 +415,8 @@ class Connection { * @returns true if configuration seems OK, false otherwise */ private function validateConfiguration() { - //first step: "soft" checks: settings that are not really necessary, but advisable. If left empty, give an info message + // first step: "soft" checks: settings that are not really + // necessary, but advisable. If left empty, give an info message if(empty($this->config['ldapBaseUsers'])) { \OCP\Util::writeLog('user_ldap', 'Base tree for Users is empty, using Base DN', \OCP\Util::INFO); $this->config['ldapBaseUsers'] = $this->config['ldapBase']; @@ -397,11 +426,16 @@ class Connection { $this->config['ldapBaseGroups'] = $this->config['ldapBase']; } if(empty($this->config['ldapGroupFilter']) && empty($this->config['ldapGroupMemberAssocAttr'])) { - \OCP\Util::writeLog('user_ldap', 'No group filter is specified, LDAP group feature will not be used.', \OCP\Util::INFO); + \OCP\Util::writeLog('user_ldap', + 'No group filter is specified, LDAP group feature will not be used.', + \OCP\Util::INFO); } - if(!in_array($this->config['ldapUuidAttribute'], array('auto', 'entryuuid', 'nsuniqueid', 'objectguid')) && (!is_null($this->configID))) { + if(!in_array($this->config['ldapUuidAttribute'], array('auto', 'entryuuid', 'nsuniqueid', 'objectguid')) + && (!is_null($this->configID))) { \OCP\Config::setAppValue($this->configID, $this->configPrefix.'ldap_uuid_attribute', 'auto'); - \OCP\Util::writeLog('user_ldap', 'Illegal value for the UUID Attribute, reset to autodetect.', \OCP\Util::INFO); + \OCP\Util::writeLog('user_ldap', + 'Illegal value for the UUID Attribute, reset to autodetect.', + \OCP\Util::INFO); } if(empty($this->config['ldapBackupPort'])) { //force default @@ -417,7 +451,9 @@ class Connection { if((strpos($this->config['ldapHost'], 'ldaps') === 0) && $this->config['ldapTLS']) { $this->config['ldapTLS'] = false; - \OCP\Util::writeLog('user_ldap', 'LDAPS (already using secure connection) and TLS do not work together. Switched off TLS.', \OCP\Util::INFO); + \OCP\Util::writeLog('user_ldap', + 'LDAPS (already using secure connection) and TLS do not work together. Switched off TLS.', + \OCP\Util::INFO); } @@ -434,20 +470,28 @@ class Connection { } if((empty($this->config['ldapAgentName']) && !empty($this->config['ldapAgentPassword'])) || (!empty($this->config['ldapAgentName']) && empty($this->config['ldapAgentPassword']))) { - \OCP\Util::writeLog('user_ldap', 'Either no password given for the user agent or a password is given, but no LDAP agent; won`t connect.', \OCP\Util::WARN); + \OCP\Util::writeLog('user_ldap', + 'Either no password given for the user agent or a password is given, but no LDAP agent; won`t connect.', + \OCP\Util::WARN); $configurationOK = false; } //TODO: check if ldapAgentName is in DN form - if(empty($this->config['ldapBase']) && (empty($this->config['ldapBaseUsers']) && empty($this->config['ldapBaseGroups']))) { + if(empty($this->config['ldapBase']) + && (empty($this->config['ldapBaseUsers']) + && empty($this->config['ldapBaseGroups']))) { \OCP\Util::writeLog('user_ldap', 'No Base DN given, won`t connect.', \OCP\Util::WARN); $configurationOK = false; } if(empty($this->config['ldapUserDisplayName'])) { - \OCP\Util::writeLog('user_ldap', 'No user display name attribute specified, won`t connect.', \OCP\Util::WARN); + \OCP\Util::writeLog('user_ldap', + 'No user display name attribute specified, won`t connect.', + \OCP\Util::WARN); $configurationOK = false; } if(empty($this->config['ldapGroupDisplayName'])) { - \OCP\Util::writeLog('user_ldap', 'No group display name attribute specified, won`t connect.', \OCP\Util::WARN); + \OCP\Util::writeLog('user_ldap', + 'No group display name attribute specified, won`t connect.', + \OCP\Util::WARN); $configurationOK = false; } if(empty($this->config['ldapLoginFilter'])) { @@ -455,7 +499,9 @@ class Connection { $configurationOK = false; } if(mb_strpos($this->config['ldapLoginFilter'], '%uid', 0, 'UTF-8') === false) { - \OCP\Util::writeLog('user_ldap', 'Login filter does not contain %uid place holder, won`t connect.', \OCP\Util::WARN); + \OCP\Util::writeLog('user_ldap', + 'Login filter does not contain %uid place holder, won`t connect.', + \OCP\Util::WARN); \OCP\Util::writeLog('user_ldap', 'Login filter was ' . $this->config['ldapLoginFilter'], \OCP\Util::DEBUG); $configurationOK = false; } @@ -519,13 +565,17 @@ class Connection { if(!$this->ldapConnectionRes) { if(!function_exists('ldap_connect')) { $phpLDAPinstalled = false; - \OCP\Util::writeLog('user_ldap', 'function ldap_connect is not available. Make sure that the PHP ldap module is installed.', \OCP\Util::ERROR); + \OCP\Util::writeLog('user_ldap', + 'function ldap_connect is not available. Make sure that the PHP ldap module is installed.', + \OCP\Util::ERROR); return false; } if($this->config['turnOffCertCheck']) { if(putenv('LDAPTLS_REQCERT=never')) { - \OCP\Util::writeLog('user_ldap', 'Turned off SSL certificate validation successfully.', \OCP\Util::WARN); + \OCP\Util::writeLog('user_ldap', + 'Turned off SSL certificate validation successfully.', + \OCP\Util::WARN); } else { \OCP\Util::writeLog('user_ldap', 'Could not turn off SSL certificate validation.', \OCP\Util::WARN); } @@ -583,7 +633,9 @@ class Connection { } $ldapLogin = @ldap_bind($cr, $this->config['ldapAgentName'], $this->config['ldapAgentPassword']); if(!$ldapLogin) { - \OCP\Util::writeLog('user_ldap', 'Bind failed: ' . ldap_errno($cr) . ': ' . ldap_error($cr), \OCP\Util::ERROR); + \OCP\Util::writeLog('user_ldap', + 'Bind failed: ' . ldap_errno($cr) . ': ' . ldap_error($cr), + \OCP\Util::ERROR); $this->ldapConnectionRes = null; return false; } diff --git a/apps/user_ldap/lib/jobs.php b/apps/user_ldap/lib/jobs.php index b265a8339ef..094d11db3d5 100644 --- a/apps/user_ldap/lib/jobs.php +++ b/apps/user_ldap/lib/jobs.php @@ -42,7 +42,9 @@ class Jobs { $actualGroups = self::getGroupBE()->getGroups(); if(empty($actualGroups) && empty($knownGroups)) { - \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – groups do not seem to be configured properly, aborting.', \OCP\Util::INFO); + \OCP\Util::writeLog('user_ldap', + 'bgJ "updateGroups" – groups do not seem to be configured properly, aborting.', + \OCP\Util::INFO); \OCP\Config::setAppValue('user_ldap', 'bgjUpdateGroupsLastRun', time()); return; } @@ -75,19 +77,25 @@ class Jobs { $hasChanged = false; foreach(array_diff($knownUsers, $actualUsers) as $removedUser) { \OCP\Util::emitHook('OC_User', 'post_removeFromGroup', array('uid' => $removedUser, 'gid' => $group)); - \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – "'.$removedUser.'" removed from "'.$group.'".', \OCP\Util::INFO); + \OCP\Util::writeLog('user_ldap', + 'bgJ "updateGroups" – "'.$removedUser.'" removed from "'.$group.'".', + \OCP\Util::INFO); $hasChanged = true; } foreach(array_diff($actualUsers, $knownUsers) as $addedUser) { \OCP\Util::emitHook('OC_User', 'post_addFromGroup', array('uid' => $addedUser, 'gid' => $group)); - \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – "'.$addedUser.'" added to "'.$group.'".', \OCP\Util::INFO); + \OCP\Util::writeLog('user_ldap', + 'bgJ "updateGroups" – "'.$addedUser.'" added to "'.$group.'".', + \OCP\Util::INFO); $hasChanged = true; } if($hasChanged) { $query->execute(array(serialize($actualUsers), $group)); } } - \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – FINISHED dealing with known Groups.', \OCP\Util::DEBUG); + \OCP\Util::writeLog('user_ldap', + 'bgJ "updateGroups" – FINISHED dealing with known Groups.', + \OCP\Util::DEBUG); } static private function handleCreatedGroups($createdGroups) { @@ -98,11 +106,15 @@ class Jobs { VALUES (?, ?) '); foreach($createdGroups as $createdGroup) { - \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – new group "'.$createdGroup.'" found.', \OCP\Util::INFO); + \OCP\Util::writeLog('user_ldap', + 'bgJ "updateGroups" – new group "'.$createdGroup.'" found.', + \OCP\Util::INFO); $users = serialize(self::getGroupBE()->usersInGroup($createdGroup)); $query->execute(array($createdGroup, $users)); } - \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – FINISHED dealing with created Groups.', \OCP\Util::DEBUG); + \OCP\Util::writeLog('user_ldap', + 'bgJ "updateGroups" – FINISHED dealing with created Groups.', + \OCP\Util::DEBUG); } static private function handleRemovedGroups($removedGroups) { @@ -113,10 +125,14 @@ class Jobs { WHERE `owncloudname` = ? '); foreach($removedGroups as $removedGroup) { - \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – group "'.$removedGroup.'" was removed.', \OCP\Util::INFO); + \OCP\Util::writeLog('user_ldap', + 'bgJ "updateGroups" – group "'.$removedGroup.'" was removed.', + \OCP\Util::INFO); $query->execute(array($removedGroup)); } - \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" – FINISHED dealing with removed groups.', \OCP\Util::DEBUG); + \OCP\Util::writeLog('user_ldap', + 'bgJ "updateGroups" – FINISHED dealing with removed groups.', + \OCP\Util::DEBUG); } static private function getConnector() { @@ -154,4 +170,4 @@ class Jobs { return self::$groupsFromDB; } -}
\ No newline at end of file +} |