]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_dline.c
Allow /ojoin !#channel/%#channel, if admin/halfop are enabled.
[irc/rqf/shadowircd.git] / modules / m_dline.c
CommitLineData
212380e3 1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_dline.c: Bans/unbans a user.
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 *
d8a4c5f6 24 * $Id$
212380e3 25 */
26
27#include "stdinc.h"
212380e3 28#include "channel.h"
29#include "class.h"
30#include "client.h"
31#include "common.h"
13ae2f4b 32#include "match.h"
212380e3 33#include "ircd.h"
34#include "hostmask.h"
35#include "numeric.h"
212380e3 36#include "s_conf.h"
37#include "s_newconf.h"
d3455e2c 38#include "logger.h"
212380e3 39#include "send.h"
40#include "hash.h"
41#include "s_serv.h"
42#include "msg.h"
43#include "parse.h"
44#include "modules.h"
d8a4c5f6 45#include "bandbi.h"
a0f4c418 46#include "operhash.h"
212380e3 47
48static int mo_dline(struct Client *, struct Client *, int, const char **);
45be325c 49static int me_dline(struct Client *, struct Client *, int, const char **);
212380e3 50static int mo_undline(struct Client *, struct Client *, int, const char **);
45be325c 51static int me_undline(struct Client *, struct Client *, int, const char **);
212380e3 52
53struct Message dline_msgtab = {
54 "DLINE", 0, 0, 0, MFLG_SLOW,
45be325c 55 {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_dline, 3}, {mo_dline, 2}}
212380e3 56};
d8a4c5f6 57
212380e3 58struct Message undline_msgtab = {
59 "UNDLINE", 0, 0, 0, MFLG_SLOW,
45be325c 60 {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_undline, 1}, {mo_undline, 2}}
212380e3 61};
62
63mapi_clist_av1 dline_clist[] = { &dline_msgtab, &undline_msgtab, NULL };
d8a4c5f6
WP
64
65DECLARE_MODULE_AV1(dline, NULL, NULL, dline_clist, NULL, NULL, "$Revision$");
212380e3 66
67static int valid_comment(char *comment);
6f3a09ff 68static int remove_temp_dline(struct ConfItem *);
e26306d3 69static int apply_dline(struct Client *, const char *, int, char *);
45be325c 70static int apply_undline(struct Client *, const char *);
212380e3 71
72/* mo_dline()
73 *
74 * parv[1] - dline to add
75 * parv[2] - reason
76 */
77static int
d8a4c5f6 78mo_dline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3 79{
80 char def[] = "No Reason";
81 const char *dlhost;
212380e3 82 char *reason = def;
212380e3 83 char cidr_form_host[HOSTLEN + 1];
212380e3 84 int tdline_time = 0;
45be325c 85 const char *target_server = NULL;
212380e3 86 int loc = 1;
87
88 if(!IsOperK(source_p))
89 {
d8a4c5f6 90 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "kline");
212380e3 91 return 0;
92 }
93
94 if((tdline_time = valid_temp_time(parv[loc])) >= 0)
95 loc++;
96
212380e3 97 dlhost = parv[loc];
907468c4 98 rb_strlcpy(cidr_form_host, dlhost, sizeof(cidr_form_host));
212380e3 99
45be325c
VY
100 loc++;
101
d8a4c5f6
WP
102 if(parc >= loc + 2 && !irccmp(parv[loc], "ON"))
103 {
a66dbced
JT
104 if(!IsOperRemoteBan(source_p))
105 {
106 sendto_one(source_p, form_str(ERR_NOPRIVS),
d8a4c5f6 107 me.name, source_p->name, "remoteban");
a66dbced
JT
108 return 0;
109 }
110
d8a4c5f6 111 target_server = parv[loc + 1];
45be325c
VY
112 loc += 2;
113 }
114
115 if(parc >= loc + 1 && !EmptyString(parv[loc]))
116 reason = LOCAL_COPY(parv[loc]);
117
118 if(target_server != NULL)
212380e3 119 {
45be325c 120 sendto_match_servs(source_p, target_server,
d8a4c5f6
WP
121 CAP_ENCAP, NOCAPS,
122 "ENCAP %s DLINE %d %s :%s",
123 target_server, tdline_time, dlhost, reason);
45be325c
VY
124
125 if(!match(target_server, me.name))
126 return 0;
212380e3 127 }
128
45be325c
VY
129 apply_dline(source_p, dlhost, tdline_time, reason);
130
131 check_dlines();
132 return 0;
133}
212380e3 134
45be325c
VY
135/* mo_undline()
136 *
137 * parv[1] = dline to remove
138 */
139static int
140mo_undline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
141{
142 const char *cidr;
143 const char *target_server = NULL;
144
145 if(!IsOperK(source_p))
146 {
d8a4c5f6
WP
147 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "unkline");
148 return 0;
149 }
150
45be325c
VY
151 cidr = parv[1];
152
153 if(parc >= 4 && !irccmp(parv[2], "ON"))
212380e3 154 {
a66dbced
JT
155 if(!IsOperRemoteBan(source_p))
156 {
157 sendto_one(source_p, form_str(ERR_NOPRIVS),
d8a4c5f6 158 me.name, source_p->name, "remoteban");
a66dbced
JT
159 return 0;
160 }
161
45be325c
VY
162 target_server = parv[3];
163 sendto_match_servs(source_p, target_server,
d8a4c5f6 164 CAP_ENCAP, NOCAPS, "ENCAP %s UNDLINE %s", target_server, cidr);
212380e3 165
45be325c 166 if(!match(target_server, me.name))
212380e3 167 return 0;
212380e3 168 }
169
45be325c
VY
170 apply_undline(source_p, cidr);
171
172 return 0;
173}
174
e26306d3
JT
175static int
176me_dline(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
177{
178 int tdline_time = atoi(parv[1]);
179 /* Since this is coming over a server link, assume that the originating
180 * server did the relevant permission/sanity checks...
181 */
182
183 if(!IsPerson(source_p))
184 return 0;
185
186 if(!find_shared_conf(source_p->username, source_p->host,
d8a4c5f6
WP
187 source_p->servptr->name,
188 tdline_time > 0 ? SHARED_TDLINE : SHARED_PDLINE))
e26306d3 189 return 0;
e26306d3
JT
190
191 apply_dline(source_p, parv[2], tdline_time, LOCAL_COPY(parv[3]));
192
193 check_dlines();
194 return 0;
195}
196
197static int
198me_undline(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
199{
200 if(!IsPerson(source_p))
201 return 0;
202
203 if(!find_shared_conf(source_p->username, source_p->host,
d8a4c5f6 204 source_p->servptr->name, SHARED_UNDLINE))
e26306d3
JT
205 return 0;
206
207 apply_undline(source_p, parv[1]);
208
209 return 0;
45be325c
VY
210}
211
212static int
213apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *reason)
214{
215 struct ConfItem *aconf;
216 char *oper_reason;
45be325c
VY
217 struct rb_sockaddr_storage daddr;
218 int t = AF_INET, ty, b;
219 const char *creason;
220
d8a4c5f6 221 ty = parse_netmask(dlhost, (struct sockaddr *) &daddr, &b);
45be325c
VY
222 if(ty == HM_HOST)
223 {
d8a4c5f6 224 sendto_one(source_p, ":%s NOTICE %s :Invalid D-Line", me.name, source_p->name);
45be325c
VY
225 return 0;
226 }
227#ifdef RB_IPV6
228 if(ty == HM_IPV6)
229 t = AF_INET6;
230 else
231#endif
232 t = AF_INET;
233
234 /* This means dlines wider than /16 cannot be set remotely */
212380e3 235 if(IsOperAdmin(source_p))
236 {
45be325c 237 if(b < 8)
212380e3 238 {
45be325c 239 sendto_one_notice(source_p,
d8a4c5f6 240 ":For safety, bitmasks less than 8 require conf access.");
212380e3 241 return 0;
242 }
243 }
244 else
245 {
45be325c 246 if(b < 16)
212380e3 247 {
45be325c 248 sendto_one_notice(source_p,
d8a4c5f6 249 ":Dline bitmasks less than 16 are for admins only.");
212380e3 250 return 0;
251 }
252 }
253
45be325c
VY
254 if(!valid_comment(reason))
255 {
256 sendto_one(source_p,
257 ":%s NOTICE %s :Invalid character '\"' in comment",
258 me.name, source_p->name);
259 return 0;
260 }
261
21c9d815
VY
262 if(ConfigFileEntry.non_redundant_klines)
263 {
d8a4c5f6 264 if((aconf = find_dline((struct sockaddr *) &daddr, t)) != NULL)
21c9d815
VY
265 {
266 int bx;
267 parse_netmask(aconf->host, NULL, &bx);
268 if(b >= bx)
269 {
270 creason = aconf->passwd ? aconf->passwd : "<No Reason>";
271 if(IsConfExemptKline(aconf))
272 sendto_one(source_p,
273 ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
d8a4c5f6
WP
274 me.name, source_p->name, dlhost, aconf->host,
275 creason);
21c9d815
VY
276 else
277 sendto_one(source_p,
278 ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
d8a4c5f6
WP
279 me.name, source_p->name, dlhost, aconf->host,
280 creason);
21c9d815
VY
281 return 0;
282 }
283 }
212380e3 284 }
285
4362b282 286 rb_set_time();
212380e3 287
288 aconf = make_conf();
289 aconf->status = CONF_DLINE;
ce60772d 290 aconf->created = rb_current_time();
62d28946 291 aconf->host = rb_strdup(dlhost);
157c1f04 292 aconf->passwd = rb_strdup(reason);
a0f4c418 293 aconf->info.oper = operhash_add(get_oper_name(source_p));
212380e3 294
1bf48553
VY
295 /* Look for an oper reason */
296 if((oper_reason = strchr(reason, '|')) != NULL)
297 {
298 *oper_reason = '\0';
299 oper_reason++;
300
301 if(!EmptyString(oper_reason))
302 aconf->spasswd = rb_strdup(oper_reason);
303 }
304
212380e3 305 if(tdline_time > 0)
306 {
9f6bbe3c 307 aconf->hold = rb_current_time() + tdline_time;
212380e3 308 add_temp_dline(aconf);
309
310 if(EmptyString(oper_reason))
311 {
931e8bc4 312 sendto_realops_snomask(SNO_GENERAL, L_ALL,
d8a4c5f6
WP
313 "%s added temporary %d min. D-Line for [%s] [%s]",
314 get_oper_name(source_p), tdline_time / 60,
315 aconf->host, reason);
212380e3 316 ilog(L_KLINE, "D %s %d %s %s",
d8a4c5f6 317 get_oper_name(source_p), tdline_time / 60, aconf->host, reason);
212380e3 318 }
319 else
320 {
931e8bc4 321 sendto_realops_snomask(SNO_GENERAL, L_ALL,
d8a4c5f6
WP
322 "%s added temporary %d min. D-Line for [%s] [%s|%s]",
323 get_oper_name(source_p), tdline_time / 60,
324 aconf->host, reason, oper_reason);
212380e3 325 ilog(L_KLINE, "D %s %d %s %s|%s",
d8a4c5f6
WP
326 get_oper_name(source_p), tdline_time / 60,
327 aconf->host, reason, oper_reason);
212380e3 328 }
329
330 sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line for [%s]",
331 me.name, source_p->name, tdline_time / 60, aconf->host);
332 }
333 else
334 {
969a1ae6 335 add_conf_by_address(aconf->host, CONF_DLINE, NULL, NULL, aconf);
d8a4c5f6
WP
336
337 bandb_add(BANDB_DLINE, source_p, aconf->host, NULL,
338 reason, EmptyString(aconf->spasswd) ? NULL : aconf->spasswd, 0);
d63447bf
WP
339
340 if(EmptyString(oper_reason))
341 {
342 sendto_realops_snomask(SNO_GENERAL, L_ALL,
343 "%s added D-Line for [%s] [%s]",
344 get_oper_name(source_p), aconf->host, reason);
345 ilog(L_KLINE, "D %s 0 %s %s",
346 get_oper_name(source_p), aconf->host, reason);
347 }
348 else
349 {
350 sendto_realops_snomask(SNO_GENERAL, L_ALL,
351 "%s added D-Line for [%s] [%s|%s]",
352 get_oper_name(source_p), aconf->host, reason, oper_reason);
353 ilog(L_KLINE, "D %s 0 %s %s|%s",
354 get_oper_name(source_p),
355 aconf->host, reason, oper_reason);
356 }
212380e3 357 }
358
212380e3 359 return 0;
360}
361
212380e3 362static int
45be325c 363apply_undline(struct Client *source_p, const char *cidr)
212380e3 364{
d8a4c5f6 365 char buf[BUFSIZE];
45be325c 366 struct ConfItem *aconf;
212380e3 367
368 if(parse_netmask(cidr, NULL, NULL) == HM_HOST)
369 {
5366977b 370 sendto_one_notice(source_p, ":Invalid D-Line");
212380e3 371 return 0;
372 }
373
6f3a09ff
JT
374 aconf = find_exact_conf_by_address(cidr, CONF_DLINE, NULL);
375 if(aconf == NULL)
376 {
377 sendto_one_notice(source_p, ":No D-Line for %s", cidr);
378 return 0;
379 }
380
907468c4 381 rb_strlcpy(buf, aconf->host, sizeof buf);
6f3a09ff 382 if(remove_temp_dline(aconf))
212380e3 383 {
384 sendto_one(source_p,
385 ":%s NOTICE %s :Un-dlined [%s] from temporary D-lines",
45be325c 386 me.name, source_p->name, buf);
212380e3 387 sendto_realops_snomask(SNO_GENERAL, L_ALL,
d8a4c5f6
WP
388 "%s has removed the temporary D-Line for: [%s]",
389 get_oper_name(source_p), buf);
6f3a09ff 390 ilog(L_KLINE, "UD %s %s", get_oper_name(source_p), buf);
212380e3 391 return 0;
392 }
393
d8a4c5f6 394 bandb_del(BANDB_DLINE, aconf->host, NULL);
212380e3 395
d8a4c5f6
WP
396 sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed", me.name, source_p->name,
397 aconf->host);
398 sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s has removed the D-Line for: [%s]",
399 get_oper_name(source_p), aconf->host);
47819d98
JT
400 ilog(L_KLINE, "UD %s %s", get_oper_name(source_p), aconf->host);
401 delete_one_address_conf(aconf->host, aconf);
212380e3 402
403 return 0;
404}
405
406/*
407 * valid_comment
408 * inputs - pointer to client
409 * - pointer to comment
410 * output - 0 if no valid comment, 1 if valid
411 * side effects - NONE
412 */
413static int
414valid_comment(char *comment)
415{
416 if(strchr(comment, '"'))
417 return 0;
418
61569b65 419 if(strlen(comment) > BANREASONLEN)
420 comment[BANREASONLEN] = '\0';
212380e3 421
422 return 1;
423}
424
212380e3 425/* remove_temp_dline()
426 *
6f3a09ff 427 * inputs - confitem to undline
212380e3 428 * outputs -
429 * side effects - tries to undline anything that matches
430 */
431static int
6f3a09ff 432remove_temp_dline(struct ConfItem *aconf)
212380e3 433{
08d11e34 434 rb_dlink_node *ptr;
212380e3 435 int i;
436
d8a4c5f6 437 for(i = 0; i < LAST_TEMP_TYPE; i++)
212380e3 438 {
08d11e34 439 RB_DLINK_FOREACH(ptr, temp_dlines[i].head)
212380e3 440 {
d8a4c5f6 441 if(aconf == ptr->data)
212380e3 442 {
9f6c3353 443 rb_dlinkDestroy(ptr, &temp_dlines[i]);
212380e3 444 delete_one_address_conf(aconf->host, aconf);
445 return YES;
446 }
447 }
448 }
449
450 return NO;
451}