blob: b816f5f7921ab28ec0c9b8ee1f3e162db7146a72 [file] [log] [blame]
Mike Frysinger50e31fa2018-01-19 18:59:49 -05001/* Copyright 2017 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.
Jorge Lucangeli Obes0b208772017-04-19 14:15:46 -04004 *
5 * Wrappers for system functionality.
6 */
7
8#ifndef _SYSTEM_H_
9#define _SYSTEM_H_
10
Mike Frysingereaab4202017-08-14 14:57:21 -040011#include <stdbool.h>
Jorge Lucangeli Obesa6eb21a2017-04-20 10:44:00 -040012#include <sys/capability.h>
13#include <sys/prctl.h>
Jorge Lucangeli Obes0b208772017-04-19 14:15:46 -040014#include <sys/types.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
Jorge Lucangeli Obesa6eb21a2017-04-20 10:44:00 -040020/* Control the ambient capability set. */
21#ifndef PR_CAP_AMBIENT
22#define PR_CAP_AMBIENT 47
23#endif
24
25#ifndef PR_CAP_AMBIENT_IS_SET
26#define PR_CAP_AMBIENT_IS_SET 1
27#endif
28
29#ifndef PR_CAP_AMBIENT_RAISE
30#define PR_CAP_AMBIENT_RAISE 2
31#endif
32
33#ifndef PR_CAP_AMBIENT_LOWER
34#define PR_CAP_AMBIENT_LOWER 3
35#endif
36
37#ifndef PR_CAP_AMBIENT_CLEAR_ALL
38#define PR_CAP_AMBIENT_CLEAR_ALL 4
39#endif
40
Luis Hector Chavezec0a2c12017-06-29 20:29:57 -070041int lock_securebits(uint64_t skip_mask);
Jorge Lucangeli Obes0b208772017-04-19 14:15:46 -040042
43unsigned int get_last_valid_cap(void);
Jorge Lucangeli Obesa6eb21a2017-04-20 10:44:00 -040044int cap_ambient_supported(void);
Jorge Lucangeli Obes0b208772017-04-19 14:15:46 -040045
46int config_net_loopback(void);
47
48int setup_pipe_end(int fds[2], size_t index);
49int setup_and_dupe_pipe_end(int fds[2], size_t index, int fd);
50
51int write_pid_to_path(pid_t pid, const char *path);
52int write_proc_file(pid_t pid, const char *content, const char *basename);
53
Mike Frysinger5fdba4e2018-01-17 15:39:48 -050054int mkdir_p(const char *path, mode_t mode, bool isdir);
55
Jorge Lucangeli Obes0b208772017-04-19 14:15:46 -040056int setup_mount_destination(const char *source, const char *dest, uid_t uid,
Mike Frysingereaab4202017-08-14 14:57:21 -040057 uid_t gid, bool bind);
Jorge Lucangeli Obes0b208772017-04-19 14:15:46 -040058
Luis Hector Chavez71323552017-09-05 09:17:22 -070059int lookup_user(const char *user, uid_t *uid, gid_t *gid);
60int lookup_group(const char *group, gid_t *gid);
61
Jorge Lucangeli Obes0b208772017-04-19 14:15:46 -040062#ifdef __cplusplus
63}; /* extern "C" */
64#endif
65
66#endif /* _SYSTEM_H_ */