Commit 8199c97a authored by Anand K. Mistry's avatar Anand K. Mistry Committed by Commit Bot

Pass resolved IP address when mounting smbfs share

In certain cases, the smbfs daemon isn't able to resolve some hosts to
IP addresses (i.e. multiple networks connected, netbios).

Bug: 939235
Change-Id: I638939333b5cd87909bb6738ad963e8f98187564
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2050001
Commit-Queue: Anand Mistry <amistry@chromium.org>
Reviewed-by: default avatarRyo Hashimoto <hashimoto@chromium.org>
Reviewed-by: default avatarAustin Tankiang <austinct@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742497}
parent 7e413b6b
......@@ -383,8 +383,9 @@ void SmbService::MountInternal(
DCHECK(user);
if (IsSmbFsEnabled()) {
// TODO(amistry): Pass resolved host address to smbfs.
SmbFsShare::MountOptions smbfs_options;
smbfs_options.resolved_host =
share_finder_->GetResolvedHost(info.share_url().GetHost());
smbfs_options.username = info.username();
smbfs_options.workgroup = info.workgroup();
smbfs_options.password = password;
......
......@@ -97,6 +97,11 @@ SmbUrl SmbShareFinder::GetResolvedUrl(const SmbUrl& url) const {
return url.ReplaceHost(ip_address);
}
net::IPAddress SmbShareFinder::GetResolvedHost(const std::string& host) const {
DCHECK(!host.empty());
return scanner_.ResolveHost(host);
}
bool SmbShareFinder::TryResolveUrl(const SmbUrl& url,
SmbUrl* updated_url) const {
*updated_url = GetResolvedUrl(url);
......
......@@ -53,6 +53,10 @@ class SmbShareFinder : public base::SupportsWeakPtr<SmbShareFinder> {
// otherwise returns |url|.
SmbUrl GetResolvedUrl(const SmbUrl& url) const;
// Returns the IP address of |host|. |host| MUST be non-empty. If |host|
// cannot be resolved, returns the empty/invalid IPAddress.
net::IPAddress GetResolvedHost(const std::string& host) const;
// Attempts to resolve |url|. If able to resolve |url|, returns true and sets
// |resolved_url| the the resolved url. If unable, returns false and sets
// |resolved_url| to |url|.
......
......@@ -2,4 +2,8 @@ amistry@chromium.org
dats@chromium.org
slangley@chromium.org
per-file *_mojom_traits*.*=set noparent
per-file *_mojom_traits*.*=file://ipc/SECURITY_OWNERS
per-file *.typemap=set noparent
per-file *.typemap=file://ipc/SECURITY_OWNERS
# COMPONENT: Platform>Apps>FileManager
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/components/smbfs/ip_address_mojom_traits.h"
namespace mojo {
// static
bool StructTraits<smbfs::mojom::IPAddressDataView, net::IPAddress>::Read(
smbfs::mojom::IPAddressDataView data,
net::IPAddress* out) {
std::vector<uint8_t> bytes;
if (!data.ReadAddressBytes(&bytes))
return false;
if (bytes.size() && bytes.size() != net::IPAddress::kIPv4AddressSize &&
bytes.size() != net::IPAddress::kIPv6AddressSize) {
return false;
}
*out = net::IPAddress(bytes.data(), bytes.size());
return true;
}
} // namespace mojo
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_COMPONENTS_SMBFS_IP_ADDRESS_MOJOM_TRAITS_H_
#define CHROMEOS_COMPONENTS_SMBFS_IP_ADDRESS_MOJOM_TRAITS_H_
#include "base/containers/span.h"
#include "chromeos/components/smbfs/mojom/ip_address.mojom-shared.h"
#include "mojo/public/cpp/bindings/struct_traits.h"
#include "net/base/ip_address.h"
namespace mojo {
template <>
struct COMPONENT_EXPORT(NETWORK_CPP_BASE)
StructTraits<smbfs::mojom::IPAddressDataView, net::IPAddress> {
static base::span<const uint8_t> address_bytes(
const net::IPAddress& ip_address) {
return ip_address.bytes();
}
static bool Read(smbfs::mojom::IPAddressDataView obj, net::IPAddress* out);
};
} // namespace mojo
#endif // CHROMEOS_COMPONENTS_SMBFS_IP_ADDRESS_MOJOM_TRAITS_H_
......@@ -5,7 +5,10 @@
import("//mojo/public/tools/bindings/mojom.gni")
mojom_component("mojom") {
sources = [ "smbfs.mojom" ]
sources = [
"ip_address.mojom",
"smbfs.mojom",
]
public_deps = [ "//mojo/public/mojom/base" ]
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module smbfs.mojom;
// This file is shared between Chrome and Chrome OS.
// In Chrome, this file is located at:
// //chromeos/components/smbfs/mojom/ip_address.mojom
// In Chrome OS, this file is located at:
// //platform2/smbfs/mojom/ip_address.mojom
// This file is a copy of //services/network/public/mojom/ip_address.mojom
// Mirror of net::IPAddress.
struct IPAddress {
// IP address as a numeric value from most to least significant byte.
// Will be of length 4 for IPv4 addresses and 16 for IPv6.
array<uint8> address_bytes;
};
......@@ -4,6 +4,8 @@
module smbfs.mojom;
import "chromeos/components/smbfs/mojom/ip_address.mojom";
// This file is shared between Chrome and Chrome OS.
// In Chrome, this file is located at:
// //chromeos/components/smbfs/mojom/smbfs.mojom
......@@ -86,6 +88,9 @@ struct MountOptions {
// (unless the user entered an IP address as the hostname).
string share_path;
// Resolved IP address of the share's hostname.
IPAddress? resolved_host;
// Authentication parameters.
string username;
string workgroup;
......
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
mojom = "//chromeos/components/smbfs/mojom/ip_address.mojom"
public_headers = [ "//net/base/ip_address.h" ]
traits_headers = [ "//chromeos/components/smbfs/ip_address_mojom_traits.h" ]
type_mappings = [ "smbfs.mojom.IPAddress=::net::IPAddress" ]
sources = [
"//chromeos/components/smbfs/ip_address_mojom_traits.cc",
"//chromeos/components/smbfs/ip_address_mojom_traits.h",
]
public_deps = [ "//net" ]
......@@ -129,6 +129,10 @@ void SmbFsMounter::OnMountDone(
mojom::MountOptionsPtr mount_options = mojom::MountOptions::New();
mount_options->share_path = share_path_;
if (options_.resolved_host.IsIPv4()) {
// TODO(crbug.com/1051291): Support IPv6.
mount_options->resolved_host = options_.resolved_host;
}
mount_options->username = options_.username;
mount_options->workgroup = options_.workgroup;
mount_options->allow_ntlm = options_.allow_ntlm;
......
......@@ -22,6 +22,7 @@
#include "chromeos/disks/mount_point.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/invitation.h"
#include "net/base/ip_address.h"
namespace smbfs {
......@@ -50,6 +51,9 @@ class COMPONENT_EXPORT(SMBFS) SmbFsMounter {
MountOptions(const MountOptions&);
~MountOptions();
// Resolved IP address for share's hostname.
net::IPAddress resolved_host;
// Authentication options.
std::string username;
std::string workgroup;
......
......@@ -290,6 +290,7 @@ TEST_F(SmbFsMounterTest, MountOptions) {
EXPECT_EQ(password_buf, kPassword);
EXPECT_TRUE(options->allow_ntlm);
EXPECT_FALSE(options->skip_connect);
EXPECT_EQ(options->resolved_host, net::IPAddress(1, 2, 3, 4));
delegate_remote = std::move(delegate);
std::move(callback).Run(mojom::MountError::kOk,
......@@ -301,6 +302,7 @@ TEST_F(SmbFsMounterTest, MountOptions) {
mount_options.workgroup = kWorkgroup;
mount_options.password = kPassword;
mount_options.allow_ntlm = true;
mount_options.resolved_host = net::IPAddress(1, 2, 3, 4);
std::unique_ptr<SmbFsMounter> mounter = std::make_unique<TestSmbFsMounter>(
kSharePath, mount_options, &mock_delegate_, base::FilePath(kMountPath),
chromeos::MOUNT_ERROR_NONE,
......
......@@ -2,4 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
typemaps = [ "//chromeos/components/drivefs/drivefs.typemap" ]
typemaps = [
"//chromeos/components/drivefs/drivefs.typemap",
"//chromeos/components/smbfs/smbfs.typemap",
]
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