aboutsummaryrefslogtreecommitdiffstats
path: root/src/firejail/fs_etc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/firejail/fs_etc.c')
-rw-r--r--src/firejail/fs_etc.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/firejail/fs_etc.c b/src/firejail/fs_etc.c
index df0e92203..b82baf1ad 100644
--- a/src/firejail/fs_etc.c
+++ b/src/firejail/fs_etc.c
@@ -24,7 +24,8 @@
24#include <sys/wait.h> 24#include <sys/wait.h>
25#include <unistd.h> 25#include <unistd.h>
26 26
27static void check_dir_or_file(const char *name) { 27// return 0 if file not found, 1 if found
28static int check_dir_or_file(const char *name) {
28 assert(name); 29 assert(name);
29 invalid_filename(name); 30 invalid_filename(name);
30 31
@@ -35,19 +36,20 @@ static void check_dir_or_file(const char *name) {
35 if (arg_debug) 36 if (arg_debug)
36 printf("Checking %s\n", fname); 37 printf("Checking %s\n", fname);
37 if (stat(fname, &s) == -1) { 38 if (stat(fname, &s) == -1) {
38 fprintf(stderr, "Error: file %s not found.\n", fname); 39 if (arg_debug)
39 exit(1); 40 printf("Warning: file %s not found.\n", fname);
41 return 0;
40 } 42 }
41 43
42 // dir or regular file 44 // dir or regular file
43 if (S_ISDIR(s.st_mode) || S_ISREG(s.st_mode)) { 45 if (S_ISDIR(s.st_mode) || S_ISREG(s.st_mode)) {
44 free(fname); 46 free(fname);
45 return; 47 return 1;
46 } 48 }
47 49
48 if (!is_link(fname)) { 50 if (!is_link(fname)) {
49 free(fname); 51 free(fname);
50 return; 52 return 1;
51 } 53 }
52 54
53 fprintf(stderr, "Error: invalid file type, %s.\n", fname); 55 fprintf(stderr, "Error: invalid file type, %s.\n", fname);
@@ -63,11 +65,23 @@ void fs_check_etc_list(void) {
63 char *dlist = strdup(cfg.etc_private_keep); 65 char *dlist = strdup(cfg.etc_private_keep);
64 if (!dlist) 66 if (!dlist)
65 errExit("strdup"); 67 errExit("strdup");
68
69 // build a new list only with the files found
70 char *newlist = malloc(strlen(cfg.etc_private_keep) + 1);
71 if (!newlist)
72 errExit("malloc");
73 *newlist = '\0';
66 74
67 char *ptr = strtok(dlist, ","); 75 char *ptr = strtok(dlist, ",");
68 check_dir_or_file(ptr); 76 if (check_dir_or_file(ptr))
69 while ((ptr = strtok(NULL, ",")) != NULL) 77 strcat(newlist, ptr);
70 check_dir_or_file(ptr); 78 while ((ptr = strtok(NULL, ",")) != NULL) {
79 if (check_dir_or_file(ptr)) {
80 strcat(newlist, ",");
81 strcat(newlist, ptr);
82 }
83 }
84 cfg.etc_private_keep = newlist;
71 85
72 free(dlist); 86 free(dlist);
73} 87}