]> jfr.im git - solanum.git/blobdiff - ircd/s_conf.c
ircd startup: avoid black magic with file descriptors
[solanum.git] / ircd / s_conf.c
index d952981b427856e45386ece170a390ecafa8e2aa..74df1cfa1b4285eb2ef3409a569f841d2af5ba3a 100644 (file)
@@ -32,7 +32,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"
 
 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;
 
@@ -169,7 +164,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
@@ -190,7 +185,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;
 
@@ -260,12 +255,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));
 
                        ServerStats.is_ref++;
                        /* jdc - lists server name & port connections are on */
@@ -394,7 +384,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
@@ -404,7 +394,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;
@@ -636,18 +626,19 @@ 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)
-       {
+       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));
@@ -655,11 +646,13 @@ rehash(int sig)
                rb_strlcpy(me.info, "unknown", sizeof(me.info));
 
        open_logfiles();
-       return (0);
+
+       call_hook(h_rehash, &hdata);
+       return false;
 }
 
 void
-rehash_bans(int sig)
+rehash_bans(void)
 {
        bandb_rehash_bans();
 }
@@ -683,15 +676,13 @@ set_default_conf(void)
        ServerInfo.description = NULL;
        ServerInfo.network_name = NULL;
 
-       memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip));
-       ServerInfo.specific_ipv4_vhost = 0;
+       memset(&ServerInfo.bind4, 0, sizeof(ServerInfo.bind4));
+       SET_SS_FAMILY(&ServerInfo.bind4, AF_UNSPEC);
 #ifdef RB_IPV6
-       memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6));
-       ServerInfo.specific_ipv6_vhost = 0;
+       memset(&ServerInfo.bind6, 0, sizeof(ServerInfo.bind6));
+       SET_SS_FAMILY(&ServerInfo.bind6, AF_UNSPEC);
 #endif
 
-       /* Don't reset hub, as that will break lazylinks */
-       /* ServerInfo.hub = false; */
        AdminInfo.name = NULL;
        AdminInfo.email = NULL;
        AdminInfo.description = NULL;
@@ -818,11 +809,11 @@ 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;
 
        if (!alias_dict)
-               alias_dict = rb_dictionary_create("alias", strcasecmp);
+               alias_dict = rb_dictionary_create("alias", rb_strcasecmp);
 }
 
 /*
@@ -865,20 +856,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 */
@@ -1419,7 +1419,7 @@ read_conf_files(bool 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;
 
@@ -1529,7 +1529,7 @@ clear_out_old_conf(void)
                alias_dict = NULL;
        }
 
-       destroy_blacklists();
+       del_blacklist_all();
 
        privilegeset_mark_all_illegal();
 
@@ -1639,7 +1639,7 @@ yyerror(const char *msg)
 {
        char newlinebuf[BUFSIZE];
 
-       strip_tabs(newlinebuf, linebuf, strlen(linebuf));
+       strip_tabs(newlinebuf, yy_linebuf, strlen(yy_linebuf));
 
        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'",