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