aboutsummaryrefslogtreecommitdiffstats
path: root/src/firejail/firejail.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/firejail/firejail.h')
-rw-r--r--src/firejail/firejail.h354
1 files changed, 354 insertions, 0 deletions
diff --git a/src/firejail/firejail.h b/src/firejail/firejail.h
new file mode 100644
index 000000000..2ec6e54c9
--- /dev/null
+++ b/src/firejail/firejail.h
@@ -0,0 +1,354 @@
1/*
2 * Copyright (C) 2014, 2015 Firejail Authors
3 *
4 * This file is part of firejail project
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19*/
20#ifndef FIREJAIL_H
21#define FIREJAIL_H
22#include "../include/common.h"
23
24#define USELOCK
25#define FIREJAIL_DIR "/tmp/firejail"
26#define RO_DIR "/tmp/firejail/firejail.ro.dir"
27#define RO_FILE "/tmp/firejail/firejail.ro.file"
28#define MNT_DIR "/tmp/firejail/mnt"
29#define OVERLAY_DIR "/tmp/firejail/overlay"
30#define HOME_DIR "/tmp/firejail/mnt/home"
31#define MAX_INCLUDE_LEVEL 6
32
33// main.c
34typedef struct bridge_t {
35 // on the host
36 char *dev; // interface device name: bridge or regular ethernet
37 uint32_t ip; // interface device IP address
38 uint32_t mask; // interface device mask
39 uint8_t mac[6]; // interface mac address
40
41 // inside the sandbox
42 char *devsandbox; // name of the device inside the sandbox
43 uint32_t ipsandbox; // ip address inside the sandbox
44 uint8_t macsandbox[6]; // mac address inside the sandbox
45 uint32_t iprange_start;// iprange arp scan start range
46 uint32_t iprange_end; // iprange arp scan end range
47
48 // flags
49 uint8_t arg_ip_none; // --ip=none
50 uint8_t macvlan; // set by --net=eth0 (or eth1, ...); reset by --net=br0 (or br1, ...)
51 uint8_t configured;
52 uint8_t scan; // set by --scan
53} Bridge;
54
55typedef struct profile_entry_t {
56 struct profile_entry_t *next;
57 char *data;
58}ProfileEntry;
59
60typedef struct config_t {
61 // user data
62 char *username;
63 char *homedir;
64
65 // filesystem
66 ProfileEntry *profile;
67 char *chrootdir; // chroot directory
68 char *home_private; // private home directory
69 char *home_private_keep; // keep list for private home directory
70 char *cwd; // current working directory
71
72 // networking
73 char *hostname;
74 uint32_t defaultgw; // default gateway
75 Bridge bridge0;
76 Bridge bridge1;
77 Bridge bridge2;
78 Bridge bridge3;
79 uint32_t dns1; // up to 3 IP addresses for dns servers
80 uint32_t dns2;
81 uint32_t dns3;
82
83 // rlimits
84 unsigned rlimit_nofile;
85 unsigned rlimit_nproc;
86 unsigned rlimit_fsize;
87 unsigned rlimit_sigpending;
88
89 // cpu affinity and control groups
90 uint32_t cpus;
91 char *cgroup;
92
93
94 // command line
95 char *command_line;
96 char *command_name;
97 char *shell;
98 char **original_argv;
99 int original_argc;
100 int original_program_index;
101} Config;
102extern Config cfg;
103
104static inline int any_bridge_configured(void) {
105 if (cfg.bridge3.configured || cfg.bridge2.configured || cfg.bridge1.configured || cfg.bridge0.configured)
106 return 1;
107 else
108 return 0;
109}
110extern int arg_private; // mount private /home and /tmp directory
111extern int arg_debug; // print debug messages
112extern int arg_nonetwork; // --net=none
113extern int arg_command; // -c
114extern int arg_overlay; // --overlay
115extern int arg_zsh; // use zsh as default shell
116extern int arg_csh; // use csh as default shell
117
118extern int arg_seccomp; // enable default seccomp filter
119extern char *arg_seccomp_list;// optional seccomp list on top of default filter
120extern char *arg_seccomp_list_drop; // seccomp drop list
121extern char *arg_seccomp_list_keep; // seccomp keep list
122
123extern int arg_caps_default_filter; // enable default capabilities filter
124extern int arg_caps_drop; // drop list
125extern int arg_caps_drop_all; // drop all capabilities
126extern int arg_caps_keep; // keep list
127extern char *arg_caps_list; // optional caps list
128
129extern int arg_trace; // syscall tracing support
130extern int arg_rlimit_nofile; // rlimit nofile
131extern int arg_rlimit_nproc; // rlimit nproc
132extern int arg_rlimit_fsize; // rlimit fsize
133extern int arg_rlimit_sigpending;// rlimit sigpending
134extern int arg_nox11; // kill the program if x11 unix domain socket is accessed
135extern int arg_nodbus; // kill the program if D-Bus is accessed
136extern int arg_nogroups; // disable supplementary groups
137extern int arg_noroot; // create a new user namespace and disable root user
138extern int arg_netfilter; // enable netfilter
139extern char *arg_netfilter_file; // netfilter file
140extern int arg_doubledash; // double dash
141extern int arg_shell_none; // run the program directly without a shell
142extern int arg_private_dev; // private dev directory
143extern int arg_scan; // arp-scan all interfaces
144
145extern int parent_to_child_fds[2];
146extern int child_to_parent_fds[2];
147extern pid_t sandbox_pid;
148
149
150
151#define MAX_ARGS 128 // maximum number of command arguments (argc)
152extern char *fullargv[MAX_ARGS];
153extern int fullargc;
154
155// main.c
156void check_user_namespace(void);
157
158// sandbox.c
159int sandbox(void* sandbox_arg);
160
161// network_main.c
162void net_configure_bridge(Bridge *br, char *dev_name);
163void net_configure_sandbox_ip(Bridge *br);
164void net_configure_veth_pair(Bridge *br, const char *ifname, pid_t child);
165void net_check_cfg(void);
166void net_dns_print_name(const char *name);
167void net_dns_print(pid_t pid);
168
169// network.c
170void net_if_up(const char *ifname);
171void net_if_ip(const char *ifname, uint32_t ip, uint32_t mask);
172int net_get_if_addr(const char *bridge, uint32_t *ip, uint32_t *mask, uint8_t mac[6]);
173int net_add_route(uint32_t dest, uint32_t mask, uint32_t gw);
174void net_ifprint(void);
175void net_bridge_add_interface(const char *bridge, const char *dev);
176uint32_t network_get_defaultgw(void);
177int net_config_mac(const char *ifname, const unsigned char mac[6]);
178int net_get_mac(const char *ifname, unsigned char mac[6]);
179
180// fs.c
181// build /tmp/firejail directory
182void fs_build_firejail_dir(void);
183// build /tmp/firejail/mnt directory
184void fs_build_mnt_dir(void);
185// blacklist files or directoies by mounting empty files on top of them
186void fs_blacklist(const char *homedir);
187//void fs_blacklist(char **blacklist, const char *homedir);
188// remount a directory read-only
189void fs_rdonly(const char *dir);
190// mount /proc and /sys directories
191void fs_proc_sys_dev_boot(void);
192// build a basic read-only filesystem
193void fs_basic_fs(void);
194// mount overlayfs on top of / directory
195void fs_overlayfs(void);
196// chroot into an existing directory; mount exiting /dev and update /etc/resolv.conf
197void fs_chroot(const char *rootdir);
198int fs_check_chroot_dir(const char *rootdir);
199
200// profile.c
201// find and read the profile specified by name from dir directory
202int profile_find(const char *name, const char *dir);
203// read a profile file
204void profile_read(const char *fname, const char *skip1, const char *skip2);
205// check profile line; if line == 0, this was generated from a command line option
206// return 1 if the command is to be added to the linked list of profile commands
207// return 0 if the command was already executed inside the function
208int profile_check_line(char *ptr, int lineno);
209// add a profile entry in cfg.profile list; use str to populate the list
210void profile_add(char *str);
211
212// list.c
213void list(void);
214void tree(void);
215void top(void);
216void netstats(void);
217
218// usage.c
219void usage(void);
220
221// join.c
222void join(pid_t pid, const char *homedir, int argc, char **argv, int index);
223void join_name(const char *name, const char *homedir, int argc, char **argv, int index);
224void shut(pid_t pid);
225void shut_name(const char *name);
226
227// restricted_shell.c
228extern char *restricted_user;
229int restricted_shell(const char *user);
230
231// arp.c
232// returns 0 if the address is not in use, -1 otherwise
233int arp_check(const char *dev, uint32_t destaddr, uint32_t srcaddr);
234// assign an IP address using arp scanning
235uint32_t arp_assign(const char *dev, Bridge *br);
236// scan interface (--scan option)
237void arp_scan(const char *dev, uint32_t srcaddr, uint32_t srcmask);
238
239// veth.c
240int net_create_veth(const char *dev, const char *nsdev, unsigned pid);
241int net_create_macvlan(const char *dev, const char *parent, unsigned pid);
242
243// util.c
244void drop_privs(int nogroups);
245void extract_command_name(const char *str);
246void logsignal(int s);
247void logmsg(const char *msg);
248void logargs(int argc, char **argv) ;
249void logerr(const char *msg);
250int copy_file(const char *srcname, const char *destname);
251char *get_link(const char *fname);
252int is_dir(const char *fname);
253int is_link(const char *fname);
254char *line_remove_spaces(const char *buf);
255char *split_comma(char *str);
256int not_unsigned(const char *str);
257int find_child(pid_t parent, pid_t *child);
258void check_private_dir(void);
259void update_map(char *mapping, char *map_file);
260void wait_for_other(int fd);
261void notify_other(int fd);
262
263// fs_var.c
264void fs_var_log(void); // mounting /var/log
265void fs_var_lib(void); // various other fixes for software in /var directory
266void fs_var_cache(void); // various other fixes for software in /var/cache directory
267void fs_var_run(void);
268void fs_var_lock(void);
269void fs_var_tmp(void);
270void fs_var_utmp(void);
271void dbg_test_dir(const char *dir);
272
273// fs_dev.c
274void fs_dev_shm(void);
275void fs_private_dev(void);
276
277// fs_home.c
278// private mode (--private)
279void fs_private(void);
280// private mode (--private=homedir)
281void fs_private_homedir(void);
282// private mode (--private.keep=list)
283void fs_private_home_list(void);
284// check directory linst specified by user (--private.keep option) - exit if it fails
285void fs_check_home_list(void);
286// check new private home directory (--private= option) - exit if it fails
287void fs_check_private_dir(void);
288
289
290// seccomp.c
291int seccomp_filter_drop(void);
292int seccomp_filter_keep(void);
293void seccomp_set(void);
294void seccomp_print_filter_name(const char *name);
295void seccomp_print_filter(pid_t pid);
296
297// caps.c
298int caps_default_filter(void);
299void caps_print(void);
300void caps_drop_all(void);
301void caps_set(uint64_t caps);
302int caps_check_list(const char *clist, void (*callback)(int));
303void caps_drop_list(const char *clist);
304void caps_keep_list(const char *clist);
305void caps_print_filter(pid_t pid);
306void caps_print_filter_name(const char *name);
307
308// syscall.c
309const char *syscall_find_nr(int nr);
310// return -1 if error, 0 if no error
311int syscall_check_list(const char *slist, void (*callback)(int));
312// print all available syscalls
313void syscall_print(void);
314
315// fs_trace.c
316void fs_trace_preload(void);
317void fs_trace(void);
318
319// fs_hostname.c
320void fs_hostname(const char *hostname);
321void fs_resolvconf(void);
322
323// rlimit.c
324void set_rlimits(void);
325
326// cpu.c
327void read_cpu_list(const char *str);
328void set_cpu_affinity(void);
329void load_cpu(const char *fname);
330void save_cpu(void);
331
332// cgroup.c
333void save_cgroup(void);
334void load_cgroup(const char *fname);
335void set_cgroup(const char *path);
336
337// output.c
338void check_output(int argc, char **argv);
339
340// netfilter.c
341void check_netfilter_file(const char *fname);
342void netfilter(const char *fname);
343
344// bandwidth.c
345void shm_create_firejail_dir(void);
346void bandwidth_shm_del_file(pid_t pid);
347void bandwidth_shm_set(pid_t pid, const char *dev, int down, int up);
348void bandwidth_name(const char *name, const char *command, const char *dev, int down, int up);
349void bandwidth_pid(pid_t pid, const char *command, const char *dev, int down, int up);
350void network_shm_del_file(pid_t pid);
351void network_shm_set_file(pid_t pid);
352
353
354#endif \ No newline at end of file