ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_kline.c
Revision: 2813
Committed: Sun Jan 12 20:23:50 2014 UTC (11 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 14328 byte(s)
Log Message:
- Renamed ban_them() to conf_try_ban()
- conf_try_ban() removed exemption notices that are now redundant

File Contents

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

Properties

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