static void storage_add(Storage **head, const char *name) { if (storage_find(*head, name)) return; Storage *s = malloc(sizeof(Storage)); if (!s) errExit("malloc"); s->next = *head; *head = s; s->name = strdup(name); if (!s->name) errExit("strdup"); }
DIR *opendir(const char *pathname) { #ifdef DEBUG printf("%s %s\n", __FUNCTION__, pathname); #endif if (!orig_opendir) orig_opendir = (orig_opendir_t)dlsym(RTLD_NEXT, "opendir"); if (!blacklist_loaded) load_blacklist(); DIR *rv = orig_opendir(pathname); if (storage_find(pathname)) sendlog(name(), __FUNCTION__, pathname); return rv; }
int lstat64(const char *pathname, struct stat64 *buf) { #ifdef DEBUG printf("%s %s\n", __FUNCTION__, pathname); #endif if (!orig_lstat) orig_lstat64 = (orig_lstat64_t)dlsym(RTLD_NEXT, "lstat64"); if (!blacklist_loaded) load_blacklist(); int rv = orig_lstat64(pathname, buf); if (storage_find(pathname)) sendlog(name(), __FUNCTION__, pathname); return rv; }
int access(const char *pathname, int mode) { #ifdef DEBUG printf("%s, %s\n", __FUNCTION__, pathname); #endif if (!orig_access) orig_access = (orig_access_t)dlsym(RTLD_NEXT, "access"); if (!blacklist_loaded) load_blacklist(); int rv = orig_access(pathname, mode); if (storage_find(pathname)) sendlog(name(), __FUNCTION__, pathname); return rv; }
int mkdirat(int dirfd, const char *pathname, mode_t mode) { #ifdef DEBUG printf("%s %s\n", __FUNCTION__, pathname); #endif if (!orig_mkdirat) orig_mkdirat = (orig_mkdirat_t)dlsym(RTLD_NEXT, "mkdirat"); if (!blacklist_loaded) load_blacklist(); int rv = orig_mkdirat(dirfd, pathname, mode); if (storage_find(pathname)) sendlog(name(), __FUNCTION__, pathname); return rv; }
int unlink(const char *pathname) { #ifdef DEBUG printf("%s %s\n", __FUNCTION__, pathname); #endif if (!orig_unlink) orig_unlink = (orig_unlink_t)dlsym(RTLD_NEXT, "unlink"); if (!blacklist_loaded) load_blacklist(); int rv = orig_unlink(pathname); if (storage_find(pathname)) sendlog(name(), __FUNCTION__, pathname); return rv; }
FILE *freopen64(const char *pathname, const char *mode, FILE *stream) { #ifdef DEBUG printf("%s %s\n", __FUNCTION__, pathname); #endif if (!orig_freopen64) orig_freopen64 = (orig_freopen64_t)dlsym(RTLD_NEXT, "freopen64"); if (!blacklist_loaded) load_blacklist(); FILE *rv = orig_freopen64(pathname, mode, stream); if (storage_find(pathname)) sendlog(name(), __FUNCTION__, pathname); return rv; }
// fopen FILE *fopen(const char *pathname, const char *mode) { #ifdef DEBUG printf("%s %s\n", __FUNCTION__, pathname); #endif if (!orig_fopen) orig_fopen = (orig_fopen_t)dlsym(RTLD_NEXT, "fopen"); if (!blacklist_loaded) load_blacklist(); FILE *rv = orig_fopen(pathname, mode); if (storage_find(pathname)) sendlog(name(), __FUNCTION__, pathname); return rv; }
int openat64(int dirfd, const char *pathname, int flags, mode_t mode) { #ifdef DEBUG printf("%s %s\n", __FUNCTION__, pathname); #endif if (!orig_openat64) orig_openat64 = (orig_openat64_t)dlsym(RTLD_NEXT, "openat64"); if (!blacklist_loaded) load_blacklist(); int rv = orig_openat64(dirfd, pathname, flags, mode); if (storage_find(pathname)) sendlog(name(), __FUNCTION__, pathname); return rv; }
static void copy_libs_for_lib(const char *lib) { Storage *lib_path; for (lib_path = lib_paths; lib_path; lib_path = lib_path->next) { char *fname; if (asprintf(&fname, "%s/%s", lib_path->name, lib) == -1) errExit("asprintf"); if (access(fname, R_OK) == 0 && is_lib_64(fname)) { if (!storage_find(libs, fname)) { storage_add(&libs, fname); // libs may need other libs parse_elf(fname); } free(fname); return; } free(fname); } // log a warning and continue if (!arg_quiet) fprintf(stderr, "Warning fldd: cannot find %s, skipping...\n", lib); }