Commit 848de07a authored by Bailey Berro's avatar Bailey Berro Committed by Commit Bot

Add credentials as parameters to SmbService::Mount api

Adds username and password as parameters to SmbSerice::Mount and the
corresponding internal functions.

Bug: chromium:757625
Change-Id: I8e5f9ea4f9779746703d066098408afc4489f620
Reviewed-on: https://chromium-review.googlesource.com/1054690
Commit-Queue: Bailey Berro <baileyberro@chromium.org>
Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Reviewed-by: default avatarScott Chen <scottchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558355}
parent d81834af
...@@ -23,6 +23,14 @@ using chromeos::file_system_provider::Service; ...@@ -23,6 +23,14 @@ using chromeos::file_system_provider::Service;
namespace chromeos { namespace chromeos {
namespace smb_client { namespace smb_client {
namespace {
bool ContainsAt(const std::string& username) {
return username.find('@') != std::string::npos;
}
} // namespace
SmbService::SmbService(Profile* profile) SmbService::SmbService(Profile* profile)
: provider_id_(ProviderId::CreateFromNativeId("smb")), profile_(profile) { : provider_id_(ProviderId::CreateFromNativeId("smb")), profile_(profile) {
if (base::FeatureList::IsEnabled(features::kNativeSmb)) { if (base::FeatureList::IsEnabled(features::kNativeSmb)) {
...@@ -39,18 +47,23 @@ SmbService* SmbService::Get(content::BrowserContext* context) { ...@@ -39,18 +47,23 @@ SmbService* SmbService::Get(content::BrowserContext* context) {
void SmbService::Mount(const file_system_provider::MountOptions& options, void SmbService::Mount(const file_system_provider::MountOptions& options,
const base::FilePath& share_path, const base::FilePath& share_path,
const std::string& username,
const std::string& password,
MountResponse callback) { MountResponse callback) {
if (!temp_file_manager_) { if (!temp_file_manager_) {
InitTempFileManagerAndMount(options, share_path, std::move(callback)); InitTempFileManagerAndMount(options, share_path, username, password,
std::move(callback));
return; return;
} }
CallMount(options, share_path, std::move(callback)); CallMount(options, share_path, username, password, std::move(callback));
} }
void SmbService::InitTempFileManagerAndMount( void SmbService::InitTempFileManagerAndMount(
const file_system_provider::MountOptions& options, const file_system_provider::MountOptions& options,
const base::FilePath& share_path, const base::FilePath& share_path,
const std::string& username,
const std::string& password,
MountResponse callback) { MountResponse callback) {
// InitTempFileManager() has to be called on a separate thread since it // InitTempFileManager() has to be called on a separate thread since it
// contains a call that requires a blockable thread. // contains a call that requires a blockable thread.
...@@ -61,7 +74,7 @@ void SmbService::InitTempFileManagerAndMount( ...@@ -61,7 +74,7 @@ void SmbService::InitTempFileManagerAndMount(
base::BindOnce(&SmbService::InitTempFileManager, base::Unretained(this)); base::BindOnce(&SmbService::InitTempFileManager, base::Unretained(this));
base::OnceClosure reply = base::OnceClosure reply =
base::BindOnce(&SmbService::CallMount, base::Unretained(this), options, base::BindOnce(&SmbService::CallMount, base::Unretained(this), options,
share_path, base::Passed(&callback)); share_path, username, password, base::Passed(&callback));
base::PostTaskWithTraitsAndReply(FROM_HERE, task_traits, std::move(task), base::PostTaskWithTraitsAndReply(FROM_HERE, task_traits, std::move(task),
std::move(reply)); std::move(reply));
...@@ -69,21 +82,35 @@ void SmbService::InitTempFileManagerAndMount( ...@@ -69,21 +82,35 @@ void SmbService::InitTempFileManagerAndMount(
void SmbService::CallMount(const file_system_provider::MountOptions& options, void SmbService::CallMount(const file_system_provider::MountOptions& options,
const base::FilePath& share_path, const base::FilePath& share_path,
const std::string& username_input,
const std::string& password_input,
MountResponse callback) { MountResponse callback) {
std::string workgroup;
std::string username; std::string username;
std::string password;
std::string workgroup;
user_manager::User* user = if (username_input.empty()) {
chromeos::ProfileHelper::Get()->GetUserByProfile(profile_); // If no credentials were provided and the user is ChromAD, pass the users
if (user && user->IsActiveDirectoryUser()) { // username and workgroup for their email address to be used for Kerberos
ParseUserPrincipalName(user->GetDisplayEmail(), &username, &workgroup); // authentication.
user_manager::User* user =
chromeos::ProfileHelper::Get()->GetUserByProfile(profile_);
if (user && user->IsActiveDirectoryUser()) {
ParseUserPrincipalName(user->GetDisplayEmail(), &username, &workgroup);
}
} else {
// Credentials were provided so use them and parse the username into
// username and workgroup if neccessary.
username = username_input;
password = password_input;
if (ContainsAt(username)) {
ParseUserPrincipalName(username_input, &username, &workgroup);
}
} }
// TODO(allenvic): Implement passing of credentials. This currently passes
// empty credentials to SmbProvider for non-ChromAD users.
GetSmbProviderClient()->Mount( GetSmbProviderClient()->Mount(
share_path, workgroup, username, share_path, workgroup, username,
temp_file_manager_->WritePasswordToFile("" /* password */), temp_file_manager_->WritePasswordToFile(password),
base::BindOnce(&SmbService::OnMountResponse, AsWeakPtr(), base::BindOnce(&SmbService::OnMountResponse, AsWeakPtr(),
base::Passed(&callback), options, share_path)); base::Passed(&callback), options, share_path));
} }
......
...@@ -49,6 +49,8 @@ class SmbService : public KeyedService, ...@@ -49,6 +49,8 @@ class SmbService : public KeyedService,
// Calls SmbProviderClient::Mount(). // Calls SmbProviderClient::Mount().
void Mount(const file_system_provider::MountOptions& options, void Mount(const file_system_provider::MountOptions& options,
const base::FilePath& share_path, const base::FilePath& share_path,
const std::string& username,
const std::string& password,
MountResponse callback); MountResponse callback);
// Completes the mounting of an SMB file system, passing |options| on to // Completes the mounting of an SMB file system, passing |options| on to
...@@ -68,12 +70,16 @@ class SmbService : public KeyedService, ...@@ -68,12 +70,16 @@ class SmbService : public KeyedService,
void InitTempFileManagerAndMount( void InitTempFileManagerAndMount(
const file_system_provider::MountOptions& options, const file_system_provider::MountOptions& options,
const base::FilePath& share_path, const base::FilePath& share_path,
const std::string& username,
const std::string& password,
MountResponse callback); MountResponse callback);
// Calls SmbProviderClient::Mount(). temp_file_manager_ must be initialized // Calls SmbProviderClient::Mount(). temp_file_manager_ must be initialized
// before this is called. // before this is called.
void CallMount(const file_system_provider::MountOptions& options, void CallMount(const file_system_provider::MountOptions& options,
const base::FilePath& share_path, const base::FilePath& share_path,
const std::string& username,
const std::string& password,
MountResponse callback); MountResponse callback);
// Calls file_system_provider::Service::UnmountFileSystem(). // Calls file_system_provider::Service::UnmountFileSystem().
......
...@@ -35,8 +35,8 @@ void SmbHandler::RegisterMessages() { ...@@ -35,8 +35,8 @@ void SmbHandler::RegisterMessages() {
void SmbHandler::HandleSmbMount(const base::ListValue* args) { void SmbHandler::HandleSmbMount(const base::ListValue* args) {
CHECK_EQ(1U, args->GetSize()); CHECK_EQ(1U, args->GetSize());
std::string mountUrl; std::string mountUrl;
CHECK(args->GetString(0, &mountUrl));
CHECK(args->GetString(0, &mountUrl));
chromeos::smb_client::SmbService* const service = chromeos::smb_client::SmbService* const service =
chromeos::smb_client::SmbService::Get(profile_); chromeos::smb_client::SmbService::Get(profile_);
...@@ -44,8 +44,8 @@ void SmbHandler::HandleSmbMount(const base::ListValue* args) { ...@@ -44,8 +44,8 @@ void SmbHandler::HandleSmbMount(const base::ListValue* args) {
mo.display_name = mountUrl; mo.display_name = mountUrl;
mo.writable = true; mo.writable = true;
service->Mount(mo, base::FilePath(mountUrl), service->Mount(mo, base::FilePath(mountUrl), "" /* username */,
base::BindOnce(&DoNothingCallback)); "" /* password */, base::BindOnce(&DoNothingCallback));
} }
} // namespace settings } // namespace settings
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment