/[svn]/ircd-hybrid-7.2/modules/m_gline.c
ViewVC logotype

Diff of /ircd-hybrid-7.2/modules/m_gline.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 936 by db, Wed Apr 8 20:32:49 2009 UTC revision 937 by db, Mon Apr 13 04:31:12 2009 UTC
# Line 59  extern dlink_list gdeny_items; Line 59  extern dlink_list gdeny_items;
59  /* internal functions */  /* internal functions */
60  static void set_local_gline(const struct Client *,  static void set_local_gline(const struct Client *,
61                              const char *, const char *, const char *);                              const char *, const char *, const char *);
62    static int remove_gline_match(const char *user, const char *host);
63    
64  #ifdef GLINE_VOTING  #ifdef GLINE_VOTING
65  static int check_majority_gline(const struct Client *,  static int check_majority(int isungline, const struct Client *,
66                                  const char *, const char *, const char *);                            const char *, const char *, const char *);
67    
68  static void add_new_majority_gline(const struct Client *,  static void add_new_majority(const struct Client *,
69                                     const char *, const char *, const char *);                               const char *, const char *, const char *);
70  #endif /* GLINE_VOTING */  #endif /* GLINE_VOTING */
71    
72  static void do_sgline(struct Client *, struct Client *, int, char **, int);  static void do_sgline(struct Client *, struct Client *, int, char **, int);
# Line 74  static void me_gline(struct Client *, st Line 75  static void me_gline(struct Client *, st
75  static void ms_gline(struct Client *, struct Client *, int, char **);  static void ms_gline(struct Client *, struct Client *, int, char **);
76  static void mo_gline(struct Client *, struct Client *, int, char **);  static void mo_gline(struct Client *, struct Client *, int, char **);
77    
78    static void do_sungline(struct Client *, struct Client *, int, char **, int);
79    
80    static void me_ungline(struct Client *, struct Client *, int, char **);
81    static void ms_ungline(struct Client *, struct Client *, int, char **);
82    static void mo_ungline(struct Client *, struct Client *, int, char **);
83    
84  /*  /*
85   * gline enforces 3 parameters to force operator to give a reason   * gline enforces 3 parameters to force operator to give a reason
86   * a gline is not valid with "No reason"   * a gline is not valid with "No reason"
# Line 84  struct Message gline_msgtab = { Line 91  struct Message gline_msgtab = {
91    {m_unregistered, m_not_oper, ms_gline, me_gline, mo_gline, m_ignore}    {m_unregistered, m_not_oper, ms_gline, me_gline, mo_gline, m_ignore}
92  };  };
93    
94    struct Message ungline_msgtab = {
95      "UNGLINE", 0, 0, 3, 0, MFLG_SLOW, 0,
96      {m_unregistered, m_not_oper, ms_ungline, me_ungline, mo_ungline, m_ignore}
97    };
98    
99                                    
100  #ifndef STATIC_MODULES  #ifndef STATIC_MODULES
101  void  void
102  _modinit(void)  _modinit(void)
103  {  {
104      mod_add_cmd(&gline_msgtab);      mod_add_cmd(&gline_msgtab);
105        mod_add_cmd(&ungline_msgtab);
106      add_capability("GLN", CAP_GLN, 1);      add_capability("GLN", CAP_GLN, 1);
107  }  }
108    
# Line 97  void Line 110  void
110  _moddeinit(void)  _moddeinit(void)
111  {  {
112    mod_del_cmd(&gline_msgtab);    mod_del_cmd(&gline_msgtab);
113      mod_del_cmd(&ungline_msgtab);
114    delete_capability("GLN");    delete_capability("GLN");
115  }  }
116    
# Line 159  mo_gline(struct Client *client_p, struct Line 173  mo_gline(struct Client *client_p, struct
173        
174  #ifdef GLINE_VOTING  #ifdef GLINE_VOTING
175    /* If at least 3 opers agree this user should be G lined then do it */    /* If at least 3 opers agree this user should be G lined then do it */
176    if (check_majority_gline(source_p, user, host, reason) ==    if (check_majority(0, source_p, user, host, reason) ==
177        GLINE_ALREADY_VOTED)        GLINE_ALREADY_VOTED)
178    {    {
179      sendto_one(source_p,      sendto_one(source_p,
# Line 363  do_sgline(struct Client *client_p, struc Line 377  do_sgline(struct Client *client_p, struc
377    
378  #ifdef GLINE_VOTING  #ifdef GLINE_VOTING
379       /* If at least 3 opers agree this user should be G lined then do it */       /* If at least 3 opers agree this user should be G lined then do it */
380       if (check_majority_gline(source_p, user, host, reason) ==       if (check_majority(0, source_p, user, host, reason) ==
381           GLINE_ALREADY_VOTED)           GLINE_ALREADY_VOTED)
382       {       {
383         sendto_realops_flags(UMODE_ALL, L_ALL, "oper or server has already voted");         sendto_realops_flags(UMODE_ALL, L_ALL, "oper or server has already voted");
# Line 429  set_local_gline(const struct Client *sou Line 443  set_local_gline(const struct Client *sou
443  }  }
444    
445  #ifdef GLINE_VOTING  #ifdef GLINE_VOTING
446  /* add_new_majority_gline()  /* add_new_majority()
447   *   *
448   * inputs       - operator requesting gline   * inputs       - operator requesting gline
449   *              - username covered by the gline   *              - username covered by the gline
# Line 441  set_local_gline(const struct Client *sou Line 455  set_local_gline(const struct Client *sou
455   * have agreed on a gline, and it can be placed. The   * have agreed on a gline, and it can be placed. The
456   * information about an operator being passed to us   * information about an operator being passed to us
457   * happens to be the operator who pushed us over the   * happens to be the operator who pushed us over the
458   * "majority" level needed. See check_majority_gline()   * "majority" level needed. See check_majority()
459   * for more information.   * for more information.
460   */   */
461  static void  static void
462  add_new_majority_gline(const struct Client *source_p,  add_new_majority(const struct Client *source_p,
463                         const char *user, const char *host, const char *reason)                   const char *user, const char *host, const char *reason)
464  {  {
465    struct gline_pending *pending = MyMalloc(sizeof(struct gline_pending));    struct gline_pending *pending = MyMalloc(sizeof(struct gline_pending));
466    
# Line 466  add_new_majority_gline(const struct Clie Line 480  add_new_majority_gline(const struct Clie
480    dlinkAdd(pending, &pending->node, &pending_glines);    dlinkAdd(pending, &pending->node, &pending_glines);
481  }  }
482    
483  /* check_majority_gline()  /* check_majority()
484   *   *
485   * inputs       - source, user, host, reason   * inputs       - source, user, host, reason
486   *   *
# Line 482  add_new_majority_gline(const struct Clie Line 496  add_new_majority_gline(const struct Clie
496   *   *
497   */   */
498  static int  static int
499  check_majority_gline(const struct Client *source_p,  check_majority(int isungline, const struct Client *source_p,
500                       const char *user, const char *host, const char *reason)                 const char *user, const char *host, const char *reason)
501  {  {
502    dlink_node *pending_node;    dlink_node *pending_node;
503    struct gline_pending *gline_pending_ptr;    struct gline_pending *gline_pending_ptr;
504      char ckuser[USERLEN * 2 + 2];
505    
506    /* if its already glined, why bother? :) -- fl_ */    /* if its already glined, why bother? :) -- fl_ */
507    if (find_is_glined(host, user))    if (!isungline && find_is_glined(host, user))
508      return(GLINE_NOT_PLACED);      return(GLINE_NOT_PLACED);
509    
510      if (isungline)
511        ircsprintf(ckuser, "-%s", user);
512      else
513        ircsprintf(ckuser, "%s", user);
514    
515    /* special case condition where there are no pending glines */    /* special case condition where there are no pending glines */
516    if (dlink_list_length(&pending_glines) == 0) /* first gline request placed */    if (dlink_list_length(&pending_glines) == 0) /* first gline request placed */
517    {    {
518      add_new_majority_gline(source_p, user, host, reason);      add_new_majority(source_p, ckuser, host, reason);
519      return(GLINE_NOT_PLACED);      return(GLINE_NOT_PLACED);
520    }    }
521    
# Line 503  check_majority_gline(const struct Client Line 523  check_majority_gline(const struct Client
523    {    {
524      gline_pending_ptr = pending_node->data;      gline_pending_ptr = pending_node->data;
525    
526      if ((irccmp(gline_pending_ptr->user, user) == 0) &&      if ((irccmp(gline_pending_ptr->user, ckuser) == 0) &&
527          (irccmp(gline_pending_ptr->host, host) == 0))          (irccmp(gline_pending_ptr->host, host) == 0))
528      {      {
529        if (((irccmp(gline_pending_ptr->oper_user1, source_p->username) == 0) ||        if (((irccmp(gline_pending_ptr->oper_user1, source_p->username) == 0) ||
# Line 524  check_majority_gline(const struct Client Line 544  check_majority_gline(const struct Client
544            return(GLINE_ALREADY_VOTED);            return(GLINE_ALREADY_VOTED);
545          }          }
546    
547          /* trigger the gline using the original reason --fl */          if(gline_pending_ptr->user[0] == '-')
548          set_local_gline(source_p, user, host, gline_pending_ptr->reason1);          {
549          cleanup_glines(NULL);            if (remove_gline_match(user, host))
550          return(GLINE_PLACED);            {
551        }              sendto_one(source_p, ":%s NOTICE %s :G-Line for [%s@%s] is removed",
552        else                         me.name, source_p->name, user, host);
553        {              sendto_realops_flags(UMODE_ALL, L_ALL,
554          strlcpy(gline_pending_ptr->oper_nick2, source_p->name,                                   "%s has removed the G-Line for: [%s@%s]",
555                  sizeof(gline_pending_ptr->oper_nick2));                                   get_oper_name(source_p), user, host);
556          strlcpy(gline_pending_ptr->oper_user2, source_p->username,              ilog(L_NOTICE, "%s removed G-Line for [%s@%s]",
557                  sizeof(gline_pending_ptr->oper_user2));                   get_oper_name(source_p), user, host);
558          strlcpy(gline_pending_ptr->oper_host2, source_p->host,            }
559                  sizeof(gline_pending_ptr->oper_host2));            else
560          strlcpy(gline_pending_ptr->reason2, reason,            {
561                  sizeof(gline_pending_ptr->reason2));              sendto_one(source_p, ":%s NOTICE %s :No G-Line for %s@%s",
562          strlcpy(gline_pending_ptr->oper_server2, source_p->servptr->name,                         me.name, source_p->name, user, host);
563                  sizeof(gline_pending_ptr->oper_server2));            }
564          gline_pending_ptr->last_gline_time = CurrentTime;          }
565          gline_pending_ptr->time_request2 = CurrentTime;          else
566          return(GLINE_NOT_PLACED);          {
567              /* trigger the gline using the original reason --fl */
568              set_local_gline(source_p, user, host, gline_pending_ptr->reason1);
569              cleanup_glines(NULL);
570              return(GLINE_PLACED);
571            }
572        }        }
573      }      }
574        else
575        {
576          strlcpy(gline_pending_ptr->oper_nick2, source_p->name,
577                  sizeof(gline_pending_ptr->oper_nick2));
578          strlcpy(gline_pending_ptr->oper_user2, source_p->username,
579                  sizeof(gline_pending_ptr->oper_user2));
580          strlcpy(gline_pending_ptr->oper_host2, source_p->host,
581                  sizeof(gline_pending_ptr->oper_host2));
582          strlcpy(gline_pending_ptr->reason2, reason,
583                  sizeof(gline_pending_ptr->reason2));
584          strlcpy(gline_pending_ptr->oper_server2, source_p->servptr->name,
585                  sizeof(gline_pending_ptr->oper_server2));
586          gline_pending_ptr->last_gline_time = CurrentTime;
587          gline_pending_ptr->time_request2 = CurrentTime;
588          return(GLINE_NOT_PLACED);
589        }
590    }    }
591    
592    /* Didn't find this user@host gline in pending gline list    /* Didn't find this user@host gline in pending gline list
593     * so add it.     * so add it.
594     */     */
595    add_new_majority_gline(source_p, user, host, reason);    add_new_majority(source_p, ckuser, host, reason);
596    return(GLINE_NOT_PLACED);    return(GLINE_NOT_PLACED);
597  }  }
598  #endif /* GLINE_VOTING */  #endif /* GLINE_VOTING */
# Line 590  remove_gline_match(const char *user, con Line 631  remove_gline_match(const char *user, con
631    return(0);    return(0);
632  }  }
633    
634    /* ms_ungline()
635     * me_ungline()
636     * do_sungline()
637     *
638     * inputs       - The usual for a m_ function
639     * output       -
640     * side effects -
641     *
642     * Remove a G line if 3 opers agree on the identical user@host
643     *
644     * ENCAP'd UNGLINES are propagated by encap code.
645     */
646    
647    static void
648    ms_ungline(struct Client *client_p, struct Client *source_p,
649             int parc, char *parv[])
650    {
651      do_sungline(client_p, source_p, parc, parv, 1);
652    }
653    
654    static void
655    me_ungline(struct Client *client_p, struct Client *source_p,
656             int parc, char *parv[])
657    {
658      do_sungline(client_p, source_p, parc, parv, 0);
659    }
660    
661    static void
662    do_sungline(struct Client *client_p, struct Client *source_p,
663              int parc, char *parv[], int prop)
664    {
665      const char *reason = NULL;      /* reason for "victims" demise       */
666      char *user = NULL;
667      char *host = NULL;              /* user and host of GLINE "victim"   */
668      int var_offset = 0;
669      int logged = 0;
670      dlink_node *ptr;
671      struct ConfItem *conf;
672      struct AccessItem *aconf;
673    
674      assert(source_p->servptr != NULL);
675    
676      user = parv[++var_offset];
677      host = parv[++var_offset];
678      reason = parv[++var_offset];
679    
680      if (ConfigFileEntry.glines)
681      {
682        if (!valid_wild_card(source_p, YES, 2, user, host))
683          return;
684    
685    #ifdef GLINE_VOTING
686         /* If at least 3 opers agree this user should be un G lined then do it */
687         if (check_majority(1, source_p, user, host, reason) ==
688             GLINE_ALREADY_VOTED)
689         {
690           sendto_realops_flags(UMODE_ALL, L_ALL, "oper or server has already voted");
691           return;
692         }
693    
694         sendto_realops_flags(UMODE_ALL, L_ALL,
695                              "%s requesting UNG-Line for [%s@%s] [%s]",
696                              get_oper_name(source_p),
697                              user, host, reason);
698         ilog(L_TRACE, "#ungline for %s@%s [%s] requested by %s",
699              user, host, reason, get_oper_name(source_p));
700    #else
701         if (remove_gline_match(user, host))
702         {
703           sendto_one(source_p, ":%s NOTICE %s :G-Line for [%s@%s] is removed",
704                      me.name, source_p->name, user, host);
705           sendto_realops_flags(UMODE_ALL, L_ALL,
706                                "%s has removed the G-Line for: [%s@%s]",
707                                get_oper_name(source_p), user, host);
708           ilog(L_NOTICE, "%s removed G-Line for [%s@%s]",
709                get_oper_name(source_p), user, host);
710         }
711         else
712         {
713           sendto_one(source_p, ":%s NOTICE %s :No G-Line for %s@%s",
714                      me.name, source_p->name, user, host);
715         }
716    #endif /* GLINE_VOTING */
717      }
718    }
719    
720    /* mo_ungline()
721     *
722     * inputs       - The usual for a m_ function
723     * output       -
724     * side effects -
725     *
726     * Remove a G line if 3 opers agree on the identical user@host
727     *
728     */
729    /* Allow this server to pass along UNGLINE if received and
730     * GLINES is not defined.
731     *
732     */
733    
734    static void
735    mo_ungline(struct Client *client_p, struct Client *source_p,
736               int parc, char *parv[])
737    {
738      char *user = NULL;
739      char *host = NULL;         /* user and host of GLINE "victim" */
740      char *reason = NULL;       /* reason for "victims" demise     */
741      char encap_ungline[IRCD_BUFSIZE];
742    
743      if (!ConfigFileEntry.glines)
744      {
745        sendto_one(source_p, ":%s NOTICE %s :UNGLINE disabled",
746                   me.name, source_p->name);
747        return;
748      }
749    
750      if (!IsOperGline(source_p))
751      {
752        sendto_one(source_p, form_str(ERR_NOPRIVS),
753                   me.name, source_p->name, "ungline");
754        return;
755      }
756    
757      if (parse_aline("UNGLINE", source_p, parc, parv,
758                      0, &user, &host, NULL, NULL, &reason) < 0)
759        return;
760    
761    #ifdef GLINE_VOTING
762      /* If at least 3 opers agree this user should be un G lined then do it */
763      if (check_majority(1, source_p, user, host, reason) ==
764          GLINE_ALREADY_VOTED)
765      {
766        sendto_one(source_p,
767                   ":%s NOTICE %s :This server or oper has already voted",
768                   me.name, source_p->name);
769        return;
770      }
771    
772      /*
773       * call these two functions first so the 'requesting' notice always comes
774       * before the 'has triggered' notice.  -bill
775       */
776      sendto_realops_flags(UMODE_ALL, L_ALL,
777                           "%s requesting UNG-Line for [%s@%s] [%s]",
778                           get_oper_name(source_p),
779                           user, host, reason);
780      ilog(L_TRACE, "#ungline for %s@%s [%s] requested by %s!%s@%s",
781           user, host, reason, source_p->name, source_p->username,
782           source_p->host);
783    #else
784      if (remove_gline_match(user, host))
785      {
786        sendto_one(source_p, ":%s NOTICE %s :G-Line for [%s@%s] is removed",
787                   me.name, source_p->name, user, host);
788        sendto_realops_flags(UMODE_ALL, L_ALL,
789                             "%s has removed the G-Line for: [%s@%s]",
790                             get_oper_name(source_p), user, host);
791        ilog(L_NOTICE, "%s removed G-Line for [%s@%s]",
792             get_oper_name(source_p), user, host);
793      }
794    #endif /* GLINE_VOTING */
795      
796      ircsprintf(encap_ungline, "UNGLINE %s %s %s",
797                  user, host, reason);
798      /* 4 param version for hyb-7 servers */
799      sendto_match_servs(NULL, NULL CAP_ENCAP, 0,
800                         "ENCAP %s", encap_ungline);
801    
802    }

Legend:
Removed from v.936  
changed lines
  Added in v.937

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28