| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef SANDBOX_MAC_LAUNCHD_INTERCEPTION_SERVER_H_ | 5 #ifndef SANDBOX_MAC_LAUNCHD_INTERCEPTION_SERVER_H_ |
| 6 #define SANDBOX_MAC_LAUNCHD_INTERCEPTION_SERVER_H_ | 6 #define SANDBOX_MAC_LAUNCHD_INTERCEPTION_SERVER_H_ |
| 7 | 7 |
| 8 #include <dispatch/dispatch.h> | 8 #include <dispatch/dispatch.h> |
| 9 | 9 |
| 10 #include "base/mac/scoped_mach_port.h" | 10 #include "base/mac/scoped_mach_port.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "sandbox/mac/message_server.h" | 12 #include "sandbox/mac/message_server.h" |
| 13 #include "sandbox/mac/os_compatibility.h" | 13 #include "sandbox/mac/os_compatibility.h" |
| 14 | 14 |
| 15 namespace sandbox { | 15 namespace sandbox { |
| 16 | 16 |
| 17 class BootstrapSandbox; | 17 class BootstrapSandbox; |
| 18 struct BootstrapSandboxPolicy; | 18 struct BootstrapSandboxPolicy; |
| 19 | 19 |
| 20 // This class is used to run a Mach IPC message server. This server can | 20 // This class is used to run a Mach IPC message server. This server can |
| 21 // hold the receive right for a bootstrap_port of a process, and it filters | 21 // hold the receive right for a bootstrap_port of a process, and it filters |
| 22 // a subset of the launchd/bootstrap IPC call set for sandboxing. It permits | 22 // a subset of the launchd/bootstrap IPC call set for sandboxing. It permits |
| 23 // or rejects requests based on the per-process policy specified in the | 23 // or rejects requests based on the per-process policy specified in the |
| 24 // BootstrapSandbox. | 24 // BootstrapSandbox. |
| 25 class LaunchdInterceptionServer : public MessageDemuxer { | 25 class LaunchdInterceptionServer : public MessageDemuxer { |
| 26 public: | 26 public: |
| 27 explicit LaunchdInterceptionServer(const BootstrapSandbox* sandbox); | 27 explicit LaunchdInterceptionServer(const BootstrapSandbox* sandbox); |
| 28 virtual ~LaunchdInterceptionServer(); | 28 ~LaunchdInterceptionServer() override; |
| 29 | 29 |
| 30 // Initializes the class and starts running the message server. If the | 30 // Initializes the class and starts running the message server. If the |
| 31 // |server_receive_right| is non-NULL, this class will take ownership of | 31 // |server_receive_right| is non-NULL, this class will take ownership of |
| 32 // the receive right and intercept messages sent to that port. | 32 // the receive right and intercept messages sent to that port. |
| 33 bool Initialize(mach_port_t server_receive_right); | 33 bool Initialize(mach_port_t server_receive_right); |
| 34 | 34 |
| 35 // MessageDemuxer: | 35 // MessageDemuxer: |
| 36 virtual void DemuxMessage(IPCMessage request) override; | 36 void DemuxMessage(IPCMessage request) override; |
| 37 | 37 |
| 38 mach_port_t server_port() const { return message_server_->GetServerPort(); } | 38 mach_port_t server_port() const { return message_server_->GetServerPort(); } |
| 39 | 39 |
| 40 private: | 40 private: |
| 41 // Given a look_up2 request message, this looks up the appropriate sandbox | 41 // Given a look_up2 request message, this looks up the appropriate sandbox |
| 42 // policy for the service name then formulates and sends the reply message. | 42 // policy for the service name then formulates and sends the reply message. |
| 43 void HandleLookUp(IPCMessage request, const BootstrapSandboxPolicy* policy); | 43 void HandleLookUp(IPCMessage request, const BootstrapSandboxPolicy* policy); |
| 44 | 44 |
| 45 // Given a swap_integer request message, this verifies that it is safe, and | 45 // Given a swap_integer request message, this verifies that it is safe, and |
| 46 // if so, forwards it on to launchd for servicing. If the request is unsafe, | 46 // if so, forwards it on to launchd for servicing. If the request is unsafe, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 64 base::mac::ScopedMachSendRight sandbox_send_port_; | 64 base::mac::ScopedMachSendRight sandbox_send_port_; |
| 65 | 65 |
| 66 // The compatibility shim that handles differences in message header IDs and | 66 // The compatibility shim that handles differences in message header IDs and |
| 67 // request/reply structures between different OS X versions. | 67 // request/reply structures between different OS X versions. |
| 68 const LaunchdCompatibilityShim compat_shim_; | 68 const LaunchdCompatibilityShim compat_shim_; |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 } // namespace sandbox | 71 } // namespace sandbox |
| 72 | 72 |
| 73 #endif // SANDBOX_MAC_LAUNCHD_INTERCEPTION_SERVER_H_ | 73 #endif // SANDBOX_MAC_LAUNCHD_INTERCEPTION_SERVER_H_ |
| OLD | NEW |