|
|
@@ -1,22 +1,42 @@
|
|
|
#include "sandbox.h"
|
|
|
+#include "sllist.h"
|
|
|
#include <sys/types.h>
|
|
|
#include <sys/stat.h>
|
|
|
#include <stdlib.h>
|
|
|
+#include <string.h>
|
|
|
#include <fcntl.h>
|
|
|
-#include <stdio.h>
|
|
|
+
|
|
|
+static t_fileinfo *open_local(struct s_sandboxenv *env, char *filename)
|
|
|
+{
|
|
|
+ t_fileinfo *result;
|
|
|
+ unsigned long long int filename_hash;
|
|
|
+ char *localpath;
|
|
|
+
|
|
|
+ filename_hash = hash_path(filename);
|
|
|
+ asprintf(&localpath, "%s/%llu", env->params->tmppath, filename_hash);
|
|
|
+ result = malloc(sizeof(*result));
|
|
|
+ result->filename = filename;
|
|
|
+ result->local_fd = open(localpath, O_CREAT, 0600);
|
|
|
+ result->fds = sllist_create();
|
|
|
+ sllist_pushback(env->filetable, result);
|
|
|
+ free(localpath);
|
|
|
+ return result;
|
|
|
+}
|
|
|
|
|
|
int ovr_open(struct s_sandboxenv *env)
|
|
|
{
|
|
|
char *pathname = getMem(env, (size_t) env->syscall_args[0], NULL);
|
|
|
int flags = (int) env->syscall_args[1];
|
|
|
mode_t mode = (mode_t) env->syscall_args[2];
|
|
|
- int ro = !(flags & (O_RDWR | O_WRONLY | O_CREAT | O_TRUNC));
|
|
|
+ int ro = !(flags & (O_RDWR | O_WRONLY | O_TRUNC));
|
|
|
t_fileinfo *fileentry;
|
|
|
|
|
|
if (*pathname != '/')
|
|
|
find_fullpath(&pathname, 1);
|
|
|
fileentry = get_fileinfo(env, pathname);
|
|
|
- if (fileentry == NULL && ro)
|
|
|
+ if (!fileentry && ro && (flags & O_CREAT) && !file_exists(pathname))
|
|
|
+ ro = 0;
|
|
|
+ if (!fileentry && ro)
|
|
|
{
|
|
|
printf("DO open %s (unmanaged)\n", pathname);
|
|
|
fflush(stdout);
|
|
|
@@ -25,7 +45,12 @@ int ovr_open(struct s_sandboxenv *env)
|
|
|
}
|
|
|
waitForSyscall(env->child_pid, SANDBOX_SYS_EXIT);
|
|
|
read_registers(env);
|
|
|
- printf("DO open ! ([%s], [%d], [%d])%s = %d\n", pathname, flags, mode, ro ? "- RO" : "- RW", env->syscall_no.syscall_return);
|
|
|
+ if (!fileentry)
|
|
|
+ fileentry = open_local(env, strdup(pathname));
|
|
|
+
|
|
|
+ sllist_pushback(fileentry->fds, (void *) env->syscall_no.syscall_return);
|
|
|
+
|
|
|
+ printf("DO open ! ([%s], [%d], [%d])%s = %d\n", pathname, flags, mode, ro ? "- RO" : "- RW", (int) env->syscall_no.syscall_return);
|
|
|
fflush(stdout);
|
|
|
free(pathname);
|
|
|
return 0;
|