diff options
author | Edward Tomasz Napierala <trasz@FreeBSD.org> | 2017-07-29 10:32:24 +0100 |
---|---|---|
committer | Edward Tomasz Napierala <trasz@FreeBSD.org> | 2017-07-29 23:52:23 +0100 |
commit | e777ae986d64863a444132885b160ab2e9c7458e (patch) | |
tree | 67f8ad54c5d61710f035dbdf26ad058514542914 /src/core/capsicum.c | |
parent | 241dd66ac11d54b37c671cd56f1320fe5b83803d (diff) | |
download | irssi-e777ae986d64863a444132885b160ab2e9c7458e.zip |
Working autolog.
Signed-off-by: Edward Tomasz Napierala <trasz@FreeBSD.org>
Diffstat (limited to 'src/core/capsicum.c')
-rw-r--r-- | src/core/capsicum.c | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/src/core/capsicum.c b/src/core/capsicum.c index 6667276c..c554fcf7 100644 --- a/src/core/capsicum.c +++ b/src/core/capsicum.c @@ -136,19 +136,62 @@ int capsicum_open(const char *path, int flags, int mode) { int fd; - /* +1 is for slash separating irclogs_path and the rest. */ - if (strlen(path) > irclogs_path_len + 1 && strncmp(path, irclogs_path, irclogs_path_len) == 0) { - fd = openat(irclogs_fd, path + irclogs_path_len + 1, flags, mode); + /* +1 is for the slash separating irclogs_path and the rest. */ + if (strlen(path) > irclogs_path_len + 1 && + strncmp(path, irclogs_path, irclogs_path_len) == 0) { + fd = openat(irclogs_fd, path + irclogs_path_len + 1, + flags, mode); } else { fd = open(path, flags, mode); } if (fd < 0 && (errno == ENOTCAPABLE || errno == ECAPMODE)) - g_warning("File system access restricted to %s due to capability mode", irclogs_path); + g_warning("File system access restricted to %s " + "due to capability mode", irclogs_path); return (fd); } +void capsicum_mkdir_with_parents(const char *path, int mode) +{ + char *component, *copy, *tofree; + int error, fd, newfd; + + /* +1 is for the slash separating irclogs_path and the rest. */ + if (strlen(path) <= irclogs_path_len + 1 || + strncmp(path, irclogs_path, irclogs_path_len) != 0) { + g_warning("Cannot create %s: file system access restricted " + "to %s due to capability mode", path, irclogs_path); + return; + } + + copy = tofree = g_strdup(path + irclogs_path_len + 1); + fd = irclogs_fd; + for (;;) { + component = strsep(©, "/"); + if (component == NULL) + break; + error = mkdirat(fd, component, mode); + if (error != 0 && errno != EEXIST) { + g_warning("cannot create %s: %s", + component, strerror(errno)); + break; + } + newfd = openat(fd, component, O_DIRECTORY); + if (newfd < 0) { + g_warning("cannot open %s: %s", + component, strerror(errno)); + break; + } + if (fd != irclogs_fd) + close(fd); + fd = newfd; + } + g_free(tofree); + if (fd != irclogs_fd) + close(fd); +} + nvlist_t *symbiont_connect(const nvlist_t *request) { nvlist_t *response; |