diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2022-06-24 12:17:30 +1000 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2022-07-06 08:10:55 +0200 |
commit | c589917e7152dd2ed6eb4e63bfdd5c98ee94e00b (patch) | |
tree | 5a68e696264c73b792c5b824514e38e3ad2ae2c3 | |
parent | dab2c6ee1f308af001dd4f57a13ec16e765f930b (diff) | |
download | passt-c589917e7152dd2ed6eb4e63bfdd5c98ee94e00b.tar passt-c589917e7152dd2ed6eb4e63bfdd5c98ee94e00b.tar.gz passt-c589917e7152dd2ed6eb4e63bfdd5c98ee94e00b.tar.bz2 passt-c589917e7152dd2ed6eb4e63bfdd5c98ee94e00b.tar.lz passt-c589917e7152dd2ed6eb4e63bfdd5c98ee94e00b.tar.xz passt-c589917e7152dd2ed6eb4e63bfdd5c98ee94e00b.tar.zst passt-c589917e7152dd2ed6eb4e63bfdd5c98ee94e00b.zip |
Parse resolv.conf with new lineread implementation
Switch the resolv.conf parsing in conf.c to use the new lineread
implementation. This means that it can now handle a resolv.conf file which
contains blank lines.
There are quite a few other fragilities with the resolv.conf parsing, but
that's out of scope for this patch.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
-rw-r--r-- | conf.c | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -38,6 +38,7 @@ #include "udp.h" #include "tcp.h" #include "pasta.h" +#include "lineread.h" /** * get_bound_ports() - Get maps of ports with bound sockets @@ -320,7 +321,9 @@ static void get_dns(struct ctx *c) struct in6_addr *dns6 = &c->dns6[0]; struct fqdn *s = c->dns_search; uint32_t *dns4 = &c->dns4[0]; - char buf[BUFSIZ], *p, *end; + struct lineread resolvconf; + int line_len; + char *line, *p, *end; dns4_set = !c->v4 || !!*dns4; dns6_set = !c->v6 || !IN6_IS_ADDR_UNSPECIFIED(dns6); @@ -333,13 +336,14 @@ static void get_dns(struct ctx *c) if ((fd = open("/etc/resolv.conf", O_RDONLY | O_CLOEXEC)) < 0) goto out; - for (*buf = 0; line_read(buf, BUFSIZ, fd); *buf = 0) { - if (!dns_set && strstr(buf, "nameserver ") == buf) { - p = strrchr(buf, ' '); + lineread_init(&resolvconf, fd); + while ((line_len = lineread_get(&resolvconf, &line)) > 0) { + if (!dns_set && strstr(line, "nameserver ") == line) { + p = strrchr(line, ' '); if (!p) continue; - end = strpbrk(buf, "%\n"); + end = strpbrk(line, "%\n"); if (end) *end = 0; @@ -356,13 +360,13 @@ static void get_dns(struct ctx *c) dns6++; memset(dns6, 0, sizeof(*dns6)); } - } else if (!dnss_set && strstr(buf, "search ") == buf && + } else if (!dnss_set && strstr(line, "search ") == line && s == c->dns_search) { - end = strpbrk(buf, "\n"); + end = strpbrk(line, "\n"); if (end) *end = 0; - if (!strtok(buf, " \t")) + if (!strtok(line, " \t")) continue; while (s - c->dns_search < ARRAY_SIZE(c->dns_search) - 1 @@ -374,6 +378,8 @@ static void get_dns(struct ctx *c) } } + if (line_len < 0) + warn("Error reading /etc/resolv.conf: %s", strerror(errno)); close(fd); out: |