diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-07-13 12:51:09 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-07-13 12:51:09 +0000 |
commit | 85ed638be3aea9c8ab6806a1fde248b10c2fee14 (patch) | |
tree | 247567f39cfc461307efa81d482a4a7ea05af098 | |
parent | 7fca0b937293ab5894f94538bf607dda8f58ab2e (diff) | |
download | s6-dns-85ed638be3aea9c8ab6806a1fde248b10c2fee14.tar.xz |
Bugfix the bigfuxes
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r-- | doc/s6-dnsip.html | 4 | ||||
-rw-r--r-- | doc/s6-dnsip4.html | 4 | ||||
-rw-r--r-- | doc/s6-dnsip6.html | 4 | ||||
-rw-r--r-- | doc/s6-dnsname.html | 4 | ||||
-rw-r--r-- | src/include/s6-dns/hosts.h | 6 | ||||
-rw-r--r-- | src/libs6dns/s6dns_hosts_ip_string.c | 18 | ||||
-rw-r--r-- | src/libs6dns/s6dns_hosts_name.c | 3 | ||||
-rw-r--r-- | 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. </li> <li> <tt>-h</tt> : use data from <tt>/etc/hosts</tt>, if available. If there's a compiled <tt>/etc/hosts.cdb</tt> file that is newer than <tt>/etc/hosts</tt>, it will be used instead. (See -<a href="s6-dns-hosts-compile.html">s6-dns-hosts-compile</a> for details.) </li> +<a href="s6-dns-hosts-compile.html">s6-dns-hosts-compile</a> for details.) +If the lookup in the hosts database returns at least one result, then +no DNS lookup is performed. </li> <li> <tt>-r</tt> : 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. </li> <li> <tt>-h</tt> : use data from <tt>/etc/hosts</tt>, if available. If there's a compiled <tt>/etc/hosts.cdb</tt> file that is newer than <tt>/etc/hosts</tt>, it will be used instead. (See -<a href="s6-dns-hosts-compile.html">s6-dns-hosts-compile</a> for details.) </li> +<a href="s6-dns-hosts-compile.html">s6-dns-hosts-compile</a> for details.) +If the lookup in the hosts database returns at least one result, then +no DNS lookup is performed. </li> <li> <tt>-r</tt> : 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. </li> <li> <tt>-h</tt> : use data from <tt>/etc/hosts</tt>, if available. If there's a compiled <tt>/etc/hosts.cdb</tt> file that is newer than <tt>/etc/hosts</tt>, it will be used instead. (See -<a href="s6-dns-hosts-compile.html">s6-dns-hosts-compile</a> for details.) </li> +<a href="s6-dns-hosts-compile.html">s6-dns-hosts-compile</a> for details.) +If the lookup in the hosts database returns at least one result, then +no DNS lookup is performed. </li> <li> <tt>-r</tt> : 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. </li> <li> <tt>-h</tt> : use data from <tt>/etc/hosts</tt>, if available. If there's a compiled <tt>/etc/hosts.cdb</tt> file that is newer than <tt>/etc/hosts</tt>, it will be used instead. (See -<a href="s6-dns-hosts-compile.html">s6-dns-hosts-compile</a> for details.) </li> +<a href="s6-dns-hosts-compile.html">s6-dns-hosts-compile</a> for details.) +If the lookup in the hosts database returns at least one result, then +no DNS lookup is performed. </li> <li> <tt>-r</tt> : 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 <errno.h> -#include <string.h> #include <skalibs/cdb.h> #include <skalibs/stralloc.h> @@ -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 <skalibs/cdb.h> #include <skalibs/stralloc.h> #include <skalibs/genalloc.h> +#include <skalibs/skamisc.h> #include <s6-dns/hosts.h> @@ -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 <string.h> #include <unistd.h> #include <stdlib.h> +#include <sys/stat.h> #include <stdio.h> #include <skalibs/sgetopt.h> @@ -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 ; |