Don't append a domain to names without dot from reverse lookup.

Some code to append "domain" from /etc/resolv.conf to unqualified names (for
server connections) erroneously applied to names from reverse DNS lookups as
well.

The effect was that "domain" from /etc/resolv.conf was appended to
"localhost", even though the DNS server intended "localhost" to be a fully
qualified name.
This commit is contained in:
Jilles Tjoelker 2015-01-16 23:23:56 +01:00
parent 3c80b42532
commit 3881a3ce5d

View file

@ -88,6 +88,8 @@ static int ns_failure_count[IRCD_MAXNS]; /* timeouts and invalid/failed replies
static void rem_request(struct reslist *request); static void rem_request(struct reslist *request);
static struct reslist *make_request(struct DNSQuery *query); static struct reslist *make_request(struct DNSQuery *query);
static void gethost_byname_type_fqdn(const char *name, struct DNSQuery *query,
int type);
static void do_query_name(struct DNSQuery *query, const char *name, struct reslist *request, int); static void do_query_name(struct DNSQuery *query, const char *name, struct reslist *request, int);
static void do_query_number(struct DNSQuery *query, const struct rb_sockaddr_storage *, static void do_query_number(struct DNSQuery *query, const struct rb_sockaddr_storage *,
struct reslist *request); struct reslist *request);
@ -435,10 +437,23 @@ static struct reslist *find_id(int id)
} }
/* /*
* gethost_byname_type - get host address from name * gethost_byname_type - get host address from name, adding domain if needed
*
*/ */
void gethost_byname_type(const char *name, struct DNSQuery *query, int type) void gethost_byname_type(const char *name, struct DNSQuery *query, int type)
{
char fqdn[IRCD_RES_HOSTLEN + 1];
assert(name != 0);
rb_strlcpy(fqdn, name, sizeof fqdn);
add_local_domain(fqdn, IRCD_RES_HOSTLEN);
gethost_byname_type_fqdn(fqdn, query, type);
}
/*
* gethost_byname_type_fqdn - get host address from fqdn
*/
static void gethost_byname_type_fqdn(const char *name, struct DNSQuery *query,
int type)
{ {
assert(name != 0); assert(name != 0);
do_query_name(query, name, NULL, type); do_query_name(query, name, NULL, type);
@ -458,19 +473,13 @@ 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[IRCD_RES_HOSTLEN + 1];
rb_strlcpy(host_name, name, IRCD_RES_HOSTLEN + 1);
add_local_domain(host_name, IRCD_RES_HOSTLEN);
if (request == NULL) if (request == NULL)
{ {
request = make_request(query); request = make_request(query);
request->name = (char *)rb_malloc(strlen(host_name) + 1); request->name = rb_strdup(name);
strcpy(request->name, host_name);
} }
rb_strlcpy(request->queryname, host_name, sizeof(request->queryname)); rb_strlcpy(request->queryname, name, sizeof(request->queryname));
request->type = type; request->type = type;
query_name(request); query_name(request);
} }
@ -866,10 +875,10 @@ static int res_read_single_reply(rb_fde_t *F, void *data)
*/ */
#ifdef RB_IPV6 #ifdef RB_IPV6
if (request->addr.ss_family == AF_INET6) if (request->addr.ss_family == AF_INET6)
gethost_byname_type(request->name, request->query, T_AAAA); gethost_byname_type_fqdn(request->name, request->query, T_AAAA);
else else
#endif #endif
gethost_byname_type(request->name, request->query, T_A); gethost_byname_type_fqdn(request->name, request->query, T_A);
rem_request(request); rem_request(request);
} }
else else