From 8ab9b0d2f293e5e1d335492ff171c79ee869178a Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 15 Nov 2011 12:43:59 +0000 Subject: [PATCH] allow to use homedirectory attribute from LDAP or ADS authentication for VFS mounts --- phpgwapi/inc/class.auth_ads.inc.php | 9 +++++++-- phpgwapi/inc/class.auth_ldap.inc.php | 9 +++++++-- phpgwapi/inc/class.egw_session.inc.php | 7 ++++++- phpgwapi/inc/class.vfs_stream_wrapper.inc.php | 2 +- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/phpgwapi/inc/class.auth_ads.inc.php b/phpgwapi/inc/class.auth_ads.inc.php index ad77dbd8e0..b21c778fb8 100644 --- a/phpgwapi/inc/class.auth_ads.inc.php +++ b/phpgwapi/inc/class.auth_ads.inc.php @@ -56,7 +56,7 @@ class auth_ads implements auth_backend } //echo "

Bind with '$username@".$GLOBALS['egw_info']['server']['ads_domain']."' with PW '$passwd'.

\n"; - $attributes = array('samaccountname','givenName','sn','mail'); + $attributes = array('samaccountname','givenName','sn','mail','homeDirectory'); $filter = "(samaccountname=$username)"; // automatic create dn from domain: domain.com ==> DC=domain,DC=com $base_dn = array(); @@ -84,10 +84,15 @@ class auth_ads implements auth_backend { return $GLOBALS['egw']->accounts->id2name($id,'account_status') == 'A'; } + // store homedirectory for egw_session->read_repositories + $GLOBALS['auto_create_acct'] = array(); + if (isset($allValues[0]['homedirectory'])) + { + $GLOBALS['auto_create_acct']['homedirectory'] = $allValues[0]['homedirectory']; + } if ($GLOBALS['egw_info']['server']['auto_create_acct']) { // create a global array with all availible info about that account - $GLOBALS['auto_create_acct'] = array(); foreach(array( 'givenname' => 'firstname', 'sn' => 'lastname', diff --git a/phpgwapi/inc/class.auth_ldap.inc.php b/phpgwapi/inc/class.auth_ldap.inc.php index d9a661aa3c..6d673a2b54 100644 --- a/phpgwapi/inc/class.auth_ldap.inc.php +++ b/phpgwapi/inc/class.auth_ldap.inc.php @@ -54,7 +54,7 @@ class auth_ldap implements auth_backend return False; } /* find the dn for this uid, the uid is not always in the dn */ - $attributes = array('uid','dn','givenName','sn','mail','uidNumber','shadowExpire'); + $attributes = array('uid','dn','givenName','sn','mail','uidNumber','shadowExpire','homeDirectory'); $filter = $GLOBALS['egw_info']['server']['ldap_search_filter'] ? $GLOBALS['egw_info']['server']['ldap_search_filter'] : '(uid=%user)'; $filter = str_replace(array('%user','%domain'),array(ldap::quote($username),$GLOBALS['egw_info']['user']['domain']),$filter); @@ -88,13 +88,18 @@ class auth_ldap implements auth_backend { if ($GLOBALS['egw_info']['server']['account_repository'] != 'ldap') { + // store homedirectory for egw_session->read_repositories + $GLOBALS['auto_create_acct'] = array(); + if (isset($allValues[0]['homedirectory'])) + { + $GLOBALS['auto_create_acct']['homedirectory'] = $allValues[0]['homedirectory']; + } if (!($id = $GLOBALS['egw']->accounts->name2id($username,'account_lid','u'))) { // account does NOT exist, check if we should create it if ($GLOBALS['egw_info']['server']['auto_create_acct']) { // create a global array with all availible info about that account - $GLOBALS['auto_create_acct'] = array(); foreach(array( 'givenname' => 'firstname', 'sn' => 'lastname', diff --git a/phpgwapi/inc/class.egw_session.inc.php b/phpgwapi/inc/class.egw_session.inc.php index 755e6dcb93..b74c1a31df 100644 --- a/phpgwapi/inc/class.egw_session.inc.php +++ b/phpgwapi/inc/class.egw_session.inc.php @@ -1079,7 +1079,7 @@ class egw_session // append the url to the webserver url, but avoid more then one slash between the parts of the url $webserver_url = $GLOBALS['egw_info']['server']['webserver_url']; - // patch inspired by vladimir kolobkov -> we should not try to match the webserver url against the url without '/' as delimiter, + // patch inspired by vladimir kolobkov -> we should not try to match the webserver url against the url without '/' as delimiter, // as $webserver_url may be part of $url (as /egw is part of phpgwapi/js/egw_instant_load.html) if (($url[0] != '/' || $webserver_url != '/') && (!$webserver_url || strpos($url, $webserver_url.'/') === false)) { @@ -1429,6 +1429,11 @@ class egw_session $GLOBALS['egw']->applications->applications($this->account_id); $this->user = $GLOBALS['egw']->accounts->read_repository(); + // set homedirectory from auth_ldap or auth_ads, to be able to use it in vfs + if (!isset($this->user['homedirectory']) && isset($GLOBALS['auto_create_acct']['homedirectory'])) + { + $this->user['homedirectory'] = $GLOBALS['auto_create_acct']['homedirectory']; + } $this->user['acl'] = $GLOBALS['egw']->acl->read_repository(); $this->user['preferences'] = $GLOBALS['egw']->preferences->read_repository(); if (is_object($GLOBALS['egw']->datetime)) diff --git a/phpgwapi/inc/class.vfs_stream_wrapper.inc.php b/phpgwapi/inc/class.vfs_stream_wrapper.inc.php index 3231c5001f..efe2487bce 100644 --- a/phpgwapi/inc/class.vfs_stream_wrapper.inc.php +++ b/phpgwapi/inc/class.vfs_stream_wrapper.inc.php @@ -194,7 +194,7 @@ class vfs_stream_wrapper implements iface_stream_wrapper 'user' => $GLOBALS['egw_info']['user']['account_lid'], 'pass' => $GLOBALS['egw_info']['user']['passwd'], 'host' => $GLOBALS['egw_info']['user']['domain'], - 'home' => $GLOBALS['egw_info']['user']['homedirectory'], + 'home' => str_replace(array('\\\\','\\'),array('','/'),$GLOBALS['egw_info']['user']['homedirectory']), ); } $parts = array_merge(parse_url($path),$defaults);