Commit 57871e9a authored by Anand K. Mistry's avatar Anand K. Mistry Committed by Commit Bot

Change SMB share "premounting" to use SmbService::MountInternal()

Also rename to MountPreconfiguredShare() to avoid the confusion between
mount/remount/premount.

Bug: 939235
Change-Id: If9df3a55b4aea6852468078b2188974adf35af24
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2035504
Commit-Queue: Anand Mistry <amistry@chromium.org>
Reviewed-by: default avatarAustin Tankiang <austinct@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738427}
parent 646dcd9f
......@@ -337,6 +337,7 @@ void SmbService::Mount(const file_system_provider::MountOptions& options,
}
MountInternal(provider_options, parsed_url, options.display_name, username,
workgroup, password, use_kerberos, save_credentials,
false /* skip_connect */,
base::BindOnce(&SmbService::MountInternalDone,
base::Unretained(this), std::move(callback),
should_open_file_manager_after_mount));
......@@ -372,6 +373,7 @@ void SmbService::MountInternal(
const std::string& password,
bool use_kerberos,
bool save_credentials,
bool skip_connect,
MountInternalCallback callback) {
user_manager::User* user =
chromeos::ProfileHelper::Get()->GetUserByProfile(profile_);
......@@ -423,6 +425,7 @@ void SmbService::MountInternal(
smb_mount_options.ntlm_enabled = IsNTLMAuthenticationEnabled();
smb_mount_options.save_password = save_credentials && !use_kerberos;
smb_mount_options.account_hash = user->username_hash();
smb_mount_options.skip_connect = skip_connect;
GetSmbProviderClient()->Mount(
base::FilePath(url), smb_mount_options, MakeFdWithContents(password),
base::BindOnce(&SmbService::OnProviderMountDone, AsWeakPtr(),
......@@ -541,8 +544,7 @@ void SmbService::OnHostsDiscovered(
Remount(file_system);
}
for (const auto& url : preconfigured_shares) {
const base::FilePath share_path(share_finder_->GetResolvedUrl(url));
Premount(share_path);
MountPreconfiguredShare(url);
}
}
......@@ -634,42 +636,34 @@ void SmbService::OnRemountResponse(const std::string& file_system_id,
mount_id_map_[file_system_id] = mount_id;
}
void SmbService::Premount(const base::FilePath& share_path) {
// Premounting is equivalent to remounting, but with an empty username and
// password.
SmbProviderClient::MountOptions smb_mount_options;
smb_mount_options.ntlm_enabled = IsNTLMAuthenticationEnabled();
smb_mount_options.skip_connect = true;
GetSmbProviderClient()->Mount(
share_path, smb_mount_options, MakeFdWithContents(""),
base::BindOnce(&SmbService::OnPremountResponse, AsWeakPtr(), share_path));
}
void SmbService::OnPremountResponse(const base::FilePath& share_path,
smbprovider::ErrorType error,
int32_t mount_id) {
DCHECK_GE(mount_id, 0);
void SmbService::MountPreconfiguredShare(const SmbUrl& share_url) {
file_system_provider::MountOptions mount_options;
mount_options.display_name = share_path.BaseName().value();
mount_options.display_name =
base::FilePath(share_url.ToString()).BaseName().value();
mount_options.writable = true;
// |is_chromad_kerberos| is false because we do not pass user and workgroup
// at mount time. Premounts also do not get remounted and currently
// |is_chromad_kerberos| is only used at remounts to determine if the share
// was mounted with chromad kerberos.
// TODO(jimmyxgong): Support chromad kerberos for premount.
mount_options.file_system_id =
CreateFileSystemId(share_path, false /* is_chromad_kerberos */);
// TODO(crbug.com/922269): Support kerberos for preconfigured shares.
mount_options.file_system_id = CreateFileSystemId(
base::FilePath(share_url.ToString()), false /* is_chromad_kerberos */);
// Disable remounting of preconfigured shares.
mount_options.persistent = false;
mount_id_map_[mount_options.file_system_id] = mount_id;
const base::File::Error result =
GetProviderService()->MountFileSystem(provider_id_, mount_options);
// Note: Preconfigured shares are mounted without credentials.
MountInternal(
mount_options, share_url, mount_options.display_name, "" /* username */,
"" /* workgroup */, "" /* password */, false /* use_kerberos */,
false /* save_credentials */, true /* skip_connect */,
base::BindOnce(&SmbService::OnMountPreconfiguredShareDone, AsWeakPtr()));
}
if (result != base::File::FILE_OK) {
LOG(ERROR) << "Error mounting preconfigured share with File Manager.";
}
void SmbService::OnMountPreconfiguredShareDone(
SmbMountResult result,
const base::FilePath& mount_path) {
LOG_IF(ERROR, result != SmbMountResult::kSuccess)
<< "Error mounting preconfigured share: " << static_cast<int>(result);
}
bool SmbService::IsKerberosEnabledViaPolicy() const {
......
......@@ -140,6 +140,7 @@ class SmbService : public KeyedService,
const std::string& password,
bool use_kerberos,
bool save_credentials,
bool skip_connect,
MountInternalCallback callback);
// Handles the response from mounting an SMB share using smbprovider.
......@@ -195,14 +196,14 @@ class SmbService : public KeyedService,
smbprovider::ErrorType error,
int32_t mount_id);
// Calls SmbProviderClient::Premount().
void Premount(const base::FilePath& share_path);
// Mounts a preconfigured (by policy) SMB share with path |share_url|. The
// share is mounted with empty credentials.
void MountPreconfiguredShare(const SmbUrl& share_url);
// Handles the response from attempting to premount a share configured via
// policy. If premounting fails it will log and exit the operation.
void OnPremountResponse(const base::FilePath& share_path,
smbprovider::ErrorType error,
int32_t mount_id);
// Handles the response from attempting to mount a share configured via
// policy.
void OnMountPreconfiguredShareDone(SmbMountResult result,
const base::FilePath& mount_path);
// Completes SmbService setup including ShareFinder initialization and
// remounting shares.
......
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