ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_gline.c
(Generate patch)

Comparing ircd-hybrid-7.2/modules/m_gline.c (file contents):
Revision 940 by db, Sat May 2 02:01:54 2009 UTC vs.
Revision 957 by michael, Tue Jul 28 18:47:23 2009 UTC

# Line 59 | Line 59 | extern dlink_list gdeny_items;
59   /* internal functions */
60   static void set_local_gline(const struct Client *,
61                              const char *, const char *, const char *);
62 < static int remove_gline_match(const char *user, const char *host);
62 > static int remove_gline_match(const char *, const char *);
63  
64   #ifdef GLINE_VOTING
65 < static int check_majority(int isungline, const struct Client *,
66 <                          const char *, const char *, const char *);
65 > static int check_majority(const struct Client *, const char *,
66 >                          const char *, const char *, int);
67  
68   static void add_new_majority(const struct Client *,
69                               const char *, const char *, const char *);
# Line 100 | Line 100 | struct Message ungline_msgtab = {
100   void
101   _modinit(void)
102   {
103 <    mod_add_cmd(&gline_msgtab);
104 <    mod_add_cmd(&ungline_msgtab);
105 <    add_capability("GLN", CAP_GLN, 1);
103 >  mod_add_cmd(&gline_msgtab);
104 >  mod_add_cmd(&ungline_msgtab);
105 >  add_capability("GLN", CAP_GLN, 1);
106   }
107  
108   void
# Line 419 | Line 419 | set_local_gline(const struct Client *sou
419  
420    current_date = smalldate(cur_time);
421    conf = make_conf_item(GLINE_TYPE);
422 <  aconf = (struct AccessItem *)map_to_conf(conf);
422 >  aconf = map_to_conf(conf);
423  
424    ircsprintf(buffer, "%s (%s)", reason, current_date);
425    DupString(aconf->reason, buffer);
# Line 458 | Line 458 | set_local_gline(const struct Client *sou
458   * for more information.
459   */
460   static void
461 < add_new_majority(const struct Client *source_p,
462 <                 const char *user, const char *host, const char *reason)
461 > add_new_majority(const struct Client *source_p, const char *user,
462 >                 const char *host, const char *reason)
463   {
464    struct gline_pending *pending = MyMalloc(sizeof(struct gline_pending));
465  
466 <  strlcpy(pending->oper_nick1, source_p->name, sizeof(pending->oper_nick1));
467 <  strlcpy(pending->oper_user1, source_p->username, sizeof(pending->oper_user1));
468 <  strlcpy(pending->oper_host1, source_p->host, sizeof(pending->oper_host1));
469 <
470 <  strlcpy(pending->oper_server1, source_p->servptr->name, sizeof(pending->oper_server1));
466 >  strlcpy(pending->vote_1.oper_nick, source_p->name, sizeof(pending->vote_1.oper_nick));
467 >  strlcpy(pending->vote_1.oper_user, source_p->username, sizeof(pending->vote_1.oper_user));
468 >  strlcpy(pending->vote_1.oper_host, source_p->host, sizeof(pending->vote_1-oper_host));
469 >  strlcpy(pending->vote_1.oper_server, source_p->servptr->name, sizeof(pending->vote_1.oper_server));
470  
471    strlcpy(pending->user, user, sizeof(pending->user));
472    strlcpy(pending->host, host, sizeof(pending->host));
473 <  strlcpy(pending->reason1, reason, sizeof(pending->reason1));
473 >  strlcpy(pending->vote_1.reason, reason, sizeof(pending->vote_1.reason));
474  
475    pending->last_gline_time = CurrentTime;
476    pending->time_request1   = CurrentTime;
477  
478 <  dlinkAdd(pending, &pending->node, &pending_glines);
478 >  dlinkAdd(pending, &pending->node, &pending_glines[GLINE_PENDING_ADD_TYPE]);
479   }
480  
481   /* check_majority()
# Line 495 | Line 494 | add_new_majority(const struct Client *so
494   *
495   */
496   static int
497 < check_majority(int isungline, const struct Client *source_p,
498 <               const char *user, const char *host, const char *reason)
497 > check_majority(const struct Client *source_p, const char *user,
498 >               const char *host, const char *reason, int type)
499   {
500 <  dlink_node *pending_node;
502 <  struct gline_pending *gline_pending_ptr;
503 <  char ckuser[USERLEN * 2 + 2];
500 >  dlink_node *dn_ptr = NULL;
501  
502 <  /* if its already glined, why bother? :) -- fl_ */
506 <  if (!isungline && find_is_glined(host, user))
507 <    return(GLINE_NOT_PLACED);
502 >  cleanup_glines(NULL);
503  
504 <  if (isungline)
505 <    ircsprintf(ckuser, "-%s", user);
506 <  else
512 <    ircsprintf(ckuser, "%s", user);
504 >  /* if its already glined, why bother? :) -- fl_ */
505 >  if ((type == GLINE_PENDING_ADD_TYPE) && find_is_glined(host, user))
506 >    return GLINE_NOT_PLACED;
507  
508 <  /* special case condition where there are no pending glines */
515 <  if (dlink_list_length(&pending_glines) == 0) /* first gline request placed */
508 >  DLINK_FOREACH(dn_ptr, pending_glines[type].head)
509    {
510 <    add_new_majority(source_p, ckuser, host, reason);
518 <    return(GLINE_NOT_PLACED);
519 <  }
510 >    struct gline_pending *gp_ptr = dn_ptr->data;
511  
512 <  DLINK_FOREACH(pending_node, pending_glines.head)
513 <  {
514 <    gline_pending_ptr = pending_node->data;
512 >    if (irccmp(gp_ptr->user, user) ||
513 >        irccmp(gp_ptr->host, host))
514 >      continue;
515  
516 <    if ((irccmp(gline_pending_ptr->user, ckuser) == 0) &&
517 <        (irccmp(gline_pending_ptr->host, host) == 0))
518 <    {
519 <      if (((irccmp(gline_pending_ptr->oper_user1, source_p->username) == 0) ||
529 <           (irccmp(gline_pending_ptr->oper_host1, source_p->host) == 0)) ||
530 <          (irccmp(gline_pending_ptr->oper_server1, source_p->servptr->name) == 0))
531 <      {
532 <        return(GLINE_ALREADY_VOTED);
533 <      }
516 >    if (!irccmp(gp_ptr->vote_1.oper_user, source_p->username) ||
517 >        !irccmp(gp_ptr->vote_1.oper_host, source_p->host)     ||
518 >        !irccmp(gp_ptr->vote_1.oper_server, source_p->servptr->name))
519 >      return GLINE_ALREADY_VOTED;
520  
521 <      if (gline_pending_ptr->oper_user2[0] != '\0')
522 <      {
521 >    if (gp_ptr->vote_2.oper_user[0] != '\0')
522 >    {
523          /* if two other opers on two different servers have voted yes */
524 +      if (!irccmp(gp_ptr->vote_2.oper_user, source_p->username) ||
525 +          !irccmp(gp_ptr->vote_2.oper_host, source_p->host)     ||
526 +          !irccmp(gp_ptr->vote_2.oper_server, source_p->servptr->name))
527 +        return GLINE_ALREADY_VOTED;
528  
529 <        if(((irccmp(gline_pending_ptr->oper_user2, source_p->username)==0) ||
530 <            (irccmp(gline_pending_ptr->oper_host2, source_p->host)==0)) ||
531 <           (irccmp(gline_pending_ptr->oper_server2, source_p->servptr->name)==0))
532 <        {
533 <          return(GLINE_ALREADY_VOTED);
534 <        }
535 <
536 <        if(gline_pending_ptr->user[0] == '-')
537 <        {
538 <          if (remove_gline_match(user, host))
549 <          {
550 <            sendto_one(source_p, ":%s NOTICE %s :G-Line for [%s@%s] is removed",
551 <                       me.name, source_p->name, user, host);
552 <            sendto_realops_flags(UMODE_ALL, L_ALL,
553 <                                 "%s has removed the G-Line for: [%s@%s]",
554 <                                 get_oper_name(source_p), user, host);
555 <            ilog(L_NOTICE, "%s removed G-Line for [%s@%s]",
556 <                 get_oper_name(source_p), user, host);
557 <          }
558 <          else
559 <          {
560 <            sendto_one(source_p, ":%s NOTICE %s :No G-Line for %s@%s",
561 <                       me.name, source_p->name, user, host);
562 <          }
563 <        }
564 <        else
565 <        {
566 <          /* trigger the gline using the original reason --fl */
567 <          set_local_gline(source_p, user, host, gline_pending_ptr->reason1);
568 <          cleanup_glines(NULL);
569 <          return(GLINE_PLACED);
570 <        }
529 >      if (type == GLINE_PENDING_DEL_TYPE)
530 >      {
531 >        if (remove_gline_match(user, host))
532 >        {
533 >          sendto_realops_flags(UMODE_ALL, L_ALL,
534 >                               "%s has removed the G-Line for: [%s@%s]",
535 >                               get_oper_name(source_p), user, host);
536 >          ilog(L_NOTICE, "%s removed G-Line for [%s@%s]",
537 >              get_oper_name(source_p), user, host);
538 >        }
539        }
540 +      else
541 +        /* trigger the gline using the original reason --fl */
542 +        set_local_gline(source_p, user, host, gp_ptr->vote_1.reason);
543 +
544 +      cleanup_glines(gp_ptr);
545 +      return GLINE_PLACED;
546      }
547 <    else
548 <    {
549 <      strlcpy(gline_pending_ptr->oper_nick2, source_p->name,
550 <              sizeof(gline_pending_ptr->oper_nick2));
551 <      strlcpy(gline_pending_ptr->oper_user2, source_p->username,
552 <              sizeof(gline_pending_ptr->oper_user2));
553 <      strlcpy(gline_pending_ptr->oper_host2, source_p->host,
554 <              sizeof(gline_pending_ptr->oper_host2));
555 <      strlcpy(gline_pending_ptr->reason2, reason,
556 <              sizeof(gline_pending_ptr->reason2));
557 <      strlcpy(gline_pending_ptr->oper_server2, source_p->servptr->name,
558 <              sizeof(gline_pending_ptr->oper_server2));
559 <      gline_pending_ptr->last_gline_time = CurrentTime;
560 <      gline_pending_ptr->time_request2 = CurrentTime;
587 <      return(GLINE_NOT_PLACED);
588 <    }
547 >
548 >    strlcpy(gp_ptr->vote2.oper_nick, source_p->name,
549 >            sizeof(gp_ptr->vote2.oper_nick));
550 >    strlcpy(gp_ptr->vote_2.oper_user, source_p->username,
551 >            sizeof(gp_ptr->vote_2.));
552 >    strlcpy(gp_ptr->vote_2.oper_host, source_p->host,
553 >            sizeof(gp_ptr->vote_2.oper_host));
554 >    strlcpy(gp_ptr->vote_2.reason, reason,
555 >            sizeof(gp_ptr->vote_2.reason));
556 >    strlcpy(gp_ptr->vote_2.oper_server, source_p->servptr->name,
557 >            sizeof(gp_ptr->vote_2.oper_server));
558 >    gp_ptr->last_gline_time = CurrentTime;
559 >    gp_ptr->vote_2.time_request = CurrentTime;
560 >    return GLINE_NOT_PLACED;
561    }
562  
563 <  /* Didn't find this user@host gline in pending gline list
563 >  /*
564 >   * Didn't find this user@host gline in pending gline list
565     * so add it.
566     */
567 <  add_new_majority(source_p, ckuser, host, reason);
568 <  return(GLINE_NOT_PLACED);
567 >  add_new_majority(source_p, user, host, reason);
568 >  return GLINE_NOT_PLACED;
569   }
570   #endif /* GLINE_VOTING */
571  
# Line 619 | Line 592 | remove_gline_match(const char *user, con
592   #ifdef IPV6
593       || (nm_t == HM_IPV6 && bits == cbits && match_ipv6(&addr, &caddr, bits))
594   #endif
595 <    )
595 >       )
596      {
597        dlinkDelete(ptr, &temporary_glines);
598        delete_one_address_conf(aconf->host, aconf);
599 <      return(1);
599 >      return 1;
600      }
601    }
602  
603 <  return(0);
603 >  return 0;
604   }
605  
606   /*
# Line 645 | Line 618 | remove_gline_match(const char *user, con
618  
619   static void
620   me_gungline(struct Client *client_p, struct Client *source_p,
621 <         int parc, char *parv[])
621 >            int parc, char *parv[])
622   {
623 +  if (!ConfigFileEntry.glines)
624 +    return;
625 +
626    do_sungline(client_p, source_p, parc, parv, 0);
627   }
628  
629   static void
630   do_sungline(struct Client *client_p, struct Client *source_p,
631 <          int parc, char *parv[], int prop)
631 >            int parc, char *parv[], int prop)
632   {
633    const char *reason = NULL;      /* reason for "victims" demise       */
634    char *user = NULL;
635    char *host = NULL;              /* user and host of GLINE "victim"   */
636 <  int var_offset = 0;
661 <  int logged = 0;
662 <  dlink_node *ptr;
663 <  struct ConfItem *conf;
664 <  struct AccessItem *aconf;
636 >  unsigned int var_offset = 0;
637  
638    assert(source_p->servptr != NULL);
639  
640 <  user = parv[++var_offset];
641 <  host = parv[++var_offset];
640 >  user   = parv[++var_offset];
641 >  host   = parv[++var_offset];
642    reason = parv[++var_offset];
643  
672  if (ConfigFileEntry.glines)
673  {
674    if (!valid_wild_card(source_p, YES, 2, user, host))
675      return;
676
644   #ifdef GLINE_VOTING
645 <     /* If at least 3 opers agree this user should be un G lined then do it */
646 <     if (check_majority(1, source_p, user, host, reason) ==
647 <         GLINE_ALREADY_VOTED)
648 <     {
649 <       sendto_realops_flags(UMODE_ALL, L_ALL, "oper or server has already voted");
650 <       return;
684 <     }
645 >  sendto_realops_flags(UMODE_ALL, L_ALL,
646 >                       "%s requesting UNG-Line for [%s@%s] [%s]",
647 >                       get_oper_name(source_p),
648 >                       user, host, reason);
649 >  ilog(L_TRACE, "#ungline for %s@%s [%s] requested by %s",
650 >       user, host, reason, get_oper_name(source_p));
651  
652 <     sendto_realops_flags(UMODE_ALL, L_ALL,
653 <                          "%s requesting UNG-Line for [%s@%s] [%s]",
654 <                          get_oper_name(source_p),
655 <                          user, host, reason);
690 <     ilog(L_TRACE, "#ungline for %s@%s [%s] requested by %s",
691 <          user, host, reason, get_oper_name(source_p));
652 >  /* If at least 3 opers agree this user should be un G lined then do it */
653 >  if (check_majority(1, source_p, user, host, reason) ==
654 >      GLINE_ALREADY_VOTED)
655 >    sendto_realops_flags(UMODE_ALL, L_ALL, "oper or server has already voted");
656   #else
657 <     if (remove_gline_match(user, host))
658 <     {
659 <       sendto_one(source_p, ":%s NOTICE %s :G-Line for [%s@%s] is removed",
660 <                  me.name, source_p->name, user, host);
661 <       sendto_realops_flags(UMODE_ALL, L_ALL,
662 <                            "%s has removed the G-Line for: [%s@%s]",
663 <                            get_oper_name(source_p), user, host);
700 <       ilog(L_NOTICE, "%s removed G-Line for [%s@%s]",
701 <            get_oper_name(source_p), user, host);
702 <     }
703 <     else
704 <     {
705 <       sendto_one(source_p, ":%s NOTICE %s :No G-Line for %s@%s",
706 <                  me.name, source_p->name, user, host);
707 <     }
708 < #endif /* GLINE_VOTING */
657 >  if (remove_gline_match(user, host))
658 >  {
659 >    sendto_realops_flags(UMODE_ALL, L_ALL,
660 >                         "%s has removed the G-Line for: [%s@%s]",
661 >                         get_oper_name(source_p), user, host);
662 >    ilog(L_NOTICE, "%s removed G-Line for [%s@%s]",
663 >    get_oper_name(source_p), user, host);
664    }
665 + #endif
666   }
667  
668   /* mo_gungline()
# Line 722 | Line 678 | do_sungline(struct Client *client_p, str
678   * GLINES is not defined.
679   *
680   */
725
681   static void
682   mo_gungline(struct Client *client_p, struct Client *source_p,
683 <           int parc, char *parv[])
683 >            int parc, char *parv[])
684   {
685    char *user = NULL;
686 <  char *host = NULL;         /* user and host of GLINE "victim" */
687 <  char *reason = NULL;       /* reason for "victims" demise     */
733 <  char encap_ungline[IRCD_BUFSIZE];
686 >  char *host = NULL;    /* user and host of GLINE "victim" */
687 >  char *reason = NULL;  /* reason for "victims" demise     */
688  
689    if (!ConfigFileEntry.glines)
690    {
691 <    sendto_one(source_p, ":%s NOTICE %s :UNGLINE disabled",
691 >    sendto_one(source_p, ":%s NOTICE %s :GUNGLINE disabled",
692                 me.name, source_p->name);
693      return;
694    }
# Line 742 | Line 696 | mo_gungline(struct Client *client_p, str
696    if (!IsOperGline(source_p))
697    {
698      sendto_one(source_p, form_str(ERR_NOPRIVS),
699 <               me.name, source_p->name, "ungline");
699 >               me.name, source_p->name, "gungline");
700      return;
701    }
702  
703 <  if (parse_aline("UNGLINE", source_p, parc, parv,
704 <                  0, &user, &host, NULL, NULL, &reason) < 0)
703 >  if (parse_aline("GUNGLINE", source_p, parc, parv, 0, &user,
704 >                  &host, NULL, NULL, &reason) < 0)
705      return;
706  
707   #ifdef GLINE_VOTING
754  /* If at least 3 opers agree this user should be un G lined then do it */
755  if (check_majority(1, source_p, user, host, reason) ==
756      GLINE_ALREADY_VOTED)
757  {
758    sendto_one(source_p,
759               ":%s NOTICE %s :This server or oper has already voted",
760               me.name, source_p->name);
761    return;
762  }
763
708    /*
709     * call these two functions first so the 'requesting' notice always comes
710     * before the 'has triggered' notice.  -bill
# Line 772 | Line 716 | mo_gungline(struct Client *client_p, str
716    ilog(L_TRACE, "#ungline for %s@%s [%s] requested by %s!%s@%s",
717         user, host, reason, source_p->name, source_p->username,
718         source_p->host);
719 +
720 +  /* If at least 3 opers agree this user should be un G lined then do it */
721 +  if (check_majority(1, source_p, user, host, reason) ==
722 +      GLINE_ALREADY_VOTED)
723 +    sendto_one(source_p,
724 +               ":%s NOTICE %s :This server or oper has already voted",
725 +               me.name, source_p->name);
726   #else
727    if (remove_gline_match(user, host))
728    {
778    sendto_one(source_p, ":%s NOTICE %s :G-Line for [%s@%s] is removed",
779               me.name, source_p->name, user, host);
729      sendto_realops_flags(UMODE_ALL, L_ALL,
730 <                         "%s has removed the G-Line for: [%s@%s]",
731 <                         get_oper_name(source_p), user, host);
730 >                         "%s has removed the G-Line for: [%s@%s]",
731 >                         get_oper_name(source_p), user, host);
732      ilog(L_NOTICE, "%s removed G-Line for [%s@%s]",
733 <         get_oper_name(source_p), user, host);
733 >         get_oper_name(source_p), user, host);
734    }
735 +  else
736 +    sendto_one(source_p, ":%s NOTICE %s :No G-Line for %s@%s",
737 +               me.name, source_p->name, user, host);
738   #endif /* GLINE_VOTING */
739 <  
740 <  ircsprintf(encap_ungline, "GUNGLINE %s %s :%s",
741 <              user, host, reason);
742 <  /* 4 param version for hyb-7 servers */
743 < /*
744 < sendto_match_servs(struct Client *source_p, const char *mask, int cap,
793 <                   const char *pattern, ...)
794 < */
795 <  sendto_match_servs(NULL, NULL, CAP_ENCAP,
796 <                     "ENCAP %s", encap_ungline);
797 <
739 >  sendto_server(client_p, NULL, CAP_ENCAP|CAP_TS6, NOCAPS,
740 >                ":%s ENCAP * GUNGLINE %s %s :%s",
741 >                ID(source_p), host, reason);
742 >  sendto_server(client_p, NULL, CAP_ENCAP, CAP_TS6,
743 >                ":%s ENCAP * GUNGLINE %s %s :%s",
744 >                source_p->name, user, host, reason);
745   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines