mirror of
https://github.com/jorisvink/kore
synced 2025-03-09 04:29:02 -04:00
resolve filemap paths after workers chrooted.
otherwise the paths inside chrooted workers are incorrect.
This commit is contained in:
parent
10cf14f756
commit
5eb2160269
@ -647,6 +647,7 @@ int kore_msg_register(u_int8_t,
|
||||
|
||||
#if !defined(KORE_NO_HTTP)
|
||||
void kore_filemap_init(void);
|
||||
void kore_filemap_resolve_paths(void);
|
||||
int kore_filemap_create(struct kore_domain *, const char *,
|
||||
const char *);
|
||||
extern char *kore_filemap_ext;
|
||||
|
@ -56,9 +56,10 @@ int
|
||||
kore_filemap_create(struct kore_domain *dom, const char *path, const char *root)
|
||||
{
|
||||
size_t sz;
|
||||
struct stat st;
|
||||
int len;
|
||||
struct filemap_entry *entry;
|
||||
char regex[1024], rpath[PATH_MAX];
|
||||
char regex[1024];
|
||||
|
||||
sz = strlen(root);
|
||||
if (sz == 0)
|
||||
@ -67,6 +68,9 @@ kore_filemap_create(struct kore_domain *dom, const char *path, const char *root)
|
||||
if (root[0] != '/' || root[sz - 1] != '/')
|
||||
return (KORE_RESULT_ERROR);
|
||||
|
||||
if (stat(path, &st) == -1)
|
||||
return (KORE_RESULT_ERROR);
|
||||
|
||||
len = snprintf(regex, sizeof(regex), "^%s.*$", root);
|
||||
if (len == -1 || (size_t)len >= sizeof(regex))
|
||||
fatal("kore_filemap_create: buffer too small");
|
||||
@ -75,22 +79,40 @@ kore_filemap_create(struct kore_domain *dom, const char *path, const char *root)
|
||||
"filemap_resolve", NULL, HANDLER_TYPE_DYNAMIC))
|
||||
return (KORE_RESULT_ERROR);
|
||||
|
||||
if (realpath(path, rpath) == NULL)
|
||||
return (KORE_RESULT_ERROR);
|
||||
|
||||
entry = kore_calloc(1, sizeof(*entry));
|
||||
|
||||
entry->domain = dom;
|
||||
entry->root_len = sz;
|
||||
entry->root = kore_strdup(root);
|
||||
entry->ondisk_len = strlen(rpath);
|
||||
entry->ondisk = kore_strdup(rpath);
|
||||
|
||||
/*
|
||||
* Resolve the ondisk component inside the workers to make sure
|
||||
* realpath() resolves the correct path (they maybe chrooted).
|
||||
*/
|
||||
entry->ondisk_len = strlen(path);
|
||||
entry->ondisk = kore_strdup(path);
|
||||
|
||||
TAILQ_INSERT_TAIL(&maps, entry, list);
|
||||
|
||||
return (KORE_RESULT_OK);
|
||||
}
|
||||
|
||||
void
|
||||
kore_filemap_resolve_paths(void)
|
||||
{
|
||||
struct filemap_entry *entry;
|
||||
char rpath[PATH_MAX];
|
||||
|
||||
TAILQ_FOREACH(entry, &maps, list) {
|
||||
if (realpath(entry->ondisk, rpath) == NULL)
|
||||
fatal("realpath(%s): %s", entry->ondisk, errno_s);
|
||||
|
||||
kore_free(entry->ondisk);
|
||||
entry->ondisk_len = strlen(rpath);
|
||||
entry->ondisk = kore_strdup(rpath);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
filemap_resolve(struct http_request *req)
|
||||
{
|
||||
|
@ -314,6 +314,7 @@ kore_worker_entry(struct kore_worker *kw)
|
||||
net_init();
|
||||
#if !defined(KORE_NO_HTTP)
|
||||
http_init();
|
||||
kore_filemap_resolve_paths();
|
||||
kore_accesslog_worker_init();
|
||||
#endif
|
||||
kore_timer_init();
|
||||
|
Loading…
x
Reference in New Issue
Block a user