Skip to content

Commit

Permalink
Merge pull request #3 from ValHayot/tristan
Browse files Browse the repository at this point in the history
added chown and __open_2 wrappers
  • Loading branch information
glatard authored May 15, 2020
2 parents 13b8a3e + 23c6a08 commit 7e78bdf
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 1 deletion.
33 changes: 33 additions & 0 deletions functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ extern "C" {
return ((funcptr___open)libc___open)(passpath, flags, mode);
}

int __open_2 (const char *file, int oflag){
initialize_passthrough_if_necessary();
log_msg(INFO, "opening file %s", file);
char passpath[PATH_MAX];
pass_getpath(file, passpath);
return ((funcptr___open_2)libc___open_2)(passpath, oflag);

}

int open64(const char* pathname, int flags, ...){
initialize_passthrough_if_necessary();
log_msg(INFO, "open64 %s", pathname);
Expand Down Expand Up @@ -494,6 +503,30 @@ extern "C" {
return ((funcptr_ftruncate)libc_ftruncate)(fd, offset);
}

int chown(const char *pathname, uid_t owner, gid_t group){
initialize_passthrough_if_necessary();
char passpath[PATH_MAX];
pass_getpath(pathname, passpath);
log_msg(INFO, "chown %s", passpath);
return ((funcptr_chown)libc_chown)(passpath, owner, group);
}

int lchown(const char *pathname, uid_t owner, gid_t group){
initialize_passthrough_if_necessary();
char passpath[PATH_MAX];
pass_getpath(pathname, passpath);
log_msg(INFO, "lchown %s", passpath);
return ((funcptr_lchown)libc_lchown)(passpath, owner, group);
}

int fchownat(int dirfd, const char *pathname, uid_t owner, gid_t group, int flags){
initialize_passthrough_if_necessary();
char passpath[PATH_MAX];
pass_getpath(pathname, passpath);
log_msg(INFO, "fchownat %s", passpath);
return ((funcptr_fchownat)libc_fchownat)(dirfd, passpath, owner, group, flags);
}

int setxattr(const char* path, const char *name, const void *value, size_t size, int flags){
initialize_passthrough_if_necessary();
log_msg(INFO, "setxattr %s", path);
Expand Down
10 changes: 10 additions & 0 deletions passthrough.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
void* libc;
void* libc_open;
void* libc___open;
void* libc___open_2;
void* libc_open64;
void* libc___open64;
void* libc_openat;
Expand Down Expand Up @@ -71,6 +72,10 @@ void* libc_fopen64;
void* libc_truncate;
void* libc_ftruncate;

void* libc_chown;
void* libc_lchown;
void* libc_fchownat;

void* libattr;
void* libattr_setxattr;
void* libattr_fsetxattr;
Expand Down Expand Up @@ -259,6 +264,7 @@ static void initialize_passthrough() {
libc = dlopen("libc.so.6", RTLD_LAZY); // TODO: link with correct libc, version vs. 32 bit vs. 64 bit
libc_open = dlsym(libc, "open");
libc___open = dlsym(libc, "__open");
libc___open_2 = dlsym(libc, "__open_2");
libc_open64 = dlsym(libc, "open64");
libc___open64 = dlsym(libc, "__open64");
libc_openat = dlsym(libc, "openat");
Expand Down Expand Up @@ -306,6 +312,10 @@ static void initialize_passthrough() {
libc_truncate = dlsym(libc, "truncate");
libc_ftruncate = dlsym(libc, "ftruncate");

libc_chown = dlsym(libc, "chown");
libc_lchown = dlsym(libc, "lchown");
libc_fchownat = dlsym(libc, "fchownat");

libattr = dlopen("libattr.so.1", RTLD_LAZY);
libattr_setxattr = dlsym(libattr, "setxattr");
libattr_fsetxattr = dlsym(libattr, "setxattr");
Expand Down
10 changes: 10 additions & 0 deletions passthrough.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern char* log_fn;

typedef int (*funcptr_open)(const char*, int, mode_t);
typedef int (*funcptr___open)(const char*, int, mode_t);
typedef int (*funcptr___open_2)(const char *file, int oflag);
typedef int (*funcptr_open64)(const char*, int, mode_t);
typedef int (*funcptr___open64)(const char*, int, mode_t);
typedef int (*funcptr_openat)(int, const char*, int);
Expand Down Expand Up @@ -73,10 +74,15 @@ typedef int (*funcptr_ftruncate)(int, off_t);
typedef int (*funcptr_setxattr)(const char*, const char*, const void*, size_t, int);
typedef int (*funcptr_fsetxattr)(int, const char*, const void*, size_t, int);

typedef int (*funcptr_chown)(const char*, uid_t, gid_t);
typedef int (*funcptr_lchown)(const char*, uid_t, gid_t);
typedef int (*funcptr_fchownat)(int, const char*, uid_t, gid_t, int);

typedef const char* (*funcptr_magic_file)(magic_t, const char* filename);

extern void* libc_open;
extern void* libc___open;
extern void* libc___open_2;
extern void* libc_open64;
extern void* libc___open64;
extern void* libc_openat;
Expand Down Expand Up @@ -125,6 +131,10 @@ extern void* libc_fopen64;
extern void* libc_truncate;
extern void* libc_ftruncate;

extern void* libc_chown;
extern void* libc_lchown;
extern void* libc_fchownat;

extern void* libattr_setxattr;
extern void* libattr_fsetxattr;

Expand Down
Binary file added tests/.tests.bats.swp
Binary file not shown.
2 changes: 2 additions & 0 deletions tests/docker/Dockerfile.bionic
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from ubuntu:bionic

RUN useradd --no-log-init -r tmpu

RUN apt update -y && apt install -y make gcc g++ git file libmagic-dev python python3
RUN git clone https://github.com/bats-core/bats-core.git && cd bats-core && ./install.sh /usr/local
2 changes: 2 additions & 0 deletions tests/docker/Dockerfile.centos6
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from centos:6

RUN useradd --no-log-init -r tmpu

RUN yum update -y && yum install -y make gcc gcc-c++ git file file-devel python
RUN git clone https://github.com/bats-core/bats-core.git && cd bats-core && ./install.sh /usr/local
2 changes: 2 additions & 0 deletions tests/docker/Dockerfile.centos7
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from centos:7

RUN useradd --no-log-init -r tmpu

# bats installation
RUN yum update -y && yum install -y make gcc gcc-c++ git file file-devel python2 python3
RUN git clone https://github.com/bats-core/bats-core.git && cd bats-core && ./install.sh /usr/local
Expand Down
2 changes: 2 additions & 0 deletions tests/docker/Dockerfile.centos8
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from centos:8

RUN useradd --no-log-init -r tmpu

# bats installation
RUN dnf update -y && dnf install -y make gcc gcc-c++ git file python2 python3
RUN git clone https://github.com/bats-core/bats-core.git && cd bats-core && ./install.sh /usr/local
Expand Down
2 changes: 2 additions & 0 deletions tests/docker/Dockerfile.fedora32
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from fedora:32

RUN useradd --no-log-init -r tmpu

RUN dnf update -y && dnf install -y make gcc gcc-c++ git findutils file file-devel python2 python3
RUN git clone https://github.com/bats-core/bats-core.git && cd bats-core && ./install.sh /usr/local
2 changes: 2 additions & 0 deletions tests/docker/Dockerfile.xenial
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from ubuntu:xenial

RUN useradd --no-log-init -r tmpu

RUN apt update -y && apt install -y make gcc g++ git file libmagic-dev python python3
RUN git clone https://github.com/bats-core/bats-core.git && cd bats-core && ./install.sh /usr/local
8 changes: 7 additions & 1 deletion tests/tests.bats
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,10 @@ MOUNT="$PWD/mount"
python3 tests/write.py ${MOUNT}/subdir/hello.txt
load unset
test -f ${SOURCE}/hello.txt
}
}

@test "chown" {
load setup
a=$(chown tmpu:tmpu ${MOUNT}/file_in_source.txt)

}

0 comments on commit 7e78bdf

Please sign in to comment.