blob: 5007981e271c86a1a9ac70d480750cdeaf15eebd [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 Chavez89cbc322018-08-06 11:31:15 -070041int secure_keep_caps_locked(void);
Jorge Lucangeli Obes54234212018-04-26 11:52:15 -040042int secure_noroot_set_and_locked(uint64_t mask);
Luis Hector Chavezec0a2c12017-06-29 20:29:57 -070043int lock_securebits(uint64_t skip_mask);
Jorge Lucangeli Obes0b208772017-04-19 14:15:46 -040044
45unsigned int get_last_valid_cap(void);
Jorge Lucangeli Obesa6eb21a2017-04-20 10:44:00 -040046int cap_ambient_supported(void);
Jorge Lucangeli Obes0b208772017-04-19 14:15:46 -040047
48int config_net_loopback(void);
49
50int setup_pipe_end(int fds[2], size_t index);
51int setup_and_dupe_pipe_end(int fds[2], size_t index, int fd);
52
53int write_pid_to_path(pid_t pid, const char *path);
54int write_proc_file(pid_t pid, const char *content, const char *basename);
55
Mike Frysinger5fdba4e2018-01-17 15:39:48 -050056int mkdir_p(const char *path, mode_t mode, bool isdir);
57
Jorge Lucangeli Obes0b208772017-04-19 14:15:46 -040058int setup_mount_destination(const char *source, const char *dest, uid_t uid,
Luis Hector Chavez0bacbf82018-07-10 20:06:55 -070059 uid_t gid, bool bind, unsigned long *mnt_flags);
Jorge Lucangeli Obes0b208772017-04-19 14:15:46 -040060
Luis Hector Chavez71323552017-09-05 09:17:22 -070061int lookup_user(const char *user, uid_t *uid, gid_t *gid);
62int lookup_group(const char *group, gid_t *gid);
63
Jorge Lucangeli Obes0b208772017-04-19 14:15:46 -040064#ifdef __cplusplus
65}; /* extern "C" */
66#endif
67
68#endif /* _SYSTEM_H_ */