diff options
author | 2021-06-14 10:15:35 -0400 | |
---|---|---|
committer | 2021-06-14 10:15:35 -0400 | |
commit | e770ab6d858bf8594edb012b1df6b899efb37e94 (patch) | |
tree | b34d2690c822d8b8879d164e9c948051f580120c | |
parent | mention new tin profile in readme/relnotes (diff) | |
download | firejail-e770ab6d8.tar.gz firejail-e770ab6d8.tar.zst firejail-e770ab6d8.zip |
appimage: automatically detect profile
-rw-r--r-- | README | 1 | ||||
-rw-r--r-- | src/firejail/appimage.c | 27 | ||||
-rw-r--r-- | src/firejail/firejail.h | 3 | ||||
-rw-r--r-- | src/firejail/main.c | 15 |
4 files changed, 43 insertions, 3 deletions
@@ -500,6 +500,7 @@ Jean-Philippe Eisenbarth (https://github.com/jpeisenbarth) | |||
500 | - fixed spotify.profile | 500 | - fixed spotify.profile |
501 | Jeff Squyres (https://github.com/jsquyres) | 501 | Jeff Squyres (https://github.com/jsquyres) |
502 | - various manpage fixes | 502 | - various manpage fixes |
503 | - cmdline.c: optionally quote the resulting command line | ||
503 | Jericho (https://github.com/attritionorg) | 504 | Jericho (https://github.com/attritionorg) |
504 | - spelling | 505 | - spelling |
505 | Jesse Smith (https://github.com/slicer69) | 506 | Jesse Smith (https://github.com/slicer69) |
diff --git a/src/firejail/appimage.c b/src/firejail/appimage.c index 6b9fed765..d194eeafb 100644 --- a/src/firejail/appimage.c +++ b/src/firejail/appimage.c | |||
@@ -30,6 +30,7 @@ | |||
30 | 30 | ||
31 | static char *devloop = NULL; // device file | 31 | static char *devloop = NULL; // device file |
32 | static long unsigned size = 0; // offset into appimage file | 32 | static long unsigned size = 0; // offset into appimage file |
33 | #define MAXBUF 4096 | ||
33 | 34 | ||
34 | #ifdef LOOP_CTL_GET_FREE // test for older kernels; this definition is found in /usr/include/linux/loop.h | 35 | #ifdef LOOP_CTL_GET_FREE // test for older kernels; this definition is found in /usr/include/linux/loop.h |
35 | static void err_loop(void) { | 36 | static void err_loop(void) { |
@@ -38,6 +39,32 @@ static void err_loop(void) { | |||
38 | } | 39 | } |
39 | #endif | 40 | #endif |
40 | 41 | ||
42 | // return 1 if found | ||
43 | int appimage_find_profile(const char *archive) { | ||
44 | assert(archive); | ||
45 | assert(strlen(archive)); | ||
46 | |||
47 | // try to match the name of the archive with the list of programs in /usr/lib/firejail/firecfg.config | ||
48 | FILE *fp = fopen(LIBDIR "/firejail/firecfg.config", "r"); | ||
49 | if (!fp) { | ||
50 | fprintf(stderr, "Error: cannot find %s, firejail is not correctly installed\n", LIBDIR "/firejail/firecfg.config"); | ||
51 | exit(1); | ||
52 | } | ||
53 | char buf[MAXBUF]; | ||
54 | while (fgets(buf, MAXBUF, fp)) { | ||
55 | if (*buf == '#') | ||
56 | continue; | ||
57 | char *ptr = strchr(buf, '\n'); | ||
58 | if (ptr) | ||
59 | *ptr = '\0'; | ||
60 | if (strcasestr(archive, buf)) | ||
61 | return profile_find_firejail(buf, 1); | ||
62 | } | ||
63 | return 0; | ||
64 | |||
65 | } | ||
66 | |||
67 | |||
41 | void appimage_set(const char *appimage) { | 68 | void appimage_set(const char *appimage) { |
42 | assert(appimage); | 69 | assert(appimage); |
43 | assert(devloop == NULL); // don't call this twice! | 70 | assert(devloop == NULL); // don't call this twice! |
diff --git a/src/firejail/firejail.h b/src/firejail/firejail.h index c442a97bf..622be4d97 100644 --- a/src/firejail/firejail.h +++ b/src/firejail/firejail.h | |||
@@ -5,7 +5,7 @@ | |||
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify | 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 | 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 | 8 | * the Free Software Foundation; eithe r version 2 of the License, or |
9 | * (at your option) any later version. | 9 | * (at your option) any later version. |
10 | * | 10 | * |
11 | * This program is distributed in the hope that it will be useful, | 11 | * This program is distributed in the hope that it will be useful, |
@@ -815,6 +815,7 @@ int checkcfg(int val); | |||
815 | void print_compiletime_support(void); | 815 | void print_compiletime_support(void); |
816 | 816 | ||
817 | // appimage.c | 817 | // appimage.c |
818 | int appimage_find_profile(const char *archive); | ||
818 | void appimage_set(const char *appimage_path); | 819 | void appimage_set(const char *appimage_path); |
819 | void appimage_mount(void); | 820 | void appimage_mount(void); |
820 | void appimage_clear(void); | 821 | void appimage_clear(void); |
diff --git a/src/firejail/main.c b/src/firejail/main.c index 12ac01de7..c6dda268d 100644 --- a/src/firejail/main.c +++ b/src/firejail/main.c | |||
@@ -2819,6 +2819,11 @@ int main(int argc, char **argv, char **envp) { | |||
2819 | // build the sandbox command | 2819 | // build the sandbox command |
2820 | if (prog_index == -1 && cfg.shell) { | 2820 | if (prog_index == -1 && cfg.shell) { |
2821 | assert(cfg.command_line == NULL); // runs cfg.shell | 2821 | assert(cfg.command_line == NULL); // runs cfg.shell |
2822 | if (arg_appimage) { | ||
2823 | fprintf(stderr, "Error: no appimage archive specified\n"); | ||
2824 | exit(1); | ||
2825 | } | ||
2826 | |||
2822 | cfg.window_title = cfg.shell; | 2827 | cfg.window_title = cfg.shell; |
2823 | cfg.command_name = cfg.shell; | 2828 | cfg.command_name = cfg.shell; |
2824 | } | 2829 | } |
@@ -2844,7 +2849,13 @@ int main(int argc, char **argv, char **envp) { | |||
2844 | 2849 | ||
2845 | // load the profile | 2850 | // load the profile |
2846 | if (!arg_noprofile && !custom_profile) { | 2851 | if (!arg_noprofile && !custom_profile) { |
2847 | custom_profile = profile_find_firejail(cfg.command_name, 1); | 2852 | if (arg_appimage) { |
2853 | custom_profile = appimage_find_profile(cfg.command_name); | ||
2854 | // disable shell=* for appimages | ||
2855 | arg_shell_none = 0; | ||
2856 | } | ||
2857 | else | ||
2858 | custom_profile = profile_find_firejail(cfg.command_name, 1); | ||
2848 | } | 2859 | } |
2849 | 2860 | ||
2850 | // use default.profile as the default | 2861 | // use default.profile as the default |
@@ -2858,7 +2869,7 @@ int main(int argc, char **argv, char **envp) { | |||
2858 | custom_profile = profile_find_firejail(profile_name, 1); | 2869 | custom_profile = profile_find_firejail(profile_name, 1); |
2859 | 2870 | ||
2860 | if (!custom_profile) { | 2871 | if (!custom_profile) { |
2861 | fprintf(stderr, "Error: no default.profile installed\n"); | 2872 | fprintf(stderr, "Error: no %s installed\n", profile_name); |
2862 | exit(1); | 2873 | exit(1); |
2863 | } | 2874 | } |
2864 | 2875 | ||