Verified Commit f27ac629 authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

Intercept links function family

parent 1f95ba1d
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -102,6 +102,11 @@ extern void* libc_fchdir;
extern void* libc_getcwd;
extern void* libc_get_current_dir_name;

extern void* libc_link;
extern void* libc_linkat;
extern void* libc_symlink;
extern void* libc_symlinkat;

extern void* libc_realpath;

void init_passthrough_if_needed();
+51 −0
Original line number Diff line number Diff line
@@ -1390,6 +1390,57 @@ char *get_current_dir_name(void) {
    return nullptr;
}


int link(const char *oldpath, const char *newpath) {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        CTX->log()->trace("{}() called [oldpath: '{}', newpath: '{}']",
               __func__, oldpath, newpath);
        CTX->log()->error("{}() not implemented", __func__);
        errno = ENOTSUP;
        return -1;
    }
    return LIBC_FUNC(link, oldpath, newpath);
}

int linkat(int olddirfd, const char *oldpath,
        int newdirfd, const char *newpath, int flags) {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        CTX->log()->trace("{}() called [olddirfd: '{}', oldpath: '{}',\
                newdirfd: '{}', newpath: '{}', flags: '{}']",
                __func__, olddirfd, oldpath, newdirfd, newpath, flags);
        CTX->log()->error("{}() not implemented", __func__);
        errno = ENOTSUP;
        return -1;
    }
    return LIBC_FUNC(linkat, olddirfd, oldpath, newdirfd, newpath, flags);
}

int symlink(const char *oldpath, const char *newpath) {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        CTX->log()->trace("{}() called [oldpath: '{}', newpath: '{}']",
               __func__, oldpath, newpath);
        CTX->log()->error("{}() not implemented", __func__);
        errno = ENOTSUP;
        return -1;
    }
    return LIBC_FUNC(symlink, oldpath, newpath);
}

int symlinkat(const char *oldpath, int fd, const char *newpath) {
    init_passthrough_if_needed();
    if(CTX->initialized()) {
        CTX->log()->trace("{}() called [oldpath: '{}', newpath: '{}']",
               __func__, oldpath, newpath);
        CTX->log()->error("{}() not implemented", __func__);
        errno = ENOTSUP;
        return -1;
    }
    return LIBC_FUNC(symlinkat, oldpath, fd, newpath);
}

char *realpath(const char *path, char *resolved_path) {
    init_passthrough_if_needed();
    if(!CTX->initialized()) {
+10 −0
Original line number Diff line number Diff line
@@ -103,6 +103,11 @@ void* libc_fchdir;
void* libc_getcwd;
void* libc_get_current_dir_name;

void* libc_link;
void* libc_linkat;
void* libc_symlink;
void* libc_symlinkat;

void* libc_realpath;


@@ -204,6 +209,11 @@ void init_passthrough_() {
    libc_getcwd = dlsym(libc, "getcwd");
    libc_get_current_dir_name = dlsym(libc, "get_current_dir_name");

    libc_link = dlsym(libc, "link");
    libc_linkat = dlsym(libc, "linkat");
    libc_symlink = dlsym(libc, "symlink");
    libc_symlinkat = dlsym(libc, "symlinkat");

    libc_realpath = dlsym(libc, "realpath");

}