aboutsummaryrefslogtreecommitdiffstats
path: root/src/irc.c
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2020-11-19 19:43:31 -0500
committerLibravatarUnit 193 <unit193@unit193.net>2020-11-19 19:43:31 -0500
commit6a0204e95aa5358ef2bf7714559ccd366dba4617 (patch)
tree18e4e77b04125f3da8c6b97903d043afe3b5826d /src/irc.c
parentde54987ff29489950322f3408ea91651f4f48b4a (diff)
New upstream version 1.1.9.upstream/1.1.9
Diffstat (limited to 'src/irc.c')
-rw-r--r--src/irc.c104
1 files changed, 72 insertions, 32 deletions
diff --git a/src/irc.c b/src/irc.c
index cb34440..efe9daa 100644
--- a/src/irc.c
+++ b/src/irc.c
@@ -54,7 +54,6 @@
#include "negcache.h"
#include "memory.h"
#include "main.h"
-#include "serno.h"
/*
@@ -66,7 +65,8 @@ static unsigned int IRC_RAW_LEN; /* Position of IRC_RAW
static int IRC_FD = -1; /* File descriptor for IRC client */
static struct sockaddr_storage IRC_SVR; /* Sock Address Struct for IRC server */
-static socklen_t svr_addrlen;
+static socklen_t IRC_SVR_LEN;
+static char IRC_SVR_STR[INET6_ADDRSTRLEN];
static time_t IRC_LAST; /* Last full line of data from irc server */
static time_t IRC_LASTRECONNECT; /* Time of last reconnection */
@@ -119,17 +119,19 @@ m_perform(char *parv[], unsigned int parc, const char *msg, const char *source_p
{
node_t *node;
- log_printf("IRC -> Connected to %s/%d", IRCItem.server, IRCItem.port);
+ log_printf("IRC -> Connected to %s[%s]:%i", IRC_SVR_STR, IRCItem.server, IRCItem.port);
/* Identify to nickserv if needed */
if (!EmptyString(IRCItem.nickserv))
irc_send("%s", IRCItem.nickserv);
/* Oper */
- irc_send("OPER %s", IRCItem.oper);
+ if (!EmptyString(IRCItem.oper))
+ irc_send("OPER %s", IRCItem.oper);
/* Set modes */
- irc_send("MODE %s %s", IRCItem.nick, IRCItem.mode);
+ if (!EmptyString(IRCItem.mode))
+ irc_send("MODE %s %s", IRCItem.nick, IRCItem.mode);
/* Set Away */
if (!EmptyString(IRCItem.away))
@@ -213,8 +215,8 @@ static void
m_ctcp(char *parv[], unsigned int parc, const char *msg, const char *source_p)
{
if (strncasecmp(parv[3], "\001VERSION\001", 9) == 0)
- irc_send("NOTICE %s :\001VERSION Hybrid Open Proxy Monitor %s(%s)\001",
- source_p, VERSION, SERIALNUM);
+ irc_send("NOTICE %s :\001VERSION Hybrid Open Proxy Monitor %s\001",
+ source_p, VERSION);
}
/* m_privmsg
@@ -468,38 +470,64 @@ userinfo_create(const char *source)
static void
irc_init(void)
{
+ int n;
const void *address;
+ struct addrinfo hints, *res = NULL;
assert(IRC_FD == -1);
memset(&IRC_SVR, 0, sizeof(IRC_SVR));
+ if (!EmptyString(IRCItem.bind))
+ {
+ memset(&hints, 0, sizeof(hints));
+
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = AI_NUMERICHOST;
+
+ n = getaddrinfo(IRCItem.bind, NULL, &hints, &res);
+ if (n)
+ {
+ log_printf("IRC -> getaddrinfo() error: %s", gai_strerror(n));
+ exit(EXIT_FAILURE);
+ }
+ }
+
/* Resolve IRC host. */
- if ((address = firedns_resolveip6(IRCItem.server)))
+ if ((res == NULL || res->ai_family == AF_INET6) && (address = firedns_resolveip6(IRCItem.server)))
{
struct sockaddr_in6 *in = (struct sockaddr_in6 *)&IRC_SVR;
- svr_addrlen = sizeof(*in);
+ IRC_SVR_LEN = sizeof(*in);
IRC_SVR.ss_family = AF_INET6;
in->sin6_port = htons(IRCItem.port);
memcpy(&in->sin6_addr, address, sizeof(in->sin6_addr));
}
- else if ((address = firedns_resolveip4(IRCItem.server)))
+ else if ((res == NULL || res->ai_family == AF_INET) && (address = firedns_resolveip4(IRCItem.server)))
{
struct sockaddr_in *in = (struct sockaddr_in *)&IRC_SVR;
- svr_addrlen = sizeof(*in);
+ IRC_SVR_LEN = sizeof(*in);
IRC_SVR.ss_family = AF_INET;
in->sin_port = htons(IRCItem.port);
memcpy(&in->sin_addr, address, sizeof(in->sin_addr));
}
else
{
- log_printf("IRC -> firedns_resolveip(\"%s\"): %s", IRCItem.server,
+ log_printf("IRC -> Error resolving host '%s': %s", IRCItem.server,
firedns_strerror(firedns_errno));
exit(EXIT_FAILURE);
}
+ n = getnameinfo((const struct sockaddr *)&IRC_SVR, IRC_SVR_LEN, IRC_SVR_STR,
+ sizeof(IRC_SVR_STR), NULL, 0, NI_NUMERICHOST);
+ if (n)
+ {
+ log_printf("IRC -> getnameinfo() error: %s", gai_strerror(n));
+ exit(EXIT_FAILURE);
+ }
+
/* Request file desc for IRC client socket */
IRC_FD = socket(IRC_SVR.ss_family, SOCK_STREAM, 0);
@@ -510,25 +538,11 @@ irc_init(void)
}
/* Bind */
- if (!EmptyString(IRCItem.vhost))
+ if (res)
{
- struct addrinfo hints, *res;
-
- memset(&hints, 0, sizeof(hints));
-
- hints.ai_family = AF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_flags = AI_NUMERICHOST;
-
- int n = getaddrinfo(IRCItem.vhost, NULL, &hints, &res);
- if (n)
+ if (bind(IRC_FD, res->ai_addr, res->ai_addrlen))
{
- log_printf("IRC -> error binding to %s: %s", IRCItem.vhost, gai_strerror(n));
- exit(EXIT_FAILURE);
- }
- else if (bind(IRC_FD, res->ai_addr, res->ai_addrlen))
- {
- log_printf("IRC -> error binding to %s: %s", IRCItem.vhost, strerror(errno));
+ log_printf("IRC -> error binding to %s: %s", IRCItem.bind, strerror(errno));
exit(EXIT_FAILURE);
}
@@ -551,6 +565,31 @@ irc_init(void)
exit(EXIT_FAILURE);
}
+ if (!EmptyString(IRCItem.rsa_private_key_file) &&
+ !EmptyString(IRCItem.tls_certificate_file))
+ {
+ if (SSL_CTX_use_certificate_chain_file(ssl_ctx, IRCItem.tls_certificate_file) != 1)
+ {
+ log_printf("IRC -> couldn't load client certificate from %s: %s",
+ IRCItem.tls_certificate_file, ERR_error_string(ERR_get_error(), NULL));
+ exit(EXIT_FAILURE);
+ }
+
+ if (SSL_CTX_use_PrivateKey_file(ssl_ctx, IRCItem.rsa_private_key_file, SSL_FILETYPE_PEM) != 1)
+ {
+ log_printf("IRC -> couldn't load private key from %s: %s",
+ IRCItem.rsa_private_key_file, ERR_error_string(ERR_get_error(), NULL));
+ exit(EXIT_FAILURE);
+ }
+
+ if (SSL_CTX_check_private_key(ssl_ctx) != 1)
+ {
+ log_printf("IRC -> Private key does not match the client certificate: %s",
+ ERR_error_string(ERR_get_error(), NULL));
+ exit(EXIT_FAILURE);
+ }
+ }
+
SSL_CTX_set_min_proto_version(ssl_ctx, TLS1_2_VERSION);
SSL_CTX_set_default_verify_paths(ssl_ctx);
}
@@ -635,8 +674,10 @@ irc_connect(void)
irc_init();
+ log_printf("IRC -> Attempting to connect to %s[%s]:%i", IRC_SVR_STR, IRCItem.server, IRCItem.port);
+
/* Connect to IRC server as client. */
- if (connect(IRC_FD, (struct sockaddr *)&IRC_SVR, svr_addrlen) == -1)
+ if (connect(IRC_FD, (struct sockaddr *)&IRC_SVR, IRC_SVR_LEN) == -1)
{
log_printf("IRC -> connect(): error connecting to %s: %s",
IRCItem.server, strerror(errno));
@@ -828,7 +869,7 @@ irc_read(void)
/* Reset counter. */
IRC_RAW_LEN = 0;
- break;
+ return;
}
if (c != '\0')
@@ -842,7 +883,6 @@ irc_read(void)
irc_close();
IRC_RAW_LEN = 0;
- return;
}
}