]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/core/m_error.c
Do not install ban .conf files (like kline.conf, rsv.conf, etc) as they aren't used...
[irc/rqf/shadowircd.git] / modules / core / m_error.c
CommitLineData
212380e3 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
23 *
212380e3 24 */
25
26#include "stdinc.h"
27#include "client.h"
28#include "common.h" /* FALSE */
29#include "ircd.h"
30#include "numeric.h"
31#include "send.h"
32#include "msg.h"
212380e3 33#include "modules.h"
d3455e2c 34#include "logger.h"
212380e3 35#include "s_conf.h"
36
37static int m_error(struct Client *, struct Client *, int, const char **);
38static int ms_error(struct Client *, struct Client *, int, const char **);
39
40struct Message error_msgtab = {
41 "ERROR", 0, 0, 0, MFLG_SLOW | MFLG_UNREG,
42 {{m_error, 0}, mg_ignore, mg_ignore, {ms_error, 0}, mg_ignore, mg_ignore}
43};
44
45mapi_clist_av1 error_clist[] = {
46 &error_msgtab, NULL
47};
48
49DECLARE_MODULE_AV1(error, NULL, NULL, error_clist, NULL, NULL, "$Revision: 494 $");
50
372b2193
JT
51/* Determine whether an ERROR message is safe to show (no IP address in it) */
52static int
53is_safe_error(const char *message)
54{
55 char prefix2[100];
56 const char *p;
57
58 if (!strncmp(message, "Closing Link: 127.0.0.1 (", 25))
59 return 1;
5b0a5279 60 rb_snprintf(prefix2, sizeof prefix2,
372b2193
JT
61 "Closing Link: 127.0.0.1 %s (", me.name);
62 if (!strncmp(message, prefix2, strlen(prefix2)))
63 return 1;
64 if (!strncmp(message, "Restart by ", 11))
65 return 1;
66 if (!strncmp(message, "Terminated by ", 14))
67 return 1;
68
69 if (!ircncmp(message, "Closing Link", 12))
70 return 0;
71 if (strchr(message, '['))
72 return 0;
73 p = strchr(message, '.');
74 if (p != NULL && p[1] != '\0')
75 return 0;
76 if (strchr(message, ':'))
77 return 0;
78
79 return 1;
80}
212380e3 81
82/*
83 * Note: At least at protocol level ERROR has only one parameter,
84 * although this is called internally from other functions
85 * --msa
86 *
212380e3 87 * parv[*] = parameters
88 */
89int
90m_error(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
91{
92 const char *para;
372b2193 93 int hideit = ConfigFileEntry.hide_error_messages;
212380e3 94
95 para = (parc > 1 && *parv[1] != '\0') ? parv[1] : "<>";
96
a13b19f9
JT
97 if (IsAnyServer(client_p))
98 {
99 ilog(L_SERVER, "Received ERROR message from %s: %s",
100 log_client_name(source_p, SHOW_IP), para);
101 }
212380e3 102
372b2193
JT
103 if(is_safe_error(para))
104 hideit = 0;
105 if(IsAnyServer(client_p))
212380e3 106 {
372b2193
JT
107 if (hideit < 2)
108 sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : (is_remote_connect(client_p) ? L_NETWIDE : L_ALL),
109 "ERROR :from %s -- %s",
715b28fe 110 client_p->name, para);
372b2193
JT
111 if (hideit > 0)
112 sendto_realops_snomask(SNO_GENERAL, (hideit == 1 ? L_OPER : L_ALL) | (is_remote_connect(client_p) ? L_NETWIDE : L_ALL),
113 "ERROR :from %s -- <hidden>",
715b28fe 114 client_p->name);
212380e3 115 }
116
117 exit_client(client_p, source_p, source_p, "ERROR");
118
119 return 0;
120}
121
122static int
123ms_error(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
124{
125 const char *para;
372b2193 126 int hideit = ConfigFileEntry.hide_error_messages;
212380e3 127
128 para = (parc > 1 && *parv[1] != '\0') ? parv[1] : "<>";
129
130 ilog(L_SERVER, "Received ERROR message from %s: %s",
131 log_client_name(source_p, SHOW_IP), para);
132
372b2193
JT
133 if(is_safe_error(para))
134 hideit = 0;
135 if(hideit == 2)
212380e3 136 return 0;
137
138 if(client_p == source_p)
139 {
372b2193 140 sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : L_ALL, "ERROR :from %s -- %s",
715b28fe 141 client_p->name, para);
212380e3 142 }
143 else
144 {
372b2193 145 sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : L_ALL, "ERROR :from %s via %s -- %s",
715b28fe 146 source_p->name, client_p->name, para);
212380e3 147 }
148
149 return 0;
150}