Jorge Lucangeli Obes | ad43cc6 | 2012-04-11 16:25:43 -0700 | [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 | #ifndef SHILL_MINIJAIL_H_ |
| 6 | #define SHILL_MINIJAIL_H_ |
| 7 | |
| 8 | #include <vector> |
| 9 | |
| 10 | extern "C" { |
| 11 | #include <linux/capability.h> |
| 12 | } |
| 13 | |
| 14 | #include <base/lazy_instance.h> |
| 15 | #include <chromeos/libminijail.h> |
| 16 | |
| 17 | namespace shill { |
| 18 | |
| 19 | // A Minijail abstraction allowing Minijail mocking in tests. |
| 20 | class Minijail { |
| 21 | public: |
| 22 | virtual ~Minijail(); |
| 23 | |
mukesh agrawal | f407d59 | 2013-07-31 11:37:57 -0700 | [diff] [blame] | 24 | // This is a singleton -- use Minijail::GetInstance()->Foo(). |
Jorge Lucangeli Obes | ad43cc6 | 2012-04-11 16:25:43 -0700 | [diff] [blame] | 25 | static Minijail *GetInstance(); |
| 26 | |
| 27 | // minijail_new |
| 28 | virtual struct minijail *New(); |
| 29 | // minijail_destroy |
| 30 | virtual void Destroy(struct minijail *jail); |
| 31 | |
| 32 | // minijail_change_user/minijail_change_group |
| 33 | virtual bool DropRoot(struct minijail *jail, const char *user); |
| 34 | // minijail_use_caps |
| 35 | virtual void UseCapabilities(struct minijail *jail, uint64_t capmask); |
| 36 | |
| 37 | // minijail_run_pid |
| 38 | virtual bool Run(struct minijail *jail, std::vector<char *> args, pid_t *pid); |
| 39 | |
Jorge Lucangeli Obes | ccd5c85 | 2012-12-19 18:08:40 -0800 | [diff] [blame] | 40 | // minijail_run_pid and waitpid |
| 41 | virtual bool RunSync(struct minijail *jail, std::vector<char *> args, |
| 42 | int *status); |
| 43 | |
Jorge Lucangeli Obes | 8c1706f | 2012-08-30 15:30:48 -0700 | [diff] [blame] | 44 | // minijail_run_pid_pipe |
| 45 | virtual bool RunPipe(struct minijail *jail, std::vector<char *> args, |
| 46 | pid_t *pid, int *stdin); |
| 47 | |
Christopher Wiley | 8fa357c | 2013-02-21 11:35:58 -0800 | [diff] [blame] | 48 | // minijail_run_pid_pipes |
| 49 | virtual bool RunPipes(struct minijail *jail, std::vector<char *> args, |
| 50 | pid_t *pid, int *stdin, int *stdout, int *stderr); |
| 51 | |
Jorge Lucangeli Obes | ad43cc6 | 2012-04-11 16:25:43 -0700 | [diff] [blame] | 52 | // Run() and Destroy() |
| 53 | virtual bool RunAndDestroy(struct minijail *jail, |
| 54 | std::vector<char *> args, |
| 55 | pid_t *pid); |
| 56 | |
Jorge Lucangeli Obes | ccd5c85 | 2012-12-19 18:08:40 -0800 | [diff] [blame] | 57 | // RunSync() and Destroy() |
| 58 | virtual bool RunSyncAndDestroy(struct minijail *jail, |
| 59 | std::vector<char *> args, |
| 60 | int *status); |
| 61 | |
Jorge Lucangeli Obes | 8c1706f | 2012-08-30 15:30:48 -0700 | [diff] [blame] | 62 | // RunPipe() and Destroy() |
| 63 | virtual bool RunPipeAndDestroy(struct minijail *jail, |
| 64 | std::vector<char *> args, |
| 65 | pid_t *pid, int *stdin); |
| 66 | |
Christopher Wiley | 8fa357c | 2013-02-21 11:35:58 -0800 | [diff] [blame] | 67 | // RunPipes() and Destroy() |
| 68 | virtual bool RunPipesAndDestroy(struct minijail *jail, |
| 69 | std::vector<char *> args, |
| 70 | pid_t *pid, int *stdin, |
| 71 | int *stdout, int *stderr); |
Jorge Lucangeli Obes | ad43cc6 | 2012-04-11 16:25:43 -0700 | [diff] [blame] | 72 | protected: |
| 73 | Minijail(); |
| 74 | |
| 75 | private: |
| 76 | friend struct base::DefaultLazyInstanceTraits<Minijail>; |
| 77 | |
| 78 | DISALLOW_COPY_AND_ASSIGN(Minijail); |
| 79 | }; |
| 80 | |
| 81 | } // namespace shill |
| 82 | |
| 83 | #endif // SHILL_MINIJAIL_H_ |