mirror of
https://github.com/weechat/weechat.git
synced 2026-06-28 05:46:38 +02:00
core: make GnuTLS a required dependency
This commit is contained in:
@@ -45,10 +45,8 @@ set(LINK_LIBS)
|
||||
|
||||
list(APPEND LINK_LIBS ${ZLIB_LIBRARY})
|
||||
|
||||
if(GNUTLS_FOUND)
|
||||
include_directories(${GNUTLS_INCLUDE_PATH})
|
||||
list(APPEND LINK_LIBS ${GNUTLS_LIBRARY})
|
||||
endif()
|
||||
include_directories(${GNUTLS_INCLUDE_PATH})
|
||||
list(APPEND LINK_LIBS ${GNUTLS_LIBRARY})
|
||||
|
||||
list(APPEND LINK_LIBS ${GCRYPT_LDFLAGS})
|
||||
|
||||
|
||||
@@ -29,9 +29,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
#include <gnutls/gnutls.h>
|
||||
#endif
|
||||
|
||||
#include "../weechat-plugin.h"
|
||||
#include "relay.h"
|
||||
@@ -233,7 +231,6 @@ relay_client_set_desc (struct t_relay_client *client)
|
||||
* Timer callback for handshake with client (for SSL connection only).
|
||||
*/
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
int
|
||||
relay_client_handshake_timer_cb (const void *pointer, void *data,
|
||||
int remaining_calls)
|
||||
@@ -311,7 +308,6 @@ relay_client_handshake_timer_cb (const void *pointer, void *data,
|
||||
/* handshake in progress, we will try again on next call to timer */
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
#endif /* HAVE_GNUTLS */
|
||||
|
||||
/*
|
||||
* Reads text data from a client: splits data on '\n' and keeps a partial
|
||||
@@ -602,12 +598,10 @@ relay_client_recv_cb (const void *pointer, void *data, int fd)
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
if (client->ssl)
|
||||
num_read = gnutls_record_recv (client->gnutls_sess, buffer,
|
||||
sizeof (buffer) - 1);
|
||||
else
|
||||
#endif /* HAVE_GNUTLS */
|
||||
num_read = recv (client->sock, buffer, sizeof (buffer) - 1, 0);
|
||||
|
||||
if (num_read > 0)
|
||||
@@ -693,7 +687,6 @@ relay_client_recv_cb (const void *pointer, void *data, int fd)
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef HAVE_GNUTLS
|
||||
if (client->ssl)
|
||||
{
|
||||
if ((num_read == 0)
|
||||
@@ -714,7 +707,6 @@ relay_client_recv_cb (const void *pointer, void *data, int fd)
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif /* HAVE_GNUTLS */
|
||||
{
|
||||
if ((num_read == 0)
|
||||
|| ((errno != EAGAIN) && (errno != EWOULDBLOCK)))
|
||||
@@ -972,11 +964,9 @@ relay_client_send (struct t_relay_client *client,
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef HAVE_GNUTLS
|
||||
if (client->ssl)
|
||||
num_sent = gnutls_record_send (client->gnutls_sess, ptr_data, data_size);
|
||||
else
|
||||
#endif /* HAVE_GNUTLS */
|
||||
num_sent = send (client->sock, ptr_data, data_size, 0);
|
||||
|
||||
if (num_sent >= 0)
|
||||
@@ -1005,7 +995,6 @@ relay_client_send (struct t_relay_client *client,
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef HAVE_GNUTLS
|
||||
if (client->ssl)
|
||||
{
|
||||
if ((num_sent == GNUTLS_E_AGAIN)
|
||||
@@ -1033,7 +1022,6 @@ relay_client_send (struct t_relay_client *client,
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif /* HAVE_GNUTLS */
|
||||
{
|
||||
if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
|
||||
{
|
||||
@@ -1078,7 +1066,6 @@ relay_client_send_outqueue (struct t_relay_client *client)
|
||||
|
||||
while (client->outqueue)
|
||||
{
|
||||
#ifdef HAVE_GNUTLS
|
||||
if (client->ssl)
|
||||
{
|
||||
num_sent = gnutls_record_send (client->gnutls_sess,
|
||||
@@ -1086,7 +1073,6 @@ relay_client_send_outqueue (struct t_relay_client *client)
|
||||
client->outqueue->data_size);
|
||||
}
|
||||
else
|
||||
#endif /* HAVE_GNUTLS */
|
||||
{
|
||||
num_sent = send (client->sock,
|
||||
client->outqueue->data,
|
||||
@@ -1149,7 +1135,6 @@ relay_client_send_outqueue (struct t_relay_client *client)
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef HAVE_GNUTLS
|
||||
if (client->ssl)
|
||||
{
|
||||
if ((num_sent == GNUTLS_E_AGAIN)
|
||||
@@ -1175,7 +1160,6 @@ relay_client_send_outqueue (struct t_relay_client *client)
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif /* HAVE_GNUTLS */
|
||||
{
|
||||
if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
|
||||
{
|
||||
@@ -1271,10 +1255,8 @@ relay_client_new (int sock, const char *address, struct t_relay_server *server)
|
||||
{
|
||||
struct t_relay_client *new_client;
|
||||
int plain_text_password;
|
||||
#ifdef HAVE_GNUTLS
|
||||
int bits;
|
||||
struct t_config_option *ptr_option;
|
||||
#endif /* HAVE_GNUTLS */
|
||||
|
||||
new_client = malloc (sizeof (*new_client));
|
||||
if (new_client)
|
||||
@@ -1284,10 +1266,8 @@ relay_client_new (int sock, const char *address, struct t_relay_server *server)
|
||||
new_client->sock = sock;
|
||||
new_client->server_port = server->port;
|
||||
new_client->ssl = server->ssl;
|
||||
#ifdef HAVE_GNUTLS
|
||||
new_client->hook_timer_handshake = NULL;
|
||||
new_client->gnutls_handshake_ok = 0;
|
||||
#endif /* HAVE_GNUTLS */
|
||||
new_client->websocket = 0;
|
||||
new_client->http_headers = NULL;
|
||||
new_client->address = strdup ((address && address[0]) ?
|
||||
@@ -1331,7 +1311,6 @@ relay_client_new (int sock, const char *address, struct t_relay_server *server)
|
||||
|
||||
relay_client_set_desc (new_client);
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
if (new_client->ssl)
|
||||
{
|
||||
if (!relay_network_init_ssl_cert_key_ok)
|
||||
@@ -1382,7 +1361,6 @@ relay_client_new (int sock, const char *address, struct t_relay_server *server)
|
||||
new_client,
|
||||
NULL);
|
||||
}
|
||||
#endif /* HAVE_GNUTLS */
|
||||
|
||||
new_client->protocol_data = NULL;
|
||||
switch (new_client->protocol)
|
||||
@@ -1490,11 +1468,9 @@ relay_client_new_with_infolist (struct t_infolist *infolist)
|
||||
new_client->sock = weechat_infolist_integer (infolist, "sock");
|
||||
new_client->server_port = weechat_infolist_integer (infolist, "server_port");
|
||||
new_client->ssl = weechat_infolist_integer (infolist, "ssl");
|
||||
#ifdef HAVE_GNUTLS
|
||||
new_client->gnutls_sess = NULL;
|
||||
new_client->hook_timer_handshake = NULL;
|
||||
new_client->gnutls_handshake_ok = 0;
|
||||
#endif /* HAVE_GNUTLS */
|
||||
new_client->websocket = weechat_infolist_integer (infolist, "websocket");
|
||||
new_client->http_headers = NULL;
|
||||
new_client->address = strdup (weechat_infolist_string (infolist, "address"));
|
||||
@@ -1614,14 +1590,12 @@ relay_client_set_status (struct t_relay_client *client,
|
||||
|
||||
relay_client_outqueue_free_all (client);
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
if (client->hook_timer_handshake)
|
||||
{
|
||||
weechat_unhook (client->hook_timer_handshake);
|
||||
client->hook_timer_handshake = NULL;
|
||||
}
|
||||
client->gnutls_handshake_ok = 0;
|
||||
#endif /* HAVE_GNUTLS */
|
||||
if (client->hook_fd)
|
||||
{
|
||||
weechat_unhook (client->hook_fd);
|
||||
@@ -1665,16 +1639,12 @@ relay_client_set_status (struct t_relay_client *client,
|
||||
|
||||
if (client->sock >= 0)
|
||||
{
|
||||
#ifdef HAVE_GNUTLS
|
||||
if (client->ssl && client->gnutls_handshake_ok)
|
||||
gnutls_bye (client->gnutls_sess, GNUTLS_SHUT_WR);
|
||||
#endif /* HAVE_GNUTLS */
|
||||
close (client->sock);
|
||||
client->sock = -1;
|
||||
#ifdef HAVE_GNUTLS
|
||||
if (client->ssl)
|
||||
gnutls_deinit (client->gnutls_sess);
|
||||
#endif /* HAVE_GNUTLS */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1721,10 +1691,8 @@ relay_client_free (struct t_relay_client *client)
|
||||
free (client->protocol_args);
|
||||
if (client->nonce)
|
||||
free (client->nonce);
|
||||
#ifdef HAVE_GNUTLS
|
||||
if (client->hook_timer_handshake)
|
||||
weechat_unhook (client->hook_timer_handshake);
|
||||
#endif /* HAVE_GNUTLS */
|
||||
if (client->http_headers)
|
||||
weechat_hashtable_free (client->http_headers);
|
||||
if (client->hook_fd)
|
||||
@@ -1833,12 +1801,10 @@ relay_client_add_to_infolist (struct t_infolist *infolist,
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "ssl", client->ssl))
|
||||
return 0;
|
||||
#ifdef HAVE_GNUTLS
|
||||
if (!weechat_infolist_new_var_pointer (ptr_item, "hook_timer_handshake", client->hook_timer_handshake))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "gnutls_handshake_ok", client->gnutls_handshake_ok))
|
||||
return 0;
|
||||
#endif /* HAVE_GNUTLS */
|
||||
if (!weechat_infolist_new_var_integer (ptr_item, "websocket", client->websocket))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_string (ptr_item, "address", client->address))
|
||||
@@ -1920,11 +1886,9 @@ relay_client_print_log ()
|
||||
weechat_log_printf (" sock. . . . . . . . . . . : %d", ptr_client->sock);
|
||||
weechat_log_printf (" server_port . . . . . . . : %d", ptr_client->server_port);
|
||||
weechat_log_printf (" ssl . . . . . . . . . . . : %d", ptr_client->ssl);
|
||||
#ifdef HAVE_GNUTLS
|
||||
weechat_log_printf (" gnutls_sess . . . . . . . : 0x%lx", ptr_client->gnutls_sess);
|
||||
weechat_log_printf (" hook_timer_handshake. . . : 0x%lx", ptr_client->hook_timer_handshake);
|
||||
weechat_log_printf (" gnutls_handshake_ok . . . : 0x%lx", ptr_client->gnutls_handshake_ok);
|
||||
#endif /* HAVE_GNUTLS */
|
||||
weechat_log_printf (" websocket . . . . . . . . : %d", ptr_client->websocket);
|
||||
weechat_log_printf (" http_headers. . . . . . . : 0x%lx (hashtable: '%s')",
|
||||
ptr_client->http_headers,
|
||||
|
||||
@@ -22,9 +22,7 @@
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
#include <gnutls/gnutls.h>
|
||||
#endif /* HAVE_GNUTLS */
|
||||
|
||||
struct t_relay_server;
|
||||
|
||||
@@ -92,11 +90,9 @@ struct t_relay_client
|
||||
int sock; /* socket for connection */
|
||||
int server_port; /* port used for connection */
|
||||
int ssl; /* 1 if SSL is enabled */
|
||||
#ifdef HAVE_GNUTLS
|
||||
gnutls_session_t gnutls_sess; /* gnutls session (only if SSL used) */
|
||||
struct t_hook *hook_timer_handshake; /* timer for doing gnutls handshake*/
|
||||
int gnutls_handshake_ok; /* 1 if handshake was done and OK */
|
||||
#endif /* HAVE_GNUTLS */
|
||||
int websocket; /* 0=not a ws, 1=init ws, 2=ws ready */
|
||||
struct t_hashtable *http_headers; /* HTTP headers for websocket */
|
||||
char *address; /* string with IP address */
|
||||
|
||||
@@ -318,7 +318,6 @@ relay_config_check_network_ssl_priorities (const void *pointer, void *data,
|
||||
struct t_config_option *option,
|
||||
const char *value)
|
||||
{
|
||||
#ifdef HAVE_GNUTLS
|
||||
gnutls_priority_t priority_cache;
|
||||
const char *pos_error;
|
||||
int rc;
|
||||
@@ -347,15 +346,6 @@ relay_config_check_network_ssl_priorities (const void *pointer, void *data,
|
||||
(pos_error) ? pos_error : value);
|
||||
|
||||
return 0;
|
||||
#else
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
(void) option;
|
||||
(void) value;
|
||||
|
||||
return 1;
|
||||
#endif /* HAVE_GNUTLS */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -371,13 +361,11 @@ relay_config_change_network_ssl_priorities (const void *pointer, void *data,
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
if (relay_network_init_ok && relay_gnutls_priority_cache)
|
||||
{
|
||||
gnutls_priority_deinit (*relay_gnutls_priority_cache);
|
||||
relay_network_set_priority ();
|
||||
}
|
||||
#endif /* HAVE_GNUTLS */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -762,17 +750,6 @@ relay_config_create_option_port_path (const void *pointer, void *data,
|
||||
relay_server_get_protocol_args (option_name, &ipv4, &ipv6, &ssl,
|
||||
&unix_socket, &protocol, &protocol_args);
|
||||
|
||||
#ifndef HAVE_GNUTLS
|
||||
if (ssl)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
_("%s%s: cannot use SSL because WeeChat was not built "
|
||||
"with GnuTLS support"),
|
||||
weechat_prefix ("error"), RELAY_PLUGIN_NAME);
|
||||
rc = WEECHAT_CONFIG_OPTION_SET_ERROR;
|
||||
}
|
||||
#endif /* HAVE_GNUTLS */
|
||||
|
||||
if (rc != WEECHAT_CONFIG_OPTION_SET_ERROR)
|
||||
{
|
||||
if (protocol)
|
||||
|
||||
@@ -21,9 +21,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
#include <gnutls/gnutls.h>
|
||||
#endif /* HAVE_GNUTLS */
|
||||
|
||||
#include "../weechat-plugin.h"
|
||||
#include "relay.h"
|
||||
@@ -34,11 +32,9 @@
|
||||
int relay_network_init_ok = 0;
|
||||
int relay_network_init_ssl_cert_key_ok = 0;
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
gnutls_certificate_credentials_t relay_gnutls_x509_cred;
|
||||
gnutls_priority_t *relay_gnutls_priority_cache = NULL;
|
||||
gnutls_dh_params_t *relay_gnutls_dh_params = NULL;
|
||||
#endif /* HAVE_GNUTLS */
|
||||
|
||||
|
||||
/*
|
||||
@@ -51,7 +47,6 @@ gnutls_dh_params_t *relay_gnutls_dh_params = NULL;
|
||||
void
|
||||
relay_network_set_ssl_cert_key (int verbose)
|
||||
{
|
||||
#ifdef HAVE_GNUTLS
|
||||
char *certkey_path, *certkey_path2, *weechat_dir;
|
||||
int ret;
|
||||
|
||||
@@ -99,10 +94,6 @@ relay_network_set_ssl_cert_key (int verbose)
|
||||
}
|
||||
free (certkey_path);
|
||||
}
|
||||
#else
|
||||
/* make C compiler happy */
|
||||
(void) verbose;
|
||||
#endif /* HAVE_GNUTLS */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -112,7 +103,6 @@ relay_network_set_ssl_cert_key (int verbose)
|
||||
void
|
||||
relay_network_set_priority ()
|
||||
{
|
||||
#ifdef HAVE_GNUTLS
|
||||
if (gnutls_priority_init (relay_gnutls_priority_cache,
|
||||
weechat_config_string (
|
||||
relay_config_network_ssl_priorities),
|
||||
@@ -124,7 +114,6 @@ relay_network_set_priority ()
|
||||
free (relay_gnutls_priority_cache);
|
||||
relay_gnutls_priority_cache = NULL;
|
||||
}
|
||||
#endif /* HAVE_GNUTLS */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -134,8 +123,6 @@ relay_network_set_priority ()
|
||||
void
|
||||
relay_network_init ()
|
||||
{
|
||||
#ifdef HAVE_GNUTLS
|
||||
|
||||
/* credentials */
|
||||
gnutls_certificate_allocate_credentials (&relay_gnutls_x509_cred);
|
||||
relay_network_set_ssl_cert_key (0);
|
||||
@@ -144,7 +131,7 @@ relay_network_init ()
|
||||
relay_gnutls_priority_cache = malloc (sizeof (*relay_gnutls_priority_cache));
|
||||
if (relay_gnutls_priority_cache)
|
||||
relay_network_set_priority ();
|
||||
#endif /* HAVE_GNUTLS */
|
||||
|
||||
relay_network_init_ok = 1;
|
||||
}
|
||||
|
||||
@@ -157,7 +144,6 @@ relay_network_end ()
|
||||
{
|
||||
if (relay_network_init_ok)
|
||||
{
|
||||
#ifdef HAVE_GNUTLS
|
||||
if (relay_gnutls_priority_cache)
|
||||
{
|
||||
gnutls_priority_deinit (*relay_gnutls_priority_cache);
|
||||
@@ -171,7 +157,7 @@ relay_network_end ()
|
||||
relay_gnutls_dh_params = NULL;
|
||||
}
|
||||
gnutls_certificate_free_credentials (relay_gnutls_x509_cred);
|
||||
#endif /* HAVE_GNUTLS */
|
||||
|
||||
relay_network_init_ok = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,18 +20,14 @@
|
||||
#ifndef WEECHAT_PLUGIN_RELAY_NETWORK_H
|
||||
#define WEECHAT_PLUGIN_RELAY_NETWORK_H
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
#include <gnutls/gnutls.h>
|
||||
#endif /* HAVE_GNUTLS */
|
||||
|
||||
extern int relay_network_init_ok;
|
||||
extern int relay_network_init_ssl_cert_key_ok;
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
extern gnutls_certificate_credentials_t relay_gnutls_x509_cred;
|
||||
extern gnutls_priority_t *relay_gnutls_priority_cache;
|
||||
extern gnutls_dh_params_t *relay_gnutls_dh_params;
|
||||
#endif /* HAVE_GNUTLS */
|
||||
|
||||
extern void relay_network_set_ssl_cert_key (int verbose);
|
||||
extern void relay_network_set_priority ();
|
||||
|
||||
@@ -21,9 +21,8 @@
|
||||
#define WEECHAT_PLUGIN_RELAY_SERVER_H
|
||||
|
||||
#include <time.h>
|
||||
#ifdef HAVE_GNUTLS
|
||||
|
||||
#define RELAY_SERVER_GNUTLS_DH_BITS 1024
|
||||
#endif /* HAVE_GNUTLS */
|
||||
|
||||
struct t_relay_server
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user