diff options
Diffstat (limited to 'apps/files_external/lib/smb_oc.php')
-rw-r--r-- | apps/files_external/lib/smb_oc.php | 45 |
1 files changed, 15 insertions, 30 deletions
diff --git a/apps/files_external/lib/smb_oc.php b/apps/files_external/lib/smb_oc.php index a7c93d97fd1..245d1ed79b3 100644 --- a/apps/files_external/lib/smb_oc.php +++ b/apps/files_external/lib/smb_oc.php @@ -8,9 +8,12 @@ namespace OC\Files\Storage; -require_once __DIR__ . '/../3rdparty/smb4php/smb.php'; -class SMB_OC extends \OC\Files\Storage\SMB { +use Icewind\SMB\Exception\AccessDeniedException; +use Icewind\SMB\Exception\Exception; +use Icewind\SMB\Server; + +class SMB_OC extends SMB { private $username_as_share; /** @@ -19,18 +22,18 @@ class SMB_OC extends \OC\Files\Storage\SMB { */ public function __construct($params) { if (isset($params['host']) && \OC::$server->getSession()->exists('smb-credentials')) { - $host=$params['host']; + $host = $params['host']; $this->username_as_share = ($params['username_as_share'] === 'true'); $params_auth = json_decode(\OC::$server->getCrypto()->decrypt(\OC::$server->getSession()->get('smb-credentials')), true); $user = \OC::$server->getSession()->get('loginname'); $password = $params_auth['password']; - $root=isset($params['root'])?$params['root']:'/'; + $root = isset($params['root']) ? $params['root'] : '/'; $share = ''; if ($this->username_as_share) { - $share = '/'.$user; + $share = '/' . $user; } elseif (isset($params['share'])) { $share = $params['share']; } else { @@ -84,33 +87,15 @@ class SMB_OC extends \OC\Files\Storage\SMB { } 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(); + $server = new Server($this->server->getHost(), '', ''); - if ($smb->client("-d 0 " . escapeshellarg('//' . $pu['host'] . '/' . $pu['share']) . " -c exit", $pu, $regexp)) { + try { + $server->listShares(); return true; - } else { + } catch (AccessDeniedException $e) { + // expected due to anonymous login + return true; + } catch (Exception $e) { return false; } } |