From 85ed638be3aea9c8ab6806a1fde248b10c2fee14 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 13 Jul 2023 12:51:09 +0000 Subject: Bugfix the bigfuxes Signed-off-by: Laurent Bercot --- doc/s6-dnsip.html | 4 +++- doc/s6-dnsip4.html | 4 +++- doc/s6-dnsip6.html | 4 +++- doc/s6-dnsname.html | 4 +++- src/include/s6-dns/hosts.h | 6 +++--- src/libs6dns/s6dns_hosts_ip_string.c | 18 +++++++++--------- src/libs6dns/s6dns_hosts_name.c | 3 ++- src/utilities/s6-dns-hosts-compile.c | 2 ++ 8 files changed, 28 insertions(+), 17 deletions(-) diff --git a/doc/s6-dnsip.html b/doc/s6-dnsip.html index 58d538f..0ffecad 100644 --- a/doc/s6-dnsip.html +++ b/doc/s6-dnsip.html @@ -56,7 +56,9 @@ the default.
  • -h : use data from /etc/hosts, if available. If there's a compiled /etc/hosts.cdb file that is newer than /etc/hosts, it will be used instead. (See -s6-dns-hosts-compile for details.)
  • +s6-dns-hosts-compile for details.) +If the lookup in the hosts database returns at least one result, then +no DNS lookup is performed.
  • -r : random. By default, the program does not sort the result, but prints them in the order received from the DNS. With this option, it performs a random permutation on the results before printing diff --git a/doc/s6-dnsip4.html b/doc/s6-dnsip4.html index ad29c7d..cb0fa78 100644 --- a/doc/s6-dnsip4.html +++ b/doc/s6-dnsip4.html @@ -56,7 +56,9 @@ the default.
  • -h : use data from /etc/hosts, if available. If there's a compiled /etc/hosts.cdb file that is newer than /etc/hosts, it will be used instead. (See -s6-dns-hosts-compile for details.)
  • +s6-dns-hosts-compile for details.) +If the lookup in the hosts database returns at least one result, then +no DNS lookup is performed.
  • -r : random. By default, the program does not sort the result, but prints them in the order received from the DNS. With this option, it performs a random permutation on the results before printing diff --git a/doc/s6-dnsip6.html b/doc/s6-dnsip6.html index c8ec11d..3c6fb8d 100644 --- a/doc/s6-dnsip6.html +++ b/doc/s6-dnsip6.html @@ -56,7 +56,9 @@ the default.
  • -h : use data from /etc/hosts, if available. If there's a compiled /etc/hosts.cdb file that is newer than /etc/hosts, it will be used instead. (See -s6-dns-hosts-compile for details.)
  • +s6-dns-hosts-compile for details.) +If the lookup in the hosts database returns at least one result, then +no DNS lookup is performed.
  • -r : random. By default, the program does not sort the result, but prints them in the order received from the DNS. With this option, it performs a random permutation on the results before printing diff --git a/doc/s6-dnsname.html b/doc/s6-dnsname.html index 63e7e15..301b5fd 100644 --- a/doc/s6-dnsname.html +++ b/doc/s6-dnsname.html @@ -57,7 +57,9 @@ the default.
  • -h : use data from /etc/hosts, if available. If there's a compiled /etc/hosts.cdb file that is newer than /etc/hosts, it will be used instead. (See -s6-dns-hosts-compile for details.)
  • +s6-dns-hosts-compile for details.) +If the lookup in the hosts database returns at least one result, then +no DNS lookup is performed.
  • -r : random. By default, the program does not sort the result, but prints them in the order received from the DNS. With this option, it performs a random permutation on the results before printing diff --git a/src/include/s6-dns/hosts.h b/src/include/s6-dns/hosts.h index e76bfcb..f9ac48e 100644 --- a/src/include/s6-dns/hosts.h +++ b/src/include/s6-dns/hosts.h @@ -47,15 +47,15 @@ extern int s6dns_hosts_aaaaa_string_r (cdb const *, char const *, genalloc *, in #define s6dns_hosts_aaaaa_string(name, ga, isunq) s6dns_hosts_aaaaa_string_r(&s6dns_hosts_here, (name), ga, isunq) #define s6dns_hosts_a_noq_r(c, name, sa) s6dns_hosts_a_string_r(c, name, (sa), 0) -#define s6dns_hosts_aaaa_noq_r(c, name, sa) s6dns_hosts_aaaa_string_r(c, name, (sa), 1) +#define s6dns_hosts_aaaa_noq_r(c, name, sa) s6dns_hosts_aaaa_string_r(c, name, (sa), 0) #define s6dns_hosts_aaaaa_noq_r(c, name, ga) s6dns_hosts_aaaaa_string_r(c, name, (ga), 0) #define s6dns_hosts_a_noq(name, sa) s6dns_hosts_a_noq_r(&s6dns_hosts_here, (name), sa) #define s6dns_hosts_aaaa_noq(name, sa) s6dns_hosts_aaaa_noq_r(&s6dns_hosts_here, (name), sa) #define s6dns_hosts_aaaaa_noq(name, ga) s6dns_hosts_aaaaa_noq_r(&s6dns_hosts_here, (name), ga) -#define s6dns_hosts_a_unq_r(c, name, sa) s6dns_hosts_a_string_r(c, name, (sa), 2) -#define s6dns_hosts_aaaa_unq_r(c, name, sa) s6dns_hosts_aaaa_string_r(c, name, (sa), 3) +#define s6dns_hosts_a_unq_r(c, name, sa) s6dns_hosts_a_string_r(c, name, (sa), 1) +#define s6dns_hosts_aaaa_unq_r(c, name, sa) s6dns_hosts_aaaa_string_r(c, name, (sa), 1) #define s6dns_hosts_aaaaa_unq_r(c, name, ga) s6dns_hosts_aaaaa_string_r(c, name, (ga), 1) #define s6dns_hosts_a_unq(name, sa) s6dns_hosts_a_unq_r(&s6dns_hosts_here, (name), sa) diff --git a/src/libs6dns/s6dns_hosts_ip_string.c b/src/libs6dns/s6dns_hosts_ip_string.c index 430f7d3..8d67cb1 100644 --- a/src/libs6dns/s6dns_hosts_ip_string.c +++ b/src/libs6dns/s6dns_hosts_ip_string.c @@ -1,7 +1,6 @@ /* ISC license. */ #include -#include #include #include @@ -14,21 +13,22 @@ extern int s6dns_hosts_ip_string_r (cdb const *c, char const *name, stralloc *sa, unsigned int flags) { s6dns_domain_t d ; - int r ; cdb_data data ; if (!c->map) return 0 ; - if (!s6dns_domain_fromstring(&d, name, strlen(name)) - || !s6dns_domain_noqualify(&d)) return -1 ; - + if (!s6dns_domain_fromstring(&d, name, strlen(name))) return -1 ; + if (!(flags & 2) && !s6dns_domain_noqualify(&d)) return -1 ; { - char tmp[3 + d.len] ; + int r ; + char tmp[4 + d.len] ; tmp[0] = flags & 2 ? 'u' : 'a' ; tmp[1] = flags & 1 ? '6' : '4' ; tmp[2] = ':' ; - memcpy(tmp + 3, d.s, d.len) ; - r = cdb_find(c, &data, tmp, 3 + d.len) ; + r = s6dns_domain_tostring(tmp + 3, d.len + 1, &d) ; + tmp[3 + r] = 0 ; + if (!r) return -1 ; + r = cdb_find(c, &data, tmp, 3 + r) ; + if (r <= 0) return r ; } - if (r <= 0) return r ; if (!data.len) return 0 ; if (data.len & (flags & 1 ? 15 : 3)) return (errno = EPROTO, -1) ; if (!stralloc_catb(sa, data.s, data.len)) return -1 ; diff --git a/src/libs6dns/s6dns_hosts_name.c b/src/libs6dns/s6dns_hosts_name.c index af2030b..53d5431 100644 --- a/src/libs6dns/s6dns_hosts_name.c +++ b/src/libs6dns/s6dns_hosts_name.c @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -24,7 +25,7 @@ int s6dns_hosts_name_r (cdb const *c, char const *ip, stralloc *sa, genalloc *ga if (!c->map) return 0 ; if (is6) tmp[1] = '6' ; memcpy(tmp + 3, ip, is6 ? 16 : 4) ; - r = cdb_find(c, &data, tmp, 7) ; + r = cdb_find(c, &data, tmp, is6 ? 19 : 7) ; if (r <= 0) return r ; if (!data.len) return 0 ; if (data.s[data.len - 1]) return (errno = EPROTO, -1) ; diff --git a/src/utilities/s6-dns-hosts-compile.c b/src/utilities/s6-dns-hosts-compile.c index 4a38955..554a569 100644 --- a/src/utilities/s6-dns-hosts-compile.c +++ b/src/utilities/s6-dns-hosts-compile.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -48,6 +49,7 @@ int main (int argc, char const *const *argv) if (!s6dns_hosts_compile(fdr, fdw)) strerr_diefu4sys(111, "compile ", ifile, " to ", tmp) ; if (fsync(fdw) == -1) strerr_diefu2sys(111, "fsync ", tmp) ; + if (fchmod(fdw, 0644) == -1) strerr_diefu2sys(111, "fchmod ", tmp) ; if (rename(tmp, ofile) == -1) strerr_diefu4sys(111, "rename ", tmp, " to ", ofile) ; } return 0 ; -- cgit v1.3.1