ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_kline.c
Revision: 3320
Committed: Tue Apr 15 15:58:33 2014 UTC (11 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 13555 byte(s)
Log Message:
- Removed useless header includes

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2014 ircd-hybrid development team
5 *
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 /*! \file m_kline.c
23 * \brief Includes required functions for processing the KLINE/UNKLINE command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "client.h"
30 #include "irc_string.h"
31 #include "ircd.h"
32 #include "conf.h"
33 #include "hostmask.h"
34 #include "numeric.h"
35 #include "log.h"
36 #include "s_misc.h"
37 #include "send.h"
38 #include "hash.h"
39 #include "s_serv.h"
40 #include "parse.h"
41 #include "modules.h"
42 #include "conf_db.h"
43 #include "memory.h"
44
45
46 static void
47 check_kline(struct AddressRec *arec)
48 {
49 dlink_node *ptr = NULL, *ptr_next = NULL;
50
51 DLINK_FOREACH_SAFE(ptr, ptr_next, local_client_list.head)
52 {
53 struct Client *client_p = ptr->data;
54
55 if (IsDead(client_p))
56 continue;
57
58 if (match(arec->username, client_p->username))
59 continue;
60
61 switch (arec->masktype)
62 {
63 case HM_IPV4:
64 if (client_p->localClient->aftype == AF_INET)
65 if (match_ipv4(&client_p->localClient->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
66 conf_try_ban(client_p, arec->conf);
67 break;
68 case HM_IPV6:
69 if (client_p->localClient->aftype == AF_INET6)
70 if (match_ipv6(&client_p->localClient->ip, &arec->Mask.ipa.addr, arec->Mask.ipa.bits))
71 conf_try_ban(client_p, arec->conf);
72 break;
73 default: /* HM_HOST */
74 if (!match(arec->Mask.hostname, client_p->host))
75 conf_try_ban(client_p, arec->conf);
76 break;
77 }
78 }
79 }
80
81 /* apply_tkline()
82 *
83 * inputs -
84 * output - NONE
85 * side effects - tkline as given is placed
86 */
87 static void
88 m_kline_add_kline(struct Client *source_p, struct MaskItem *conf,
89 time_t tkline_time)
90 {
91 if (tkline_time)
92 {
93 conf->until = CurrentTime + tkline_time;
94 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
95 "%s added temporary %d min. K-Line for [%s@%s] [%s]",
96 get_oper_name(source_p), tkline_time/60,
97 conf->user, conf->host,
98 conf->reason);
99 sendto_one_notice(source_p, &me, ":Added temporary %d min. K-Line [%s@%s]",
100 tkline_time/60, conf->user, conf->host);
101 ilog(LOG_TYPE_KLINE, "%s added temporary %d min. K-Line for [%s@%s] [%s]",
102 get_oper_name(source_p), tkline_time/60,
103 conf->user, conf->host, conf->reason);
104 }
105 else
106 {
107 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
108 "%s added K-Line for [%s@%s] [%s]",
109 get_oper_name(source_p),
110 conf->user, conf->host, conf->reason);
111 sendto_one_notice(source_p, &me, ":Added K-Line [%s@%s]",
112 conf->user, conf->host);
113 ilog(LOG_TYPE_KLINE, "%s added K-Line for [%s@%s] [%s]",
114 get_oper_name(source_p), conf->user, conf->host, conf->reason);
115 }
116
117 conf->setat = CurrentTime;
118 SetConfDatabase(conf);
119
120 check_kline(add_conf_by_address(CONF_KLINE, conf));
121 }
122
123 /* static int remove_tkline_match(const char *host, const char *user)
124 * Input: A hostname, a username to unkline.
125 * Output: returns YES on success, NO if no tkline removed.
126 * Side effects: Any matching tklines are removed.
127 */
128 static int
129 remove_kline_match(const char *host, const char *user)
130 {
131 struct irc_ssaddr iphost, *piphost;
132 struct MaskItem *conf;
133 int t = 0;
134 int aftype = 0;
135
136 if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
137 {
138 #ifdef IPV6
139 if (t == HM_IPV6)
140 aftype = AF_INET6;
141 else
142 #endif
143 aftype = AF_INET;
144 piphost = &iphost;
145 }
146 else
147 piphost = NULL;
148
149 if ((conf = find_conf_by_address(host, piphost, CONF_KLINE, aftype, user, NULL, 0)))
150 {
151 if (IsConfDatabase(conf))
152 {
153 delete_one_address_conf(host, conf);
154 return 1;
155 }
156 }
157
158 return 0;
159 }
160
161 /* already_placed_kline()
162 * inputs - user to complain to, username & host to check for
163 * outputs - returns 1 on existing K-line, 0 if doesn't exist
164 * side effects - notifies source_p if the K-line already exists
165 */
166 /*
167 * Note: This currently works if the new K-line is a special case of an
168 * existing K-line, but not the other way round. To do that we would
169 * have to walk the hash and check every existing K-line. -A1kmm.
170 */
171 static int
172 already_placed_kline(struct Client *source_p, const char *luser, const char *lhost, int warn)
173 {
174 const char *reason;
175 struct irc_ssaddr iphost, *piphost;
176 struct MaskItem *conf = NULL;
177 int t = 0;
178 int aftype = 0;
179
180 if ((t = parse_netmask(lhost, &iphost, NULL)) != HM_HOST)
181 {
182 #ifdef IPV6
183 if (t == HM_IPV6)
184 aftype = AF_INET6;
185 else
186 #endif
187 aftype = AF_INET;
188 piphost = &iphost;
189 }
190 else
191 piphost = NULL;
192
193 if ((conf = find_conf_by_address(lhost, piphost, CONF_KLINE, aftype, luser, NULL, 0)))
194 {
195 if (warn)
196 {
197 reason = conf->reason ? conf->reason : CONF_NOREASON;
198 sendto_one_notice(source_p, &me, ":[%s@%s] already K-Lined by [%s@%s] - %s",
199 luser, lhost, conf->user, conf->host, reason);
200 }
201
202 return 1;
203 }
204
205 return 0;
206 }
207
208 /* mo_kline()
209 *
210 * inputs - pointer to server
211 * - pointer to client
212 * - parameter count
213 * - parameter list
214 * output -
215 * side effects - k line is added
216 */
217 static int
218 mo_kline(struct Client *source_p, int parc, char *parv[])
219 {
220 char buffer[IRCD_BUFSIZE];
221 char *reason = NULL;
222 char *user = NULL;
223 char *host = NULL;
224 const char *current_date;
225 char *target_server = NULL;
226 struct MaskItem *conf;
227 time_t tkline_time = 0;
228
229 if (!HasOFlag(source_p, OPER_FLAG_K))
230 {
231 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "kline");
232 return 0;
233 }
234
235 if (parse_aline("KLINE", source_p, parc, parv, AWILD, &user, &host,
236 &tkline_time, &target_server, &reason) < 0)
237 return 0;
238
239 if (target_server != NULL)
240 {
241 sendto_match_servs(source_p, target_server, CAP_KLN, "KLINE %s %lu %s %s :%s",
242 target_server, (unsigned long)tkline_time,
243 user, host, reason);
244
245 /* Allow ON to apply local kline as well if it matches */
246 if (match(target_server, me.name))
247 return 0;
248 }
249 else
250 cluster_a_line(source_p, "KLINE", CAP_KLN, SHARED_KLINE,
251 "%d %s %s :%s", tkline_time, user, host, reason);
252
253 if (already_placed_kline(source_p, user, host, 1))
254 return 0;
255
256 current_date = smalldate(0);
257 conf = conf_make(CONF_KLINE);
258
259 conf->host = xstrdup(host);
260 conf->user = xstrdup(user);
261
262 if (tkline_time != 0)
263 snprintf(buffer, sizeof(buffer), "Temporary K-line %d min. - %s (%s)",
264 (int)(tkline_time/60), reason, current_date);
265 else
266 snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
267
268 conf->reason = xstrdup(buffer);
269 m_kline_add_kline(source_p, conf, tkline_time);
270 return 0;
271 }
272
273 /* me_kline - handle remote kline. no propagation */
274 static int
275 me_kline(struct Client *source_p, int parc, char *parv[])
276 {
277 char buffer[IRCD_BUFSIZE];
278 struct MaskItem *conf = NULL;
279 int tkline_time = 0;
280 const char *current_date;
281 char *kuser, *khost, *kreason;
282
283 if (parc != 6 || EmptyString(parv[5]))
284 return 0;
285
286 if (match(parv[1], me.name))
287 return 0;
288
289 tkline_time = valid_tkline(parv[2], TK_SECONDS);
290 kuser = parv[3];
291 khost = parv[4];
292 kreason = parv[5];
293
294 current_date = smalldate(0);
295
296 if (HasFlag(source_p, FLAGS_SERVICE) ||
297 find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
298 source_p->username, source_p->host,
299 SHARED_KLINE))
300 {
301 if (!IsClient(source_p) ||
302 already_placed_kline(source_p, kuser, khost, 1))
303 return 0;
304
305 conf = conf_make(CONF_KLINE);
306 conf->host = xstrdup(khost);
307 conf->user = xstrdup(kuser);
308
309 if (tkline_time != 0)
310 snprintf(buffer, sizeof(buffer), "Temporary K-line %d min. - %s (%s)",
311 (int)(tkline_time/60), kreason, current_date);
312 else
313 snprintf(buffer, sizeof(buffer), "%s (%s)", kreason, current_date);
314
315 conf->reason = xstrdup(buffer);
316 m_kline_add_kline(source_p, conf, tkline_time);
317 }
318
319 return 0;
320 }
321
322 static int
323 ms_kline(struct Client *source_p, int parc, char *parv[])
324 {
325 if (parc != 6 || EmptyString(parv[5]))
326 return 0;
327
328 /* parv[0] parv[1] parv[2] parv[3] parv[4] parv[5] */
329 /* oper target_server tkline_time user host reason */
330 sendto_match_servs(source_p, parv[1], CAP_KLN, "KLINE %s %s %s %s :%s",
331 parv[1], parv[2], parv[3], parv[4], parv[5]);
332
333 return me_kline(source_p, parc, parv);
334 }
335
336 /*
337 ** mo_unkline
338 ** Added Aug 31, 1997
339 ** common (Keith Fralick) fralick@gate.net
340 **
341 ** parv[0] = command
342 ** parv[1] = address to remove
343 *
344 *
345 */
346 static int
347 mo_unkline(struct Client *source_p, int parc, char *parv[])
348 {
349 char *target_server = NULL;
350 char *user, *host;
351
352 if (!HasOFlag(source_p, OPER_FLAG_UNKLINE))
353 {
354 sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "unkline");
355 return 0;
356 }
357
358 if (EmptyString(parv[1]))
359 {
360 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "UNKLINE");
361 return 0;
362 }
363
364 if (parse_aline("UNKLINE", source_p, parc, parv, 0, &user,
365 &host, NULL, &target_server, NULL) < 0)
366 return 0;
367
368 if (target_server != NULL)
369 {
370 sendto_match_servs(source_p, target_server, CAP_UNKLN,
371 "UNKLINE %s %s %s",
372 target_server, user, host);
373
374 /* Allow ON to apply local unkline as well if it matches */
375 if (match(target_server, me.name))
376 return 0;
377 }
378 else
379 cluster_a_line(source_p, "UNKLINE", CAP_UNKLN, SHARED_UNKLINE,
380 "%s %s", user, host);
381
382 if (remove_kline_match(host, user))
383 {
384 sendto_one_notice(source_p, &me, ":K-Line for [%s@%s] is removed",
385 user, host);
386 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
387 "%s has removed the K-Line for: [%s@%s]",
388 get_oper_name(source_p), user, host);
389 ilog(LOG_TYPE_KLINE, "%s removed K-Line for [%s@%s]",
390 get_oper_name(source_p), user, host);
391 }
392 else
393 sendto_one_notice(source_p, &me, ":No K-Line for [%s@%s] found",
394 user, host);
395 return 0;
396 }
397
398 /* me_unkline()
399 *
400 * inputs - server
401 * - client
402 * - parc
403 * - parv
404 * outputs - none
405 * side effects - if server is authorized, kline is removed
406 * does not propagate message
407 */
408 static int
409 me_unkline(struct Client *source_p, int parc, char *parv[])
410 {
411 const char *kuser, *khost;
412
413 if (parc != 4)
414 return 0;
415
416 kuser = parv[2];
417 khost = parv[3];
418
419 if (!IsClient(source_p) || match(parv[1], me.name))
420 return 0;
421
422 if (HasFlag(source_p, FLAGS_SERVICE) ||
423 find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
424 source_p->username, source_p->host,
425 SHARED_UNKLINE))
426 {
427 if (remove_kline_match(khost, kuser))
428 {
429 sendto_one_notice(source_p, &me, ":K-Line for [%s@%s] is removed",
430 kuser, khost);
431 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
432 "%s has removed the K-Line for: [%s@%s]",
433 get_oper_name(source_p), kuser, khost);
434 ilog(LOG_TYPE_KLINE, "%s removed K-Line for [%s@%s]",
435 get_oper_name(source_p), kuser, khost);
436 }
437 else
438 sendto_one_notice(source_p, &me, ":No K-Line for [%s@%s] found",
439 kuser, khost);
440 }
441
442 return 0;
443 }
444
445 /* ms_unkline - propagates and handles a remote unkline message */
446 static int
447 ms_unkline(struct Client *source_p, int parc, char *parv[])
448 {
449 if (parc != 4)
450 return 0;
451
452 sendto_match_servs(source_p, parv[1], CAP_UNKLN,
453 "UNKLINE %s %s %s",
454 parv[1], parv[2], parv[3]);
455
456 return me_unkline(source_p, parc, parv);
457 }
458
459 static struct Message kline_msgtab =
460 {
461 "KLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
462 { m_unregistered, m_not_oper, ms_kline, me_kline, mo_kline, m_ignore }
463 };
464
465 static struct Message unkline_msgtab =
466 {
467 "UNKLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
468 { m_unregistered, m_not_oper, ms_unkline, me_unkline, mo_unkline, m_ignore }
469 };
470
471 static void
472 module_init(void)
473 {
474 mod_add_cmd(&kline_msgtab);
475 mod_add_cmd(&unkline_msgtab);
476 add_capability("KLN", CAP_KLN, 1);
477 add_capability("UNKLN", CAP_UNKLN, 1);
478 }
479
480 static void
481 module_exit(void)
482 {
483 mod_del_cmd(&kline_msgtab);
484 mod_del_cmd(&unkline_msgtab);
485 delete_capability("UNKLN");
486 delete_capability("KLN");
487 }
488
489 struct module module_entry =
490 {
491 .node = { NULL, NULL, NULL },
492 .name = NULL,
493 .version = "$Revision$",
494 .handle = NULL,
495 .modinit = module_init,
496 .modexit = module_exit,
497 .flags = 0
498 };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision