diff options
Diffstat (limited to 'src/kike.c')
-rw-r--r-- | src/kike.c | 66 |
1 files changed, 35 insertions, 31 deletions
@@ -1073,15 +1073,20 @@ irc_initialize_ssl (struct server_context *ctx) return true; if (!ssl_cert) - { print_error ("no SSL certificate set"); - return false; - } if (!ssl_key) - { print_error ("no SSL private key set"); + if (!ssl_cert || !ssl_key) + return false; + + char *cert_path = resolve_config_filename (ssl_cert); + char *key_path = resolve_config_filename (ssl_key); + if (!cert_path) + print_error ("%s: %s", "cannot open file", ssl_cert); + if (!key_path) + print_error ("%s: %s", "cannot open file", ssl_key); + if (!cert_path || !key_path) return false; - } ctx->ssl_ctx = SSL_CTX_new (SSLv23_server_method ()); if (!ctx->ssl_ctx) @@ -1091,13 +1096,13 @@ irc_initialize_ssl (struct server_context *ctx) // XXX: maybe we should call SSL_CTX_set_options() for some workarounds // XXX: perhaps we should read the files ourselves for better messages - if (!SSL_CTX_use_certificate_chain_file (ctx->ssl_ctx, ssl_cert)) + if (!SSL_CTX_use_certificate_chain_file (ctx->ssl_ctx, cert_path)) { print_error ("%s: %s", "setting the SSL client certificate failed", ERR_error_string (ERR_get_error (), NULL)); goto error_ssl_2; } - if (!SSL_CTX_use_PrivateKey_file (ctx->ssl_ctx, ssl_key, SSL_FILETYPE_PEM)) + if (!SSL_CTX_use_PrivateKey_file (ctx->ssl_ctx, key_path, SSL_FILETYPE_PEM)) { print_error ("%s: %s", "setting the SSL private key failed", ERR_error_string (ERR_get_error (), NULL)); @@ -1132,7 +1137,16 @@ irc_initialize_catalog (struct server_context *ctx, struct error **e) if (!catalog) return true; - ctx->catalog = catopen (catalog, NL_CAT_LOCALE); + char *path = resolve_config_filename (catalog); + if (!path) + { + error_set (e, IO_ERROR, IO_ERROR_FAILED, "%s: %s", + "cannot open file", catalog); + return false; + } + ctx->catalog = catopen (path, NL_CAT_LOCALE); + free (path); + if (ctx->catalog == (nl_catd) -1) { error_set (e, IO_ERROR, IO_ERROR_FAILED, "%s: %s", @@ -1150,11 +1164,20 @@ irc_initialize_motd (struct server_context *ctx, struct error **e) if (!motd) return true; - FILE *fp = fopen (motd, "r"); + char *path = resolve_config_filename (motd); + if (!path) + { + error_set (e, IO_ERROR, IO_ERROR_FAILED, "%s: %s", + "cannot open file", motd); + return false; + } + FILE *fp = fopen (path, "r"); + free (path); + if (!fp) { - error_set (e, IO_ERROR, IO_ERROR_FAILED, - "%s: %s", "failed reading the MOTD file", strerror (errno)); + error_set (e, IO_ERROR, IO_ERROR_FAILED, "%s: %s", + "failed reading the MOTD file", strerror (errno)); return false; } @@ -1312,25 +1335,6 @@ print_usage (const char *program_name) program_name); } -static void -call_write_default_config (const char *hint) -{ - static const char *prolog = - "# " PROGRAM_NAME " " PROGRAM_VERSION " configuration file\n" - "\n"; - - struct error *e = NULL; - char *filename = write_default_config (hint, prolog, g_config_table, &e); - if (!filename) - { - print_fatal ("%s", e->message); - error_free (e); - exit (EXIT_FAILURE); - } - print_status ("configuration written to `%s'", filename); - free (filename); -} - int main (int argc, char *argv[]) { @@ -1365,7 +1369,7 @@ main (int argc, char *argv[]) printf (PROGRAM_NAME " " PROGRAM_VERSION "\n"); exit (EXIT_SUCCESS); case 'w': - call_write_default_config (optarg); + call_write_default_config (optarg, g_config_table); exit (EXIT_SUCCESS); default: print_fatal ("error in options"); |