aboutsummaryrefslogtreecommitdiffstats
path: root/src/fcopy
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@yahoo.com>2019-07-04 12:22:07 -0400
committerLibravatar netblue30 <netblue30@yahoo.com>2019-07-04 12:22:07 -0400
commitccd01529adc647e75b618aa35c1742cffd17c694 (patch)
tree67a6bcaace93559f9f96aa620213b71997dbc798 /src/fcopy
parentMerge pull request #2825 from Bandie/master (diff)
downloadfirejail-ccd01529adc647e75b618aa35c1742cffd17c694.tar.gz
firejail-ccd01529adc647e75b618aa35c1742cffd17c694.tar.zst
firejail-ccd01529adc647e75b618aa35c1742cffd17c694.zip
fix #2820 - adjustable file copy limit; export FIREJAIL_DEBUG into sbox
Diffstat (limited to 'src/fcopy')
-rw-r--r--src/fcopy/main.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/fcopy/main.c b/src/fcopy/main.c
index 9fca2a39b..3f507a361 100644
--- a/src/fcopy/main.c
+++ b/src/fcopy/main.c
@@ -25,9 +25,11 @@
25#include <pwd.h> 25#include <pwd.h>
26 26
27int arg_quiet = 0; 27int arg_quiet = 0;
28int arg_debug = 0;
28static int arg_follow_link = 0; 29static int arg_follow_link = 0;
29 30
30#define COPY_LIMIT (500 * 1024 *1024) 31static int copy_limit = 500 * 1024 *1024; // 500 MB
32#define COPY_LIMIT (
31static int size_limit_reached = 0; 33static int size_limit_reached = 0;
32static unsigned file_cnt = 0; 34static unsigned file_cnt = 0;
33static unsigned size_cnt = 0; 35static unsigned size_cnt = 0;
@@ -184,8 +186,8 @@ static int fs_copydir(const char *infname, const struct stat *st, int ftype, str
184 mode_t mode = s.st_mode; 186 mode_t mode = s.st_mode;
185 187
186 // recalculate size 188 // recalculate size
187 if ((s.st_size + size_cnt) > COPY_LIMIT) { 189 if ((s.st_size + size_cnt) > copy_limit) {
188 fprintf(stderr, "Error fcopy: size limit of %dMB reached\n", (COPY_LIMIT / 1024) / 1024); 190 fprintf(stderr, "Error fcopy: size limit of %dMB reached\n", (copy_limit / 1024) / 1024);
189 size_limit_reached = 1; 191 size_limit_reached = 1;
190 free(outfname); 192 free(outfname);
191 return 0; 193 return 0;
@@ -330,6 +332,9 @@ int main(int argc, char **argv) {
330 char *quiet = getenv("FIREJAIL_QUIET"); 332 char *quiet = getenv("FIREJAIL_QUIET");
331 if (quiet && strcmp(quiet, "yes") == 0) 333 if (quiet && strcmp(quiet, "yes") == 0)
332 arg_quiet = 1; 334 arg_quiet = 1;
335 char *debug = getenv("FIREJAIL_DEBUG");
336 if (debug && strcmp(debug, "yes") == 0)
337 arg_debug = 1;
333 338
334 char *src; 339 char *src;
335 char *dest; 340 char *dest;
@@ -384,6 +389,14 @@ int main(int argc, char **argv) {
384 exit(1); 389 exit(1);
385 } 390 }
386 391
392 // extract copy limit size from env variable, if any
393 char *cl = getenv("FIREJAIL_FILE_COPY_LIMIT");
394 if (cl) {
395 copy_limit = atoi(cl) * 1024 * 1024;
396 if (arg_debug)
397 printf("file copy limit %d bytes\n", copy_limit);
398 }
399
387 // copy files 400 // copy files
388 if ((arg_follow_link ? stat : lstat)(src, &s) == -1) { 401 if ((arg_follow_link ? stat : lstat)(src, &s) == -1) {
389 fprintf(stderr, "Error fcopy: src %s: %s\n", src, strerror(errno)); 402 fprintf(stderr, "Error fcopy: src %s: %s\n", src, strerror(errno));