ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_dline.c
(Generate patch)

Comparing ircd-hybrid/trunk/modules/m_dline.c (file contents):
Revision 1618 by michael, Tue Oct 30 21:04:38 2012 UTC vs.
Revision 2810 by michael, Sun Jan 12 18:30:44 2014 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  m_dline.c: Bans a user.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 2002-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
# Line 18 | Line 17
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 < *  $Id$
20 > */
21 >
22 > /*! \file m_dline.c
23 > * \brief Includes required functions for processing the DLINE/UNDLINE command.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
# Line 27 | Line 29
29   #include "channel.h"
30   #include "client.h"
31   #include "irc_string.h"
32 < #include "sprintf_irc.h"
32 > #include "conf.h"
33   #include "ircd.h"
34   #include "hostmask.h"
35   #include "numeric.h"
36   #include "fdlist.h"
37   #include "s_bsd.h"
36 #include "conf.h"
38   #include "log.h"
39   #include "s_misc.h"
40   #include "send.h"
41   #include "hash.h"
42   #include "s_serv.h"
42 #include "s_gline.h"
43   #include "parse.h"
44   #include "modules.h"
45 + #include "conf_db.h"
46 + #include "memory.h"
47  
48  
49   /* apply_tdline()
# Line 51 | Line 53
53   * side effects - tkline as given is placed
54   */
55   static void
56 < apply_tdline(struct Client *source_p, struct ConfItem *conf,
57 <             const char *current_date, int tkline_time)
56 > apply_dline(struct Client *source_p, struct MaskItem *conf,
57 >            time_t tkline_time)
58   {
59 <  struct AccessItem *aconf;
59 >  if (tkline_time)
60 >  {
61 >    conf->until = CurrentTime + tkline_time;
62 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
63 >                         "%s added temporary %d min. D-Line for [%s] [%s]",
64 >                         get_oper_name(source_p), tkline_time/60,
65 >                         conf->host, conf->reason);
66 >    sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line [%s]",
67 >               MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
68 >               source_p->name, tkline_time/60, conf->host);
69 >    ilog(LOG_TYPE_DLINE, "%s added temporary %d min. D-Line for [%s] [%s]",
70 >         get_oper_name(source_p), tkline_time/60, conf->host, conf->reason);
71 >  }
72 >  else
73 >  {
74 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
75 >                         "%s added D-Line for [%s] [%s]",
76 >                         get_oper_name(source_p), conf->host, conf->reason);
77 >    sendto_one(source_p, ":%s NOTICE %s :Added D-Line [%s]",
78 >               MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
79 >               source_p->name, conf->host);
80 >    ilog(LOG_TYPE_DLINE, "%s added D-Line for [%s] [%s]",
81 >         get_oper_name(source_p), conf->host, conf->reason);
82  
83 <  aconf = map_to_conf(conf);
60 <  aconf->hold = CurrentTime + tkline_time;
61 <  SetConfTemporary(aconf);
62 <  add_conf_by_address(CONF_DLINE, aconf);
63 <
64 <
65 <  sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
66 <                       "%s added temporary %d min. D-Line for [%s] [%s]",
67 <                       get_oper_name(source_p), tkline_time/60,
68 <                       aconf->host, aconf->reason);
69 <
70 <  sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line [%s]",
71 <             MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
72 <             source_p->name, tkline_time/60, aconf->host);
73 <  ilog(LOG_TYPE_DLINE, "%s added temporary %d min. D-Line for [%s] [%s]",
74 <       source_p->name, tkline_time/60, aconf->host, aconf->reason);
83 >  }
84  
85 +  SetConfDatabase(conf);
86 +  conf->setat = CurrentTime;
87 +  add_conf_by_address(CONF_DLINE, conf);
88    rehashed_klines = 1;
89   }
90  
# Line 82 | Line 94 | apply_tdline(struct Client *source_p, st
94   * Side effects: Any matching tdlines are removed.
95   */
96   static int
97 < remove_tdline_match(const char *host)
97 > remove_dline_match(const char *host)
98   {
99    struct irc_ssaddr iphost, *piphost;
100 <  struct AccessItem *aconf;
101 <  int t;
100 >  struct MaskItem *conf;
101 >  int t = 0;
102 >  int aftype = 0;
103  
104    if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
105    {
106   #ifdef IPV6
107      if (t == HM_IPV6)
108 <      t = AF_INET6;
108 >      aftype = AF_INET6;
109      else
110   #endif
111 <      t = AF_INET;
111 >      aftype = AF_INET;
112      piphost = &iphost;
113    }
114    else
102  {
103    t = 0;
115      piphost = NULL;
105  }
116  
117 <  if ((aconf = find_conf_by_address(host, piphost, CONF_DLINE, t, NULL, NULL, 0)))
117 >  if ((conf = find_conf_by_address(host, piphost, CONF_DLINE | 1, aftype, NULL, NULL, 0)))
118    {
119 <    if (IsConfTemporary(aconf))
119 >    if (IsConfDatabase(conf))
120      {
121 <      delete_one_address_conf(host, aconf);
121 >      delete_one_address_conf(host, conf);
122        return 1;
123      }
124    }
# Line 130 | Line 140 | static void
140   mo_dline(struct Client *client_p, struct Client *source_p,
141           int parc, char *parv[])
142   {
143 <  char def_reason[] = "<No reason specified>";
144 <  char *dlhost = NULL, *oper_reason = NULL, *reason = NULL;
143 >  char def_reason[] = CONF_NOREASON;
144 >  char *dlhost = NULL, *reason = NULL;
145    char *target_server = NULL;
146    const char *creason;
147    const struct Client *target_p = NULL;
148    struct irc_ssaddr daddr;
149 <  struct ConfItem *conf=NULL;
140 <  struct AccessItem *aconf=NULL;
149 >  struct MaskItem *conf=NULL;
150    time_t tkline_time=0;
151 <  int bits, t;
151 >  int bits = 0, aftype = 0, t = 0;
152    const char *current_date = NULL;
153    time_t cur_time;
154    char hostip[HOSTIPLEN + 1];
# Line 147 | Line 156 | mo_dline(struct Client *client_p, struct
156  
157    if (!HasOFlag(source_p, OPER_FLAG_DLINE))
158    {
159 <    sendto_one(source_p, form_str(ERR_NOPRIVS),
160 <               me.name, source_p->name, "dline");
159 >    sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
160 >               source_p->name, "dline");
161      return;
162    }
163  
# Line 158 | Line 167 | mo_dline(struct Client *client_p, struct
167  
168    if (target_server != NULL)
169    {
170 <    if (HasID(source_p))
171 <    {
172 <      sendto_server(NULL, CAP_DLN|CAP_TS6, NOCAPS,
164 <                    ":%s DLINE %s %lu %s :%s",
165 <                    source_p->id, target_server, (unsigned long)tkline_time,
166 <                    dlhost, reason);
167 <      sendto_server(NULL, CAP_DLN, CAP_TS6,
168 <                    ":%s DLINE %s %lu %s :%s",
169 <                    source_p->name, target_server, (unsigned long)tkline_time,
170 <                    dlhost, reason);
171 <    }
172 <    else
173 <      sendto_server(NULL, CAP_DLN, NOCAPS,
174 <                    ":%s DLINE %s %lu %s :%s",
175 <                    source_p->name, target_server, (unsigned long)tkline_time,
176 <                    dlhost, reason);
170 >    sendto_match_servs(source_p, target_server, CAP_DLN, "DLINE %s %lu %s :%s",
171 >                       target_server, (unsigned long)tkline_time,
172 >                       dlhost, reason);
173  
174      /* Allow ON to apply local kline as well if it matches */
175 <    if (!match(target_server, me.name))
175 >    if (match(target_server, me.name))
176        return;
177    }
178    else
# Line 185 | Line 181 | mo_dline(struct Client *client_p, struct
181  
182    if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
183    {
184 <    if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL)
184 >    if ((target_p = find_chasing(source_p, dlhost, NULL)) == NULL)
185        return;
186  
187      if (!MyConnect(target_p))
# Line 198 | Line 194 | mo_dline(struct Client *client_p, struct
194  
195      if (IsExemptKline(target_p))
196      {
197 <      sendto_one(source_p,
198 <                 ":%s NOTICE %s :%s is E-lined", me.name,
203 <                 source_p->name, target_p->name);
197 >      sendto_one(source_p, ":%s NOTICE %s :%s is E-lined",
198 >                 me.name, source_p->name, target_p->name);
199        return;
200      }
201  
# Line 222 | Line 217 | mo_dline(struct Client *client_p, struct
217  
218   #ifdef IPV6
219    if (t == HM_IPV6)
220 <    t = AF_INET6;
220 >    aftype = AF_INET6;
221    else
222   #endif
223 <    t = AF_INET;
223 >    aftype = AF_INET;
224  
225    parse_netmask(dlhost, &daddr, NULL);
226  
227 <  if ((aconf = find_dline_conf(&daddr, t)) != NULL)
227 >  if ((conf = find_dline_conf(&daddr, aftype)) != NULL)
228    {
229 <    creason = aconf->reason ? aconf->reason : def_reason;
230 <    if (IsConfExemptKline(aconf))
231 <      sendto_one(source_p,
232 <                 ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
233 <                 me.name, source_p->name, dlhost, aconf->host, creason);
229 >    creason = conf->reason ? conf->reason : def_reason;
230 >
231 >    if (IsConfExemptKline(conf))
232 >      sendto_one(source_p, ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
233 >                 me.name, source_p->name, dlhost, conf->host, creason);
234      else
235 <      sendto_one(source_p,
236 <                 ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
242 <                 me.name, source_p->name, dlhost, aconf->host, creason);
235 >      sendto_one(source_p, ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
236 >                 me.name, source_p->name, dlhost, conf->host, creason);
237      return;
238    }
239  
240    cur_time = CurrentTime;
241    current_date = smalldate(cur_time);
242  
249  /* Look for an oper reason */
250  if ((oper_reason = strchr(reason, '|')) != NULL)
251    *oper_reason++ = '\0';
252
243    if (!valid_comment(source_p, reason, 1))
244      return;
245  
246 <  conf = make_conf_item(DLINE_TYPE);
247 <  aconf = map_to_conf(conf);
258 <  DupString(aconf->host, dlhost);
246 >  conf = conf_make(CONF_DLINE);
247 >  conf->host = xstrdup(dlhost);
248  
249    if (tkline_time != 0)
261  {
250      snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
251               (int)(tkline_time/60), reason, current_date);
264    DupString(aconf->reason, buffer);
265    if (oper_reason != NULL)
266      DupString(aconf->oper_reason, oper_reason);
267    apply_tdline(source_p, conf, current_date, tkline_time);
268  }
252    else
270  {
253      snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
272    DupString(aconf->reason, buffer);
273    if (oper_reason != NULL)
274      DupString(aconf->oper_reason, oper_reason);
275    add_conf_by_address(CONF_DLINE, aconf);
276    write_conf_line(source_p, conf, current_date, cur_time);
277  }
254  
255 +  conf->reason = xstrdup(buffer);
256 +  apply_dline(source_p, conf, tkline_time);
257    rehashed_klines = 1;
258   }
259  
# Line 283 | Line 261 | static void
261   ms_dline(struct Client *client_p, struct Client *source_p,
262           int parc, char *parv[])
263   {
264 <  char def_reason[] = "<No reason specified>";
265 <  char *dlhost, *oper_reason, *reason;
264 >  char def_reason[] = CONF_NOREASON;
265 >  char *dlhost, *reason;
266    const char *creason;
267    const struct Client *target_p = NULL;
268    struct irc_ssaddr daddr;
269 <  struct ConfItem *conf=NULL;
292 <  struct AccessItem *aconf=NULL;
269 >  struct MaskItem *conf=NULL;
270    time_t tkline_time=0;
271 <  int bits, t;
271 >  int bits = 0, aftype = 0, t = 0;
272    const char *current_date = NULL;
273    time_t cur_time;
274    char hostip[HOSTIPLEN + 1];
# Line 306 | Line 283 | ms_dline(struct Client *client_p, struct
283                       "DLINE %s %s %s :%s",
284                       parv[1], parv[2], parv[3], parv[4]);
285  
286 <  if (!match(parv[1], me.name))
286 >  if (match(parv[1], me.name))
287      return;
288  
289    tkline_time = valid_tkline(parv[2], TK_SECONDS);
290    dlhost = parv[3];
291    reason = parv[4];
292  
293 <  if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(ULINE_TYPE, source_p->servptr->name,
293 >  if (HasFlag(source_p, FLAGS_SERVICE) ||
294 >      find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
295                                source_p->username, source_p->host,
296                                SHARED_DLINE))
297    {
# Line 321 | Line 299 | ms_dline(struct Client *client_p, struct
299        return;
300      if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
301      {
302 <      if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL)
302 >      if ((target_p = find_chasing(source_p, dlhost, NULL)) == NULL)
303          return;
304  
305        if (!MyConnect(target_p))
# Line 358 | Line 336 | ms_dline(struct Client *client_p, struct
336  
337   #ifdef IPV6
338      if (t == HM_IPV6)
339 <      t = AF_INET6;
339 >      aftype= AF_INET6;
340      else
341   #endif
342 <      t = AF_INET;
342 >      aftype = AF_INET;
343  
344      parse_netmask(dlhost, &daddr, NULL);
345  
346 <    if ((aconf = find_dline_conf(&daddr, t)) != NULL)
346 >    if ((conf = find_dline_conf(&daddr, aftype)) != NULL)
347      {
348 <      creason = aconf->reason ? aconf->reason : def_reason;
349 <      if (IsConfExemptKline(aconf))
348 >      creason = conf->reason ? conf->reason : def_reason;
349 >      if (IsConfExemptKline(conf))
350          sendto_one(source_p,
351                     ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
352 <                   me.name, source_p->name, dlhost, aconf->host, creason);
352 >                   me.name, source_p->name, dlhost, conf->host, creason);
353        else
354          sendto_one(source_p,
355                     ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
356 <                   me.name, source_p->name, dlhost, aconf->host, creason);
356 >                   me.name, source_p->name, dlhost, conf->host, creason);
357        return;
358      }
359  
360      cur_time = CurrentTime;
361      current_date = smalldate(cur_time);
362  
385    /* Look for an oper reason */
386    if ((oper_reason = strchr(reason, '|')) != NULL)
387      *oper_reason++ = '\0';
388
363      if (!valid_comment(source_p, reason, 1))
364        return;
365  
366 <    conf = make_conf_item(DLINE_TYPE);
367 <    aconf = map_to_conf(conf);
394 <    DupString(aconf->host, dlhost);
366 >    conf = conf_make(CONF_DLINE);
367 >    conf->host = xstrdup(dlhost);
368  
369      if (tkline_time != 0)
397    {
370        snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
371                 (int)(tkline_time/60), reason, current_date);
400      DupString(aconf->reason, buffer);
401      if (oper_reason != NULL)
402        DupString(aconf->oper_reason, oper_reason);
403      apply_tdline(source_p, conf, current_date, tkline_time);
404    }
372      else
406    {
373        snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
408      DupString(aconf->reason, buffer);
409      if (oper_reason != NULL)
410        DupString(aconf->oper_reason, oper_reason);
411      add_conf_by_address(CONF_DLINE, aconf);
412      write_conf_line(source_p, conf, current_date, cur_time);
413    }
374  
375 +    conf->reason = xstrdup(buffer);
376 +    apply_dline(source_p, conf, tkline_time);
377      rehashed_klines = 1;
378    }
379   }
# Line 434 | Line 396 | mo_undline(struct Client *client_p, stru
396  
397    if (!HasOFlag(source_p, OPER_FLAG_UNDLINE))
398    {
399 <    sendto_one(source_p, form_str(ERR_NOPRIVS),
400 <               me.name, source_p->name, "undline");
399 >    sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
400 >               source_p->name, "undline");
401      return;
402    }
403  
# Line 456 | Line 418 | mo_undline(struct Client *client_p, stru
418                         "UNDLINE %s %s", target_server, addr);
419  
420      /* Allow ON to apply local unkline as well if it matches */
421 <    if (!match(target_server, me.name))
421 >    if (match(target_server, me.name))
422        return;
423    }
424    else
425      cluster_a_line(source_p, "UNDLINE", CAP_UNDLN, SHARED_UNDLINE,
426                     "%s", addr);
427  
428 <  if (remove_tdline_match(addr))
467 <  {
468 <    sendto_one(source_p,
469 <               ":%s NOTICE %s :Un-Dlined [%s] from temporary D-Lines",
470 <               me.name, source_p->name, addr);
471 <    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
472 <                         "%s has removed the temporary D-Line for: [%s]",
473 <                         get_oper_name(source_p), addr);
474 <    ilog(LOG_TYPE_DLINE, "%s removed temporary D-Line for [%s]",
475 <         source_p->name, addr);
476 <    return;
477 <  }
478 <
479 <  if (remove_conf_line(DLINE_TYPE, source_p, addr, NULL) > 0)
428 >  if (remove_dline_match(addr))
429    {
430      sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed",
431                 me.name, source_p->name, addr);
432      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
433 <                         "%s has removed the D-Line for: [%s]",
434 <                         get_oper_name(source_p), addr);
433 >                         "%s has removed the D-Line for: [%s]",
434 >                         get_oper_name(source_p), addr);
435      ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
436           get_oper_name(source_p), addr);
437    }
# Line 502 | Line 451 | me_undline(struct Client *client_p, stru
451  
452    addr = parv[2];
453  
454 <  if (!IsClient(source_p) || !match(parv[1], me.name))
454 >  if (!IsClient(source_p) || match(parv[1], me.name))
455      return;
456  
457 <  if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(ULINE_TYPE,
458 <                                   source_p->servptr->name,
459 <                                   source_p->username, source_p->host,
460 <                                   SHARED_UNDLINE))
457 >  if (HasFlag(source_p, FLAGS_SERVICE) ||
458 >      find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
459 >                              source_p->username, source_p->host,
460 >                              SHARED_UNDLINE))
461    {
462 <    if (remove_tdline_match(addr))
514 <    {
515 <      sendto_one(source_p,
516 <                 ":%s NOTICE %s :Un-Dlined [%s] from temporary D-Lines",
517 <                 me.name, source_p->name, addr);
518 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
519 <                           "%s has removed the temporary D-Line for: [%s]",
520 <                           get_oper_name(source_p), addr);
521 <      ilog(LOG_TYPE_DLINE, "%s removed temporary D-Line for [%s]",
522 <           source_p->name, addr);
523 <      return;
524 <    }
525 <
526 <    if (remove_conf_line(DLINE_TYPE, source_p, addr, NULL) > 0)
462 >    if (remove_dline_match(addr))
463      {
464        sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed",
465                   me.name, source_p->name, addr);
# Line 547 | Line 483 | ms_undline(struct Client *client_p, stru
483      return;
484  
485    sendto_match_servs(source_p, parv[1], CAP_UNDLN,
486 <                     "UNDLINE %s %s %s",
486 >                     "UNDLINE %s %s",
487                       parv[1], parv[2]);
488  
489    me_undline(client_p, source_p, parc, parv);
490   }
491  
492 < static struct Message dline_msgtab = {
492 > static struct Message dline_msgtab =
493 > {
494    "DLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
495 <   {m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore}
495 >  { m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore }
496   };
497  
498 < static struct Message undline_msgtab = {
498 > static struct Message undline_msgtab =
499 > {
500    "UNDLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
501 <   {m_unregistered, m_not_oper, ms_undline, m_ignore, mo_undline, m_ignore}
501 >  { m_unregistered, m_not_oper, ms_undline, m_ignore, mo_undline, m_ignore }
502   };
503  
504   static void
# Line 581 | Line 519 | module_exit(void)
519    delete_capability("DLN");
520   }
521  
522 < struct module module_entry = {
522 > struct module module_entry =
523 > {
524    .node    = { NULL, NULL, NULL },
525    .name    = NULL,
526    .version = "$Revision$",

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)