Remove unused function: dns_randfn_() in dns.c.
[tor.git] / src / lib / sandbox / sandbox.h
blob5bec09a36a2f5665608d7edca70d0904f504e2cc
1 /* Copyright (c) 2001 Matej Pfajfar.
2 * Copyright (c) 2001-2004, Roger Dingledine.
3 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4 * Copyright (c) 2007-2019, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
7 /**
8 * \file sandbox.h
9 * \brief Header file for sandbox.c.
10 **/
12 #ifndef SANDBOX_H_
13 #define SANDBOX_H_
15 #include "orconfig.h"
16 #include "lib/cc/torint.h"
18 #ifndef SYS_SECCOMP
20 /**
21 * Used by SIGSYS signal handler to check if the signal was issued due to a
22 * seccomp2 filter violation.
24 #define SYS_SECCOMP 1
26 #endif /* !defined(SYS_SECCOMP) */
28 #if defined(HAVE_SECCOMP_H) && defined(__linux__)
29 #define USE_LIBSECCOMP
30 #endif
32 struct sandbox_cfg_elem;
34 /** Typedef to structure used to manage a sandbox configuration. */
35 typedef struct sandbox_cfg_elem sandbox_cfg_t;
37 /**
38 * Linux definitions
40 #ifdef USE_LIBSECCOMP
42 #include <sys/ucontext.h>
43 #include <seccomp.h>
44 #include <netdb.h>
46 #define PARAM_PTR 0
47 #define PARAM_NUM 1
49 /**
50 * Enum used to manage the type of the implementation for general purpose.
52 typedef enum {
53 /** Libseccomp implementation based on seccomp2*/
54 LIBSECCOMP2 = 0
55 } SB_IMPL;
57 /**
58 * Configuration parameter structure associated with the LIBSECCOMP2
59 * implementation.
61 typedef struct smp_param {
62 /** syscall associated with parameter. */
63 int syscall;
65 /** parameter value. */
66 char *value;
67 /** parameter value, second argument. */
68 char *value2;
70 /** parameter flag (0 = not protected, 1 = protected). */
71 int prot;
72 } smp_param_t;
74 /**
75 * Structure used to manage a sandbox configuration.
77 * It is implemented as a linked list of parameters. Currently only controls
78 * parameters for open, openat, execve, stat64.
80 struct sandbox_cfg_elem {
81 /** Sandbox implementation which dictates the parameter type. */
82 SB_IMPL implem;
84 /** Configuration parameter. */
85 smp_param_t *param;
87 /** Next element of the configuration*/
88 struct sandbox_cfg_elem *next;
91 /** Function pointer defining the prototype of a filter function.*/
92 typedef int (*sandbox_filter_func_t)(scmp_filter_ctx ctx,
93 sandbox_cfg_t *filter);
95 /** Type that will be used in step 3 in order to manage multiple sandboxes.*/
96 typedef struct {
97 /** function pointers associated with the filter */
98 sandbox_filter_func_t *filter_func;
100 /** filter function pointer parameters */
101 sandbox_cfg_t *filter_dynamic;
102 } sandbox_t;
104 #endif /* defined(USE_LIBSECCOMP) */
106 #ifdef USE_LIBSECCOMP
107 /** Returns a registered protected string used with the sandbox, given that
108 * it matches the parameter.
110 const char* sandbox_intern_string(const char *param);
111 #else /* !(defined(USE_LIBSECCOMP)) */
112 #define sandbox_intern_string(s) (s)
113 #endif /* defined(USE_LIBSECCOMP) */
115 /** Creates an empty sandbox configuration file.*/
116 sandbox_cfg_t * sandbox_cfg_new(void);
119 * Function used to add a open allowed filename to a supplied configuration.
120 * The (char*) specifies the path to the allowed file; we take ownership
121 * of the pointer.
123 int sandbox_cfg_allow_open_filename(sandbox_cfg_t **cfg, char *file);
125 int sandbox_cfg_allow_chmod_filename(sandbox_cfg_t **cfg, char *file);
126 int sandbox_cfg_allow_chown_filename(sandbox_cfg_t **cfg, char *file);
128 /* DOCDOC */
129 int sandbox_cfg_allow_rename(sandbox_cfg_t **cfg, char *file1, char *file2);
132 * Function used to add a openat allowed filename to a supplied configuration.
133 * The (char*) specifies the path to the allowed file; we steal the pointer to
134 * that file.
136 int sandbox_cfg_allow_openat_filename(sandbox_cfg_t **cfg, char *file);
139 * Function used to add a stat/stat64 allowed filename to a configuration.
140 * The (char*) specifies the path to the allowed file; that pointer is stolen.
142 int sandbox_cfg_allow_stat_filename(sandbox_cfg_t **cfg, char *file);
144 /** Function used to initialise a sandbox configuration.*/
145 int sandbox_init(sandbox_cfg_t* cfg);
147 /** Return true iff the sandbox is turned on. */
148 int sandbox_is_active(void);
150 #endif /* !defined(SANDBOX_H_) */