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
|
||||
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_key = str_map_find (&ctx->config, "ssl_key");
|
||||
|
||||
|
@ -1057,18 +1056,18 @@ irc_initialize_ssl (struct server_context *ctx)
|
|||
return true;
|
||||
|
||||
if (!ssl_cert)
|
||||
print_error ("no SSL certificate set");
|
||||
if (!ssl_key)
|
||||
print_error ("no SSL private key set");
|
||||
error_set (e, "no SSL certificate set");
|
||||
else if (!ssl_key)
|
||||
error_set (e, "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);
|
||||
error_set (e, "%s: %s", "cannot open file", ssl_cert);
|
||||
else if (!key_path)
|
||||
error_set (e, "%s: %s", "cannot open file", ssl_key);
|
||||
if (!cert_path || !key_path)
|
||||
return false;
|
||||
|
||||
|
@ -1077,7 +1076,7 @@ irc_initialize_ssl (struct server_context *ctx)
|
|||
{
|
||||
// XXX: these error strings are really nasty; also there could be
|
||||
// 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));
|
||||
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
|
||||
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));
|
||||
goto error_ssl_2;
|
||||
}
|
||||
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));
|
||||
goto error_ssl_2;
|
||||
}
|
||||
|
@ -1419,9 +1418,8 @@ main (int argc, char *argv[])
|
|||
poller_set (&ctx.poller, g_signal_pipe[0], POLLIN,
|
||||
(poller_dispatcher_func) on_signal_pipe_readable, &ctx);
|
||||
|
||||
if (!irc_initialize_ssl (&ctx))
|
||||
exit (EXIT_FAILURE);
|
||||
if (!irc_initialize_server_name (&ctx, &e)
|
||||
if (!irc_initialize_ssl (&ctx, &e)
|
||||
|| !irc_initialize_server_name (&ctx, &e)
|
||||
|| !irc_initialize_motd (&ctx, &e)
|
||||
|| !irc_initialize_catalog (&ctx, &e)
|
||||
|| !irc_listen (&ctx, &e))
|
||||
|
|
Loading…
Reference in New Issue