blob: 0df119e804d20b9bcda93ba620c5626335cf1229 [file] [log] [blame]
Elly Jonescd7a9042011-07-22 13:56:51 -04001/* Copyright (c) 2011 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/* The general pattern of use here:
6 * 1) Construct a minijail with minijail_new()
7 * 2) Apply the desired restrictions to it
8 * 3) Enter it, which locks the current process inside it, or:
9 * 3) Run a process inside it
10 * 4) Destroy it.
11 */
12
13#ifndef LIBMINIJAIL_H_
14#define LIBMINIJAIL_H_
15
16#include <stdint.h>
17#include <sys/types.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23enum {
24 MINIJAIL_ERR_PRELOAD = 252,
25 MINIJAIL_ERR_JAIL = 253,
26 MINIJAIL_ERR_INIT = 254,
27};
28
29struct minijail;
30
31/* Allocates a new minijail with no restrictions. */
32struct minijail *minijail_new(void);
33
34/* These functions add restrictions to the minijail. They are not applied until
35 * minijail_enter() is called. See the documentation in minijail0.1 for
36 * explanations in detail of what the restrictions do. */
37void minijail_change_uid(struct minijail *j, uid_t uid);
38void minijail_change_gid(struct minijail *j, gid_t gid);
39/* 'user' should be kept valid until minijail_destroy() */
40int minijail_change_user(struct minijail *j, const char *user);
41/* 'group' should be kept valid until minijail_destroy() */
42int minijail_change_group(struct minijail *j, const char *group);
43void minijail_use_seccomp(struct minijail *j);
44void minijail_use_caps(struct minijail *j, uint64_t capmask);
45void minijail_namespace_vfs(struct minijail *j);
46void minijail_namespace_pids(struct minijail *j);
47void minijail_remount_readonly(struct minijail *j);
48void minijail_inherit_usergroups(struct minijail *j);
49void minijail_disable_ptrace(struct minijail *j);
50
51/* Lock this process into the given minijail. Note that this procedure cannot fail,
52 * since there is no way to undo privilege-dropping; therefore, if any part of
53 * the privilege-drop fails, minijail_enter() will abort the entire process.
54 *
55 * Some restrictions cannot be enabled this way (pid namespaces) and attempting
56 * to do so will cause an abort.
57 */
58void minijail_enter(const struct minijail *j);
59
60/* Run the specified command in the given minijail, execve(3)-style. This is
61 * required if minijail_namespace_pids() was used. */
62int minijail_run(struct minijail *j, const char *filename, char *const argv[]);
63
64/* Kill the specified minijail. The minijail must have been created with pid
65 * namespacing; if it was, all processes inside it are atomically killed. */
66int minijail_kill(struct minijail *j);
67
68/* Wait for all processed in the specified minijail to exit. Returns the exit
69 * status of the _first_ process spawned in the jail. */
70int minijail_wait(struct minijail *j);
71
72/* Frees the given minijail. It does not matter if the process is inside the minijail or
73 * not. */
74void minijail_destroy(struct minijail *j);
75
76#ifdef __cplusplus
77}; /* extern "C" */
78#endif
79
80#endif /* !LIBMINIJAIL_H_ */