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 1398 by michael, Sun May 6 10:57:06 2012 UTC vs.
ircd-hybrid/trunk/modules/m_dline.c (file contents), Revision 2807 by michael, Sun Jan 12 17:19:01 2014 UTC

# Line 27 | Line 27
27   #include "channel.h"
28   #include "client.h"
29   #include "irc_string.h"
30 < #include "sprintf_irc.h"
30 > #include "conf.h"
31   #include "ircd.h"
32   #include "hostmask.h"
33   #include "numeric.h"
34   #include "fdlist.h"
35   #include "s_bsd.h"
36 #include "conf.h"
36   #include "log.h"
37   #include "s_misc.h"
38   #include "send.h"
39   #include "hash.h"
40   #include "s_serv.h"
42 #include "s_gline.h"
41   #include "parse.h"
42   #include "modules.h"
43 + #include "conf_db.h"
44 + #include "memory.h"
45  
46  
47   /* apply_tdline()
# Line 51 | Line 51
51   * side effects - tkline as given is placed
52   */
53   static void
54 < apply_tdline(struct Client *source_p, struct ConfItem *conf,
55 <             const char *current_date, int tkline_time)
54 > apply_dline(struct Client *source_p, struct MaskItem *conf,
55 >            time_t tkline_time)
56   {
57 <  struct AccessItem *aconf;
57 >  if (tkline_time)
58 >  {
59 >    conf->until = CurrentTime + tkline_time;
60 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
61 >                         "%s added temporary %d min. D-Line for [%s] [%s]",
62 >                         get_oper_name(source_p), tkline_time/60,
63 >                         conf->host, conf->reason);
64 >    sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line [%s]",
65 >               MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
66 >               source_p->name, tkline_time/60, conf->host);
67 >    ilog(LOG_TYPE_DLINE, "%s added temporary %d min. D-Line for [%s] [%s]",
68 >         get_oper_name(source_p), tkline_time/60, conf->host, conf->reason);
69 >  }
70 >  else
71 >  {
72 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
73 >                         "%s added D-Line for [%s] [%s]",
74 >                         get_oper_name(source_p), conf->host, conf->reason);
75 >    sendto_one(source_p, ":%s NOTICE %s :Added D-Line [%s]",
76 >               MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
77 >               source_p->name, conf->host);
78 >    ilog(LOG_TYPE_DLINE, "%s added D-Line for [%s] [%s]",
79 >         get_oper_name(source_p), conf->host, conf->reason);
80  
81 <  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);
81 >  }
82  
83 +  SetConfDatabase(conf);
84 +  conf->setat = CurrentTime;
85 +  add_conf_by_address(CONF_DLINE, conf);
86    rehashed_klines = 1;
87   }
88  
# Line 82 | Line 92 | apply_tdline(struct Client *source_p, st
92   * Side effects: Any matching tdlines are removed.
93   */
94   static int
95 < remove_tdline_match(const char *host)
95 > remove_dline_match(const char *host)
96   {
97    struct irc_ssaddr iphost, *piphost;
98 <  struct AccessItem *aconf;
99 <  int t;
98 >  struct MaskItem *conf;
99 >  int t = 0;
100 >  int aftype = 0;
101  
102    if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
103    {
104   #ifdef IPV6
105      if (t == HM_IPV6)
106 <      t = AF_INET6;
106 >      aftype = AF_INET6;
107      else
108   #endif
109 <      t = AF_INET;
109 >      aftype = AF_INET;
110      piphost = &iphost;
111    }
112    else
102  {
103    t = 0;
113      piphost = NULL;
105  }
114  
115 <  if ((aconf = find_conf_by_address(host, piphost, CONF_DLINE, t, NULL, NULL, 0)))
115 >  if ((conf = find_conf_by_address(host, piphost, CONF_DLINE | 1, aftype, NULL, NULL, 0)))
116    {
117 <    if (IsConfTemporary(aconf))
117 >    if (IsConfDatabase(conf))
118      {
119 <      delete_one_address_conf(host, aconf);
119 >      delete_one_address_conf(host, conf);
120        return 1;
121      }
122    }
# Line 130 | Line 138 | static void
138   mo_dline(struct Client *client_p, struct Client *source_p,
139           int parc, char *parv[])
140   {
141 <  char def_reason[] = "<No reason specified>";
142 <  char *dlhost = NULL, *oper_reason = NULL, *reason = NULL;
141 >  char def_reason[] = CONF_NOREASON;
142 >  char *dlhost = NULL, *reason = NULL;
143    char *target_server = NULL;
144    const char *creason;
145    const struct Client *target_p = NULL;
146    struct irc_ssaddr daddr;
147 <  struct ConfItem *conf=NULL;
140 <  struct AccessItem *aconf=NULL;
147 >  struct MaskItem *conf=NULL;
148    time_t tkline_time=0;
149 <  int bits, t;
149 >  int bits = 0, aftype = 0, t = 0;
150    const char *current_date = NULL;
151    time_t cur_time;
152    char hostip[HOSTIPLEN + 1];
# Line 148 | Line 155 | mo_dline(struct Client *client_p, struct
155    if (!HasOFlag(source_p, OPER_FLAG_DLINE))
156    {
157      sendto_one(source_p, form_str(ERR_NOPRIVS),
158 <               me.name, source_p->name, "kline");
158 >               me.name, source_p->name, "dline");
159      return;
160    }
161  
# Line 158 | Line 165 | mo_dline(struct Client *client_p, struct
165  
166    if (target_server != NULL)
167    {
168 <    if (HasID(source_p))
169 <    {
170 <      sendto_server(NULL, 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, 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, NULL, CAP_DLN, NOCAPS,
174 <                    ":%s DLINE %s %lu %s :%s",
175 <                    source_p->name, target_server, (unsigned long)tkline_time,
176 <                    dlhost, reason);
168 >    sendto_match_servs(source_p, target_server, CAP_DLN, "DLINE %s %lu %s :%s",
169 >                       target_server, (unsigned long)tkline_time,
170 >                       dlhost, reason);
171  
172      /* Allow ON to apply local kline as well if it matches */
173 <    if (!match(target_server, me.name))
173 >    if (match(target_server, me.name))
174        return;
175    }
176    else
# Line 185 | Line 179 | mo_dline(struct Client *client_p, struct
179  
180    if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
181    {
182 <    if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL)
182 >    if ((target_p = find_chasing(source_p, dlhost, NULL)) == NULL)
183        return;
184  
185      if (!MyConnect(target_p))
# Line 222 | Line 216 | mo_dline(struct Client *client_p, struct
216  
217   #ifdef IPV6
218    if (t == HM_IPV6)
219 <    t = AF_INET6;
219 >    aftype = AF_INET6;
220    else
221   #endif
222 <    t = AF_INET;
222 >    aftype = AF_INET;
223  
224    parse_netmask(dlhost, &daddr, NULL);
225  
226 <  if ((aconf = find_dline_conf(&daddr, t)) != NULL)
226 >  if ((conf = find_dline_conf(&daddr, aftype)) != NULL)
227    {
228 <    creason = aconf->reason ? aconf->reason : def_reason;
229 <    if (IsConfExemptKline(aconf))
228 >    creason = conf->reason ? conf->reason : def_reason;
229 >    if (IsConfExemptKline(conf))
230        sendto_one(source_p,
231                   ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
232 <                 me.name, source_p->name, dlhost, aconf->host, creason);
232 >                 me.name, source_p->name, dlhost, conf->host, creason);
233      else
234        sendto_one(source_p,
235                   ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
236 <                 me.name, source_p->name, dlhost, aconf->host, creason);
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) || find_matching_name_conf(CONF_ULINE, source_p->servptr->name,
294                                source_p->username, source_p->host,
295                                SHARED_DLINE))
296    {
# Line 321 | Line 298 | ms_dline(struct Client *client_p, struct
298        return;
299      if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
300      {
301 <      if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL)
301 >      if ((target_p = find_chasing(source_p, dlhost, NULL)) == NULL)
302          return;
303  
304        if (!MyConnect(target_p))
# Line 358 | Line 335 | ms_dline(struct Client *client_p, struct
335  
336   #ifdef IPV6
337      if (t == HM_IPV6)
338 <      t = AF_INET6;
338 >      aftype= AF_INET6;
339      else
340   #endif
341 <      t = AF_INET;
341 >      aftype = AF_INET;
342  
343      parse_netmask(dlhost, &daddr, NULL);
344  
345 <    if ((aconf = find_dline_conf(&daddr, t)) != NULL)
345 >    if ((conf = find_dline_conf(&daddr, aftype)) != NULL)
346      {
347 <      creason = aconf->reason ? aconf->reason : def_reason;
348 <      if (IsConfExemptKline(aconf))
347 >      creason = conf->reason ? conf->reason : def_reason;
348 >      if (IsConfExemptKline(conf))
349          sendto_one(source_p,
350                     ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
351 <                   me.name, source_p->name, dlhost, aconf->host, creason);
351 >                   me.name, source_p->name, dlhost, conf->host, creason);
352        else
353          sendto_one(source_p,
354                     ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
355 <                   me.name, source_p->name, dlhost, aconf->host, creason);
355 >                   me.name, source_p->name, dlhost, conf->host, creason);
356        return;
357      }
358  
359      cur_time = CurrentTime;
360      current_date = smalldate(cur_time);
361  
385    /* Look for an oper reason */
386    if ((oper_reason = strchr(reason, '|')) != NULL)
387      *oper_reason++ = '\0';
388
362      if (!valid_comment(source_p, reason, 1))
363        return;
364  
365 <    conf = make_conf_item(DLINE_TYPE);
366 <    aconf = map_to_conf(conf);
394 <    DupString(aconf->host, dlhost);
365 >    conf = conf_make(CONF_DLINE);
366 >    conf->host = xstrdup(dlhost);
367  
368      if (tkline_time != 0)
397    {
369        snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
370                 (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    }
371      else
406    {
372        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    }
373  
374 +    conf->reason = xstrdup(buffer);
375 +    apply_dline(source_p, conf, tkline_time);
376      rehashed_klines = 1;
377    }
378   }
# Line 456 | Line 417 | mo_undline(struct Client *client_p, stru
417                         "UNDLINE %s %s", target_server, addr);
418  
419      /* Allow ON to apply local unkline as well if it matches */
420 <    if (!match(target_server, me.name))
420 >    if (match(target_server, me.name))
421        return;
422    }
423    else
424      cluster_a_line(source_p, "UNDLINE", CAP_UNDLN, SHARED_UNDLINE,
425                     "%s", addr);
426  
427 <  if (remove_tdline_match(addr))
427 >  if (remove_dline_match(addr))
428    {
429      sendto_one(source_p,
430 <               ":%s NOTICE %s :Un-Dlined [%s] from temporary D-Lines",
430 >               ":%s NOTICE %s :D-Line for [%s] is removed",
431                 me.name, source_p->name, addr);
432 <    sendto_realops_flags(UMODE_ALL, L_ALL,
433 <                         "%s has removed the temporary D-Line for: [%s]",
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);
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);
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,
457 >  if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_ULINE,
458                                     source_p->servptr->name,
459                                     source_p->username, source_p->host,
460                                     SHARED_UNDLINE))
461    {
462 <    if (remove_tdline_match(addr))
462 >    if (remove_dline_match(addr))
463      {
464        sendto_one(source_p,
465 <                 ":%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,
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",
465 >                 ":%s NOTICE %s :D-Line for [%s] is removed",
466                   me.name, source_p->name, addr);
467 <      sendto_realops_flags(UMODE_ALL, L_ALL,
467 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
468                             "%s has removed the D-Line for: [%s]",
469                             get_oper_name(source_p), addr);
470        ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
# Line 547 | Line 484 | ms_undline(struct Client *client_p, stru
484      return;
485  
486    sendto_match_servs(source_p, parv[1], CAP_UNDLN,
487 <                     "UNDLINE %s %s %s",
487 >                     "UNDLINE %s %s",
488                       parv[1], parv[2]);
489  
490    me_undline(client_p, source_p, parc, parv);

Diff Legend

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