Add basic pledge/unveil sandbox on OpenBSD
[tinc] / src / bsd / openbsd / sandbox.h
1 #ifndef TINC_BSD_OPENBSD_SANDBOX_H
2 #define TINC_BSD_OPENBSD_SANDBOX_H
3
4 #include "../../system.h"
5
6 typedef struct unveil_path_t {
7         const char *path;
8         const char *priv;
9 } unveil_path_t;
10
11 // No restrictions
12 static const char *PROMISES_ALL = NULL;
13
14 // Full restrictions; children can call nothing but exit()
15 static const char *PROMISES_NONE = "";
16
17 // Allow access to the paths with the specified privileges. Can be called multiple times.
18 // This is a thin logging wrapper around unveil(2).
19 // Paths that are equal to NULL are skipped. The last path in the array must be (NULL, NULL).
20 // Note that after the last call to this function you should lock access to
21 // unveil(2) using pledge(2) to prevent the program from undoing the sandbox.
22 extern void allow_paths(const unveil_path_t paths[]);
23
24 // Allow access to a single path. Logging wrapper around unveil().
25 extern void allow_path(const char *path, const char *priv);
26
27 // Restrict privileges. Can be called multiple times to further restrict (but not regain) them.
28 // It's a thin logging wrapper around unveil(2), see man page for details.
29 extern bool restrict_privs(const char *promises, const char *execpromises);
30
31 #endif // TINC_BSD_OPENBSD_SANDBOX_H