]> jfr.im git - solanum.git/blobdiff - ircd/s_newconf.c
valid_temp_time: more simplification and test fixes
[solanum.git] / ircd / s_newconf.c
index 7231d13e70cf6f84abd0872a71a600ff1e5777fb..6ecf1a519fde1642a82d440285431c46a62467d0 100644 (file)
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
- *
- * $Id: s_newconf.c 3508 2007-06-04 16:04:49Z jilles $
  */
 
 #include "stdinc.h"
 #include "ircd_defs.h"
-#include "common.h"
 #include "s_conf.h"
 #include "s_newconf.h"
 #include "client.h"
 #include "hostmask.h"
 #include "newconf.h"
 #include "hash.h"
-#include "irc_dictionary.h"
-#include "irc_radixtree.h"
+#include "rb_dictionary.h"
+#include "rb_radixtree.h"
 #include "s_assert.h"
 #include "logger.h"
 #include "dns.h"
 
-rb_dlink_list shared_conf_list;
 rb_dlink_list cluster_conf_list;
 rb_dlink_list oper_conf_list;
-rb_dlink_list hubleaf_conf_list;
 rb_dlink_list server_conf_list;
 rb_dlink_list xline_conf_list;
 rb_dlink_list resv_conf_list;  /* nicks only! */
@@ -85,25 +80,12 @@ clear_s_newconf(void)
        rb_dlink_node *ptr;
        rb_dlink_node *next_ptr;
 
-       RB_DLINK_FOREACH_SAFE(ptr, next_ptr, shared_conf_list.head)
-       {
-               /* ptr here is ptr->data->node */
-               rb_dlinkDelete(ptr, &shared_conf_list);
-               free_remote_conf(ptr->data);
-       }
-
        RB_DLINK_FOREACH_SAFE(ptr, next_ptr, cluster_conf_list.head)
        {
                rb_dlinkDelete(ptr, &cluster_conf_list);
                free_remote_conf(ptr->data);
        }
 
-       RB_DLINK_FOREACH_SAFE(ptr, next_ptr, hubleaf_conf_list.head)
-       {
-               rb_dlinkDelete(ptr, &hubleaf_conf_list);
-               free_remote_conf(ptr->data);
-       }
-
        RB_DLINK_FOREACH_SAFE(ptr, next_ptr, oper_conf_list.head)
        {
                free_oper_conf(ptr->data);
@@ -176,31 +158,6 @@ free_remote_conf(struct remote_conf *remote_p)
        rb_free(remote_p);
 }
 
-int
-find_shared_conf(const char *username, const char *host,
-               const char *server, int flags)
-{
-       struct remote_conf *shared_p;
-       rb_dlink_node *ptr;
-
-       RB_DLINK_FOREACH(ptr, shared_conf_list.head)
-       {
-               shared_p = ptr->data;
-
-               if(match(shared_p->username, username) &&
-                  match(shared_p->host, host) &&
-                  match(shared_p->server, server))
-               {
-                       if(shared_p->flags & flags)
-                               return YES;
-                       else
-                               return NO;
-               }
-       }
-
-       return NO;
-}
-
 void
 propagate_generic(struct Client *source_p, const char *command,
                const char *target, int cap, const char *format, ...)
@@ -307,7 +264,7 @@ find_oper_conf(const char *username, const char *host, const char *locip, const
 
                if(parse_netmask(addr, &ip, &bits) != HM_HOST)
                {
-                       if(ip.ss_family == cip.ss_family &&
+                       if(GET_SS_FAMILY(&ip) == GET_SS_FAMILY(&cip) &&
                           comp_with_mask_sock((struct sockaddr *)&ip, (struct sockaddr *)&cip, bits))
                                return oper_p;
                }
@@ -327,7 +284,21 @@ struct server_conf *
 make_server_conf(void)
 {
        struct server_conf *server_p = rb_malloc(sizeof(struct server_conf));
-       server_p->aftype = AF_INET;
+
+       SET_SS_FAMILY(&server_p->connect4, AF_UNSPEC);
+       SET_SS_LEN(&server_p->connect4, sizeof(struct sockaddr_in));
+
+       SET_SS_FAMILY(&server_p->bind4, AF_UNSPEC);
+       SET_SS_LEN(&server_p->bind4, sizeof(struct sockaddr_in));
+
+       SET_SS_FAMILY(&server_p->connect6, AF_UNSPEC);
+       SET_SS_LEN(&server_p->connect6, sizeof(struct sockaddr_in6));
+
+       SET_SS_FAMILY(&server_p->bind6, AF_UNSPEC);
+       SET_SS_LEN(&server_p->bind6, sizeof(struct sockaddr_in6));
+
+       server_p->aftype = AF_UNSPEC;
+
        return server_p;
 }
 
@@ -351,13 +322,46 @@ free_server_conf(struct server_conf *server_p)
        }
 
        rb_free(server_p->name);
-       rb_free(server_p->host);
+       rb_free(server_p->connect_host);
+       rb_free(server_p->bind_host);
        rb_free(server_p->class_name);
+       rb_free(server_p->certfp);
        rb_free(server_p);
 }
 
 /*
- * conf_dns_callback
+ * conf_connect_dns_callback
+ * inputs       - pointer to struct ConfItem
+ *              - pointer to adns reply
+ * output       - none
+ * side effects - called when resolver query finishes
+ * if the query resulted in a successful search, hp will contain
+ * a non-null pointer, otherwise hp will be null.
+ * if successful save hp in the conf item it was called with
+ */
+static void
+conf_connect_dns_callback(const char *result, int status, int aftype, void *data)
+{
+       struct server_conf *server_p = data;
+
+       if(aftype == AF_INET)
+       {
+               if(status == 1)
+                       rb_inet_pton_sock(result, &server_p->connect4);
+
+               server_p->dns_query_connect4 = 0;
+       }
+       else if(aftype == AF_INET6)
+       {
+               if(status == 1)
+                       rb_inet_pton_sock(result, &server_p->connect6);
+
+               server_p->dns_query_connect6 = 0;
+       }
+}
+
+/*
+ * conf_bind_dns_callback
  * inputs       - pointer to struct ConfItem
  *              - pointer to adns reply
  * output       - none
@@ -367,14 +371,24 @@ free_server_conf(struct server_conf *server_p)
  * if successful save hp in the conf item it was called with
  */
 static void
-conf_dns_callback(const char *result, int status, int aftype, void *data)
+conf_bind_dns_callback(const char *result, int status, int aftype, void *data)
 {
        struct server_conf *server_p = data;
 
-       if(status == 1)
-               rb_inet_pton_sock(result, (struct sockaddr *)&server_p->my_ipnum);
+       if(aftype == AF_INET)
+       {
+               if(status == 1)
+                       rb_inet_pton_sock(result, &server_p->bind4);
+
+               server_p->dns_query_bind4 = 0;
+       }
+       else if(aftype == AF_INET6)
+       {
+               if(status == 1)
+                       rb_inet_pton_sock(result, &server_p->bind6);
 
-       server_p->dns_query = 0;
+               server_p->dns_query_bind6 = 0;
+       }
 }
 
 void
@@ -398,11 +412,21 @@ add_server_conf(struct server_conf *server_p)
                server_p->class_name = rb_strdup("default");
        }
 
-       if(strpbrk(server_p->host, "*?"))
-               return;
+       if(server_p->connect_host && !strpbrk(server_p->connect_host, "*?"))
+       {
+               server_p->dns_query_connect4 =
+                       lookup_hostname(server_p->connect_host, AF_INET, conf_connect_dns_callback, server_p);
+               server_p->dns_query_connect6 =
+                       lookup_hostname(server_p->connect_host, AF_INET6, conf_connect_dns_callback, server_p);
+       }
 
-       server_p->dns_query =
-               lookup_hostname(server_p->host, GET_SS_FAMILY(&server_p->my_ipnum), conf_dns_callback, server_p);
+       if(server_p->bind_host)
+       {
+               server_p->dns_query_bind4 =
+                       lookup_hostname(server_p->bind_host, AF_INET, conf_bind_dns_callback, server_p);
+               server_p->dns_query_bind6 =
+                       lookup_hostname(server_p->bind_host, AF_INET6, conf_bind_dns_callback, server_p);
+       }
 }
 
 struct server_conf *
@@ -479,7 +503,7 @@ set_server_conf_autoconn(struct Client *source_p, const char *name, int newval)
                else
                        server_p->flags &= ~SERVER_AUTOCONN;
 
-               sendto_realops_snomask(SNO_GENERAL, L_ALL,
+               sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
                                "%s has changed AUTOCONN for %s to %i",
                                get_oper_name(source_p), name, newval);
        }
@@ -497,7 +521,7 @@ disable_server_conf_autoconn(const char *name)
        {
                server_p->flags &= ~SERVER_AUTOCONN;
 
-               sendto_realops_snomask(SNO_GENERAL, L_ALL,
+               sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
                                "Disabling AUTOCONN for %s because of error",
                                name);
                ilog(L_SERVER, "Disabling AUTOCONN for %s because of error",
@@ -661,23 +685,55 @@ time_t
 valid_temp_time(const char *p)
 {
        time_t result = 0;
+       long current = 0;
 
-       while(*p)
-       {
-               if(IsDigit(*p))
-               {
-                       result *= 10;
-                       result += ((*p) & 0xF);
-                       p++;
-               }
-               else
+       while (*p) {
+               char *endp;
+               int mul;
+
+               errno = 0;
+               current = strtol(p, &endp, 10);
+
+               if (endp == p)
+                       return -1;
+               if (current < 0)
                        return -1;
-       }
 
-       if(result > (60 * 24 * 7 * 52))
-               result = (60 * 24 * 7 * 52);
+               switch (*endp) {
+               case '\0': /* No unit was given so send it back as minutes */
+               case 'm':
+                       mul = 60;
+                       break;
+               case 'h':
+                       mul = 3600;
+                       break;
+               case 'd':
+                       mul = 86400;
+                       break;
+               case 'w':
+                       mul = 604800;
+                       break;
+               default:
+                       return -1;
+               }
+
+               if (current > LONG_MAX / mul)
+                       return MAX_TEMP_TIME;
+
+               current *= mul;
+
+               if (current > MAX_TEMP_TIME - result)
+                       return MAX_TEMP_TIME;
+
+               result += current;
+
+               if (*endp == '\0')
+                       break;
+
+               p = endp + 1;
+       }
 
-       return(result * 60);
+       return MIN(result, MAX_TEMP_TIME);
 }
 
 /* Propagated bans are expired elsewhere. */
@@ -687,10 +743,9 @@ expire_temp_rxlines(void *unused)
        struct ConfItem *aconf;
        rb_dlink_node *ptr;
        rb_dlink_node *next_ptr;
-       int i;
-       struct irc_radixtree_iteration_state state;
+       rb_radixtree_iteration_state state;
 
-       IRC_RADIXTREE_FOREACH(aconf, &state, resv_tree)
+       RB_RADIXTREE_FOREACH(aconf, &state, resv_tree)
        {
                if(aconf->lifetime != 0)
                        continue;
@@ -701,7 +756,7 @@ expire_temp_rxlines(void *unused)
                                                "Temporary RESV for [%s] expired",
                                                aconf->host);
 
-                       irc_radixtree_delete(resv_tree, aconf->host);
+                       rb_radixtree_delete(resv_tree, aconf->host);
                        free_conf(aconf);
                }
        }
@@ -752,7 +807,7 @@ add_nd_entry(const char *name)
 {
        struct nd_entry *nd;
 
-       if(irc_dictionary_find(nd_dict, name) != NULL)
+       if(rb_dictionary_find(nd_dict, name) != NULL)
                return;
 
        nd = rb_bh_alloc(nd_heap);
@@ -763,13 +818,13 @@ add_nd_entry(const char *name)
        /* this list is ordered */
        rb_dlinkAddTail(nd, &nd->lnode, &nd_list);
 
-       irc_dictionary_add(nd_dict, nd->name, nd);
+       rb_dictionary_add(nd_dict, nd->name, nd);
 }
 
 void
 free_nd_entry(struct nd_entry *nd)
 {
-       irc_dictionary_delete(nd_dict, nd->name);
+       rb_dictionary_delete(nd_dict, nd->name);
 
        rb_dlinkDelete(&nd->lnode, &nd_list);
        rb_bh_free(nd_heap, nd);