Allow the resolver to process longer hostnames,

for the benefit of some DNSBLs like the "TorDNSEL service".
This commit is contained in:
Jilles Tjoelker 2008-11-15 16:13:39 +01:00
parent 863efb0e6b
commit 570ca08a4f
5 changed files with 20 additions and 15 deletions

View File

@ -29,7 +29,7 @@
struct Blacklist { struct Blacklist {
unsigned int status; /* If CONF_ILLEGAL, delete when no clients */ unsigned int status; /* If CONF_ILLEGAL, delete when no clients */
int refcount; int refcount;
char host[HOSTLEN]; char host[IRCD_RES_HOSTLEN + 1];
char reject_reason[IRCD_BUFSIZE]; char reject_reason[IRCD_BUFSIZE];
unsigned int hits; unsigned int hits;
time_t lastwarning; time_t lastwarning;

View File

@ -7,6 +7,11 @@
#ifndef _CHARYBDIS_RESLIB_H #ifndef _CHARYBDIS_RESLIB_H
#define _CHARYBDIS_RESLIB_H #define _CHARYBDIS_RESLIB_H
/* Longest hostname we're willing to work with.
* Due to DNSBLs this is more than HOSTLEN.
*/
#define IRCD_RES_HOSTLEN 255
/* Here we define some values lifted from nameser.h */ /* Here we define some values lifted from nameser.h */
#define NS_NOTIFY_OP 4 #define NS_NOTIFY_OP 4
#define NS_INT16SZ 2 #define NS_INT16SZ 2
@ -115,6 +120,6 @@ extern void irc_ns_put16(unsigned int src, unsigned char *dst);
extern void irc_ns_put32(unsigned long src, unsigned char *dst); extern void irc_ns_put32(unsigned long src, unsigned char *dst);
extern int irc_res_mkquery(const char *dname, int class, int type, unsigned char *buf, int buflen); extern int irc_res_mkquery(const char *dname, int class, int type, unsigned char *buf, int buflen);
extern char irc_domain[HOSTLEN + 1]; extern char irc_domain[IRCD_RES_HOSTLEN + 1];
#endif #endif

View File

@ -117,7 +117,7 @@ static void blacklist_dns_callback(void *vptr, struct DNSReply *reply)
static void initiate_blacklist_dnsquery(struct Blacklist *blptr, struct Client *client_p) static void initiate_blacklist_dnsquery(struct Blacklist *blptr, struct Client *client_p)
{ {
struct BlacklistClient *blcptr = rb_malloc(sizeof(struct BlacklistClient)); struct BlacklistClient *blcptr = rb_malloc(sizeof(struct BlacklistClient));
char buf[IRCD_BUFSIZE]; char buf[IRCD_RES_HOSTLEN + 1];
int ip[4]; int ip[4];
blcptr->blacklist = blptr; blcptr->blacklist = blptr;
@ -130,7 +130,7 @@ static void initiate_blacklist_dnsquery(struct Blacklist *blptr, struct Client *
sscanf(client_p->sockhost, "%d.%d.%d.%d", &ip[3], &ip[2], &ip[1], &ip[0]); sscanf(client_p->sockhost, "%d.%d.%d.%d", &ip[3], &ip[2], &ip[1], &ip[0]);
/* becomes 2.0.0.127.torbl.ahbl.org or whatever */ /* becomes 2.0.0.127.torbl.ahbl.org or whatever */
rb_snprintf(buf, IRCD_BUFSIZE, "%d.%d.%d.%d.%s", ip[0], ip[1], ip[2], ip[3], blptr->host); rb_snprintf(buf, sizeof buf, "%d.%d.%d.%d.%s", ip[0], ip[1], ip[2], ip[3], blptr->host);
gethost_byname_type(buf, &blcptr->dns_query, T_A); gethost_byname_type(buf, &blcptr->dns_query, T_A);
@ -154,7 +154,7 @@ struct Blacklist *new_blacklist(char *name, char *reject_reason)
} }
else else
blptr->status &= ~CONF_ILLEGAL; blptr->status &= ~CONF_ILLEGAL;
rb_strlcpy(blptr->host, name, HOSTLEN); rb_strlcpy(blptr->host, name, IRCD_RES_HOSTLEN + 1);
rb_strlcpy(blptr->reject_reason, reject_reason, IRCD_BUFSIZE); rb_strlcpy(blptr->reject_reason, reject_reason, IRCD_BUFSIZE);
blptr->lastwarning = 0; blptr->lastwarning = 0;

View File

@ -62,7 +62,7 @@ struct reslist
int id; int id;
time_t ttl; time_t ttl;
char type; char type;
char queryname[128]; /* name currently being queried */ char queryname[IRCD_RES_HOSTLEN + 1]; /* name currently being queried */
char retries; /* retry counter */ char retries; /* retry counter */
char sends; /* number of sends (>1 means resent) */ char sends; /* number of sends (>1 means resent) */
time_t sentat; time_t sentat;
@ -433,10 +433,10 @@ void gethost_byaddr(const struct rb_sockaddr_storage *addr, struct DNSQuery *que
static void do_query_name(struct DNSQuery *query, const char *name, struct reslist *request, static void do_query_name(struct DNSQuery *query, const char *name, struct reslist *request,
int type) int type)
{ {
char host_name[HOSTLEN + 1]; char host_name[IRCD_RES_HOSTLEN + 1];
rb_strlcpy(host_name, name, HOSTLEN + 1); rb_strlcpy(host_name, name, IRCD_RES_HOSTLEN + 1);
add_local_domain(host_name, HOSTLEN); add_local_domain(host_name, IRCD_RES_HOSTLEN);
if (request == NULL) if (request == NULL)
{ {
@ -462,7 +462,7 @@ static void do_query_number(struct DNSQuery *query, const struct rb_sockaddr_sto
{ {
request = make_request(query); request = make_request(query);
memcpy(&request->addr, addr, sizeof(struct rb_sockaddr_storage)); memcpy(&request->addr, addr, sizeof(struct rb_sockaddr_storage));
request->name = (char *)rb_malloc(HOSTLEN + 1); request->name = (char *)rb_malloc(IRCD_RES_HOSTLEN + 1);
} }
if (addr->ss_family == AF_INET) if (addr->ss_family == AF_INET)
@ -576,7 +576,7 @@ static void resend_query(struct reslist *request)
*/ */
static int check_question(struct reslist *request, HEADER * header, char *buf, char *eob) static int check_question(struct reslist *request, HEADER * header, char *buf, char *eob)
{ {
char hostbuf[128]; /* working buffer */ char hostbuf[IRCD_RES_HOSTLEN + 1]; /* working buffer */
unsigned char *current; /* current position in buf */ unsigned char *current; /* current position in buf */
int n; /* temp count */ int n; /* temp count */
@ -597,7 +597,7 @@ static int check_question(struct reslist *request, HEADER * header, char *buf, c
*/ */
static int proc_answer(struct reslist *request, HEADER * header, char *buf, char *eob) static int proc_answer(struct reslist *request, HEADER * header, char *buf, char *eob)
{ {
char hostbuf[HOSTLEN + 100]; /* working buffer */ char hostbuf[IRCD_RES_HOSTLEN + 100]; /* working buffer */
unsigned char *current; /* current position in buf */ unsigned char *current; /* current position in buf */
int query_class; /* answer class */ int query_class; /* answer class */
int type; /* answer type */ int type; /* answer type */
@ -642,7 +642,7 @@ static int proc_answer(struct reslist *request, HEADER * header, char *buf, char
return (0); return (0);
} }
hostbuf[HOSTLEN] = '\0'; hostbuf[IRCD_RES_HOSTLEN] = '\0';
/* With Address arithmetic you have to be very anal /* With Address arithmetic you have to be very anal
* this code was not working on alpha due to that * this code was not working on alpha due to that
@ -708,7 +708,7 @@ static int proc_answer(struct reslist *request, HEADER * header, char *buf, char
else if (n == 0) else if (n == 0)
return (0); /* no more answers left */ return (0); /* no more answers left */
rb_strlcpy(request->name, hostbuf, HOSTLEN + 1); rb_strlcpy(request->name, hostbuf, IRCD_RES_HOSTLEN + 1);
return (1); return (1);
break; break;

View File

@ -97,7 +97,7 @@
struct rb_sockaddr_storage irc_nsaddr_list[IRCD_MAXNS]; struct rb_sockaddr_storage irc_nsaddr_list[IRCD_MAXNS];
int irc_nscount = 0; int irc_nscount = 0;
char irc_domain[HOSTLEN + 1]; char irc_domain[IRCD_RES_HOSTLEN + 1];
static const char digitvalue[256] = { static const char digitvalue[256] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*16*/ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*16*/