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 1298 by michael, Tue Feb 28 18:51:13 2012 UTC vs.
ircd-hybrid/trunk/modules/m_dline.c (file contents), Revision 1625 by michael, Thu Nov 1 13:49:25 2012 UTC

# Line 33 | Line 33
33   #include "numeric.h"
34   #include "fdlist.h"
35   #include "s_bsd.h"
36 < #include "s_conf.h"
37 < #include "s_log.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  
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 AccessItem *aconf,
55 >            time_t tkline_time)
56   {
57 <  struct AccessItem *aconf;
58 <
59 <  aconf = map_to_conf(conf);
60 <  aconf->hold = CurrentTime + tkline_time;
57 >  if (tkline_time)
58 >  {
59 >    aconf->hold = CurrentTime + tkline_time;
60 >    SetConfTemporary(aconf);
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 >                         aconf->host, aconf->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, aconf->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, aconf->host, aconf->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), aconf->host, aconf->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, aconf->host);
79 >    ilog(LOG_TYPE_DLINE, "%s added D-Line for [%s] [%s]",
80 >         get_oper_name(source_p), aconf->host, aconf->reason);
81  
82 <  add_temp_line(conf);
63 <  sendto_realops_flags(UMODE_ALL, L_ALL,
64 <                       "%s added temporary %d min. D-Line for [%s] [%s]",
65 <                       get_oper_name(source_p), tkline_time/60,
66 <                       aconf->host, aconf->reason);
67 <
68 <  sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line [%s]",
69 <             MyConnect(source_p) ? me.name : ID_or_name(&me, source_p->from),
70 <             source_p->name, tkline_time/60, aconf->host);
71 <  ilog(LOG_TYPE_DLINE, "%s added temporary %d min. D-Line for [%s] [%s]",
72 <       source_p->name, tkline_time/60, aconf->host, aconf->reason);
82 >  }
83  
84 +  aconf->setat = CurrentTime;
85 +  add_conf_by_address(CONF_DLINE, aconf);
86    rehashed_klines = 1;
87   }
88  
# Line 80 | 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 AccessItem *td_conf;
98 <  dlink_node *td_node;
99 <  struct irc_ssaddr addr, caddr;
88 <  int nm_t, cnm_t, bits, cbits;
89 <
90 <  nm_t = parse_netmask(host, &addr, &bits);
97 >  struct irc_ssaddr iphost, *piphost;
98 >  struct AccessItem *aconf;
99 >  int t;
100  
101 <  DLINK_FOREACH(td_node, temporary_dlines.head)
101 >  if ((t = parse_netmask(host, &iphost, NULL)) != HM_HOST)
102    {
94    td_conf = map_to_conf(td_node->data);
95    cnm_t   = parse_netmask(td_conf->host, &caddr, &cbits);
96
97    if (cnm_t != nm_t)
98      continue;
99
100    if ((nm_t == HM_HOST && !irccmp(td_conf->host, host)) ||
101        (nm_t == HM_IPV4 && bits == cbits && match_ipv4(&addr, &caddr, bits))
103   #ifdef IPV6
104 <     || (nm_t == HM_IPV6 && bits == cbits && match_ipv6(&addr, &caddr, bits))
104 >    if (t == HM_IPV6)
105 >      t = AF_INET6;
106 >    else
107   #endif
108 <      )
108 >      t = AF_INET;
109 >    piphost = &iphost;
110 >  }
111 >  else
112 >  {
113 >    t = 0;
114 >    piphost = NULL;
115 >  }
116 >
117 >  if ((aconf = find_conf_by_address(host, piphost, CONF_DLINE, t, NULL, NULL, 0)))
118 >  {
119 >    if (!IsConfMain(aconf))
120      {
121 <      dlinkDelete(td_node, &temporary_dlines);
108 <      delete_one_address_conf(td_conf->host, td_conf);
121 >      delete_one_address_conf(host, aconf);
122        return 1;
123      }
124    }
# Line 127 | 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";
144 <  char *dlhost, *oper_reason, *reason;
143 >  char def_reason[] = "<No reason specified>";
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;
# Line 138 | Line 152 | mo_dline(struct Client *client_p, struct
152    int bits, t;
153    const char *current_date = NULL;
154    time_t cur_time;
155 <  char hostip[HOSTIPLEN];
155 >  char hostip[HOSTIPLEN + 1];
156    char buffer[IRCD_BUFSIZE];
157  
158 <  if (!HasOFlag(source_p, OPER_FLAG_K))
158 >  if (!HasOFlag(source_p, OPER_FLAG_DLINE))
159    {
160      sendto_one(source_p, form_str(ERR_NOPRIVS),
161 <               me.name, source_p->name, "kline");
161 >               me.name, source_p->name, "dline");
162      return;
163    }
164  
165    if (parse_aline("DLINE", source_p,  parc, parv, AWILD, &dlhost,
166 <                  NULL, &tkline_time, NULL, &reason) < 0)
166 >                  NULL, &tkline_time, &target_server, &reason) < 0)
167      return;
168  
169 +  if (target_server != NULL)
170 +  {
171 +    if (HasID(source_p))
172 +    {
173 +      sendto_server(NULL, CAP_DLN|CAP_TS6, NOCAPS,
174 +                    ":%s DLINE %s %lu %s :%s",
175 +                    source_p->id, target_server, (unsigned long)tkline_time,
176 +                    dlhost, reason);
177 +      sendto_server(NULL, CAP_DLN, CAP_TS6,
178 +                    ":%s DLINE %s %lu %s :%s",
179 +                    source_p->name, target_server, (unsigned long)tkline_time,
180 +                    dlhost, reason);
181 +    }
182 +    else
183 +      sendto_server(NULL, CAP_DLN, NOCAPS,
184 +                    ":%s DLINE %s %lu %s :%s",
185 +                    source_p->name, target_server, (unsigned long)tkline_time,
186 +                    dlhost, reason);
187 +
188 +    /* Allow ON to apply local kline as well if it matches */
189 +    if (!match(target_server, me.name))
190 +      return;
191 +  }
192 +  else
193 +    cluster_a_line(source_p, "DLINE", CAP_DLN, SHARED_DLINE,
194 +                   "%d %s :%s", tkline_time, dlhost, reason);
195 +
196    if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
197    {
198      if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL)
# Line 215 | Line 256 | mo_dline(struct Client *client_p, struct
256    cur_time = CurrentTime;
257    current_date = smalldate(cur_time);
258  
218  /* Look for an oper reason */
219  if ((oper_reason = strchr(reason, '|')) != NULL)
220    *oper_reason++ = '\0';
221
259    if (!valid_comment(source_p, reason, 1))
260      return;
261  
# Line 231 | Line 268 | mo_dline(struct Client *client_p, struct
268      snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
269               (int)(tkline_time/60), reason, current_date);
270      DupString(aconf->reason, buffer);
271 <    if (oper_reason != NULL)
235 <      DupString(aconf->oper_reason, oper_reason);
236 <    apply_tdline(source_p, conf, current_date, tkline_time);
271 >    apply_dline(source_p, aconf, tkline_time);
272    }
273    else
274    {
275      snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
276      DupString(aconf->reason, buffer);
277 <    if (oper_reason != NULL)
243 <      DupString(aconf->oper_reason, oper_reason);
244 <    add_conf_by_address(CONF_DLINE, aconf);
245 <    write_conf_line(source_p, conf, current_date, cur_time);
277 >    apply_dline(source_p, aconf, 0);
278    }
279  
280    rehashed_klines = 1;
281   }
282  
283 + static void
284 + ms_dline(struct Client *client_p, struct Client *source_p,
285 +         int parc, char *parv[])
286 + {
287 +  char def_reason[] = "<No reason specified>";
288 +  char *dlhost, *reason;
289 +  const char *creason;
290 +  const struct Client *target_p = NULL;
291 +  struct irc_ssaddr daddr;
292 +  struct ConfItem *conf=NULL;
293 +  struct AccessItem *aconf=NULL;
294 +  time_t tkline_time=0;
295 +  int bits, t;
296 +  const char *current_date = NULL;
297 +  time_t cur_time;
298 +  char hostip[HOSTIPLEN + 1];
299 +  char buffer[IRCD_BUFSIZE];
300 +
301 +  if (parc != 5 || EmptyString(parv[4]))
302 +    return;
303 +
304 +  /* parv[0]  parv[1]        parv[2]      parv[3]  parv[4] */
305 +  /* oper     target_server  tkline_time  host     reason  */
306 +  sendto_match_servs(source_p, parv[1], CAP_DLN,
307 +                     "DLINE %s %s %s :%s",
308 +                     parv[1], parv[2], parv[3], parv[4]);
309 +
310 +  if (!match(parv[1], me.name))
311 +    return;
312 +
313 +  tkline_time = valid_tkline(parv[2], TK_SECONDS);
314 +  dlhost = parv[3];
315 +  reason = parv[4];
316 +
317 +  if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(ULINE_TYPE, source_p->servptr->name,
318 +                              source_p->username, source_p->host,
319 +                              SHARED_DLINE))
320 +  {
321 +    if (!IsClient(source_p))
322 +      return;
323 +    if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
324 +    {
325 +      if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL)
326 +        return;
327 +
328 +      if (!MyConnect(target_p))
329 +      {
330 +        sendto_one(source_p,
331 +                   ":%s NOTICE %s :Can't DLINE nick on another server",
332 +                   me.name, source_p->name);
333 +        return;
334 +      }
335 +
336 +      if (IsExemptKline(target_p))
337 +      {
338 +        sendto_one(source_p,
339 +                   ":%s NOTICE %s :%s is E-lined", me.name,
340 +                   source_p->name, target_p->name);
341 +        return;
342 +      }
343 +
344 +      getnameinfo((struct sockaddr *)&target_p->localClient->ip,
345 +                  target_p->localClient->ip.ss_len, hostip,
346 +                  sizeof(hostip), NULL, 0, NI_NUMERICHOST);
347 +      dlhost = hostip;
348 +      t = parse_netmask(dlhost, NULL, &bits);
349 +      assert(t == HM_IPV4 || t == HM_IPV6);
350 +    }
351 +
352 +    if (bits < 8)
353 +    {
354 +      sendto_one(source_p,
355 +                 ":%s NOTICE %s :For safety, bitmasks less than 8 require conf access.",
356 +                 me.name, source_p->name);
357 +      return;
358 +    }
359 +
360 + #ifdef IPV6
361 +    if (t == HM_IPV6)
362 +      t = AF_INET6;
363 +    else
364 + #endif
365 +      t = AF_INET;
366 +
367 +    parse_netmask(dlhost, &daddr, NULL);
368 +
369 +    if ((aconf = find_dline_conf(&daddr, t)) != NULL)
370 +    {
371 +      creason = aconf->reason ? aconf->reason : def_reason;
372 +      if (IsConfExemptKline(aconf))
373 +        sendto_one(source_p,
374 +                   ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
375 +                   me.name, source_p->name, dlhost, aconf->host, creason);
376 +      else
377 +        sendto_one(source_p,
378 +                   ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
379 +                   me.name, source_p->name, dlhost, aconf->host, creason);
380 +      return;
381 +    }
382 +
383 +    cur_time = CurrentTime;
384 +    current_date = smalldate(cur_time);
385 +
386 +    if (!valid_comment(source_p, reason, 1))
387 +      return;
388 +
389 +    conf = make_conf_item(DLINE_TYPE);
390 +    aconf = map_to_conf(conf);
391 +    DupString(aconf->host, dlhost);
392 +
393 +    if (tkline_time != 0)
394 +    {
395 +      snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
396 +               (int)(tkline_time/60), reason, current_date);
397 +      DupString(aconf->reason, buffer);
398 +      apply_dline(source_p, aconf, tkline_time);
399 +    }
400 +    else
401 +    {
402 +      snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
403 +      DupString(aconf->reason, buffer);
404 +      apply_dline(source_p, aconf, 0);
405 +    }
406 +
407 +    rehashed_klines = 1;
408 +  }
409 + }
410 +
411   /*
412   ** m_undline
413   ** added May 28th 2000 by Toby Verrall <toot@melnet.co.uk>
# Line 261 | Line 421 | static void
421   mo_undline(struct Client *client_p, struct Client *source_p,
422             int parc, char *parv[])
423   {
424 <  const char *addr = NULL;
424 >  char *addr = NULL, *user = NULL;
425 >  char *target_server = NULL;
426  
427 <  if (!HasOFlag(source_p, OPER_FLAG_UNKLINE))
427 >  if (!HasOFlag(source_p, OPER_FLAG_UNDLINE))
428    {
429      sendto_one(source_p, form_str(ERR_NOPRIVS),
430                 me.name, source_p->name, "undline");
431      return;
432    }
433  
434 <  addr = parv[1];
274 <
275 <  if (remove_tdline_match(addr))
434 >  if (parc < 2 || EmptyString(parv[1]))
435    {
436 <    sendto_one(source_p,
437 <              ":%s NOTICE %s :Un-Dlined [%s] from temporary D-Lines",
279 <              me.name, source_p->name, addr);
280 <    sendto_realops_flags(UMODE_ALL, L_ALL,
281 <                         "%s has removed the temporary D-Line for: [%s]",
282 <                         get_oper_name(source_p), addr);
283 <    ilog(LOG_TYPE_DLINE, "%s removed temporary D-Line for [%s]", source_p->name, addr);
436 >    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
437 >               me.name, source_p->name, "UNDLINE");
438      return;
439    }
440  
441 <  if (remove_conf_line(DLINE_TYPE, source_p, addr, NULL) > 0)
441 >  if (parse_aline("UNDLINE", source_p, parc, parv, 0, &user,
442 >                  &addr, NULL, &target_server, NULL) < 0)
443 >    return;
444 >
445 >  if (target_server != NULL)
446    {
447 <    sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed",
447 >    sendto_match_servs(source_p, target_server, CAP_UNDLN,
448 >                       "UNDLINE %s %s", target_server, addr);
449 >
450 >    /* Allow ON to apply local unkline as well if it matches */
451 >    if (!match(target_server, me.name))
452 >      return;
453 >  }
454 >  else
455 >    cluster_a_line(source_p, "UNDLINE", CAP_UNDLN, SHARED_UNDLINE,
456 >                   "%s", addr);
457 >
458 >  if (remove_dline_match(addr))
459 >  {
460 >    sendto_one(source_p,
461 >               ":%s NOTICE %s :D-Line for [%s] is removed",
462                 me.name, source_p->name, addr);
463 <    sendto_realops_flags(UMODE_ALL, L_ALL,
464 <                         "%s has removed the D-Line for: [%s]",
465 <                         get_oper_name(source_p), addr);
463 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
464 >                         "%s has removed the D-Line for: [%s]",
465 >                         get_oper_name(source_p), addr);
466      ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
467           get_oper_name(source_p), addr);
468    }
# Line 299 | Line 471 | mo_undline(struct Client *client_p, stru
471                 me.name, source_p->name, addr);
472   }
473  
474 + static void
475 + me_undline(struct Client *client_p, struct Client *source_p,
476 +           int parc, char *parv[])
477 + {
478 +  const char *addr = NULL;
479 +
480 +  if (parc != 3 || EmptyString(parv[2]))
481 +    return;
482 +
483 +  addr = parv[2];
484 +
485 +  if (!IsClient(source_p) || !match(parv[1], me.name))
486 +    return;
487 +
488 +  if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(ULINE_TYPE,
489 +                                   source_p->servptr->name,
490 +                                   source_p->username, source_p->host,
491 +                                   SHARED_UNDLINE))
492 +  {
493 +    if (remove_dline_match(addr))
494 +    {
495 +      sendto_one(source_p,
496 +                 ":%s NOTICE %s :D-Line for [%s] is removed",
497 +                 me.name, source_p->name, addr);
498 +      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
499 +                           "%s has removed the D-Line for: [%s]",
500 +                           get_oper_name(source_p), addr);
501 +      ilog(LOG_TYPE_DLINE, "%s removed temporary D-Line for [%s]",
502 +           get_oper_name(source_p), addr);
503 +    }
504 +    else
505 +      sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found",
506 +                 me.name, source_p->name, addr);
507 +  }
508 + }
509 +
510 + static void
511 + ms_undline(struct Client *client_p, struct Client *source_p,
512 +           int parc, char *parv[])
513 + {
514 +  if (parc != 3 || EmptyString(parv[2]))
515 +    return;
516 +
517 +  sendto_match_servs(source_p, parv[1], CAP_UNDLN,
518 +                     "UNDLINE %s %s %s",
519 +                     parv[1], parv[2]);
520 +
521 +  me_undline(client_p, source_p, parc, parv);
522 + }
523 +
524   static struct Message dline_msgtab = {
525    "DLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
526 <   {m_unregistered, m_not_oper, rfc1459_command_send_error, m_ignore, mo_dline, m_ignore}
526 >   {m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore}
527   };
528  
529   static struct Message undline_msgtab = {
530    "UNDLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
531 <   {m_unregistered, m_not_oper, rfc1459_command_send_error, m_ignore, mo_undline, m_ignore}
531 >   {m_unregistered, m_not_oper, ms_undline, m_ignore, mo_undline, m_ignore}
532   };
533  
534   static void
# Line 314 | Line 536 | module_init(void)
536   {
537    mod_add_cmd(&dline_msgtab);
538    mod_add_cmd(&undline_msgtab);
539 +  add_capability("DLN", CAP_DLN, 1);
540 +  add_capability("UNDLN", CAP_UNDLN, 1);
541   }
542  
543   static void
# Line 321 | Line 545 | module_exit(void)
545   {
546    mod_del_cmd(&dline_msgtab);
547    mod_del_cmd(&undline_msgtab);
548 +  delete_capability("UNDLN");
549 +  delete_capability("DLN");
550   }
551  
552   struct module module_entry = {

Diff Legend

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