"Fossies" - the Fresh Open Source Software Archive

Member "ircd-hybrid-8.2.26/modules/m_xline.c" (31 May 2019, 7234 Bytes) of package /linux/privat/ircd-hybrid-8.2.26.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "m_xline.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 8.2.25_vs_8.2.26.

    1 /*
    2  *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
    3  *
    4  *  Copyright (c) 2003-2019 ircd-hybrid development team
    5  *
    6  *  This program is free software; you can redistribute it and/or modify
    7  *  it under the terms of the GNU General Public License as published by
    8  *  the Free Software Foundation; either version 2 of the License, or
    9  *  (at your option) any later version.
   10  *
   11  *  This program is distributed in the hope that it will be useful,
   12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  *  GNU General Public License for more details.
   15  *
   16  *  You should have received a copy of the GNU General Public License
   17  *  along with this program; if not, write to the Free Software
   18  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
   19  *  USA
   20  */
   21 
   22 /*! \file m_xline.c
   23  * \brief Includes required functions for processing the XLINE command.
   24  * \version $Id: m_xline.c 8985 2019-05-22 16:47:20Z michael $
   25  */
   26 
   27 #include "stdinc.h"
   28 #include "list.h"
   29 #include "client.h"
   30 #include "irc_string.h"
   31 #include "ircd.h"
   32 #include "conf.h"
   33 #include "conf_cluster.h"
   34 #include "conf_gecos.h"
   35 #include "conf_shared.h"
   36 #include "numeric.h"
   37 #include "log.h"
   38 #include "misc.h"
   39 #include "send.h"
   40 #include "server_capab.h"
   41 #include "parse.h"
   42 #include "modules.h"
   43 #include "memory.h"
   44 
   45 
   46 static void
   47 xline_check(const struct GecosItem *gecos)
   48 {
   49   dlink_node *node, *node_next;
   50 
   51   DLINK_FOREACH_SAFE(node, node_next, local_client_list.head)
   52   {
   53     struct Client *client_p = node->data;
   54 
   55     if (IsDead(client_p))
   56       continue;
   57 
   58     if (match(gecos->mask, client_p->info) == 0)
   59       conf_try_ban(client_p, CLIENT_BAN_XLINE, gecos->reason);
   60   }
   61 }
   62 
   63 /* xline_handle()
   64  *
   65  * inputs       - client taking credit for xline, gecos, reason, xline type
   66  * outputs      - none
   67  * side effects - when successful, adds an xline to the conf
   68  */
   69 static void
   70 xline_handle(struct Client *source_p, const struct aline_ctx *aline)
   71 {
   72   char buf[IRCD_BUFSIZE];
   73 
   74   if (!HasFlag(source_p, FLAGS_SERVICE))
   75   {
   76     if (valid_wild_card_simple(aline->mask) == false)
   77     {
   78       if (IsClient(source_p))
   79         sendto_one_notice(source_p, &me, ":Please include at least %u non-wildcard characters with the xline",
   80                           ConfigGeneral.min_nonwildcard_simple);
   81       return;
   82     }
   83   }
   84 
   85   struct GecosItem *gecos;
   86   if ((gecos = gecos_find(aline->mask, match)))
   87   {
   88     if (IsClient(source_p))
   89       sendto_one_notice(source_p, &me, ":[%s] already X-Lined by [%s] - %s",
   90                         aline->mask, gecos->mask, gecos->reason);
   91     return;
   92   }
   93 
   94   if (aline->duration)
   95     snprintf(buf, sizeof(buf), "Temporary X-line %ju min. - %.*s (%s)",
   96              aline->duration / 60, REASONLEN, aline->reason, date_iso8601(0));
   97   else
   98     snprintf(buf, sizeof(buf), "%.*s (%s)", REASONLEN, aline->reason, date_iso8601(0));
   99 
  100   gecos = gecos_make();
  101   gecos->mask = xstrdup(aline->mask);
  102   gecos->reason = xstrdup(buf);
  103   gecos->setat = event_base->time.sec_real;
  104   gecos->in_database = true;
  105 
  106   if (aline->duration)
  107   {
  108     gecos->expire = event_base->time.sec_real + aline->duration;
  109 
  110     if (IsClient(source_p))
  111       sendto_one_notice(source_p, &me, ":Added temporary %ju min. X-Line [%s]",
  112                         aline->duration / 60, gecos->mask);
  113 
  114     sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
  115                          "%s added temporary %ju min. X-Line for [%s] [%s]",
  116                          get_oper_name(source_p), aline->duration / 60,
  117                          gecos->mask, gecos->reason);
  118     ilog(LOG_TYPE_XLINE, "%s added temporary %ju min. X-Line for [%s] [%s]",
  119          get_oper_name(source_p), aline->duration / 60, gecos->mask, gecos->reason);
  120   }
  121   else
  122   {
  123     if (IsClient(source_p))
  124       sendto_one_notice(source_p, &me, ":Added X-Line [%s] [%s]",
  125                         gecos->mask, gecos->reason);
  126 
  127     sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
  128                          "%s added X-Line for [%s] [%s]",
  129                          get_oper_name(source_p), gecos->mask,
  130                          gecos->reason);
  131     ilog(LOG_TYPE_XLINE, "%s added X-Line for [%s] [%s]",
  132          get_oper_name(source_p), gecos->mask, gecos->reason);
  133   }
  134 
  135   xline_check(gecos);
  136 }
  137 
  138 /* mo_xline()
  139  *
  140  * inputs   - pointer to server
  141  *      - pointer to client
  142  *      - parameter count
  143  *      - parameter list
  144  * output   -
  145  * side effects - x line is added
  146  *
  147  */
  148 static int
  149 mo_xline(struct Client *source_p, int parc, char *parv[])
  150 {
  151   struct aline_ctx aline = { .add = true, .simple_mask = true };
  152 
  153   if (!HasOFlag(source_p, OPER_FLAG_XLINE))
  154   {
  155     sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "xline");
  156     return 0;
  157   }
  158 
  159   if (parse_aline("XLINE", source_p, parc, parv, &aline) == false)
  160     return 0;
  161 
  162   if (aline.server)
  163   {
  164     sendto_match_servs(source_p, aline.server, CAPAB_CLUSTER, "XLINE %s %s %ju :%s",
  165                        aline.server, aline.mask, aline.duration, aline.reason);
  166 
  167     /* Allow ON to apply local xline as well if it matches */
  168     if (match(aline.server, me.name))
  169       return 0;
  170   }
  171   else
  172     cluster_distribute(source_p, "XLINE", CAPAB_CLUSTER, CLUSTER_XLINE, "%s %ju :%s",
  173                        aline.mask, aline.mask, aline.reason);
  174 
  175   xline_handle(source_p, &aline);
  176   return 0;
  177 }
  178 
  179 /*! \brief XLINE command handler
  180  *
  181  * \param source_p Pointer to allocated Client struct from which the message
  182  *                 originally comes from.  This can be a local or remote client.
  183  * \param parc     Integer holding the number of supplied arguments.
  184  * \param parv     Argument vector where parv[0] .. parv[parc-1] are non-NULL
  185  *                 pointers.
  186  * \note Valid arguments for this command are:
  187  *      - parv[0] = command
  188  *      - parv[1] = target server mask
  189  *      - parv[2] = gecos
  190  *      - parv[3] = duration in seconds
  191  *      - parv[4] = reason
  192  */
  193 static int
  194 ms_xline(struct Client *source_p, int parc, char *parv[])
  195 {
  196   struct aline_ctx aline =
  197   {
  198     .add = true,
  199     .simple_mask = true,
  200     .mask = parv[2],
  201     .reason = parv[4],
  202     .server = parv[1],
  203     .duration = strtoumax(parv[3], NULL, 10)
  204   };
  205 
  206   if (parc != 5 || EmptyString(parv[parc - 1]))
  207     return 0;
  208 
  209   sendto_match_servs(source_p, aline.server, CAPAB_CLUSTER, "XLINE %s %s %ju :%s",
  210                      aline.server, aline.mask, aline.duration, aline.reason);
  211 
  212   if (match(aline.server, me.name))
  213     return 0;
  214 
  215   if (HasFlag(source_p, FLAGS_SERVICE) ||
  216       shared_find(SHARED_XLINE, source_p->servptr->name,
  217                   source_p->username, source_p->host))
  218     xline_handle(source_p, &aline);
  219 
  220   return 0;
  221 }
  222 
  223 static struct Message xline_msgtab =
  224 {
  225   .cmd = "XLINE",
  226   .args_min = 2,
  227   .args_max = MAXPARA,
  228   .handlers[UNREGISTERED_HANDLER] = m_unregistered,
  229   .handlers[CLIENT_HANDLER] = m_not_oper,
  230   .handlers[SERVER_HANDLER] = ms_xline,
  231   .handlers[ENCAP_HANDLER] = m_ignore,
  232   .handlers[OPER_HANDLER] = mo_xline
  233 };
  234 
  235 static void
  236 module_init(void)
  237 {
  238   mod_add_cmd(&xline_msgtab);
  239 }
  240 
  241 static void
  242 module_exit(void)
  243 {
  244   mod_del_cmd(&xline_msgtab);
  245 }
  246 
  247 struct module module_entry =
  248 {
  249   .version = "$Revision: 8985 $",
  250   .modinit = module_init,
  251   .modexit = module_exit,
  252 };