aboutsummaryrefslogtreecommitdiffstats
path: root/src/fseccomp/syscall.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fseccomp/syscall.c')
-rw-r--r--src/fseccomp/syscall.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/fseccomp/syscall.c b/src/fseccomp/syscall.c
index c67d45598..e2052efde 100644
--- a/src/fseccomp/syscall.c
+++ b/src/fseccomp/syscall.c
@@ -1,3 +1,22 @@
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*/
1#include "fseccomp.h" 20#include "fseccomp.h"
2#include <sys/syscall.h> 21#include <sys/syscall.h>
3 22
@@ -16,6 +35,29 @@ static SyscallEntry syslist[] = {
16// 35//
17}; // end of syslist 36}; // end of syslist
18 37
38// return -1 if error, or syscall number
39int syscall_find_name(const char *name) {
40 int i;
41 int elems = sizeof(syslist) / sizeof(syslist[0]);
42 for (i = 0; i < elems; i++) {
43 if (strcmp(name, syslist[i].name) == 0)
44 return syslist[i].nr;
45 }
46
47 return -1;
48}
49
50char *syscall_find_nr(int nr) {
51 int i;
52 int elems = sizeof(syslist) / sizeof(syslist[0]);
53 for (i = 0; i < elems; i++) {
54 if (nr == syslist[i].nr)
55 return syslist[i].name;
56 }
57
58 return "unknown";
59}
60
19void syscall_print(void) { 61void syscall_print(void) {
20 int i; 62 int i;
21 int elems = sizeof(syslist) / sizeof(syslist[0]); 63 int elems = sizeof(syslist) / sizeof(syslist[0]);
@@ -24,3 +66,45 @@ void syscall_print(void) {
24 } 66 }
25 printf("\n"); 67 printf("\n");
26} 68}
69
70// return 1 if error, 0 if OK
71int syscall_check_list(const char *slist, void (*callback)(int fd, int syscall, int arg), int fd, int arg) {
72 // don't allow empty lists
73 if (slist == NULL || *slist == '\0') {
74 fprintf(stderr, "Error: empty syscall lists are not allowed\n");
75 return -1;
76 }
77
78 // work on a copy of the string
79 char *str = strdup(slist);
80 if (!str)
81 errExit("strdup");
82
83 char *ptr = str;
84 char *start = str;
85 while (*ptr != '\0') {
86 if (islower(*ptr) || isdigit(*ptr) || *ptr == '_')
87 ;
88 else if (*ptr == ',') {
89 *ptr = '\0';
90 int nr = syscall_find_name(start);
91 if (nr == -1)
92 fprintf(stderr, "Warning: syscall %s not found\n", start);
93 else if (callback != NULL)
94 callback(fd, nr, arg);
95
96 start = ptr + 1;
97 }
98 ptr++;
99 }
100 if (*start != '\0') {
101 int nr = syscall_find_name(start);
102 if (nr == -1)
103 fprintf(stderr, "Warning: syscall %s not found\n", start);
104 else if (callback != NULL)
105 callback(fd, nr, arg);
106 }
107
108 free(str);
109 return 0;
110}