aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@protonmail.com>2022-04-25 15:34:24 -0400
committerLibravatar netblue30 <netblue30@protonmail.com>2022-04-25 15:34:24 -0400
commit1cdfa6f9554c42eb3a817e2cdf68f10e02be9f00 (patch)
tree2d4dc520cc6b110bf3ca620e1f9523cf73cc3510 /src
parentfix firecfg --guide (diff)
downloadfirejail-1cdfa6f9554c42eb3a817e2cdf68f10e02be9f00.tar.gz
firejail-1cdfa6f9554c42eb3a817e2cdf68f10e02be9f00.tar.zst
firejail-1cdfa6f9554c42eb3a817e2cdf68f10e02be9f00.zip
more on firecfg --guide: fzenity
Diffstat (limited to 'src')
-rwxr-xr-xsrc/firecfg/firejail-welcome.sh11
-rw-r--r--src/firecfg/main.c6
-rw-r--r--src/fzenity/Makefile.in17
-rw-r--r--src/fzenity/main.c176
4 files changed, 205 insertions, 5 deletions
diff --git a/src/firecfg/firejail-welcome.sh b/src/firecfg/firejail-welcome.sh
index 7183b74e1..a7e74ebc3 100755
--- a/src/firecfg/firejail-welcome.sh
+++ b/src/firecfg/firejail-welcome.sh
@@ -36,12 +36,13 @@ enable_nonewprivs=false
36read -r -d $'\0' MSG_INTRO <<EOM 36read -r -d $'\0' MSG_INTRO <<EOM
37<big><b>Welcome to Firejail!</b></big> 37<big><b>Welcome to Firejail!</b></big>
38 38
39This guide will walk you through some of the most common sandbox customizations. At the end of the 39This guide will walk you through some of the most common sandbox customizations.
40guide you'll have the option to save your changes in Firejail's global config file at 40At the end of the guide you'll have the option to save your changes in Firejail's
41<b>/etc/firejail/firejail.config</b>. A copy of the original file is stored as 41global config file at <b>/etc/firejail/firejail.config</b>. A copy of the original file is saved
42<b>/etc/firejal/firejail.config-</b>. 42as <b>/etc/firejal/firejail.config-</b>.
43 43
44Please note that running this script a second time can set new options, but does not clear options set in a previous run. 44Please note that running this script a second time can set new options, but does
45not clear options set in a previous run.
45 46
46Press OK to continue, or close this window to stop the program. 47Press OK to continue, or close this window to stop the program.
47 48
diff --git a/src/firecfg/main.c b/src/firecfg/main.c
index 0c81f69bd..07e30415b 100644
--- a/src/firecfg/main.c
+++ b/src/firecfg/main.c
@@ -444,8 +444,14 @@ int main(int argc, char **argv) {
444 444
445 if (arg_guide) { 445 if (arg_guide) {
446 char *cmd; 446 char *cmd;
447if (arg_debug) {
448 if (asprintf(&cmd, "sudo %s/firejail/firejail-welcome.sh /usr/lib/firejail/fzenity %s %s", LIBDIR, SYSCONFDIR, user) == -1)
449 errExit("asprintf");
450}
451else {
447 if (asprintf(&cmd, "sudo %s/firejail/firejail-welcome.sh /usr/bin/zenity %s %s", LIBDIR, SYSCONFDIR, user) == -1) 452 if (asprintf(&cmd, "sudo %s/firejail/firejail-welcome.sh /usr/bin/zenity %s %s", LIBDIR, SYSCONFDIR, user) == -1)
448 errExit("asprintf"); 453 errExit("asprintf");
454}
449 int status = system(cmd); 455 int status = system(cmd);
450 if (status == -1) { 456 if (status == -1) {
451 fprintf(stderr, "Error: cannot run firejail-welcome.sh\n"); 457 fprintf(stderr, "Error: cannot run firejail-welcome.sh\n");
diff --git a/src/fzenity/Makefile.in b/src/fzenity/Makefile.in
new file mode 100644
index 000000000..d9f976165
--- /dev/null
+++ b/src/fzenity/Makefile.in
@@ -0,0 +1,17 @@
1.PHONY: all
2all: fzenity
3
4include ../common.mk
5
6%.o : %.c $(H_FILE_LIST) ../include/common.h
7 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(INCLUDE) -c $< -o $@
8
9fzenity: $(OBJS)
10 $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) $(EXTRA_LDFLAGS)
11
12.PHONY: clean
13clean:; rm -fr *.o fzenity *.gcov *.gcda *.gcno *.plist
14
15.PHONY: distclean
16distclean: clean
17 rm -fr Makefile
diff --git a/src/fzenity/main.c b/src/fzenity/main.c
new file mode 100644
index 000000000..4a0d3abac
--- /dev/null
+++ b/src/fzenity/main.c
@@ -0,0 +1,176 @@
1#include "../include/common.h"
2#include <sys/ioctl.h>
3
4static char *arg_title = NULL;
5static char *arg_text = NULL;
6static int arg_info = 0;
7static int arg_question = 0;
8
9static inline void ansi_topleft(void) {
10 char str[] = {0x1b, '[', '1', ';', '1', 'H', '\0'};
11 printf("%s", str);
12 fflush(0);
13}
14
15static inline void ansi_clrscr(void) {
16 ansi_topleft();
17 char str[] = {0x1b, '[', '0', 'J', '\0'};
18 printf("%s", str);
19 fflush(0);
20}
21
22char *remove_markup(char *in) {
23 char *out = malloc(strlen(in) + 1);
24 if (!out)
25 errExit("malloc");
26 memset(out, 0, strlen(in) + 1);
27
28 char *ptr = in;
29 char *outptr = out;
30 while (*ptr != '\0') {
31 // skip <> markup
32 if (*ptr == '<') {
33 while (*ptr != '\0' && *ptr != '>')
34 ptr++;
35 if (*ptr == '\0') {
36 fprintf(stderr, "Error: invalid markup\n");
37 exit(0);
38 }
39 ptr++;
40 }
41 // replace literal \n with char '\n'
42 else if (*ptr == '\\' && *(ptr + 1) == 'n') {
43 ptr += 2;
44 *outptr++ = '\n';
45 continue;
46 }
47 // replace '/n' with ' '
48 else if (*ptr == '\n') {
49 if (*(ptr + 1) == '\n') {
50 *outptr++ = '\n';
51 *outptr++ = '\n';
52 ptr += 2;
53 }
54 else {
55 *outptr++ = ' ';
56 ptr++;
57 }
58 }
59 else
60 *outptr++ = *ptr++;
61 }
62
63 return out;
64}
65
66char *print_line(char *in, int col) {
67 char *ptr = in;
68 int i = 0;
69 while (*ptr != '\n' && *ptr != '\0' && i < col) {
70 ptr++;
71 i++;
72 }
73
74 if (*ptr == '\n') {
75 *ptr++ = '\0';
76 printf("%s\n", in);
77 return ptr++;
78 }
79 else if (i == col) {
80 while (*ptr != ' ' && ptr != in)
81 ptr--;
82 *ptr++ = '\0';
83 printf("%s\n", in);
84 return ptr;
85 }
86 assert(0);
87 return NULL;
88}
89
90void paginate(char *in) {
91 struct winsize w;
92 int col = 80;
93 if (ioctl(0, TIOCGWINSZ, &w) == 0)
94 col = w.ws_col;
95
96 char *ptr = in;
97 while (*ptr != '\0') {
98 if (strlen(ptr) < col) {
99 printf("%s", ptr);
100 return;
101 }
102 ptr =print_line(ptr, col);
103 }
104
105 return;
106}
107
108static void info(void) {
109 ansi_clrscr();
110 if (arg_text == NULL) {
111 fprintf(stderr, "Error: --text argument required\n");
112 exit(1);
113 }
114
115 if (arg_title)
116 printf("%s\n\n", arg_title);
117
118 char *ptr = strstr(arg_text, "Press OK to continue");
119 if (ptr)
120 *ptr = '\0';
121 char *out = remove_markup(arg_text);
122 paginate(out);
123 free(out);
124
125 printf("\nContinue? (Y/N): ");
126
127 int c = getchar();
128 if (c == 'y' || c == 'Y')
129 exit(0);
130 exit(1);
131}
132
133static void question(void) {
134 ansi_clrscr();
135 if (arg_text == NULL) {
136 fprintf(stderr, "Error: --text argument required\n");
137 exit(1);
138 }
139
140 if (arg_title)
141 printf("%s\n\n", arg_title);
142
143 char *ptr = strstr(arg_text, "Press OK to continue");
144 if (ptr)
145 *ptr = '\0';
146 char *out = remove_markup(arg_text);
147 paginate(out);
148 free(out);
149
150 printf("\n\n(Y/N): ");
151
152 int c = getchar();
153 if (c == 'y' || c == 'Y')
154 exit(0);
155 exit(1);
156}
157
158int main(int argc, char **argv) {
159 int i;
160 for (i = 1; i < argc; i++) {
161//printf("argv %d: #%s#\n", i, argv[i]);
162 if (strcmp(argv[i], "--info") == 0)
163 arg_info = 1;
164 else if (strcmp(argv[i], "--question") == 0)
165 arg_question = 1;
166 else if (strncmp(argv[i], "--text=", 7) == 0)
167 arg_text = argv[i] + 7;
168 }
169
170 if (arg_question)
171 question();
172 else if (arg_info)
173 info();
174
175 return 0;
176}