Commit d3e1b119 authored by Lambros Lambrou's avatar Lambros Lambrou Committed by Commit Bot

Implement PermissionWizard checker

This is a reland of
https://chromium-review.googlesource.com/c/chromium/src/+/1903934
with missing deps added.

This adds a PermissionWizard::Delegate implementation which runs the
Me2Me or IT2Me binary with a command-line for checking permissions.

This can be used to create a PermissionWizard which checks the
permissions on either the ME2ME or IT2ME host.

TBR=garykac@chromium.org

Bug: 1015201
Change-Id: Ie704ff1a7c6c90c33b614f042a19c81e9ad6e2d7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1912917Reviewed-by: default avatarLambros Lambrou <lambroslambrou@chromium.org>
Commit-Queue: Lambros Lambrou <lambroslambrou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714695}
parent a1849a11
...@@ -20,6 +20,24 @@ source_set("constants") { ...@@ -20,6 +20,24 @@ source_set("constants") {
] ]
} }
source_set("permission_checking") {
sources = [
"permission_checker.cc",
"permission_checker.h",
"permission_process_utils.cc",
"permission_process_utils.h",
"permission_utils.h",
"permission_utils.mm",
"permission_wizard.h",
"permission_wizard.mm",
]
deps = [
":constants",
"//remoting/resources",
]
}
executable("remoting_me2me_host_service") { executable("remoting_me2me_host_service") {
sources = [ sources = [
"host_service_main.cc", "host_service_main.cc",
...@@ -95,14 +113,8 @@ target("mac_app_bundle", "remoting_me2me_host") { ...@@ -95,14 +113,8 @@ target("mac_app_bundle", "remoting_me2me_host") {
# defines = [ "REMOTING_ENABLE_BREAKPAD" ] # defines = [ "REMOTING_ENABLE_BREAKPAD" ]
# } # }
sources = [
"permission_utils.h",
"permission_utils.mm",
"permission_wizard.h",
"permission_wizard.mm",
]
deps = [ deps = [
":permission_checking",
"//remoting/base:breakpad", "//remoting/base:breakpad",
"//remoting/host:main", "//remoting/host:main",
"//remoting/host:remoting_me2me_host_static", "//remoting/host:remoting_me2me_host_static",
......
// 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 "remoting/host/mac/permission_checker.h"
#include <utility>
#include "base/bind.h"
#include "base/task_runner_util.h"
#include "remoting/host/mac/permission_process_utils.h"
#include "remoting/host/version.h"
namespace remoting {
namespace mac {
PermissionChecker::PermissionChecker(
HostMode mode,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
: mode_(mode), io_task_runner_(io_task_runner) {}
PermissionChecker::~PermissionChecker() = default;
std::string PermissionChecker::GetBundleName() {
if (mode_ == HostMode::ME2ME) {
std::string host_bundle(HOST_BUNDLE_NAME);
// Strip off the ".app" suffix.
auto dot_position = host_bundle.rfind('.');
if (dot_position != std::string::npos) {
host_bundle = host_bundle.substr(0, dot_position);
}
return host_bundle;
}
return "remote_assistance_host";
}
void PermissionChecker::CheckAccessibilityPermission(
PermissionWizard::ResultCallback onResult) {
base::PostTaskAndReplyWithResult(
io_task_runner_.get(), FROM_HERE,
base::BindOnce(remoting::mac::CheckAccessibilityPermission, mode_),
std::move(onResult));
}
void PermissionChecker::CheckScreenRecordingPermission(
PermissionWizard::ResultCallback onResult) {
base::PostTaskAndReplyWithResult(
io_task_runner_.get(), FROM_HERE,
base::BindOnce(remoting::mac::CheckScreenRecordingPermission, mode_),
std::move(onResult));
}
} // namespace mac
} // namespace remoting
// 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 REMOTING_HOST_MAC_PERMISSION_CHECKER_H_
#define REMOTING_HOST_MAC_PERMISSION_CHECKER_H_
#include "remoting/host/mac/permission_wizard.h"
#include "base/single_thread_task_runner.h"
#include "remoting/host/mac/permission_process_utils.h"
namespace remoting {
namespace mac {
class PermissionChecker : public PermissionWizard::Delegate {
public:
PermissionChecker(HostMode mode,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner);
PermissionChecker(const PermissionChecker&) = delete;
PermissionChecker& operator=(const PermissionChecker&) = delete;
~PermissionChecker() override;
std::string GetBundleName() override;
void CheckAccessibilityPermission(
PermissionWizard::ResultCallback onResult) override;
void CheckScreenRecordingPermission(
PermissionWizard::ResultCallback onResult) override;
private:
HostMode mode_;
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
};
} // namespace mac
} // namespace remoting
#endif // REMOTING_HOST_MAC_PERMISSION_CHECKER_H_
// 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 "remoting/host/mac/permission_process_utils.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/process/launch.h"
#include "base/process/process.h"
#include "remoting/host/mac/constants_mac.h"
namespace remoting {
namespace mac {
namespace {
base::FilePath GetHostExePath(HostMode mode) {
// Path to the host bundle top directory.
base::FilePath host_path(kHostBinaryPath);
host_path = host_path.Append("Contents/MacOS");
if (mode == HostMode::ME2ME)
return host_path.Append("remoting_me2me_host");
return host_path.Append(
"RemoteAssistanceHost.app/Contents/MacOS/remote_assistance_host");
}
bool CheckHostPermission(base::FilePath exe_path, std::string command_switch) {
base::CommandLine cmdLine(exe_path);
cmdLine.AppendSwitch(command_switch);
base::LaunchOptions options;
options.disclaim_responsibility = true;
base::Process process = base::LaunchProcess(cmdLine, options);
if (!process.IsValid()) {
LOG(ERROR) << "Unable to launch host process";
return false;
}
int exit_code;
process.WaitForExit(&exit_code);
LOG(INFO) << "Permission '" << command_switch << "' is "
<< ((exit_code == 0) ? "granted" : "denied");
return exit_code == 0;
}
} // namespace
bool CheckAccessibilityPermission(HostMode mode) {
return CheckHostPermission(GetHostExePath(mode),
"check-accessibility-permission");
}
bool CheckScreenRecordingPermission(HostMode mode) {
return CheckHostPermission(GetHostExePath(mode),
"check-screen-recording-permission");
}
} // namespace mac
} // namespace remoting
// 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 REMOTING_HOST_MAC_PERMISSION_PROCESS_UTILS_H_
#define REMOTING_HOST_MAC_PERMISSION_PROCESS_UTILS_H_
// Utilities for doing permission-checks in a separate process from the
// ME2ME or IT2ME host binaries. These checks are carried out by running the
// relevant binary (the one that needs the permission) with a command-line
// option, and examining the returned exit-code.
namespace remoting {
namespace mac {
enum class HostMode { ME2ME, IT2ME };
// These methods must be called on a thread which allows blocking I/O.
bool CheckAccessibilityPermission(HostMode mode);
bool CheckScreenRecordingPermission(HostMode mode);
} // namespace mac
} // namespace remoting
#endif // REMOTING_HOST_MAC_PERMISSION_PROCESS_UTILS_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