Unverified Commit 373e88de authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

intercept faccessat

parent 7091baf0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ int hook_pwritev(unsigned long fd, const struct iovec * iov, unsigned long iovcn
                 unsigned long pos_l, unsigned long pos_h);
int hook_unlinkat(int dirfd, const char * cpath, int flags);
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);
int hook_truncate(const char *path, long length);
int hook_ftruncate(unsigned int fd, unsigned long length);
+25 −0
Original line number Diff line number Diff line
@@ -222,6 +222,31 @@ int hook_access(const char* path, int mask) {
    return syscall_no_intercept(SYS_access, rel_path.c_str(), mask);
}

int hook_faccessat(int dirfd, const char * cpath, int mode) {
    CTX->log()->trace("{}() called with path '{}' dirfd {}, mode {}",
                      __func__, cpath, dirfd, mode);

    std::string resolved;
    auto rstatus = CTX->relativize_fd_path(dirfd, cpath, resolved);
    switch(rstatus) {
        case RelativizeStatus::fd_unknown:
            return syscall_no_intercept(SYS_faccessat, dirfd, cpath, mode);

        case RelativizeStatus::external:
            return syscall_no_intercept(SYS_faccessat, dirfd, resolved.c_str(), mode);

        case RelativizeStatus::fd_not_a_dir:
            return -ENOTDIR;

        case RelativizeStatus::internal:
            return with_errno(adafs_access(resolved, mode));

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

int hook_lseek(unsigned int fd, off_t offset, unsigned int whence) {
    CTX->log()->trace("{}() called with fd {}, offset {}, whence {}", __func__, fd, offset, whence);
    if (CTX->file_map()->exist(fd)) {
+7 −1
Original line number Diff line number Diff line
@@ -128,10 +128,16 @@ static inline int hook(long syscall_number,
        break;

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

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

    case SYS_lseek:
        *result = hook_lseek(static_cast<unsigned int>(arg0),
                             static_cast<off_t>(arg1),