"Fossies" - the Fresh Open Source Software Archive

Member "ircd-hybrid-8.2.26/modules/m_set.c" (31 May 2019, 11452 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_set.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 8.2.24_vs_8.2.25.

    1 /*
    2  *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
    3  *
    4  *  Copyright (c) 1997-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_set.c
   23  * \brief Includes required functions for processing the SET command.
   24  * \version $Id: m_set.c 8892 2019-04-21 14:10:43Z michael $
   25  */
   26 
   27 #include "stdinc.h"
   28 #include "client.h"
   29 #include "event.h"
   30 #include "irc_string.h"
   31 #include "ircd.h"
   32 #include "numeric.h"
   33 #include "send.h"
   34 #include "conf.h"
   35 #include "parse.h"
   36 #include "modules.h"
   37 #include "misc.h"
   38 
   39 
   40 /* SET AUTOCONN */
   41 static void
   42 quote_autoconn(struct Client *source_p, const char *arg, int newval)
   43 {
   44   if (EmptyString(arg))
   45   {
   46     sendto_one_notice(source_p, &me, ":Please specify a server name!");
   47     return;
   48   }
   49 
   50   struct MaskItem *conf = connect_find(arg, irccmp);
   51   if (conf == NULL)
   52   {
   53     sendto_one_notice(source_p, &me, ":Cannot find %s", arg);
   54     return;
   55   }
   56 
   57   if (newval)
   58     SetConfAllowAutoConn(conf);
   59   else
   60     ClearConfAllowAutoConn(conf);
   61 
   62   sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
   63                        "%s has changed AUTOCONN for %s to %i",
   64                        get_oper_name(source_p), conf->name, newval);
   65   sendto_one_notice(source_p, &me, ":AUTOCONN for %s is now set to %i",
   66                     conf->name, newval);
   67 }
   68 
   69 /* SET AUTOCONNALL */
   70 static void
   71 quote_autoconnall(struct Client *source_p, const char *arg, int newval)
   72 {
   73   static const char *const status[] =
   74   {
   75     "OFF", "ON"
   76   };
   77 
   78   if (newval >= 0)
   79   {
   80     GlobalSetOptions.autoconn = newval != 0;
   81     sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
   82                          "%s has changed AUTOCONNALL to %s",
   83                          get_oper_name(source_p), status[GlobalSetOptions.autoconn == true]);
   84   }
   85   else
   86     sendto_one_notice(source_p, &me, ":AUTOCONNALL is currently %s",
   87                       status[GlobalSetOptions.autoconn == true]);
   88 }
   89 
   90 /* SET FLOODCOUNT */
   91 static void
   92 quote_floodcount(struct Client *source_p, const char *arg, int newval)
   93 {
   94   if (newval >= 0)
   95   {
   96     GlobalSetOptions.floodcount = newval;
   97     sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
   98                          "%s has changed FLOODCOUNT to %u",
   99                          get_oper_name(source_p), GlobalSetOptions.floodcount);
  100   }
  101   else
  102     sendto_one_notice(source_p, &me, ":FLOODCOUNT is currently %u",
  103                       GlobalSetOptions.floodcount);
  104 }
  105 
  106 /* SET FLOODTIME */
  107 static void
  108 quote_floodtime(struct Client *source_p, const char *arg, int newval)
  109 {
  110   if (newval >= 0)
  111   {
  112     GlobalSetOptions.floodtime = newval;
  113     sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
  114                          "%s has changed FLOODTIME to %u",
  115                          get_oper_name(source_p), GlobalSetOptions.floodtime);
  116   }
  117   else
  118     sendto_one_notice(source_p, &me, ":FLOODTIME is currently %u",
  119                       GlobalSetOptions.floodtime);
  120 }
  121 
  122 /* SET MAX */
  123 static void
  124 quote_max(struct Client *source_p, const char *arg, int newval)
  125 {
  126   if (newval > 0)
  127   {
  128     if (newval > MAXCLIENTS_MAX)
  129     {
  130       sendto_one_notice(source_p, &me, ":You cannot set MAXCLIENTS to > %d, restoring to %u",
  131                         MAXCLIENTS_MAX, GlobalSetOptions.maxclients);
  132       return;
  133     }
  134 
  135     GlobalSetOptions.maxclients = newval;
  136     sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
  137                          "%s set new MAXCLIENTS to %u (%u current)",
  138                          get_oper_name(source_p), GlobalSetOptions.maxclients, dlink_list_length(&local_client_list));
  139   }
  140   else
  141     sendto_one_notice(source_p, &me, ":Current MAXCLIENTS = %u (%u)",
  142                       GlobalSetOptions.maxclients, dlink_list_length(&local_client_list));
  143 }
  144 
  145 /* SET SPAMNUM */
  146 static void
  147 quote_spamnum(struct Client *source_p, const char *arg, int newval)
  148 {
  149   if (newval >= 0)
  150   {
  151     if (newval == 0)
  152     {
  153       GlobalSetOptions.spam_num = newval;
  154       sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
  155                            "%s has disabled ANTI_SPAMBOT", source_p->name);
  156       return;
  157     }
  158 
  159     GlobalSetOptions.spam_num = IRCD_MAX(newval, MIN_SPAM_NUM);
  160     sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
  161                          "%s has changed SPAMNUM to %i",
  162                          get_oper_name(source_p), GlobalSetOptions.spam_num);
  163   }
  164   else
  165     sendto_one_notice(source_p, &me, ":SPAMNUM is currently %i",
  166                       GlobalSetOptions.spam_num);
  167 }
  168 
  169 /* SET SPAMTIME */
  170 static void
  171 quote_spamtime(struct Client *source_p, const char *arg, int newval)
  172 {
  173   if (newval > 0)
  174   {
  175     GlobalSetOptions.spam_time = IRCD_MAX(newval, MIN_SPAM_TIME);
  176     sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
  177                          "%s has changed SPAMTIME to %u",
  178                          get_oper_name(source_p), GlobalSetOptions.spam_time);
  179   }
  180   else
  181     sendto_one_notice(source_p, &me, ":SPAMTIME is currently %u",
  182                       GlobalSetOptions.spam_time);
  183 }
  184 
  185 /* SET JFLOODTIME */
  186 static void
  187 quote_jfloodtime(struct Client *source_p, const char *arg, int newval)
  188 {
  189   if (newval >= 0)
  190   {
  191     GlobalSetOptions.joinfloodtime = newval;
  192     sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
  193                          "%s has changed JFLOODTIME to %u",
  194                          get_oper_name(source_p), GlobalSetOptions.joinfloodtime);
  195   }
  196   else
  197     sendto_one_notice(source_p, &me, ":JFLOODTIME is currently %u",
  198                       GlobalSetOptions.joinfloodtime);
  199 }
  200 
  201 /* SET JFLOODCOUNT */
  202 static void
  203 quote_jfloodcount(struct Client *source_p, const char *arg, int newval)
  204 {
  205   if (newval >= 0)
  206   {
  207     GlobalSetOptions.joinfloodcount = newval;
  208     sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
  209                          "%s has changed JFLOODCOUNT to %u",
  210                          get_oper_name(source_p), GlobalSetOptions.joinfloodcount);
  211   }
  212   else
  213     sendto_one_notice(source_p, &me, ":JFLOODCOUNT is currently %u",
  214                       GlobalSetOptions.joinfloodcount);
  215 }
  216 
  217 /* Structure used for the SET table itself */
  218 struct SetStruct
  219 {
  220   const char *const name;
  221   void (*const handler)(struct Client *, const char *, int);
  222   bool wants_char;  /* 1 if it expects (char *, [int]) */
  223   bool wants_int;  /* 1 if it expects ([char *], int) */
  224   /* eg:  0, 1 == only an int arg
  225    * eg:  1, 1 == char and int args */
  226 };
  227 
  228 /*
  229  * If this ever needs to be expanded to more than one arg of each
  230  * type, want_char/want_int could be the count of the arguments,
  231  * instead of just a boolean flag...
  232  *
  233  * -davidt
  234  */
  235 static const struct SetStruct set_cmd_table[] =
  236 {
  237   /* name               function        string arg  int arg */
  238   /* ------------------------------------------------------ */
  239   { "AUTOCONN",         quote_autoconn,     true,   true  },
  240   { "AUTOCONNALL",      quote_autoconnall,  false,  true  },
  241   { "FLOODCOUNT",       quote_floodcount,   false,  true  },
  242   { "FLOODTIME",        quote_floodtime,    false,  true  },
  243   { "MAX",              quote_max,          false,  true  },
  244   { "SPAMNUM",          quote_spamnum,      false,  true  },
  245   { "SPAMTIME",         quote_spamtime,     false,  true  },
  246   { "JFLOODTIME",       quote_jfloodtime,   false,  true  },
  247   { "JFLOODCOUNT",      quote_jfloodcount,  false,  true  },
  248   /* ------------------------------------------------------ */
  249   { NULL,               NULL,               false,  false }
  250 };
  251 
  252 /*
  253  * list_quote_commands() sends the client all the available commands.
  254  * Four to a line for now.
  255  */
  256 static void
  257 list_quote_commands(struct Client *source_p)
  258 {
  259   unsigned int j = 0;
  260   const char *names[4] = { "", "", "", "" };
  261 
  262   sendto_one_notice(source_p, &me, ":Available QUOTE SET commands:");
  263 
  264   for (const struct SetStruct *tab = set_cmd_table; tab->handler; ++tab)
  265   {
  266     names[j++] = tab->name;
  267 
  268     if (j > 3)
  269     {
  270       sendto_one_notice(source_p, &me, ":%s %s %s %s",
  271                         names[0], names[1],
  272                         names[2], names[3]);
  273       j = 0;
  274       names[0] = names[1] = names[2] = names[3] = "";
  275     }
  276   }
  277 
  278   if (j)
  279     sendto_one_notice(source_p, &me, ":%s %s %s %s",
  280                       names[0], names[1],
  281                       names[2], names[3]);
  282 }
  283 
  284 /*
  285  * mo_set - SET command handler
  286  * set options while running
  287  */
  288 static int
  289 mo_set(struct Client *source_p, int parc, char *parv[])
  290 {
  291   int newval;
  292   const char *strarg = NULL;
  293   const char *intarg = NULL;
  294 
  295   if (!HasOFlag(source_p, OPER_FLAG_SET))
  296   {
  297     sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "set");
  298     return 0;
  299   }
  300 
  301   if (parc > 1)
  302   {
  303     /*
  304      * Go through all the commands in set_cmd_table, until one is
  305      * matched.
  306      */
  307     for (const struct SetStruct *tab = set_cmd_table; tab->handler; ++tab)
  308     {
  309       if (irccmp(tab->name, parv[1]))
  310         continue;
  311 
  312       /*
  313        * Command found; now execute the code
  314        */
  315       int n = 2;
  316 
  317       if (tab->wants_char)
  318         strarg = parv[n++];
  319 
  320       if (tab->wants_int)
  321         intarg = parv[n++];
  322 
  323       if ((n - 1) > parc)
  324         sendto_one_notice(source_p, &me, ":SET %s expects (\"%s%s\") args", tab->name,
  325                           (tab->wants_char ? "string, " : ""),
  326                           (tab->wants_int ? "int" : ""));
  327 
  328       if (parc <= 2)
  329       {
  330         strarg = NULL;
  331         intarg = NULL;
  332       }
  333 
  334       if (tab->wants_int && parc > 2)
  335       {
  336         if (intarg)
  337         {
  338           if (irccmp(intarg, "yes") == 0 || irccmp(intarg, "on") == 0)
  339             newval = 1;
  340           else if (irccmp(intarg, "no") == 0 || irccmp(intarg, "off") == 0)
  341             newval = 0;
  342           else
  343             newval = atoi(intarg);
  344         }
  345         else
  346           newval = -1;
  347 
  348         if (newval < 0)
  349         {
  350           sendto_one_notice(source_p, &me, ":Value less than 0 illegal for %s", tab->name);
  351           return 0;
  352         }
  353       }
  354       else
  355         newval = -1;
  356 
  357       tab->handler(source_p, strarg, newval);
  358       return 0;
  359     }
  360 
  361     /*
  362      * Code here will be executed when a /QUOTE SET command is not
  363      * found within set_cmd_table.
  364      */
  365     sendto_one_notice(source_p, &me, ":Variable not found.");
  366     return 0;
  367   }
  368 
  369   list_quote_commands(source_p);
  370   return 0;
  371 }
  372 
  373 static struct Message set_msgtab =
  374 {
  375   .cmd = "SET",
  376   .args_max = MAXPARA,
  377   .handlers[UNREGISTERED_HANDLER] = m_unregistered,
  378   .handlers[CLIENT_HANDLER] = m_not_oper,
  379   .handlers[SERVER_HANDLER] = m_ignore,
  380   .handlers[ENCAP_HANDLER] = m_ignore,
  381   .handlers[OPER_HANDLER] = mo_set
  382 };
  383 
  384 static void
  385 module_init(void)
  386 {
  387   mod_add_cmd(&set_msgtab);
  388 }
  389 
  390 static void
  391 module_exit(void)
  392 {
  393   mod_del_cmd(&set_msgtab);
  394 }
  395 
  396 struct module module_entry =
  397 {
  398   .version = "$Revision: 8892 $",
  399   .modinit = module_init,
  400   .modexit = module_exit,
  401 };