"Fossies" - the Fresh Open Source Software Archive

Member "ircd-hybrid-8.2.26/src/conf_resv.c" (31 May 2019, 5754 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 "conf_resv.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) 2001-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 conf_resv.c
   23  * \brief Functions to reserve(jupe) a nick/channel.
   24  * \version $Id: conf_resv.c 8971 2019-05-18 12:52:56Z michael $
   25  */
   26 
   27 #include "stdinc.h"
   28 #include "list.h"
   29 #include "send.h"
   30 #include "client.h"
   31 #include "memory.h"
   32 #include "ircd.h"
   33 #include "irc_string.h"
   34 #include "ircd_defs.h"
   35 #include "misc.h"
   36 #include "conf.h"
   37 #include "conf_resv.h"
   38 #include "hostmask.h"
   39 
   40 
   41 static dlink_list resv_chan_list;
   42 static dlink_list resv_nick_list;
   43 
   44 
   45 const dlink_list *
   46 resv_chan_get_list(void)
   47 {
   48   return &resv_chan_list;
   49 }
   50 
   51 const dlink_list *
   52 resv_nick_get_list(void)
   53 {
   54   return &resv_nick_list;
   55 }
   56 
   57 void
   58 resv_delete(struct ResvItem *resv, bool expired)
   59 {
   60   if (expired == true)
   61     sendto_realops_flags(UMODE_EXPIRATION, L_ALL, SEND_NOTICE, "Temporary RESV for [%s] expired",
   62                          resv->mask);
   63 
   64   while (resv->exempt_list.head)
   65   {
   66     struct ResvExemptItem *exempt = resv->exempt_list.head->data;
   67 
   68     dlinkDelete(&exempt->node, &resv->exempt_list);
   69     xfree(exempt->name);
   70     xfree(exempt->user);
   71     xfree(exempt->host);
   72     xfree(exempt);
   73   }
   74 
   75   dlinkDelete(&resv->node, resv->list);
   76   xfree(resv->mask);
   77   xfree(resv->reason);
   78   xfree(resv);
   79 }
   80 
   81 /* create_resv()
   82  *
   83  * inputs   - name of nick to create resv for
   84  *      - reason for resv
   85  *      - 1 if from ircd.conf, 0 if from elsewhere
   86  * output   - pointer to struct ResvNick
   87  * side effects -
   88  */
   89 struct ResvItem *
   90 resv_make(const char *mask, const char *reason, const dlink_list *elist)
   91 {
   92   dlink_list *list;
   93 
   94   if (IsChanPrefix(*mask))
   95     list = &resv_chan_list;
   96   else
   97     list = &resv_nick_list;
   98 
   99   struct ResvItem *resv = xcalloc(sizeof(*resv));
  100   resv->list = list;
  101   resv->mask = xstrdup(mask);
  102   resv->reason = xstrndup(reason, IRCD_MIN(strlen(reason), REASONLEN));
  103   dlinkAdd(resv, &resv->node, resv->list);
  104 
  105   if (elist)
  106   {
  107     dlink_node *node;
  108 
  109     DLINK_FOREACH(node, elist->head)
  110     {
  111       char nick[NICKLEN + 1];
  112       char user[USERLEN + 1];
  113       char host[HOSTLEN + 1];
  114       struct split_nuh_item nuh;
  115       char *s = node->data;
  116 
  117       nuh.nuhmask  = s;
  118       nuh.nickptr  = nick;
  119       nuh.userptr  = user;
  120       nuh.hostptr  = host;
  121 
  122       nuh.nicksize = sizeof(nick);
  123       nuh.usersize = sizeof(user);
  124       nuh.hostsize = sizeof(host);
  125 
  126       split_nuh(&nuh);
  127 
  128       struct ResvExemptItem *exempt = xcalloc(sizeof(*exempt));
  129       exempt->name = xstrdup(nick);
  130       exempt->user = xstrdup(user);
  131       exempt->host = xstrdup(host);
  132       exempt->type = parse_netmask(host, &exempt->addr, &exempt->bits);
  133       dlinkAdd(exempt, &exempt->node, &resv->exempt_list);
  134     }
  135   }
  136 
  137   return resv;
  138 }
  139 
  140 struct ResvItem *
  141 resv_find(const char *name, int (*compare)(const char *, const char *))
  142 {
  143   dlink_node *node, *node_next;
  144   dlink_list *list;
  145 
  146   if (IsChanPrefix(*name))
  147     list = &resv_chan_list;
  148   else
  149     list = &resv_nick_list;
  150 
  151   DLINK_FOREACH_SAFE(node, node_next, list->head)
  152   {
  153     struct ResvItem *resv = node->data;
  154 
  155     if (resv->expire &&
  156         (resv->expire <= event_base->time.sec_real))
  157       resv_delete(resv, true);
  158     else if (compare(resv->mask, name) == 0)
  159       return resv;
  160   }
  161 
  162   return NULL;
  163 }
  164 
  165 bool
  166 resv_exempt_find(const struct Client *client_p, const struct ResvItem *resv)
  167 {
  168   dlink_node *node;
  169 
  170   DLINK_FOREACH(node, resv->exempt_list.head)
  171   {
  172     const struct ResvExemptItem *exempt = node->data;
  173 
  174     if (match(exempt->name, client_p->name) == 0 && match(exempt->user, client_p->username) == 0)
  175     {
  176       switch (exempt->type)
  177       {
  178         case HM_HOST:
  179           if (match(exempt->host, client_p->host) == 0 || match(exempt->host, client_p->sockhost) == 0)
  180             return true;
  181           break;
  182         case HM_IPV4:
  183           if (client_p->ip.ss.ss_family == AF_INET)
  184             if (match_ipv4(&client_p->ip, &exempt->addr, exempt->bits))
  185               return true;
  186           break;
  187         case HM_IPV6:
  188           if (client_p->ip.ss.ss_family == AF_INET6)
  189             if (match_ipv6(&client_p->ip, &exempt->addr, exempt->bits))
  190               return true;
  191           break;
  192         default:
  193           assert(0);
  194       }
  195     }
  196   }
  197 
  198   return false;
  199 }
  200 
  201 void
  202 resv_clear(void)
  203 {
  204   dlink_list *tab[] = { &resv_chan_list, &resv_nick_list, NULL };
  205 
  206   for (dlink_list **list = tab; *list; ++list)
  207   {
  208     dlink_node *node, *node_next;
  209 
  210     DLINK_FOREACH_SAFE(node, node_next, (*list)->head)
  211     {
  212       struct ResvItem *resv = node->data;
  213 
  214       if (resv->in_database == false)
  215         resv_delete(resv, false);
  216     }
  217   }
  218 }
  219 
  220 void
  221 resv_expire(void)
  222 {
  223   dlink_list *tab[] = { &resv_chan_list, &resv_nick_list, NULL };
  224 
  225   for (dlink_list **list = tab; *list; ++list)
  226   {
  227     dlink_node *node, *node_next;
  228 
  229     DLINK_FOREACH_SAFE(node, node_next, (*list)->head)
  230     {
  231       struct ResvItem *resv = node->data;
  232 
  233       if (resv->expire &&
  234           (resv->expire <= event_base->time.sec_real))
  235         resv_delete(resv, true);
  236     }
  237   }
  238 }