1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-06 23:43:13 +02:00

Log linking attempts and errors. Also report them to IRCOps in an uniform way.

Reported by Mr_Smoke in https://bugs.unrealircd.org/view.php?id=3973
This commit is contained in:
Bram Matthys
2018-09-07 11:57:47 +02:00
parent 8d05951298
commit bd19e9c87a
5 changed files with 53 additions and 35 deletions
+1
View File
@@ -290,6 +290,7 @@ extern void sendto_snomask_normal(int snomask, char *pattern, ...) __attribute__
extern void sendto_snomask_normal_global(int snomask, char *pattern, ...) __attribute__((format(printf,2,3)));
extern void sendnotice(aClient *to, char *pattern, ...) __attribute__((format(printf,2,3)));
extern void sendto_server(aClient *one, unsigned long caps, unsigned long nocaps, const char *format, ...) __attribute__((format(printf, 4,5)));
extern void sendto_ops_and_log(char *pattern, ...) __attribute__((format(printf,1,2)));
extern MODVAR int writecalls, writeb[];
extern int deliver_it(aClient *, char *, int);
+20 -22
View File
@@ -271,7 +271,7 @@ int _verify_link(aClient *cptr, aClient *sptr, char *servername, ConfigItem_link
servername);
sendto_one(cptr, "ERROR :%s", xerrmsg);
sendto_umode(UMODE_OPER, "Outgoing link aborted to %s(%s@%s) (%s) %s",
sendto_ops_and_log("Outgoing link aborted to %s(%s@%s) (%s) %s",
cptr->serv->conf->servername, cptr->username, cptr->local->sockhost, xerrmsg, inpath);
return exit_client(cptr, sptr, &me, xerrmsg);
}
@@ -307,7 +307,7 @@ errlink:
"ERROR :Link denied (No link block found named '%s' or link::incoming::mask did not match your IP %s) %s",
servername, GetIP(cptr), inpath);
/* And send the "verbose" error msg only to locally connected ircops */
sendto_umode(UMODE_OPER, "Link denied for %s(%s@%s) (%s) %s",
sendto_ops_and_log("Link denied for %s(%s@%s) (%s) %s",
servername, cptr->username, cptr->local->sockhost, xerrmsg, inpath);
return exit_client(cptr, sptr, &me,
"Link denied (No link block found with your server name or link::incoming::mask did not match)");
@@ -320,7 +320,7 @@ skip_host_check:
sendto_one(cptr,
"ERROR :Link '%s' denied (Authentication failed) %s",
servername, inpath);
sendto_umode(UMODE_OPER, "Link denied for '%s' (Authentication failed [Bad password?]) %s",
sendto_ops_and_log("Link denied for '%s' (Authentication failed [Bad password?]) %s",
servername, inpath);
return exit_client(cptr, sptr, &me,
"Link denied (Authentication failed)");
@@ -336,7 +336,7 @@ skip_host_check:
sendto_one(cptr,
"ERROR :Link '%s' denied (Not using SSL/TLS) %s",
servername, inpath);
sendto_umode(UMODE_OPER, "Link denied for '%s' (Not using SSL/TLS and verify-certificate is on) %s",
sendto_ops_and_log("Link denied for '%s' (Not using SSL/TLS and verify-certificate is on) %s",
servername, inpath);
return exit_client(cptr, sptr, &me,
"Link denied (Not using SSL/TLS)");
@@ -346,9 +346,9 @@ skip_host_check:
sendto_one(cptr,
"ERROR :Link '%s' denied (Certificate verification failed) %s",
servername, inpath);
sendto_umode(UMODE_OPER, "Link denied for '%s' (Certificate verification failed) %s",
sendto_ops_and_log("Link denied for '%s' (Certificate verification failed) %s",
servername, inpath);
sendto_umode(UMODE_OPER, "Reason for certificate verification failure: %s", errstr);
sendto_ops_and_log("Reason for certificate verification failure: %s", errstr);
return exit_client(cptr, sptr, &me,
"Link denied (Certificate verification failed)");
}
@@ -364,7 +364,7 @@ skip_host_check:
if (IsMe(acptr))
{
sendto_realops("Link %s rejected, server trying to link with my name (%s)",
sendto_ops_and_log("Link %s rejected, server trying to link with my name (%s)",
get_client_name(sptr, TRUE), me.name);
sendto_one(sptr, "ERROR: Server %s exists (it's me!)", me.name);
return exit_client(sptr, sptr, sptr, "Server Exists");
@@ -379,7 +379,7 @@ skip_host_check:
"ERROR :Server %s already exists from %s",
servername,
(ocptr->from ? ocptr->from->name : "<nobody>"));
sendto_realops
sendto_ops_and_log
("Link %s cancelled, server %s already exists from %s",
get_client_name(acptr, TRUE), servername,
(ocptr->from ? ocptr->from->name : "<nobody>"));
@@ -388,7 +388,7 @@ skip_host_check:
}
if ((bconf = Find_ban(NULL, servername, CONF_BAN_SERVER)))
{
sendto_realops
sendto_ops_and_log
("Cancelling link %s, banned server",
get_client_name(cptr, TRUE));
sendto_one(cptr, "ERROR :Banned server (%s)", bconf->reason ? bconf->reason : "no reason");
@@ -396,15 +396,14 @@ skip_host_check:
}
if (link->class->clients + 1 > link->class->maxclients)
{
sendto_realops
("Cancelling link %s, full class",
sendto_ops_and_log("Cancelling link %s, full class",
get_client_name(cptr, TRUE));
return exit_client(cptr, cptr, &me, "Full class");
}
if (!IsLocal(cptr) && (iConf.plaintext_policy_server == PLAINTEXT_POLICY_DENY) && !IsSecure(cptr))
{
sendto_one(cptr, "ERROR :Servers need to use SSL/TLS (set::plaintext-policy::server is 'deny')");
sendto_realops("Rejected insecure server. See https://www.unrealircd.org/docs/FAQ#ERROR:_Servers_need_to_use_SSL.2FTLS");
sendto_ops_and_log("Rejected insecure server %s. See https://www.unrealircd.org/docs/FAQ#ERROR:_Servers_need_to_use_SSL.2FTLS", cptr->name);
return exit_client(cptr, sptr, &me, "Servers need to use SSL/TLS (set::plaintext-policy::server is 'deny')");
}
if (link_out)
@@ -556,7 +555,7 @@ CMD_FUNC(m_server)
{
if (deny->flag.type == CRULE_ALL && !match(deny->mask, servername)
&& crule_eval(deny->rule)) {
sendto_ops("Refused connection from %s.",
sendto_ops_and_log("Refused connection from %s. Rejected by deny link { } block.",
get_client_host(cptr));
return exit_client(cptr, cptr, cptr,
"Disallowed by connection rule");
@@ -600,7 +599,7 @@ CMD_FUNC(m_server_remote)
if (IsMe(acptr))
{
sendto_realops("Link %s rejected, server trying to link with my name (%s)",
sendto_ops_and_log("Link %s rejected, server trying to link with my name (%s)",
get_client_name(sptr, TRUE), me.name);
sendto_one(sptr, "ERROR: Server %s exists (it's me!)", me.name);
return exit_client(sptr, sptr, sptr, "Server Exists");
@@ -615,7 +614,7 @@ CMD_FUNC(m_server_remote)
"ERROR :Server %s already exists from %s",
servername,
(ocptr->from ? ocptr->from->name : "<nobody>"));
sendto_realops
sendto_ops_and_log
("Link %s cancelled, server %s already exists from %s",
get_client_name(acptr, TRUE), servername,
(ocptr->from ? ocptr->from->name : "<nobody>"));
@@ -633,8 +632,7 @@ CMD_FUNC(m_server_remote)
}
if ((bconf = Find_ban(NULL, servername, CONF_BAN_SERVER)))
{
sendto_realops
("Cancelling link %s, banned server %s",
sendto_ops_and_log("Cancelling link %s, banned server %s",
get_client_name(cptr, TRUE), servername);
sendto_one(cptr, "ERROR :Banned server (%s)", bconf->reason ? bconf->reason : "no reason");
return exit_client(cptr, cptr, &me, "Brought in banned server");
@@ -644,19 +642,19 @@ CMD_FUNC(m_server_remote)
strlcpy(info, parv[parc - 1], sizeof(info));
if (!cptr->serv->conf)
{
sendto_realops("Lost conf for %s!!, dropping link", cptr->name);
sendto_ops_and_log("Internal error: lost conf for %s!!, dropping link", cptr->name);
return exit_client(cptr, cptr, cptr, "Lost configuration");
}
aconf = cptr->serv->conf;
if (!aconf->hub)
{
sendto_umode(UMODE_OPER, "Link %s cancelled, is Non-Hub but introduced Leaf %s",
sendto_ops_and_log("Link %s cancelled, is Non-Hub but introduced Leaf %s",
cptr->name, servername);
return exit_client(cptr, cptr, cptr, "Non-Hub Link");
}
if (match(aconf->hub, servername))
{
sendto_umode(UMODE_OPER, "Link %s cancelled, linked in %s, which hub config disallows",
sendto_ops_and_log("Link %s cancelled, linked in %s, which hub config disallows",
cptr->name, servername);
return exit_client(cptr, cptr, cptr, "Not matching hub configuration");
}
@@ -664,14 +662,14 @@ CMD_FUNC(m_server_remote)
{
if (match(aconf->leaf, servername))
{
sendto_umode(UMODE_OPER, "Link %s(%s) cancelled, disallowed by leaf configuration",
sendto_ops_and_log("Link %s(%s) cancelled, disallowed by leaf configuration",
cptr->name, servername);
return exit_client(cptr, cptr, cptr, "Disallowed by leaf configuration");
}
}
if (aconf->leaf_depth && (hop > aconf->leaf_depth))
{
sendto_umode(UMODE_OPER, "Link %s(%s) cancelled, too deep depth",
sendto_ops_and_log("Link %s(%s) cancelled, too deep depth",
cptr->name, servername);
return exit_client(cptr, cptr, cptr, "Too deep link depth (leaf)");
}
+7 -7
View File
@@ -190,7 +190,7 @@ void reinit_resolver(aClient *sptr)
{
EventDel(unrealdns_timeout_hdl);
sendto_realops("%s requested reinitalization of resolver!", sptr->name);
sendto_ops_and_log("%s requested reinitalization of resolver!", sptr->name);
sendto_realops("Destroying resolver channel, along with all currently pending queries...");
ares_destroy(resolver_channel);
sendto_realops("Initializing resolver again...");
@@ -411,7 +411,7 @@ void unrealdns_cb_nametoip_link(void *arg, int status, int timeouts, struct host
}
/* fatal error while resolving */
sendto_realops("Unable to resolve hostname '%s', when trying to connect to server %s.",
sendto_ops_and_log("Unable to resolve hostname '%s', when trying to connect to server %s.",
r->name, r->linkblock->servername);
r->linkblock->refcount--;
unrealdns_freeandremovereq(r);
@@ -423,7 +423,7 @@ void unrealdns_cb_nametoip_link(void *arg, int status, int timeouts, struct host
!(ip = inetntop(r->ipv6 ? AF_INET6 : AF_INET, he->h_addr_list[0], ipbuf, sizeof(ipbuf))))
{
/* Illegal response -- fatal */
sendto_realops("Unable to resolve hostname '%s', when trying to connect to server %s.",
sendto_ops_and_log("Unable to resolve hostname '%s', when trying to connect to server %s.",
r->name, r->linkblock->servername);
unrealdns_freeandremovereq(r);
return;
@@ -438,17 +438,17 @@ void unrealdns_cb_nametoip_link(void *arg, int status, int timeouts, struct host
switch ((n = connect_server(r->linkblock, r->cptr, he2)))
{
case 0:
sendto_realops("Connecting to %s[%s].", r->linkblock->servername, ip);
sendto_ops_and_log("Connecting to server %s[%s].", r->linkblock->servername, ip);
break;
case -1:
sendto_realops("Couldn't connect to %s[%s].", r->linkblock->servername, ip);
sendto_ops_and_log("Couldn't connect to server %s[%s].", r->linkblock->servername, ip);
break;
case -2:
/* Should not happen since he is not NULL */
sendto_realops("Hostname %s is unknown for server %s (!?).", r->linkblock->outgoing.hostname, r->linkblock->servername);
sendto_ops_and_log("Hostname %s is unknown for server %s (!?).", r->linkblock->outgoing.hostname, r->linkblock->servername);
break;
default:
sendto_realops("Connection to %s failed: %s", r->linkblock->servername, STRERROR(n));
sendto_ops_and_log("Connection to server %s failed: %s", r->linkblock->servername, STRERROR(n));
}
unrealdns_freeandremovereq(r);
+10 -6
View File
@@ -290,7 +290,7 @@ static void listener_accept(int listener_fd, int revents, void *data)
ircstp->is_ref++;
if (last_allinuse < TStime() - 15)
{
sendto_realops("All connections in use. ([@%s/%u])", listener->ip, listener->port);
sendto_ops_and_log("All connections in use. ([@%s/%u])", listener->ip, listener->port);
last_allinuse = TStime();
}
@@ -340,7 +340,7 @@ int inetport(ConfigItem_listen *listener, char *ip, int port, int ipv6)
if (++OpenFiles >= MAXCLIENTS)
{
sendto_ops("No more connections allowed (%s)", listener->ip);
sendto_ops_and_log("No more connections allowed (%s)", listener->ip);
fd_close(listener->fd);
listener->fd = -1;
--OpenFiles;
@@ -612,7 +612,7 @@ void start_server_handshake(aClient *cptr)
if (!aconf)
{
/* Should be impossible. */
sendto_ops("Lost configuration for %s in start_server_handshake()", get_client_name(cptr, FALSE));
sendto_ops_and_log("Lost configuration for %s in start_server_handshake()", get_client_name(cptr, FALSE));
return;
}
@@ -663,7 +663,7 @@ void completed_connection(int fd, int revents, void *data)
if (!aconf)
{
sendto_ops("Lost configuration for %s", get_client_name(cptr, FALSE));
sendto_ops_and_log("Lost configuration for %s", get_client_name(cptr, FALSE));
return;
}
@@ -1336,8 +1336,12 @@ void read_packet(int fd, int revents, void *data)
return;
if (IsServer(cptr) || cptr->serv) /* server or outgoing connection */
{
sendto_umode_global(UMODE_OPER, "Lost connection to %s: Read error",
get_client_name(cptr, FALSE));
get_client_name(cptr, FALSE));
ircd_log(LOG_ERROR, "Lost connection to %s: Read error",
get_client_name(cptr, FALSE));
}
exit_client(cptr, cptr, cptr, "Read error");
return;
@@ -1577,7 +1581,7 @@ int connect_inet(ConfigItem_link *aconf, aClient *cptr)
}
if (++OpenFiles >= MAXCLIENTS)
{
sendto_realops("No more connections allowed (%s)", cptr->name);
sendto_ops_and_log("No more connections allowed (%s)", cptr->name);
return 0;
}
+15
View File
@@ -1473,3 +1473,18 @@ void send_raw_direct(aClient *user, char *pattern, ...)
va_end(vl);
(void)send(user->fd, sendbuf, sendlen, 0);
}
/** Send a message to all locally connected IRCOps and log the error.
*/
void sendto_ops_and_log(char *pattern, ...)
{
va_list vl;
char buf[1024];
va_start(vl, pattern);
ircvsnprintf(buf, sizeof(buf), pattern, vl);
va_end(vl);
ircd_log(LOG_ERROR, "%s", buf);
sendto_umode(UMODE_OPER, "%s", buf);
}