]> jfr.im git - irc/freenode/solanum.git/blame - modules/core/m_error.c
make more snotes L_NETWIDE
[irc/freenode/solanum.git] / modules / core / m_error.c
CommitLineData
212380e3
WP
1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_error.c: Handles error messages from the other end.
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
212380e3
WP
23 */
24
25#include "stdinc.h"
26#include "client.h"
212380e3
WP
27#include "ircd.h"
28#include "numeric.h"
29#include "send.h"
30#include "msg.h"
212380e3 31#include "modules.h"
4016731b 32#include "logger.h"
212380e3
WP
33#include "s_conf.h"
34
eeabf33a
EM
35static const char error_desc[] =
36 "Provides the ERROR command for clients and servers";
37
3c7d6fcc
EM
38static void m_error(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
39static void ms_error(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
212380e3
WP
40
41struct Message error_msgtab = {
7baa37a9 42 "ERROR", 0, 0, 0, 0,
212380e3
WP
43 {{m_error, 0}, mg_ignore, mg_ignore, {ms_error, 0}, mg_ignore, mg_ignore}
44};
45
46mapi_clist_av1 error_clist[] = {
47 &error_msgtab, NULL
48};
49
ee6dcb05 50DECLARE_MODULE_AV2(error, NULL, NULL, error_clist, NULL, NULL, NULL, NULL, error_desc);
212380e3 51
922aa826 52/* Determine whether an ERROR message is safe to show (no IP address in it) */
3c7d6fcc 53static bool
922aa826
JT
54is_safe_error(const char *message)
55{
56 char prefix2[100];
57 const char *p;
58
59 if (!strncmp(message, "Closing Link: 127.0.0.1 (", 25))
3c7d6fcc 60 return true;
5203cba5 61 snprintf(prefix2, sizeof prefix2,
922aa826
JT
62 "Closing Link: 127.0.0.1 %s (", me.name);
63 if (!strncmp(message, prefix2, strlen(prefix2)))
3c7d6fcc 64 return true;
922aa826 65 if (!strncmp(message, "Restart by ", 11))
3c7d6fcc 66 return true;
922aa826 67 if (!strncmp(message, "Terminated by ", 14))
3c7d6fcc 68 return true;
922aa826 69
f956cb0f 70 if (!rb_strncasecmp(message, "Closing Link", 12))
3c7d6fcc 71 return false;
922aa826 72 if (strchr(message, '['))
3c7d6fcc 73 return false;
922aa826
JT
74 p = strchr(message, '.');
75 if (p != NULL && p[1] != '\0')
3c7d6fcc 76 return false;
922aa826 77 if (strchr(message, ':'))
3c7d6fcc 78 return false;
922aa826 79
3c7d6fcc 80 return true;
922aa826 81}
212380e3
WP
82
83/*
84 * Note: At least at protocol level ERROR has only one parameter,
85 * although this is called internally from other functions
86 * --msa
87 *
212380e3
WP
88 * parv[*] = parameters
89 */
3c7d6fcc 90static void
428ca87b 91m_error(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
WP
92{
93 const char *para;
922aa826 94 int hideit = ConfigFileEntry.hide_error_messages;
212380e3
WP
95
96 para = (parc > 1 && *parv[1] != '\0') ? parv[1] : "<>";
97
0a849a8f
JT
98 if (IsAnyServer(client_p))
99 {
100 ilog(L_SERVER, "Received ERROR message from %s: %s",
101 log_client_name(source_p, SHOW_IP), para);
102 }
212380e3 103
922aa826
JT
104 if(is_safe_error(para))
105 hideit = 0;
106 if(IsAnyServer(client_p))
212380e3 107 {
922aa826 108 if (hideit < 2)
a9227555 109 sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : L_NETWIDE,
922aa826 110 "ERROR :from %s -- %s",
b3ebc7ab 111 client_p->name, para);
922aa826 112 if (hideit > 0)
a9227555 113 sendto_realops_snomask(SNO_GENERAL, hideit == 1 ? L_OPER | L_NETWIDE : L_NETWIDE,
922aa826 114 "ERROR :from %s -- <hidden>",
b3ebc7ab 115 client_p->name);
212380e3
WP
116 }
117
118 exit_client(client_p, source_p, source_p, "ERROR");
212380e3
WP
119}
120
3c7d6fcc 121static void
428ca87b 122ms_error(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
WP
123{
124 const char *para;
922aa826 125 int hideit = ConfigFileEntry.hide_error_messages;
212380e3
WP
126
127 para = (parc > 1 && *parv[1] != '\0') ? parv[1] : "<>";
128
129 ilog(L_SERVER, "Received ERROR message from %s: %s",
130 log_client_name(source_p, SHOW_IP), para);
131
922aa826
JT
132 if(is_safe_error(para))
133 hideit = 0;
134 if(hideit == 2)
3c7d6fcc 135 return;
212380e3
WP
136
137 if(client_p == source_p)
138 {
a9227555 139 sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : L_NETWIDE, "ERROR :from %s -- %s",
b3ebc7ab 140 client_p->name, para);
212380e3
WP
141 }
142 else
143 {
a9227555 144 sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : L_NETWIDE, "ERROR :from %s via %s -- %s",
b3ebc7ab 145 source_p->name, client_p->name, para);
212380e3 146 }
212380e3 147}