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 1247 by michael, Sat Oct 1 07:54:24 2011 UTC vs.
ircd-hybrid/trunk/modules/m_dline.c (file contents), Revision 1761 by michael, Fri Jan 18 19:21:39 2013 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"
37 < #include "s_conf.h"
37 < #include "s_log.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  
47 static int remove_tdline_match(const char *);
48
48   /* apply_tdline()
49   *
50   * inputs       -
# Line 53 | Line 52 | static int remove_tdline_match(const cha
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;
59 <
60 <  aconf = map_to_conf(conf);
61 <  aconf->hold = CurrentTime + tkline_time;
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 <  add_temp_line(conf);
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  
90 + /* static int remove_tdline_match(const char *host, const char *user)
91 + * Input: An ip to undline.
92 + * Output: returns YES on success, NO if no tdline removed.
93 + * Side effects: Any matching tdlines are removed.
94 + */
95 + static int
96 + remove_dline_match(const char *host)
97 + {
98 +  struct irc_ssaddr iphost, *piphost;
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 +      aftype = AF_INET6;
108 +    else
109 + #endif
110 +      aftype = AF_INET;
111 +    piphost = &iphost;
112 +  }
113 +  else
114 +    piphost = NULL;
115 +
116 +  if ((conf = find_conf_by_address(host, piphost, CONF_DLINE | 1, aftype, NULL, NULL, 0)))
117 +  {
118 +    if (IsConfDatabase(conf))
119 +    {
120 +      delete_one_address_conf(host, conf);
121 +      return 1;
122 +    }
123 +  }
124 +
125 +  return 0;
126 + }
127 +
128   /* mo_dline()
129   *
130   * inputs       - pointer to server
# Line 90 | Line 139 | static void
139   mo_dline(struct Client *client_p, struct Client *source_p,
140           int parc, char *parv[])
141   {
142 <  char def_reason[] = "No reason";
143 <  char *dlhost, *oper_reason, *reason;
142 >  char def_reason[] = "<No reason specified>";
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;
99 <  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];
153 >  char hostip[HOSTIPLEN + 1];
154    char buffer[IRCD_BUFSIZE];
155  
156 <  if (!HasOFlag(source_p, OPER_FLAG_K))
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  
163    if (parse_aline("DLINE", source_p,  parc, parv, AWILD, &dlhost,
164 <                  NULL, &tkline_time, NULL, &reason) < 0)
164 >                  NULL, &tkline_time, &target_server, &reason) < 0)
165      return;
166  
167 +  if (target_server != NULL)
168 +  {
169 +    if (HasID(source_p))
170 +    {
171 +      sendto_server(NULL, CAP_DLN|CAP_TS6, NOCAPS,
172 +                    ":%s DLINE %s %lu %s :%s",
173 +                    source_p->id, target_server, (unsigned long)tkline_time,
174 +                    dlhost, reason);
175 +      sendto_server(NULL, CAP_DLN, CAP_TS6,
176 +                    ":%s DLINE %s %lu %s :%s",
177 +                    source_p->name, target_server, (unsigned long)tkline_time,
178 +                    dlhost, reason);
179 +    }
180 +    else
181 +      sendto_server(NULL, CAP_DLN, NOCAPS,
182 +                    ":%s DLINE %s %lu %s :%s",
183 +                    source_p->name, target_server, (unsigned long)tkline_time,
184 +                    dlhost, reason);
185 +
186 +    /* Allow ON to apply local kline as well if it matches */
187 +    if (match(target_server, me.name))
188 +      return;
189 +  }
190 +  else
191 +    cluster_a_line(source_p, "DLINE", CAP_DLN, SHARED_DLINE,
192 +                   "%d %s :%s", tkline_time, dlhost, reason);
193 +
194    if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
195    {
196      if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL)
# Line 154 | 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  
181  /* Look for an oper reason */
182  if ((oper_reason = strchr(reason, '|')) != NULL)
183    *oper_reason++ = '\0';
184
257    if (!valid_comment(source_p, reason, 1))
258      return;
259  
260 <  conf = make_conf_item(DLINE_TYPE);
261 <  aconf = map_to_conf(conf);
190 <  DupString(aconf->host, dlhost);
260 >  conf = conf_make(CONF_DLINE);
261 >  conf->host = xstrdup(dlhost);
262  
263    if (tkline_time != 0)
193  {
264      snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
265               (int)(tkline_time/60), reason, current_date);
196    DupString(aconf->reason, buffer);
197    if (oper_reason != NULL)
198      DupString(aconf->oper_reason, oper_reason);
199    apply_tdline(source_p, conf, current_date, tkline_time);
200  }
266    else
202  {
267      snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
204    DupString(aconf->reason, buffer);
205    if (oper_reason != NULL)
206      DupString(aconf->oper_reason, oper_reason);
207    add_conf_by_address(CONF_DLINE, aconf);
208    write_conf_line(source_p, conf, current_date, cur_time);
209  }
268  
269 +  conf->reason = xstrdup(buffer);
270 +  apply_dline(source_p, conf, tkline_time);
271    rehashed_klines = 1;
272   }
273  
274 < /* static int remove_tdline_match(const char *host, const char *user)
275 < * Input: An ip to undline.
276 < * Output: returns YES on success, NO if no tdline removed.
217 < * Side effects: Any matching tdlines are removed.
218 < */
219 < static int
220 < remove_tdline_match(const char *cidr)
274 > static void
275 > ms_dline(struct Client *client_p, struct Client *source_p,
276 >         int parc, char *parv[])
277   {
278 <  struct AccessItem *td_conf;
279 <  dlink_node *td_node;
280 <  struct irc_ssaddr addr, caddr;
281 <  int nm_t, cnm_t, bits, cbits;
282 <  nm_t = parse_netmask(cidr, &addr, &bits);
283 <
284 <  DLINK_FOREACH(td_node, temporary_dlines.head)
278 >  char def_reason[] = "<No reason specified>";
279 >  char *dlhost, *reason;
280 >  const char *creason;
281 >  const struct Client *target_p = NULL;
282 >  struct irc_ssaddr daddr;
283 >  struct MaskItem *conf=NULL;
284 >  time_t tkline_time=0;
285 >  int bits = 0, aftype = 0, t = 0;
286 >  const char *current_date = NULL;
287 >  time_t cur_time;
288 >  char hostip[HOSTIPLEN + 1];
289 >  char buffer[IRCD_BUFSIZE];
290 >
291 >  if (parc != 5 || EmptyString(parv[4]))
292 >    return;
293 >
294 >  /* parv[0]  parv[1]        parv[2]      parv[3]  parv[4] */
295 >  /* oper     target_server  tkline_time  host     reason  */
296 >  sendto_match_servs(source_p, parv[1], CAP_DLN,
297 >                     "DLINE %s %s %s :%s",
298 >                     parv[1], parv[2], parv[3], parv[4]);
299 >
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(CONF_ULINE, source_p->servptr->name,
308 >                              source_p->username, source_p->host,
309 >                              SHARED_DLINE))
310    {
311 <    td_conf = map_to_conf(td_node->data);
312 <    cnm_t   = parse_netmask(td_conf->host, &caddr, &cbits);
311 >    if (!IsClient(source_p))
312 >      return;
313 >    if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
314 >    {
315 >      if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL)
316 >        return;
317 >
318 >      if (!MyConnect(target_p))
319 >      {
320 >        sendto_one(source_p,
321 >                   ":%s NOTICE %s :Can't DLINE nick on another server",
322 >                   me.name, source_p->name);
323 >        return;
324 >      }
325 >
326 >      if (IsExemptKline(target_p))
327 >      {
328 >        sendto_one(source_p,
329 >                   ":%s NOTICE %s :%s is E-lined", me.name,
330 >                   source_p->name, target_p->name);
331 >        return;
332 >      }
333 >
334 >      getnameinfo((struct sockaddr *)&target_p->localClient->ip,
335 >                  target_p->localClient->ip.ss_len, hostip,
336 >                  sizeof(hostip), NULL, 0, NI_NUMERICHOST);
337 >      dlhost = hostip;
338 >      t = parse_netmask(dlhost, NULL, &bits);
339 >      assert(t == HM_IPV4 || t == HM_IPV6);
340 >    }
341  
342 <    if (cnm_t != nm_t)
343 <      continue;
342 >    if (bits < 8)
343 >    {
344 >      sendto_one(source_p,
345 >                 ":%s NOTICE %s :For safety, bitmasks less than 8 require conf access.",
346 >                 me.name, source_p->name);
347 >      return;
348 >    }
349  
236    if((nm_t==HM_HOST && !irccmp(td_conf->host, cidr)) ||
237       (nm_t==HM_IPV4 && bits==cbits && match_ipv4(&addr, &caddr, bits))
350   #ifdef IPV6
351 <       || (nm_t==HM_IPV6 && bits==cbits && match_ipv6(&addr, &caddr, bits))
351 >    if (t == HM_IPV6)
352 >      aftype= AF_INET6;
353 >    else
354   #endif
355 <      )
355 >      aftype = AF_INET;
356 >
357 >    parse_netmask(dlhost, &daddr, NULL);
358 >
359 >    if ((conf = find_dline_conf(&daddr, aftype)) != NULL)
360      {
361 <      dlinkDelete(td_node, &temporary_dlines);
362 <      delete_one_address_conf(td_conf->host, td_conf);
363 <      return 1;
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, 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, conf->host, creason);
370 >      return;
371      }
247  }
372  
373 <  return 0;
373 >    cur_time = CurrentTime;
374 >    current_date = smalldate(cur_time);
375 >
376 >    if (!valid_comment(source_p, reason, 1))
377 >      return;
378 >
379 >    conf = conf_make(CONF_DLINE);
380 >    conf->host = xstrdup(dlhost);
381 >
382 >    if (tkline_time != 0)
383 >      snprintf(buffer, sizeof(buffer), "Temporary D-line %d min. - %s (%s)",
384 >               (int)(tkline_time/60), reason, current_date);
385 >    else
386 >      snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
387 >
388 >    conf->reason = xstrdup(buffer);
389 >    apply_dline(source_p, conf, tkline_time);
390 >    rehashed_klines = 1;
391 >  }
392   }
393  
394   /*
# Line 262 | Line 404 | static void
404   mo_undline(struct Client *client_p, struct Client *source_p,
405             int parc, char *parv[])
406   {
407 <  const char *cidr = NULL;
407 >  char *addr = NULL, *user = NULL;
408 >  char *target_server = NULL;
409  
410 <  if (!HasOFlag(source_p, OPER_FLAG_UNKLINE))
410 >  if (!HasOFlag(source_p, OPER_FLAG_UNDLINE))
411    {
412      sendto_one(source_p, form_str(ERR_NOPRIVS),
413                 me.name, source_p->name, "undline");
414      return;
415    }
416  
417 <  cidr = parv[1];
275 <
276 <  if (remove_tdline_match(cidr))
417 >  if (parc < 2 || EmptyString(parv[1]))
418    {
419 <    sendto_one(source_p,
420 <              ":%s NOTICE %s :Un-Dlined [%s] from temporary D-Lines",
280 <              me.name, source_p->name, cidr);
281 <    sendto_realops_flags(UMODE_ALL, L_ALL,
282 <                         "%s has removed the temporary D-Line for: [%s]",
283 <                         get_oper_name(source_p), cidr);
284 <    ilog(LOG_TYPE_DLINE, "%s removed temporary D-Line for [%s]", source_p->name, cidr);
419 >    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
420 >               me.name, source_p->name, "UNDLINE");
421      return;
422    }
423  
424 <  if (remove_conf_line(DLINE_TYPE, source_p, cidr, NULL) > 0)
425 <  {
426 <    sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed",
427 <               me.name, source_p->name, cidr);
428 <    sendto_realops_flags(UMODE_ALL, L_ALL,
429 <                         "%s has removed the D-Line for: [%s]",
430 <                         get_oper_name(source_p), cidr);
424 >  if (parse_aline("UNDLINE", source_p, parc, parv, 0, &user,
425 >                  &addr, NULL, &target_server, NULL) < 0)
426 >    return;
427 >
428 >  if (target_server != NULL)
429 >  {
430 >    sendto_match_servs(source_p, target_server, CAP_UNDLN,
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))
435 >      return;
436 >  }
437 >  else
438 >    cluster_a_line(source_p, "UNDLINE", CAP_UNDLN, SHARED_UNDLINE,
439 >                   "%s", addr);
440 >
441 >  if (remove_dline_match(addr))
442 >  {
443 >    sendto_one(source_p,
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, SEND_NOTICE,
447 >                         "%s has removed the D-Line for: [%s]",
448 >                         get_oper_name(source_p), addr);
449      ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
450 <         get_oper_name(source_p), cidr);
450 >         get_oper_name(source_p), addr);
451    }
452    else
453      sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found",
454 <               me.name, source_p->name, cidr);
454 >               me.name, source_p->name, addr);
455 > }
456 >
457 > static void
458 > me_undline(struct Client *client_p, struct Client *source_p,
459 >           int parc, char *parv[])
460 > {
461 >  const char *addr = NULL;
462 >
463 >  if (parc != 3 || EmptyString(parv[2]))
464 >    return;
465 >
466 >  addr = parv[2];
467 >
468 >  if (!IsClient(source_p) || match(parv[1], me.name))
469 >    return;
470 >
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_dline_match(addr))
477 >    {
478 >      sendto_one(source_p,
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, 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 temporary D-Line for [%s]",
485 >           get_oper_name(source_p), addr);
486 >    }
487 >    else
488 >      sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found",
489 >                 me.name, source_p->name, addr);
490 >  }
491 > }
492 >
493 > static void
494 > ms_undline(struct Client *client_p, struct Client *source_p,
495 >           int parc, char *parv[])
496 > {
497 >  if (parc != 3 || EmptyString(parv[2]))
498 >    return;
499 >
500 >  sendto_match_servs(source_p, parv[1], CAP_UNDLN,
501 >                     "UNDLINE %s %s",
502 >                     parv[1], parv[2]);
503 >
504 >  me_undline(client_p, source_p, parc, parv);
505   }
506  
507   static struct Message dline_msgtab = {
508    "DLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
509 <   {m_unregistered, m_not_oper, rfc1459_command_send_error, m_ignore, mo_dline, m_ignore}
509 >   {m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore}
510   };
511  
512   static struct Message undline_msgtab = {
513    "UNDLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
514 <   {m_unregistered, m_not_oper, rfc1459_command_send_error, m_ignore, mo_undline, m_ignore}
514 >   {m_unregistered, m_not_oper, ms_undline, m_ignore, mo_undline, m_ignore}
515   };
516  
517   static void
# Line 315 | Line 519 | module_init(void)
519   {
520    mod_add_cmd(&dline_msgtab);
521    mod_add_cmd(&undline_msgtab);
522 +  add_capability("DLN", CAP_DLN, 1);
523 +  add_capability("UNDLN", CAP_UNDLN, 1);
524   }
525  
526   static void
# Line 322 | Line 528 | module_exit(void)
528   {
529    mod_del_cmd(&dline_msgtab);
530    mod_del_cmd(&undline_msgtab);
531 +  delete_capability("UNDLN");
532 +  delete_capability("DLN");
533   }
534  
535   struct module module_entry = {

Diff Legend

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