blob: bae1e1ba9d1ced8e52547479333fcf79774986ab [file] [log] [blame]
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -05001// 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
7namespace debugd {
8
9SandboxedProcess::SandboxedProcess()
10 : sandboxing_(true), user_("debugd"), group_("debugd") { }
11SandboxedProcess::~SandboxedProcess() { }
12
13bool 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-Jonesec8d7622013-01-22 11:35:22 -050023 AddArg("--");
Elly Fong-Jonesd9a16cd2012-11-12 16:09:49 -050024 }
25 return true;
26}
27
28void SandboxedProcess::DisableSandbox() {
29 sandboxing_ = false;
30}
31
32void 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