diff options
author | netblue30 <netblue30@yahoo.com> | 2016-03-12 12:36:16 -0500 |
---|---|---|
committer | netblue30 <netblue30@yahoo.com> | 2016-03-12 12:36:16 -0500 |
commit | ac68ec0de9249c60c92099ae37d7d4efd34fefcc (patch) | |
tree | 8bc9ded8ec868071e9f3138f856a6771676afa67 | |
parent | file transfer fixes (diff) | |
download | firejail-ac68ec0de9249c60c92099ae37d7d4efd34fefcc.tar.gz firejail-ac68ec0de9249c60c92099ae37d7d4efd34fefcc.tar.zst firejail-ac68ec0de9249c60c92099ae37d7d4efd34fefcc.zip |
build fixes
-rw-r--r-- | src/firejail/checkcfg.c | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/firejail/checkcfg.c b/src/firejail/checkcfg.c new file mode 100644 index 000000000..9313bb1a4 --- /dev/null +++ b/src/firejail/checkcfg.c | |||
@@ -0,0 +1,82 @@ | |||
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 | #include "firejail.h" | ||
21 | #include <sys/stat.h> | ||
22 | |||
23 | #define MAX_READ 8192 // line buffer for profile files | ||
24 | |||
25 | static int initialized = 0; | ||
26 | static int cfg_val[CFG_MAX]; | ||
27 | |||
28 | int checkcfg(int val) { | ||
29 | EUID_ASSERT(); | ||
30 | assert(val < CFG_MAX); | ||
31 | int line = 0; | ||
32 | |||
33 | if (!initialized) { | ||
34 | // initialize defaults | ||
35 | int i; | ||
36 | for (i = 0; i < CFG_MAX; i++) | ||
37 | cfg_val[i] = 1; // most of them are enabled by default | ||
38 | |||
39 | // open configuration file | ||
40 | char *fname; | ||
41 | if (asprintf(&fname, "%s/firejail.config", SYSCONFDIR) == -1) | ||
42 | errExit("asprintf"); | ||
43 | |||
44 | FILE *fp = fopen(fname, "r"); | ||
45 | if (!fp) { | ||
46 | fprintf(stderr, "Error: Firejail configuration file %s not found\n", fname); | ||
47 | exit(1); | ||
48 | } | ||
49 | |||
50 | // read configuration file | ||
51 | char buf[MAX_READ]; | ||
52 | while (fgets(buf,MAX_READ, fp)) { | ||
53 | line++; | ||
54 | if (*buf == '#' || *buf == '\n') | ||
55 | continue; | ||
56 | |||
57 | // parse line | ||
58 | line_remove_spaces(buf); | ||
59 | if (strncmp(buf, "file-transfer ", 14) == 0) { | ||
60 | if (strcmp(buf + 14, "yes") == 0) | ||
61 | cfg_val[CFG_FILE_TRANSFER] = 1; | ||
62 | else if (strcmp(buf + 14, "no") == 0) | ||
63 | cfg_val[CFG_FILE_TRANSFER] = 0; | ||
64 | else | ||
65 | goto errout; | ||
66 | } | ||
67 | else | ||
68 | goto errout; | ||
69 | } | ||
70 | |||
71 | fclose(fp); | ||
72 | free(fname); | ||
73 | initialized = 1; | ||
74 | } | ||
75 | |||
76 | return cfg_val[val]; | ||
77 | |||
78 | errout: | ||
79 | fprintf(stderr, "Error: invalid line %d in firejail configuration file\n", line ); | ||
80 | exit(1); | ||
81 | } | ||
82 | |||