diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2012-08-28 14:24:31 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@owncloud.com> | 2012-08-28 14:24:50 +0200 |
commit | 42a996930481783af1a5a3fbbae18dc1201fbb0b (patch) | |
tree | 87198f8d4e39e89610d97f7396b70fe27f5c6156 /apps | |
parent | 549f69cbc1aafa13be6f011554ee82d26d814e52 (diff) | |
download | nextcloud-server-42a996930481783af1a5a3fbbae18dc1201fbb0b.tar.gz nextcloud-server-42a996930481783af1a5a3fbbae18dc1201fbb0b.zip |
LDAP: implement getHome() function, use either username (default) or specify an LDAP attribute value to use
Diffstat (limited to 'apps')
-rw-r--r-- | apps/user_ldap/lib/connection.php | 4 | ||||
-rw-r--r-- | apps/user_ldap/settings.php | 8 | ||||
-rw-r--r-- | apps/user_ldap/templates/settings.php | 1 | ||||
-rw-r--r-- | apps/user_ldap/user_ldap.php | 40 |
4 files changed, 50 insertions, 3 deletions
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php index dc160a1642d..1922e7ff1f2 100644 --- a/apps/user_ldap/lib/connection.php +++ b/apps/user_ldap/lib/connection.php @@ -55,6 +55,7 @@ class Connection { 'ldapCacheTTL' => null, 'ldapUuidAttribute' => null, 'ldapOverrideUuidAttribute' => null, + 'homeFolderNamingRule' => null, ); public function __construct($configID = 'user_ldap') { @@ -200,6 +201,7 @@ class Connection { $this->config['ldapCacheTTL'] = \OCP\Config::getAppValue($this->configID, 'ldap_cache_ttl', 10*60); $this->config['ldapUuidAttribute'] = \OCP\Config::getAppValue($this->configID, 'ldap_uuid_attribute', 'auto'); $this->config['ldapOverrideUuidAttribute'] = \OCP\Config::getAppValue($this->configID, 'ldap_override_uuid_attribute', 0); + $this->config['homeFolderNamingRule'] = \OCP\Config::getAppValue($this->configID, 'home_folder_naming_rule', 'opt:username'); $this->configured = $this->validateConfiguration(); } @@ -218,7 +220,7 @@ class Connection { $params = array('ldap_host'=>'ldapHost', 'ldap_port'=>'ldapPort', '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'); + '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'); foreach($config as $parameter => $value) { if(isset($this->config[$parameter])) { diff --git a/apps/user_ldap/settings.php b/apps/user_ldap/settings.php index 39aa3296265..23018890eac 100644 --- a/apps/user_ldap/settings.php +++ b/apps/user_ldap/settings.php @@ -20,7 +20,7 @@ * License along with this library. If not, see <http://www.gnu.org/licenses/>. * */ -$params = array('ldap_host', 'ldap_port', 'ldap_dn', 'ldap_agent_password', 'ldap_base', 'ldap_base_users', 'ldap_base_groups', 'ldap_userlist_filter', 'ldap_login_filter', 'ldap_group_filter', 'ldap_display_name', 'ldap_group_display_name', 'ldap_tls', 'ldap_turn_off_cert_check', 'ldap_nocase', 'ldap_quota_def', 'ldap_quota_attr', 'ldap_email_attr', 'ldap_group_member_assoc_attribute', 'ldap_cache_ttl'); +$params = array('ldap_host', 'ldap_port', 'ldap_dn', 'ldap_agent_password', 'ldap_base', 'ldap_base_users', 'ldap_base_groups', 'ldap_userlist_filter', 'ldap_login_filter', 'ldap_group_filter', 'ldap_display_name', 'ldap_group_display_name', 'ldap_tls', 'ldap_turn_off_cert_check', 'ldap_nocase', 'ldap_quota_def', 'ldap_quota_attr', 'ldap_email_attr', 'ldap_group_member_assoc_attribute', 'ldap_cache_ttl', 'home_folder_naming_rule'); OCP\Util::addscript('user_ldap', 'settings'); OCP\Util::addstyle('user_ldap', 'settings'); @@ -36,6 +36,9 @@ if ($_POST) { $ldap->clearCache(); OCP\Config::setAppValue('user_ldap', $param, $_POST[$param]); } + } elseif('home_folder_naming_rule' == $param) { + $value = empty($_POST[$param]) ? 'opt:username' : 'attr:'.$_POST[$param]; + OCP\Config::setAppValue('user_ldap', $param, $value); } else { OCP\Config::setAppValue('user_ldap', $param, $_POST[$param]); } @@ -67,5 +70,8 @@ $tmpl->assign( 'ldap_group_display_name', OCP\Config::getAppValue('user_ldap', ' $tmpl->assign( 'ldap_group_member_assoc_attribute', OCP\Config::getAppValue('user_ldap', 'ldap_group_member_assoc_attribute', 'uniqueMember')); $tmpl->assign( 'ldap_agent_password', base64_decode(OCP\Config::getAppValue('user_ldap', 'ldap_agent_password'))); $tmpl->assign( 'ldap_cache_ttl', OCP\Config::getAppValue('user_ldap', 'ldap_cache_ttl', '600')); +$hfnr = OCP\Config::getAppValue('user_ldap', 'home_folder_naming_rule', 'opt:username'); +$hfnr = ($hfnr == 'opt:username') ? '' : substr($hfnr, strlen('attr:')); +$tmpl->assign( 'home_folder_naming_rule', $hfnr, ''); return $tmpl->fetchPage(); diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php index 861c9ba6052..d1aaeedbdf9 100644 --- a/apps/user_ldap/templates/settings.php +++ b/apps/user_ldap/templates/settings.php @@ -27,6 +27,7 @@ <label for="ldap_quota_def">Quota Default</label><input type="text" id="ldap_quota_def" name="ldap_quota_def" value="<?php if (isset($_['ldap_quota_def'])) echo $_['ldap_quota_def']; ?>" title="<?php echo $l->t('in bytes');?>" /></p> <p><label for="ldap_email_attr">Email Field</label><input type="text" id="ldap_email_attr" name="ldap_email_attr" value="<?php echo $_['ldap_email_attr']; ?>" /></p> <p><label for="ldap_cache_ttl">Cache Time-To-Live</label><input type="text" id="ldap_cache_ttl" name="ldap_cache_ttl" value="<?php echo $_['ldap_cache_ttl']; ?>" title="<?php echo $l->t('in seconds. A change empties the cache.');?>" /></p> + <p><label for="home_folder_naming_rule">User Home Folder Naming Rule</label><input type="text" id="home_folder_naming_rule" name="home_folder_naming_rule" value="<?php echo $_['home_folder_naming_rule']; ?>" title="<?php echo $l->t('Leave empty for user name (default). Otherwise, specify an LDAP/AD attribute.');?>" /></p> </fieldset> <input type="submit" value="Save" /> <button id="ldap_action_test_connection" name="ldap_action_test_connection">Test Configuration</button> <a href="http://owncloud.org/support/ldap-backend/" target="_blank"><img src="<?php echo OCP\Util::imagePath('','actions/info.png'); ?>" style="height:1.75ex" /> <?php echo $l->t('Help');?></a> </div> diff --git a/apps/user_ldap/user_ldap.php b/apps/user_ldap/user_ldap.php index a97df7b4fd1..d297374600a 100644 --- a/apps/user_ldap/user_ldap.php +++ b/apps/user_ldap/user_ldap.php @@ -161,6 +161,44 @@ class USER_LDAP extends lib\Access implements \OCP\UserInterface { } /** + * @brief determine the user's home directory + * @param string $uid the owncloud username + * @return boolean + */ + private function determineHomeDir($uid) { + if(strpos($this->connection->homeFolderNamingRule, 'attr:') === 0) { + $attr = substr($this->connection->homeFolderNamingRule, strlen('attr:')); + $homedir = $this->readAttribute($this->username2dn($uid), $attr); + if($homedir) { + $homedir = \OCP\Config::getSystemValue( "datadirectory", \OC::$SERVERROOT."/data" ) . '/' . $homedir[0]; + \OCP\Config::setUserValue($uid, 'user_ldap', 'homedir', $homedir); + return $homedir; + } + } + + //fallback and default: username + $homedir = \OCP\Config::getSystemValue( "datadirectory", \OC::$SERVERROOT."/data" ) . '/' . $uid; + \OCP\Config::setUserValue($uid, 'user_ldap', 'homedir', $homedir); + return $homedir; + } + + /** + * @brief get the user's home directory + * @param string $uid the username + * @return boolean + */ + public function getHome($uid){ + if($this->userExists($uid)) { + $homedir = \OCP\Config::getUserValue($uid, 'user_ldap', 'homedir', false); + if(!$homedir) { + $homedir = $this->determineHomeDir($uid); + } + return $homedir; + } + return false; + } + + /** * @brief Check if backend implements actions * @param $actions bitwise-or'ed actions * @returns boolean @@ -169,7 +207,7 @@ class USER_LDAP extends lib\Access implements \OCP\UserInterface { * compared with OC_USER_BACKEND_CREATE_USER etc. */ public function implementsActions($actions) { - return (bool)(OC_USER_BACKEND_CHECK_PASSWORD & $actions); + return (bool)((OC_USER_BACKEND_CHECK_PASSWORD | OC_USER_BACKEND_GET_HOME) & $actions); } }
\ No newline at end of file |