]>
Commit | Line | Data |
---|---|---|
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" | |
ee6dcb05 | 27 | #include "common.h" |
212380e3 AC |
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 |
36 | static int m_error(struct MsgBuf *, struct Client *, struct Client *, int, const char **); |
37 | static int ms_error(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
212380e3 AC |
38 | |
39 | struct 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 | ||
44 | mapi_clist_av1 error_clist[] = { | |
45 | &error_msgtab, NULL | |
46 | }; | |
47 | ||
ee6dcb05 EM |
48 | static const char error_desc[] = |
49 | "Provides the ERROR command for clients and servers"; | |
50 | ||
51 | DECLARE_MODULE_AV2(error, NULL, NULL, error_clist, NULL, NULL, NULL, NULL, error_desc); | |
212380e3 | 52 | |
922aa826 JT |
53 | /* Determine whether an ERROR message is safe to show (no IP address in it) */ |
54 | static int | |
55 | is_safe_error(const char *message) | |
56 | { | |
57 | char prefix2[100]; | |
58 | const char *p; | |
59 | ||
60 | if (!strncmp(message, "Closing Link: 127.0.0.1 (", 25)) | |
61 | return 1; | |
5203cba5 | 62 | snprintf(prefix2, sizeof prefix2, |
922aa826 JT |
63 | "Closing Link: 127.0.0.1 %s (", me.name); |
64 | if (!strncmp(message, prefix2, strlen(prefix2))) | |
65 | return 1; | |
66 | if (!strncmp(message, "Restart by ", 11)) | |
67 | return 1; | |
68 | if (!strncmp(message, "Terminated by ", 14)) | |
69 | return 1; | |
70 | ||
71 | if (!ircncmp(message, "Closing Link", 12)) | |
72 | return 0; | |
73 | if (strchr(message, '[')) | |
74 | return 0; | |
75 | p = strchr(message, '.'); | |
76 | if (p != NULL && p[1] != '\0') | |
77 | return 0; | |
78 | if (strchr(message, ':')) | |
79 | return 0; | |
80 | ||
81 | return 1; | |
82 | } | |
212380e3 AC |
83 | |
84 | /* | |
85 | * Note: At least at protocol level ERROR has only one parameter, | |
86 | * although this is called internally from other functions | |
87 | * --msa | |
88 | * | |
212380e3 AC |
89 | * parv[*] = parameters |
90 | */ | |
91 | int | |
428ca87b | 92 | m_error(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
93 | { |
94 | const char *para; | |
922aa826 | 95 | int hideit = ConfigFileEntry.hide_error_messages; |
212380e3 AC |
96 | |
97 | para = (parc > 1 && *parv[1] != '\0') ? parv[1] : "<>"; | |
98 | ||
0a849a8f JT |
99 | if (IsAnyServer(client_p)) |
100 | { | |
101 | ilog(L_SERVER, "Received ERROR message from %s: %s", | |
102 | log_client_name(source_p, SHOW_IP), para); | |
103 | } | |
212380e3 | 104 | |
922aa826 JT |
105 | if(is_safe_error(para)) |
106 | hideit = 0; | |
107 | if(IsAnyServer(client_p)) | |
212380e3 | 108 | { |
922aa826 JT |
109 | if (hideit < 2) |
110 | sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : (is_remote_connect(client_p) ? L_NETWIDE : L_ALL), | |
111 | "ERROR :from %s -- %s", | |
b3ebc7ab | 112 | client_p->name, para); |
922aa826 JT |
113 | if (hideit > 0) |
114 | sendto_realops_snomask(SNO_GENERAL, (hideit == 1 ? L_OPER : L_ALL) | (is_remote_connect(client_p) ? L_NETWIDE : L_ALL), | |
115 | "ERROR :from %s -- <hidden>", | |
b3ebc7ab | 116 | client_p->name); |
212380e3 AC |
117 | } |
118 | ||
119 | exit_client(client_p, source_p, source_p, "ERROR"); | |
120 | ||
121 | return 0; | |
122 | } | |
123 | ||
124 | static int | |
428ca87b | 125 | ms_error(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
126 | { |
127 | const char *para; | |
922aa826 | 128 | int hideit = ConfigFileEntry.hide_error_messages; |
212380e3 AC |
129 | |
130 | para = (parc > 1 && *parv[1] != '\0') ? parv[1] : "<>"; | |
131 | ||
132 | ilog(L_SERVER, "Received ERROR message from %s: %s", | |
133 | log_client_name(source_p, SHOW_IP), para); | |
134 | ||
922aa826 JT |
135 | if(is_safe_error(para)) |
136 | hideit = 0; | |
137 | if(hideit == 2) | |
212380e3 AC |
138 | return 0; |
139 | ||
140 | if(client_p == source_p) | |
141 | { | |
922aa826 | 142 | sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : L_ALL, "ERROR :from %s -- %s", |
b3ebc7ab | 143 | client_p->name, para); |
212380e3 AC |
144 | } |
145 | else | |
146 | { | |
922aa826 | 147 | sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : L_ALL, "ERROR :from %s via %s -- %s", |
b3ebc7ab | 148 | source_p->name, client_p->name, para); |
212380e3 AC |
149 | } |
150 | ||
151 | return 0; | |
152 | } |