summaryrefslogtreecommitdiff
path: root/src/user/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/user/lib')
-rw-r--r--src/user/lib/draw/draw.c3
-rw-r--r--src/user/lib/fs/misc.c2
-rw-r--r--src/user/lib/fs/whitelist.c9
-rw-r--r--src/user/lib/stdio/file.c12
-rw-r--r--src/user/lib/stdlib.c2
-rw-r--r--src/user/lib/unistd.c9
6 files changed, 27 insertions, 10 deletions
diff --git a/src/user/lib/draw/draw.c b/src/user/lib/draw/draw.c
index 27c1d33..943b8ba 100644
--- a/src/user/lib/draw/draw.c
+++ b/src/user/lib/draw/draw.c
@@ -1,3 +1,4 @@
+#include <camellia/flags.h>
#include <camellia/syscalls.h>
#include <errno.h>
#include <stdio.h>
@@ -32,7 +33,7 @@ int fb_setup(struct framebuf *fb, const char *base) {
/* assumes the read went correctly */
fclose(f);
- fb->fd = _syscall_open(path, strlen(path), 0);
+ fb->fd = _syscall_open(path, strlen(path), OPEN_RW);
if (fb->fd < 0) return fb->fd;
fb->width = strtol(spec, &spec, 0);
diff --git a/src/user/lib/fs/misc.c b/src/user/lib/fs/misc.c
index f660f6f..860b312 100644
--- a/src/user/lib/fs/misc.c
+++ b/src/user/lib/fs/misc.c
@@ -135,7 +135,7 @@ void fs_union(const char **list) {
size_t prefixlen = strlen(prefix);
// TODO only open the directories once
// TODO ensure trailing slash
- handle_t h = _syscall_open(prefix, prefixlen, 0);
+ handle_t h = _syscall_open(prefix, prefixlen, OPEN_READ);
if (h < 0) continue;
end = end || dir_append_from(&db, h);
_syscall_close(h);
diff --git a/src/user/lib/fs/whitelist.c b/src/user/lib/fs/whitelist.c
index 676b36f..571ebfb 100644
--- a/src/user/lib/fs/whitelist.c
+++ b/src/user/lib/fs/whitelist.c
@@ -1,5 +1,6 @@
#include <camellia/flags.h>
#include <camellia/syscalls.h>
+#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <user/lib/fs/dir.h>
@@ -49,6 +50,7 @@ void fs_whitelist(const char **whitelist) {
switch (res.op) {
case VFSOP_OPEN: {
+ bool error = false;
bool passthru = false;
bool inject = false;
@@ -57,8 +59,9 @@ void fs_whitelist(const char **whitelist) {
size_t entry_len = suffix_parse(*entry, strlen(*entry), &ro);
/* If *entry is a prefix of the opened path, pass the open() through. */
if (prefix_match(*entry, entry_len, buf, res.len)) {
- if (ro) res.flags |= OPEN_RO;
passthru = true;
+ if (ro && OPEN_WRITEABLE(res.flags))
+ error = true;
break;
}
/* If the path is a prefix of *entry, we might need to inject a directory. */
@@ -66,7 +69,9 @@ void fs_whitelist(const char **whitelist) {
inject = true;
}
}
- if (passthru) {
+ if (error) {
+ _syscall_fs_respond(reqh, NULL, -EACCES, 0);
+ } else if (passthru) {
forward_open(reqh, buf, res.len, res.flags);
} else if (inject) {
// TODO all the inject points could be precomputed
diff --git a/src/user/lib/stdio/file.c b/src/user/lib/stdio/file.c
index 8c0fc57..f3120d7 100644
--- a/src/user/lib/stdio/file.c
+++ b/src/user/lib/stdio/file.c
@@ -42,8 +42,16 @@ FILE *fopen(const char *path, const char *mode) {
path = tmppath;
}
- if (mode[0] == 'w' || mode[0] == 'a')
- flags |= OPEN_CREATE;
+ if (strchr(mode, 'e')) {
+ /* camellia extension: open as executable */
+ flags |= OPEN_EXEC;
+ } else if (strchr(mode, 'r')) {
+ flags |= OPEN_READ;
+ if (strchr(mode, '+'))
+ flags |= OPEN_WRITE;
+ } else {
+ flags |= OPEN_WRITE | OPEN_CREATE;
+ }
h = _syscall_open(path, strlen(path), flags);
if (tmppath) free(tmppath);
diff --git a/src/user/lib/stdlib.c b/src/user/lib/stdlib.c
index 38e87ad..c1ee217 100644
--- a/src/user/lib/stdlib.c
+++ b/src/user/lib/stdlib.c
@@ -10,7 +10,7 @@ _Noreturn void abort(void) {
int mkstemp(char *template) {
// TODO randomize template
- handle_t h = _syscall_open(template, strlen(template), OPEN_CREATE);
+ handle_t h = _syscall_open(template, strlen(template), OPEN_CREATE | OPEN_RW);
if (h < 0) {
errno = -h;
return -1;
diff --git a/src/user/lib/unistd.c b/src/user/lib/unistd.c
index ed8d77f..04a060d 100644
--- a/src/user/lib/unistd.c
+++ b/src/user/lib/unistd.c
@@ -1,3 +1,4 @@
+#include <camellia/flags.h>
#include <camellia/path.h>
#include <camellia/syscalls.h>
#include <errno.h>
@@ -30,7 +31,8 @@ int unlink(const char *path) {
size_t abslen = absolutepath(abspath, path, len);
if (abslen == 0) { errno = EINVAL; goto err; }
- handle_t h = _syscall_open(abspath, abslen - 1, 0);
+ // TODO take cwd into account
+ handle_t h = _syscall_open(abspath, abslen - 1, OPEN_WRITE);
if (h < 0) { errno = -h; goto err; }
long ret = _syscall_remove(h);
@@ -49,7 +51,7 @@ int isatty(int fd) {
int execv(const char *path, char *const argv[]) {
- FILE *file = fopen(path, "r");
+ FILE *file = fopen(path, "e");
char hdr[4] = {0};
if (!file)
return -1;
@@ -114,7 +116,8 @@ int chdir(const char *path) {
cwd2[len + 1] = '\0';
}
- h = _syscall_open(cwd2, strlen(cwd2), 0);
+ /* check if exists */
+ h = _syscall_open(cwd2, strlen(cwd2), OPEN_READ);
if (h < 0) {
errno = ENOENT;
return -1;