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

Comparing ircd-hybrid/trunk/src/conf.c (file contents):
Revision 2275 by michael, Tue Jun 18 16:30:11 2013 UTC vs.
Revision 3215 by michael, Tue Mar 25 19:23:15 2014 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  conf.c: Configuration file functions.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2014 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
# Line 18 | Line 17
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file conf.c
23 > * \brief Configuration file functions.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
# Line 55 | Line 57
57   #include "conf_class.h"
58   #include "motd.h"
59  
60 +
61 + struct config_channel_entry ConfigChannel;
62   struct config_server_hide ConfigServerHide;
63 + struct config_file_entry ConfigFileEntry;
64 + struct logging_entry ConfigLoggingEntry = { .use_logging = 1 };
65 + struct server_info ServerInfo;
66 + struct admin_info AdminInfo;
67  
68   /* general conf items link list root, other than k lines etc. */
69   dlink_list service_items = { NULL, NULL, 0 };
# Line 196 | Line 204 | conf_free(struct MaskItem *conf)
204    DLINK_FOREACH_SAFE(ptr, ptr_next, conf->hub_list.head)
205    {
206      MyFree(ptr->data);
207 +    dlinkDelete(ptr, &conf->hub_list);
208      free_dlink_node(ptr);
209    }
210  
211    DLINK_FOREACH_SAFE(ptr, ptr_next, conf->leaf_list.head)
212    {
213      MyFree(ptr->data);
214 +    dlinkDelete(ptr, &conf->leaf_list);
215      free_dlink_node(ptr);
216    }
217  
# Line 209 | Line 219 | conf_free(struct MaskItem *conf)
219    {
220      struct exempt *exptr = ptr->data;
221  
222 +    dlinkDelete(ptr, &conf->exempt_list);
223      MyFree(exptr->name);
224      MyFree(exptr->user);
225      MyFree(exptr->host);
# Line 235 | Line 246 | int
246   check_client(struct Client *source_p)
247   {
248    int i;
249 <
249 >
250    if ((i = verify_access(source_p)))
251 <    ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
251 >    ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
252           source_p->name, source_p->sockhost);
253  
254    switch (i)
# Line 250 | Line 261 | check_client(struct Client *source_p)
261        ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
262             get_client_name(source_p, SHOW_IP));
263        ++ServerStats.is_ref;
264 <      exit_client(source_p, &me, "No more connections allowed on that IP");
264 >      exit_client(source_p, "No more connections allowed on that IP");
265        break;
266  
267      case I_LINE_FULL:
# Line 261 | Line 272 | check_client(struct Client *source_p)
272        ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
273             get_client_name(source_p, SHOW_IP));
274        ++ServerStats.is_ref;
275 <      exit_client(source_p, &me,
265 <                  "No more connections allowed in your connection class");
275 >      exit_client(source_p, "No more connections allowed in your connection class");
276        break;
277  
278      case NOT_AUTHORIZED:
# Line 281 | Line 291 | check_client(struct Client *source_p)
291             source_p->localClient->listener->name,
292             source_p->localClient->listener->port);
293  
294 <      exit_client(source_p, &me, "You are not authorized to use this server");
294 >      exit_client(source_p, "You are not authorized to use this server");
295        break;
296  
297     case BANNED_CLIENT:
298 <     exit_client(source_p, &me, "Banned");
298 >     exit_client(source_p, "Banned");
299       ++ServerStats.is_ref;
300       break;
301  
# Line 307 | Line 317 | static int
317   verify_access(struct Client *client_p)
318   {
319    struct MaskItem *conf = NULL;
320 <  char non_ident[USERLEN + 1] = { '~', '\0' };
320 >  char non_ident[USERLEN + 1] = "~";
321  
322    if (IsGotId(client_p))
323    {
# Line 325 | Line 335 | verify_access(struct Client *client_p)
335                               client_p->localClient->passwd);
336    }
337  
338 <  if (conf != NULL)
338 >  if (conf)
339    {
340      if (IsConfClient(conf))
341      {
342        if (IsConfRedir(conf))
343        {
344 <        sendto_one(client_p, form_str(RPL_REDIR),
345 <                   me.name, client_p->name,
346 <                   conf->name ? conf->name : "",
337 <                   conf->port);
344 >        sendto_one_numeric(client_p, &me, RPL_REDIR,
345 >                           conf->name ? conf->name : "",
346 >                           conf->port);
347          return NOT_AUTHORIZED;
348        }
349  
# Line 357 | Line 366 | verify_access(struct Client *client_p)
366      else if (IsConfKill(conf) || (ConfigFileEntry.glines && IsConfGline(conf)))
367      {
368        if (IsConfGline(conf))
369 <        sendto_one(client_p, ":%s NOTICE %s :*** G-lined", me.name,
370 <                   client_p->name);
362 <      sendto_one(client_p, ":%s NOTICE %s :*** Banned: %s",
363 <                 me.name, client_p->name, conf->reason);
369 >        sendto_one_notice(client_p, &me, ":*** G-lined");
370 >      sendto_one_notice(client_p, &me, ":*** Banned: %s", conf->reason);
371        return BANNED_CLIENT;
372      }
373    }
# Line 383 | Line 390 | attach_iline(struct Client *client_p, st
390    int a_limit_reached = 0;
391    unsigned int local = 0, global = 0, ident = 0;
392  
393 +  assert(conf->class);
394 +
395    ip_found = find_or_add_ip(&client_p->localClient->ip);
396    ip_found->count++;
397    SetIpHash(client_p);
398  
390  if (conf->class == NULL)
391    return NOT_AUTHORIZED;  /* If class is missing, this is best */
392
399    class = conf->class;
400  
401    count_user_host(client_p->username, client_p->host,
# Line 416 | Line 422 | attach_iline(struct Client *client_p, st
422      if (!IsConfExemptLimits(conf))
423        return TOO_MANY;   /* Already at maximum allowed */
424  
425 <    sendto_one(client_p,
426 <               ":%s NOTICE %s :*** Your connection class is full, "
421 <               "but you have exceed_limit = yes;", me.name, client_p->name);
425 >    sendto_one_notice(client_p, &me, ":*** Your connection class is full, "
426 >                      "but you have exceed_limit = yes;");
427    }
428  
429    return attach_conf(client_p, conf);
# Line 577 | Line 582 | hash_ip(struct irc_ssaddr *addr)
582      uint32_t *ip = (uint32_t *)&v6->sin6_addr.s6_addr;
583  
584      hash  = ip[0] ^ ip[3];
585 <    hash ^= hash >> 16;  
586 <    hash ^= hash >> 8;  
585 >    hash ^= hash >> 16;
586 >    hash ^= hash >> 8;
587      hash  = hash & (IP_HASH_SIZE - 1);
588      return hash;
589    }
# Line 589 | Line 594 | hash_ip(struct irc_ssaddr *addr)
594  
595   /* count_ip_hash()
596   *
597 < * inputs        - pointer to counter of number of ips hashed
597 > * inputs        - pointer to counter of number of ips hashed
598   *               - pointer to memory used for ip hash
599   * output        - returned via pointers input
600   * side effects  - NONE
# Line 681 | Line 686 | detach_conf(struct Client *client_p, enu
686      dlinkDelete(ptr, &client_p->localClient->confs);
687      free_dlink_node(ptr);
688  
689 <    if (conf->type & CONF_CLIENT)
689 >    if (conf->type == CONF_CLIENT)
690        remove_from_cidr_check(&client_p->localClient->ip, conf->class);
691  
692      if (--conf->class->ref_count == 0 && conf->class->active == 0)
# Line 777 | Line 782 | find_conf_name(dlink_list *list, const c
782    DLINK_FOREACH(ptr, list->head)
783    {
784      conf = ptr->data;
785 <    
785 >
786      if (conf->type == type)
787      {
788        if (conf->name && (irccmp(conf->name, name) == 0 ||
# Line 895 | Line 900 | find_matching_name_conf(enum maskitem_ty
900          return conf;
901      }
902      break;
903 <  
903 >
904    default:
905      break;
906    }
# Line 932 | Line 937 | find_exact_name_conf(enum maskitem_type
937  
938        if (EmptyString(conf->name))
939          continue;
940 <    
940 >
941        if (irccmp(conf->name, name) == 0)
942        {
943          if ((user == NULL && (host == NULL)))
# Line 998 | Line 1003 | find_exact_name_conf(enum maskitem_type
1003  
1004        if (EmptyString(conf->name))
1005          continue;
1006 <    
1006 >
1007        if (name == NULL)
1008        {
1009          if (EmptyString(conf->host))
# Line 1030 | Line 1035 | rehash(int sig)
1035   {
1036    if (sig != 0)
1037      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1038 <                         "Got signal SIGHUP, reloading ircd.conf file");
1038 >                         "Got signal SIGHUP, reloading configuration file(s)");
1039  
1040    restart_resolver();
1041  
# Line 1119 | Line 1124 | set_default_conf(void)
1124    ConfigServerHide.hide_server_ips = 0;
1125    ConfigServerHide.disable_remote_commands = 0;
1126  
1122  
1127    ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT);
1128    ConfigFileEntry.max_watch = WATCHSIZE_DEFAULT;
1129 +  ConfigFileEntry.cycle_on_host_change = 1;
1130    ConfigFileEntry.glines = 0;
1131    ConfigFileEntry.gline_time = 12 * 3600;
1132    ConfigFileEntry.gline_request_time = GLINE_REQUEST_EXPIRE_DEFAULT;
# Line 1190 | Line 1195 | validate_conf(void)
1195    ConfigFileEntry.max_watch = IRCD_MAX(ConfigFileEntry.max_watch, WATCHSIZE_MIN);
1196   }
1197  
1198 < /* read_conf()
1198 > /* read_conf()
1199   *
1200   * inputs       - file descriptor pointing to config file to use
1201   * output       - None
# Line 1283 | Line 1288 | conf_connect_allowed(struct irc_ssaddr *
1288    return 0;
1289   }
1290  
1286 /* find_kill()
1287 *
1288 * inputs       - pointer to client structure
1289 * output       - pointer to struct MaskItem if found
1290 * side effects - See if this user is klined already,
1291 *                and if so, return struct MaskItem pointer
1292 */
1293 struct MaskItem *
1294 find_kill(struct Client *client_p)
1295 {
1296  struct MaskItem *conf = NULL;
1297
1298  assert(client_p != NULL);
1299
1300  conf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
1301                              CONF_KLINE, client_p->localClient->aftype,
1302                              client_p->username, NULL, 1);
1303  return conf;
1304 }
1305
1306 struct MaskItem *
1307 find_gline(struct Client *client_p)
1308 {
1309  struct MaskItem *conf;
1310
1311  assert(client_p != NULL);
1312
1313  conf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
1314                              CONF_GLINE, client_p->localClient->aftype,
1315                              client_p->username, NULL, 1);
1316  return conf;
1317 }
1318
1291   /* cleanup_tklines()
1292   *
1293   * inputs       - NONE
# Line 1327 | Line 1299 | void
1299   cleanup_tklines(void *notused)
1300   {
1301    hostmask_expire_temporary();
1302 <  expire_tklines(&xconf_items);
1302 >  expire_tklines(&xconf_items);
1303    expire_tklines(&nresv_items);
1304    expire_tklines(&cresv_items);
1305   }
# Line 1394 | Line 1366 | static const struct oper_privs
1366    { OPER_FLAG_SQUIT,          'R' },
1367    { OPER_FLAG_SQUIT_REMOTE,   'S' },
1368    { OPER_FLAG_UNKLINE,        'U' },
1369 <  { OPER_FLAG_X,              'X' },
1369 >  { OPER_FLAG_XLINE,          'X' },
1370    { 0, '\0' }
1371   };
1372  
1373   char *
1374   oper_privs_as_string(const unsigned int port)
1375   {
1376 <  static char privs_out[16];
1376 >  static char privs_out[IRCD_BUFSIZE];
1377    char *privs_ptr = privs_out;
1378    const struct oper_privs *opriv = flag_list;
1379  
# Line 1427 | Line 1399 | oper_privs_as_string(const unsigned int
1399   const char *
1400   get_oper_name(const struct Client *client_p)
1401   {
1402 <  dlink_node *cnode = NULL;
1402 >  const dlink_node *cnode = NULL;
1403    /* +5 for !,@,{,} and null */
1404    static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
1405  
# Line 1435 | Line 1407 | get_oper_name(const struct Client *clien
1407    {
1408      if ((cnode = client_p->localClient->confs.head))
1409      {
1410 <      struct MaskItem *conf = cnode->data;
1410 >      const struct MaskItem *conf = cnode->data;
1411  
1412        if (IsConfOperator(conf))
1413        {
# Line 1445 | Line 1417 | get_oper_name(const struct Client *clien
1417        }
1418      }
1419  
1420 <    /* Probably should assert here for now. If there is an oper out there
1420 >    /* Probably should assert here for now. If there is an oper out there
1421       * with no oper{} conf attached, it would be good for us to know...
1422       */
1423      assert(0); /* Oper without oper conf! */
# Line 1466 | Line 1438 | void
1438   read_conf_files(int cold)
1439   {
1440    const char *filename;
1441 <  char chanmodes[32];
1442 <  char chanlimit[32];
1441 >  char chanmodes[IRCD_BUFSIZE];
1442 >  char chanlimit[IRCD_BUFSIZE];
1443  
1444    conf_parser_ctx.boot = cold;
1445    filename = ConfigFileEntry.configfile;
# Line 1476 | Line 1448 | read_conf_files(int cold)
1448       FIXME: The full path is in conffilenamebuf first time since we
1449               dont know anything else
1450  
1451 <     - Gozem 2002-07-21
1451 >     - Gozem 2002-07-21
1452    */
1453    strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1454  
# Line 1550 | Line 1522 | clear_out_old_conf(void)
1522    /* We only need to free anything allocated by yyparse() here.
1523     * Resetting structs, etc, is taken care of by set_default_conf().
1524     */
1525 <  
1525 >
1526    for (; *iterator != NULL; iterator++)
1527    {
1528      DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
# Line 1637 | Line 1609 | clear_out_old_conf(void)
1609   *
1610   * inputs       - pointer to config item
1611   * output       - NONE
1612 < * side effects - Add a class pointer to a conf
1612 > * side effects - Add a class pointer to a conf
1613   */
1614   void
1615   conf_add_class_to_conf(struct MaskItem *conf, const char *class_name)
1616   {
1617 <  if (class_name == NULL)
1617 >  if (class_name == NULL)
1618    {
1619      conf->class = class_default;
1620  
# Line 1709 | Line 1681 | conf_error_report(const char *msg)
1681  
1682   /*
1683   * valid_tkline()
1684 < *
1684 > *
1685   * inputs       - pointer to ascii string to check
1686   *              - whether the specified time is in seconds or minutes
1687   * output       - -1 not enough parameters
# Line 1718 | Line 1690 | conf_error_report(const char *msg)
1690   * Originally written by Dianora (Diane, db@db.net)
1691   */
1692   time_t
1693 < valid_tkline(const char *p, int minutes)
1693 > valid_tkline(const char *data, const int minutes)
1694   {
1695 +  const unsigned char *p = (const unsigned char *)data;
1696 +  unsigned char tmpch = '\0';
1697    time_t result = 0;
1698  
1699 <  for (; *p; ++p)
1699 >  while ((tmpch = *p++))
1700    {
1701 <    if (!IsDigit(*p))
1701 >    if (!IsDigit(tmpch))
1702        return 0;
1703  
1704      result *= 10;
1705 <    result += (*p & 0xF);
1705 >    result += (tmpch & 0xF);
1706    }
1707  
1708    /*
1709 <   * In the degenerate case where oper does a /quote kline 0 user@host :reason
1709 >   * In the degenerate case where oper does a /quote kline 0 user@host :reason
1710     * i.e. they specifically use 0, I am going to return 1 instead
1711     * as a return value of non-zero is used to flag it as a temporary kline
1712     */
1713    if (result == 0)
1714      result = 1;
1715  
1716 <  /*
1716 >  /*
1717     * If the incoming time is in seconds convert it to minutes for the purpose
1718     * of this calculation
1719     */
1720    if (!minutes)
1721 <    result = result / (time_t)60;
1721 >    result = result / 60;
1722  
1723    if (result > MAX_TDKLINE_TIME)
1724      result = MAX_TDKLINE_TIME;
1725  
1726 <  result = result * (time_t)60;  /* turn it into seconds */
1726 >  result = result * 60;  /* turn it into seconds */
1727  
1728    return result;
1729   }
# Line 1829 | Line 1803 | valid_wild_card(struct Client *source_p,
1803           * break - no point in searching further.
1804           */
1805          if (++nonwild >= ConfigFileEntry.min_nonwildcard)
1806 +        {
1807 +          va_end(args);
1808            return 1;
1809 +        }
1810        }
1811      }
1812    }
1813  
1814    if (warn)
1815 <    sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the mask",
1816 <               me.name, source_p->name, ConfigFileEntry.min_nonwildcard);
1815 >    sendto_one_notice(source_p, &me,
1816 >                      ":Please include at least %d non-wildcard characters with the mask",
1817 >                      ConfigFileEntry.min_nonwildcard);
1818 >  va_end(args);
1819    return 0;
1820   }
1821  
# Line 1850 | Line 1829 | valid_wild_card(struct Client *source_p,
1829   *              - parse_flags bit map of things to test
1830   *              - pointer to user or string to parse into
1831   *              - pointer to host or NULL to parse into if non NULL
1832 < *              - pointer to optional tkline time or NULL
1832 > *              - pointer to optional tkline time or NULL
1833   *              - pointer to target_server to parse into if non NULL
1834   *              - pointer to reason to parse into
1835   *
# Line 1895 | Line 1874 | parse_aline(const char *cmd, struct Clie
1874        *tkline_time = found_tkline_time;
1875      else
1876      {
1877 <      sendto_one(source_p, ":%s NOTICE %s :temp_line not supported by %s",
1899 <                 me.name, source_p->name, cmd);
1877 >      sendto_one_notice(source_p, &me, ":temp_line not supported by %s", cmd);
1878        return -1;
1879      }
1880    }
1881  
1882    if (parc == 0)
1883    {
1884 <    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1907 <               me.name, source_p->name, cmd);
1884 >    sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1885      return -1;
1886    }
1887  
# Line 1918 | Line 1895 | parse_aline(const char *cmd, struct Clie
1895      *up_p = user;
1896      *h_p = host;
1897    }
1898 <
1898 >
1899    parc--;
1900    parv++;
1901  
# Line 1931 | Line 1908 | parse_aline(const char *cmd, struct Clie
1908  
1909        if (target_server == NULL)
1910        {
1911 <        sendto_one(source_p, ":%s NOTICE %s :ON server not supported by %s",
1935 <                   me.name, source_p->name, cmd);
1911 >        sendto_one_notice(source_p, &me, ":ON server not supported by %s", cmd);
1912          return -1;
1913        }
1914  
1915        if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
1916        {
1917 <        sendto_one(source_p, form_str(ERR_NOPRIVS),
1942 <                   me.name, source_p->name, "remoteban");
1917 >        sendto_one_numeric(source_p, &me, ERR_NOPRIVS, "remoteban");
1918          return -1;
1919        }
1920  
1921        if (parc == 0 || EmptyString(*parv))
1922        {
1923 <        sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1949 <                   me.name, source_p->name, cmd);
1923 >        sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, cmd);
1924          return -1;
1925        }
1926  
# Line 1968 | Line 1942 | parse_aline(const char *cmd, struct Clie
1942    {
1943      if (strchr(user, '!') != NULL)
1944      {
1945 <      sendto_one(source_p, ":%s NOTICE %s :Invalid character '!' in kline",
1972 <                 me.name, source_p->name);
1945 >      sendto_one_notice(source_p, &me, ":Invalid character '!' in kline");
1946        return -1;
1947      }
1948  
# Line 2040 | Line 2013 | find_user_host(struct Client *source_p,
2013        luser[1] = '\0';
2014        strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
2015      }
2016 <    
2016 >
2017      return 1;
2018    }
2019    else
2020    {
2021      /* Try to find user@host mask from nick */
2022      /* Okay to use source_p as the first param, because source_p == client_p */
2023 <    if ((target_p =
2024 <        find_chasing(source_p, source_p, user_host_or_nick, NULL)) == NULL)
2023 >    if ((target_p =
2024 >        find_chasing(source_p, user_host_or_nick)) == NULL)
2025        return 0;
2026  
2027      if (IsExemptKline(target_p))
2028      {
2029        if (!IsServer(source_p))
2030 <        sendto_one(source_p,
2058 <                   ":%s NOTICE %s :%s is E-lined",
2059 <                   me.name, source_p->name, target_p->name);
2030 >        sendto_one_notice(source_p, &me, ":%s is E-lined", target_p->name);
2031        return 0;
2032      }
2033  
# Line 2201 | Line 2172 | split_nuh(struct split_nuh_item *const i
2172      if (iptr->nickptr && *iptr->nuhmask != '\0')
2173        strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
2174  
2175 <    if ((q = strchr(++p, '@'))) {
2175 >    if ((q = strchr(++p, '@')))
2176 >    {
2177        *q++ = '\0';
2178  
2179        if (*p != '\0')

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)