2014-03-21 18:22:48 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Lukas Reschke <lukas@owncloud.com>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Robin Appelman <icewind@owncloud.com>
|
|
|
|
* @author Robin McCorkell <rmccorkell@karoshi.org.uk>
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
2014-03-21 18:22:48 +04:00
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2014-03-21 18:22:48 +04:00
|
|
|
namespace OC\Files\Storage;
|
|
|
|
|
2014-03-26 15:04:13 +04:00
|
|
|
|
2014-08-26 20:46:07 +04:00
|
|
|
use Icewind\SMB\Exception\AccessDeniedException;
|
|
|
|
use Icewind\SMB\Exception\Exception;
|
|
|
|
use Icewind\SMB\Server;
|
|
|
|
|
|
|
|
class SMB_OC extends SMB {
|
2014-03-26 15:04:13 +04:00
|
|
|
private $username_as_share;
|
|
|
|
|
2014-10-23 22:17:08 +04:00
|
|
|
/**
|
|
|
|
* @param array $params
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
2014-03-21 18:22:48 +04:00
|
|
|
public function __construct($params) {
|
2015-03-20 18:55:53 +03:00
|
|
|
if (isset($params['host'])) {
|
2014-08-26 20:46:07 +04:00
|
|
|
$host = $params['host'];
|
2014-03-26 15:04:13 +04:00
|
|
|
$this->username_as_share = ($params['username_as_share'] === 'true');
|
2014-03-21 18:22:48 +04:00
|
|
|
|
2015-03-20 18:55:53 +03:00
|
|
|
// dummy credentials, unused, to satisfy constructor
|
|
|
|
$user = 'foo';
|
|
|
|
$password = 'bar';
|
|
|
|
if (\OC::$server->getSession()->exists('smb-credentials')) {
|
|
|
|
$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'];
|
|
|
|
} else {
|
|
|
|
// assume we are testing from the admin section
|
|
|
|
}
|
2014-03-21 18:22:48 +04:00
|
|
|
|
2014-08-26 20:46:07 +04:00
|
|
|
$root = isset($params['root']) ? $params['root'] : '/';
|
2014-03-21 18:22:48 +04:00
|
|
|
$share = '';
|
|
|
|
|
2014-03-26 15:04:13 +04:00
|
|
|
if ($this->username_as_share) {
|
2014-08-26 20:46:07 +04:00
|
|
|
$share = '/' . $user;
|
2014-03-21 18:22:48 +04:00
|
|
|
} 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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-23 22:17:08 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Intercepts the user credentials on login and stores them
|
|
|
|
* encrypted inside the session if SMB_OC storage is enabled.
|
|
|
|
* @param array $params
|
|
|
|
*/
|
|
|
|
public static function login($params) {
|
|
|
|
$mountpoints = \OC_Mount_Config::getAbsoluteMountPoints($params['uid']);
|
|
|
|
$mountpointClasses = array();
|
|
|
|
foreach($mountpoints as $mountpoint) {
|
|
|
|
$mountpointClasses[$mountpoint['class']] = true;
|
|
|
|
}
|
|
|
|
if(isset($mountpointClasses['\OC\Files\Storage\SMB_OC'])) {
|
|
|
|
\OC::$server->getSession()->set('smb-credentials', \OC::$server->getCrypto()->encrypt(json_encode($params)));
|
|
|
|
}
|
2014-03-21 18:22:48 +04:00
|
|
|
}
|
2014-03-24 19:15:15 +04:00
|
|
|
|
2014-10-23 22:17:08 +04:00
|
|
|
/**
|
|
|
|
* @param string $path
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2014-03-24 19:15:15 +04:00
|
|
|
public function isSharable($path) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-26 15:04:13 +04:00
|
|
|
|
2014-10-23 22:17:08 +04:00
|
|
|
/**
|
|
|
|
* @param bool $isPersonal
|
|
|
|
* @return bool
|
|
|
|
*/
|
2014-03-26 15:04:13 +04:00
|
|
|
public function test($isPersonal = true) {
|
|
|
|
if ($isPersonal) {
|
2014-03-26 19:11:09 +04:00
|
|
|
if ($this->stat('')) {
|
2014-03-26 15:04:13 +04:00
|
|
|
return true;
|
2014-03-26 19:11:09 +04:00
|
|
|
}
|
2014-03-26 15:04:13 +04:00
|
|
|
return false;
|
|
|
|
} else {
|
2014-08-26 20:46:07 +04:00
|
|
|
$server = new Server($this->server->getHost(), '', '');
|
2014-03-26 15:04:13 +04:00
|
|
|
|
2014-08-26 20:46:07 +04:00
|
|
|
try {
|
|
|
|
$server->listShares();
|
2014-03-26 15:04:13 +04:00
|
|
|
return true;
|
2014-08-26 20:46:07 +04:00
|
|
|
} catch (AccessDeniedException $e) {
|
|
|
|
// expected due to anonymous login
|
|
|
|
return true;
|
|
|
|
} catch (Exception $e) {
|
2014-03-26 15:04:13 +04:00
|
|
|
return false;
|
2014-03-26 19:11:09 +04:00
|
|
|
}
|
2014-03-26 15:04:13 +04:00
|
|
|
}
|
|
|
|
}
|
2014-03-21 18:22:48 +04:00
|
|
|
}
|