Unverified Commit 7e73302c authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

intercept symlinkat

parent 2f851f37
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ int hook_writev(unsigned long fd, const struct iovec * iov, unsigned long iovcnt
int hook_pwritev(unsigned long fd, const struct iovec * iov, unsigned long iovcnt,
                 unsigned long pos_l, unsigned long pos_h);
int hook_unlinkat(int dirfd, const char * cpath, int flags);
int hook_symlinkat(const char * oldname, int newdfd, const char * newname);
int hook_access(const char* path, int mask);
int hook_faccessat(int dirfd, const char * cpath, int mode);
int hook_lseek(unsigned int fd, off_t offset, unsigned int whence);
+33 −0
Original line number Diff line number Diff line
@@ -209,6 +209,39 @@ int hook_unlinkat(int dirfd, const char * cpath, int flags) {
    }
}

int hook_symlinkat(const char * oldname, int newdfd, const char * newname) {
    CTX->log()->trace("{}() called with oldname '{}', new fd {}, new name '{}'",
                      __func__, oldname, newdfd, newname);

    std::string oldname_resolved;
    if (CTX->relativize_path(oldname, oldname_resolved)) {
        CTX->log()->warn("{}() operation not supported", __func__);
        return -ENOTSUP;
    }

    std::string newname_resolved;
    auto rstatus = CTX->relativize_fd_path(newdfd, newname, newname_resolved, false);
    switch(rstatus) {
        case RelativizeStatus::fd_unknown:
            return syscall_no_intercept(SYS_symlinkat, oldname, newdfd, newname);

        case RelativizeStatus::external:
            return syscall_no_intercept(SYS_symlinkat, oldname, newdfd, newname_resolved.c_str());

        case RelativizeStatus::fd_not_a_dir:
            return -ENOTDIR;

        case RelativizeStatus::internal:
            CTX->log()->warn("{}() operation not supported", __func__);
            return -ENOTSUP;

        default:
            CTX->log()->error("{}() relativize status unknown", __func__);
            return -EINVAL;
    }
}


int hook_access(const char* path, int mask) {
    CTX->log()->trace("{}() called path '{}', mask {}", __func__, path, mask);
    std::string rel_path;
+12 −0
Original line number Diff line number Diff line
@@ -133,6 +133,18 @@ static inline int hook(long syscall_number,
                                AT_REMOVEDIR);
        break;

    case SYS_symlink:
        *result = hook_symlinkat(reinterpret_cast<const char *>(arg0),
                                 AT_FDCWD,
                                 reinterpret_cast<const char *>(arg1));
        break;

    case SYS_symlinkat:
        *result = hook_symlinkat(reinterpret_cast<const char *>(arg0),
                                 static_cast<int>(arg1),
                                 reinterpret_cast<const char *>(arg2));
        break;

    case SYS_access:
        *result = hook_access(reinterpret_cast<const char*>(arg0),
                              static_cast<int>(arg1));