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.
This commit is contained in:
Robin McCorkell 2014-03-21 14:22:48 +00:00
parent b656c68ede
commit ba63e46b5e
3 changed files with 60 additions and 3 deletions

View File

@ -1,6 +1,7 @@
<?php
/**
* Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
* Copyright (c) 2014 Robin McCorkell <rmccorkell@karoshi.org.uk>
* 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');

View File

@ -5,6 +5,7 @@
* @author Michael Gapczynski
* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
* @copyright 2014 Vincent Petry <pvince81@owncloud.com>
* @copyright 2014 Robin McCorkell <rmccorkell@karoshi.org.uk>
*
* 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");

View File

@ -0,0 +1,46 @@
<?php
/**
* Copyright (c) 2014 Robin McCorkell <rmccorkell@karoshi.org.uk>
* 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);
}
}