diff options
author | 2016-06-05 10:38:02 -0400 | |
---|---|---|
committer | 2016-06-05 10:38:02 -0400 | |
commit | a4444baae73f99dc57b6eb337182f26c553b0094 (patch) | |
tree | 78af4aa55c16b6db787ddddb59714829e99fdded /src/firejail/appimage.c | |
parent | networking fixes (diff) | |
download | firejail-a4444baae73f99dc57b6eb337182f26c553b0094.tar.gz firejail-a4444baae73f99dc57b6eb337182f26c553b0094.tar.zst firejail-a4444baae73f99dc57b6eb337182f26c553b0094.zip |
appimage support
Diffstat (limited to 'src/firejail/appimage.c')
-rw-r--r-- | src/firejail/appimage.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/src/firejail/appimage.c b/src/firejail/appimage.c new file mode 100644 index 000000000..e25d50a2d --- /dev/null +++ b/src/firejail/appimage.c | |||
@@ -0,0 +1,94 @@ | |||
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 | // http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=770fe30a46a12b6fb6b63fbe1737654d28e84844 | ||
21 | // sudo mount -o loop krita-3.0-x86_64.appimage mnt | ||
22 | |||
23 | #include "firejail.h" | ||
24 | #include <sys/types.h> | ||
25 | #include <sys/stat.h> | ||
26 | #include <sys/mount.h> | ||
27 | #include <fcntl.h> | ||
28 | #include <linux/loop.h> | ||
29 | |||
30 | |||
31 | |||
32 | char *appimage_set(const char *appimage_path) { | ||
33 | assert(appimage_path); | ||
34 | EUID_ASSERT(); | ||
35 | |||
36 | // check appimage_path | ||
37 | if (access(appimage_path, R_OK) == -1) { | ||
38 | fprintf(stderr, "Error: cannot access AppImage file\n"); | ||
39 | exit(1); | ||
40 | } | ||
41 | |||
42 | EUID_ROOT(); | ||
43 | |||
44 | // find or allocate a free loop device to use | ||
45 | int cfd = open("/dev/loop-control", O_RDWR); | ||
46 | int devnr = ioctl(cfd, LOOP_CTL_GET_FREE); | ||
47 | if (devnr == -1) { | ||
48 | fprintf(stderr, "Error: cannot allocate a new loopback device\n"); | ||
49 | exit(1); | ||
50 | } | ||
51 | close(cfd); | ||
52 | char *devloop; | ||
53 | if (asprintf(&devloop, "/dev/loop%d", devnr) == -1) | ||
54 | errExit("asprintf"); | ||
55 | |||
56 | int ffd = open(appimage_path, O_RDONLY|O_CLOEXEC); | ||
57 | int lfd = open(devloop, O_RDONLY); | ||
58 | if (ioctl(lfd, LOOP_SET_FD, ffd) == -1) { | ||
59 | fprintf(stderr, "Error: cannot configure the loopback device\n"); | ||
60 | exit(1); | ||
61 | } | ||
62 | close(lfd); | ||
63 | close(ffd); | ||
64 | |||
65 | char dirname[] = "/tmp/firejail-mnt-XXXXXX"; | ||
66 | char *mntdir = strdup(mkdtemp(dirname)); | ||
67 | if (mntdir == NULL) { | ||
68 | fprintf(stderr, "Error: cannot create temporary directory\n"); | ||
69 | exit(1); | ||
70 | } | ||
71 | mkdir(mntdir, 755); | ||
72 | chown(mntdir, getuid(), getgid()); | ||
73 | chmod(mntdir, 755); | ||
74 | |||
75 | char *mode; | ||
76 | if (asprintf(&mode, "mode=755,uid=%d,gid=%d", getuid(), getgid()) == -1) | ||
77 | errExit("asprintf"); | ||
78 | |||
79 | if (mount(devloop, mntdir, "iso9660",MS_MGC_VAL|MS_RDONLY, mode) < 0) | ||
80 | errExit("mounting appimage"); | ||
81 | |||
82 | if (arg_debug) | ||
83 | printf("appimage mounted on %s\n", mntdir); | ||
84 | EUID_USER(); | ||
85 | |||
86 | // build new command line | ||
87 | if (asprintf(&cfg.command_line, "%s/AppRun", mntdir) == -1) | ||
88 | errExit("asprintf"); | ||
89 | |||
90 | free(devloop); | ||
91 | free(mode); | ||
92 | |||
93 | return mntdir; | ||
94 | } | ||