Moving this to a VM for saner handling
This commit is contained in:
parent
f11ac76330
commit
185f718936
2 changed files with 24 additions and 3 deletions
4
Makefile
4
Makefile
|
@ -1,7 +1,9 @@
|
|||
all: program test
|
||||
|
||||
.PHONY: test
|
||||
|
||||
test: program
|
||||
sudo ./program foo
|
||||
sudo ./program tmp
|
||||
|
||||
program: main.c
|
||||
gcc main.c -o program
|
||||
|
|
23
main.c
23
main.c
|
@ -3,8 +3,8 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/mount.h>
|
||||
#include <dirent.h>
|
||||
#define _GNU_SOURCE
|
||||
#include <sched.h>
|
||||
#define _GNU_SOURCE
|
||||
#include <sched.h>
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
@ -15,12 +15,21 @@ struct args {
|
|||
|
||||
uint8_t CSTACK[8192];
|
||||
|
||||
int setup_jail() {
|
||||
mount("tmpfs", "jail/tmp", "tmpfs", MS_PRIVATE, NULL); // TODO this needs to also have a tmpfs data to limit size
|
||||
mount("foo", "jail/foo", NULL, MS_PRIVATE|MS_BIND|MS_RDONLY, NULL);
|
||||
chdir("jail");
|
||||
chroot(".");
|
||||
}
|
||||
|
||||
int myreaddir(void *fooargs) {
|
||||
int len;
|
||||
struct dirent *pDirent;
|
||||
DIR *pDir;
|
||||
struct args *myargs = (struct args *) fooargs;
|
||||
|
||||
setup_jail();
|
||||
|
||||
if (myargs->c < 2) {
|
||||
printf ("Usage: testprog <dirname>\n");
|
||||
return 1;
|
||||
|
@ -30,12 +39,22 @@ int myreaddir(void *fooargs) {
|
|||
mount(NULL, ".", NULL, MS_PRIVATE, NULL);
|
||||
umount(myargs->v[1]);
|
||||
|
||||
// sleep(100);
|
||||
|
||||
pDir = opendir (myargs->v[1]);
|
||||
if (pDir == NULL) {
|
||||
printf ("Cannot open directory '%s'\n", myargs->v[1]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
char file[32];
|
||||
snprintf(file, 32, "/tmp/%08d", rand());
|
||||
|
||||
FILE *foo=fopen(file, "w");
|
||||
fclose(file);
|
||||
|
||||
sleep(100);
|
||||
|
||||
while ((pDirent = readdir(pDir)) != NULL) {
|
||||
printf ("[%s]\n", pDirent->d_name);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue