Unverified Commit 56495ac8 authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

Intercept realpath

parent 94a44560
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -70,6 +70,8 @@ extern void* libc_closedir;

extern void* libc_chdir;

extern void* libc_realpath;

void init_passthrough_if_needed();

#endif //IFS_PASSTHROUGH_HPP
+23 −0
Original line number Diff line number Diff line
@@ -728,3 +728,26 @@ int chdir(const char* path){
    }
    return (reinterpret_cast<decltype(&chdir)>(libc_chdir))(path);
}

char *realpath(const char *path, char *resolved_path) {
    init_passthrough_if_needed();
    CTX->log()->trace("{}() called with path {}", __func__, path);
    std::string rel_path(path);
    if (CTX->relativize_path(rel_path)) {
        if(resolved_path != nullptr) {
            CTX->log()->error("{}() use of user level buffer not supported", __func__);
            errno = ENOTSUP;
            return nullptr;
        }
        auto absolute_path = CTX->mountdir() + rel_path;
        auto ret_ptr = static_cast<char*>(malloc(absolute_path.size() +  1));
        if(ret_ptr == nullptr){
            CTX->log()->error("{}() failed to allocate buffer for called with path {}", __func__, path);
            errno = ENOMEM;
            return nullptr;
        }
        strcpy(ret_ptr, absolute_path.c_str());
        return ret_ptr;
    }
    return (reinterpret_cast<decltype(&realpath)>(libc_realpath))(path, resolved_path);
}
+4 −0
Original line number Diff line number Diff line
@@ -75,6 +75,8 @@ void* libc_closedir;

void* libc_chdir;

void* libc_realpath;


void init_passthrough_() {
    libc = dlopen("libc.so.6", RTLD_LAZY);
@@ -146,6 +148,8 @@ void init_passthrough_() {

    libc_chdir = dlsym(libc, "chdir");

    libc_realpath = dlsym(libc, "realpath");

}

void init_passthrough_if_needed() {