aboutsummaryrefslogtreecommitdiffstats
path: root/src/fcopy
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@yahoo.com>2017-02-15 19:51:50 -0500
committerLibravatar netblue30 <netblue30@yahoo.com>2017-02-15 19:51:50 -0500
commitf4ab39bfce61aa7b61b860fab96488b7f3e8fb66 (patch)
treeae8cae477d8a19cdf3a107b1dcfb3c8cbfef480d /src/fcopy
parentmerge #1100 from zackw: fcopy rework, --follow-link support in fcopy (diff)
downloadfirejail-f4ab39bfce61aa7b61b860fab96488b7f3e8fb66.tar.gz
firejail-f4ab39bfce61aa7b61b860fab96488b7f3e8fb66.tar.zst
firejail-f4ab39bfce61aa7b61b860fab96488b7f3e8fb66.zip
merge #1100 from zackw: follow link support in --private-bin
Diffstat (limited to 'src/fcopy')
-rw-r--r--src/fcopy/main.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/fcopy/main.c b/src/fcopy/main.c
index 089152efc..9f19b6dd8 100644
--- a/src/fcopy/main.c
+++ b/src/fcopy/main.c
@@ -23,6 +23,8 @@
23#include <ftw.h> 23#include <ftw.h>
24#include <errno.h> 24#include <errno.h>
25 25
26static int arg_follow_link = 0;
27
26 28
27#define COPY_LIMIT (500 * 1024 *1024) 29#define COPY_LIMIT (500 * 1024 *1024)
28static int size_limit_reached = 0; 30static int size_limit_reached = 0;
@@ -221,7 +223,7 @@ static void duplicate_dir(const char *src, const char *dest, struct stat *s) {
221} 223}
222 224
223static void duplicate_file(const char *src, const char *dest, struct stat *s) { 225static void duplicate_file(const char *src, const char *dest, struct stat *s) {
224 char *rsrc = check(src); // we drop the result and use the original name 226 char *rsrc = check(src);
225 char *rdest = check(dest); 227 char *rdest = check(dest);
226 uid_t uid = s->st_uid; 228 uid_t uid = s->st_uid;
227 gid_t gid = s->st_gid; 229 gid_t gid = s->st_gid;
@@ -229,7 +231,7 @@ static void duplicate_file(const char *src, const char *dest, struct stat *s) {
229 231
230 // build destination file name 232 // build destination file name
231 char *name; 233 char *name;
232 char *ptr = strrchr(src, '/'); 234 char *ptr = (arg_follow_link)? strrchr(src, '/'): strrchr(rsrc, '/');
233 ptr++; 235 ptr++;
234 if (asprintf(&name, "%s/%s", rdest, ptr) == -1) 236 if (asprintf(&name, "%s/%s", rdest, ptr) == -1)
235 errExit("asprintf"); 237 errExit("asprintf");
@@ -251,7 +253,7 @@ static void duplicate_link(const char *src, const char *dest, struct stat *s) {
251 253
252 // build destination file name 254 // build destination file name
253 char *name; 255 char *name;
254// char *ptr = strrchr(rsrc, '/'); 256// char *ptr = strrchr(rsrc, '/');
255 char *ptr = strrchr(src, '/'); 257 char *ptr = strrchr(src, '/');
256 ptr++; 258 ptr++;
257 if (asprintf(&name, "%s/%s", rdest, ptr) == -1) 259 if (asprintf(&name, "%s/%s", rdest, ptr) == -1)
@@ -287,19 +289,19 @@ printf("\n");
287#endif 289#endif
288 char *src; 290 char *src;
289 char *dest; 291 char *dest;
290 int follow_link;
291 292
292 if (argc == 3) { 293 if (argc == 3) {
293 src = argv[1]; 294 src = argv[1];
294 dest = argv[2]; 295 dest = argv[2];
295 follow_link = 0; 296 arg_follow_link = 0;
296 } 297 }
297 else if (argc == 4 && !strcmp(argv[1], "--follow-link")) { 298 else if (argc == 4 && !strcmp(argv[1], "--follow-link")) {
298 src = argv[2]; 299 src = argv[2];
299 dest = argv[3]; 300 dest = argv[3];
300 follow_link = 1; 301 arg_follow_link = 1;
301 } 302 }
302 else { 303 else {
304 fprintf(stderr, "Error: arguments missing\n");
303 usage(); 305 usage();
304 exit(1); 306 exit(1);
305 } 307 }
@@ -334,7 +336,7 @@ printf("\n");
334 } 336 }
335 337
336 // copy files 338 // copy files
337 if ((follow_link ? stat : lstat)(src, &s) == -1) { 339 if ((arg_follow_link ? stat : lstat)(src, &s) == -1) {
338 fprintf(stderr, "Error fcopy: src %s: %s\n", src, strerror(errno)); 340 fprintf(stderr, "Error fcopy: src %s: %s\n", src, strerror(errno));
339 exit(1); 341 exit(1);
340 } 342 }