Skip to content

Commit

Permalink
Add --mkdir and --mkfile command line options for firejail
Browse files Browse the repository at this point in the history
Profile files are defined as a means to "pass several command line
arguments to firejail" but apparently for example mkdir and mkfile
options are available in context of profile files, but can't be
specified directly from command line.

Add support for -mkdir and --mkfile options so that executing:
  firejail --mkdir=${HOME}/directory/path\
           --whitelist=${HOME}/directory/path

behaves similarly as having profile file content:
  mkdir ${HOME}/directory/path
  whitelist ${HOME}/directory/path

Signed-off-by: Simo Piiroinen <[email protected]>
Signed-off-by: Tomi Leppänen <[email protected]>
  • Loading branch information
spiiroin authored and Tomin1 committed Feb 25, 2021
1 parent 8a7b969 commit 2dc81fa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/firejail/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,26 @@ int main(int argc, char **argv, char **envp) {
profile_add(line);
}
#endif

else if (strncmp(argv[i], "--mkdir=", 8) == 0) {
char *line;
if (asprintf(&line, "mkdir %s", argv[i] + 8) == -1)
errExit("asprintf");
/* Note: Applied both immediately in profile_check_line()
* and later on via fs_blacklist().
*/
profile_check_line(line, 0, NULL);
profile_add(line);
}
else if (strncmp(argv[i], "--mkfile=", 9) == 0) {
char *line;
if (asprintf(&line, "mkfile %s", argv[i] + 9) == -1)
errExit("asprintf");
/* Note: Applied both immediately in profile_check_line()
* and later on via fs_blacklist().
*/
profile_check_line(line, 0, NULL);
profile_add(line);
}
else if (strncmp(argv[i], "--read-only=", 12) == 0) {
char *line;
if (asprintf(&line, "read-only %s", argv[i] + 12) == -1)
Expand Down
2 changes: 2 additions & 0 deletions src/firejail/usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ static char *usage_str =
#ifdef HAVE_WHITELIST
" --whitelist=filename - whitelist directory or file.\n"
#endif
" --mkdir=dirname - create a directory.\n"
" --mkfile=filename - create a file.\n"
" --writable-etc - /etc directory is mounted read-write.\n"
" --writable-run-user - allow access to /run/user/$UID/systemd and\n"
"\t/run/user/$UID/gnupg.\n"
Expand Down

0 comments on commit 2dc81fa

Please sign in to comment.