blob: 285a489245cfa08efe76392c5038c1ea02c86a8f [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_);
23 }
24 return true;
25}
26
27void SandboxedProcess::DisableSandbox() {
28 sandboxing_ = false;
29}
30
31void SandboxedProcess::SandboxAs(const std::string& user,
32 const std::string& group) {
33 sandboxing_ = true;
34 user_ = user;
35 group_ = group;
36}
37
38}; // namespace debugd