Return `struct error' from irc_initialize_ssl()
This commit is contained in:
parent
a508f85bea
commit
531b1c71bf
26
src/kike.c
26
src/kike.c
|
@ -1045,9 +1045,8 @@ irc_ssl_verify_callback (int verify_ok, X509_STORE_CTX *ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
irc_initialize_ssl (struct server_context *ctx)
|
irc_initialize_ssl (struct server_context *ctx, struct error **e)
|
||||||
{
|
{
|
||||||
// TODO: this could definitely return an error object
|
|
||||||
const char *ssl_cert = str_map_find (&ctx->config, "ssl_cert");
|
const char *ssl_cert = str_map_find (&ctx->config, "ssl_cert");
|
||||||
const char *ssl_key = str_map_find (&ctx->config, "ssl_key");
|
const char *ssl_key = str_map_find (&ctx->config, "ssl_key");
|
||||||
|
|
||||||
|
@ -1057,18 +1056,18 @@ irc_initialize_ssl (struct server_context *ctx)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!ssl_cert)
|
if (!ssl_cert)
|
||||||
print_error ("no SSL certificate set");
|
error_set (e, "no SSL certificate set");
|
||||||
if (!ssl_key)
|
else if (!ssl_key)
|
||||||
print_error ("no SSL private key set");
|
error_set (e, "no SSL private key set");
|
||||||
if (!ssl_cert || !ssl_key)
|
if (!ssl_cert || !ssl_key)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
char *cert_path = resolve_config_filename (ssl_cert);
|
char *cert_path = resolve_config_filename (ssl_cert);
|
||||||
char *key_path = resolve_config_filename (ssl_key);
|
char *key_path = resolve_config_filename (ssl_key);
|
||||||
if (!cert_path)
|
if (!cert_path)
|
||||||
print_error ("%s: %s", "cannot open file", ssl_cert);
|
error_set (e, "%s: %s", "cannot open file", ssl_cert);
|
||||||
if (!key_path)
|
else if (!key_path)
|
||||||
print_error ("%s: %s", "cannot open file", ssl_key);
|
error_set (e, "%s: %s", "cannot open file", ssl_key);
|
||||||
if (!cert_path || !key_path)
|
if (!cert_path || !key_path)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -1077,7 +1076,7 @@ irc_initialize_ssl (struct server_context *ctx)
|
||||||
{
|
{
|
||||||
// XXX: these error strings are really nasty; also there could be
|
// XXX: these error strings are really nasty; also there could be
|
||||||
// multiple errors on the OpenSSL stack.
|
// multiple errors on the OpenSSL stack.
|
||||||
print_error ("%s: %s", "could not initialize SSL",
|
error_set (e, "%s: %s", "could not initialize SSL",
|
||||||
ERR_error_string (ERR_get_error (), NULL));
|
ERR_error_string (ERR_get_error (), NULL));
|
||||||
goto error_ssl_1;
|
goto error_ssl_1;
|
||||||
}
|
}
|
||||||
|
@ -1088,13 +1087,13 @@ irc_initialize_ssl (struct server_context *ctx)
|
||||||
// XXX: perhaps we should read the files ourselves for better messages
|
// XXX: perhaps we should read the files ourselves for better messages
|
||||||
if (!SSL_CTX_use_certificate_chain_file (ctx->ssl_ctx, cert_path))
|
if (!SSL_CTX_use_certificate_chain_file (ctx->ssl_ctx, cert_path))
|
||||||
{
|
{
|
||||||
print_error ("%s: %s", "setting the SSL client certificate failed",
|
error_set (e, "%s: %s", "setting the SSL client certificate failed",
|
||||||
ERR_error_string (ERR_get_error (), NULL));
|
ERR_error_string (ERR_get_error (), NULL));
|
||||||
goto error_ssl_2;
|
goto error_ssl_2;
|
||||||
}
|
}
|
||||||
if (!SSL_CTX_use_PrivateKey_file (ctx->ssl_ctx, key_path, 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",
|
error_set (e, "%s: %s", "setting the SSL private key failed",
|
||||||
ERR_error_string (ERR_get_error (), NULL));
|
ERR_error_string (ERR_get_error (), NULL));
|
||||||
goto error_ssl_2;
|
goto error_ssl_2;
|
||||||
}
|
}
|
||||||
|
@ -1419,9 +1418,8 @@ main (int argc, char *argv[])
|
||||||
poller_set (&ctx.poller, g_signal_pipe[0], POLLIN,
|
poller_set (&ctx.poller, g_signal_pipe[0], POLLIN,
|
||||||
(poller_dispatcher_func) on_signal_pipe_readable, &ctx);
|
(poller_dispatcher_func) on_signal_pipe_readable, &ctx);
|
||||||
|
|
||||||
if (!irc_initialize_ssl (&ctx))
|
if (!irc_initialize_ssl (&ctx, &e)
|
||||||
exit (EXIT_FAILURE);
|
|| !irc_initialize_server_name (&ctx, &e)
|
||||||
if (!irc_initialize_server_name (&ctx, &e)
|
|
||||||
|| !irc_initialize_motd (&ctx, &e)
|
|| !irc_initialize_motd (&ctx, &e)
|
||||||
|| !irc_initialize_catalog (&ctx, &e)
|
|| !irc_initialize_catalog (&ctx, &e)
|
||||||
|| !irc_listen (&ctx, &e))
|
|| !irc_listen (&ctx, &e))
|
||||||
|
|
Loading…
Reference in New Issue