Mike Frysinger | 50e31fa | 2018-01-19 18:59:49 -0500 | [diff] [blame] | 1 | /* 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 Obes | 0b20877 | 2017-04-19 14:15:46 -0400 | [diff] [blame] | 4 | * |
| 5 | * Wrappers for system functionality. |
| 6 | */ |
| 7 | |
| 8 | #ifndef _SYSTEM_H_ |
| 9 | #define _SYSTEM_H_ |
| 10 | |
Mike Frysinger | eaab420 | 2017-08-14 14:57:21 -0400 | [diff] [blame] | 11 | #include <stdbool.h> |
Jorge Lucangeli Obes | a6eb21a | 2017-04-20 10:44:00 -0400 | [diff] [blame] | 12 | #include <sys/capability.h> |
| 13 | #include <sys/prctl.h> |
Jorge Lucangeli Obes | 0b20877 | 2017-04-19 14:15:46 -0400 | [diff] [blame] | 14 | #include <sys/types.h> |
| 15 | |
| 16 | #ifdef __cplusplus |
| 17 | extern "C" { |
| 18 | #endif |
| 19 | |
Jorge Lucangeli Obes | a6eb21a | 2017-04-20 10:44:00 -0400 | [diff] [blame] | 20 | /* 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 Chavez | 89cbc32 | 2018-08-06 11:31:15 -0700 | [diff] [blame] | 41 | int secure_keep_caps_locked(void); |
Jorge Lucangeli Obes | 5423421 | 2018-04-26 11:52:15 -0400 | [diff] [blame] | 42 | int secure_noroot_set_and_locked(uint64_t mask); |
Luis Hector Chavez | ec0a2c1 | 2017-06-29 20:29:57 -0700 | [diff] [blame] | 43 | int lock_securebits(uint64_t skip_mask); |
Jorge Lucangeli Obes | 0b20877 | 2017-04-19 14:15:46 -0400 | [diff] [blame] | 44 | |
| 45 | unsigned int get_last_valid_cap(void); |
Jorge Lucangeli Obes | a6eb21a | 2017-04-20 10:44:00 -0400 | [diff] [blame] | 46 | int cap_ambient_supported(void); |
Jorge Lucangeli Obes | 0b20877 | 2017-04-19 14:15:46 -0400 | [diff] [blame] | 47 | |
| 48 | int config_net_loopback(void); |
| 49 | |
| 50 | int setup_pipe_end(int fds[2], size_t index); |
| 51 | int setup_and_dupe_pipe_end(int fds[2], size_t index, int fd); |
| 52 | |
| 53 | int write_pid_to_path(pid_t pid, const char *path); |
| 54 | int write_proc_file(pid_t pid, const char *content, const char *basename); |
| 55 | |
Mike Frysinger | 5fdba4e | 2018-01-17 15:39:48 -0500 | [diff] [blame] | 56 | int mkdir_p(const char *path, mode_t mode, bool isdir); |
| 57 | |
Jorge Lucangeli Obes | 0b20877 | 2017-04-19 14:15:46 -0400 | [diff] [blame] | 58 | int setup_mount_destination(const char *source, const char *dest, uid_t uid, |
Luis Hector Chavez | 0bacbf8 | 2018-07-10 20:06:55 -0700 | [diff] [blame] | 59 | uid_t gid, bool bind, unsigned long *mnt_flags); |
Jorge Lucangeli Obes | 0b20877 | 2017-04-19 14:15:46 -0400 | [diff] [blame] | 60 | |
Luis Hector Chavez | 7132355 | 2017-09-05 09:17:22 -0700 | [diff] [blame] | 61 | int lookup_user(const char *user, uid_t *uid, gid_t *gid); |
| 62 | int lookup_group(const char *group, gid_t *gid); |
| 63 | |
Jorge Lucangeli Obes | 0b20877 | 2017-04-19 14:15:46 -0400 | [diff] [blame] | 64 | #ifdef __cplusplus |
| 65 | }; /* extern "C" */ |
| 66 | #endif |
| 67 | |
| 68 | #endif /* _SYSTEM_H_ */ |