]>
Commit | Line | Data |
---|---|---|
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 "modules.h" | |
35 | #include "logger.h" | |
36 | #include "s_conf.h" | |
37 | ||
38 | static int m_error(struct Client *, struct Client *, int, const char **); | |
39 | static int ms_error(struct Client *, struct Client *, int, const char **); | |
40 | ||
41 | struct Message error_msgtab = { | |
42 | "ERROR", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, | |
43 | {{m_error, 0}, mg_ignore, mg_ignore, {ms_error, 0}, mg_ignore, mg_ignore} | |
44 | }; | |
45 | ||
46 | mapi_clist_av1 error_clist[] = { | |
47 | &error_msgtab, NULL | |
48 | }; | |
49 | ||
50 | DECLARE_MODULE_AV1(error, NULL, NULL, error_clist, NULL, NULL, "$Revision: 494 $"); | |
51 | ||
52 | /* Determine whether an ERROR message is safe to show (no IP address in it) */ | |
53 | static int | |
54 | is_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)) | |
60 | return 1; | |
61 | rb_snprintf(prefix2, sizeof prefix2, | |
62 | "Closing Link: 127.0.0.1 %s (", me.name); | |
63 | if (!strncmp(message, prefix2, strlen(prefix2))) | |
64 | return 1; | |
65 | if (!strncmp(message, "Restart by ", 11)) | |
66 | return 1; | |
67 | if (!strncmp(message, "Terminated by ", 14)) | |
68 | return 1; | |
69 | ||
70 | if (!ircncmp(message, "Closing Link", 12)) | |
71 | return 0; | |
72 | if (strchr(message, '[')) | |
73 | return 0; | |
74 | p = strchr(message, '.'); | |
75 | if (p != NULL && p[1] != '\0') | |
76 | return 0; | |
77 | if (strchr(message, ':')) | |
78 | return 0; | |
79 | ||
80 | return 1; | |
81 | } | |
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 | * | |
88 | * parv[*] = parameters | |
89 | */ | |
90 | int | |
91 | m_error(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
92 | { | |
93 | const char *para; | |
94 | int hideit = ConfigFileEntry.hide_error_messages; | |
95 | ||
96 | para = (parc > 1 && *parv[1] != '\0') ? parv[1] : "<>"; | |
97 | ||
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 | } | |
103 | ||
104 | if(is_safe_error(para)) | |
105 | hideit = 0; | |
106 | if(IsAnyServer(client_p)) | |
107 | { | |
108 | if (hideit < 2) | |
109 | sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : (is_remote_connect(client_p) ? L_NETWIDE : L_ALL), | |
110 | "ERROR :from %s -- %s", | |
111 | client_p->name, para); | |
112 | if (hideit > 0) | |
113 | sendto_realops_snomask(SNO_GENERAL, (hideit == 1 ? L_OPER : L_ALL) | (is_remote_connect(client_p) ? L_NETWIDE : L_ALL), | |
114 | "ERROR :from %s -- <hidden>", | |
115 | client_p->name); | |
116 | } | |
117 | ||
118 | exit_client(client_p, source_p, source_p, "ERROR"); | |
119 | ||
120 | return 0; | |
121 | } | |
122 | ||
123 | static int | |
124 | ms_error(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
125 | { | |
126 | const char *para; | |
127 | int hideit = ConfigFileEntry.hide_error_messages; | |
128 | ||
129 | para = (parc > 1 && *parv[1] != '\0') ? parv[1] : "<>"; | |
130 | ||
131 | ilog(L_SERVER, "Received ERROR message from %s: %s", | |
132 | log_client_name(source_p, SHOW_IP), para); | |
133 | ||
134 | if(is_safe_error(para)) | |
135 | hideit = 0; | |
136 | if(hideit == 2) | |
137 | return 0; | |
138 | ||
139 | if(client_p == source_p) | |
140 | { | |
141 | sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : L_ALL, "ERROR :from %s -- %s", | |
142 | client_p->name, para); | |
143 | } | |
144 | else | |
145 | { | |
146 | sendto_realops_snomask(SNO_GENERAL, hideit ? L_ADMIN : L_ALL, "ERROR :from %s via %s -- %s", | |
147 | source_p->name, client_p->name, para); | |
148 | } | |
149 | ||
150 | return 0; | |
151 | } |