Commit 3c22484f authored by Anand K. Mistry's avatar Anand K. Mistry Committed by Commit Bot

Export a D-Bus service used to bootstrap Mojo IPC for SmbFs.

When mounting SmbFs through cros-disks, there is currently no ability to
pass a file descriptor (eg. for a socket) over the D-Bus Mount() method.
Instead, a random string is generated and provided to SmbFs as part of
the mount source path. SmbFs will then generate a socket pair and pass
one end back to Chrome, along with the random string as an identifier,
through this D-Bus service.

This service is an exact duplicate of org.chromium.DriveFileStream.

Bug: 939235
Change-Id: Ideaec725a50ab7a1dba6e11b152fb08280c3a75b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1890378Reviewed-by: default avatarJorge Lucangeli Obes <jorgelo@chromium.org>
Reviewed-by: default avatarAlexander Alekseev <alemate@chromium.org>
Commit-Queue: Anand Mistry <amistry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714124}
parent 2dc4c185
......@@ -884,6 +884,8 @@ source_set("chromeos") {
"dbus/proxy_resolution_service_provider.h",
"dbus/screen_lock_service_provider.cc",
"dbus/screen_lock_service_provider.h",
"dbus/smb_fs_service_provider.cc",
"dbus/smb_fs_service_provider.h",
"dbus/virtual_file_request_service_provider.cc",
"dbus/virtual_file_request_service_provider.h",
"dbus/vm_applications_service_provider.cc",
......@@ -2354,6 +2356,7 @@ action("dbus_service_files") {
"dbus/org.chromium.NetworkProxyService.conf",
"dbus/org.chromium.PluginVmService.conf",
"dbus/org.chromium.ScreenLockService.conf",
"dbus/org.chromium.SmbFsService.conf",
"dbus/org.chromium.VirtualFileRequestService.conf",
"dbus/org.chromium.VmApplicationsService.conf",
]
......
......@@ -57,6 +57,7 @@
#include "chrome/browser/chromeos/dbus/plugin_vm_service_provider.h"
#include "chrome/browser/chromeos/dbus/proxy_resolution_service_provider.h"
#include "chrome/browser/chromeos/dbus/screen_lock_service_provider.h"
#include "chrome/browser/chromeos/dbus/smb_fs_service_provider.h"
#include "chrome/browser/chromeos/dbus/virtual_file_request_service_provider.h"
#include "chrome/browser/chromeos/dbus/vm_applications_service_provider.h"
#include "chrome/browser/chromeos/display/quirks_manager_delegate_impl.h"
......@@ -315,6 +316,12 @@ class DBusServices {
CrosDBusService::CreateServiceProviderList(
std::make_unique<CryptohomeKeyDelegateServiceProvider>()));
smb_fs_service_ =
CrosDBusService::Create(system_bus, smbfs::kSmbFsServiceName,
dbus::ObjectPath(smbfs::kSmbFsServicePath),
CrosDBusService::CreateServiceProviderList(
std::make_unique<SmbFsServiceProvider>()));
if (arc::IsArcVmEnabled()) {
libvda_service_ = CrosDBusService::Create(
system_bus, libvda::kLibvdaServiceName,
......@@ -401,6 +408,7 @@ class DBusServices {
std::unique_ptr<CrosDBusService> cryptohome_key_delegate_service_;
std::unique_ptr<CrosDBusService> libvda_service_;
std::unique_ptr<CrosDBusService> machine_learning_decision_service_;
std::unique_ptr<CrosDBusService> smb_fs_service_;
DISALLOW_COPY_AND_ASSIGN(DBusServices);
};
......
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<!--
Copyright 2019 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.
-->
<busconfig>
<policy user="chronos">
<allow own="org.chromium.SmbFs"/>
</policy>
<policy user="fuse-smbfs">
<allow send_destination="org.chromium.SmbFs"
send_interface="org.chromium.SmbFs"/>
</policy>
</busconfig>
// Copyright 2019 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 "chrome/browser/chromeos/dbus/smb_fs_service_provider.h"
#include <string>
#include <utility>
#include "base/bind.h"
#include "base/files/scoped_file.h"
#include "base/logging.h"
#include "chromeos/components/mojo_bootstrap/pending_connection_manager.h"
#include "dbus/message.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
namespace chromeos {
SmbFsServiceProvider::SmbFsServiceProvider() = default;
SmbFsServiceProvider::~SmbFsServiceProvider() = default;
void SmbFsServiceProvider::Start(
scoped_refptr<dbus::ExportedObject> exported_object) {
exported_object->ExportMethod(
smbfs::kSmbFsInterface, smbfs::kOpenIpcChannelMethod,
base::BindRepeating(&SmbFsServiceProvider::HandleOpenIpcChannel,
weak_ptr_factory_.GetWeakPtr()),
base::BindRepeating([](const std::string& interface_name,
const std::string& method_name, bool success) {
LOG_IF(ERROR, !success)
<< "Failed to export " << interface_name << "." << method_name;
}));
}
void SmbFsServiceProvider::HandleOpenIpcChannel(
dbus::MethodCall* method_call,
dbus::ExportedObject::ResponseSender response_sender) {
std::string id;
base::ScopedFD fd;
dbus::MessageReader reader(method_call);
if (!reader.PopString(&id)) {
response_sender.Run(dbus::ErrorResponse::FromMethodCall(
method_call, DBUS_ERROR_INVALID_ARGS, "First argument is not string."));
return;
}
if (!reader.PopFileDescriptor(&fd)) {
response_sender.Run(dbus::ErrorResponse::FromMethodCall(
method_call, DBUS_ERROR_INVALID_ARGS, "Second argument is not FD."));
return;
}
if (!mojo_bootstrap::PendingConnectionManager::Get().OpenIpcChannel(
id, std::move(fd))) {
response_sender.Run(dbus::ErrorResponse::FromMethodCall(
method_call, DBUS_ERROR_FAILED, "Failed to open IPC"));
return;
}
response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
} // namespace chromeos
// Copyright 2019 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 CHROME_BROWSER_CHROMEOS_DBUS_SMB_FS_SERVICE_PROVIDER_H_
#define CHROME_BROWSER_CHROMEOS_DBUS_SMB_FS_SERVICE_PROVIDER_H_
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "chromeos/dbus/services/cros_dbus_service.h"
#include "dbus/exported_object.h"
namespace dbus {
class MethodCall;
}
namespace chromeos {
// SmbFsServiceProvider exposes a D-Bus method which is used by instances of
// SmbFs to bootstrap a Mojo IPC connection. The method by which SmbFs is
// started cannot be passed a file descriptor, therefore this D-Bus method is
// used to asynchronously associate a FD with an identified SmbFs instance.
class SmbFsServiceProvider : public CrosDBusService::ServiceProviderInterface {
public:
SmbFsServiceProvider();
~SmbFsServiceProvider() override;
// CrosDBusService::ServiceProviderInterface overrides:
void Start(scoped_refptr<dbus::ExportedObject> exported_object) override;
private:
// Handler for the OpenIpcChannel() D-Bus method.
void HandleOpenIpcChannel(
dbus::MethodCall* method_call,
dbus::ExportedObject::ResponseSender response_sender);
base::WeakPtrFactory<SmbFsServiceProvider> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(SmbFsServiceProvider);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_DBUS_SMB_FS_SERVICE_PROVIDER_H_
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