1 |
adx |
30 |
/* |
2 |
michael |
2820 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
adx |
30 |
* |
4 |
michael |
2820 |
* Copyright (c) 2003-2014 ircd-hybrid development team |
5 |
adx |
30 |
* |
6 |
|
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
|
* it under the terms of the GNU General Public License as published by |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 |
|
|
* USA |
20 |
|
|
*/ |
21 |
|
|
|
22 |
michael |
2820 |
/*! \file m_xline.c |
23 |
michael |
3352 |
* \brief Includes required functions for processing the XLINE command. |
24 |
michael |
2820 |
* \version $Id$ |
25 |
|
|
*/ |
26 |
|
|
|
27 |
adx |
30 |
#include "stdinc.h" |
28 |
michael |
1011 |
#include "list.h" |
29 |
adx |
30 |
#include "client.h" |
30 |
|
|
#include "irc_string.h" |
31 |
|
|
#include "ircd.h" |
32 |
michael |
1632 |
#include "conf.h" |
33 |
adx |
30 |
#include "numeric.h" |
34 |
michael |
1309 |
#include "log.h" |
35 |
adx |
30 |
#include "send.h" |
36 |
michael |
3347 |
#include "server.h" |
37 |
adx |
30 |
#include "parse.h" |
38 |
|
|
#include "modules.h" |
39 |
michael |
1622 |
#include "conf_db.h" |
40 |
michael |
1666 |
#include "memory.h" |
41 |
adx |
30 |
|
42 |
|
|
|
43 |
michael |
2877 |
static void |
44 |
|
|
check_xline(struct MaskItem *conf) |
45 |
|
|
{ |
46 |
|
|
dlink_node *ptr = NULL, *ptr_next = NULL; |
47 |
|
|
|
48 |
|
|
DLINK_FOREACH_SAFE(ptr, ptr_next, local_client_list.head) |
49 |
|
|
{ |
50 |
|
|
struct Client *client_p = ptr->data; |
51 |
|
|
|
52 |
|
|
if (IsDead(client_p)) |
53 |
|
|
continue; |
54 |
|
|
|
55 |
|
|
if (!match(conf->name, client_p->username)) |
56 |
|
|
conf_try_ban(client_p, conf); |
57 |
|
|
} |
58 |
|
|
} |
59 |
|
|
|
60 |
michael |
2974 |
/* valid_xline() |
61 |
|
|
* |
62 |
|
|
* inputs - client to complain to, gecos, reason, whether to complain |
63 |
|
|
* outputs - 1 for valid, else 0 |
64 |
|
|
* side effects - complains to client, when warn != 0 |
65 |
|
|
*/ |
66 |
|
|
static int |
67 |
|
|
valid_xline(struct Client *source_p, const char *gecos, const char *reason, int warn) |
68 |
|
|
{ |
69 |
|
|
if (EmptyString(reason)) |
70 |
|
|
{ |
71 |
|
|
if (warn) |
72 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "XLINE"); |
73 |
michael |
2974 |
return 0; |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
if (!valid_wild_card_simple(gecos)) |
77 |
|
|
{ |
78 |
|
|
if (warn) |
79 |
michael |
4058 |
sendto_one_notice(source_p, &me, ":Please include at least %u non-wildcard characters with the xline", |
80 |
michael |
3110 |
ConfigFileEntry.min_nonwildcard_simple); |
81 |
michael |
2974 |
|
82 |
|
|
return 0; |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
return 1; |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
/* write_xline() |
89 |
|
|
* |
90 |
|
|
* inputs - client taking credit for xline, gecos, reason, xline type |
91 |
|
|
* outputs - none |
92 |
|
|
* side effects - when successful, adds an xline to the conf |
93 |
|
|
*/ |
94 |
|
|
static void |
95 |
|
|
write_xline(struct Client *source_p, char *gecos, char *reason, |
96 |
|
|
time_t tkline_time) |
97 |
|
|
{ |
98 |
|
|
struct MaskItem *conf = conf_make(CONF_XLINE); |
99 |
|
|
|
100 |
|
|
conf->name = xstrdup(gecos); |
101 |
|
|
conf->reason = xstrdup(reason); |
102 |
|
|
conf->setat = CurrentTime; |
103 |
|
|
|
104 |
|
|
SetConfDatabase(conf); |
105 |
|
|
|
106 |
michael |
3368 |
if (tkline_time) |
107 |
michael |
2974 |
{ |
108 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
109 |
|
|
"%s added temporary %d min. X-Line for [%s] [%s]", |
110 |
|
|
get_oper_name(source_p), (int)tkline_time/60, |
111 |
|
|
conf->name, conf->reason); |
112 |
michael |
3110 |
sendto_one_notice(source_p, &me, ":Added temporary %d min. X-Line [%s]", |
113 |
|
|
(int)tkline_time/60, conf->name); |
114 |
michael |
2974 |
ilog(LOG_TYPE_XLINE, "%s added temporary %d min. X-Line for [%s] [%s]", |
115 |
|
|
source_p->name, (int)tkline_time/60, conf->name, conf->reason); |
116 |
|
|
conf->until = CurrentTime + tkline_time; |
117 |
|
|
} |
118 |
|
|
else |
119 |
|
|
{ |
120 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
121 |
|
|
"%s added X-Line for [%s] [%s]", |
122 |
|
|
get_oper_name(source_p), conf->name, |
123 |
|
|
conf->reason); |
124 |
michael |
3110 |
sendto_one_notice(source_p, &me, ":Added X-Line [%s] [%s]", |
125 |
|
|
conf->name, conf->reason); |
126 |
michael |
2974 |
ilog(LOG_TYPE_XLINE, "%s added X-Line for [%s] [%s]", |
127 |
|
|
get_oper_name(source_p), conf->name, conf->reason); |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
check_xline(conf); |
131 |
|
|
} |
132 |
|
|
|
133 |
|
|
static void |
134 |
|
|
relay_xline(struct Client *source_p, char *parv[]) |
135 |
|
|
{ |
136 |
|
|
struct MaskItem *conf = NULL; |
137 |
|
|
int t_sec; |
138 |
|
|
|
139 |
|
|
t_sec = atoi(parv[3]); |
140 |
|
|
|
141 |
|
|
sendto_match_servs(source_p, parv[1], CAP_CLUSTER, |
142 |
|
|
"XLINE %s %s %s :%s", |
143 |
|
|
parv[1], parv[2], parv[3], parv[4]); |
144 |
|
|
|
145 |
|
|
if (match(parv[1], me.name)) |
146 |
|
|
return; |
147 |
|
|
|
148 |
|
|
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name, |
149 |
|
|
source_p->username, source_p->host, |
150 |
|
|
SHARED_XLINE)) |
151 |
|
|
{ |
152 |
|
|
if ((conf = find_matching_name_conf(CONF_XLINE, parv[2], NULL, NULL, 0))) |
153 |
|
|
{ |
154 |
michael |
3110 |
sendto_one_notice(source_p, &me, ":[%s] already X-Lined by [%s] - %s", |
155 |
|
|
parv[2], conf->name, conf->reason); |
156 |
michael |
2974 |
return; |
157 |
|
|
} |
158 |
|
|
|
159 |
|
|
write_xline(source_p, parv[2], parv[4], t_sec); |
160 |
|
|
} |
161 |
|
|
} |
162 |
|
|
|
163 |
adx |
30 |
/* mo_xline() |
164 |
|
|
* |
165 |
|
|
* inputs - pointer to server |
166 |
|
|
* - pointer to client |
167 |
|
|
* - parameter count |
168 |
|
|
* - parameter list |
169 |
|
|
* output - |
170 |
|
|
* side effects - x line is added |
171 |
|
|
* |
172 |
|
|
*/ |
173 |
michael |
2820 |
static int |
174 |
michael |
3156 |
mo_xline(struct Client *source_p, int parc, char *parv[]) |
175 |
adx |
30 |
{ |
176 |
|
|
char *reason = NULL; |
177 |
|
|
char *gecos = NULL; |
178 |
michael |
1632 |
struct MaskItem *conf = NULL; |
179 |
adx |
30 |
char *target_server = NULL; |
180 |
|
|
time_t tkline_time = 0; |
181 |
|
|
|
182 |
michael |
2852 |
if (!HasOFlag(source_p, OPER_FLAG_XLINE)) |
183 |
adx |
30 |
{ |
184 |
michael |
3109 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "xline"); |
185 |
michael |
2820 |
return 0; |
186 |
adx |
30 |
} |
187 |
|
|
|
188 |
|
|
/* |
189 |
|
|
* XLINE <gecos> <time> ON <mask> :<reason> |
190 |
|
|
* XLINE <gecos> ON <mask> :<reason> |
191 |
|
|
*/ |
192 |
|
|
if (parse_aline("XLINE", source_p, parc, parv, AWILD, &gecos, NULL, |
193 |
|
|
&tkline_time, &target_server, &reason) < 0) |
194 |
michael |
2820 |
return 0; |
195 |
adx |
30 |
|
196 |
michael |
3368 |
if (target_server) |
197 |
adx |
30 |
{ |
198 |
|
|
/* if a given expire time is given, ENCAP it */ |
199 |
michael |
3368 |
if (tkline_time) |
200 |
adx |
30 |
sendto_match_servs(source_p, target_server, CAP_ENCAP, |
201 |
michael |
2820 |
"ENCAP %s XLINE %d %s 0 :%s", |
202 |
|
|
target_server, (int)tkline_time, gecos, reason); |
203 |
adx |
30 |
else |
204 |
|
|
sendto_match_servs(source_p, target_server, CAP_CLUSTER, |
205 |
michael |
2820 |
"XLINE %s %s %d :%s", |
206 |
|
|
target_server, gecos, (int)tkline_time, reason); |
207 |
adx |
30 |
|
208 |
|
|
/* Allow ON to apply local xline as well if it matches */ |
209 |
michael |
1652 |
if (match(target_server, me.name)) |
210 |
michael |
2820 |
return 0; |
211 |
adx |
30 |
} |
212 |
michael |
2820 |
else |
213 |
adx |
30 |
{ |
214 |
michael |
3368 |
if (tkline_time) |
215 |
adx |
30 |
cluster_a_line(source_p, "ENCAP", CAP_ENCAP, SHARED_XLINE, |
216 |
michael |
2820 |
"XLINE %d %s 0 :%s", (int)tkline_time, gecos, reason); |
217 |
adx |
30 |
else |
218 |
|
|
cluster_a_line(source_p, "XLINE", CAP_KLN, SHARED_XLINE, |
219 |
michael |
2820 |
"%s 0 :%s", gecos, reason); |
220 |
adx |
30 |
} |
221 |
|
|
|
222 |
|
|
if (!valid_xline(source_p, gecos, reason, 0)) |
223 |
michael |
2820 |
return 0; |
224 |
adx |
30 |
|
225 |
michael |
2820 |
if ((conf = find_matching_name_conf(CONF_XLINE, gecos, NULL, NULL, 0))) |
226 |
adx |
30 |
{ |
227 |
michael |
3110 |
sendto_one_notice(source_p, &me, ":[%s] already X-Lined by [%s] - %s", |
228 |
|
|
gecos, conf->name, conf->reason); |
229 |
michael |
2820 |
return 0; |
230 |
adx |
30 |
} |
231 |
|
|
|
232 |
|
|
write_xline(source_p, gecos, reason, tkline_time); |
233 |
michael |
2820 |
return 0; |
234 |
adx |
30 |
} |
235 |
|
|
|
236 |
|
|
/* ms_xline() |
237 |
|
|
* |
238 |
|
|
* inputs - oper, target server, xline, {type}, reason |
239 |
|
|
* |
240 |
|
|
* outputs - none |
241 |
|
|
* side effects - propagates xline, applies it if we are a target |
242 |
|
|
*/ |
243 |
michael |
2820 |
static int |
244 |
michael |
3156 |
ms_xline(struct Client *source_p, int parc, char *parv[]) |
245 |
adx |
30 |
{ |
246 |
|
|
if (parc != 5 || EmptyString(parv[4])) |
247 |
michael |
2820 |
return 0; |
248 |
adx |
30 |
|
249 |
|
|
if (!IsClient(source_p)) |
250 |
michael |
2820 |
return 0; |
251 |
adx |
30 |
|
252 |
|
|
if (!valid_xline(source_p, parv[2], parv[4], 0)) |
253 |
michael |
2820 |
return 0; |
254 |
adx |
30 |
|
255 |
|
|
relay_xline(source_p, parv); |
256 |
michael |
2820 |
return 0; |
257 |
adx |
30 |
} |
258 |
|
|
|
259 |
|
|
/* me_xline() |
260 |
|
|
* |
261 |
|
|
* inputs - server |
262 |
|
|
* - client (oper) |
263 |
|
|
* - parc number of arguments |
264 |
|
|
* - parv list of arguments |
265 |
|
|
* via parv[] |
266 |
michael |
2828 |
* parv[1] = target server |
267 |
|
|
* parv[2] = xline |
268 |
|
|
* parv[3] = time |
269 |
|
|
* parv[4] = reason |
270 |
adx |
30 |
* |
271 |
|
|
* outputs - none |
272 |
michael |
2820 |
* side effects - |
273 |
adx |
30 |
*/ |
274 |
michael |
2820 |
static int |
275 |
michael |
3156 |
me_xline(struct Client *source_p, int parc, char *parv[]) |
276 |
adx |
30 |
{ |
277 |
|
|
if (!IsClient(source_p) || parc != 5) |
278 |
michael |
2820 |
return 0; |
279 |
adx |
30 |
|
280 |
|
|
relay_xline(source_p, parv); |
281 |
michael |
2820 |
return 0; |
282 |
adx |
30 |
} |
283 |
|
|
|
284 |
michael |
2820 |
static struct Message xline_msgtab = |
285 |
|
|
{ |
286 |
michael |
1230 |
"XLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
287 |
|
|
{ m_unregistered, m_not_oper, ms_xline, me_xline, mo_xline, m_ignore } |
288 |
|
|
}; |
289 |
|
|
|
290 |
|
|
static void |
291 |
|
|
module_init(void) |
292 |
|
|
{ |
293 |
|
|
mod_add_cmd(&xline_msgtab); |
294 |
|
|
} |
295 |
|
|
|
296 |
|
|
static void |
297 |
|
|
module_exit(void) |
298 |
|
|
{ |
299 |
|
|
mod_del_cmd(&xline_msgtab); |
300 |
|
|
} |
301 |
|
|
|
302 |
michael |
2820 |
struct module module_entry = |
303 |
|
|
{ |
304 |
michael |
1230 |
.node = { NULL, NULL, NULL }, |
305 |
|
|
.name = NULL, |
306 |
|
|
.version = "$Revision$", |
307 |
|
|
.handle = NULL, |
308 |
|
|
.modinit = module_init, |
309 |
|
|
.modexit = module_exit, |
310 |
|
|
.flags = 0 |
311 |
|
|
}; |