]> jfr.im git - solanum.git/blobdiff - ircd/s_conf.c
Add general::hidden_caps
[solanum.git] / ircd / s_conf.c
index 0377678933302091e5ebcb2cacb0da9223e4998e..8bd98aa05ed2187083a50fc1b64fd4a05c5d0ae4 100644 (file)
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
- *
- *  $Id: s_conf.c 3550 2007-08-09 06:47:26Z nenolod $
  */
 
 #include "stdinc.h"
 #include "ircd_defs.h"
 #include "s_conf.h"
+#include "s_user.h"
 #include "s_newconf.h"
 #include "newconf.h"
 #include "s_serv.h"
@@ -34,7 +33,6 @@
 #include "channel.h"
 #include "class.h"
 #include "client.h"
-#include "common.h"
 #include "hash.h"
 #include "match.h"
 #include "ircd.h"
 #include "send.h"
 #include "reject.h"
 #include "cache.h"
-#include "blacklist.h"
 #include "privilege.h"
 #include "sslproc.h"
+#include "wsproc.h"
 #include "bandbi.h"
 #include "operhash.h"
 #include "chmode.h"
 #include "hook.h"
 #include "s_assert.h"
-#include "authd.h"
+#include "authproc.h"
+#include "supported.h"
 
 struct config_server_hide ConfigServerHide;
 
 extern int yyparse(void);              /* defined in y.tab.c */
-extern char linebuf[];
-
-#ifndef INADDR_NONE
-#define INADDR_NONE ((unsigned int) 0xffffffff)
-#endif
+extern char yy_linebuf[16384];         /* defined in ircd_lexer.l */
 
 static rb_bh *confitem_heap = NULL;
 
@@ -171,7 +166,7 @@ free_conf(struct ConfItem *aconf)
  * inputs      - pointer to client
  * output      - 0 = Success
  *               NOT_AUTHORISED (-1) = Access denied (no I line match)
- *               SOCKET_ERROR   (-2) = Bad socket.
+ *               I_SOCKET_ERROR (-2) = Bad socket.
  *               I_LINE_FULL    (-3) = I-line is full
  *               TOO_MANY       (-4) = Too many connections from hostname
  *               BANNED_CLIENT  (-5) = K-lined
@@ -192,7 +187,7 @@ check_client(struct Client *client_p, struct Client *source_p, const char *usern
 
        switch (i)
        {
-       case SOCKET_ERROR:
+       case I_SOCKET_ERROR:
                exit_client(client_p, source_p, &me, "Socket Error");
                break;
 
@@ -262,12 +257,7 @@ check_client(struct Client *client_p, struct Client *source_p, const char *usern
        case NOT_AUTHORISED:
                {
                        int port = -1;
-#ifdef RB_IPV6
-                       if(source_p->localClient->ip.ss_family == AF_INET6)
-                               port = ntohs(((struct sockaddr_in6 *)&source_p->localClient->listener->addr)->sin6_port);
-                       else
-#endif
-                               port = ntohs(((struct sockaddr_in *)&source_p->localClient->listener->addr)->sin_port);
+                       port = ntohs(GET_SS_PORT(&source_p->localClient->listener->addr[0]));
 
                        ServerStats.is_ref++;
                        /* jdc - lists server name & port connections are on */
@@ -290,9 +280,8 @@ check_client(struct Client *client_p, struct Client *source_p, const char *usern
                                source_p->name, IsGotId(source_p) ? "" : "~",
                                source_p->username, source_p->sockhost,
                                source_p->localClient->listener->name, port);
-                       add_reject(client_p, NULL, NULL);
-                       exit_client(client_p, source_p, &me,
-                                   "You are not authorised to use this server");
+                       add_reject(client_p, NULL, NULL, NULL, "You are not authorised to use this server.");
+                       exit_client(client_p, source_p, &me, "You are not authorised to use this server.");
                        break;
                }
        case BANNED_CLIENT:
@@ -374,7 +363,7 @@ verify_access(struct Client *client_p, const char *username)
                                        form_str(ERR_YOUREBANNEDCREEP),
                                        me.name, client_p->name,
                                        get_user_ban_reason(aconf));
-               add_reject(client_p, aconf->user, aconf->host);
+               add_reject(client_p, aconf->user, aconf->host, aconf, NULL);
                return (BANNED_CLIENT);
        }
 
@@ -396,7 +385,7 @@ find_address_conf_by_client(struct Client *client_p, const char *username)
                aconf = find_address_conf(client_p->host, client_p->sockhost,
                                        client_p->username, client_p->username,
                                        (struct sockaddr *) &client_p->localClient->ip,
-                                       client_p->localClient->ip.ss_family,
+                                       GET_SS_FAMILY(&client_p->localClient->ip),
                                        client_p->localClient->auth_user);
        }
        else
@@ -406,7 +395,7 @@ find_address_conf_by_client(struct Client *client_p, const char *username)
                aconf = find_address_conf(client_p->host, client_p->sockhost,
                                        non_ident, client_p->username,
                                        (struct sockaddr *) &client_p->localClient->ip,
-                                       client_p->localClient->ip.ss_family,
+                                       GET_SS_FAMILY(&client_p->localClient->ip),
                                        client_p->localClient->auth_user);
        }
        return aconf;
@@ -541,6 +530,20 @@ attach_iline(struct Client *client_p, struct ConfItem *aconf)
        return (attach_conf(client_p, aconf));
 }
 
+/*
+ * deref_conf
+ *
+ * inputs      - ConfItem that is referenced by something other than a client
+ * side effects        - Decrement and free ConfItem if appropriate
+ */
+void
+deref_conf(struct ConfItem *aconf)
+{
+       aconf->clients--;
+       if(!aconf->clients && IsIllegal(aconf))
+               free_conf(aconf);
+}
+
 /*
  * detach_conf
  *
@@ -601,11 +604,11 @@ attach_conf(struct Client *client_p, struct ConfItem *aconf)
        if(IsIllegal(aconf))
                return (NOT_AUTHORISED);
 
-       if(ClassPtr(aconf))
-       {
-               if(!add_ip_limit(client_p, aconf))
-                       return (TOO_MANY_LOCAL);
-       }
+       if(s_assert(ClassPtr(aconf)))
+               return (NOT_AUTHORISED);
+
+       if(!add_ip_limit(client_p, aconf))
+               return (TOO_MANY_LOCAL);
 
        if((aconf->status & CONF_CLIENT) &&
           ConfCurrUsers(aconf) >= ConfMaxUsers(aconf) && ConfMaxUsers(aconf) > 0)
@@ -638,18 +641,21 @@ attach_conf(struct Client *client_p, struct ConfItem *aconf)
  * as a result of an operator issuing this command, else assume it has been
  * called as a result of the server receiving a HUP signal.
  */
-int
-rehash(int sig)
+bool
+rehash(bool sig)
 {
-       if(sig != 0)
-       {
+       rb_dlink_node *n;
+
+       hook_data_rehash hdata = { sig };
+
+       if(sig)
                sendto_realops_snomask(SNO_GENERAL, L_ALL,
                                     "Got signal SIGHUP, reloading ircd conf. file");
-       }
 
        rehash_authd();
+
        /* don't close listeners until we know we can go ahead with the rehash */
-       read_conf_files(NO);
+       read_conf_files(false);
 
        if(ServerInfo.description != NULL)
                rb_strlcpy(me.info, ServerInfo.description, sizeof(me.info));
@@ -657,11 +663,23 @@ rehash(int sig)
                rb_strlcpy(me.info, "unknown", sizeof(me.info));
 
        open_logfiles();
-       return (0);
+
+       RB_DLINK_FOREACH(n, local_oper_list.head)
+       {
+               struct Client *oper = n->data;
+               const char *modeparv[4];
+               modeparv[0] = modeparv[1] = oper->name;
+               modeparv[2] = "+";
+               modeparv[3] = NULL;
+               user_mode(oper, oper, 3, modeparv);
+       }
+
+       call_hook(h_rehash, &hdata);
+       return false;
 }
 
 void
-rehash_bans(int sig)
+rehash_bans(void)
 {
        bandb_rehash_bans();
 }
@@ -677,10 +695,6 @@ rehash_bans(int sig)
  *               of values later, put them in validate_conf().
  */
 
-#define YES     1
-#define NO      0
-#define UNSET  -1
-
 static void
 set_default_conf(void)
 {
@@ -689,15 +703,11 @@ set_default_conf(void)
        ServerInfo.description = NULL;
        ServerInfo.network_name = NULL;
 
-       memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip));
-       ServerInfo.specific_ipv4_vhost = 0;
-#ifdef RB_IPV6
-       memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6));
-       ServerInfo.specific_ipv6_vhost = 0;
-#endif
+       memset(&ServerInfo.bind4, 0, sizeof(ServerInfo.bind4));
+       SET_SS_FAMILY(&ServerInfo.bind4, AF_UNSPEC);
+       memset(&ServerInfo.bind6, 0, sizeof(ServerInfo.bind6));
+       SET_SS_FAMILY(&ServerInfo.bind6, AF_UNSPEC);
 
-       /* Don't reset hub, as that will break lazylinks */
-       /* ServerInfo.hub = NO; */
        AdminInfo.name = NULL;
        AdminInfo.email = NULL;
        AdminInfo.description = NULL;
@@ -708,39 +718,38 @@ set_default_conf(void)
        ConfigFileEntry.sasl_service = NULL;
 
        ConfigFileEntry.default_umodes = UMODE_INVISIBLE;
-       ConfigFileEntry.failed_oper_notice = YES;
-       ConfigFileEntry.anti_nick_flood = NO;
-       ConfigFileEntry.disable_fake_channels = NO;
+       ConfigFileEntry.failed_oper_notice = true;
+       ConfigFileEntry.anti_nick_flood = false;
+       ConfigFileEntry.disable_fake_channels = false;
        ConfigFileEntry.max_nick_time = 20;
        ConfigFileEntry.max_nick_changes = 5;
        ConfigFileEntry.max_accept = 20;
        ConfigFileEntry.max_monitor = 60;
        ConfigFileEntry.nick_delay = 900;       /* 15 minutes */
-       ConfigFileEntry.target_change = YES;
+       ConfigFileEntry.target_change = true;
        ConfigFileEntry.anti_spam_exit_message_time = 0;
        ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
        ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
-       ConfigFileEntry.client_exit = YES;
-       ConfigFileEntry.dline_with_reason = YES;
-       ConfigFileEntry.kline_with_reason = YES;
-       ConfigFileEntry.kline_delay = 0;
-       ConfigFileEntry.warn_no_nline = YES;
-       ConfigFileEntry.non_redundant_klines = YES;
-       ConfigFileEntry.stats_e_disabled = NO;
-       ConfigFileEntry.stats_o_oper_only = NO;
+       ConfigFileEntry.client_exit = true;
+       ConfigFileEntry.dline_with_reason = true;
+       ConfigFileEntry.kline_with_reason = true;
+       ConfigFileEntry.warn_no_nline = true;
+       ConfigFileEntry.non_redundant_klines = true;
+       ConfigFileEntry.stats_e_disabled = false;
+       ConfigFileEntry.stats_o_oper_only = false;
        ConfigFileEntry.stats_k_oper_only = 1;  /* masked */
        ConfigFileEntry.stats_i_oper_only = 1;  /* masked */
-       ConfigFileEntry.stats_P_oper_only = NO;
-       ConfigFileEntry.stats_c_oper_only = NO;
-       ConfigFileEntry.stats_y_oper_only = NO;
-       ConfigFileEntry.stats_h_oper_only = NO;
-       ConfigFileEntry.map_oper_only = YES;
-       ConfigFileEntry.operspy_admin_only = NO;
+       ConfigFileEntry.stats_P_oper_only = false;
+       ConfigFileEntry.stats_c_oper_only = false;
+       ConfigFileEntry.stats_y_oper_only = false;
+       ConfigFileEntry.stats_h_oper_only = false;
+       ConfigFileEntry.map_oper_only = true;
+       ConfigFileEntry.operspy_admin_only = false;
        ConfigFileEntry.pace_wait = 10;
        ConfigFileEntry.caller_id_wait = 60;
        ConfigFileEntry.pace_wait_simple = 1;
-       ConfigFileEntry.short_motd = NO;
-       ConfigFileEntry.no_oper_flood = NO;
+       ConfigFileEntry.short_motd = false;
+       ConfigFileEntry.no_oper_flood = false;
        ConfigFileEntry.fname_userlog = NULL;
        ConfigFileEntry.fname_fuserlog = NULL;
        ConfigFileEntry.fname_operlog = NULL;
@@ -750,19 +759,20 @@ set_default_conf(void)
        ConfigFileEntry.fname_klinelog = NULL;
        ConfigFileEntry.fname_operspylog = NULL;
        ConfigFileEntry.fname_ioerrorlog = NULL;
-       ConfigFileEntry.hide_spoof_ips = YES;
+       ConfigFileEntry.hide_spoof_ips = true;
        ConfigFileEntry.hide_error_messages = 1;
        ConfigFileEntry.dots_in_ident = 0;
        ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
-       ConfigFileEntry.use_whois_actually = YES;
-       ConfigFileEntry.burst_away = NO;
-       ConfigFileEntry.collision_fnc = YES;
-       ConfigFileEntry.resv_fnc = YES;
-       ConfigFileEntry.global_snotices = YES;
-       ConfigFileEntry.operspy_dont_care_user_info = NO;
-       ConfigFileEntry.use_propagated_bans = YES;
+       ConfigFileEntry.use_whois_actually = true;
+       ConfigFileEntry.burst_away = false;
+       ConfigFileEntry.collision_fnc = true;
+       ConfigFileEntry.resv_fnc = true;
+       ConfigFileEntry.global_snotices = true;
+       ConfigFileEntry.operspy_dont_care_user_info = false;
+       ConfigFileEntry.use_propagated_bans = true;
        ConfigFileEntry.max_ratelimit_tokens = 30;
        ConfigFileEntry.away_interval = 30;
+       ConfigFileEntry.tls_ciphers_oper_only = false;
 
 #ifdef HAVE_LIBZ
        ConfigFileEntry.compression_level = 4;
@@ -773,28 +783,29 @@ set_default_conf(void)
        ConfigFileEntry.oper_only_umodes = UMODE_SERVNOTICE;
        ConfigFileEntry.oper_snomask = SNO_GENERAL;
 
-       ConfigChannel.use_except = YES;
-       ConfigChannel.use_invex = YES;
-       ConfigChannel.use_forward = YES;
-       ConfigChannel.use_knock = YES;
+       ConfigChannel.use_except = true;
+       ConfigChannel.use_invex = true;
+       ConfigChannel.use_forward = true;
+       ConfigChannel.use_knock = true;
        ConfigChannel.knock_delay = 300;
        ConfigChannel.knock_delay_channel = 60;
        ConfigChannel.max_chans_per_user = 15;
        ConfigChannel.max_chans_per_user_large = 60;
        ConfigChannel.max_bans = 25;
        ConfigChannel.max_bans_large = 500;
-       ConfigChannel.only_ascii_channels = NO;
-       ConfigChannel.burst_topicwho = NO;
-       ConfigChannel.kick_on_split_riding = NO;
+       ConfigChannel.only_ascii_channels = false;
+       ConfigChannel.burst_topicwho = false;
+       ConfigChannel.kick_on_split_riding = false;
 
        ConfigChannel.default_split_user_count = 15000;
        ConfigChannel.default_split_server_count = 10;
-       ConfigChannel.no_join_on_split = NO;
-       ConfigChannel.no_create_on_split = YES;
-       ConfigChannel.resv_forcepart = YES;
-       ConfigChannel.channel_target_change = YES;
-       ConfigChannel.disable_local_channels = NO;
+       ConfigChannel.no_join_on_split = false;
+       ConfigChannel.no_create_on_split = true;
+       ConfigChannel.resv_forcepart = true;
+       ConfigChannel.channel_target_change = true;
+       ConfigChannel.disable_local_channels = false;
        ConfigChannel.displayed_usercount = 3;
+       ConfigChannel.opmod_send_statusmsg = false;
 
        ConfigChannel.autochanmodes = MODE_TOPICLIMIT | MODE_NOPRIVMSGS;
 
@@ -824,16 +835,14 @@ set_default_conf(void)
        ServerInfo.default_max_clients = MAXCONNECTIONS;
 
        ConfigFileEntry.nicklen = NICKLEN;
-       ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_SHA1;
+       ConfigFileEntry.certfp_method = RB_SSL_CERTFP_METH_CERT_SHA1;
        ConfigFileEntry.hide_opers_in_whois = 0;
+       ConfigFileEntry.hide_opers = 0;
 
        if (!alias_dict)
-               alias_dict = irc_dictionary_create("alias", strcasecmp);
+               alias_dict = rb_dictionary_create("alias", rb_strcasecmp);
 }
 
-#undef YES
-#undef NO
-
 /*
  * read_conf()
  *
@@ -874,20 +883,29 @@ validate_conf(void)
        if(ServerInfo.ssld_count < 1)
                ServerInfo.ssld_count = 1;
 
+       /* XXX: configurable? */
+       ServerInfo.wsockd_count = 1;
+
        if(!rb_setup_ssl_server(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params, ServerInfo.ssl_cipher_list))
        {
                ilog(L_MAIN, "WARNING: Unable to setup SSL.");
-               ssl_ok = 0;
+               ircd_ssl_ok = false;
        } else {
-               ssl_ok = 1;
-               send_new_ssl_certs(ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params, ServerInfo.ssl_cipher_list);
+               ircd_ssl_ok = true;
+               ssld_update_config();
        }
 
        if(ServerInfo.ssld_count > get_ssld_count())
        {
                int start = ServerInfo.ssld_count - get_ssld_count();
                /* start up additional ssld if needed */
-               start_ssldaemon(start, ServerInfo.ssl_cert, ServerInfo.ssl_private_key, ServerInfo.ssl_dh_params, ServerInfo.ssl_cipher_list);
+               start_ssldaemon(start);
+       }
+
+       if(ServerInfo.wsockd_count > get_wsockd_count())
+       {
+               int start = ServerInfo.wsockd_count - get_wsockd_count();
+               start_wsockd(start);
        }
 
        /* General conf */
@@ -927,6 +945,12 @@ validate_conf(void)
                splitmode = 0;
                splitchecking = 0;
        }
+
+       CharAttrs['&'] |= CHANPFX_C;
+       if (ConfigChannel.disable_local_channels)
+               CharAttrs['&'] &= ~CHANPFX_C;
+
+       chantypes_update();
 }
 
 /* add_temp_kline()
@@ -1114,12 +1138,17 @@ deactivate_conf(struct ConfItem *aconf, rb_dlink_node *ptr, time_t now)
                        break;
        }
        if (aconf->lifetime != 0 && now < aconf->lifetime)
+       {
                aconf->status |= CONF_ILLEGAL;
+       }
        else
        {
                if (aconf->lifetime != 0)
                        rb_dlinkDestroy(ptr, &prop_bans);
-               free_conf(aconf);
+               if (aconf->clients == 0)
+                       free_conf(aconf);
+               else
+                       aconf->status |= CONF_ILLEGAL;
        }
 }
 
@@ -1265,13 +1294,13 @@ char *
 get_oper_name(struct Client *client_p)
 {
        /* +5 for !,@,{,} and null */
-       static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
+       static char buffer[NAMELEN + USERLEN + HOSTLEN + HOSTLEN + 5];
 
        if(MyOper(client_p))
        {
                snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}",
                                client_p->name, client_p->username,
-                               client_p->host, client_p->localClient->opername);
+                               client_p->host, client_p->user->opername);
                return buffer;
        }
 
@@ -1317,7 +1346,8 @@ get_user_ban_reason(struct ConfItem *aconf)
 {
        static char reasonbuf[BUFSIZE];
 
-       if (aconf->flags & CONF_FLAGS_TEMPORARY &&
+       if (!ConfigFileEntry.hide_tkdline_duration &&
+                       aconf->flags & CONF_FLAGS_TEMPORARY &&
                        (aconf->status == CONF_KILL || aconf->status == CONF_DLINE))
                snprintf(reasonbuf, sizeof reasonbuf,
                                "Temporary %c-line %d min. - ",
@@ -1351,7 +1381,7 @@ get_printable_kline(struct Client *source_p, struct ConfItem *aconf,
        *user = EmptyString(aconf->user) ? null : aconf->user;
        *reason = get_user_ban_reason(aconf);
 
-       if(!IsOper(source_p))
+       if(!IsOperGeneral(source_p))
                *oper_reason = NULL;
        else
        {
@@ -1366,12 +1396,12 @@ get_printable_kline(struct Client *source_p, struct ConfItem *aconf,
 /*
  * read_conf_files
  *
- * inputs       - cold start YES or NO
+ * inputs       - cold start
  * output       - none
  * side effects - read all conf files needed, ircd.conf kline.conf etc.
  */
 void
-read_conf_files(int cold)
+read_conf_files(bool cold)
 {
        const char *filename;
 
@@ -1428,7 +1458,7 @@ read_conf_files(int cold)
  * free an alias{} entry.
  */
 static void
-free_alias_cb(struct DictionaryElement *ptr, void *unused)
+free_alias_cb(rb_dictionary_element *ptr, void *unused)
 {
        struct alias_entry *aptr = ptr->data;
 
@@ -1461,7 +1491,7 @@ clear_out_old_conf(void)
                MaxUsers(cltmp) = -1;
        }
 
-       clear_out_address_conf();
+       clear_out_address_conf(AC_CONFIG);
        clear_s_newconf();
 
        /* clean out module paths */
@@ -1505,6 +1535,14 @@ clear_out_old_conf(void)
        rb_free(ConfigFileEntry.sasl_service);
        ConfigFileEntry.sasl_service = NULL;
 
+       if (ConfigFileEntry.hidden_caps != NULL)
+       {
+               for (size_t i = 0; ConfigFileEntry.hidden_caps[i] != NULL; i++)
+                       rb_free(ConfigFileEntry.hidden_caps[i]);
+               rb_free(ConfigFileEntry.hidden_caps);
+       }
+       ConfigFileEntry.hidden_caps = NULL;
+
        /* clean out log */
        rb_free(ConfigFileEntry.fname_userlog);
        ConfigFileEntry.fname_userlog = NULL;
@@ -1534,11 +1572,11 @@ clear_out_old_conf(void)
        /* remove any aliases... -- nenolod */
        if (alias_dict != NULL)
        {
-               irc_dictionary_destroy(alias_dict, free_alias_cb, NULL);
+               rb_dictionary_destroy(alias_dict, free_alias_cb, NULL);
                alias_dict = NULL;
        }
 
-       destroy_blacklists();
+       del_dnsbl_entry_all();
 
        privilegeset_mark_all_illegal();
 
@@ -1617,15 +1655,15 @@ conf_add_d_conf(struct ConfItem *aconf)
        }
 }
 
-static char *
-strip_tabs(char *dest, const char *src, size_t len)
+static void
+strip_tabs(char *dest, const char *src, size_t size)
 {
        char *d = dest;
 
        if(dest == NULL || src == NULL)
-               return NULL;
+               return;
 
-       rb_strlcpy(dest, src, len);
+       rb_strlcpy(dest, src, size);
 
        while(*d)
        {
@@ -1633,7 +1671,6 @@ strip_tabs(char *dest, const char *src, size_t len)
                        *d = ' ';
                d++;
        }
-       return dest;
 }
 
 /*
@@ -1648,7 +1685,7 @@ yyerror(const char *msg)
 {
        char newlinebuf[BUFSIZE];
 
-       strip_tabs(newlinebuf, linebuf, strlen(linebuf));
+       strip_tabs(newlinebuf, yy_linebuf, sizeof(newlinebuf));
 
        ierror("\"%s\", line %d: %s at '%s'", conffilebuf, lineno + 1, msg, newlinebuf);
        sendto_realops_snomask(SNO_GENERAL, L_ALL, "\"%s\", line %d: %s at '%s'",