Elly Fong-Jones | d9a16cd | 2012-11-12 16:09:49 -0500 | [diff] [blame] | 1 | // Copyright (c) 2012 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 | |
| 5 | #include "sandboxed_process.h" |
| 6 | |
| 7 | namespace debugd { |
| 8 | |
| 9 | SandboxedProcess::SandboxedProcess() |
| 10 | : sandboxing_(true), user_("debugd"), group_("debugd") { } |
| 11 | SandboxedProcess::~SandboxedProcess() { } |
| 12 | |
| 13 | bool SandboxedProcess::Init() { |
| 14 | const char *kMiniJail = "/sbin/minijail0"; |
| 15 | if (sandboxing_) { |
| 16 | if (user_.empty() || group_.empty()) |
| 17 | return false; |
| 18 | AddArg(kMiniJail); |
| 19 | AddArg("-u"); |
| 20 | AddArg(user_); |
| 21 | AddArg("-g"); |
| 22 | AddArg(group_); |
Elly Fong-Jones | ec8d762 | 2013-01-22 11:35:22 -0500 | [diff] [blame] | 23 | AddArg("--"); |
Elly Fong-Jones | d9a16cd | 2012-11-12 16:09:49 -0500 | [diff] [blame] | 24 | } |
| 25 | return true; |
| 26 | } |
| 27 | |
| 28 | void SandboxedProcess::DisableSandbox() { |
| 29 | sandboxing_ = false; |
| 30 | } |
| 31 | |
| 32 | void SandboxedProcess::SandboxAs(const std::string& user, |
| 33 | const std::string& group) { |
| 34 | sandboxing_ = true; |
| 35 | user_ = user; |
| 36 | group_ = group; |
| 37 | } |
| 38 | |
| 39 | }; // namespace debugd |