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 1300 by michael, Tue Feb 28 18:51:13 2012 UTC vs.
Revision 1301 by michael, Sat Mar 10 21:47:17 2012 UTC

# Line 127 | Line 127 | static void
127   mo_dline(struct Client *client_p, struct Client *source_p,
128           int parc, char *parv[])
129   {
130 <  char def_reason[] = "No reason";
131 <  char *dlhost, *oper_reason, *reason;
130 >  char def_reason[] = "<No reason specified>";
131 >  char *dlhost = NULL, *oper_reason = NULL, *reason = NULL;
132 >  char *target_server = NULL;
133    const char *creason;
134    const struct Client *target_p = NULL;
135    struct irc_ssaddr daddr;
# Line 141 | Line 142 | mo_dline(struct Client *client_p, struct
142    char hostip[HOSTIPLEN];
143    char buffer[IRCD_BUFSIZE];
144  
145 <  if (!HasOFlag(source_p, OPER_FLAG_K))
145 >  if (!HasOFlag(source_p, OPER_FLAG_DLINE))
146    {
147      sendto_one(source_p, form_str(ERR_NOPRIVS),
148                 me.name, source_p->name, "kline");
# Line 149 | Line 150 | mo_dline(struct Client *client_p, struct
150    }
151  
152    if (parse_aline("DLINE", source_p,  parc, parv, AWILD, &dlhost,
153 <                  NULL, &tkline_time, NULL, &reason) < 0)
153 >                  NULL, &tkline_time, &target_server, &reason) < 0)
154      return;
155  
156 +  if (target_server != NULL)
157 +  {
158 +    if (HasID(source_p))
159 +    {
160 +      sendto_server(NULL, NULL, CAP_DLN|CAP_TS6, NOCAPS,
161 +                    ":%s DLINE %s %lu %s :%s",
162 +                    source_p->id, target_server, (unsigned long)tkline_time,
163 +                    dlhost, reason);
164 +      sendto_server(NULL, NULL, CAP_DLN, CAP_TS6,
165 +                    ":%s DLINE %s %lu %s :%s",
166 +                    source_p->name, target_server, (unsigned long)tkline_time,
167 +                    dlhost, reason);
168 +    }
169 +    else
170 +      sendto_server(NULL, NULL, CAP_DLN, NOCAPS,
171 +                    ":%s DLINE %s %lu %s :%s",
172 +                    source_p->name, target_server, (unsigned long)tkline_time,
173 +                    dlhost, reason);
174 +
175 +    /* Allow ON to apply local kline as well if it matches */
176 +    if (!match(target_server, me.name))
177 +      return;
178 +  }
179 +  else
180 +    cluster_a_line(source_p, "DLINE", CAP_DLN, SHARED_DLINE,
181 +                   "%d %s :%s", tkline_time, dlhost, reason);
182 +
183    if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
184    {
185      if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL)
# Line 248 | Line 276 | mo_dline(struct Client *client_p, struct
276    rehashed_klines = 1;
277   }
278  
279 + static void
280 + ms_dline(struct Client *client_p, struct Client *source_p,
281 +         int parc, char *parv[])
282 + {
283 +  char def_reason[] = "<No reason specified>";
284 +  char *dlhost, *oper_reason, *reason;
285 +  const char *creason;
286 +  const struct Client *target_p = NULL;
287 +  struct irc_ssaddr daddr;
288 +  struct ConfItem *conf=NULL;
289 +  struct AccessItem *aconf=NULL;
290 +  time_t tkline_time=0;
291 +  int bits, t;
292 +  const char *current_date = NULL;
293 +  time_t cur_time;
294 +  char hostip[HOSTIPLEN];
295 +  char buffer[IRCD_BUFSIZE];
296 +
297 +  if (parc != 5 || EmptyString(parv[4]))
298 +    return;
299 +
300 +  /* parv[0]  parv[1]        parv[2]      parv[3]  parv[4] */
301 +  /* oper     target_server  tkline_time  host     reason  */
302 +  sendto_match_servs(source_p, parv[1], CAP_DLN,
303 +                     "DLINE %s %s %s :%s",
304 +                     parv[1], parv[2], parv[3], parv[4]);
305 +
306 +  if (!match(parv[1], me.name))
307 +    return;
308 +
309 +  tkline_time = valid_tkline(parv[2], TK_SECONDS);
310 +  dlhost = parv[3];
311 +  reason = parv[4];
312 +
313 +  if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(ULINE_TYPE, source_p->servptr->name,
314 +                              source_p->username, source_p->host,
315 +                              SHARED_DLINE))
316 +  {
317 +    if (!IsClient(source_p))
318 +      return;
319 +    if ((t = parse_netmask(dlhost, NULL, &bits)) == HM_HOST)
320 +    {
321 +      if ((target_p = find_chasing(client_p, source_p, dlhost, NULL)) == NULL)
322 +        return;
323 +
324 +      if (!MyConnect(target_p))
325 +      {
326 +        sendto_one(source_p,
327 +                   ":%s NOTICE %s :Can't DLINE nick on another server",
328 +                   me.name, source_p->name);
329 +        return;
330 +      }
331 +
332 +      if (IsExemptKline(target_p))
333 +      {
334 +        sendto_one(source_p,
335 +                   ":%s NOTICE %s :%s is E-lined", me.name,
336 +                   source_p->name, target_p->name);
337 +        return;
338 +      }
339 +
340 +      getnameinfo((struct sockaddr *)&target_p->localClient->ip,
341 +                  target_p->localClient->ip.ss_len, hostip,
342 +                  sizeof(hostip), NULL, 0, NI_NUMERICHOST);
343 +      dlhost = hostip;
344 +      t = parse_netmask(dlhost, NULL, &bits);
345 +      assert(t == HM_IPV4 || t == HM_IPV6);
346 +    }
347 +
348 +    if (bits < 8)
349 +    {
350 +      sendto_one(source_p,
351 +                 ":%s NOTICE %s :For safety, bitmasks less than 8 require conf access.",
352 +                 me.name, source_p->name);
353 +      return;
354 +    }
355 +
356 + #ifdef IPV6
357 +    if (t == HM_IPV6)
358 +      t = AF_INET6;
359 +    else
360 + #endif
361 +      t = AF_INET;
362 +
363 +    parse_netmask(dlhost, &daddr, NULL);
364 +
365 +    if ((aconf = find_dline_conf(&daddr, t)) != NULL)
366 +    {
367 +      creason = aconf->reason ? aconf->reason : def_reason;
368 +      if (IsConfExemptKline(aconf))
369 +        sendto_one(source_p,
370 +                   ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
371 +                   me.name, source_p->name, dlhost, aconf->host, creason);
372 +      else
373 +        sendto_one(source_p,
374 +                   ":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
375 +                   me.name, source_p->name, dlhost, aconf->host, creason);
376 +      return;
377 +    }
378 +
379 +    cur_time = CurrentTime;
380 +    current_date = smalldate(cur_time);
381 +
382 +    /* Look for an oper reason */
383 +    if ((oper_reason = strchr(reason, '|')) != NULL)
384 +      *oper_reason++ = '\0';
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 +      if (oper_reason != NULL)
399 +        DupString(aconf->oper_reason, oper_reason);
400 +      apply_tdline(source_p, conf, current_date, tkline_time);
401 +    }
402 +    else
403 +    {
404 +      snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date);
405 +      DupString(aconf->reason, buffer);
406 +      if (oper_reason != NULL)
407 +        DupString(aconf->oper_reason, oper_reason);
408 +      add_conf_by_address(CONF_DLINE, aconf);
409 +      write_conf_line(source_p, conf, current_date, cur_time);
410 +    }
411 +
412 +    rehashed_klines = 1;
413 +  }
414 + }
415 +
416   /*
417   ** m_undline
418   ** added May 28th 2000 by Toby Verrall <toot@melnet.co.uk>
# Line 261 | Line 426 | static void
426   mo_undline(struct Client *client_p, struct Client *source_p,
427             int parc, char *parv[])
428   {
429 <  const char *addr = NULL;
429 >  char *addr = NULL, *user = NULL;
430 >  char *target_server = NULL;
431  
432 <  if (!HasOFlag(source_p, OPER_FLAG_UNKLINE))
432 >  if (!HasOFlag(source_p, OPER_FLAG_UNDLINE))
433    {
434      sendto_one(source_p, form_str(ERR_NOPRIVS),
435                 me.name, source_p->name, "undline");
436      return;
437    }
438  
439 <  addr = parv[1];
439 >  if (parc < 2 || EmptyString(parv[1]))
440 >  {
441 >    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
442 >               me.name, source_p->name, "UNDLINE");
443 >    return;
444 >  }
445 >
446 >  if (parse_aline("UNDLINE", source_p, parc, parv, 0, &user,
447 >                  &addr, NULL, &target_server, NULL) < 0)
448 >    return;
449 >
450 >  if (target_server != NULL)
451 >  {
452 >    sendto_match_servs(source_p, target_server, CAP_UNDLN,
453 >                       "UNDLINE %s %s", target_server, addr);
454 >
455 >    /* Allow ON to apply local unkline as well if it matches */
456 >    if (!match(target_server, me.name))
457 >      return;
458 >  }
459 >  else
460 >    cluster_a_line(source_p, "UNDLINE", CAP_UNDLN, SHARED_UNDLINE,
461 >                   "%s", addr);
462  
463    if (remove_tdline_match(addr))
464    {
465      sendto_one(source_p,
466 <              ":%s NOTICE %s :Un-Dlined [%s] from temporary D-Lines",
467 <              me.name, source_p->name, addr);
466 >               ":%s NOTICE %s :Un-Dlined [%s] from temporary D-Lines",
467 >               me.name, source_p->name, addr);
468      sendto_realops_flags(UMODE_ALL, L_ALL,
469                           "%s has removed the temporary D-Line for: [%s]",
470                           get_oper_name(source_p), addr);
471 <    ilog(LOG_TYPE_DLINE, "%s removed temporary D-Line for [%s]", source_p->name, addr);
471 >    ilog(LOG_TYPE_DLINE, "%s removed temporary D-Line for [%s]",
472 >         source_p->name, addr);
473      return;
474    }
475  
# Line 299 | Line 488 | mo_undline(struct Client *client_p, stru
488                 me.name, source_p->name, addr);
489   }
490  
491 + static void
492 + me_undline(struct Client *client_p, struct Client *source_p,
493 +           int parc, char *parv[])
494 + {
495 +  const char *addr = NULL;
496 +
497 +  if (parc != 3 || EmptyString(parv[2]))
498 +    return;
499 +
500 +  addr = parv[2];
501 +
502 +  if (!IsClient(source_p) || !match(parv[1], me.name))
503 +    return;
504 +
505 +  if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(ULINE_TYPE,
506 +                                   source_p->servptr->name,
507 +                                   source_p->username, source_p->host,
508 +                                   SHARED_UNDLINE))
509 +  {
510 +    if (remove_tdline_match(addr))
511 +    {
512 +      sendto_one(source_p,
513 +                 ":%s NOTICE %s :Un-Dlined [%s] from temporary D-Lines",
514 +                 me.name, source_p->name, addr);
515 +      sendto_realops_flags(UMODE_ALL, L_ALL,
516 +                           "%s has removed the temporary D-Line for: [%s]",
517 +                           get_oper_name(source_p), addr);
518 +      ilog(LOG_TYPE_DLINE, "%s removed temporary D-Line for [%s]",
519 +           source_p->name, addr);
520 +      return;
521 +    }
522 +
523 +    if (remove_conf_line(DLINE_TYPE, source_p, addr, NULL) > 0)
524 +    {
525 +      sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed",
526 +                 me.name, source_p->name, addr);
527 +      sendto_realops_flags(UMODE_ALL, L_ALL,
528 +                           "%s has removed the D-Line for: [%s]",
529 +                           get_oper_name(source_p), addr);
530 +      ilog(LOG_TYPE_DLINE, "%s removed D-Line for [%s]",
531 +           get_oper_name(source_p), addr);
532 +    }
533 +    else
534 +      sendto_one(source_p, ":%s NOTICE %s :No D-Line for [%s] found",
535 +                 me.name, source_p->name, addr);
536 +  }
537 + }
538 +
539 + static void
540 + ms_undline(struct Client *client_p, struct Client *source_p,
541 +           int parc, char *parv[])
542 + {
543 +  if (parc != 3 || EmptyString(parv[2]))
544 +    return;
545 +
546 +  sendto_match_servs(source_p, parv[1], CAP_UNDLN,
547 +                     "UNDLINE %s %s %s",
548 +                     parv[1], parv[2]);
549 +
550 +  me_undline(client_p, source_p, parc, parv);
551 + }
552 +
553   static struct Message dline_msgtab = {
554    "DLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
555 <   {m_unregistered, m_not_oper, rfc1459_command_send_error, m_ignore, mo_dline, m_ignore}
555 >   {m_unregistered, m_not_oper, ms_dline, m_ignore, mo_dline, m_ignore}
556   };
557  
558   static struct Message undline_msgtab = {
559    "UNDLINE", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
560 <   {m_unregistered, m_not_oper, rfc1459_command_send_error, m_ignore, mo_undline, m_ignore}
560 >   {m_unregistered, m_not_oper, ms_undline, m_ignore, mo_undline, m_ignore}
561   };
562  
563   static void
# Line 314 | Line 565 | module_init(void)
565   {
566    mod_add_cmd(&dline_msgtab);
567    mod_add_cmd(&undline_msgtab);
568 +  add_capability("DLN", CAP_DLN, 1);
569 +  add_capability("UNDLN", CAP_UNDLN, 1);
570   }
571  
572   static void
# Line 321 | Line 574 | module_exit(void)
574   {
575    mod_del_cmd(&dline_msgtab);
576    mod_del_cmd(&undline_msgtab);
577 +  delete_capability("UNDLN");
578 +  delete_capability("DLN");
579   }
580  
581   struct module module_entry = {

Diff Legend

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