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