aboutsummaryrefslogtreecommitdiffstats
path: root/src/firejail/syscall.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/firejail/syscall.c')
-rw-r--r--src/firejail/syscall.c105
1 files changed, 0 insertions, 105 deletions
diff --git a/src/firejail/syscall.c b/src/firejail/syscall.c
deleted file mode 100644
index f405f23c8..000000000
--- a/src/firejail/syscall.c
+++ /dev/null
@@ -1,105 +0,0 @@
1/*
2 * Copyright (C) 2014-2016 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
21#ifdef HAVE_SECCOMP
22#include "firejail.h"
23#include <sys/syscall.h>
24
25typedef struct {
26 char *name;
27 int nr;
28} SyscallEntry;
29
30static SyscallEntry syslist[] = {
31//
32// code generated using tools/extract-syscall
33//
34#include "../include/syscall.h"
35//
36// end of generated code
37//
38}; // end of syslist
39
40const char *syscall_find_nr(int nr) {
41 int i;
42 int elems = sizeof(syslist) / sizeof(syslist[0]);
43 for (i = 0; i < elems; i++) {
44 if (nr == syslist[i].nr)
45 return syslist[i].name;
46 }
47
48 return "unknown";
49}
50
51// return -1 if error, or syscall number
52static int syscall_find_name(const char *name) {
53 int i;
54 int elems = sizeof(syslist) / sizeof(syslist[0]);
55 for (i = 0; i < elems; i++) {
56 if (strcmp(name, syslist[i].name) == 0)
57 return syslist[i].nr;
58 }
59
60 return -1;
61}
62
63// return 1 if error, 0 if OK
64int syscall_check_list(const char *slist, void (*callback)(int syscall, int arg), int arg) {
65 // don't allow empty lists
66 if (slist == NULL || *slist == '\0') {
67 fprintf(stderr, "Error: empty syscall lists are not allowed\n");
68 return -1;
69 }
70
71 // work on a copy of the string
72 char *str = strdup(slist);
73 if (!str)
74 errExit("strdup");
75
76 char *ptr = str;
77 char *start = str;
78 while (*ptr != '\0') {
79 if (islower(*ptr) || isdigit(*ptr) || *ptr == '_')
80 ;
81 else if (*ptr == ',') {
82 *ptr = '\0';
83 int nr = syscall_find_name(start);
84 if (nr == -1)
85 fprintf(stderr, "Warning: syscall %s not found\n", start);
86 else if (callback != NULL)
87 callback(nr, arg);
88
89 start = ptr + 1;
90 }
91 ptr++;
92 }
93 if (*start != '\0') {
94 int nr = syscall_find_name(start);
95 if (nr == -1)
96 fprintf(stderr, "Warning: syscall %s not found\n", start);
97 else if (callback != NULL)
98 callback(nr, arg);
99 }
100
101 free(str);
102 return 0;
103}
104
105#endif // HAVE_SECCOMP