Skip to content

Commit

Permalink
private-lib: minor simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
smitsohu committed Feb 24, 2021
1 parent e7eaf95 commit 04cdc12
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/firejail/fs_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,10 @@ void fslib_duplicate(const char *full_path) {
lib_cnt++;
}


// requires full path for lib
// it could be a library or an executable
// lib is not copied, only libraries used by it
static void fslib_copy_libs(const char *full_path, unsigned mask) {
// if library/executable does not exist or the user does not have read access to it
// print a warning and exit the function.
if (((mask & SBOX_USER) && access(full_path, R_OK)) ||
((mask & SBOX_ROOT) && access(full_path, F_OK))) {
if (arg_debug || arg_debug_private_lib)
printf("cannot find %s for private-lib, skipping...\n", full_path);
return;
}

// create an empty RUN_LIB_FILE and allow the user to write to it
unlink(RUN_LIB_FILE); // in case is there
create_empty_file_as_root(RUN_LIB_FILE, 0644);
Expand Down Expand Up @@ -186,13 +176,28 @@ void fslib_copy_libs_parse_as_root(const char *full_path) {
assert(full_path);
if (arg_debug || arg_debug_private_lib)
printf(" fslib_copy_libs_parse_as_root %s\n", full_path);

struct stat s;
if (stat(full_path, &s)) {
if (arg_debug || arg_debug_private_lib)
printf("cannot find %s for private-lib, skipping...\n", full_path);
return;
}
fslib_copy_libs(full_path, SBOX_ROOT);
}

// if library/executable does not exist or the user does not have read access to it
// print a warning and exit the function.
void fslib_copy_libs_parse_as_user(const char *full_path) {
assert(full_path);
if (arg_debug || arg_debug_private_lib)
printf(" fslib_copy_libs_parse_as_user %s\n", full_path);

if (access(full_path, R_OK)) {
if (arg_debug || arg_debug_private_lib)
printf("cannot find %s for private-lib, skipping...\n", full_path);
return;
}
fslib_copy_libs(full_path, SBOX_USER);
}

Expand Down

0 comments on commit 04cdc12

Please sign in to comment.