X-Git-Url: https://jfr.im/git/solanum.git/blobdiff_plain/02e141f7a3c7cfff57cccd5f721fb9352b78531d..ea41b24fd4807e3565bf5f8f293e2efc4c20b62d:/authd/dns.c diff --git a/authd/dns.c b/authd/dns.c index 487979fe..909c42a9 100644 --- a/authd/dns.c +++ b/authd/dns.c @@ -43,13 +43,11 @@ lookup_ip(const char *host, int aftype, DNSCB callback, void *data) query->type = QUERY_A; g_type = T_A; } -#ifdef RB_IPV6 else if(aftype == AF_INET6) { query->type = QUERY_AAAA; g_type = T_AAAA; } -#endif else { rb_free(query); @@ -75,7 +73,7 @@ lookup_hostname(const char *ip, DNSCB callback, void *data) struct dns_query *query = rb_malloc(sizeof(struct dns_query)); int aftype; - if(!rb_inet_pton_sock(ip, (struct sockaddr *)&query->addr)) + if(!rb_inet_pton_sock(ip, &query->addr)) { rb_free(query); return NULL; @@ -85,10 +83,8 @@ lookup_hostname(const char *ip, DNSCB callback, void *data) if(aftype == AF_INET) query->type = QUERY_PTR_A; -#ifdef RB_IPV6 else if(aftype == AF_INET6) query->type = QUERY_PTR_AAAA; -#endif else { rb_free(query); @@ -119,11 +115,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; @@ -134,7 +133,6 @@ handle_lookup_ip_reply(void *data, struct DNSReply *reply) if(GET_SS_FAMILY(&reply->addr) == AF_INET) rb_inet_ntop_sock((struct sockaddr *)&reply->addr, ip, sizeof(ip)); break; -#ifdef RB_IPV6 case QUERY_AAAA: if(GET_SS_FAMILY(&reply->addr) == AF_INET6) { @@ -146,9 +144,10 @@ 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: @@ -166,8 +165,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; @@ -181,7 +183,6 @@ handle_lookup_hostname_reply(void *data, struct DNSReply *reply) if(ip->sin_addr.s_addr == ip_fwd->sin_addr.s_addr) hostname = reply->h_name; } -#ifdef RB_IPV6 else if(query->type == QUERY_PTR_AAAA) { struct sockaddr_in6 *ip, *ip_fwd; @@ -191,10 +192,13 @@ handle_lookup_hostname_reply(void *data, struct DNSReply *reply) if(memcmp(&ip->sin6_addr, &ip_fwd->sin6_addr, sizeof(struct in6_addr)) == 0) hostname = reply->h_name; } -#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); @@ -208,7 +212,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) { @@ -231,39 +238,35 @@ handle_resolve_dns(int parc, char *parv[]) switch(qtype) { -#ifdef RB_IPV6 case '6': aftype = AF_INET6; -#endif case '4': if(!lookup_ip(record, aftype, submit_dns_answer, id)) submit_dns_answer(NULL, false, qtype, NULL); break; -#ifdef RB_IPV6 case 'S': -#endif case 'R': if(!lookup_hostname(record, submit_dns_answer, id)) 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; size_t s = 0; - uint32_t i_rid = (uint32_t)strtol(rid, NULL, 16); if (!irc_nscount) { /* Shouldn't happen */ - stats_error(i_rid, letter, "NONAMESERVERS"); - return; + warn_opers(L_CRIT, "DNS: no name servers!"); + stats_error(rid, letter, "NONAMESERVERS"); + exit(EX_DNS_ERROR); } for(int i = 0; i < irc_nscount; i++) @@ -276,19 +279,20 @@ enumerate_nameservers(const char *rid, const char letter) if (!addr[0]) { /* Shouldn't happen */ - stats_error(i_rid, letter, "INVALIDNAMESERVER"); - return; + warn_opers(L_CRIT, "DNS: bad nameserver!"); + stats_error(rid, letter, "INVALIDNAMESERVER"); + exit(EX_DNS_ERROR); } addrlen = strlen(addr) + 1; - (void)snprintf(c, sizeof(buf) - s, "%s ", addr); - c += addrlen; + (void)snprintf(&buf[s], sizeof(buf) - s, "%s ", addr); s += addrlen; } - *(--c) = '\0'; + if(s > 0) + buf[--s] = '\0'; - stats_result(i_rid, letter, "%s", buf); + stats_result(rid, letter, "%s", buf); } void