Skip to content
Snippets Groups Projects
Commit 35d5253f authored by Daniel Salzman's avatar Daniel Salzman
Browse files

Add relative dname support

If the input domain name doesn't have a trailing dot, this dot is appended.

refs #2137
parent 8ece93a1
No related branches found
No related tags found
No related merge requests found
......@@ -150,6 +150,27 @@ char* get_reverse_name(const char *name)
}
}
char* get_fqd_name(const char *name)
{
char *fqd_name = NULL;
if (name == NULL) {
return NULL;
}
// If name is FQD, make copy.
if (name[strlen(name) - 1] == '.') {
fqd_name = strdup(name);
// Else append trailing dot.
} else {
fqd_name = malloc(strlen(name) + 2);
strcpy(fqd_name, name);
strcat(fqd_name, ".");
}
return fqd_name;
}
void params_flag_tcp(params_t *params)
{
params->protocol = PROTO_TCP;
......@@ -174,7 +195,7 @@ int params_parse_interval(const char *value, int32_t *dst)
} else if (num < 1) {
num = 1;
WARN("interval is too short, using %ld seconds\n", num);
/* Reduce maximal value. Poll takes signed int in milliseconds.. */
/* Reduce maximal value. Poll takes signed int in milliseconds. */
} else if (num > INT32_MAX) {
num = INT32_MAX / 1000;
WARN("interval is too long, using %ld seconds\n", num);
......
......@@ -133,6 +133,8 @@ int parse_type(const char *rtype, int32_t *type_num, int64_t *ixfr_serial);
char* get_reverse_name(const char *name);
char* get_fqd_name(const char *name);
void params_flag_tcp(params_t *params);
void params_flag_verbose(params_t *params);
......
......@@ -123,14 +123,19 @@ static void host_params_flag_nowait(params_t *params)
static int host_params_parse_name(params_t *params, const char *name)
{
char *reverse = get_reverse_name(name);
char *fqd_name = NULL;
query_t *query;
// If name is not FQDN, append trailing dot.
fqd_name = get_fqd_name(name);
// RR type is known.
if (params->type_num >= 0) {
if (params->type_num == KNOT_RRTYPE_PTR) {
// Check for correct address.
if (reverse == NULL) {
ERR("invalid IPv4 or IPv6 address");
ERR("invalid IPv4 or IPv6 address\n");
free(fqd_name);
return KNOT_EINVAL;
}
......@@ -138,14 +143,16 @@ static int host_params_parse_name(params_t *params, const char *name)
query = query_create(reverse, params->type_num);
if (query == NULL) {
free(reverse);
free(fqd_name);
return KNOT_ENOMEM;
}
add_tail(&params->queries, (node *)query);
} else {
// Add query for name and specified type.
query = query_create(name, params->type_num);
query = query_create(fqd_name, params->type_num);
if (query == NULL) {
free(reverse);
free(fqd_name);
return KNOT_ENOMEM;
}
// Set SOA serial for IXFR query.
......@@ -158,22 +165,28 @@ static int host_params_parse_name(params_t *params, const char *name)
} else {
if (reverse == NULL) {
// Add query for name and type A.
query = query_create(name, KNOT_RRTYPE_A);
query = query_create(fqd_name, KNOT_RRTYPE_A);
if (query == NULL) {
free(fqd_name);
free(fqd_name);
return KNOT_ENOMEM;
}
add_tail(&params->queries, (node *)query);
// Add query for name and type AAAA.
query = query_create(name, KNOT_RRTYPE_AAAA);
query = query_create(fqd_name, KNOT_RRTYPE_AAAA);
if (query == NULL) {
free(fqd_name);
free(fqd_name);
return KNOT_ENOMEM;
}
add_tail(&params->queries, (node *)query);
// Add query for name and type MX.
query = query_create(name, KNOT_RRTYPE_MX);
query = query_create(fqd_name, KNOT_RRTYPE_MX);
if (query == NULL) {
free(fqd_name);
free(fqd_name);
return KNOT_ENOMEM;
}
add_tail(&params->queries, (node *)query);
......@@ -182,14 +195,15 @@ static int host_params_parse_name(params_t *params, const char *name)
query = query_create(reverse, KNOT_RRTYPE_PTR);
if (query == NULL) {
free(reverse);
free(fqd_name);
return KNOT_ENOMEM;
}
add_tail(&params->queries, (node *)query);
}
}
// Dealloc possible reverse name.
free(reverse);
free(fqd_name);
return KNOT_EOK;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment