aboutsummaryrefslogtreecommitdiffstats
path: root/src/tools/profcleaner.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/profcleaner.c')
-rw-r--r--src/tools/profcleaner.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/tools/profcleaner.c b/src/tools/profcleaner.c
new file mode 100644
index 000000000..93bb3f73d
--- /dev/null
+++ b/src/tools/profcleaner.c
@@ -0,0 +1,75 @@
1/*
2 * Copyright (C) 2014-2021 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//*************************************************************
22// Small utility program to convert profiles from blacklist/whitelist to deny/allow
23// Compile:
24// gcc -o profcleaner profcleaner.c
25// Usage:
26// profcleaner *.profile
27//*************************************************************
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <string.h>
32#include <unistd.h>
33#define MAXBUF 4096
34
35int main(int argc, char **argv) {
36 printf("Usage: profcleaner files\n");
37 int i;
38
39 for (i = 1; i < argc; i++) {
40 FILE *fp = fopen(argv[i], "r");
41 if (!fp) {
42 fprintf(stderr, "Error: cannot open %s\n", argv[i]);
43 return 1;
44 }
45
46 FILE *fpout = fopen("profcleaner-tmp", "w");
47 if (!fpout) {
48 fprintf(stderr, "Error: cannot open output file\n");
49 return 1;
50 }
51
52 char buf[MAXBUF];
53 while (fgets(buf, MAXBUF, fp)) {
54 if (strncmp(buf, "blacklist-nolog", 15) == 0)
55 fprintf(fpout, "deny-nolog %s", buf + 15);
56 else if (strncmp(buf, "blacklist", 9) == 0)
57 fprintf(fpout, "deny %s", buf + 9);
58 else if (strncmp(buf, "noblacklist", 11) == 0)
59 fprintf(fpout, "nodeny %s", buf + 11);
60 else if (strncmp(buf, "whitelist", 9) == 0)
61 fprintf(fpout, "allow %s", buf + 9);
62 else if (strncmp(buf, "nowhitelist", 11) == 0)
63 fprintf(fpout, "noallow %s", buf + 11);
64 else
65 fprintf(fpout, "%s", buf);
66 }
67
68 fclose(fp);
69 fclose(fpout);
70 unlink(argv[i]);
71 rename("profcleaner-tmp", argv[i]);
72 }
73
74 return 0;
75} \ No newline at end of file