2013-05-01 17:17:16 +02:00
|
|
|
|
/*
|
2021-01-11 23:46:08 +01:00
|
|
|
|
* Copyright (c) 2013-2021 Joris Vink <joris@coders.se>
|
2013-05-01 17:17:16 +02:00
|
|
|
|
*
|
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-07-06 16:16:15 +02:00
|
|
|
|
#include <sys/param.h>
|
2019-03-06 09:29:46 +01:00
|
|
|
|
#include <sys/types.h>
|
2014-03-07 09:55:28 +01:00
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
2016-01-22 12:08:13 +01:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
2017-02-06 12:13:29 +01:00
|
|
|
|
#include <stdint.h>
|
2013-05-01 17:17:16 +02:00
|
|
|
|
#include <ctype.h>
|
2013-09-02 08:52:16 +02:00
|
|
|
|
#include <limits.h>
|
2013-05-01 17:17:16 +02:00
|
|
|
|
#include <fcntl.h>
|
2013-06-26 11:18:32 +02:00
|
|
|
|
#include <pwd.h>
|
2013-05-01 17:17:16 +02:00
|
|
|
|
|
|
|
|
|
#include "kore.h"
|
2013-09-22 20:05:24 +02:00
|
|
|
|
#include "http.h"
|
2013-05-01 17:17:16 +02:00
|
|
|
|
|
2014-07-04 09:14:05 +02:00
|
|
|
|
#if defined(KORE_USE_PGSQL)
|
|
|
|
|
#include "pgsql.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-06-04 10:29:22 +02:00
|
|
|
|
#if defined(KORE_USE_TASKS)
|
|
|
|
|
#include "tasks.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-01-12 23:38:51 +01:00
|
|
|
|
#if defined(KORE_USE_PYTHON)
|
|
|
|
|
#include "python_api.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-04-24 00:10:47 +02:00
|
|
|
|
#if defined(KORE_USE_CURL)
|
|
|
|
|
#include "curl.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-11-06 19:33:53 +01:00
|
|
|
|
#if defined(KORE_USE_ACME)
|
|
|
|
|
#include "acme.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-10-31 12:52:10 +01:00
|
|
|
|
#if defined(__linux__)
|
|
|
|
|
#include "seccomp.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-01-22 22:55:10 +01:00
|
|
|
|
/* XXX - This is becoming a clusterfuck. Fix it. */
|
|
|
|
|
|
2019-11-06 19:33:53 +01:00
|
|
|
|
static int configure_load(char *);
|
|
|
|
|
static void configure_check_var(char **, const char *, const char *);
|
2017-01-26 13:13:23 +01:00
|
|
|
|
|
|
|
|
|
#if defined(KORE_SINGLE_BINARY)
|
2016-07-06 16:16:15 +02:00
|
|
|
|
static FILE *config_file_write(void);
|
|
|
|
|
extern u_int8_t asset_builtin_kore_conf[];
|
|
|
|
|
extern u_int32_t asset_len_builtin_kore_conf;
|
2019-09-26 15:49:00 +02:00
|
|
|
|
#elif defined(KORE_USE_PYTHON)
|
|
|
|
|
static int configure_file(char *);
|
2016-07-06 16:16:15 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2019-11-06 19:33:53 +01:00
|
|
|
|
#if defined(KORE_USE_ACME)
|
|
|
|
|
static int configure_acme(char *);
|
|
|
|
|
static int configure_acme_root(char *);
|
|
|
|
|
static int configure_acme_runas(char *);
|
2020-01-13 11:00:40 +01:00
|
|
|
|
static int configure_acme_email(char *);
|
2019-11-06 19:33:53 +01:00
|
|
|
|
static int configure_acme_provider(char *);
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-09-27 12:22:35 +02:00
|
|
|
|
static int configure_tls(char *);
|
2019-09-27 20:00:35 +02:00
|
|
|
|
static int configure_server(char *);
|
2016-02-01 21:33:51 +01:00
|
|
|
|
static int configure_include(char *);
|
|
|
|
|
static int configure_bind(char *);
|
2018-10-07 20:49:16 +02:00
|
|
|
|
static int configure_bind_unix(char *);
|
2019-09-27 12:22:35 +02:00
|
|
|
|
static int configure_attach(char *);
|
2016-02-01 21:33:51 +01:00
|
|
|
|
static int configure_domain(char *);
|
2018-07-11 09:44:29 +02:00
|
|
|
|
static int configure_root(char *);
|
2016-02-01 21:33:51 +01:00
|
|
|
|
static int configure_runas(char *);
|
|
|
|
|
static int configure_workers(char *);
|
|
|
|
|
static int configure_pidfile(char *);
|
|
|
|
|
static int configure_rlimit_nofiles(char *);
|
|
|
|
|
static int configure_max_connections(char *);
|
|
|
|
|
static int configure_accept_threshold(char *);
|
2019-03-22 09:49:50 +01:00
|
|
|
|
static int configure_death_policy(char *);
|
2016-02-01 21:33:51 +01:00
|
|
|
|
static int configure_set_affinity(char *);
|
|
|
|
|
static int configure_socket_backlog(char *);
|
2015-11-27 16:22:50 +01:00
|
|
|
|
|
2018-07-31 06:51:34 +02:00
|
|
|
|
#if defined(KORE_USE_PLATFORM_PLEDGE)
|
|
|
|
|
static int configure_add_pledge(char *);
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-02-28 05:58:04 +01:00
|
|
|
|
static int configure_rand_file(char *);
|
2016-02-01 21:33:51 +01:00
|
|
|
|
static int configure_certfile(char *);
|
|
|
|
|
static int configure_certkey(char *);
|
|
|
|
|
static int configure_tls_version(char *);
|
|
|
|
|
static int configure_tls_cipher(char *);
|
|
|
|
|
static int configure_tls_dhparam(char *);
|
2018-07-11 09:44:29 +02:00
|
|
|
|
static int configure_keymgr_root(char *);
|
|
|
|
|
static int configure_keymgr_runas(char *);
|
|
|
|
|
static int configure_client_verify(char *);
|
2018-06-09 12:50:50 +02:00
|
|
|
|
static int configure_client_verify_depth(char *);
|
2015-11-27 16:22:50 +01:00
|
|
|
|
|
|
|
|
|
#if !defined(KORE_NO_HTTP)
|
2019-11-15 08:11:02 +01:00
|
|
|
|
static int configure_route(char *);
|
2018-06-28 13:27:44 +02:00
|
|
|
|
static int configure_filemap(char *);
|
2020-03-03 11:28:16 +01:00
|
|
|
|
static int configure_return(char *);
|
2020-02-07 06:42:33 +01:00
|
|
|
|
static int configure_redirect(char *);
|
2016-02-01 21:33:51 +01:00
|
|
|
|
static int configure_static_handler(char *);
|
|
|
|
|
static int configure_dynamic_handler(char *);
|
2019-11-15 08:11:02 +01:00
|
|
|
|
static int configure_restrict(char *);
|
2016-02-01 21:33:51 +01:00
|
|
|
|
static int configure_accesslog(char *);
|
|
|
|
|
static int configure_http_header_max(char *);
|
2019-04-11 20:51:49 +02:00
|
|
|
|
static int configure_http_header_timeout(char *);
|
2016-02-01 21:33:51 +01:00
|
|
|
|
static int configure_http_body_max(char *);
|
2019-04-11 20:51:49 +02:00
|
|
|
|
static int configure_http_body_timeout(char *);
|
2018-07-03 19:58:43 +02:00
|
|
|
|
static int configure_filemap_ext(char *);
|
2018-06-28 23:00:42 +02:00
|
|
|
|
static int configure_filemap_index(char *);
|
2018-06-28 13:27:44 +02:00
|
|
|
|
static int configure_http_media_type(char *);
|
2016-02-01 21:33:51 +01:00
|
|
|
|
static int configure_http_hsts_enable(char *);
|
|
|
|
|
static int configure_http_keepalive_time(char *);
|
2018-03-14 13:41:17 +01:00
|
|
|
|
static int configure_http_request_ms(char *);
|
2016-02-01 21:33:51 +01:00
|
|
|
|
static int configure_http_request_limit(char *);
|
|
|
|
|
static int configure_http_body_disk_offload(char *);
|
|
|
|
|
static int configure_http_body_disk_path(char *);
|
2020-02-18 22:29:41 +01:00
|
|
|
|
static int configure_http_server_version(char *);
|
2020-03-03 12:53:18 +01:00
|
|
|
|
static int configure_http_pretty_error(char *);
|
2016-02-01 21:33:51 +01:00
|
|
|
|
static int configure_validator(char *);
|
|
|
|
|
static int configure_params(char *);
|
|
|
|
|
static int configure_validate(char *);
|
|
|
|
|
static int configure_authentication(char *);
|
|
|
|
|
static int configure_authentication_uri(char *);
|
|
|
|
|
static int configure_authentication_type(char *);
|
|
|
|
|
static int configure_authentication_value(char *);
|
|
|
|
|
static int configure_authentication_validator(char *);
|
|
|
|
|
static int configure_websocket_maxframe(char *);
|
|
|
|
|
static int configure_websocket_timeout(char *);
|
2015-11-27 16:22:50 +01:00
|
|
|
|
#endif
|
2014-01-22 22:55:10 +01:00
|
|
|
|
|
2014-07-04 09:14:05 +02:00
|
|
|
|
#if defined(KORE_USE_PGSQL)
|
2016-02-01 21:33:51 +01:00
|
|
|
|
static int configure_pgsql_conn_max(char *);
|
2018-02-13 13:21:27 +01:00
|
|
|
|
static int configure_pgsql_queue_limit(char *);
|
2014-07-04 09:14:05 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2015-06-04 10:29:22 +02:00
|
|
|
|
#if defined(KORE_USE_TASKS)
|
2016-02-01 21:33:51 +01:00
|
|
|
|
static int configure_task_threads(char *);
|
2015-06-04 10:29:22 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2017-01-12 23:38:51 +01:00
|
|
|
|
#if defined(KORE_USE_PYTHON)
|
2019-09-26 15:49:00 +02:00
|
|
|
|
static int configure_deployment(char *);
|
2018-03-01 12:55:33 +01:00
|
|
|
|
static int configure_python_path(char *);
|
2017-01-12 23:38:51 +01:00
|
|
|
|
static int configure_python_import(char *);
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-04-24 00:10:47 +02:00
|
|
|
|
#if defined(KORE_USE_CURL)
|
|
|
|
|
static int configure_curl_timeout(char *);
|
|
|
|
|
static int configure_curl_recv_max(char *);
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-10-31 12:52:10 +01:00
|
|
|
|
#if defined(__linux__)
|
|
|
|
|
static int configure_seccomp_tracing(char *);
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-05-01 17:17:16 +02:00
|
|
|
|
static struct {
|
|
|
|
|
const char *name;
|
2016-02-01 21:33:51 +01:00
|
|
|
|
int (*configure)(char *);
|
2019-09-26 15:49:00 +02:00
|
|
|
|
} config_directives[] = {
|
2019-09-27 12:22:35 +02:00
|
|
|
|
{ "tls", configure_tls },
|
2019-11-06 19:33:53 +01:00
|
|
|
|
#if defined(KORE_USE_ACME)
|
|
|
|
|
{ "acme", configure_acme },
|
|
|
|
|
#endif
|
2013-06-26 16:37:22 +02:00
|
|
|
|
{ "bind", configure_bind },
|
|
|
|
|
{ "load", configure_load },
|
2019-09-26 15:49:00 +02:00
|
|
|
|
{ "domain", configure_domain },
|
2019-11-06 19:33:53 +01:00
|
|
|
|
{ "server", configure_server },
|
2019-09-27 12:22:35 +02:00
|
|
|
|
{ "attach", configure_attach },
|
2019-09-26 15:49:00 +02:00
|
|
|
|
{ "certkey", configure_certkey },
|
2019-11-06 19:33:53 +01:00
|
|
|
|
{ "certfile", configure_certfile },
|
|
|
|
|
{ "include", configure_include },
|
|
|
|
|
{ "unix", configure_bind_unix },
|
2019-09-26 15:49:00 +02:00
|
|
|
|
{ "client_verify", configure_client_verify },
|
|
|
|
|
{ "client_verify_depth", configure_client_verify_depth },
|
2019-09-27 12:22:35 +02:00
|
|
|
|
#if defined(KORE_USE_PYTHON)
|
|
|
|
|
{ "python_path", configure_python_path },
|
|
|
|
|
{ "python_import", configure_python_import },
|
2019-09-26 15:49:00 +02:00
|
|
|
|
#endif
|
|
|
|
|
#if !defined(KORE_NO_HTTP)
|
2019-11-15 08:11:02 +01:00
|
|
|
|
{ "route", configure_route},
|
2019-09-26 15:49:00 +02:00
|
|
|
|
{ "filemap", configure_filemap },
|
2020-02-07 06:42:33 +01:00
|
|
|
|
{ "redirect", configure_redirect },
|
2020-03-03 11:28:16 +01:00
|
|
|
|
{ "return", configure_return },
|
2019-09-26 15:49:00 +02:00
|
|
|
|
{ "static", configure_static_handler },
|
|
|
|
|
{ "dynamic", configure_dynamic_handler },
|
|
|
|
|
{ "accesslog", configure_accesslog },
|
|
|
|
|
{ "restrict", configure_restrict },
|
|
|
|
|
{ "validator", configure_validator },
|
|
|
|
|
{ "params", configure_params },
|
|
|
|
|
{ "validate", configure_validate },
|
|
|
|
|
{ "authentication", configure_authentication },
|
|
|
|
|
{ "authentication_uri", configure_authentication_uri },
|
|
|
|
|
{ "authentication_type", configure_authentication_type },
|
|
|
|
|
{ "authentication_value", configure_authentication_value },
|
|
|
|
|
{ "authentication_validator", configure_authentication_validator },
|
|
|
|
|
#endif
|
|
|
|
|
{ NULL, NULL },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
|
const char *name;
|
|
|
|
|
int (*configure)(char *);
|
|
|
|
|
} config_settings[] = {
|
2018-07-11 09:44:29 +02:00
|
|
|
|
{ "root", configure_root },
|
|
|
|
|
{ "chroot", configure_root },
|
2013-06-26 16:37:22 +02:00
|
|
|
|
{ "runas", configure_runas },
|
|
|
|
|
{ "workers", configure_workers },
|
|
|
|
|
{ "worker_max_connections", configure_max_connections },
|
2014-07-31 09:14:03 +02:00
|
|
|
|
{ "worker_rlimit_nofiles", configure_rlimit_nofiles },
|
2015-05-18 12:20:28 +02:00
|
|
|
|
{ "worker_accept_threshold", configure_accept_threshold },
|
2019-03-22 09:49:50 +01:00
|
|
|
|
{ "worker_death_policy", configure_death_policy },
|
2015-04-27 10:36:33 +02:00
|
|
|
|
{ "worker_set_affinity", configure_set_affinity },
|
2013-06-26 16:37:22 +02:00
|
|
|
|
{ "pidfile", configure_pidfile },
|
2015-11-27 16:22:50 +01:00
|
|
|
|
{ "socket_backlog", configure_socket_backlog },
|
|
|
|
|
{ "tls_version", configure_tls_version },
|
|
|
|
|
{ "tls_cipher", configure_tls_cipher },
|
|
|
|
|
{ "tls_dhparam", configure_tls_dhparam },
|
2017-02-28 05:58:04 +01:00
|
|
|
|
{ "rand_file", configure_rand_file },
|
2018-07-11 09:44:29 +02:00
|
|
|
|
{ "keymgr_runas", configure_keymgr_runas },
|
|
|
|
|
{ "keymgr_root", configure_keymgr_root },
|
2019-11-06 19:33:53 +01:00
|
|
|
|
#if defined(KORE_USE_ACME)
|
|
|
|
|
{ "acme_runas", configure_acme_runas },
|
|
|
|
|
{ "acme_root", configure_acme_root },
|
2020-01-13 11:00:40 +01:00
|
|
|
|
{ "acme_email", configure_acme_email },
|
2019-11-06 19:33:53 +01:00
|
|
|
|
{ "acme_provider", configure_acme_provider },
|
|
|
|
|
#endif
|
2019-09-27 12:22:35 +02:00
|
|
|
|
#if defined(KORE_USE_PLATFORM_PLEDGE)
|
|
|
|
|
{ "pledge", configure_add_pledge },
|
2015-11-27 16:22:50 +01:00
|
|
|
|
#endif
|
2019-10-31 12:52:10 +01:00
|
|
|
|
#if defined(__linux__)
|
|
|
|
|
{ "seccomp_tracing", configure_seccomp_tracing },
|
|
|
|
|
#endif
|
2015-11-27 16:22:50 +01:00
|
|
|
|
#if !defined(KORE_NO_HTTP)
|
2018-07-03 19:58:43 +02:00
|
|
|
|
{ "filemap_ext", configure_filemap_ext },
|
2018-06-28 23:00:42 +02:00
|
|
|
|
{ "filemap_index", configure_filemap_index },
|
2018-06-28 13:27:44 +02:00
|
|
|
|
{ "http_media_type", configure_http_media_type },
|
2013-09-22 20:05:24 +02:00
|
|
|
|
{ "http_header_max", configure_http_header_max },
|
2019-04-11 20:51:49 +02:00
|
|
|
|
{ "http_header_timeout", configure_http_header_timeout },
|
2014-10-08 11:03:14 +02:00
|
|
|
|
{ "http_body_max", configure_http_body_max },
|
2019-04-11 20:51:49 +02:00
|
|
|
|
{ "http_body_timeout", configure_http_body_timeout },
|
2013-10-15 10:44:56 +02:00
|
|
|
|
{ "http_hsts_enable", configure_http_hsts_enable },
|
2013-10-15 11:10:45 +02:00
|
|
|
|
{ "http_keepalive_time", configure_http_keepalive_time },
|
2018-03-14 13:41:17 +01:00
|
|
|
|
{ "http_request_ms", configure_http_request_ms },
|
2015-04-09 15:29:44 +02:00
|
|
|
|
{ "http_request_limit", configure_http_request_limit },
|
2016-01-18 11:30:22 +01:00
|
|
|
|
{ "http_body_disk_offload", configure_http_body_disk_offload },
|
|
|
|
|
{ "http_body_disk_path", configure_http_body_disk_path },
|
2020-02-18 22:29:41 +01:00
|
|
|
|
{ "http_server_version", configure_http_server_version },
|
2020-03-03 12:53:18 +01:00
|
|
|
|
{ "http_pretty_error", configure_http_pretty_error },
|
2014-11-24 11:01:12 +01:00
|
|
|
|
{ "websocket_maxframe", configure_websocket_maxframe },
|
|
|
|
|
{ "websocket_timeout", configure_websocket_timeout },
|
2015-11-27 16:22:50 +01:00
|
|
|
|
#endif
|
2019-09-26 15:49:00 +02:00
|
|
|
|
#if defined(KORE_USE_PYTHON)
|
|
|
|
|
{ "deployment", configure_deployment },
|
|
|
|
|
#endif
|
2014-07-04 09:14:05 +02:00
|
|
|
|
#if defined(KORE_USE_PGSQL)
|
|
|
|
|
{ "pgsql_conn_max", configure_pgsql_conn_max },
|
2018-02-13 13:21:27 +01:00
|
|
|
|
{ "pgsql_queue_limit", configure_pgsql_queue_limit },
|
2015-06-04 10:29:22 +02:00
|
|
|
|
#endif
|
|
|
|
|
#if defined(KORE_USE_TASKS)
|
|
|
|
|
{ "task_threads", configure_task_threads },
|
2019-04-24 00:10:47 +02:00
|
|
|
|
#endif
|
|
|
|
|
#if defined(KORE_USE_CURL)
|
|
|
|
|
{ "curl_timeout", configure_curl_timeout },
|
|
|
|
|
{ "curl_recv_max", configure_curl_recv_max },
|
2019-09-26 15:49:00 +02:00
|
|
|
|
#endif
|
|
|
|
|
#if !defined(KORE_SINGLE_BINARY) && defined(KORE_USE_PYTHON)
|
|
|
|
|
{ "file", configure_file },
|
2014-07-04 09:14:05 +02:00
|
|
|
|
#endif
|
2013-06-26 16:37:22 +02:00
|
|
|
|
{ NULL, NULL },
|
2013-05-01 17:17:16 +02:00
|
|
|
|
};
|
|
|
|
|
|
2019-09-26 15:49:00 +02:00
|
|
|
|
static int finalized = 0;
|
|
|
|
|
|
2016-07-06 16:16:15 +02:00
|
|
|
|
#if !defined(KORE_SINGLE_BINARY)
|
2013-11-10 15:17:15 +01:00
|
|
|
|
char *config_file = NULL;
|
2016-07-06 16:16:15 +02:00
|
|
|
|
#endif
|
2015-11-27 16:22:50 +01:00
|
|
|
|
|
|
|
|
|
#if !defined(KORE_NO_HTTP)
|
2013-11-10 15:17:15 +01:00
|
|
|
|
static u_int8_t current_method = 0;
|
2018-01-16 18:47:50 +01:00
|
|
|
|
static int current_flags = 0;
|
2014-01-22 22:55:10 +01:00
|
|
|
|
static struct kore_auth *current_auth = NULL;
|
2013-11-10 15:17:15 +01:00
|
|
|
|
static struct kore_module_handle *current_handler = NULL;
|
2015-11-27 16:22:50 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
2016-07-06 16:16:15 +02:00
|
|
|
|
extern const char *__progname;
|
2015-11-27 16:22:50 +01:00
|
|
|
|
static struct kore_domain *current_domain = NULL;
|
2019-09-27 20:00:35 +02:00
|
|
|
|
static struct kore_server *current_server = NULL;
|
2013-05-02 13:30:13 +02:00
|
|
|
|
|
2013-05-01 17:17:16 +02:00
|
|
|
|
void
|
2013-06-26 11:18:32 +02:00
|
|
|
|
kore_parse_config(void)
|
2014-04-22 13:15:19 +02:00
|
|
|
|
{
|
2018-04-09 12:51:20 +02:00
|
|
|
|
FILE *fp;
|
2021-04-21 22:39:35 +02:00
|
|
|
|
BIO *bio;
|
2018-07-11 09:44:29 +02:00
|
|
|
|
char path[PATH_MAX];
|
2018-04-09 12:51:20 +02:00
|
|
|
|
|
2019-09-26 15:49:00 +02:00
|
|
|
|
if (finalized)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
fp = NULL;
|
|
|
|
|
|
2016-07-06 16:16:15 +02:00
|
|
|
|
#if !defined(KORE_SINGLE_BINARY)
|
2019-09-26 15:49:00 +02:00
|
|
|
|
if (config_file != NULL) {
|
|
|
|
|
if ((fp = fopen(config_file, "r")) == NULL) {
|
|
|
|
|
fatal("configuration given cannot be opened: %s",
|
|
|
|
|
config_file);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-06 16:16:15 +02:00
|
|
|
|
#else
|
2018-04-09 12:51:20 +02:00
|
|
|
|
fp = config_file_write();
|
2016-07-06 16:16:15 +02:00
|
|
|
|
#endif
|
2014-04-22 13:15:19 +02:00
|
|
|
|
|
2019-09-26 15:49:00 +02:00
|
|
|
|
if (fp != NULL) {
|
|
|
|
|
kore_parse_config_file(fp);
|
|
|
|
|
(void)fclose(fp);
|
|
|
|
|
}
|
2018-04-09 12:51:20 +02:00
|
|
|
|
|
2021-04-21 22:39:35 +02:00
|
|
|
|
if (tls_dhparam == NULL) {
|
|
|
|
|
if ((bio = BIO_new_file(KORE_DHPARAM_PATH, "r")) == NULL)
|
|
|
|
|
fatal("failed to open %s", KORE_DHPARAM_PATH);
|
|
|
|
|
|
|
|
|
|
tls_dhparam = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
|
|
|
|
|
BIO_free(bio);
|
|
|
|
|
|
|
|
|
|
if (tls_dhparam == NULL)
|
|
|
|
|
fatal("PEM_read_bio_DHparams(): %s", ssl_errno_s);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-22 13:15:19 +02:00
|
|
|
|
if (!kore_module_loaded())
|
2016-07-06 16:16:15 +02:00
|
|
|
|
fatal("no application module was loaded");
|
2014-07-31 13:59:42 +02:00
|
|
|
|
|
2018-07-11 09:44:29 +02:00
|
|
|
|
if (kore_root_path == NULL) {
|
|
|
|
|
if (getcwd(path, sizeof(path)) == NULL)
|
|
|
|
|
fatal("getcwd: %s", errno_s);
|
|
|
|
|
kore_root_path = kore_strdup(path);
|
2018-11-15 16:01:37 +01:00
|
|
|
|
|
|
|
|
|
if (!kore_quiet) {
|
|
|
|
|
kore_log(LOG_NOTICE, "privsep: no root path set, "
|
|
|
|
|
"using working directory");
|
|
|
|
|
}
|
2015-05-18 21:34:39 +02:00
|
|
|
|
}
|
2015-05-20 11:34:57 +02:00
|
|
|
|
|
2021-04-21 22:39:35 +02:00
|
|
|
|
if (getuid() != 0 && skip_chroot == 0)
|
2015-05-18 21:34:39 +02:00
|
|
|
|
fatal("cannot chroot, use -n to skip it");
|
2014-07-31 13:59:42 +02:00
|
|
|
|
|
2021-04-21 22:39:35 +02:00
|
|
|
|
if (skip_runas != 1 && kore_runas_user == NULL)
|
2016-02-01 21:54:09 +01:00
|
|
|
|
fatal("missing runas user, use -r to skip it");
|
2015-05-20 11:34:57 +02:00
|
|
|
|
|
2021-04-21 22:39:35 +02:00
|
|
|
|
if (getuid() != 0 && skip_runas == 0)
|
2015-12-08 02:42:16 +01:00
|
|
|
|
fatal("cannot drop privileges, use -r to skip it");
|
2018-07-11 09:44:29 +02:00
|
|
|
|
|
|
|
|
|
if (skip_runas) {
|
2018-11-15 16:01:37 +01:00
|
|
|
|
if (!kore_quiet)
|
|
|
|
|
kore_log(LOG_WARNING, "privsep: will not change user");
|
2018-07-11 09:44:29 +02:00
|
|
|
|
} else {
|
2019-11-06 19:33:53 +01:00
|
|
|
|
configure_check_var(&keymgr_runas_user, kore_runas_user,
|
|
|
|
|
"privsep: no keymgr_runas set, using 'runas` user");
|
|
|
|
|
#if defined(KORE_USE_ACME)
|
|
|
|
|
configure_check_var(&acme_runas_user, kore_runas_user,
|
|
|
|
|
"privsep: no acme_runas set, using 'runas` user");
|
|
|
|
|
#endif
|
2018-07-11 09:44:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-06 19:33:53 +01:00
|
|
|
|
configure_check_var(&keymgr_root_path, kore_root_path,
|
|
|
|
|
"privsep: no keymgr_root set, using 'root` directory");
|
|
|
|
|
|
|
|
|
|
#if defined(KORE_USE_ACME)
|
|
|
|
|
configure_check_var(&acme_root_path, kore_root_path,
|
|
|
|
|
"privsep: no acme_root set, using 'root` directory");
|
|
|
|
|
#endif
|
2018-07-11 09:44:29 +02:00
|
|
|
|
|
2018-11-15 16:01:37 +01:00
|
|
|
|
if (skip_chroot && !kore_quiet)
|
2018-07-11 09:44:29 +02:00
|
|
|
|
kore_log(LOG_WARNING, "privsep: will not chroot");
|
2019-09-26 15:49:00 +02:00
|
|
|
|
|
|
|
|
|
finalized = 1;
|
2014-04-22 13:15:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-09 12:51:20 +02:00
|
|
|
|
void
|
|
|
|
|
kore_parse_config_file(FILE *fp)
|
2013-05-01 17:17:16 +02:00
|
|
|
|
{
|
|
|
|
|
int i, lineno;
|
2016-02-01 21:33:51 +01:00
|
|
|
|
char buf[BUFSIZ], *p, *t;
|
2013-05-01 17:17:16 +02:00
|
|
|
|
|
|
|
|
|
lineno = 1;
|
2016-02-01 22:10:10 +01:00
|
|
|
|
while ((p = kore_read_line(fp, buf, sizeof(buf))) != NULL) {
|
|
|
|
|
if (strlen(p) == 0) {
|
2013-05-01 17:17:16 +02:00
|
|
|
|
lineno++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-27 20:00:35 +02:00
|
|
|
|
if (!strcmp(p, "}") && current_server != NULL) {
|
2019-09-27 12:22:35 +02:00
|
|
|
|
lineno++;
|
2019-09-27 20:00:35 +02:00
|
|
|
|
kore_server_finalize(current_server);
|
|
|
|
|
current_server = NULL;
|
2019-09-27 12:22:35 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-27 16:22:50 +01:00
|
|
|
|
#if !defined(KORE_NO_HTTP)
|
2013-11-10 15:17:15 +01:00
|
|
|
|
if (!strcmp(p, "}") && current_handler != NULL) {
|
|
|
|
|
lineno++;
|
2018-01-16 18:47:50 +01:00
|
|
|
|
current_flags = 0;
|
|
|
|
|
current_method = 0;
|
2013-11-10 15:17:15 +01:00
|
|
|
|
current_handler = NULL;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-22 22:55:10 +01:00
|
|
|
|
if (!strcmp(p, "}") && current_auth != NULL) {
|
|
|
|
|
if (current_auth->validator == NULL) {
|
|
|
|
|
fatal("no authentication validator for %s",
|
|
|
|
|
current_auth->name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lineno++;
|
|
|
|
|
current_auth = NULL;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-11-27 16:22:50 +01:00
|
|
|
|
#endif
|
2014-01-22 22:55:10 +01:00
|
|
|
|
|
2019-03-26 21:36:45 +01:00
|
|
|
|
if (!strcmp(p, "}") && current_domain != NULL) {
|
2019-09-27 20:00:35 +02:00
|
|
|
|
if (current_domain->server == NULL) {
|
|
|
|
|
fatal("domain '%s' not attached to server",
|
2019-09-27 12:22:35 +02:00
|
|
|
|
current_domain->domain);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-06 19:33:53 +01:00
|
|
|
|
if (current_domain->server->tls == 1) {
|
|
|
|
|
#if defined(KORE_USE_ACME)
|
|
|
|
|
if (current_domain->acme) {
|
|
|
|
|
lineno++;
|
|
|
|
|
current_domain = NULL;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
if (current_domain->certfile == NULL ||
|
|
|
|
|
current_domain->certkey == NULL) {
|
|
|
|
|
fatal("incomplete TLS setup for '%s'",
|
|
|
|
|
current_domain->domain);
|
|
|
|
|
}
|
2019-03-26 21:36:45 +01:00
|
|
|
|
}
|
2019-09-27 12:22:35 +02:00
|
|
|
|
|
2018-07-11 09:44:29 +02:00
|
|
|
|
current_domain = NULL;
|
2019-03-26 21:36:45 +01:00
|
|
|
|
}
|
2013-06-24 11:32:45 +02:00
|
|
|
|
|
2015-05-07 16:24:08 +02:00
|
|
|
|
if (!strcmp(p, "}")) {
|
|
|
|
|
lineno++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
if ((t = strchr(p, ' ')) == NULL) {
|
|
|
|
|
printf("ignoring \"%s\" on line %d\n", p, lineno++);
|
|
|
|
|
continue;
|
2013-05-01 17:17:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
*(t)++ = '\0';
|
|
|
|
|
|
|
|
|
|
p = kore_text_trim(p, strlen(p));
|
|
|
|
|
t = kore_text_trim(t, strlen(t));
|
|
|
|
|
|
|
|
|
|
if (strlen(p) == 0 || strlen(t) == 0) {
|
|
|
|
|
printf("ignoring \"%s\" on line %d\n", p, lineno++);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-26 15:49:00 +02:00
|
|
|
|
for (i = 0; config_directives[i].name != NULL; i++) {
|
|
|
|
|
if (!strcmp(config_directives[i].name, p)) {
|
|
|
|
|
if (config_directives[i].configure(t))
|
|
|
|
|
break;
|
|
|
|
|
fatal("configuration error on line %d", lineno);
|
|
|
|
|
/* NOTREACHED */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (config_directives[i].name != NULL) {
|
|
|
|
|
lineno++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; config_settings[i].name != NULL; i++) {
|
|
|
|
|
if (!strcmp(config_settings[i].name, p)) {
|
|
|
|
|
if (config_settings[i].configure(t))
|
2016-02-01 21:33:51 +01:00
|
|
|
|
break;
|
|
|
|
|
fatal("configuration error on line %d", lineno);
|
|
|
|
|
/* NOTREACHED */
|
|
|
|
|
}
|
2015-05-06 10:59:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-26 15:49:00 +02:00
|
|
|
|
if (config_settings[i].name == NULL)
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("ignoring \"%s\" on line %d\n", p, lineno);
|
2019-09-26 15:49:00 +02:00
|
|
|
|
|
2013-05-01 17:17:16 +02:00
|
|
|
|
lineno++;
|
|
|
|
|
}
|
2014-04-22 13:15:19 +02:00
|
|
|
|
}
|
2014-04-09 14:43:23 +02:00
|
|
|
|
|
2019-09-26 15:49:00 +02:00
|
|
|
|
#if defined(KORE_USE_PYTHON)
|
|
|
|
|
int
|
|
|
|
|
kore_configure_setting(const char *name, char *value)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (finalized)
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
|
|
|
|
|
for (i = 0; config_settings[i].name != NULL; i++) {
|
|
|
|
|
if (!strcmp(config_settings[i].name, name)) {
|
|
|
|
|
if (config_settings[i].configure(value))
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
fatal("bad value '%s' for '%s'", value, name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kore_log(LOG_NOTICE, "ignoring unknown kore.config.%s setting", name);
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-11-06 19:33:53 +01:00
|
|
|
|
static void
|
|
|
|
|
configure_check_var(char **var, const char *other, const char *logmsg)
|
|
|
|
|
{
|
|
|
|
|
if (*var == NULL) {
|
|
|
|
|
if (!kore_quiet)
|
|
|
|
|
kore_log(LOG_NOTICE, "%s", logmsg);
|
|
|
|
|
*var = kore_strdup(other);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-22 13:15:19 +02:00
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_include(char *path)
|
2014-04-22 13:15:19 +02:00
|
|
|
|
{
|
2018-04-09 12:51:20 +02:00
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
|
|
if ((fp = fopen(path, "r")) == NULL)
|
|
|
|
|
fatal("failed to open include '%s'", path);
|
|
|
|
|
|
|
|
|
|
kore_parse_config_file(fp);
|
2018-04-10 14:39:57 +02:00
|
|
|
|
(void)fclose(fp);
|
2018-02-14 13:48:49 +01:00
|
|
|
|
|
2014-04-22 13:15:19 +02:00
|
|
|
|
return (KORE_RESULT_OK);
|
2013-05-01 17:17:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-27 12:22:35 +02:00
|
|
|
|
static int
|
2019-09-27 20:00:35 +02:00
|
|
|
|
configure_server(char *options)
|
2019-09-27 12:22:35 +02:00
|
|
|
|
{
|
2019-09-27 20:00:35 +02:00
|
|
|
|
struct kore_server *srv;
|
2019-09-27 12:22:35 +02:00
|
|
|
|
char *argv[3];
|
|
|
|
|
|
2019-09-27 20:00:35 +02:00
|
|
|
|
if (current_server != NULL) {
|
|
|
|
|
printf("nested server contexts are not allowed\n");
|
2019-09-27 12:22:35 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kore_split_string(options, " ", argv, 3);
|
|
|
|
|
|
|
|
|
|
if (argv[0] == NULL || argv[1] == NULL) {
|
2019-09-27 20:00:35 +02:00
|
|
|
|
printf("invalid server context\n");
|
2019-09-27 12:22:35 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strcmp(argv[1], "{")) {
|
2019-09-27 20:00:35 +02:00
|
|
|
|
printf("server context not opened correctly\n");
|
2019-09-27 12:22:35 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-27 20:00:35 +02:00
|
|
|
|
if ((srv = kore_server_lookup(argv[0])) != NULL) {
|
|
|
|
|
printf("a server with name '%s' already exists\n", srv->name);
|
2019-09-27 12:22:35 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-27 20:00:35 +02:00
|
|
|
|
current_server = kore_server_create(argv[0]);
|
2019-09-27 12:22:35 +02:00
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
configure_tls(char *yesno)
|
|
|
|
|
{
|
2019-09-27 20:00:35 +02:00
|
|
|
|
if (current_server == NULL) {
|
|
|
|
|
printf("bind directive not inside a server context\n");
|
2019-09-27 12:22:35 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strcmp(yesno, "no")) {
|
2019-09-27 20:00:35 +02:00
|
|
|
|
current_server->tls = 0;
|
2019-09-27 12:22:35 +02:00
|
|
|
|
} else if (!strcmp(yesno, "yes")) {
|
2019-09-27 20:00:35 +02:00
|
|
|
|
current_server->tls = 1;
|
2019-09-27 12:22:35 +02:00
|
|
|
|
} else {
|
|
|
|
|
printf("invalid '%s' for yes|no tls option\n", yesno);
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-06 19:33:53 +01:00
|
|
|
|
#if defined(KORE_USE_ACME)
|
|
|
|
|
static int
|
|
|
|
|
configure_acme(char *yesno)
|
|
|
|
|
{
|
|
|
|
|
if (current_domain == NULL) {
|
|
|
|
|
printf("acme directive not inside a domain context\n");
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strchr(current_domain->domain, '*')) {
|
|
|
|
|
printf("wildcards not supported due to lack of dns-01\n");
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strcmp(yesno, "no")) {
|
|
|
|
|
current_domain->acme = 0;
|
|
|
|
|
} else if (!strcmp(yesno, "yes")) {
|
|
|
|
|
current_domain->acme = 1;
|
|
|
|
|
|
|
|
|
|
/* Override keyfile and certfile locations. */
|
|
|
|
|
kore_free(current_domain->certkey);
|
|
|
|
|
kore_free(current_domain->certfile);
|
|
|
|
|
|
2019-11-13 23:01:24 +01:00
|
|
|
|
kore_acme_get_paths(current_domain->domain,
|
|
|
|
|
¤t_domain->certkey, ¤t_domain->certfile);
|
2019-11-06 19:33:53 +01:00
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
printf("invalid '%s' for yes|no acme option\n", yesno);
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
configure_acme_runas(char *user)
|
|
|
|
|
{
|
|
|
|
|
kore_free(acme_runas_user);
|
|
|
|
|
acme_runas_user = kore_strdup(user);
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
configure_acme_root(char *root)
|
|
|
|
|
{
|
|
|
|
|
kore_free(acme_root_path);
|
|
|
|
|
acme_root_path = kore_strdup(root);
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-13 11:00:40 +01:00
|
|
|
|
static int
|
|
|
|
|
configure_acme_email(char *email)
|
|
|
|
|
{
|
|
|
|
|
kore_free(acme_email);
|
|
|
|
|
acme_email = kore_strdup(email);
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-06 19:33:53 +01:00
|
|
|
|
static int
|
|
|
|
|
configure_acme_provider(char *provider)
|
|
|
|
|
{
|
|
|
|
|
kore_free(acme_provider);
|
|
|
|
|
acme_provider = kore_strdup(provider);
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-05-01 17:17:16 +02:00
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_bind(char *options)
|
2013-05-01 17:17:16 +02:00
|
|
|
|
{
|
2016-02-01 21:33:51 +01:00
|
|
|
|
char *argv[4];
|
|
|
|
|
|
2019-09-27 20:00:35 +02:00
|
|
|
|
if (current_server == NULL) {
|
|
|
|
|
printf("bind directive not inside a server context\n");
|
2019-09-27 12:22:35 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
kore_split_string(options, " ", argv, 4);
|
|
|
|
|
if (argv[0] == NULL || argv[1] == NULL)
|
2013-05-01 17:17:16 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
|
2019-09-27 20:00:35 +02:00
|
|
|
|
return (kore_server_bind(current_server, argv[0], argv[1], argv[2]));
|
2013-05-01 17:17:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-07 20:49:16 +02:00
|
|
|
|
static int
|
|
|
|
|
configure_bind_unix(char *options)
|
|
|
|
|
{
|
|
|
|
|
char *argv[3];
|
|
|
|
|
|
2019-09-27 20:00:35 +02:00
|
|
|
|
if (current_server == NULL) {
|
|
|
|
|
printf("bind_unix directive not inside a server context\n");
|
2019-09-27 12:22:35 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-07 20:49:16 +02:00
|
|
|
|
kore_split_string(options, " ", argv, 3);
|
|
|
|
|
if (argv[0] == NULL)
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
|
2019-09-27 20:00:35 +02:00
|
|
|
|
return (kore_server_bind_unix(current_server, argv[0], argv[1]));
|
2018-10-07 20:49:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-01 17:17:16 +02:00
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_load(char *options)
|
2013-05-01 17:17:16 +02:00
|
|
|
|
{
|
2016-02-01 21:33:51 +01:00
|
|
|
|
char *argv[3];
|
|
|
|
|
|
|
|
|
|
kore_split_string(options, " ", argv, 3);
|
|
|
|
|
if (argv[0] == NULL)
|
2013-05-01 17:17:16 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
|
2017-01-12 23:38:51 +01:00
|
|
|
|
kore_module_load(argv[0], argv[1], KORE_MODULE_NATIVE);
|
2013-05-30 21:26:39 +02:00
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
2017-01-26 13:13:23 +01:00
|
|
|
|
|
|
|
|
|
#if defined(KORE_SINGLE_BINARY)
|
2016-07-06 16:16:15 +02:00
|
|
|
|
static FILE *
|
|
|
|
|
config_file_write(void)
|
|
|
|
|
{
|
|
|
|
|
FILE *fp;
|
|
|
|
|
ssize_t ret;
|
|
|
|
|
int fd, len;
|
|
|
|
|
char fpath[MAXPATHLEN];
|
|
|
|
|
|
|
|
|
|
len = snprintf(fpath, sizeof(fpath), "/tmp/%s.XXXXXX", __progname);
|
|
|
|
|
if (len == -1 || (size_t)len >= sizeof(fpath))
|
|
|
|
|
fatal("failed to create temporary path");
|
|
|
|
|
|
|
|
|
|
if ((fd = mkstemp(fpath)) == -1)
|
|
|
|
|
fatal("mkstemp(%s): %s", fpath, errno_s);
|
|
|
|
|
|
|
|
|
|
(void)unlink(fpath);
|
|
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
ret = write(fd, asset_builtin_kore_conf,
|
|
|
|
|
asset_len_builtin_kore_conf);
|
|
|
|
|
if (ret == -1) {
|
|
|
|
|
if (errno == EINTR)
|
|
|
|
|
continue;
|
|
|
|
|
fatal("failed to write temporary config: %s", errno_s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((size_t)ret != asset_len_builtin_kore_conf)
|
|
|
|
|
fatal("failed to write temporary config");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((fp = fdopen(fd, "w+")) == NULL)
|
|
|
|
|
fatal("fdopen(): %s", errno_s);
|
|
|
|
|
|
|
|
|
|
rewind(fp);
|
|
|
|
|
|
|
|
|
|
return (fp);
|
|
|
|
|
}
|
2019-09-26 15:49:00 +02:00
|
|
|
|
#elif defined(KORE_USE_PYTHON)
|
|
|
|
|
static int
|
|
|
|
|
configure_file(char *file)
|
|
|
|
|
{
|
2019-09-26 19:58:13 +02:00
|
|
|
|
free(config_file);
|
|
|
|
|
if ((config_file = strdup(file)) == NULL)
|
|
|
|
|
fatal("strdup");
|
2019-09-26 15:49:00 +02:00
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
2016-07-06 16:16:15 +02:00
|
|
|
|
#endif
|
2013-05-30 21:26:39 +02:00
|
|
|
|
|
2013-06-27 08:43:07 +02:00
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_tls_version(char *version)
|
2015-05-06 10:59:43 +02:00
|
|
|
|
{
|
2018-10-29 20:38:58 +01:00
|
|
|
|
if (!strcmp(version, "1.3")) {
|
|
|
|
|
tls_version = KORE_TLS_VERSION_1_3;
|
|
|
|
|
} else if (!strcmp(version, "1.2")) {
|
2015-05-06 10:59:43 +02:00
|
|
|
|
tls_version = KORE_TLS_VERSION_1_2;
|
2016-02-01 21:33:51 +01:00
|
|
|
|
} else if (!strcmp(version, "both")) {
|
2015-05-06 10:59:43 +02:00
|
|
|
|
tls_version = KORE_TLS_VERSION_BOTH;
|
|
|
|
|
} else {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("unknown value for tls_version: %s\n", version);
|
2015-05-06 10:59:43 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_tls_cipher(char *cipherlist)
|
2013-06-27 08:43:07 +02:00
|
|
|
|
{
|
2015-05-06 10:59:43 +02:00
|
|
|
|
if (strcmp(kore_tls_cipher_list, KORE_DEFAULT_CIPHER_LIST)) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("tls_cipher specified twice\n");
|
2013-06-27 08:43:07 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
kore_tls_cipher_list = kore_strdup(cipherlist);
|
2013-06-27 08:43:07 +02:00
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-07 16:51:39 +02:00
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_tls_dhparam(char *path)
|
2013-08-07 16:51:39 +02:00
|
|
|
|
{
|
|
|
|
|
BIO *bio;
|
|
|
|
|
|
2015-05-06 10:59:43 +02:00
|
|
|
|
if (tls_dhparam != NULL) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("tls_dhparam specified twice\n");
|
2013-08-07 16:51:39 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
if ((bio = BIO_new_file(path, "r")) == NULL) {
|
|
|
|
|
printf("%s did not exist\n", path);
|
2013-08-07 16:51:39 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-06 10:59:43 +02:00
|
|
|
|
tls_dhparam = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
|
2013-08-07 16:51:39 +02:00
|
|
|
|
BIO_free(bio);
|
|
|
|
|
|
2015-05-06 10:59:43 +02:00
|
|
|
|
if (tls_dhparam == NULL) {
|
2013-09-22 20:11:56 +02:00
|
|
|
|
printf("PEM_read_bio_DHparams(): %s\n", ssl_errno_s);
|
2013-08-07 16:51:39 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
2016-02-01 21:33:51 +01:00
|
|
|
|
|
2013-05-01 17:17:16 +02:00
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
2013-05-04 22:18:27 +02:00
|
|
|
|
|
2018-06-09 12:50:50 +02:00
|
|
|
|
static int
|
|
|
|
|
configure_client_verify_depth(char *value)
|
|
|
|
|
{
|
|
|
|
|
int err, depth;
|
|
|
|
|
|
|
|
|
|
if (current_domain == NULL) {
|
|
|
|
|
printf("client_verify_depth not specified in domain context\n");
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
depth = kore_strtonum(value, 10, 0, INT_MAX, &err);
|
|
|
|
|
if (err != KORE_RESULT_OK) {
|
|
|
|
|
printf("bad client_verify_depth value: %s\n", value);
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
current_domain->x509_verify_depth = depth;
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-14 16:31:07 +01:00
|
|
|
|
static int
|
2018-07-11 09:44:29 +02:00
|
|
|
|
configure_client_verify(char *options)
|
2013-12-14 16:31:07 +01:00
|
|
|
|
{
|
2016-02-01 21:33:51 +01:00
|
|
|
|
char *argv[3];
|
|
|
|
|
|
2013-12-14 16:31:07 +01:00
|
|
|
|
if (current_domain == NULL) {
|
2018-07-11 09:44:29 +02:00
|
|
|
|
printf("client_verify not specified in domain context\n");
|
2013-12-14 16:31:07 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
kore_split_string(options, " ", argv, 3);
|
|
|
|
|
if (argv[0] == NULL) {
|
2018-07-11 09:44:29 +02:00
|
|
|
|
printf("client_verify is missing a parameter\n");
|
2013-12-14 16:31:07 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (current_domain->cafile != NULL) {
|
2018-07-11 09:44:29 +02:00
|
|
|
|
printf("client_verify already set for %s\n",
|
2013-12-14 16:31:07 +01:00
|
|
|
|
current_domain->domain);
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
current_domain->cafile = kore_strdup(argv[0]);
|
|
|
|
|
if (argv[1] != NULL)
|
|
|
|
|
current_domain->crlfile = kore_strdup(argv[1]);
|
2014-10-18 02:32:05 +02:00
|
|
|
|
|
2013-12-14 16:31:07 +01:00
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-28 05:58:04 +01:00
|
|
|
|
static int
|
|
|
|
|
configure_rand_file(char *path)
|
|
|
|
|
{
|
|
|
|
|
if (rand_file != NULL)
|
|
|
|
|
kore_free(rand_file);
|
|
|
|
|
|
|
|
|
|
rand_file = kore_strdup(path);
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 09:36:40 +02:00
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_certfile(char *path)
|
2013-06-24 09:36:40 +02:00
|
|
|
|
{
|
|
|
|
|
if (current_domain == NULL) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("certfile not specified in domain context\n");
|
2013-06-24 09:36:40 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-06 19:33:53 +01:00
|
|
|
|
kore_free(current_domain->certfile);
|
2016-02-01 21:33:51 +01:00
|
|
|
|
current_domain->certfile = kore_strdup(path);
|
2013-06-24 11:32:45 +02:00
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_certkey(char *path)
|
2013-06-24 11:32:45 +02:00
|
|
|
|
{
|
|
|
|
|
if (current_domain == NULL) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("certkey not specified in domain text\n");
|
2013-06-24 09:36:40 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-06 19:33:53 +01:00
|
|
|
|
kore_free(current_domain->certkey);
|
2016-02-01 21:33:51 +01:00
|
|
|
|
current_domain->certkey = kore_strdup(path);
|
2013-06-24 09:36:40 +02:00
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
2013-06-24 11:32:45 +02:00
|
|
|
|
|
2018-07-11 09:44:29 +02:00
|
|
|
|
static int
|
|
|
|
|
configure_keymgr_runas(char *user)
|
|
|
|
|
{
|
|
|
|
|
if (keymgr_runas_user != NULL)
|
|
|
|
|
kore_free(keymgr_runas_user);
|
|
|
|
|
keymgr_runas_user = kore_strdup(user);
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
configure_keymgr_root(char *root)
|
|
|
|
|
{
|
|
|
|
|
if (keymgr_root_path != NULL)
|
|
|
|
|
kore_free(keymgr_root_path);
|
|
|
|
|
keymgr_root_path = kore_strdup(root);
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-26 16:37:22 +02:00
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_domain(char *options)
|
2013-06-26 16:37:22 +02:00
|
|
|
|
{
|
2016-02-01 21:33:51 +01:00
|
|
|
|
char *argv[3];
|
2013-06-26 16:37:22 +02:00
|
|
|
|
|
2015-11-27 16:22:50 +01:00
|
|
|
|
if (current_domain != NULL) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("nested domain contexts are not allowed\n");
|
2013-06-26 16:37:22 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
2015-11-27 16:22:50 +01:00
|
|
|
|
}
|
2013-06-26 16:37:22 +02:00
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
kore_split_string(options, " ", argv, 3);
|
|
|
|
|
|
2019-09-27 12:22:35 +02:00
|
|
|
|
if (argv[0] == NULL || argv[1] == NULL) {
|
|
|
|
|
printf("invalid domain context\n");
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
if (strcmp(argv[1], "{")) {
|
|
|
|
|
printf("domain context not opened correctly\n");
|
2015-11-27 16:22:50 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
2016-06-08 13:55:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strlen(argv[0]) >= KORE_DOMAINNAME_LEN - 1) {
|
|
|
|
|
printf("domain name '%s' too long\n", argv[0]);
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
2015-11-27 16:22:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-27 12:22:35 +02:00
|
|
|
|
current_domain = kore_domain_new(argv[0]);
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
configure_attach(char *name)
|
|
|
|
|
{
|
2019-09-27 20:00:35 +02:00
|
|
|
|
struct kore_server *srv;
|
2019-09-27 12:22:35 +02:00
|
|
|
|
|
|
|
|
|
if (current_domain == NULL) {
|
|
|
|
|
printf("attach not specified in domain context\n");
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-27 20:00:35 +02:00
|
|
|
|
if (current_domain->server != NULL) {
|
|
|
|
|
printf("domain '%s' already attached to server\n",
|
2019-09-27 12:22:35 +02:00
|
|
|
|
current_domain->domain);
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-27 20:00:35 +02:00
|
|
|
|
if ((srv = kore_server_lookup(name)) == NULL) {
|
|
|
|
|
printf("server '%s' does not exist\n", name);
|
2019-09-27 12:22:35 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-27 20:00:35 +02:00
|
|
|
|
if (!kore_domain_attach(current_domain, srv)) {
|
2019-09-27 12:22:35 +02:00
|
|
|
|
printf("failed to attach '%s' to '%s'\n",
|
|
|
|
|
current_domain->domain, name);
|
2013-06-26 16:37:22 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
2013-09-22 20:11:56 +02:00
|
|
|
|
}
|
2013-06-26 16:37:22 +02:00
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-27 16:22:50 +01:00
|
|
|
|
#if !defined(KORE_NO_HTTP)
|
2014-07-31 09:14:03 +02:00
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_static_handler(char *options)
|
|
|
|
|
{
|
2019-11-15 08:11:02 +01:00
|
|
|
|
kore_log(LOG_NOTICE, "static keyword removed, use route instead");
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
2016-02-01 21:33:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
configure_dynamic_handler(char *options)
|
2014-07-31 09:14:03 +02:00
|
|
|
|
{
|
2019-11-15 08:11:02 +01:00
|
|
|
|
kore_log(LOG_NOTICE, "dynamic keyword removed, use route instead");
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
2016-02-01 21:33:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2019-11-15 08:11:02 +01:00
|
|
|
|
configure_route(char *options)
|
2016-02-01 21:33:51 +01:00
|
|
|
|
{
|
2019-11-15 08:11:02 +01:00
|
|
|
|
int type;
|
2016-02-01 21:33:51 +01:00
|
|
|
|
char *argv[4];
|
2014-07-31 09:14:03 +02:00
|
|
|
|
|
2015-11-27 16:22:50 +01:00
|
|
|
|
if (current_domain == NULL) {
|
2019-11-15 08:11:02 +01:00
|
|
|
|
printf("route not specified in domain context\n");
|
2015-11-27 16:22:50 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
kore_split_string(options, " ", argv, 4);
|
2014-07-31 09:14:03 +02:00
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
if (argv[0] == NULL || argv[1] == NULL) {
|
2019-11-15 08:11:02 +01:00
|
|
|
|
printf("missing parameters for route \n");
|
2015-11-27 16:22:50 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
2016-02-01 21:33:51 +01:00
|
|
|
|
}
|
2015-11-27 16:22:50 +01:00
|
|
|
|
|
2019-11-15 08:11:02 +01:00
|
|
|
|
if (*argv[0] == '/')
|
|
|
|
|
type = HANDLER_TYPE_STATIC;
|
|
|
|
|
else
|
|
|
|
|
type = HANDLER_TYPE_DYNAMIC;
|
|
|
|
|
|
2019-09-27 12:22:35 +02:00
|
|
|
|
if (!kore_module_handler_new(current_domain,
|
|
|
|
|
argv[0], argv[1], argv[2], type)) {
|
2019-11-15 08:11:02 +01:00
|
|
|
|
printf("cannot create route for %s\n", argv[0]);
|
2014-07-31 09:14:03 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
2015-04-23 10:24:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-03 11:28:16 +01:00
|
|
|
|
static int
|
|
|
|
|
configure_return(char *options)
|
|
|
|
|
{
|
|
|
|
|
char *argv[3];
|
|
|
|
|
int elm, status, err;
|
|
|
|
|
|
|
|
|
|
if (current_domain == NULL) {
|
|
|
|
|
printf("return outside of domain context\n");
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
elm = kore_split_string(options, " ", argv, 3);
|
|
|
|
|
if (elm != 2) {
|
|
|
|
|
printf("missing parameters for return\n");
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status = kore_strtonum(argv[1], 10, 400, 600, &err);
|
|
|
|
|
if (err != KORE_RESULT_OK) {
|
|
|
|
|
printf("invalid status code on return (%s)\n", argv[1]);
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!http_redirect_add(current_domain, argv[0], status, NULL)) {
|
|
|
|
|
printf("invalid regex on return path\n");
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-07 06:42:33 +01:00
|
|
|
|
static int
|
|
|
|
|
configure_redirect(char *options)
|
|
|
|
|
{
|
|
|
|
|
char *argv[4];
|
|
|
|
|
int elm, status, err;
|
|
|
|
|
|
|
|
|
|
if (current_domain == NULL) {
|
|
|
|
|
printf("redirect outside of domain context\n");
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
elm = kore_split_string(options, " ", argv, 4);
|
|
|
|
|
if (elm != 3) {
|
|
|
|
|
printf("missing parameters for redirect\n");
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status = kore_strtonum(argv[1], 10, 300, 399, &err);
|
|
|
|
|
if (err != KORE_RESULT_OK) {
|
|
|
|
|
printf("invalid status code on redirect (%s)\n", argv[1]);
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!http_redirect_add(current_domain, argv[0], status, argv[2])) {
|
|
|
|
|
printf("invalid regex on redirect path\n");
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-28 13:27:44 +02:00
|
|
|
|
static int
|
|
|
|
|
configure_filemap(char *options)
|
|
|
|
|
{
|
|
|
|
|
char *argv[3];
|
|
|
|
|
|
|
|
|
|
if (current_domain == NULL) {
|
|
|
|
|
printf("filemap outside of domain context\n");
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kore_split_string(options, " ", argv, 3);
|
|
|
|
|
|
|
|
|
|
if (argv[0] == NULL || argv[1] == NULL) {
|
|
|
|
|
printf("missing parameters for filemap\n");
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!kore_filemap_create(current_domain, argv[1], argv[0])) {
|
|
|
|
|
printf("cannot create filemap for %s\n", argv[1]);
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-23 10:24:00 +02:00
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_accesslog(char *path)
|
2015-04-23 10:24:00 +02:00
|
|
|
|
{
|
2015-11-27 16:22:50 +01:00
|
|
|
|
if (current_domain == NULL) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
kore_debug("accesslog not specified in domain context\n");
|
2015-04-23 10:24:00 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
2015-04-27 10:36:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-27 16:22:50 +01:00
|
|
|
|
if (current_domain->accesslog != -1) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("domain %s already has an open accesslog\n",
|
2015-11-27 16:22:50 +01:00
|
|
|
|
current_domain->domain);
|
2015-04-27 10:36:33 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
2015-11-27 16:22:50 +01:00
|
|
|
|
}
|
2015-04-27 10:36:33 +02:00
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
current_domain->accesslog = open(path,
|
2015-11-27 16:22:50 +01:00
|
|
|
|
O_CREAT | O_APPEND | O_WRONLY,
|
|
|
|
|
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
|
|
|
|
if (current_domain->accesslog == -1) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("accesslog open(%s): %s\n", path, errno_s);
|
2015-04-27 10:36:33 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
2014-07-31 09:14:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-17 14:23:57 +02:00
|
|
|
|
static int
|
|
|
|
|
configure_restrict(char *options)
|
|
|
|
|
{
|
|
|
|
|
struct kore_module_handle *hdlr;
|
|
|
|
|
int i, cnt;
|
|
|
|
|
char *argv[10];
|
|
|
|
|
|
|
|
|
|
if (current_domain == NULL) {
|
|
|
|
|
printf("restrict not used in domain context\n");
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cnt = kore_split_string(options, " ", argv, 10);
|
|
|
|
|
if (cnt < 2) {
|
|
|
|
|
printf("bad restrict option '%s', missing methods\n", options);
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hdlr = NULL;
|
|
|
|
|
TAILQ_FOREACH(hdlr, &(current_domain->handlers), list) {
|
|
|
|
|
if (!strcmp(hdlr->path, argv[0]))
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hdlr == NULL) {
|
2018-07-17 14:36:21 +02:00
|
|
|
|
printf("bad restrict option handler '%s' not found\n", argv[0]);
|
2018-07-17 14:23:57 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hdlr->methods = 0;
|
|
|
|
|
|
|
|
|
|
for (i = 1; i < cnt; i++) {
|
|
|
|
|
if (!strcasecmp(argv[i], "post")) {
|
|
|
|
|
hdlr->methods |= HTTP_METHOD_POST;
|
|
|
|
|
} else if (!strcasecmp(argv[i], "get")) {
|
|
|
|
|
hdlr->methods |= HTTP_METHOD_GET;
|
|
|
|
|
} else if (!strcasecmp(argv[i], "put")) {
|
|
|
|
|
hdlr->methods |= HTTP_METHOD_PUT;
|
|
|
|
|
} else if (!strcasecmp(argv[i], "delete")) {
|
|
|
|
|
hdlr->methods |= HTTP_METHOD_DELETE;
|
|
|
|
|
} else if (!strcasecmp(argv[i], "head")) {
|
|
|
|
|
hdlr->methods |= HTTP_METHOD_HEAD;
|
|
|
|
|
} else if (!strcasecmp(argv[i], "patch")) {
|
|
|
|
|
hdlr->methods |= HTTP_METHOD_PATCH;
|
|
|
|
|
} else {
|
|
|
|
|
printf("unknown method: %s in restrict for %s\n",
|
|
|
|
|
argv[i], argv[0]);
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-03 19:58:43 +02:00
|
|
|
|
static int
|
|
|
|
|
configure_filemap_ext(char *ext)
|
|
|
|
|
{
|
|
|
|
|
kore_free(kore_filemap_ext);
|
|
|
|
|
kore_filemap_ext = kore_strdup(ext);
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-28 23:00:42 +02:00
|
|
|
|
static int
|
|
|
|
|
configure_filemap_index(char *index)
|
|
|
|
|
{
|
|
|
|
|
kore_free(kore_filemap_index);
|
|
|
|
|
kore_filemap_index = kore_strdup(index);
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-28 13:27:44 +02:00
|
|
|
|
static int
|
|
|
|
|
configure_http_media_type(char *type)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
char *extensions, *ext[10];
|
|
|
|
|
|
|
|
|
|
extensions = strchr(type, ' ');
|
|
|
|
|
if (extensions == NULL) {
|
|
|
|
|
printf("bad http_media_type value: %s\n", type);
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*(extensions)++ = '\0';
|
|
|
|
|
|
|
|
|
|
kore_split_string(extensions, " \t", ext, 10);
|
|
|
|
|
for (i = 0; ext[i] != NULL; i++) {
|
|
|
|
|
if (!http_media_register(ext[i], type)) {
|
|
|
|
|
printf("duplicate extension found: %s\n", ext[i]);
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
|
printf("missing extensions in: %s\n", type);
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-22 20:05:24 +02:00
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_http_header_max(char *option)
|
2013-09-22 20:05:24 +02:00
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
http_header_max = kore_strtonum(option, 10, 1, 65535, &err);
|
2013-09-22 20:05:24 +02:00
|
|
|
|
if (err != KORE_RESULT_OK) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("bad http_header_max value: %s\n", option);
|
2013-09-22 20:05:24 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-11 20:51:49 +02:00
|
|
|
|
static int
|
|
|
|
|
configure_http_header_timeout(char *option)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
http_header_timeout = kore_strtonum(option, 10, 1, 65535, &err);
|
|
|
|
|
if (err != KORE_RESULT_OK) {
|
|
|
|
|
printf("bad http_header_timeout value: %s\n", option);
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-22 20:05:24 +02:00
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_http_body_max(char *option)
|
2013-09-22 20:05:24 +02:00
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
2017-02-06 21:28:33 +01:00
|
|
|
|
http_body_max = kore_strtonum(option, 10, 0, LONG_MAX, &err);
|
2013-09-22 20:05:24 +02:00
|
|
|
|
if (err != KORE_RESULT_OK) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("bad http_body_max value: %s\n", option);
|
2013-09-22 20:05:24 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-11 20:51:49 +02:00
|
|
|
|
static int
|
|
|
|
|
configure_http_body_timeout(char *option)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
http_body_timeout = kore_strtonum(option, 10, 1, 65535, &err);
|
|
|
|
|
if (err != KORE_RESULT_OK) {
|
|
|
|
|
printf("bad http_body_timeout value: %s\n", option);
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-18 11:30:22 +01:00
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_http_body_disk_offload(char *option)
|
2016-01-18 11:30:22 +01:00
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
http_body_disk_offload = kore_strtonum(option, 10, 0, LONG_MAX, &err);
|
2016-01-18 11:30:22 +01:00
|
|
|
|
if (err != KORE_RESULT_OK) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("bad http_body_disk_offload value: %s\n", option);
|
2016-01-18 11:30:22 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_http_body_disk_path(char *path)
|
2016-01-18 11:30:22 +01:00
|
|
|
|
{
|
2016-01-18 11:43:10 +01:00
|
|
|
|
if (strcmp(http_body_disk_path, HTTP_BODY_DISK_PATH))
|
2016-07-12 13:54:14 +02:00
|
|
|
|
kore_free(http_body_disk_path);
|
2016-01-18 11:30:22 +01:00
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
http_body_disk_path = kore_strdup(path);
|
2016-01-18 11:30:22 +01:00
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-18 22:29:41 +01:00
|
|
|
|
static int
|
|
|
|
|
configure_http_server_version(char *version)
|
|
|
|
|
{
|
|
|
|
|
http_server_version(version);
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-03 12:53:18 +01:00
|
|
|
|
static int
|
|
|
|
|
configure_http_pretty_error(char *yesno)
|
|
|
|
|
{
|
|
|
|
|
if (!strcmp(yesno, "no")) {
|
|
|
|
|
http_pretty_error = 0;
|
|
|
|
|
} else if (!strcmp(yesno, "yes")) {
|
|
|
|
|
http_pretty_error = 1;
|
|
|
|
|
} else {
|
2020-03-04 08:36:10 +01:00
|
|
|
|
printf("invalid '%s' for yes|no http_pretty_error option\n",
|
|
|
|
|
yesno);
|
2020-03-03 12:53:18 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-15 10:44:56 +02:00
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_http_hsts_enable(char *option)
|
2013-10-15 10:44:56 +02:00
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
http_hsts_enable = kore_strtonum(option, 10, 0, LONG_MAX, &err);
|
2013-10-15 10:44:56 +02:00
|
|
|
|
if (err != KORE_RESULT_OK) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("bad http_hsts_enable value: %s\n", option);
|
2013-10-15 10:44:56 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-15 11:10:45 +02:00
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_http_keepalive_time(char *option)
|
2013-10-15 11:10:45 +02:00
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
http_keepalive_time = kore_strtonum(option, 10, 0, USHRT_MAX, &err);
|
2013-10-15 11:10:45 +02:00
|
|
|
|
if (err != KORE_RESULT_OK) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("bad http_keepalive_time value: %s\n", option);
|
2013-10-15 11:10:45 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-14 13:41:17 +01:00
|
|
|
|
static int
|
|
|
|
|
configure_http_request_ms(char *option)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
http_request_ms = kore_strtonum(option, 10, 0, UINT_MAX, &err);
|
|
|
|
|
if (err != KORE_RESULT_OK) {
|
|
|
|
|
printf("bad http_request_ms value: %s\n", option);
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-09 15:29:44 +02:00
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_http_request_limit(char *option)
|
2015-04-09 15:29:44 +02:00
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
http_request_limit = kore_strtonum(option, 10, 0, UINT_MAX, &err);
|
2015-04-09 15:29:44 +02:00
|
|
|
|
if (err != KORE_RESULT_OK) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("bad http_request_limit value: %s\n", option);
|
2015-04-09 15:29:44 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-09 16:21:52 +01:00
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_validator(char *name)
|
2013-11-09 16:21:52 +01:00
|
|
|
|
{
|
|
|
|
|
u_int8_t type;
|
2016-02-01 21:33:51 +01:00
|
|
|
|
char *tname, *value;
|
|
|
|
|
|
|
|
|
|
if ((tname = strchr(name, ' ')) == NULL) {
|
|
|
|
|
printf("missing validator name\n");
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
2013-11-09 16:21:52 +01:00
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
*(tname)++ = '\0';
|
|
|
|
|
tname = kore_text_trim(tname, strlen(tname));
|
|
|
|
|
if ((value = strchr(tname, ' ')) == NULL) {
|
|
|
|
|
printf("missing validator value\n");
|
2013-11-09 16:21:52 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
2016-02-01 21:33:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*(value)++ = '\0';
|
|
|
|
|
value = kore_text_trim(value, strlen(value));
|
2013-11-09 16:21:52 +01:00
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
if (!strcmp(tname, "regex")) {
|
2013-11-09 16:21:52 +01:00
|
|
|
|
type = KORE_VALIDATOR_TYPE_REGEX;
|
2016-02-01 21:33:51 +01:00
|
|
|
|
} else if (!strcmp(tname, "function")) {
|
2013-11-09 16:21:52 +01:00
|
|
|
|
type = KORE_VALIDATOR_TYPE_FUNCTION;
|
|
|
|
|
} else {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("bad type for validator %s\n", tname);
|
2013-11-09 16:21:52 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
if (!kore_validator_add(name, type, value)) {
|
|
|
|
|
printf("bad validator specified: %s\n", tname);
|
2013-11-09 16:21:52 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-10 15:17:15 +01:00
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_params(char *options)
|
2013-11-10 15:17:15 +01:00
|
|
|
|
{
|
|
|
|
|
struct kore_module_handle *hdlr;
|
2018-01-16 18:47:50 +01:00
|
|
|
|
char *method, *argv[3];
|
2013-11-10 15:17:15 +01:00
|
|
|
|
|
|
|
|
|
if (current_domain == NULL) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("params not used in domain context\n");
|
2013-11-10 15:17:15 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (current_handler != NULL) {
|
|
|
|
|
printf("previous params block not closed\n");
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
kore_split_string(options, " ", argv, 3);
|
|
|
|
|
if (argv[1] == NULL)
|
2013-11-10 15:17:15 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
|
2018-01-16 18:47:50 +01:00
|
|
|
|
if ((method = strchr(argv[0], ':')) != NULL) {
|
|
|
|
|
*(method)++ = '\0';
|
|
|
|
|
if (!strcasecmp(argv[0], "qs")) {
|
|
|
|
|
current_flags = KORE_PARAMS_QUERY_STRING;
|
|
|
|
|
} else {
|
|
|
|
|
printf("unknown prefix '%s' for '%s'\n",
|
|
|
|
|
argv[0], argv[1]);
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
method = argv[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strcasecmp(method, "post")) {
|
2013-11-10 15:17:15 +01:00
|
|
|
|
current_method = HTTP_METHOD_POST;
|
2018-01-16 18:47:50 +01:00
|
|
|
|
} else if (!strcasecmp(method, "get")) {
|
2013-11-10 15:17:15 +01:00
|
|
|
|
current_method = HTTP_METHOD_GET;
|
2018-01-16 18:47:50 +01:00
|
|
|
|
/* Let params get /foo {} imply qs:get automatically. */
|
|
|
|
|
current_flags |= KORE_PARAMS_QUERY_STRING;
|
|
|
|
|
} else if (!strcasecmp(method, "put")) {
|
2015-04-09 01:46:27 +02:00
|
|
|
|
current_method = HTTP_METHOD_PUT;
|
2018-01-16 18:47:50 +01:00
|
|
|
|
} else if (!strcasecmp(method, "delete")) {
|
2015-04-09 01:46:27 +02:00
|
|
|
|
current_method = HTTP_METHOD_DELETE;
|
2018-01-16 18:47:50 +01:00
|
|
|
|
} else if (!strcasecmp(method, "head")) {
|
2015-04-09 01:46:27 +02:00
|
|
|
|
current_method = HTTP_METHOD_HEAD;
|
2018-01-16 18:47:50 +01:00
|
|
|
|
} else if (!strcasecmp(method, "patch")) {
|
2018-01-02 22:27:59 +01:00
|
|
|
|
current_method = HTTP_METHOD_PATCH;
|
2013-11-10 15:17:15 +01:00
|
|
|
|
} else {
|
|
|
|
|
printf("unknown method: %s in params block for %s\n",
|
2018-01-16 18:47:50 +01:00
|
|
|
|
method, argv[1]);
|
2013-11-10 15:17:15 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Find the handler ourselves, otherwise the regex is applied
|
|
|
|
|
* in case of a dynamic page.
|
|
|
|
|
*/
|
|
|
|
|
TAILQ_FOREACH(hdlr, &(current_domain->handlers), list) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
if (!strcmp(hdlr->path, argv[1])) {
|
2013-11-10 15:17:15 +01:00
|
|
|
|
current_handler = hdlr;
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("params for unknown page handler: %s\n", argv[1]);
|
2013-11-10 15:17:15 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_validate(char *options)
|
2013-11-10 15:17:15 +01:00
|
|
|
|
{
|
|
|
|
|
struct kore_handler_params *p;
|
|
|
|
|
struct kore_validator *val;
|
2016-02-01 21:33:51 +01:00
|
|
|
|
char *argv[3];
|
2013-11-10 15:17:15 +01:00
|
|
|
|
|
|
|
|
|
if (current_handler == NULL) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("validate not used in domain context\n");
|
2013-11-10 15:17:15 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
kore_split_string(options, " ", argv, 3);
|
|
|
|
|
if (argv[1] == NULL)
|
2013-11-10 15:17:15 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
if ((val = kore_validator_lookup(argv[1])) == NULL) {
|
|
|
|
|
printf("unknown validator %s for %s\n", argv[1], argv[0]);
|
2013-11-10 15:17:15 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p = kore_malloc(sizeof(*p));
|
|
|
|
|
p->validator = val;
|
2018-01-16 18:47:50 +01:00
|
|
|
|
p->flags = current_flags;
|
2013-11-10 15:17:15 +01:00
|
|
|
|
p->method = current_method;
|
2016-02-01 21:33:51 +01:00
|
|
|
|
p->name = kore_strdup(argv[0]);
|
2013-11-10 15:17:15 +01:00
|
|
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&(current_handler->params), p, list);
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-22 22:55:10 +01:00
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_authentication(char *options)
|
2014-01-22 22:55:10 +01:00
|
|
|
|
{
|
2016-02-01 21:33:51 +01:00
|
|
|
|
char *argv[3];
|
|
|
|
|
|
|
|
|
|
if (current_auth != NULL) {
|
|
|
|
|
printf("previous authentication block not closed\n");
|
2014-01-22 22:55:10 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
kore_split_string(options, " ", argv, 3);
|
|
|
|
|
if (argv[1] == NULL) {
|
|
|
|
|
printf("missing name for authentication block\n");
|
2014-01-22 22:55:10 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
if (strcmp(argv[1], "{")) {
|
2014-01-22 22:55:10 +01:00
|
|
|
|
printf("missing { for authentication block\n");
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
if (!kore_auth_new(argv[0]))
|
2014-01-22 22:55:10 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
current_auth = kore_auth_lookup(argv[0]);
|
2014-01-22 22:55:10 +01:00
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_authentication_type(char *option)
|
2014-01-22 22:55:10 +01:00
|
|
|
|
{
|
|
|
|
|
if (current_auth == NULL) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("authentication_type outside authentication context\n");
|
2014-01-22 22:55:10 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
if (!strcmp(option, "cookie")) {
|
2014-01-22 22:55:10 +01:00
|
|
|
|
current_auth->type = KORE_AUTH_TYPE_COOKIE;
|
2016-02-01 21:33:51 +01:00
|
|
|
|
} else if (!strcmp(option, "header")) {
|
2014-01-22 23:11:52 +01:00
|
|
|
|
current_auth->type = KORE_AUTH_TYPE_HEADER;
|
2016-02-01 21:33:51 +01:00
|
|
|
|
} else if (!strcmp(option, "request")) {
|
2015-02-04 12:04:07 +01:00
|
|
|
|
current_auth->type = KORE_AUTH_TYPE_REQUEST;
|
2014-01-22 22:55:10 +01:00
|
|
|
|
} else {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("unknown authentication type '%s'\n", option);
|
2014-01-22 22:55:10 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_authentication_value(char *option)
|
2014-01-22 22:55:10 +01:00
|
|
|
|
{
|
|
|
|
|
if (current_auth == NULL) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("authentication_value outside authentication context\n");
|
2014-01-22 22:55:10 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
if (current_auth->value != NULL)
|
2016-07-12 13:54:14 +02:00
|
|
|
|
kore_free(current_auth->value);
|
2016-02-01 21:33:51 +01:00
|
|
|
|
current_auth->value = kore_strdup(option);
|
2014-01-22 22:55:10 +01:00
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_authentication_validator(char *validator)
|
2014-01-22 22:55:10 +01:00
|
|
|
|
{
|
|
|
|
|
struct kore_validator *val;
|
|
|
|
|
|
|
|
|
|
if (current_auth == NULL) {
|
|
|
|
|
printf("authentication_validator outside authentication\n");
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
if ((val = kore_validator_lookup(validator)) == NULL) {
|
|
|
|
|
printf("authentication validator '%s' not found\n", validator);
|
2014-01-22 22:55:10 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
current_auth->validator = val;
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_authentication_uri(char *uri)
|
2014-01-22 22:55:10 +01:00
|
|
|
|
{
|
|
|
|
|
if (current_auth == NULL) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("authentication_uri outside authentication context\n");
|
2014-01-22 22:55:10 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
if (current_auth->redirect != NULL)
|
2016-07-12 13:54:14 +02:00
|
|
|
|
kore_free(current_auth->redirect);
|
2016-02-01 21:33:51 +01:00
|
|
|
|
current_auth->redirect = kore_strdup(uri);
|
2014-01-22 22:55:10 +01:00
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-24 11:01:12 +01:00
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_websocket_maxframe(char *option)
|
2014-11-24 11:01:12 +01:00
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
kore_websocket_maxframe = kore_strtonum64(option, 1, &err);
|
2014-11-24 11:01:12 +01:00
|
|
|
|
if (err != KORE_RESULT_OK) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("bad kore_websocket_maxframe value: %s\n", option);
|
2014-11-24 11:01:12 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_websocket_timeout(char *option)
|
2014-11-24 11:01:12 +01:00
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
kore_websocket_timeout = kore_strtonum64(option, 1, &err);
|
2014-11-24 11:01:12 +01:00
|
|
|
|
if (err != KORE_RESULT_OK) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("bad kore_websocket_timeout value: %s\n", option);
|
2014-11-24 11:01:12 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kore_websocket_timeout = kore_websocket_timeout * 1000;
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-27 18:12:08 +01:00
|
|
|
|
#endif /* !KORE_NO_HTTP */
|
2015-11-27 16:22:50 +01:00
|
|
|
|
|
|
|
|
|
static int
|
2018-07-11 09:44:29 +02:00
|
|
|
|
configure_root(char *path)
|
2015-11-27 16:22:50 +01:00
|
|
|
|
{
|
2018-07-11 09:44:29 +02:00
|
|
|
|
if (kore_root_path != NULL)
|
|
|
|
|
kore_free(kore_root_path);
|
|
|
|
|
kore_root_path = kore_strdup(path);
|
2015-11-27 16:22:50 +01:00
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_runas(char *user)
|
2015-11-27 16:22:50 +01:00
|
|
|
|
{
|
2018-07-11 09:44:29 +02:00
|
|
|
|
if (kore_runas_user != NULL)
|
|
|
|
|
kore_free(kore_runas_user);
|
|
|
|
|
kore_runas_user = kore_strdup(user);
|
2015-11-27 16:22:50 +01:00
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_workers(char *option)
|
2015-11-27 16:22:50 +01:00
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
2019-10-16 12:05:27 +02:00
|
|
|
|
worker_count = kore_strtonum(option, 10, 1, KORE_WORKER_MAX, &err);
|
2015-11-27 16:22:50 +01:00
|
|
|
|
if (err != KORE_RESULT_OK) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("%s is not a valid worker number\n", option);
|
2015-11-27 16:22:50 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_pidfile(char *path)
|
2015-11-27 16:22:50 +01:00
|
|
|
|
{
|
2016-02-01 21:33:51 +01:00
|
|
|
|
if (strcmp(kore_pidfile, KORE_PIDFILE_DEFAULT))
|
2016-07-12 13:54:14 +02:00
|
|
|
|
kore_free(kore_pidfile);
|
2016-02-01 21:33:51 +01:00
|
|
|
|
kore_pidfile = kore_strdup(path);
|
2015-11-27 16:22:50 +01:00
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_max_connections(char *option)
|
2015-11-27 16:22:50 +01:00
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
worker_max_connections = kore_strtonum(option, 10, 1, UINT_MAX, &err);
|
2015-11-27 16:22:50 +01:00
|
|
|
|
if (err != KORE_RESULT_OK) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("bad value for worker_max_connections: %s\n", option);
|
2015-11-27 16:22:50 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_rlimit_nofiles(char *option)
|
2015-11-27 16:22:50 +01:00
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
worker_rlimit_nofiles = kore_strtonum(option, 10, 1, UINT_MAX, &err);
|
2015-11-27 16:22:50 +01:00
|
|
|
|
if (err != KORE_RESULT_OK) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("bad value for worker_rlimit_nofiles: %s\n", option);
|
2015-11-27 16:22:50 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_accept_threshold(char *option)
|
2015-11-27 16:22:50 +01:00
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
worker_accept_threshold = kore_strtonum(option, 0, 1, UINT_MAX, &err);
|
2015-11-27 16:22:50 +01:00
|
|
|
|
if (err != KORE_RESULT_OK) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("bad value for worker_accept_threshold: %s\n", option);
|
2015-11-27 16:22:50 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
2019-03-22 09:49:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
configure_death_policy(char *option)
|
|
|
|
|
{
|
|
|
|
|
if (!strcmp(option, "restart")) {
|
|
|
|
|
worker_policy = KORE_WORKER_POLICY_RESTART;
|
|
|
|
|
} else if (!strcmp(option, "terminate")) {
|
|
|
|
|
worker_policy = KORE_WORKER_POLICY_TERMINATE;
|
|
|
|
|
} else {
|
|
|
|
|
printf("bad value for worker_death_policy: %s\n", option);
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
2015-11-27 16:22:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_set_affinity(char *option)
|
2015-11-27 16:22:50 +01:00
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
worker_set_affinity = kore_strtonum(option, 10, 0, 1, &err);
|
2015-11-27 16:22:50 +01:00
|
|
|
|
if (err != KORE_RESULT_OK) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("bad value for worker_set_affinity: %s\n", option);
|
2015-11-27 16:22:50 +01:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-09 15:29:44 +02:00
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_socket_backlog(char *option)
|
2015-04-09 15:29:44 +02:00
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
kore_socket_backlog = kore_strtonum(option, 10, 0, UINT_MAX, &err);
|
2015-04-09 15:29:44 +02:00
|
|
|
|
if (err != KORE_RESULT_OK) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("bad socket_backlog value: %s\n", option);
|
2015-04-09 15:29:44 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-04 09:14:05 +02:00
|
|
|
|
#if defined(KORE_USE_PGSQL)
|
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_pgsql_conn_max(char *option)
|
2014-07-04 09:14:05 +02:00
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
pgsql_conn_max = kore_strtonum(option, 10, 0, USHRT_MAX, &err);
|
2014-07-04 09:14:05 +02:00
|
|
|
|
if (err != KORE_RESULT_OK) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("bad value for pgsql_conn_max: %s\n", option);
|
2014-07-04 09:14:05 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
2018-02-13 13:21:27 +01:00
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
configure_pgsql_queue_limit(char *option)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
pgsql_queue_limit = kore_strtonum(option, 10, 0, UINT_MAX, &err);
|
|
|
|
|
if (err != KORE_RESULT_OK) {
|
|
|
|
|
printf("bad value for pgsql_queue_limit: %s\n", option);
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
2015-06-04 10:29:22 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if defined(KORE_USE_TASKS)
|
|
|
|
|
static int
|
2016-02-01 21:33:51 +01:00
|
|
|
|
configure_task_threads(char *option)
|
2015-06-04 10:29:22 +02:00
|
|
|
|
{
|
|
|
|
|
int err;
|
2014-07-04 09:14:05 +02:00
|
|
|
|
|
2016-02-01 21:33:51 +01:00
|
|
|
|
kore_task_threads = kore_strtonum(option, 10, 0, UCHAR_MAX, &err);
|
2015-06-04 10:29:22 +02:00
|
|
|
|
if (err != KORE_RESULT_OK) {
|
2016-02-01 21:33:51 +01:00
|
|
|
|
printf("bad value for task_threads: %s\n", option);
|
2015-06-04 10:29:22 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
2014-07-04 09:14:05 +02:00
|
|
|
|
#endif
|
2017-01-12 23:38:51 +01:00
|
|
|
|
|
|
|
|
|
#if defined(KORE_USE_PYTHON)
|
2019-09-26 15:49:00 +02:00
|
|
|
|
static int
|
|
|
|
|
configure_deployment(char *value)
|
|
|
|
|
{
|
2021-05-10 10:27:32 +02:00
|
|
|
|
if (!strcmp(value, "docker")) {
|
|
|
|
|
kore_foreground = 1;
|
2021-05-10 10:32:54 +02:00
|
|
|
|
skip_runas = 0;
|
|
|
|
|
skip_chroot = 0;
|
2021-05-10 10:27:32 +02:00
|
|
|
|
} else if (!strcmp(value, "dev") || !strcmp(value, "development")) {
|
2021-01-11 23:35:16 +01:00
|
|
|
|
kore_foreground = 1;
|
2019-09-26 15:49:00 +02:00
|
|
|
|
skip_runas = 1;
|
|
|
|
|
skip_chroot = 1;
|
|
|
|
|
} else if (!strcmp(value, "production")) {
|
2021-01-11 23:35:16 +01:00
|
|
|
|
kore_foreground = 0;
|
2019-09-26 15:49:00 +02:00
|
|
|
|
skip_runas = 0;
|
|
|
|
|
skip_chroot = 0;
|
|
|
|
|
} else {
|
|
|
|
|
kore_log(LOG_NOTICE,
|
2021-05-02 00:23:11 +02:00
|
|
|
|
"kore.config.deployment: bad value '%s'", value);
|
2019-09-26 15:49:00 +02:00
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 12:55:33 +01:00
|
|
|
|
static int
|
|
|
|
|
configure_python_path(char *path)
|
|
|
|
|
{
|
|
|
|
|
kore_python_path(path);
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-12 23:38:51 +01:00
|
|
|
|
static int
|
|
|
|
|
configure_python_import(char *module)
|
|
|
|
|
{
|
|
|
|
|
char *argv[3];
|
|
|
|
|
|
|
|
|
|
kore_split_string(module, " ", argv, 3);
|
|
|
|
|
if (argv[0] == NULL)
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
|
|
|
|
|
kore_module_load(argv[0], argv[1], KORE_MODULE_PYTHON);
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2018-07-31 06:51:34 +02:00
|
|
|
|
|
|
|
|
|
#if defined(KORE_USE_PLATFORM_PLEDGE)
|
|
|
|
|
static int
|
|
|
|
|
configure_add_pledge(char *pledge)
|
|
|
|
|
{
|
|
|
|
|
kore_platform_add_pledge(pledge);
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2019-04-24 00:10:47 +02:00
|
|
|
|
|
|
|
|
|
#if defined(KORE_USE_CURL)
|
|
|
|
|
static int
|
|
|
|
|
configure_curl_recv_max(char *option)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
kore_curl_recv_max = kore_strtonum64(option, 1, &err);
|
|
|
|
|
if (err != KORE_RESULT_OK) {
|
|
|
|
|
printf("bad curl_recv_max value: %s\n", option);
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
configure_curl_timeout(char *option)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
kore_curl_timeout = kore_strtonum(option, 10, 0, USHRT_MAX, &err);
|
|
|
|
|
if (err != KORE_RESULT_OK) {
|
|
|
|
|
printf("bad kore_curl_timeout value: %s\n", option);
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2019-10-31 12:52:10 +01:00
|
|
|
|
|
|
|
|
|
#if defined(__linux__)
|
|
|
|
|
static int
|
|
|
|
|
configure_seccomp_tracing(char *opt)
|
|
|
|
|
{
|
|
|
|
|
if (!strcmp(opt, "yes")) {
|
|
|
|
|
kore_seccomp_tracing = 1;
|
|
|
|
|
} else if (!strcmp(opt, "no")) {
|
|
|
|
|
kore_seccomp_tracing = 0;
|
|
|
|
|
} else {
|
|
|
|
|
printf("bad seccomp_tracing value: %s (expected yes|no)\n",
|
|
|
|
|
opt);
|
|
|
|
|
return (KORE_RESULT_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (KORE_RESULT_OK);
|
|
|
|
|
}
|
|
|
|
|
#endif
|