From ba63e46b5e11bddc1bc5a636ef6622b60da579f1 Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Fri, 21 Mar 2014 14:22:48 +0000 Subject: SMB/CIFS mount using OwnCloud logon credentials Selecting 'SMB/CIFS Auto' in the mounts configuration allows an SMB/CIFS mount to be configured that uses the credentials of the user logging in to authenticate to the server. Optionally, the username can be used as the share name, permitting home shares to be dynamically mounted. --- apps/files_external/appinfo/app.php | 3 +++ apps/files_external/lib/config.php | 14 ++++++++--- apps/files_external/lib/smb_auto.php | 46 ++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 apps/files_external/lib/smb_auto.php (limited to 'apps') diff --git a/apps/files_external/appinfo/app.php b/apps/files_external/appinfo/app.php index 0e83660f845..f98d000b989 100644 --- a/apps/files_external/appinfo/app.php +++ b/apps/files_external/appinfo/app.php @@ -1,6 +1,7 @@ + * Copyright (c) 2014 Robin McCorkell * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. @@ -13,6 +14,7 @@ OC::$CLASSPATH['OC\Files\Storage\OwnCloud'] = 'files_external/lib/owncloud.php'; OC::$CLASSPATH['OC\Files\Storage\Google'] = 'files_external/lib/google.php'; OC::$CLASSPATH['OC\Files\Storage\Swift'] = 'files_external/lib/swift.php'; OC::$CLASSPATH['OC\Files\Storage\SMB'] = 'files_external/lib/smb.php'; +OC::$CLASSPATH['OC\Files\Storage\SMB_Auto'] = 'files_external/lib/smb_auto.php'; OC::$CLASSPATH['OC\Files\Storage\AmazonS3'] = 'files_external/lib/amazons3.php'; OC::$CLASSPATH['OC\Files\Storage\Dropbox'] = 'files_external/lib/dropbox.php'; OC::$CLASSPATH['OC\Files\Storage\SFTP'] = 'files_external/lib/sftp.php'; @@ -27,4 +29,5 @@ if (OCP\Config::getAppValue('files_external', 'allow_user_mounting', 'yes') == ' // connecting hooks OCP\Util::connectHook('OC_Filesystem', 'post_initMountPoints', '\OC_Mount_Config', 'initMountPointsHook'); OCP\Util::connectHook('OC_User', 'post_login', 'OC\Files\Storage\iRODS', 'login'); +OCP\Util::connectHook('OC_User', 'post_login', 'OC\Files\Storage\SMB_Auto', 'login'); diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index f7caafb74aa..3512071aeb8 100755 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -5,6 +5,7 @@ * @author Michael Gapczynski * @copyright 2012 Michael Gapczynski mtgap@owncloud.com * @copyright 2014 Vincent Petry +* @copyright 2014 Robin McCorkell * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE @@ -122,11 +123,18 @@ class OC_Mount_Config { 'password' => '*Password', 'share' => 'Share', 'root' => '&Root')); + $backends['\OC\Files\Storage\SMB_Auto'] = array( + 'backend' => 'SMB / CIFS Auto', + 'configuration' => array( + 'host' => 'URL', + 'username_as_share' => '!Username as share', + 'share' => '&Share', + 'root' => '&Root')); } } if(OC_Mount_Config::checkcurl()){ - $backends['\OC\Files\Storage\DAV']=array( + $backends['\OC\Files\Storage\DAV']=array( 'backend' => 'WebDAV', 'configuration' => array( 'host' => 'URL', @@ -134,7 +142,7 @@ class OC_Mount_Config { 'password' => '*Password', 'root' => '&Root', 'secure' => '!Secure https://')); - $backends['\OC\Files\Storage\OwnCloud']=array( + $backends['\OC\Files\Storage\OwnCloud']=array( 'backend' => 'ownCloud', 'configuration' => array( 'host' => 'URL', @@ -185,7 +193,7 @@ class OC_Mount_Config { * @return array of mount point string as key, mountpoint config as value */ public static function getAbsoluteMountPoints($user) { - $mountPoints = array(); + $mountPoints = array(); $datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data"); $mount_file = \OC_Config::getValue("mount_file", $datadir . "/mount.json"); diff --git a/apps/files_external/lib/smb_auto.php b/apps/files_external/lib/smb_auto.php new file mode 100644 index 00000000000..52fceea64f4 --- /dev/null +++ b/apps/files_external/lib/smb_auto.php @@ -0,0 +1,46 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Files\Storage; + +class SMB_Auto extends \OC\Files\Storage\SMB{ + public function __construct($params) { + if (isset($params['host']) && \OC::$session->exists('smb-credentials')) { + $host=$params['host']; + $username_as_share = ($params['username_as_share'] === 'true'); + + $params_auth = \OC::$session->get('smb-credentials'); + $user = \OC_User::getDisplayName($params_auth['uid']); + $password = $params_auth['password']; + + $root=isset($params['root'])?$params['root']:'/'; + $share = ''; + + if ($username_as_share) { + $share = '/'.$user; + } elseif (isset($params['share'])) { + $share = $params['share']; + } else { + throw new \Exception(); + } + parent::__construct(array( + "user" => $user, + "password" => $password, + "host" => $host, + "share" => $share, + "root" => $root + )); + } else { + throw new \Exception(); + } + } + + public static function login( $params ) { + \OC::$session->set('smb-credentials', $params); + } +} -- cgit v1.2.3 From 3445c062ecf188134c3ef236aa911a074ff29cff Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Mon, 24 Mar 2014 15:05:14 +0000 Subject: Use loginname instead of display name getDisplayName would return the display name of the user, not great if it is a canonical string. The uid passed back from 'login' is the UUID of the user, so also not suitable. The login name from the session is the username the user used to log in to ownCloud in the first place, which is what is needed. --- apps/files_external/lib/smb_auto.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps') diff --git a/apps/files_external/lib/smb_auto.php b/apps/files_external/lib/smb_auto.php index 52fceea64f4..f2ebdca9cdf 100644 --- a/apps/files_external/lib/smb_auto.php +++ b/apps/files_external/lib/smb_auto.php @@ -15,7 +15,7 @@ class SMB_Auto extends \OC\Files\Storage\SMB{ $username_as_share = ($params['username_as_share'] === 'true'); $params_auth = \OC::$session->get('smb-credentials'); - $user = \OC_User::getDisplayName($params_auth['uid']); + $user = \OC::$session->get('loginname'); $password = $params_auth['password']; $root=isset($params['root'])?$params['root']:'/'; -- cgit v1.2.3 From 86aa6104e690f8647c800f49b61bb95e2a625f97 Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Mon, 24 Mar 2014 15:15:15 +0000 Subject: Revoke sharable permission on automatic SMB shares Shares authenticated with user credentials (aka not hard coded) cannot be accessed by other users, breaking sharing. This change completely revokes sharing for such shares --- apps/files_external/lib/smb_auto.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'apps') diff --git a/apps/files_external/lib/smb_auto.php b/apps/files_external/lib/smb_auto.php index f2ebdca9cdf..0556aa64843 100644 --- a/apps/files_external/lib/smb_auto.php +++ b/apps/files_external/lib/smb_auto.php @@ -43,4 +43,8 @@ class SMB_Auto extends \OC\Files\Storage\SMB{ public static function login( $params ) { \OC::$session->set('smb-credentials', $params); } + + public function isSharable($path) { + return false; + } } -- cgit v1.2.3 From cac4aaa8c4dab1b59ab3ba3f155439473ae28250 Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Tue, 25 Mar 2014 13:54:54 +0000 Subject: Rename SMB_Auto to SMB_OC and change visible name SMB_Auto is now SMB_OC, and the name has been changed from "SMB / CIFS Auto" to "SMB / CIFS using OC login" --- apps/files_external/appinfo/app.php | 4 +-- apps/files_external/lib/config.php | 4 +-- apps/files_external/lib/smb_auto.php | 50 ------------------------------------ apps/files_external/lib/smb_oc.php | 50 ++++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 54 deletions(-) delete mode 100644 apps/files_external/lib/smb_auto.php create mode 100644 apps/files_external/lib/smb_oc.php (limited to 'apps') diff --git a/apps/files_external/appinfo/app.php b/apps/files_external/appinfo/app.php index f98d000b989..aeb7a2cb23a 100644 --- a/apps/files_external/appinfo/app.php +++ b/apps/files_external/appinfo/app.php @@ -14,7 +14,7 @@ OC::$CLASSPATH['OC\Files\Storage\OwnCloud'] = 'files_external/lib/owncloud.php'; OC::$CLASSPATH['OC\Files\Storage\Google'] = 'files_external/lib/google.php'; OC::$CLASSPATH['OC\Files\Storage\Swift'] = 'files_external/lib/swift.php'; OC::$CLASSPATH['OC\Files\Storage\SMB'] = 'files_external/lib/smb.php'; -OC::$CLASSPATH['OC\Files\Storage\SMB_Auto'] = 'files_external/lib/smb_auto.php'; +OC::$CLASSPATH['OC\Files\Storage\SMB_OC'] = 'files_external/lib/smb_oc.php'; OC::$CLASSPATH['OC\Files\Storage\AmazonS3'] = 'files_external/lib/amazons3.php'; OC::$CLASSPATH['OC\Files\Storage\Dropbox'] = 'files_external/lib/dropbox.php'; OC::$CLASSPATH['OC\Files\Storage\SFTP'] = 'files_external/lib/sftp.php'; @@ -29,5 +29,5 @@ if (OCP\Config::getAppValue('files_external', 'allow_user_mounting', 'yes') == ' // connecting hooks OCP\Util::connectHook('OC_Filesystem', 'post_initMountPoints', '\OC_Mount_Config', 'initMountPointsHook'); OCP\Util::connectHook('OC_User', 'post_login', 'OC\Files\Storage\iRODS', 'login'); -OCP\Util::connectHook('OC_User', 'post_login', 'OC\Files\Storage\SMB_Auto', 'login'); +OCP\Util::connectHook('OC_User', 'post_login', 'OC\Files\Storage\SMB_OC', 'login'); diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 3512071aeb8..af37a05cae0 100755 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -123,8 +123,8 @@ class OC_Mount_Config { 'password' => '*Password', 'share' => 'Share', 'root' => '&Root')); - $backends['\OC\Files\Storage\SMB_Auto'] = array( - 'backend' => 'SMB / CIFS Auto', + $backends['\OC\Files\Storage\SMB_OC'] = array( + 'backend' => 'SMB / CIFS using OC login', 'configuration' => array( 'host' => 'URL', 'username_as_share' => '!Username as share', diff --git a/apps/files_external/lib/smb_auto.php b/apps/files_external/lib/smb_auto.php deleted file mode 100644 index 0556aa64843..00000000000 --- a/apps/files_external/lib/smb_auto.php +++ /dev/null @@ -1,50 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -namespace OC\Files\Storage; - -class SMB_Auto extends \OC\Files\Storage\SMB{ - public function __construct($params) { - if (isset($params['host']) && \OC::$session->exists('smb-credentials')) { - $host=$params['host']; - $username_as_share = ($params['username_as_share'] === 'true'); - - $params_auth = \OC::$session->get('smb-credentials'); - $user = \OC::$session->get('loginname'); - $password = $params_auth['password']; - - $root=isset($params['root'])?$params['root']:'/'; - $share = ''; - - if ($username_as_share) { - $share = '/'.$user; - } elseif (isset($params['share'])) { - $share = $params['share']; - } else { - throw new \Exception(); - } - parent::__construct(array( - "user" => $user, - "password" => $password, - "host" => $host, - "share" => $share, - "root" => $root - )); - } else { - throw new \Exception(); - } - } - - public static function login( $params ) { - \OC::$session->set('smb-credentials', $params); - } - - public function isSharable($path) { - return false; - } -} diff --git a/apps/files_external/lib/smb_oc.php b/apps/files_external/lib/smb_oc.php new file mode 100644 index 00000000000..a62a2c01533 --- /dev/null +++ b/apps/files_external/lib/smb_oc.php @@ -0,0 +1,50 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\Files\Storage; + +class SMB_OC extends \OC\Files\Storage\SMB { + public function __construct($params) { + if (isset($params['host']) && \OC::$session->exists('smb-credentials')) { + $host=$params['host']; + $username_as_share = ($params['username_as_share'] === 'true'); + + $params_auth = \OC::$session->get('smb-credentials'); + $user = \OC::$session->get('loginname'); + $password = $params_auth['password']; + + $root=isset($params['root'])?$params['root']:'/'; + $share = ''; + + if ($username_as_share) { + $share = '/'.$user; + } elseif (isset($params['share'])) { + $share = $params['share']; + } else { + throw new \Exception(); + } + parent::__construct(array( + "user" => $user, + "password" => $password, + "host" => $host, + "share" => $share, + "root" => $root + )); + } else { + throw new \Exception(); + } + } + + public static function login( $params ) { + \OC::$session->set('smb-credentials', $params); + } + + public function isSharable($path) { + return false; + } +} -- cgit v1.2.3 From b077528087fba76add6913563b4c8221ca99aa3f Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Wed, 26 Mar 2014 11:04:13 +0000 Subject: Perform proper checking for share availability To check for shares, the code attempts to connect anonymously to the share. In most cases this will fail with NT_STATUS_ACCESS_DENIED, so the regex array used for parsing the output of smbclient in smb4php has been overridden to treat such output as success. The 'test' method for storage classes can now take a single parameter, $isPersonal, which allows the storage to adjust the tests performed based on if they are being configured as personal shares or as system shares. --- apps/files_external/3rdparty/smb4php/smb.php | 80 +++++++++++++++------------- apps/files_external/lib/config.php | 12 ++--- apps/files_external/lib/smb_oc.php | 43 ++++++++++++++- 3 files changed, 90 insertions(+), 45 deletions(-) (limited to 'apps') diff --git a/apps/files_external/3rdparty/smb4php/smb.php b/apps/files_external/3rdparty/smb4php/smb.php index 656930514f0..e325506fa14 100644 --- a/apps/files_external/3rdparty/smb4php/smb.php +++ b/apps/files_external/3rdparty/smb4php/smb.php @@ -8,6 +8,8 @@ # Homepage: http://www.phpclasses.org/smb4php # # Copyright (c) 2007 Victor M. Varela +# Copyright (c) 2012 Frank Karlitschek +# Copyright (c) 2014 Robin McCorkell # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -19,8 +21,6 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # -# Addition 17/12/2012 Frank Karlitschek (frank@owncloud.org) -# Addition 17/03/2014 Robin McCorkell (rmccorkell@karoshi.org.uk) # On the official website http://www.phpclasses.org/smb4php the # license is listed as LGPL so we assume that this is # dual-licensed GPL/LGPL @@ -44,6 +44,42 @@ $GLOBALS['__smb_cache'] = array ('stat' => array (), 'dir' => array ()); class smb { + private static $regexp = array ( + '^added interface ip=(.*) bcast=(.*) nmask=(.*)$' => 'skip', + 'Anonymous login successful' => 'skip', + '^Domain=\[(.*)\] OS=\[(.*)\] Server=\[(.*)\]$' => 'skip', + '^\tSharename[ ]+Type[ ]+Comment$' => 'shares', + '^\t---------[ ]+----[ ]+-------$' => 'skip', + '^\tServer [ ]+Comment$' => 'servers', + '^\t---------[ ]+-------$' => 'skip', + '^\tWorkgroup[ ]+Master$' => 'workg', + '^\t(.*)[ ]+(Disk|IPC)[ ]+IPC.*$' => 'skip', + '^\tIPC\\\$(.*)[ ]+IPC' => 'skip', + '^\t(.*)[ ]+(Disk)[ ]+(.*)$' => 'share', + '^\t(.*)[ ]+(Printer)[ ]+(.*)$' => 'skip', + '([0-9]+) blocks of size ([0-9]+)\. ([0-9]+) blocks available' => 'skip', + 'Got a positive name query response from ' => 'skip', + '^(session setup failed): (.*)$' => 'error', + '^(.*): ERRSRV - ERRbadpw' => 'error', + '^Error returning browse list: (.*)$' => 'error', + '^tree connect failed: (.*)$' => 'error', + '^(Connection to .* failed)(.*)$' => 'error-connect', + '^NT_STATUS_(.*) ' => 'error', + '^NT_STATUS_(.*)\$' => 'error', + 'ERRDOS - ERRbadpath \((.*).\)' => 'error', + 'cd (.*): (.*)$' => 'error', + '^cd (.*): NT_STATUS_(.*)' => 'error', + '^\t(.*)$' => 'srvorwg', + '^([0-9]+)[ ]+([0-9]+)[ ]+(.*)$' => 'skip', + '^Job ([0-9]+) cancelled' => 'skip', + '^[ ]+(.*)[ ]+([0-9]+)[ ]+(Mon|Tue|Wed|Thu|Fri|Sat|Sun)[ ](Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[ ]+([0-9]+)[ ]+([0-9]{2}:[0-9]{2}:[0-9]{2})[ ]([0-9]{4})$' => 'files', + '^message start: ERRSRV - (ERRmsgoff)' => 'error' + ); + + function getRegexp() { + return self::$regexp; + } + function parse_url ($url) { $pu = parse_url (trim($url)); foreach (array ('domain', 'user', 'pass', 'host', 'port', 'path') as $i) { @@ -75,46 +111,16 @@ class smb { } - function execute ($command, $purl) { + function execute ($command, $purl, $regexp = NULL) { return smb::client ('-d 0 ' . escapeshellarg ('//' . $purl['host'] . '/' . $purl['share']) - . ' -c ' . escapeshellarg ($command), $purl + . ' -c ' . escapeshellarg ($command), $purl, $regexp ); } - function client ($params, $purl) { - - static $regexp = array ( - '^added interface ip=(.*) bcast=(.*) nmask=(.*)$' => 'skip', - 'Anonymous login successful' => 'skip', - '^Domain=\[(.*)\] OS=\[(.*)\] Server=\[(.*)\]$' => 'skip', - '^\tSharename[ ]+Type[ ]+Comment$' => 'shares', - '^\t---------[ ]+----[ ]+-------$' => 'skip', - '^\tServer [ ]+Comment$' => 'servers', - '^\t---------[ ]+-------$' => 'skip', - '^\tWorkgroup[ ]+Master$' => 'workg', - '^\t(.*)[ ]+(Disk|IPC)[ ]+IPC.*$' => 'skip', - '^\tIPC\\\$(.*)[ ]+IPC' => 'skip', - '^\t(.*)[ ]+(Disk)[ ]+(.*)$' => 'share', - '^\t(.*)[ ]+(Printer)[ ]+(.*)$' => 'skip', - '([0-9]+) blocks of size ([0-9]+)\. ([0-9]+) blocks available' => 'skip', - 'Got a positive name query response from ' => 'skip', - '^(session setup failed): (.*)$' => 'error', - '^(.*): ERRSRV - ERRbadpw' => 'error', - '^Error returning browse list: (.*)$' => 'error', - '^tree connect failed: (.*)$' => 'error', - '^(Connection to .* failed)(.*)$' => 'error-connect', - '^NT_STATUS_(.*) ' => 'error', - '^NT_STATUS_(.*)\$' => 'error', - 'ERRDOS - ERRbadpath \((.*).\)' => 'error', - 'cd (.*): (.*)$' => 'error', - '^cd (.*): NT_STATUS_(.*)' => 'error', - '^\t(.*)$' => 'srvorwg', - '^([0-9]+)[ ]+([0-9]+)[ ]+(.*)$' => 'skip', - '^Job ([0-9]+) cancelled' => 'skip', - '^[ ]+(.*)[ ]+([0-9]+)[ ]+(Mon|Tue|Wed|Thu|Fri|Sat|Sun)[ ](Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[ ]+([0-9]+)[ ]+([0-9]{2}:[0-9]{2}:[0-9]{2})[ ]([0-9]{4})$' => 'files', - '^message start: ERRSRV - (ERRmsgoff)' => 'error' - ); + function client ($params, $purl, $regexp = NULL) { + + if ($regexp === NULL) $regexp = smb::$regexp; if (SMB4PHP_AUTHMODE == 'env') { putenv("USER={$purl['user']}%{$purl['pass']}"); diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index af37a05cae0..043265d8982 100755 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -319,7 +319,7 @@ class OC_Mount_Config { 'backend' => $backends[$mount['class']]['backend'], 'options' => $mount['options'], 'applicable' => array('groups' => array($group), 'users' => array()), - 'status' => self::getBackendStatus($mount['class'], $mount['options']) + 'status' => self::getBackendStatus($mount['class'], $mount['options'], false) ); $hash = self::makeConfigHash($config); // If an existing config exists (with same class, mountpoint and options) @@ -349,7 +349,7 @@ class OC_Mount_Config { 'backend' => $backends[$mount['class']]['backend'], 'options' => $mount['options'], 'applicable' => array('groups' => array(), 'users' => array($user)), - 'status' => self::getBackendStatus($mount['class'], $mount['options']) + 'status' => self::getBackendStatus($mount['class'], $mount['options'], true) ); $hash = self::makeConfigHash($config); // If an existing config exists (with same class, mountpoint and options) @@ -389,7 +389,7 @@ class OC_Mount_Config { 'mountpoint' => substr($mountPoint, strlen($uid) + 8), 'backend' => $backends[$mount['class']]['backend'], 'options' => $mount['options'], - 'status' => self::getBackendStatus($mount['class'], $mount['options']) + 'status' => self::getBackendStatus($mount['class'], $mount['options'], true) ); } } @@ -402,7 +402,7 @@ class OC_Mount_Config { * @param array $options backend configuration options * @return bool true if the connection succeeded, false otherwise */ - private static function getBackendStatus($class, $options) { + private static function getBackendStatus($class, $options, $isPersonal) { if (self::$skipTest) { return true; } @@ -412,7 +412,7 @@ class OC_Mount_Config { if (class_exists($class)) { try { $storage = new $class($options); - return $storage->test(); + return $storage->test($isPersonal); } catch (Exception $exception) { \OCP\Util::logException('files_external', $exception); return false; @@ -479,7 +479,7 @@ class OC_Mount_Config { $mountPoints[$mountType] = $mount; } self::writeData($isPersonal, $mountPoints); - return self::getBackendStatus($class, $classOptions); + return self::getBackendStatus($class, $classOptions, $isPersonal); } /** diff --git a/apps/files_external/lib/smb_oc.php b/apps/files_external/lib/smb_oc.php index a62a2c01533..ac325cd4fbc 100644 --- a/apps/files_external/lib/smb_oc.php +++ b/apps/files_external/lib/smb_oc.php @@ -8,11 +8,15 @@ namespace OC\Files\Storage; +require_once __DIR__ . '/../3rdparty/smb4php/smb.php'; + class SMB_OC extends \OC\Files\Storage\SMB { + private $username_as_share; + public function __construct($params) { if (isset($params['host']) && \OC::$session->exists('smb-credentials')) { $host=$params['host']; - $username_as_share = ($params['username_as_share'] === 'true'); + $this->username_as_share = ($params['username_as_share'] === 'true'); $params_auth = \OC::$session->get('smb-credentials'); $user = \OC::$session->get('loginname'); @@ -21,7 +25,7 @@ class SMB_OC extends \OC\Files\Storage\SMB { $root=isset($params['root'])?$params['root']:'/'; $share = ''; - if ($username_as_share) { + if ($this->username_as_share) { $share = '/'.$user; } elseif (isset($params['share'])) { $share = $params['share']; @@ -47,4 +51,39 @@ class SMB_OC extends \OC\Files\Storage\SMB { public function isSharable($path) { return false; } + + public function test($isPersonal = true) { + if ($isPersonal) { + if ($this->stat('')) + return true; + return false; + } else { + $smb = new \smb(); + $pu = $smb->parse_url($this->constructUrl('')); + + // Attempt to connect anonymously + $pu['user'] = ''; + $pu['pass'] = ''; + + // Share cannot be checked if dynamic + if ($this->username_as_share) { + if ($smb->look($pu)) + return true; + else + return false; + } + if (!$pu['share']) + return false; + + // The following error messages are expected due to anonymous login + $regexp = array( + '(NT_STATUS_ACCESS_DENIED)' => 'skip' + ) + $smb->getRegexp(); + + if ($smb->client("-d 0 " . escapeshellarg('//' . $pu['host'] . '/' . $pu['share']) . " -c exit", $pu, $regexp)) + return true; + else + return false; + } + } } -- cgit v1.2.3 From cd5ebac7c40ad045828ea44c533b57fa25f01177 Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Wed, 26 Mar 2014 11:22:47 +0000 Subject: Fix error in $isPersonal setting --- apps/files_external/lib/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps') diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 043265d8982..472c3963d51 100755 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -349,7 +349,7 @@ class OC_Mount_Config { 'backend' => $backends[$mount['class']]['backend'], 'options' => $mount['options'], 'applicable' => array('groups' => array(), 'users' => array($user)), - 'status' => self::getBackendStatus($mount['class'], $mount['options'], true) + 'status' => self::getBackendStatus($mount['class'], $mount['options'], false) ); $hash = self::makeConfigHash($config); // If an existing config exists (with same class, mountpoint and options) -- cgit v1.2.3 From a1dca821f9c2cf770b6884e943a0841c0ab6171d Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Wed, 26 Mar 2014 15:11:09 +0000 Subject: Use braces on single line if statements --- apps/files_external/lib/smb_oc.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'apps') diff --git a/apps/files_external/lib/smb_oc.php b/apps/files_external/lib/smb_oc.php index ac325cd4fbc..0c79c06c5df 100644 --- a/apps/files_external/lib/smb_oc.php +++ b/apps/files_external/lib/smb_oc.php @@ -54,8 +54,9 @@ class SMB_OC extends \OC\Files\Storage\SMB { public function test($isPersonal = true) { if ($isPersonal) { - if ($this->stat('')) + if ($this->stat('')) { return true; + } return false; } else { $smb = new \smb(); @@ -67,23 +68,26 @@ class SMB_OC extends \OC\Files\Storage\SMB { // Share cannot be checked if dynamic if ($this->username_as_share) { - if ($smb->look($pu)) + if ($smb->look($pu)) { return true; - else + } else { return false; + } } - if (!$pu['share']) + if (!$pu['share']) { return false; + } // The following error messages are expected due to anonymous login $regexp = array( '(NT_STATUS_ACCESS_DENIED)' => 'skip' ) + $smb->getRegexp(); - if ($smb->client("-d 0 " . escapeshellarg('//' . $pu['host'] . '/' . $pu['share']) . " -c exit", $pu, $regexp)) + if ($smb->client("-d 0 " . escapeshellarg('//' . $pu['host'] . '/' . $pu['share']) . " -c exit", $pu, $regexp)) { return true; - else + } else { return false; + } } } } -- cgit v1.2.3