Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 1 | // Copyright 2020 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | #ifndef SYSTEM_PROXY_SANDBOXED_WORKER_H_ |
| 5 | #define SYSTEM_PROXY_SANDBOXED_WORKER_H_ |
| 6 | |
| 7 | #include <array> |
| 8 | #include <memory> |
| 9 | #include <string> |
| 10 | |
| 11 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 12 | |
| 13 | #include <base/files/file_descriptor_watcher_posix.h> |
| 14 | #include <base/files/scoped_file.h> |
| 15 | #include <chromeos/scoped_minijail.h> |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 16 | |
| 17 | namespace system_proxy { |
| 18 | |
| 19 | class SandboxedWorker { |
| 20 | public: |
| 21 | SandboxedWorker(); |
| 22 | SandboxedWorker(const SandboxedWorker&) = delete; |
| 23 | SandboxedWorker& operator=(const SandboxedWorker&) = delete; |
| 24 | virtual ~SandboxedWorker() = default; |
| 25 | |
| 26 | // Starts a sandboxed worker with pipes. |
| 27 | virtual void Start(); |
Andreea Costinas | 41e0644 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 28 | // Sends the username and password to the worker via communication pipes. |
| 29 | void SetUsernameAndPassword(const std::string& username, |
| 30 | const std::string& password); |
| 31 | // Sends the listening address and port to the worker via communication |
| 32 | // pipes. |
| 33 | void SetListeningAddress(uint32_t addr, int port); |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 34 | |
| 35 | // Terminates the child process by sending a SIGTERM signal. |
| 36 | virtual bool Stop(); |
| 37 | |
| 38 | virtual bool IsRunning(); |
| 39 | |
| 40 | pid_t pid() { return pid_; } |
| 41 | |
| 42 | private: |
Andreea Costinas | 41e0644 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 43 | friend class SystemProxyAdaptorTest; |
| 44 | FRIEND_TEST(SystemProxyAdaptorTest, SetSystemTrafficCredentials); |
| 45 | |
Andreea Costinas | c7d5ad0 | 2020-03-09 09:41:51 +0100 | [diff] [blame] | 46 | void OnMessageReceived(); |
| 47 | void OnErrorReceived(); |
| 48 | |
| 49 | bool is_being_terminated_ = false; |
| 50 | ScopedMinijail jail_; |
| 51 | base::ScopedFD stdin_pipe_; |
| 52 | base::ScopedFD stdout_pipe_; |
| 53 | base::ScopedFD stderr_pipe_; |
| 54 | |
| 55 | std::unique_ptr<base::FileDescriptorWatcher::Controller> stdout_watcher_; |
| 56 | std::unique_ptr<base::FileDescriptorWatcher::Controller> stderr_watcher_; |
| 57 | |
| 58 | pid_t pid_; |
| 59 | }; |
| 60 | |
| 61 | } // namespace system_proxy |
| 62 | |
| 63 | #endif // SYSTEM_PROXY_SANDBOXED_WORKER_H_ |