diff options
author | Robin McCorkell <rmccorkell@karoshi.org.uk> | 2014-03-21 14:22:48 +0000 |
---|---|---|
committer | Robin McCorkell <rmccorkell@karoshi.org.uk> | 2014-03-26 14:35:07 +0000 |
commit | ba63e46b5e11bddc1bc5a636ef6622b60da579f1 (patch) | |
tree | 880e3ab26c08831143ab7ee778a0c5cac69ed867 /apps/files_external/lib | |
parent | b656c68edee995e17f6eb1febe2a1d620564a2c9 (diff) | |
download | nextcloud-server-ba63e46b5e11bddc1bc5a636ef6622b60da579f1.tar.gz nextcloud-server-ba63e46b5e11bddc1bc5a636ef6622b60da579f1.zip |
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.
Diffstat (limited to 'apps/files_external/lib')
-rwxr-xr-x | apps/files_external/lib/config.php | 14 | ||||
-rw-r--r-- | apps/files_external/lib/smb_auto.php | 46 |
2 files changed, 57 insertions, 3 deletions
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 <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"); 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 @@ +<?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); + } +} |