1
0
mirror of https://github.com/irssi/irssi.git synced 2024-09-29 04:45:57 -04:00

Working autolog.

Signed-off-by: Edward Tomasz Napierala <trasz@FreeBSD.org>
This commit is contained in:
Edward Tomasz Napierala 2017-07-29 10:32:24 +01:00
parent 241dd66ac1
commit e777ae986d
5 changed files with 73 additions and 5 deletions

View File

@ -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(&copy, "/");
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;

View File

@ -5,6 +5,7 @@ gboolean capsicum_enabled(void);
int capsicum_net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip);
int capsicum_net_gethostbyname(const char *addr, IPADDR *ip4, IPADDR *ip6);
int capsicum_open(const char *path, int flags, int mode);
void capsicum_mkdir_with_parents(const char *path, int mode);
void capsicum_init(void);
void capsicum_deinit(void);

View File

@ -127,7 +127,14 @@ int log_start_logging(LOG_REC *log)
/* path may contain variables (%time, $vars),
make sure the directory is created */
dir = g_path_get_dirname(log->real_fname);
#ifdef HAVE_CAPSICUM
if (capsicum_enabled())
capsicum_mkdir_with_parents(dir, log_dir_create_mode);
else
g_mkdir_with_parents(dir, log_dir_create_mode);
#else
g_mkdir_with_parents(dir, log_dir_create_mode);
#endif
g_free(dir);
}

View File

@ -167,7 +167,14 @@ void rawlog_save(RAWLOG_REC *rawlog, const char *fname)
int f;
dir = g_path_get_dirname(fname);
g_mkdir_with_parents(dir, log_dir_create_mode);
#ifdef HAVE_CAPSICUM
if (capsicum_enabled())
capsicum_mkdir_with_parents(dir, log_dir_create_mode);
else
g_mkdir_with_parents(dir, log_dir_create_mode);
#else
g_mkdir_with_parents(dir, log_dir_create_mode);
#endif
g_free(dir);
path = convert_home(fname);

View File

@ -30,6 +30,9 @@
#include "special-vars.h"
#include "settings.h"
#include "lib-config/iconfig.h"
#ifdef HAVE_CAPSICUM
#include "capsicum.h"
#endif
#include "fe-windows.h"
#include "window-items.h"
@ -451,7 +454,14 @@ static void autolog_open(SERVER_REC *server, const char *server_tag,
log_item_add(log, LOG_ITEM_TARGET, target, server_tag);
dir = g_path_get_dirname(log->real_fname);
#ifdef HAVE_CAPSICUM
if (capsicum_enabled())
capsicum_mkdir_with_parents(dir, log_dir_create_mode);
else
g_mkdir_with_parents(dir, log_dir_create_mode);
#else
g_mkdir_with_parents(dir, log_dir_create_mode);
#endif
g_free(dir);
log->temp = TRUE;