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-8/modules/m_dline.c (file contents), Revision 1474 by michael, Sun Jul 22 14:44:07 2012 UTC vs.
ircd-hybrid/trunk/modules/m_dline.c (file contents), Revision 1703 by michael, Sun Dec 23 14:26:36 2012 UTC

# Line 28 | Line 28
28   #include "client.h"
29   #include "irc_string.h"
30   #include "sprintf_irc.h"
31 + #include "conf.h"
32   #include "ircd.h"
33   #include "hostmask.h"
34   #include "numeric.h"
35   #include "fdlist.h"
36   #include "s_bsd.h"
36 #include "conf.h"
37   #include "log.h"
38   #include "s_misc.h"
39   #include "send.h"
40   #include "hash.h"
41   #include "s_serv.h"
42 #include "s_gline.h"
42   #include "parse.h"
43   #include "modules.h"
44 + #include "conf_db.h"
45 + #include "memory.h"
46  
47  
48   /* apply_tdline()
# Line 51 | Line 52
52   * side effects - tkline as given is placed
53   */
54   static void
55 < apply_tdline(struct Client *source_p, struct ConfItem *conf,
56 <             const char *current_date, int tkline_time)
55 > apply_dline(struct Client *source_p, struct MaskItem *conf,
56 >            time_t tkline_time)
57   {
58 <  struct AccessItem *aconf;
58 >  if (tkline_time)
59 >  {
60 >    conf->until = CurrentTime + tkline_time;
61 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
62 >                         "%s added temporary %d min. D-Line for [%s] [%s]",
63 >                         get_oper_name(source_p), tkline_time/60,
64 >                         conf->host, conf->reason);
65 >    sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line [%s]",
66 >               MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
67 >               source_p->name, tkline_time/60, conf->host);
68 >    ilog(LOG_TYPE_DLINE, "%s added temporary %d min. D-Line for [%s] [%s]",
69 >         get_oper_name(source_p), tkline_time/60, conf->host, conf->reason);
70 >  }
71 >  else
72 >  {
73 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
74 >                         "%s added D-Line for [%s] [%s]",
75 >                         get_oper_name(source_p), conf->host, conf->reason);
76 >    sendto_one(source_p, ":%s NOTICE %s :Added D-Line [%s]",
77 >               MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
78 >               source_p->name, conf->host);
79 >    ilog(LOG_TYPE_DLINE, "%s added D-Line for [%s] [%s]",
80 >         get_oper_name(source_p), conf->host, conf->reason);
81  
82 <  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,
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);
82 >  }
83  
84 +  SetConfDatabase(conf);
85 +  conf->setat = CurrentTime;
86 +  add_conf_by_address(CONF_DLINE, conf);
87    rehashed_klines = 1;
88   }
89  
# Line 82 | Line 93 | apply_tdline(struct Client *source_p, st
93   * Side effects: Any matching tdlines are removed.
94   */
95   static int
96 < remove_tdline_match(const char *host)
96 > remove_dline_match(const char *host)
97   {
98    struct irc_ssaddr iphost, *piphost;
99 <  struct AccessItem *aconf;
100 <  int t;
99 >  struct MaskItem *conf;
100 >  int t = 0;
101 >  int aftype = 0;
102  
103    if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
104    {
105   #ifdef IPV6
106      if (t == HM_IPV6)
107 <      t = AF_INET6;
107 >      aftype = AF_INET6;
108      else
109   #endif
110 <      t = AF_INET;
110 >      aftype = AF_INET;
111      piphost = &iphost;
112    }
113    else
102  {
103    t = 0;
114      piphost = NULL;
105  }
115  
116 <  if ((aconf = find_conf_by_address(host, piphost, CONF_DLINE, t, NULL, NULL, 0)))
116 >  if ((conf = find_conf_by_address(host, piphost, CONF_DLINE | 1, aftype, NULL, NULL, 0)))
117    {
118 <    if (IsConfTemporary(aconf))
118 >    if (IsConfDatabase(conf))
119      {
120 <      delete_one_address_conf(host, aconf);
120 >      delete_one_address_conf(host, conf);
121        return 1;
122      }
123    }
# Line 131 | Line 140 | mo_dline(struct Client *client_p, struct
140           int parc, char *parv[])
141   {
142    char def_reason[] = "<No reason specified>";
143 <  char *dlhost = NULL, *oper_reason = NULL, *reason = NULL;
143 >  char *dlhost = NULL, *reason = NULL;
144    char *target_server = NULL;
145    const char *creason;
146    const struct Client *target_p = NULL;
147    struct irc_ssaddr daddr;
148 <  struct ConfItem *conf=NULL;
140 <  struct AccessItem *aconf=NULL;
148 >  struct MaskItem *conf=NULL;
149    time_t tkline_time=0;
150 <  int bits, t;
150 >  int bits = 0, aftype = 0, t = 0;
151    const char *current_date = NULL;
152    time_t cur_time;
153    char hostip[HOSTIPLEN + 1];
# Line 148 | Line 156 | mo_dline(struct Client *client_p, struct
156    if (!HasOFlag(source_p, OPER_FLAG_DLINE))
157    {
158      sendto_one(source_p, form_str(ERR_NOPRIVS),
159 <               me.name, source_p->name, "kline");
159 >               me.name, source_p->name, "dline");
160      return;
161    }
162  
# Line 176 | Line 184 | mo_dline(struct Client *client_p, struct
184                      dlhost, reason);
185  
186      /* Allow ON to apply local kline as well if it matches */
187 <    if (!match(target_server, me.name))
187 >    if (match(target_server, me.name))
188        return;
189    }
190    else
# Line 222 | Line 230 | mo_dline(struct Client *client_p, struct
230  
231   #ifdef IPV6
232    if (t == HM_IPV6)
233 <    t = AF_INET6;
233 >    aftype = AF_INET6;
234    else
235   #endif
236 <    t = AF_INET;
236 >    aftype = AF_INET;
237  
238    parse_netmask(dlhost, &daddr, NULL);
239  
240 <  if ((aconf = find_dline_conf(&daddr, t)) != NULL)
240 >  if ((conf = find_dline_conf(&daddr, aftype)) != NULL)
241    {
242 <    creason = aconf->reason ? aconf->reason : def_reason;
243 <    if (IsConfExemptKline(aconf))
242 >    creason = conf->reason ? conf->reason : def_reason;
243 >    if (IsConfExemptKline(conf))
244        sendto_one(source_p,
245                   ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
246 <                 me.name, source_p->name, dlhost, aconf->host, creason);
246 >                 me.name, source_p->name, dlhost, conf->host, creason);
247      else
248        sendto_one(source_p,
249                   ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
250 <                 me.name, source_p->name, dlhost, aconf->host, creason);
250 >                 me.name, source_p->name, dlhost, conf->host, creason);
251      return;
252    }
253  
254    cur_time = CurrentTime;
255    current_date = smalldate(cur_time);
256  
249  /* Look for an oper reason */
250  if ((oper_reason = strchr(reason, '|')) != NULL)
251    *oper_reason++ = '\0';
252
257    if (!valid_comment(source_p, reason, 1))
258      return;
259  
260 <  conf = make_conf_item(DLINE_TYPE);
261 <  aconf = map_to_conf(conf);
258 <  DupString(aconf->host, dlhost);
260 >  conf = conf_make(CONF_DLINE);
261 >  conf->host = xstrdup(dlhost);
262  
263    if (tkline_time != 0)
261  {
264      snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
265               (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  }
266    else
270  {
267      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  }
268  
269 +  conf->reason = xstrdup(buffer);
270 +  apply_dline(source_p, conf, tkline_time);
271    rehashed_klines = 1;
272   }
273  
# Line 284 | Line 276 | ms_dline(struct Client *client_p, struct
276           int parc, char *parv[])
277   {
278    char def_reason[] = "<No reason specified>";
279 <  char *dlhost, *oper_reason, *reason;
279 >  char *dlhost, *reason;
280    const char *creason;
281    const struct Client *target_p = NULL;
282    struct irc_ssaddr daddr;
283 <  struct ConfItem *conf=NULL;
292 <  struct AccessItem *aconf=NULL;
283 >  struct MaskItem *conf=NULL;
284    time_t tkline_time=0;
285 <  int bits, t;
285 >  int bits = 0, aftype = 0, t = 0;
286    const char *current_date = NULL;
287    time_t cur_time;
288    char hostip[HOSTIPLEN + 1];
# Line 306 | Line 297 | ms_dline(struct Client *client_p, struct
297                       "DLINE %s %s %s :%s",
298                       parv[1], parv[2], parv[3], parv[4]);
299  
300 <  if (!match(parv[1], me.name))
300 >  if (match(parv[1], me.name))
301      return;
302  
303    tkline_time = valid_tkline(parv[2], TK_SECONDS);
304    dlhost = parv[3];
305    reason = parv[4];
306  
307 <  if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(ULINE_TYPE, source_p->servptr->name,
307 >  if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
308                                source_p->username, source_p->host,
309                                SHARED_DLINE))
310    {
# Line 358 | Line 349 | ms_dline(struct Client *client_p, struct
349  
350   #ifdef IPV6
351      if (t == HM_IPV6)
352 <      t = AF_INET6;
352 >      aftype= AF_INET6;
353      else
354   #endif
355 <      t = AF_INET;
355 >      aftype = AF_INET;
356  
357      parse_netmask(dlhost, &daddr, NULL);
358  
359 <    if ((aconf = find_dline_conf(&daddr, t)) != NULL)
359 >    if ((conf = find_dline_conf(&daddr, aftype)) != NULL)
360      {
361 <      creason = aconf->reason ? aconf->reason : def_reason;
362 <      if (IsConfExemptKline(aconf))
361 >      creason = conf->reason ? conf->reason : def_reason;
362 >      if (IsConfExemptKline(conf))
363          sendto_one(source_p,
364                     ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
365 <                   me.name, source_p->name, dlhost, aconf->host, creason);
365 >                   me.name, source_p->name, dlhost, conf->host, creason);
366        else
367          sendto_one(source_p,
368                     ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
369 <                   me.name, source_p->name, dlhost, aconf->host, creason);
369 >                   me.name, source_p->name, dlhost, conf->host, creason);
370        return;
371      }
372  
373      cur_time = CurrentTime;
374      current_date = smalldate(cur_time);
375  
385    /* Look for an oper reason */
386    if ((oper_reason = strchr(reason, '|')) != NULL)
387      *oper_reason++ = '\0';
388
376      if (!valid_comment(source_p, reason, 1))
377        return;
378  
379 <    conf = make_conf_item(DLINE_TYPE);
380 <    aconf = map_to_conf(conf);
394 <    DupString(aconf->host, dlhost);
379 >    conf = conf_make(CONF_DLINE);
380 >    conf->host = xstrdup(dlhost);
381  
382      if (tkline_time != 0)
397    {
383        snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
384                 (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    }
385      else
406    {
386        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    }
387  
388 +    conf->reason = xstrdup(buffer);
389 +    apply_dline(source_p, conf, tkline_time);
390      rehashed_klines = 1;
391    }
392   }
# Line 456 | Line 431 | mo_undline(struct Client *client_p, stru
431                         "UNDLINE %s %s", target_server, addr);
432  
433      /* Allow ON to apply local unkline as well if it matches */
434 <    if (!match(target_server, me.name))
434 >    if (match(target_server, me.name))
435        return;
436    }
437    else
438      cluster_a_line(source_p, "UNDLINE", CAP_UNDLN, SHARED_UNDLINE,
439                     "%s", addr);
440  
441 <  if (remove_tdline_match(addr))
441 >  if (remove_dline_match(addr))
442    {
443      sendto_one(source_p,
444 <               ":%s NOTICE %s :Un-Dlined [%s] from temporary D-Lines",
444 >               ":%s NOTICE %s :D-Line for [%s] is removed",
445                 me.name, source_p->name, addr);
446 <    sendto_realops_flags(UMODE_ALL, L_ALL,
447 <                         "%s has removed the temporary D-Line for: [%s]",
446 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
447 >                         "%s has removed the D-Line for: [%s]",
448                           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)
480  {
481    sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed",
482               me.name, source_p->name, addr);
483    sendto_realops_flags(UMODE_ALL, L_ALL,
484                         "%s has removed the D-Line for: [%s]",
485                         get_oper_name(source_p), addr);
449      ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
450           get_oper_name(source_p), addr);
451    }
# Line 502 | Line 465 | me_undline(struct Client *client_p, stru
465  
466    addr = parv[2];
467  
468 <  if (!IsClient(source_p) || !match(parv[1], me.name))
468 >  if (!IsClient(source_p) || match(parv[1], me.name))
469      return;
470  
471 <  if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(ULINE_TYPE,
471 >  if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE,
472                                     source_p->servptr->name,
473                                     source_p->username, source_p->host,
474                                     SHARED_UNDLINE))
475    {
476 <    if (remove_tdline_match(addr))
476 >    if (remove_dline_match(addr))
477      {
478        sendto_one(source_p,
479 <                 ":%s NOTICE %s :Un-Dlined [%s] from temporary D-Lines",
479 >                 ":%s NOTICE %s :D-Line for [%s] is removed",
480                   me.name, source_p->name, addr);
481 <      sendto_realops_flags(UMODE_ALL, L_ALL,
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)
527 <    {
528 <      sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed",
529 <                 me.name, source_p->name, addr);
530 <      sendto_realops_flags(UMODE_ALL, L_ALL,
481 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
482                             "%s has removed the D-Line for: [%s]",
483                             get_oper_name(source_p), addr);
484 <      ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
484 >      ilog(LOG_TYPE_DLINE, "%s removed temporary D-Line for [%s]",
485             get_oper_name(source_p), addr);
486      }
487      else

Diff Legend

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