]> jfr.im git - solanum.git/blobdiff - authd/dns.c
build_rdns: minor cleanup
[solanum.git] / authd / dns.c
index 45db36a28a707c77fe69cf3fb0607a5262aa93ad..b251dd636a18df0ed08ad321556378632a84a08c 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "authd.h"
 #include "dns.h"
+#include "notice.h"
 #include "res.h"
 
 static void handle_lookup_ip_reply(void *data, struct DNSReply *reply);
@@ -118,11 +119,14 @@ static void
 handle_lookup_ip_reply(void *data, struct DNSReply *reply)
 {
        struct dns_query *query = data;
-       char ip[64] = "*";
+       char ip[HOSTIPLEN] = "*";
 
        if(query == NULL)
+       {
                /* Shouldn't happen */
-               exit(2);
+               warn_opers(L_CRIT, "DNS: handle_lookup_ip_reply: query == NULL!");
+               exit(EX_DNS_ERROR);
+       }
 
        if(reply == NULL)
                goto end;
@@ -147,7 +151,9 @@ handle_lookup_ip_reply(void *data, struct DNSReply *reply)
                break;
 #endif
        default:
-               exit(3);
+               warn_opers(L_CRIT, "DNS: handle_lookup_ip_reply: unknown query type %d",
+                               query->type);
+               exit(EX_DNS_ERROR);
        }
 
 end:
@@ -165,8 +171,11 @@ handle_lookup_hostname_reply(void *data, struct DNSReply *reply)
        char *hostname = NULL;
 
        if(query == NULL)
+       {
                /* Shouldn't happen */
-               exit(4);
+               warn_opers(L_CRIT, "DNS: handle_lookup_hostname_reply: query == NULL!");
+               exit(EX_DNS_ERROR);
+       }
 
        if(reply == NULL)
                goto end;
@@ -192,8 +201,12 @@ handle_lookup_hostname_reply(void *data, struct DNSReply *reply)
        }
 #endif
        else
+       {
                /* Shouldn't happen */
-               exit(5);
+               warn_opers(L_CRIT, "DNS: handle_lookup_hostname_reply: unknown query type %d",
+                               query->type);
+               exit(EX_DNS_ERROR);
+       }
 end:
        if(query->callback)
                query->callback(hostname, hostname != NULL, query->type, query->data);
@@ -207,7 +220,10 @@ submit_dns_answer(const char *reply, bool status, query_type type, void *data)
        char *id = data;
 
        if(!id || type == QUERY_INVALID)
-               exit(6);
+       {
+               warn_opers(L_CRIT, "DNS: submit_dns_answer gave us a bad query");
+               exit(EX_DNS_ERROR);
+       }
 
        if(reply == NULL || status == false)
        {
@@ -221,7 +237,7 @@ submit_dns_answer(const char *reply, bool status, query_type type, void *data)
 }
 
 void
-resolve_dns(int parc, char *parv[])
+handle_resolve_dns(int parc, char *parv[])
 {
        char *id = rb_strdup(parv[1]);
        char qtype = *parv[2];
@@ -246,44 +262,49 @@ resolve_dns(int parc, char *parv[])
                        submit_dns_answer(NULL, false, qtype, NULL);
                break;
        default:
-               exit(7);
+               warn_opers(L_CRIT, "DNS: handle_resolve_dns got an unknown query: %c", qtype);
+               exit(EX_DNS_ERROR);
        }
 }
 
 void
-enumerate_nameservers(const char *rid, const char letter)
+enumerate_nameservers(uint32_t rid, const char letter)
 {
        char buf[(HOSTIPLEN + 1) * IRCD_MAXNS];
-       char *c = buf;
-       int i;
+       size_t s = 0;
 
        if (!irc_nscount)
        {
                /* Shouldn't happen */
-               rb_helper_write(authd_helper, "X %s %c NONAMESERVERS", rid, letter);
-               return;
+               warn_opers(L_CRIT, "DNS: no name servers!");
+               stats_error(rid, letter, "NONAMESERVERS");
+               exit(EX_DNS_ERROR);
        }
 
-       for(i = 0; i < irc_nscount; i++)
+       for(int i = 0; i < irc_nscount; i++)
        {
                char addr[HOSTIPLEN];
+               size_t addrlen;
 
                rb_inet_ntop_sock((struct sockaddr *)&irc_nsaddr_list[i], addr, sizeof(addr));
 
                if (!addr[0])
                {
                        /* Shouldn't happen */
-                       rb_helper_write(authd_helper, "X %s %c INVALIDNAMESERVER", rid, letter);
-                       return;
+                       warn_opers(L_CRIT, "DNS: bad nameserver!");
+                       stats_error(rid, letter, "INVALIDNAMESERVER");
+                       exit(EX_DNS_ERROR);
                }
 
-               (void)snprintf(c, HOSTIPLEN + 1, "%s ", addr);
-               c += strlen(addr) + 1;
+               addrlen = strlen(addr) + 1;
+               (void)snprintf(&buf[s], sizeof(buf) - s, "%s ", addr);
+               s += addrlen;
        }
 
-       *(--c) = '\0';
+       if(s > 0)
+               buf[--s] = '\0';
 
-       rb_helper_write(authd_helper, "Y %s %c %s", rid, letter, buf);
+       stats_result(rid, letter, "%s", buf);
 }
 
 void