]>
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 | |
23 | * | |
24 | * $Id: m_error.c 494 2006-01-15 16:08:28Z jilles $ | |
25 | */ | |
26 | ||
27 | #include "stdinc.h" | |
28 | #include "client.h" | |
29 | #include "common.h" /* FALSE */ | |
30 | #include "ircd.h" | |
31 | #include "numeric.h" | |
32 | #include "send.h" | |
33 | #include "msg.h" | |
34 | #include "memory.h" | |
35 | #include "modules.h" | |
36 | #include "s_log.h" | |
37 | #include "s_conf.h" | |
38 | ||
39 | static int m_error(struct Client *, struct Client *, int, const char **); | |
40 | static int ms_error(struct Client *, struct Client *, int, const char **); | |
41 | ||
42 | struct Message error_msgtab = { | |
43 | "ERROR", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, | |
44 | {{m_error, 0}, mg_ignore, mg_ignore, {ms_error, 0}, mg_ignore, mg_ignore} | |
45 | }; | |
46 | ||
47 | mapi_clist_av1 error_clist[] = { | |
48 | &error_msgtab, NULL | |
49 | }; | |
50 | ||
51 | DECLARE_MODULE_AV1(error, NULL, NULL, error_clist, NULL, NULL, "$Revision: 494 $"); | |
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; | |
62 | snprintf(prefix2, sizeof prefix2, | |
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 | * | |
89 | * parv[0] = sender prefix | |
90 | * parv[*] = parameters | |
91 | */ | |
92 | int | |
93 | m_error(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
94 | { | |
95 | const char *para; | |
922aa826 | 96 | int hideit = ConfigFileEntry.hide_error_messages; |
212380e3 AC |
97 | |
98 | para = (parc > 1 && *parv[1] != '\0') ? parv[1] : "<>"; | |
99 | ||
100 | ilog(L_SERVER, "Received ERROR message from %s: %s", | |
101 | log_client_name(source_p, SHOW_IP), para); | |
102 | ||
922aa826 JT |
103 | if(is_safe_error(para)) |
104 | hideit = 0; | |
105 | if(IsAnyServer(client_p)) | |
212380e3 | 106 | { |
922aa826 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", | |
110 | get_server_name(client_p, HIDE_IP), para); | |
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>", | |
114 | get_server_name(client_p, HIDE_IP)); | |
212380e3 AC |
115 | } |
116 | ||
117 | exit_client(client_p, source_p, source_p, "ERROR"); | |
118 | ||
119 | return 0; | |
120 | } | |
121 | ||
122 | static int | |
123 | ms_error(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
124 | { | |
125 | const char *para; | |
922aa826 | 126 | int hideit = ConfigFileEntry.hide_error_messages; |
212380e3 AC |
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 | ||
922aa826 JT |
133 | if(is_safe_error(para)) |
134 | hideit = 0; | |
135 | if(hideit == 2) | |
212380e3 AC |
136 | return 0; |
137 | ||
138 | if(client_p == source_p) | |
139 | { | |
922aa826 | 140 | sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : L_ALL, "ERROR :from %s -- %s", |
212380e3 | 141 | get_server_name(client_p, HIDE_IP), para); |
212380e3 AC |
142 | } |
143 | else | |
144 | { | |
922aa826 | 145 | sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : L_ALL, "ERROR :from %s via %s -- %s", |
212380e3 | 146 | source_p->name, get_server_name(client_p, HIDE_IP), para); |
212380e3 AC |
147 | } |
148 | ||
149 | return 0; | |
150 | } |