]> jfr.im git - irc/rqf/shadowircd.git/blobdiff - src/res.c
Fix limits on simple modes.
[irc/rqf/shadowircd.git] / src / res.c
index 2a3677642ea1c091f97bbc15bdb1ea1f155085eb..81e23c0913e81cecd3402ced5f503c0ade1bbdbe 100644 (file)
--- a/src/res.c
+++ b/src/res.c
@@ -31,8 +31,7 @@
 #include "ircd.h"
 #include "res.h"
 #include "reslib.h"
-#include "irc_string.h"
-#include "sprintf_irc.h"
+#include "match.h"
 #include "numeric.h"
 #include "client.h" /* SNO_* */
 
@@ -57,26 +56,16 @@ static PF res_readreply;
 #define RDLENGTH_SIZE     (size_t)2
 #define ANSWER_FIXED_SIZE (TYPE_SIZE + CLASS_SIZE + TTL_SIZE + RDLENGTH_SIZE)
 
-typedef enum
-{
-       REQ_IDLE,               /* We're doing not much at all */
-       REQ_PTR,                /* Looking up a PTR */
-       REQ_A,                  /* Looking up an A or AAAA */
-       REQ_CNAME               /* We got a CNAME in response, we better get a real answer next */
-} request_state;
-
 struct reslist
 {
        rb_dlink_node node;
        int id;
        int sent;               /* number of requests sent */
-       request_state state;    /* State the resolver machine is in */
        time_t ttl;
        char type;
        char queryname[128];    /* name currently being queried */
        char retries;           /* retry counter */
        char sends;             /* number of sends (>1 means resent) */
-       char resend;            /* send flag. 0 == dont resend */
        time_t sentat;
        time_t timeout;
        struct rb_sockaddr_storage addr;
@@ -100,11 +89,6 @@ static int proc_answer(struct reslist *request, HEADER * header, char *, char *)
 static struct reslist *find_id(int id);
 static struct DNSReply *make_dnsreply(struct reslist *request);
 
-extern struct rb_sockaddr_storage irc_nsaddr_list[IRCD_MAXNS];
-extern int irc_nscount;
-extern char irc_domain[HOSTLEN + 1];
-
-
 /*
  * int
  * res_ourserver(inp)
@@ -118,28 +102,28 @@ extern char irc_domain[HOSTLEN + 1];
  */
 static int res_ourserver(const struct rb_sockaddr_storage *inp)
 {
-#ifdef IPV6
-       struct sockaddr_in6 *v6;
-       struct sockaddr_in6 *v6in = (struct sockaddr_in6 *)inp;
+#ifdef RB_IPV6
+       const struct sockaddr_in6 *v6;
+       const struct sockaddr_in6 *v6in = (const struct sockaddr_in6 *)inp;
 #endif
-       struct sockaddr_in *v4;
-       struct sockaddr_in *v4in = (struct sockaddr_in *)inp;
+       const struct sockaddr_in *v4;
+       const struct sockaddr_in *v4in = (const struct sockaddr_in *)inp;
        int ns;
 
        for (ns = 0; ns < irc_nscount; ns++)
        {
                const struct rb_sockaddr_storage *srv = &irc_nsaddr_list[ns];
-#ifdef IPV6
-               v6 = (struct sockaddr_in6 *)srv;
+#ifdef RB_IPV6
+               v6 = (const struct sockaddr_in6 *)srv;
 #endif
-               v4 = (struct sockaddr_in *)srv;
+               v4 = (const struct sockaddr_in *)srv;
 
                /* could probably just memcmp(srv, inp, srv.ss_len) here
                 * but we'll air on the side of caution - stu
                 */
                switch (srv->ss_family)
                {
-#ifdef IPV6
+#ifdef RB_IPV6
                  case AF_INET6:
                          if (srv->ss_family == inp->ss_family)
                                  if (v6->sin6_port == v6in->sin6_port)
@@ -225,7 +209,7 @@ static void start_resolver(void)
 {
        irc_res_init();
 
-       if (res_fd <= 0)        /* there isn't any such thing as fd 0, that's just a myth. */
+       if (res_fd == NULL)
        {
                if ((res_fd = rb_socket(irc_nsaddr_list[0].ss_family, SOCK_DGRAM, 0,
                               "UDP resolver socket")) == NULL)
@@ -302,10 +286,8 @@ static struct reslist *make_request(struct DNSQuery *query)
 
        request->sentat = rb_current_time();
        request->retries = 3;
-       request->resend = 1;
        request->timeout = 4;   /* start at 4 and exponential inc. */
        request->query = query;
-       request->state = REQ_IDLE;
 
        rb_dlinkAdd(request, &request->node, &request_list);
 
@@ -407,7 +389,7 @@ static void do_query_name(struct DNSQuery *query, const char *name, struct resli
 {
        char host_name[HOSTLEN + 1];
 
-       strlcpy(host_name, name, HOSTLEN + 1);
+       rb_strlcpy(host_name, name, HOSTLEN + 1);
        add_local_domain(host_name, HOSTLEN);
 
        if (request == NULL)
@@ -415,10 +397,9 @@ static void do_query_name(struct DNSQuery *query, const char *name, struct resli
                request = make_request(query);
                request->name = (char *)rb_malloc(strlen(host_name) + 1);
                strcpy(request->name, host_name);
-               request->state = REQ_A;
        }
 
-       strlcpy(request->queryname, host_name, sizeof(request->queryname));
+       rb_strlcpy(request->queryname, host_name, sizeof(request->queryname));
        request->type = type;
        query_name(request);
 }
@@ -440,16 +421,16 @@ static void do_query_number(struct DNSQuery *query, const struct rb_sockaddr_sto
 
        if (addr->ss_family == AF_INET)
        {
-               struct sockaddr_in *v4 = (struct sockaddr_in *)addr;
+               const struct sockaddr_in *v4 = (const struct sockaddr_in *)addr;
                cp = (const unsigned char *)&v4->sin_addr.s_addr;
 
                rb_sprintf(request->queryname, "%u.%u.%u.%u.in-addr.arpa", (unsigned int)(cp[3]),
                           (unsigned int)(cp[2]), (unsigned int)(cp[1]), (unsigned int)(cp[0]));
        }
-#ifdef IPV6
+#ifdef RB_IPV6
        else if (addr->ss_family == AF_INET6)
        {
-               struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr;
+               const struct sockaddr_in6 *v6 = (const struct sockaddr_in6 *)addr;
                cp = (const unsigned char *)&v6->sin6_addr.s6_addr;
 
                (void)sprintf(request->queryname, "%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x.%x."
@@ -523,16 +504,13 @@ static void query_name(struct reslist *request)
 
 static void resend_query(struct reslist *request)
 {
-       if (request->resend == 0)
-               return;
-
        switch (request->type)
        {
          case T_PTR:
                  do_query_number(NULL, &request->addr, request);
                  break;
          case T_A:
-#ifdef IPV6
+#ifdef RB_IPV6
          case T_AAAA:
 #endif
                  do_query_name(NULL, request->name, request, request->type);
@@ -577,7 +555,7 @@ static int proc_answer(struct reslist *request, HEADER * header, char *buf, char
        int n;                  /* temp count */
        int rd_length;
        struct sockaddr_in *v4; /* conversion */
-#ifdef IPV6
+#ifdef RB_IPV6
        struct sockaddr_in6 *v6;
 #endif
        current = (unsigned char *)buf + sizeof(HEADER);
@@ -658,7 +636,7 @@ static int proc_answer(struct reslist *request, HEADER * header, char *buf, char
                          memcpy(&v4->sin_addr, current, sizeof(struct in_addr));
                          return (1);
                          break;
-#ifdef IPV6
+#ifdef RB_IPV6
                  case T_AAAA:
                          if (request->type != T_AAAA)
                                  return (0);
@@ -681,26 +659,12 @@ static int proc_answer(struct reslist *request, HEADER * header, char *buf, char
                          else if (n == 0)
                                  return (0);   /* no more answers left */
 
-                         strlcpy(request->name, hostbuf, HOSTLEN + 1);
+                         rb_strlcpy(request->name, hostbuf, HOSTLEN + 1);
 
                          return (1);
                          break;
-                 case T_CNAME: /* first check we already havent started looking 
-                                          into a cname */
-                         if (request->type != T_PTR)
-                                 return (0);
-
-                         if (request->state == REQ_CNAME)
-                         {
-                                 n = irc_dn_expand((unsigned char *)buf, (unsigned char *)eob,
-                                                   current, hostbuf, sizeof(hostbuf));
-
-                                 if (n < 0)
-                                         return (0);
-                                 return (1);
-                         }
-
-                         request->state = REQ_CNAME;
+                 case T_CNAME:
+                         /* real answer will follow */
                          current += rd_length;
                          break;
 
@@ -818,7 +782,7 @@ static void res_readreply(rb_fde_t *F, void *data)
                         * ip#. 
                         *
                         */
-#ifdef IPV6
+#ifdef RB_IPV6
                        if (request->addr.ss_family == AF_INET6)
                                gethost_byname_type(request->name, request->query, T_AAAA);
                        else
@@ -864,9 +828,9 @@ void report_dns_servers(struct Client *source_p)
 
        for (i = 0; i < irc_nscount; i++)
        {
-               if (!inetntop_sock((struct sockaddr *)&(irc_nsaddr_list[i]),
+               if (!rb_inet_ntop_sock((struct sockaddr *)&(irc_nsaddr_list[i]),
                                ipaddr, sizeof ipaddr))
-                       strlcpy(ipaddr, "?", sizeof ipaddr);
+                       rb_strlcpy(ipaddr, "?", sizeof ipaddr);
                sendto_one_numeric(source_p, RPL_STATSDEBUG,
                                "A %s", ipaddr);
        }