aboutsummaryrefslogtreecommitdiffstats
path: root/src/fnetfilter/main.c
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@yahoo.com>2018-04-01 07:48:11 -0400
committerLibravatar netblue30 <netblue30@yahoo.com>2018-04-01 07:48:11 -0400
commit1fb1bfe20fbde64d769e846b1581ce021d03e864 (patch)
treeb284305324ca31fa5c0b2b318a9dbeaae146da55 /src/fnetfilter/main.c
parentmerges (diff)
downloadfirejail-1fb1bfe20fbde64d769e846b1581ce021d03e864.tar.gz
firejail-1fb1bfe20fbde64d769e846b1581ce021d03e864.tar.zst
firejail-1fb1bfe20fbde64d769e846b1581ce021d03e864.zip
testing
Diffstat (limited to 'src/fnetfilter/main.c')
-rw-r--r--src/fnetfilter/main.c41
1 files changed, 17 insertions, 24 deletions
diff --git a/src/fnetfilter/main.c b/src/fnetfilter/main.c
index 828b30d40..ba58ba3c9 100644
--- a/src/fnetfilter/main.c
+++ b/src/fnetfilter/main.c
@@ -50,19 +50,20 @@ static void usage(void) {
50 printf("\tfnetfilter netfilter-command destination-file\n"); 50 printf("\tfnetfilter netfilter-command destination-file\n");
51} 51}
52 52
53static void err_exit_cannot_open_file(const char *fname) {
54 fprintf(stderr, "Error fnetfilter: cannot open %s\n", fname);
55 exit(1);
56}
57
53 58
54static void copy(const char *src, const char *dest) { 59static void copy(const char *src, const char *dest) {
55 FILE *fp1 = fopen(src, "r"); 60 FILE *fp1 = fopen(src, "r");
56 if (!fp1) { 61 if (!fp1)
57 fprintf(stderr, "Error fnetfilter: cannot open %s\n", src); 62 err_exit_cannot_open_file(src);
58 exit(1);
59 }
60 63
61 FILE *fp2 = fopen(dest, "w"); 64 FILE *fp2 = fopen(dest, "w");
62 if (!fp2) { 65 if (!fp2)
63 fprintf(stderr, "Error fnetfilter: cannot open %s\n", dest); 66 err_exit_cannot_open_file(dest);
64 exit(1);
65 }
66 67
67 char buf[MAXBUF]; 68 char buf[MAXBUF];
68 while (fgets(buf, MAXBUF, fp1)) 69 while (fgets(buf, MAXBUF, fp1))
@@ -106,16 +107,12 @@ for (i = 0; i < argcnt; i++)
106 107
107 // open the files 108 // open the files
108 FILE *fp1 = fopen(src, "r"); 109 FILE *fp1 = fopen(src, "r");
109 if (!fp1) { 110 if (!fp1)
110 fprintf(stderr, "Error fnetfilter: cannot open %s\n", src); 111 err_exit_cannot_open_file(src);
111 exit(1);
112 }
113 112
114 FILE *fp2 = fopen(dest, "w"); 113 FILE *fp2 = fopen(dest, "w");
115 if (!fp2) { 114 if (!fp2)
116 fprintf(stderr, "Error fnetfilter: cannot open %s\n", dest); 115 err_exit_cannot_open_file(dest);
117 exit(1);
118 }
119 116
120 int line = 0; 117 int line = 0;
121 char buf[MAXBUF]; 118 char buf[MAXBUF];
@@ -186,19 +183,15 @@ printf("\n");
186//printf("destfile %s\n", destfile); 183//printf("destfile %s\n", destfile);
187 // destfile is a real filename 184 // destfile is a real filename
188 int len = strlen(destfile); 185 int len = strlen(destfile);
189 if (strcspn(destfile, "\\&!?\"'<>%^(){};,*[]") != (size_t)len) { 186 if (strcspn(destfile, "\\&!?\"'<>%^(){};,*[]") != (size_t)len)
190 fprintf(stderr, "Error fnetfilter: invalid destination file in netfilter command\n"); 187 err_exit_cannot_open_file(destfile);
191 exit(1);
192 }
193 188
194 // handle default config (command = NULL, destfile) 189 // handle default config (command = NULL, destfile)
195 if (command == NULL) { 190 if (command == NULL) {
196 // create a default filter file 191 // create a default filter file
197 FILE *fp = fopen(destfile, "w"); 192 FILE *fp = fopen(destfile, "w");
198 if (!fp) { 193 if (!fp)
199 fprintf(stderr, "Error fnetfilter: cannot open %s\n", destfile); 194 err_exit_cannot_open_file(destfile);
200 exit(1);
201 }
202 fprintf(fp, "%s\n", default_filter); 195 fprintf(fp, "%s\n", default_filter);
203 fclose(fp); 196 fclose(fp);
204 } 197 }