diff options
-rw-r--r-- | README.md | 31 | ||||
-rw-r--r-- | RELNOTES | 1 | ||||
-rw-r--r-- | src/firejail/firejail.h | 3 | ||||
-rw-r--r-- | src/firejail/main.c | 4 | ||||
-rw-r--r-- | src/firejail/run_symlink.c | 91 |
5 files changed, 130 insertions, 0 deletions
@@ -34,6 +34,37 @@ FAQ: https://firejail.wordpress.com/support/frequently-asked-questions/ | |||
34 | 34 | ||
35 | # Current development version: 0.9.37 | 35 | # Current development version: 0.9.37 |
36 | 36 | ||
37 | ## Symlink invocation | ||
38 | |||
39 | This is a small thing, but very convenient. Make a symbolic link (ln -s) to /usr/bin/firejail under | ||
40 | the name of the program you want to run, and put the link in the first $PATH position (for | ||
41 | example in /usr/local/bin). Example: | ||
42 | ````` | ||
43 | $ which -a transmission-gtk | ||
44 | /usr/bin/transmission-gtk | ||
45 | |||
46 | $ sudo ln -s /usr/bin/firejail /usr/local/bin/transmission-gtk | ||
47 | |||
48 | $ which -a transmission-gtk | ||
49 | /usr/local/bin/transmission-gtk | ||
50 | /usr/bin/transmission-gtk | ||
51 | ````` | ||
52 | We have in this moment two entries in $PATH for transmission. The first one is a symlink to firejail. | ||
53 | The second one is the real program. Starting transmission in this moment, invokes "firejail transmission-gtk" | ||
54 | ````` | ||
55 | $ transmission-gtk | ||
56 | Redirecting symlink to /usr/bin/transmission-gtk | ||
57 | Reading profile /etc/firejail/transmission-gtk.profile | ||
58 | Reading profile /etc/firejail/disable-mgmt.inc | ||
59 | Reading profile /etc/firejail/disable-secret.inc | ||
60 | Reading profile /etc/firejail/disable-common.inc | ||
61 | Reading profile /etc/firejail/disable-devel.inc | ||
62 | Parent pid 19343, child pid 19344 | ||
63 | Blacklist violations are logged to syslog | ||
64 | Child process initialized | ||
65 | ````` | ||
66 | |||
67 | |||
37 | ## IPv6 support: | 68 | ## IPv6 support: |
38 | ````` | 69 | ````` |
39 | --ip6=address | 70 | --ip6=address |
@@ -5,6 +5,7 @@ firejail (0.9.37) baseline; urgency=low | |||
5 | * --ip6 option - IPv6 support | 5 | * --ip6 option - IPv6 support |
6 | * added KMail profile | 6 | * added KMail profile |
7 | * --join command enhancement (--join-network, --join-filesystem) | 7 | * --join command enhancement (--join-network, --join-filesystem) |
8 | * symlink invocation | ||
8 | -- netblue30 <netblue30@yahoo.com> | 9 | -- netblue30 <netblue30@yahoo.com> |
9 | 10 | ||
10 | firejail (0.9.36) baseline; urgency=low | 11 | firejail (0.9.36) baseline; urgency=low |
diff --git a/src/firejail/firejail.h b/src/firejail/firejail.h index 1de38c43a..ba8a9dc48 100644 --- a/src/firejail/firejail.h +++ b/src/firejail/firejail.h | |||
@@ -500,5 +500,8 @@ void fs_logger_change_owner(void); | |||
500 | void fs_logger_print_log_name(const char *name); | 500 | void fs_logger_print_log_name(const char *name); |
501 | void fs_logger_print_log(pid_t pid); | 501 | void fs_logger_print_log(pid_t pid); |
502 | 502 | ||
503 | // run_symlink.c | ||
504 | void run_symlink(int argc, char **argv); | ||
505 | |||
503 | #endif | 506 | #endif |
504 | 507 | ||
diff --git a/src/firejail/main.c b/src/firejail/main.c index 58d735010..43d2f0fa2 100644 --- a/src/firejail/main.c +++ b/src/firejail/main.c | |||
@@ -459,6 +459,10 @@ int main(int argc, char **argv) { | |||
459 | int highest_errno = errno_highest_nr(); | 459 | int highest_errno = errno_highest_nr(); |
460 | #endif | 460 | #endif |
461 | 461 | ||
462 | // check argv[0] symlink wrapper | ||
463 | run_symlink(argc, argv); | ||
464 | |||
465 | |||
462 | // check if we already have a sandbox running | 466 | // check if we already have a sandbox running |
463 | int rv = check_kernel_procs(); | 467 | int rv = check_kernel_procs(); |
464 | if (rv == 0) { | 468 | if (rv == 0) { |
diff --git a/src/firejail/run_symlink.c b/src/firejail/run_symlink.c new file mode 100644 index 000000000..5f8d131ae --- /dev/null +++ b/src/firejail/run_symlink.c | |||
@@ -0,0 +1,91 @@ | |||
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/types.h> | ||
22 | #include <sys/stat.h> | ||
23 | #include <unistd.h> | ||
24 | |||
25 | void run_symlink(int argc, char **argv) { | ||
26 | char *program = strrchr(argv[0], '/'); | ||
27 | if (program) | ||
28 | program += 1; | ||
29 | else | ||
30 | program = argv[0]; | ||
31 | if (strcmp(program, "firejail") == 0) | ||
32 | return; | ||
33 | |||
34 | // find the real program | ||
35 | // probably the first entry returend by "which -a" is a symlink - use the second entry! | ||
36 | char *p = getenv("PATH"); | ||
37 | if (!p) { | ||
38 | fprintf(stderr, "Error: PATH environment variable not set\n"); | ||
39 | exit(1); | ||
40 | } | ||
41 | |||
42 | char *path = strdup(p); | ||
43 | if (!path) | ||
44 | errExit("strdup"); | ||
45 | |||
46 | // look in path for our program | ||
47 | char *tok = strtok(path, ":"); | ||
48 | int found = 0; | ||
49 | while (tok) { | ||
50 | char *name; | ||
51 | if (asprintf(&name, "%s/%s", tok, program) == -1) | ||
52 | errExit("asprintf"); | ||
53 | |||
54 | struct stat s; | ||
55 | if (stat(name, &s) == 0) { | ||
56 | if (!is_link(name)) { | ||
57 | program = strdup(name); | ||
58 | found = 1; | ||
59 | break; | ||
60 | } | ||
61 | } | ||
62 | |||
63 | free(name); | ||
64 | tok = strtok(NULL, ":"); | ||
65 | } | ||
66 | if (!found) { | ||
67 | fprintf(stderr, "Error: cannot find the program in the path\n"); | ||
68 | exit(1); | ||
69 | } | ||
70 | |||
71 | |||
72 | // start the argv[0] program in a new sandbox | ||
73 | char *firejail; | ||
74 | if (asprintf(&firejail, "%s/bin/firejail", PREFIX) == -1) | ||
75 | errExit("asprintf"); | ||
76 | |||
77 | printf("Redirecting symlink to %s\n", firejail, program); | ||
78 | |||
79 | // run command | ||
80 | char *a[3 + argc]; | ||
81 | a[0] = firejail; | ||
82 | a[1] = program; | ||
83 | int i; | ||
84 | for (i = 0; i < (argc - 1); i++) | ||
85 | a[i + 2] = argv[i + 1]; | ||
86 | a[i + 2] = NULL; | ||
87 | execvp(a[0], a); | ||
88 | |||
89 | perror("execvp"); | ||
90 | exit(1); | ||
91 | } | ||