-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SMB/CIFS mounts using ownCloud login, fixes #7843 #7875
Merged
PVince81
merged 7 commits into
owncloud:master
from
RobinMcCorkell:files_external_smb_auto
Mar 27, 2014
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ba63e46
SMB/CIFS mount using OwnCloud logon credentials
3445c06
Use loginname instead of display name
86aa610
Revoke sharable permission on automatic SMB shares
cac4aaa
Rename SMB_Auto to SMB_OC and change visible name
b077528
Perform proper checking for share availability
cd5ebac
Fix error in $isPersonal setting
a1dca82
Use braces on single line if statements
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?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; | ||
|
||
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']; | ||
$this->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 ($this->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; | ||
} | ||
|
||
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; | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please always use {}