Skip to content

Commit

Permalink
Allow multiple hostnames in dns.hosts
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Nov 22, 2023
1 parent 2fa8566 commit 98b5a92
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/config/validator.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ bool validate_dns_hosts(union conf_value *val, char err[VALIDATOR_ERRBUF_LEN])
char *str = strdup(item->valuestring);
char *tmp = str;
char *ip = strsep(&tmp, " ");
char *host = strsep(&tmp, " ");
char *tail = strsep(&tmp, " ");

if(!ip || !host || !*ip || !*host || tail)
if(!ip || !*ip)
{
snprintf(err, VALIDATOR_ERRBUF_LEN, "%d%s element is not in the form \"IP HOSTNAME\" (\"%s\")",
snprintf(err, VALIDATOR_ERRBUF_LEN, "%d%s element does not have an IP address (\"%s\")",
i, get_ordinal_suffix(i), item->valuestring);
free(str);
return false;
Expand All @@ -62,11 +60,28 @@ bool validate_dns_hosts(union conf_value *val, char err[VALIDATOR_ERRBUF_LEN])
return false;
}

// Check if hostname is valid
if(strlen(host) < 1 || strlen(host) > 128)
// Check if all hostnames are valid
// The HOSTS format allows any number of space-separated
// hostnames to come after the IP address
unsigned int hosts = 0;
char *host = NULL;
while((host = strsep(&tmp, " ")) != NULL)
{
snprintf(err, VALIDATOR_ERRBUF_LEN, "%d%s element is not a valid hostname (\"%s\")",
i, get_ordinal_suffix(i), host);
if(!valid_domain(host, strlen(host), false))
{
snprintf(err, VALIDATOR_ERRBUF_LEN, "%d%s element has an invalid hostname (\"%s\")",
i, get_ordinal_suffix(i), host);
free(str);
return false;
}
hosts++;
}

// Check if there is at least one hostname in this record
if(hosts < 1)
{
snprintf(err, VALIDATOR_ERRBUF_LEN, "%d%s element does not have at least one hostname (\"%s\")",
i, get_ordinal_suffix(i), item->valuestring);
free(str);
return false;
}
Expand Down

0 comments on commit 98b5a92

Please sign in to comment.