aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@yahoo.com>2015-12-06 19:37:08 -0500
committerLibravatar netblue30 <netblue30@yahoo.com>2015-12-06 19:37:08 -0500
commit1365b0d41b013a8fd209acfd2f7adefb9b6adbdc (patch)
tree48e0ce6dad2ecf712cbc5b598b222209d93501f4 /src
parenttracelog (diff)
downloadfirejail-1365b0d41b013a8fd209acfd2f7adefb9b6adbdc.tar.gz
firejail-1365b0d41b013a8fd209acfd2f7adefb9b6adbdc.tar.zst
firejail-1365b0d41b013a8fd209acfd2f7adefb9b6adbdc.zip
tracelog fixes
Diffstat (limited to 'src')
-rw-r--r--src/libtracelog/libtracelog.c83
1 files changed, 82 insertions, 1 deletions
diff --git a/src/libtracelog/libtracelog.c b/src/libtracelog/libtracelog.c
index d89998f61..0e133d7e4 100644
--- a/src/libtracelog/libtracelog.c
+++ b/src/libtracelog/libtracelog.c
@@ -32,7 +32,7 @@
32#include <syslog.h> 32#include <syslog.h>
33#include <dirent.h> 33#include <dirent.h>
34 34
35//#define DEBUG 35#define DEBUG
36 36
37// break recursivity on fopen call 37// break recursivity on fopen call
38typedef FILE *(*orig_fopen_t)(const char *pathname, const char *mode); 38typedef FILE *(*orig_fopen_t)(const char *pathname, const char *mode);
@@ -63,6 +63,9 @@ static inline uint32_t hash(const char *str) {
63} 63}
64 64
65static void storage_add(const char *str) { 65static void storage_add(const char *str) {
66#ifdef DEBUG
67 printf("add %s\n", str);
68#endif
66 ListElem *ptr = malloc(sizeof(ListElem)); 69 ListElem *ptr = malloc(sizeof(ListElem));
67 if (!ptr) { 70 if (!ptr) {
68 fprintf(stderr, "Error: cannot allocate memory\n"); 71 fprintf(stderr, "Error: cannot allocate memory\n");
@@ -82,11 +85,20 @@ static void storage_add(const char *str) {
82} 85}
83 86
84static char *storage_find(const char *str) { 87static char *storage_find(const char *str) {
88#ifdef DEBUG
89 printf("storage find %s\n", str);
90#endif
85 const char *tofind = str; 91 const char *tofind = str;
86 int allocated = 0; 92 int allocated = 0;
87 93
88 if (strstr(str, "..") || strstr(str, "/./")) { 94 if (strstr(str, "..") || strstr(str, "/./")) {
89 tofind = realpath(str, NULL); 95 tofind = realpath(str, NULL);
96 if (!tofind) {
97#ifdef DEBUG
98 printf("realpath failed\n");
99#endif
100 return NULL;
101 }
90 allocated = 1; 102 allocated = 1;
91 } 103 }
92 104
@@ -96,6 +108,9 @@ static char *storage_find(const char *str) {
96 if (strcmp(tofind, ptr->path) == 0) { 108 if (strcmp(tofind, ptr->path) == 0) {
97 if (allocated) 109 if (allocated)
98 free((char *) tofind); 110 free((char *) tofind);
111#ifdef DEBUG
112 printf("storage found\n");
113#endif
99 return ptr->path; 114 return ptr->path;
100 } 115 }
101 ptr = ptr->next; 116 ptr = ptr->next;
@@ -103,6 +118,9 @@ static char *storage_find(const char *str) {
103 118
104 if (allocated) 119 if (allocated)
105 free((char *) tofind); 120 free((char *) tofind);
121#ifdef DEBUG
122 printf("storage not found\n");
123#endif
106 return NULL; 124 return NULL;
107} 125}
108 126
@@ -249,6 +267,9 @@ static char *name(void) {
249typedef int (*orig_open_t)(const char *pathname, int flags, mode_t mode); 267typedef int (*orig_open_t)(const char *pathname, int flags, mode_t mode);
250static orig_open_t orig_open = NULL; 268static orig_open_t orig_open = NULL;
251int open(const char *pathname, int flags, mode_t mode) { 269int open(const char *pathname, int flags, mode_t mode) {
270#ifdef DEBUG
271 printf("%s\n", __FUNCTION__);
272#endif
252 if (!orig_open) 273 if (!orig_open)
253 orig_open = (orig_open_t)dlsym(RTLD_NEXT, "open"); 274 orig_open = (orig_open_t)dlsym(RTLD_NEXT, "open");
254 275
@@ -261,9 +282,16 @@ int open(const char *pathname, int flags, mode_t mode) {
261 return rv; 282 return rv;
262} 283}
263 284
285
286
287
288//#if 0 - todo: fix problems on google-chrome and opera - seems to be crashing when open64 is called
264typedef int (*orig_open64_t)(const char *pathname, int flags, mode_t mode); 289typedef int (*orig_open64_t)(const char *pathname, int flags, mode_t mode);
265static orig_open64_t orig_open64 = NULL; 290static orig_open64_t orig_open64 = NULL;
266int open64(const char *pathname, int flags, mode_t mode) { 291int open64(const char *pathname, int flags, mode_t mode) {
292#ifdef DEBUG
293 printf("%s %s\n", __FUNCTION__, pathname);
294#endif
267 if (!orig_open64) 295 if (!orig_open64)
268 orig_open64 = (orig_open64_t)dlsym(RTLD_NEXT, "open64"); 296 orig_open64 = (orig_open64_t)dlsym(RTLD_NEXT, "open64");
269 if (!blacklist_loaded) 297 if (!blacklist_loaded)
@@ -274,11 +302,16 @@ int open64(const char *pathname, int flags, mode_t mode) {
274 sendlog(name(), __FUNCTION__, pathname); 302 sendlog(name(), __FUNCTION__, pathname);
275 return rv; 303 return rv;
276} 304}
305//#endif
306
277 307
278// openat 308// openat
279typedef int (*orig_openat_t)(int dirfd, const char *pathname, int flags, mode_t mode); 309typedef int (*orig_openat_t)(int dirfd, const char *pathname, int flags, mode_t mode);
280static orig_openat_t orig_openat = NULL; 310static orig_openat_t orig_openat = NULL;
281int openat(int dirfd, const char *pathname, int flags, mode_t mode) { 311int openat(int dirfd, const char *pathname, int flags, mode_t mode) {
312#ifdef DEBUG
313 printf("%s\n", __FUNCTION__);
314#endif
282 if (!orig_openat) 315 if (!orig_openat)
283 orig_openat = (orig_openat_t)dlsym(RTLD_NEXT, "openat"); 316 orig_openat = (orig_openat_t)dlsym(RTLD_NEXT, "openat");
284 if (!blacklist_loaded) 317 if (!blacklist_loaded)
@@ -293,6 +326,9 @@ int openat(int dirfd, const char *pathname, int flags, mode_t mode) {
293typedef int (*orig_openat64_t)(int dirfd, const char *pathname, int flags, mode_t mode); 326typedef int (*orig_openat64_t)(int dirfd, const char *pathname, int flags, mode_t mode);
294static orig_openat64_t orig_openat64 = NULL; 327static orig_openat64_t orig_openat64 = NULL;
295int openat64(int dirfd, const char *pathname, int flags, mode_t mode) { 328int openat64(int dirfd, const char *pathname, int flags, mode_t mode) {
329#ifdef DEBUG
330 printf("%s\n", __FUNCTION__);
331#endif
296 if (!orig_openat64) 332 if (!orig_openat64)
297 orig_openat64 = (orig_openat64_t)dlsym(RTLD_NEXT, "openat64"); 333 orig_openat64 = (orig_openat64_t)dlsym(RTLD_NEXT, "openat64");
298 if (!blacklist_loaded) 334 if (!blacklist_loaded)
@@ -307,6 +343,9 @@ int openat64(int dirfd, const char *pathname, int flags, mode_t mode) {
307 343
308// fopen 344// fopen
309FILE *fopen(const char *pathname, const char *mode) { 345FILE *fopen(const char *pathname, const char *mode) {
346#ifdef DEBUG
347 printf("%s\n", __FUNCTION__);
348#endif
310 if (!orig_fopen) 349 if (!orig_fopen)
311 orig_fopen = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen"); 350 orig_fopen = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen");
312 if (!blacklist_loaded) 351 if (!blacklist_loaded)
@@ -320,6 +359,9 @@ FILE *fopen(const char *pathname, const char *mode) {
320 359
321#ifdef __GLIBC__ 360#ifdef __GLIBC__
322FILE *fopen64(const char *pathname, const char *mode) { 361FILE *fopen64(const char *pathname, const char *mode) {
362#ifdef DEBUG
363 printf("%s\n", __FUNCTION__);
364#endif
323 if (!orig_fopen64) 365 if (!orig_fopen64)
324 orig_fopen64 = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen64"); 366 orig_fopen64 = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen64");
325 if (!blacklist_loaded) 367 if (!blacklist_loaded)
@@ -337,6 +379,9 @@ FILE *fopen64(const char *pathname, const char *mode) {
337typedef FILE *(*orig_freopen_t)(const char *pathname, const char *mode, FILE *stream); 379typedef FILE *(*orig_freopen_t)(const char *pathname, const char *mode, FILE *stream);
338static orig_freopen_t orig_freopen = NULL; 380static orig_freopen_t orig_freopen = NULL;
339FILE *freopen(const char *pathname, const char *mode, FILE *stream) { 381FILE *freopen(const char *pathname, const char *mode, FILE *stream) {
382#ifdef DEBUG
383 printf("%s\n", __FUNCTION__);
384#endif
340 if (!orig_freopen) 385 if (!orig_freopen)
341 orig_freopen = (orig_freopen_t)dlsym(RTLD_NEXT, "freopen"); 386 orig_freopen = (orig_freopen_t)dlsym(RTLD_NEXT, "freopen");
342 if (!blacklist_loaded) 387 if (!blacklist_loaded)
@@ -352,6 +397,9 @@ FILE *freopen(const char *pathname, const char *mode, FILE *stream) {
352typedef FILE *(*orig_freopen64_t)(const char *pathname, const char *mode, FILE *stream); 397typedef FILE *(*orig_freopen64_t)(const char *pathname, const char *mode, FILE *stream);
353static orig_freopen64_t orig_freopen64 = NULL; 398static orig_freopen64_t orig_freopen64 = NULL;
354FILE *freopen64(const char *pathname, const char *mode, FILE *stream) { 399FILE *freopen64(const char *pathname, const char *mode, FILE *stream) {
400#ifdef DEBUG
401 printf("%s\n", __FUNCTION__);
402#endif
355 if (!orig_freopen64) 403 if (!orig_freopen64)
356 orig_freopen64 = (orig_freopen64_t)dlsym(RTLD_NEXT, "freopen64"); 404 orig_freopen64 = (orig_freopen64_t)dlsym(RTLD_NEXT, "freopen64");
357 if (!blacklist_loaded) 405 if (!blacklist_loaded)
@@ -368,6 +416,9 @@ FILE *freopen64(const char *pathname, const char *mode, FILE *stream) {
368typedef int (*orig_unlink_t)(const char *pathname); 416typedef int (*orig_unlink_t)(const char *pathname);
369static orig_unlink_t orig_unlink = NULL; 417static orig_unlink_t orig_unlink = NULL;
370int unlink(const char *pathname) { 418int unlink(const char *pathname) {
419#ifdef DEBUG
420 printf("%s\n", __FUNCTION__);
421#endif
371 if (!orig_unlink) 422 if (!orig_unlink)
372 orig_unlink = (orig_unlink_t)dlsym(RTLD_NEXT, "unlink"); 423 orig_unlink = (orig_unlink_t)dlsym(RTLD_NEXT, "unlink");
373 if (!blacklist_loaded) 424 if (!blacklist_loaded)
@@ -382,6 +433,9 @@ int unlink(const char *pathname) {
382typedef int (*orig_unlinkat_t)(int dirfd, const char *pathname, int flags); 433typedef int (*orig_unlinkat_t)(int dirfd, const char *pathname, int flags);
383static orig_unlinkat_t orig_unlinkat = NULL; 434static orig_unlinkat_t orig_unlinkat = NULL;
384int unlinkat(int dirfd, const char *pathname, int flags) { 435int unlinkat(int dirfd, const char *pathname, int flags) {
436#ifdef DEBUG
437 printf("%s\n", __FUNCTION__);
438#endif
385 if (!orig_unlinkat) 439 if (!orig_unlinkat)
386 orig_unlinkat = (orig_unlinkat_t)dlsym(RTLD_NEXT, "unlinkat"); 440 orig_unlinkat = (orig_unlinkat_t)dlsym(RTLD_NEXT, "unlinkat");
387 if (!blacklist_loaded) 441 if (!blacklist_loaded)
@@ -397,6 +451,9 @@ int unlinkat(int dirfd, const char *pathname, int flags) {
397typedef int (*orig_mkdir_t)(const char *pathname, mode_t mode); 451typedef int (*orig_mkdir_t)(const char *pathname, mode_t mode);
398static orig_mkdir_t orig_mkdir = NULL; 452static orig_mkdir_t orig_mkdir = NULL;
399int mkdir(const char *pathname, mode_t mode) { 453int mkdir(const char *pathname, mode_t mode) {
454#ifdef DEBUG
455 printf("%s\n", __FUNCTION__);
456#endif
400 if (!orig_mkdir) 457 if (!orig_mkdir)
401 orig_mkdir = (orig_mkdir_t)dlsym(RTLD_NEXT, "mkdir"); 458 orig_mkdir = (orig_mkdir_t)dlsym(RTLD_NEXT, "mkdir");
402 if (!blacklist_loaded) 459 if (!blacklist_loaded)
@@ -411,6 +468,9 @@ int mkdir(const char *pathname, mode_t mode) {
411typedef int (*orig_mkdirat_t)(int dirfd, const char *pathname, mode_t mode); 468typedef int (*orig_mkdirat_t)(int dirfd, const char *pathname, mode_t mode);
412static orig_mkdirat_t orig_mkdirat = NULL; 469static orig_mkdirat_t orig_mkdirat = NULL;
413int mkdirat(int dirfd, const char *pathname, mode_t mode) { 470int mkdirat(int dirfd, const char *pathname, mode_t mode) {
471#ifdef DEBUG
472 printf("%s\n", __FUNCTION__);
473#endif
414 if (!orig_mkdirat) 474 if (!orig_mkdirat)
415 orig_mkdirat = (orig_mkdirat_t)dlsym(RTLD_NEXT, "mkdirat"); 475 orig_mkdirat = (orig_mkdirat_t)dlsym(RTLD_NEXT, "mkdirat");
416 if (!blacklist_loaded) 476 if (!blacklist_loaded)
@@ -425,6 +485,9 @@ int mkdirat(int dirfd, const char *pathname, mode_t mode) {
425typedef int (*orig_rmdir_t)(const char *pathname); 485typedef int (*orig_rmdir_t)(const char *pathname);
426static orig_rmdir_t orig_rmdir = NULL; 486static orig_rmdir_t orig_rmdir = NULL;
427int rmdir(const char *pathname) { 487int rmdir(const char *pathname) {
488#ifdef DEBUG
489 printf("%s\n", __FUNCTION__);
490#endif
428 if (!orig_rmdir) 491 if (!orig_rmdir)
429 orig_rmdir = (orig_rmdir_t)dlsym(RTLD_NEXT, "rmdir"); 492 orig_rmdir = (orig_rmdir_t)dlsym(RTLD_NEXT, "rmdir");
430 if (!blacklist_loaded) 493 if (!blacklist_loaded)
@@ -440,6 +503,9 @@ int rmdir(const char *pathname) {
440typedef int (*orig_stat_t)(const char *pathname, struct stat *buf); 503typedef int (*orig_stat_t)(const char *pathname, struct stat *buf);
441static orig_stat_t orig_stat = NULL; 504static orig_stat_t orig_stat = NULL;
442int stat(const char *pathname, struct stat *buf) { 505int stat(const char *pathname, struct stat *buf) {
506#ifdef DEBUG
507 printf("%s\n", __FUNCTION__);
508#endif
443 if (!orig_stat) 509 if (!orig_stat)
444 orig_stat = (orig_stat_t)dlsym(RTLD_NEXT, "stat"); 510 orig_stat = (orig_stat_t)dlsym(RTLD_NEXT, "stat");
445 if (!blacklist_loaded) 511 if (!blacklist_loaded)
@@ -455,6 +521,9 @@ int stat(const char *pathname, struct stat *buf) {
455typedef int (*orig_stat64_t)(const char *pathname, struct stat64 *buf); 521typedef int (*orig_stat64_t)(const char *pathname, struct stat64 *buf);
456static orig_stat64_t orig_stat64 = NULL; 522static orig_stat64_t orig_stat64 = NULL;
457int stat64(const char *pathname, struct stat64 *buf) { 523int stat64(const char *pathname, struct stat64 *buf) {
524#ifdef DEBUG
525 printf("%s\n", __FUNCTION__);
526#endif
458 if (!orig_stat) 527 if (!orig_stat)
459 orig_stat64 = (orig_stat64_t)dlsym(RTLD_NEXT, "stat64"); 528 orig_stat64 = (orig_stat64_t)dlsym(RTLD_NEXT, "stat64");
460 if (!blacklist_loaded) 529 if (!blacklist_loaded)
@@ -470,6 +539,9 @@ int stat64(const char *pathname, struct stat64 *buf) {
470typedef int (*orig_lstat_t)(const char *pathname, struct stat *buf); 539typedef int (*orig_lstat_t)(const char *pathname, struct stat *buf);
471static orig_lstat_t orig_lstat = NULL; 540static orig_lstat_t orig_lstat = NULL;
472int lstat(const char *pathname, struct stat *buf) { 541int lstat(const char *pathname, struct stat *buf) {
542#ifdef DEBUG
543 printf("%s\n", __FUNCTION__);
544#endif
473 if (!orig_lstat) 545 if (!orig_lstat)
474 orig_lstat = (orig_lstat_t)dlsym(RTLD_NEXT, "lstat"); 546 orig_lstat = (orig_lstat_t)dlsym(RTLD_NEXT, "lstat");
475 if (!blacklist_loaded) 547 if (!blacklist_loaded)
@@ -485,6 +557,9 @@ int lstat(const char *pathname, struct stat *buf) {
485typedef int (*orig_lstat64_t)(const char *pathname, struct stat64 *buf); 557typedef int (*orig_lstat64_t)(const char *pathname, struct stat64 *buf);
486static orig_lstat64_t orig_lstat64 = NULL; 558static orig_lstat64_t orig_lstat64 = NULL;
487int lstat64(const char *pathname, struct stat64 *buf) { 559int lstat64(const char *pathname, struct stat64 *buf) {
560#ifdef DEBUG
561 printf("%s\n", __FUNCTION__);
562#endif
488 if (!orig_lstat) 563 if (!orig_lstat)
489 orig_lstat64 = (orig_lstat64_t)dlsym(RTLD_NEXT, "lstat64"); 564 orig_lstat64 = (orig_lstat64_t)dlsym(RTLD_NEXT, "lstat64");
490 if (!blacklist_loaded) 565 if (!blacklist_loaded)
@@ -501,6 +576,9 @@ int lstat64(const char *pathname, struct stat64 *buf) {
501typedef int (*orig_access_t)(const char *pathname, int mode); 576typedef int (*orig_access_t)(const char *pathname, int mode);
502static orig_access_t orig_access = NULL; 577static orig_access_t orig_access = NULL;
503int access(const char *pathname, int mode) { 578int access(const char *pathname, int mode) {
579#ifdef DEBUG
580 printf("%s\n", __FUNCTION__);
581#endif
504 if (!orig_access) 582 if (!orig_access)
505 orig_access = (orig_access_t)dlsym(RTLD_NEXT, "access"); 583 orig_access = (orig_access_t)dlsym(RTLD_NEXT, "access");
506 if (!blacklist_loaded) 584 if (!blacklist_loaded)
@@ -516,6 +594,9 @@ int access(const char *pathname, int mode) {
516typedef DIR *(*orig_opendir_t)(const char *pathname); 594typedef DIR *(*orig_opendir_t)(const char *pathname);
517static orig_opendir_t orig_opendir = NULL; 595static orig_opendir_t orig_opendir = NULL;
518DIR *opendir(const char *pathname) { 596DIR *opendir(const char *pathname) {
597#ifdef DEBUG
598 printf("%s\n", __FUNCTION__);
599#endif
519 if (!orig_opendir) 600 if (!orig_opendir)
520 orig_opendir = (orig_opendir_t)dlsym(RTLD_NEXT, "opendir"); 601 orig_opendir = (orig_opendir_t)dlsym(RTLD_NEXT, "opendir");
521 if (!blacklist_loaded) 602 if (!blacklist_loaded)